Annotation of loncom/interface/domainprefs.pm, revision 1.423
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.423 ! raeburn 4: # $Id: domainprefs.pm,v 1.422 2023/04/11 20:35:19 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.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.419 raeburn 170: use Apache::courseprefs();
1.69 raeburn 171: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 172: use LONCAPA::Enrollment;
1.81 raeburn 173: use LONCAPA::lonauthcgi();
1.275 raeburn 174: use LONCAPA::SSL;
1.9 raeburn 175: use File::Copy;
1.43 raeburn 176: use Locale::Language;
1.62 raeburn 177: use DateTime::TimeZone;
1.68 raeburn 178: use DateTime::Locale;
1.267 raeburn 179: use Time::HiRes qw( sleep );
1.373 raeburn 180: use Net::CIDR;
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',
225: 'privacy','passwords','proctoring','wafproxy','ipaccess'],$dom);
1.320 raeburn 226: my %encconfig =
1.405 raeburn 227: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.297 raeburn 228: if (ref($domconfig{'ltitools'}) eq 'HASH') {
229: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 ! raeburn 230: my $is_home;
! 231: my $home = &Apache::lonnet::domain($dom,'primary');
! 232: unless (($home eq 'no_host') || ($home eq '')) {
! 233: my @ids=&Apache::lonnet::current_machine_ids();
! 234: if (grep(/^\Q$home\E$/,@ids)) {
! 235: $is_home = 1;
! 236: }
! 237: }
1.297 raeburn 238: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 239: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
240: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 241: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 ! raeburn 242: if (($is_home) && ($phase eq 'process')) {
! 243: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
! 244: }
1.297 raeburn 245: }
246: }
247: }
248: }
1.320 raeburn 249: if (ref($domconfig{'lti'}) eq 'HASH') {
250: if (ref($encconfig{'lti'}) eq 'HASH') {
251: foreach my $id (keys(%{$domconfig{'lti'}})) {
252: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
253: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
254: foreach my $item ('key','secret') {
255: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
256: }
257: }
258: }
259: }
260: }
1.405 raeburn 261: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 262: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 263: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 264: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
265: unless ($id =~ /^\d+$/) {
266: delete($domconfig{'ltisec'}{'linkprot'}{$id});
267: }
268: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 269: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
270: foreach my $item ('key','secret') {
1.406 raeburn 271: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 272: }
273: }
274: }
275: }
276: }
277: }
1.372 raeburn 278: if (ref($domconfig{'proctoring'}) eq 'HASH') {
279: if (ref($encconfig{'proctoring'}) eq 'HASH') {
280: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
281: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
282: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
284: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
285: }
286: }
287: }
288: }
289: }
1.394 raeburn 290: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
291: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 292: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 293: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 294: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 295: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
296: 'trust','lti');
1.171 raeburn 297: my %existing;
298: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
299: %existing = %{$domconfig{'loadbalancing'}};
300: }
301: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 302: push(@prefs_order,'loadbalancing');
303: }
1.30 raeburn 304: my %prefs = (
305: 'rolecolors' =>
306: { text => 'Default color schemes',
1.67 raeburn 307: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 308: header => [{col1 => 'Student Settings',
309: col2 => '',},
310: {col1 => 'Coordinator Settings',
311: col2 => '',},
312: {col1 => 'Author Settings',
313: col2 => '',},
314: {col1 => 'Administrator Settings',
315: col2 => '',}],
1.230 raeburn 316: print => \&print_rolecolors,
317: modify => \&modify_rolecolors,
1.30 raeburn 318: },
1.110 raeburn 319: 'login' =>
1.30 raeburn 320: { text => 'Log-in page options',
1.67 raeburn 321: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 322: header => [{col1 => 'Log-in Page Items',
323: col2 => '',},
324: {col1 => 'Log-in Help',
1.256 raeburn 325: col2 => 'Value'},
326: {col1 => 'Custom HTML in document head',
1.386 raeburn 327: col2 => 'Value'},
328: {col1 => 'SSO',
329: col2 => 'Dual login: SSO and non-SSO options'},
330: ],
1.230 raeburn 331: print => \&print_login,
332: modify => \&modify_login,
1.30 raeburn 333: },
1.43 raeburn 334: 'defaults' =>
1.236 raeburn 335: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 336: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 337: header => [{col1 => 'Setting',
1.236 raeburn 338: col2 => 'Value'},
339: {col1 => 'Institutional user types',
1.409 raeburn 340: col2 => 'Name displayed'},
341: {col1 => 'Mapping for missing usernames via standard log-in',
342: col2 => 'Rules in use'}],
1.230 raeburn 343: print => \&print_defaults,
344: modify => \&modify_defaults,
1.43 raeburn 345: },
1.381 raeburn 346: 'wafproxy' =>
347: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 348: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 349: header => [{col1 => 'Domain(s)',
350: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 351: },
1.381 raeburn 352: {col1 => 'Domain(s)',
353: col2 => 'WAF Configuration',}],
1.373 raeburn 354: print => \&print_wafproxy,
1.381 raeburn 355: modify => \&modify_wafproxy,
1.373 raeburn 356: },
1.354 raeburn 357: 'passwords' =>
358: { text => 'Passwords (Internal authentication)',
359: help => 'Domain_Configuration_Passwords',
360: header => [{col1 => 'Resetting Forgotten Password',
361: col2 => 'Settings'},
362: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
363: col2 => 'Settings'},
364: {col1 => 'Rules for LON-CAPA Passwords',
365: col2 => 'Settings'},
366: {col1 => 'Course Owner Changing Student Passwords',
367: col2 => 'Settings'}],
368: print => \&print_passwords,
369: modify => \&modify_passwords,
370: },
1.30 raeburn 371: 'quotas' =>
1.413 raeburn 372: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 373: help => 'Domain_Configuration_Quotas',
1.77 raeburn 374: header => [{col1 => 'User affiliation',
1.72 raeburn 375: col2 => 'Available tools',
1.213 raeburn 376: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 377: print => \&print_quotas,
378: modify => \&modify_quotas,
1.30 raeburn 379: },
380: 'autoenroll' =>
381: { text => 'Auto-enrollment settings',
1.67 raeburn 382: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 383: header => [{col1 => 'Configuration setting',
384: col2 => 'Value(s)'}],
1.230 raeburn 385: print => \&print_autoenroll,
386: modify => \&modify_autoenroll,
1.30 raeburn 387: },
388: 'autoupdate' =>
389: { text => 'Auto-update settings',
1.67 raeburn 390: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 391: header => [{col1 => 'Setting',
392: col2 => 'Value',},
1.131 raeburn 393: {col1 => 'Setting',
394: col2 => 'Affiliation'},
1.43 raeburn 395: {col1 => 'User population',
1.227 bisitz 396: col2 => 'Updatable user data'}],
1.230 raeburn 397: print => \&print_autoupdate,
398: modify => \&modify_autoupdate,
1.30 raeburn 399: },
1.125 raeburn 400: 'autocreate' =>
401: { text => 'Auto-course creation settings',
402: help => 'Domain_Configuration_Auto_Creation',
403: header => [{col1 => 'Configuration Setting',
404: col2 => 'Value',}],
1.230 raeburn 405: print => \&print_autocreate,
406: modify => \&modify_autocreate,
1.125 raeburn 407: },
1.30 raeburn 408: 'directorysrch' =>
1.277 raeburn 409: { text => 'Directory searches',
1.67 raeburn 410: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 411: header => [{col1 => 'Institutional Directory Setting',
412: col2 => 'Value',},
413: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 414: col2 => 'Value',}],
1.230 raeburn 415: print => \&print_directorysrch,
416: modify => \&modify_directorysrch,
1.30 raeburn 417: },
418: 'contacts' =>
1.286 raeburn 419: { text => 'E-mail addresses and helpform',
1.67 raeburn 420: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 421: header => [{col1 => 'Default e-mail addresses',
422: col2 => 'Value',},
423: {col1 => 'Recipient(s) for notifications',
424: col2 => 'Value',},
1.340 raeburn 425: {col1 => 'Nightly status check e-mail',
426: col2 => 'Settings',},
1.286 raeburn 427: {col1 => 'Ask helpdesk form settings',
428: col2 => 'Value',},],
1.230 raeburn 429: print => \&print_contacts,
430: modify => \&modify_contacts,
1.30 raeburn 431: },
432: 'usercreation' =>
433: { text => 'User creation',
1.67 raeburn 434: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 435: header => [{col1 => 'Format rule type',
436: col2 => 'Format rules in force'},
1.34 raeburn 437: {col1 => 'User account creation',
438: col2 => 'Usernames which may be created',},
1.30 raeburn 439: {col1 => 'Context',
1.43 raeburn 440: col2 => 'Assignable authentication types'}],
1.230 raeburn 441: print => \&print_usercreation,
442: modify => \&modify_usercreation,
1.30 raeburn 443: },
1.224 raeburn 444: 'selfcreation' =>
445: { text => 'Users self-creating accounts',
446: help => 'Domain_Configuration_Self_Creation',
447: header => [{col1 => 'Self-creation with institutional username',
448: col2 => 'Enabled?'},
449: {col1 => 'Institutional user type (login/SSO self-creation)',
450: col2 => 'Information user can enter'},
1.303 raeburn 451: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 452: col2 => 'Settings'}],
1.230 raeburn 453: print => \&print_selfcreation,
454: modify => \&modify_selfcreation,
1.224 raeburn 455: },
1.69 raeburn 456: 'usermodification' =>
1.33 raeburn 457: { text => 'User modification',
1.67 raeburn 458: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 459: header => [{col1 => 'Target user has role',
1.227 bisitz 460: col2 => 'User information updatable in author context'},
1.33 raeburn 461: {col1 => 'Target user has role',
1.227 bisitz 462: col2 => 'User information updatable in course context'}],
1.230 raeburn 463: print => \&print_usermodification,
464: modify => \&modify_usermodification,
1.33 raeburn 465: },
1.69 raeburn 466: 'scantron' =>
1.346 raeburn 467: { text => 'Bubblesheet format',
1.67 raeburn 468: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 469: header => [ {col1 => 'Bubblesheet format file',
470: col2 => ''},
471: {col1 => 'Bubblesheet data upload formats',
472: col2 => 'Settings'}],
1.230 raeburn 473: print => \&print_scantron,
474: modify => \&modify_scantron,
1.46 raeburn 475: },
1.86 raeburn 476: 'requestcourses' =>
477: {text => 'Request creation of courses',
478: help => 'Domain_Configuration_Request_Courses',
479: header => [{col1 => 'User affiliation',
1.102 raeburn 480: col2 => 'Availability/Processing of requests',},
481: {col1 => 'Setting',
1.216 raeburn 482: col2 => 'Value'},
483: {col1 => 'Available textbooks',
1.235 raeburn 484: col2 => ''},
1.242 raeburn 485: {col1 => 'Available templates',
486: col2 => ''},
1.235 raeburn 487: {col1 => 'Validation (not official courses)',
488: col2 => 'Value'},],
1.230 raeburn 489: print => \&print_quotas,
490: modify => \&modify_quotas,
1.86 raeburn 491: },
1.163 raeburn 492: 'requestauthor' =>
1.223 bisitz 493: {text => 'Request Authoring Space',
1.163 raeburn 494: help => 'Domain_Configuration_Request_Author',
495: header => [{col1 => 'User affiliation',
496: col2 => 'Availability/Processing of requests',},
497: {col1 => 'Setting',
498: col2 => 'Value'}],
1.230 raeburn 499: print => \&print_quotas,
500: modify => \&modify_quotas,
1.163 raeburn 501: },
1.69 raeburn 502: 'coursecategories' =>
1.120 raeburn 503: { text => 'Cataloging of courses/communities',
1.67 raeburn 504: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 505: header => [{col1 => 'Catalog type/availability',
506: col2 => '',},
507: {col1 => 'Category settings for standard catalog',
1.57 raeburn 508: col2 => '',},
509: {col1 => 'Categories',
510: col2 => '',
511: }],
1.230 raeburn 512: print => \&print_coursecategories,
513: modify => \&modify_coursecategories,
1.69 raeburn 514: },
515: 'serverstatuses' =>
1.77 raeburn 516: {text => 'Access to server status pages',
1.69 raeburn 517: help => 'Domain_Configuration_Server_Status',
518: header => [{col1 => 'Status Page',
519: col2 => 'Other named users',
520: col3 => 'Specific IPs',
521: }],
1.230 raeburn 522: print => \&print_serverstatuses,
523: modify => \&modify_serverstatuses,
1.69 raeburn 524: },
1.118 jms 525: 'helpsettings' =>
1.282 raeburn 526: {text => 'Support settings',
1.118 jms 527: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 528: header => [{col1 => 'Help Page Settings (logged-in users)',
529: col2 => 'Value'},
530: {col1 => 'Helpdesk Roles',
531: col2 => 'Settings'},],
1.230 raeburn 532: print => \&print_helpsettings,
533: modify => \&modify_helpsettings,
1.118 jms 534: },
1.121 raeburn 535: 'coursedefaults' =>
536: {text => 'Course/Community defaults',
537: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 538: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
539: col2 => 'Value',},
540: {col1 => 'Defaults which can be overridden for each course by a DC',
541: col2 => 'Value',},],
1.230 raeburn 542: print => \&print_coursedefaults,
543: modify => \&modify_coursedefaults,
1.121 raeburn 544: },
1.231 raeburn 545: 'selfenrollment' =>
546: {text => 'Self-enrollment in Course/Community',
547: help => 'Domain_Configuration_Selfenrollment',
548: header => [{col1 => 'Configuration Rights',
549: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
550: {col1 => 'Defaults',
551: col2 => 'Value'},
552: {col1 => 'Self-enrollment validation (optional)',
553: col2 => 'Value'},],
554: print => \&print_selfenrollment,
555: modify => \&modify_selfenrollment,
556: },
1.120 raeburn 557: 'privacy' =>
1.357 raeburn 558: {text => 'Availability of User Information',
1.120 raeburn 559: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 560: header => [{col1 => 'Role assigned in different domain',
561: col2 => 'Approval options'},
562: {col1 => 'Role assigned in different domain to user of type',
563: col2 => 'User information available in that domain'},
564: {col1 => "Role assigned in user's domain",
565: col2 => 'Information viewable by privileged user'},
566: {col1 => "Role assigned in user's domain",
567: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 568: print => \&print_privacy,
569: modify => \&modify_privacy,
1.120 raeburn 570: },
1.141 raeburn 571: 'usersessions' =>
1.145 raeburn 572: {text => 'User session hosting/offloading',
1.137 raeburn 573: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 574: header => [{col1 => 'Domain server',
575: col2 => 'Servers to offload sessions to when busy'},
576: {col1 => 'Hosting of users from other domains',
1.137 raeburn 577: col2 => 'Rules'},
578: {col1 => "Hosting domain's own users elsewhere",
579: col2 => 'Rules'}],
1.230 raeburn 580: print => \&print_usersessions,
581: modify => \&modify_usersessions,
1.137 raeburn 582: },
1.279 raeburn 583: 'loadbalancing' =>
1.185 raeburn 584: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 585: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 586: header => [{col1 => 'Balancers',
1.150 raeburn 587: col2 => 'Default destinations',
1.183 bisitz 588: col3 => 'User affiliation',
1.150 raeburn 589: col4 => 'Overrides'},
590: ],
1.230 raeburn 591: print => \&print_loadbalancing,
592: modify => \&modify_loadbalancing,
1.150 raeburn 593: },
1.279 raeburn 594: 'ltitools' =>
1.267 raeburn 595: {text => 'External Tools (LTI)',
1.296 raeburn 596: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 597: header => [{col1 => 'Encryption of shared secrets',
598: col2 => 'Settings'},
599: {col1 => 'Rules for shared secrets',
600: col2 => 'Settings'},
601: {col1 => 'Providers',
602: col2 => 'Settings',}],
1.267 raeburn 603: print => \&print_ltitools,
604: modify => \&modify_ltitools,
605: },
1.372 raeburn 606: 'proctoring' =>
607: {text => 'Remote Proctoring Integration',
608: help => 'Domain_Configuration_Proctoring',
609: header => [{col1 => 'Name',
610: col2 => 'Configuration'}],
611: print => \&print_proctoring,
612: modify => \&modify_proctoring,
613: },
1.279 raeburn 614: 'ssl' =>
1.275 raeburn 615: {text => 'LON-CAPA Network (SSL)',
616: help => 'Domain_Configuration_Network_SSL',
617: header => [{col1 => 'Server',
618: col2 => 'Certificate Status'},
619: {col1 => 'Connections to other servers',
620: col2 => 'Rules'},
1.293 raeburn 621: {col1 => 'Connections from other servers',
622: col2 => 'Rules'},
1.275 raeburn 623: {col1 => "Replicating domain's published content",
624: col2 => 'Rules'}],
625: print => \&print_ssl,
626: modify => \&modify_ssl,
627: },
1.279 raeburn 628: 'trust' =>
629: {text => 'Trust Settings',
630: help => 'Domain_Configuration_Trust',
631: header => [{col1 => "Access to this domain's content by others",
632: col2 => 'Rules'},
633: {col1 => "Access to other domain's content by this domain",
634: col2 => 'Rules'},
635: {col1 => "Enrollment in this domain's courses by others",
636: col2 => 'Rules',},
637: {col1 => "Co-author roles in this domain for others",
638: col2 => 'Rules',},
639: {col1 => "Co-author roles for this domain's users elsewhere",
640: col2 => 'Rules',},
641: {col1 => "Domain roles in this domain assignable to others",
642: col2 => 'Rules'},
643: {col1 => "Course catalog for this domain displayed elsewhere",
644: col2 => 'Rules'},
645: {col1 => "Requests for creation of courses in this domain by others",
646: col2 => 'Rules'},
647: {col1 => "Users in other domains can send messages to this domain",
648: col2 => 'Rules'},],
649: print => \&print_trust,
650: modify => \&modify_trust,
651: },
1.320 raeburn 652: 'lti' =>
1.405 raeburn 653: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 654: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 655: header => [{col1 => 'Encryption of shared secrets',
656: col2 => 'Settings'},
657: {col1 => 'Rules for shared secrets',
658: col2 => 'Settings'},
1.406 raeburn 659: {col1 => 'Link Protectors',
1.405 raeburn 660: col2 => 'Settings'},
661: {col1 => 'Consumers',
662: col2 => 'Settings'},],
1.320 raeburn 663: print => \&print_lti,
664: modify => \&modify_lti,
665: },
1.394 raeburn 666: 'ipaccess' =>
667: {text => 'IP-based access control',
668: help => 'Domain_Configuration_IP_Access',
669: header => [{col1 => 'Setting',
670: col2 => 'Value'},],
671: print => \&print_ipaccess,
672: modify => \&modify_ipaccess,
673: },
1.3 raeburn 674: );
1.110 raeburn 675: if (keys(%servers) > 1) {
676: $prefs{'login'} = { text => 'Log-in page options',
677: help => 'Domain_Configuration_Login_Page',
678: header => [{col1 => 'Log-in Service',
679: col2 => 'Server Setting',},
680: {col1 => 'Log-in Page Items',
1.405 raeburn 681: col2 => 'Settings'},
1.168 raeburn 682: {col1 => 'Log-in Help',
1.256 raeburn 683: col2 => 'Value'},
684: {col1 => 'Custom HTML in document head',
1.386 raeburn 685: col2 => 'Value'},
686: {col1 => 'SSO',
687: col2 => 'Dual login: SSO and non-SSO options'},
688: ],
1.230 raeburn 689: print => \&print_login,
690: modify => \&modify_login,
1.110 raeburn 691: };
692: }
1.174 foxr 693:
1.6 raeburn 694: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 695: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 696: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 697: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 698: text=>"Settings to display/modify"});
1.9 raeburn 699: my $confname = $dom.'-domainconfig';
1.174 foxr 700:
1.3 raeburn 701: if ($phase eq 'process') {
1.212 raeburn 702: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
703: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 704: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 705: $r->rflush();
1.212 raeburn 706: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 707: }
1.30 raeburn 708: } elsif ($phase eq 'display') {
1.192 raeburn 709: my $js = &recaptcha_js().
1.236 raeburn 710: &toggle_display_js();
1.171 raeburn 711: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 712: my ($othertitle,$usertypes,$types) =
713: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 714: $js .= &lonbalance_targets_js($dom,$types,\%servers,
715: $domconfig{'loadbalancing'}).
1.170 raeburn 716: &new_spares_js().
717: &common_domprefs_js().
718: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 719: }
1.216 raeburn 720: if (grep(/^requestcourses$/,@actions)) {
721: my $javascript_validations;
722: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
723: $js .= <<END;
724: <script type="text/javascript">
725: $javascript_validations
726: </script>
727: $coursebrowserjs
728: END
1.394 raeburn 729: } elsif (grep(/^ipaccess$/,@actions)) {
730: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 731: }
1.305 raeburn 732: if (grep(/^selfcreation$/,@actions)) {
733: $js .= &selfcreate_javascript();
734: }
1.286 raeburn 735: if (grep(/^contacts$/,@actions)) {
736: $js .= &contacts_javascript();
737: }
1.346 raeburn 738: if (grep(/^scantron$/,@actions)) {
739: $js .= &scantron_javascript();
740: }
1.150 raeburn 741: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 742: } else {
1.180 raeburn 743: # check if domconfig user exists for the domain.
744: my $servadm = $r->dir_config('lonAdmEMail');
745: my ($configuserok,$author_ok,$switchserver) =
746: &config_check($dom,$confname,$servadm);
747: unless ($configuserok eq 'ok') {
1.181 raeburn 748: &Apache::lonconfigsettings::print_header($r,$phase,$context);
749: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 750: $confname).
1.181 raeburn 751: '<br />'
752: );
1.180 raeburn 753: if ($switchserver) {
1.181 raeburn 754: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
755: '<br />'.
756: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
757: '<br />'.
758: &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).
759: '<br />'.
760: &mt('To do that now, use the following link: [_1]',$switchserver)
761: );
762: } else {
763: $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.').
764: '<br />'.
765: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
766: );
1.180 raeburn 767: }
768: $r->print(&Apache::loncommon::end_page());
769: return OK;
770: }
1.21 raeburn 771: if (keys(%domconfig) == 0) {
772: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 773: my @ids=&Apache::lonnet::current_machine_ids();
774: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 775: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 776: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 777: my $custom_img_count = 0;
778: foreach my $img (@loginimages) {
779: if ($designhash{$dom.'.login.'.$img} ne '') {
780: $custom_img_count ++;
781: }
782: }
783: foreach my $role (@roles) {
784: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
785: $custom_img_count ++;
786: }
787: }
788: if ($custom_img_count > 0) {
1.94 raeburn 789: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 790: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 791: $r->print(
792: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
793: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
794: &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 />'.
795: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
796: if ($switch_server) {
1.30 raeburn 797: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 798: }
1.91 raeburn 799: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 800: return OK;
801: }
802: }
803: }
1.91 raeburn 804: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 805: }
806: return OK;
807: }
808:
809: sub process_changes {
1.205 raeburn 810: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 811: my %domconfig;
812: if (ref($values) eq 'HASH') {
813: %domconfig = %{$values};
814: }
1.3 raeburn 815: my $output;
816: if ($action eq 'login') {
1.205 raeburn 817: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 818: } elsif ($action eq 'rolecolors') {
1.9 raeburn 819: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 820: $lastactref,%domconfig);
1.3 raeburn 821: } elsif ($action eq 'quotas') {
1.216 raeburn 822: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 823: } elsif ($action eq 'autoenroll') {
1.205 raeburn 824: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 825: } elsif ($action eq 'autoupdate') {
826: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 827: } elsif ($action eq 'autocreate') {
828: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 829: } elsif ($action eq 'directorysrch') {
1.295 raeburn 830: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 831: } elsif ($action eq 'usercreation') {
1.28 raeburn 832: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 833: } elsif ($action eq 'selfcreation') {
1.305 raeburn 834: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 835: } elsif ($action eq 'usermodification') {
836: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 837: } elsif ($action eq 'contacts') {
1.205 raeburn 838: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 839: } elsif ($action eq 'defaults') {
1.212 raeburn 840: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 841: } elsif ($action eq 'scantron') {
1.205 raeburn 842: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 843: } elsif ($action eq 'coursecategories') {
1.239 raeburn 844: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 845: } elsif ($action eq 'serverstatuses') {
846: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 847: } elsif ($action eq 'requestcourses') {
1.216 raeburn 848: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 849: } elsif ($action eq 'requestauthor') {
1.216 raeburn 850: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 851: } elsif ($action eq 'helpsettings') {
1.285 raeburn 852: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 853: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 854: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 855: } elsif ($action eq 'selfenrollment') {
856: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 857: } elsif ($action eq 'usersessions') {
1.212 raeburn 858: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 859: } elsif ($action eq 'loadbalancing') {
860: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 861: } elsif ($action eq 'ltitools') {
862: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 863: } elsif ($action eq 'proctoring') {
864: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 865: } elsif ($action eq 'ssl') {
866: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 867: } elsif ($action eq 'trust') {
868: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 869: } elsif ($action eq 'lti') {
870: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 871: } elsif ($action eq 'privacy') {
872: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 873: } elsif ($action eq 'passwords') {
874: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 875: } elsif ($action eq 'wafproxy') {
876: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 877: } elsif ($action eq 'ipaccess') {
878: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 879: }
880: return $output;
881: }
882:
883: sub print_config_box {
1.9 raeburn 884: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 885: my $rowtotal = 0;
1.49 raeburn 886: my $output;
887: if ($action eq 'coursecategories') {
888: $output = &coursecategories_javascript($settings);
1.236 raeburn 889: } elsif ($action eq 'defaults') {
890: $output = &defaults_javascript($settings);
1.354 raeburn 891: } elsif ($action eq 'passwords') {
1.405 raeburn 892: $output = &passwords_javascript($action);
1.282 raeburn 893: } elsif ($action eq 'helpsettings') {
894: my (%privs,%levelscurrent);
895: my %full=();
896: my %levels=(
897: course => {},
898: domain => {},
899: system => {},
900: );
901: my $context = 'domain';
902: my $crstype = 'Course';
903: my $formname = 'display';
904: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
905: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
906: $output =
907: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
908: \@templateroles);
1.334 raeburn 909: } elsif ($action eq 'ltitools') {
1.421 raeburn 910: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 911: } elsif ($action eq 'lti') {
1.421 raeburn 912: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 913: <i_javascript($dom,$settings);
1.372 raeburn 914: } elsif ($action eq 'proctoring') {
915: $output .= &proctoring_javascript($settings);
1.381 raeburn 916: } elsif ($action eq 'wafproxy') {
917: $output .= &wafproxy_javascript($dom);
1.385 raeburn 918: } elsif ($action eq 'autoupdate') {
919: $output .= &autoupdate_javascript();
1.399 raeburn 920: } elsif ($action eq 'autoenroll') {
921: $output .= &autoenroll_javascript();
1.386 raeburn 922: } elsif ($action eq 'login') {
923: $output .= &saml_javascript();
1.394 raeburn 924: } elsif ($action eq 'ipaccess') {
925: $output .= &ipaccess_javascript($settings);
1.91 raeburn 926: }
1.236 raeburn 927: $output .=
1.30 raeburn 928: '<table class="LC_nested_outer">
1.3 raeburn 929: <tr>
1.306 raeburn 930: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 931: &mt($item->{text}).' '.
932: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
933: '</tr>';
1.30 raeburn 934: $rowtotal ++;
1.110 raeburn 935: my $numheaders = 1;
936: if (ref($item->{'header'}) eq 'ARRAY') {
937: $numheaders = scalar(@{$item->{'header'}});
938: }
939: if ($numheaders > 1) {
1.64 raeburn 940: my $colspan = '';
1.145 raeburn 941: my $rightcolspan = '';
1.369 raeburn 942: my $leftnobr = '';
1.238 raeburn 943: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 944: ($action eq 'directorysrch') ||
1.386 raeburn 945: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 946: $colspan = ' colspan="2"';
947: }
1.145 raeburn 948: if ($action eq 'usersessions') {
949: $rightcolspan = ' colspan="3"';
950: }
1.369 raeburn 951: if ($action eq 'passwords') {
952: $leftnobr = ' LC_nobreak';
953: }
1.30 raeburn 954: $output .= '
1.3 raeburn 955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">
1.369 raeburn 959: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 960: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 961: </tr>';
1.69 raeburn 962: $rowtotal ++;
1.230 raeburn 963: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 964: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 965: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 966: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 967: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
968: ($action eq 'lti') || ($action eq 'ltitools')) {
1.230 raeburn 969: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 970: } elsif ($action eq 'passwords') {
971: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 972: } elsif ($action eq 'coursecategories') {
1.230 raeburn 973: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 974: } elsif ($action eq 'scantron') {
975: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 976: } elsif ($action eq 'login') {
1.386 raeburn 977: if ($numheaders == 5) {
1.168 raeburn 978: $colspan = ' colspan="2"';
979: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
980: } else {
981: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
982: }
1.230 raeburn 983: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 984: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 985: } elsif ($action eq 'rolecolors') {
1.30 raeburn 986: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 987: }
1.30 raeburn 988: $output .= '
1.6 raeburn 989: </table>
990: </td>
991: </tr>
992: <tr>
993: <td>
994: <table class="LC_nested">
995: <tr class="LC_info_row">
1.230 raeburn 996: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 997: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 998: </tr>';
999: $rowtotal ++;
1.230 raeburn 1000: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1001: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1002: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1003: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1004: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1005: ($action eq 'ltitools')) {
1.238 raeburn 1006: if ($action eq 'coursecategories') {
1007: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1008: $colspan = ' colspan="2"';
1.279 raeburn 1009: } elsif ($action eq 'trust') {
1010: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1011: } elsif ($action eq 'passwords') {
1012: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 1013: } else {
1014: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1015: }
1.279 raeburn 1016: if ($action eq 'trust') {
1017: $output .= '
1018: </table>
1019: </td>
1020: </tr>';
1021: my @trusthdrs = qw(2 3 4 5 6 7);
1022: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1023: for (my $i=0; $i<@trusthdrs; $i++) {
1024: $output .= '
1025: <tr>
1026: <td>
1027: <table class="LC_nested">
1028: <tr class="LC_info_row">
1029: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1030: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1031: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1032: </table>
1033: </td>
1034: </tr>';
1035: }
1036: $output .= '
1037: <tr>
1038: <td>
1039: <table class="LC_nested">
1040: <tr class="LC_info_row">
1041: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1042: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1043: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1044: } else {
1045: $output .= '
1.63 raeburn 1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1055: </tr>'."\n";
1.279 raeburn 1056: if ($action eq 'coursecategories') {
1057: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1058: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1059: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1060: if ($action eq 'passwords') {
1061: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1062: } else {
1063: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1064: }
1065: $output .= '
1.340 raeburn 1066: </tr>
1067: </table>
1068: </td>
1069: </tr>
1070: <tr>
1071: <td>
1072: <table class="LC_nested">
1073: <tr class="LC_info_row">
1.369 raeburn 1074: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1075: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1076: if ($action eq 'passwords') {
1077: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1078: } else {
1079: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1080: }
1081: $output .= '
1.340 raeburn 1082: </table>
1083: </td>
1084: </tr>
1085: <tr>';
1.279 raeburn 1086: } else {
1087: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1088: }
1.238 raeburn 1089: }
1.63 raeburn 1090: $rowtotal ++;
1.236 raeburn 1091: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1092: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1093: ($action eq 'wafproxy')) {
1.230 raeburn 1094: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1095: } elsif ($action eq 'scantron') {
1096: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1097: } elsif ($action eq 'ssl') {
1098: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1099: </table>
1100: </td>
1101: </tr>
1102: <tr>
1103: <td>
1104: <table class="LC_nested">
1105: <tr class="LC_info_row">
1106: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1107: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1108: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1109: </table>
1110: </td>
1111: </tr>
1112: <tr>
1113: <td>
1114: <table class="LC_nested">
1115: <tr class="LC_info_row">
1116: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1117: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1118: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1119: } elsif ($action eq 'login') {
1.386 raeburn 1120: if ($numheaders == 5) {
1.168 raeburn 1121: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1122: </table>
1123: </td>
1124: </tr>
1125: <tr>
1126: <td>
1127: <table class="LC_nested">
1128: <tr class="LC_info_row">
1129: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1130: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1131: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1132: $rowtotal ++;
1133: } else {
1134: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1135: }
1.256 raeburn 1136: $output .= '
1137: </table>
1138: </td>
1139: </tr>
1140: <tr>
1141: <td>
1142: <table class="LC_nested">
1143: <tr class="LC_info_row">';
1.386 raeburn 1144: if ($numheaders == 5) {
1.256 raeburn 1145: $output .= '
1146: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1147: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1148: </tr>';
1149: } else {
1150: $output .= '
1151: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1152: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1153: </tr>';
1154: }
1155: $rowtotal ++;
1.386 raeburn 1156: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1157: </table>
1158: </td>
1159: </tr>
1160: <tr>
1161: <td>
1162: <table class="LC_nested">
1163: <tr class="LC_info_row">';
1164: if ($numheaders == 5) {
1165: $output .= '
1166: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1167: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1168: </tr>';
1169: } else {
1170: $output .= '
1171: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1172: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1173: </tr>';
1174: }
1175: $rowtotal ++;
1176: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1177: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1178: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1179: $rowtotal ++;
1180: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1181: </table>
1182: </td>
1183: </tr>
1184: <tr>
1185: <td>
1186: <table class="LC_nested">
1187: <tr class="LC_info_row">
1188: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1189: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1190: &textbookcourses_javascript($settings).
1191: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1192: </table>
1193: </td>
1194: </tr>
1195: <tr>
1196: <td>
1197: <table class="LC_nested">
1198: <tr class="LC_info_row">
1199: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1200: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1201: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1202: </table>
1203: </td>
1204: </tr>
1205: <tr>
1206: <td>
1207: <table class="LC_nested">
1208: <tr class="LC_info_row">
1.306 raeburn 1209: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1210: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1211: </tr>'.
1212: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1213: } elsif ($action eq 'requestauthor') {
1214: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1215: $rowtotal ++;
1.122 jms 1216: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1217: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1218: </table>
1219: </td>
1220: </tr>
1221: <tr>
1222: <td>
1223: <table class="LC_nested">
1224: <tr class="LC_info_row">
1.306 raeburn 1225: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1226: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1227: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1228: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1229: </tr>'.
1.30 raeburn 1230: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1231: </table>
1232: </td>
1233: </tr>
1234: <tr>
1235: <td>
1236: <table class="LC_nested">
1237: <tr class="LC_info_row">
1.59 bisitz 1238: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1239: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1240: </tr>'.
1.30 raeburn 1241: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1242: $rowtotal += 2;
1.6 raeburn 1243: }
1.3 raeburn 1244: } else {
1.30 raeburn 1245: $output .= '
1.3 raeburn 1246: <tr>
1247: <td>
1248: <table class="LC_nested">
1.30 raeburn 1249: <tr class="LC_info_row">';
1.277 raeburn 1250: if ($action eq 'login') {
1.30 raeburn 1251: $output .= '
1.59 bisitz 1252: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1253: } elsif ($action eq 'serverstatuses') {
1254: $output .= '
1.306 raeburn 1255: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1256: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1257:
1.6 raeburn 1258: } else {
1.30 raeburn 1259: $output .= '
1.306 raeburn 1260: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1261: }
1.72 raeburn 1262: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1263: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1264: &mt($item->{'header'}->[0]->{'col2'});
1265: if ($action eq 'serverstatuses') {
1266: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1267: }
1.69 raeburn 1268: } else {
1.306 raeburn 1269: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1270: &mt($item->{'header'}->[0]->{'col2'});
1271: }
1272: $output .= '</td>';
1273: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1274: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1275: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1276: &mt($item->{'header'}->[0]->{'col3'});
1277: } else {
1.306 raeburn 1278: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1279: &mt($item->{'header'}->[0]->{'col3'});
1280: }
1.69 raeburn 1281: if ($action eq 'serverstatuses') {
1282: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1283: }
1284: $output .= '</td>';
1.6 raeburn 1285: }
1.150 raeburn 1286: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1287: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1288: &mt($item->{'header'}->[0]->{'col4'});
1289: }
1.69 raeburn 1290: $output .= '</tr>';
1.48 raeburn 1291: $rowtotal ++;
1.168 raeburn 1292: if ($action eq 'quotas') {
1.86 raeburn 1293: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1294: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1295: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1296: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1297: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1298: }
1.3 raeburn 1299: }
1.30 raeburn 1300: $output .= '
1.3 raeburn 1301: </table>
1302: </td>
1303: </tr>
1.30 raeburn 1304: </table><br />';
1305: return ($output,$rowtotal);
1.1 raeburn 1306: }
1307:
1.3 raeburn 1308: sub print_login {
1.168 raeburn 1309: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1310: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1311: my %choices = &login_choices();
1.386 raeburn 1312: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1313: %lt = &login_file_options();
1314: $switchserver = &check_switchserver($dom,$confname);
1315: }
1.168 raeburn 1316: if ($caller eq 'service') {
1.149 raeburn 1317: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1318: my $choice = $choices{'disallowlogin'};
1319: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1320: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1321: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1322: '<th>'.$choices{'server'}.'</th>'.
1323: '<th>'.$choices{'serverpath'}.'</th>'.
1324: '<th>'.$choices{'custompath'}.'</th>'.
1325: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1326: my %disallowed;
1327: if (ref($settings) eq 'HASH') {
1328: if (ref($settings->{'loginvia'}) eq 'HASH') {
1329: %disallowed = %{$settings->{'loginvia'}};
1330: }
1331: }
1332: foreach my $lonhost (sort(keys(%servers))) {
1333: my $direct = 'selected="selected"';
1.128 raeburn 1334: if (ref($disallowed{$lonhost}) eq 'HASH') {
1335: if ($disallowed{$lonhost}{'server'} ne '') {
1336: $direct = '';
1337: }
1.110 raeburn 1338: }
1.115 raeburn 1339: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1340: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1341: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1342: '</option>';
1.184 raeburn 1343: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1344: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1345: my $selected = '';
1.128 raeburn 1346: if (ref($disallowed{$lonhost}) eq 'HASH') {
1347: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1348: $selected = 'selected="selected"';
1349: }
1.110 raeburn 1350: }
1351: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1352: $servers{$hostid}.'</option>';
1353: }
1.128 raeburn 1354: $datatable .= '</select></td>'.
1355: '<td><select name="'.$lonhost.'_serverpath">';
1356: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1357: my $pathname = $path;
1358: if ($path eq 'custom') {
1359: $pathname = &mt('Custom Path').' ->';
1360: }
1361: my $selected = '';
1362: if (ref($disallowed{$lonhost}) eq 'HASH') {
1363: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1364: $selected = 'selected="selected"';
1365: }
1366: } elsif ($path eq '') {
1367: $selected = 'selected="selected"';
1368: }
1369: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1370: }
1371: $datatable .= '</select></td>';
1372: my ($custom,$exempt);
1373: if (ref($disallowed{$lonhost}) eq 'HASH') {
1374: $custom = $disallowed{$lonhost}{'custompath'};
1375: $exempt = $disallowed{$lonhost}{'exempt'};
1376: }
1377: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1378: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1379: '</tr>';
1.110 raeburn 1380: }
1381: $datatable .= '</table></td></tr>';
1382: return $datatable;
1.168 raeburn 1383: } elsif ($caller eq 'page') {
1384: my %defaultchecked = (
1385: 'coursecatalog' => 'on',
1.188 raeburn 1386: 'helpdesk' => 'on',
1.168 raeburn 1387: 'adminmail' => 'off',
1388: 'newuser' => 'off',
1389: );
1.188 raeburn 1390: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1391: my (%checkedon,%checkedoff);
1.42 raeburn 1392: foreach my $item (@toggles) {
1.168 raeburn 1393: if ($defaultchecked{$item} eq 'on') {
1394: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1395: $checkedoff{$item} = ' ';
1.168 raeburn 1396: } elsif ($defaultchecked{$item} eq 'off') {
1397: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1398: $checkedon{$item} = ' ';
1399: }
1.1 raeburn 1400: }
1.168 raeburn 1401: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1402: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1403: my @logintext = ('textcol','bgcol');
1404: my @bgs = ('pgbg','mainbg','sidebg');
1405: my @links = ('link','alink','vlink');
1406: my %designhash = &Apache::loncommon::get_domainconf($dom);
1407: my %defaultdesign = %Apache::loncommon::defaultdesign;
1408: my (%is_custom,%designs);
1409: my %defaults = (
1410: font => $defaultdesign{'login.font'},
1411: );
1.6 raeburn 1412: foreach my $item (@images) {
1.168 raeburn 1413: $defaults{$item} = $defaultdesign{'login.'.$item};
1414: $defaults{'showlogo'}{$item} = 1;
1415: }
1416: foreach my $item (@bgs) {
1417: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1418: }
1.41 raeburn 1419: foreach my $item (@logintext) {
1.168 raeburn 1420: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1421: }
1.168 raeburn 1422: foreach my $item (@links) {
1423: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1424: }
1.168 raeburn 1425: if (ref($settings) eq 'HASH') {
1426: foreach my $item (@toggles) {
1427: if ($settings->{$item} eq '1') {
1428: $checkedon{$item} = ' checked="checked" ';
1429: $checkedoff{$item} = ' ';
1430: } elsif ($settings->{$item} eq '0') {
1431: $checkedoff{$item} = ' checked="checked" ';
1432: $checkedon{$item} = ' ';
1433: }
1434: }
1435: foreach my $item (@images) {
1436: if (defined($settings->{$item})) {
1437: $designs{$item} = $settings->{$item};
1438: $is_custom{$item} = 1;
1439: }
1440: if (defined($settings->{'showlogo'}{$item})) {
1441: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1442: }
1443: }
1.402 raeburn 1444: foreach my $item (@alttext) {
1445: if (ref($settings->{'alttext'}) eq 'HASH') {
1446: if ($settings->{'alttext'}->{$item} ne '') {
1447: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1448: }
1449: }
1450: }
1.168 raeburn 1451: foreach my $item (@logintext) {
1452: if ($settings->{$item} ne '') {
1453: $designs{'logintext'}{$item} = $settings->{$item};
1454: $is_custom{$item} = 1;
1455: }
1456: }
1457: if ($settings->{'font'} ne '') {
1458: $designs{'font'} = $settings->{'font'};
1459: $is_custom{'font'} = 1;
1460: }
1461: foreach my $item (@bgs) {
1462: if ($settings->{$item} ne '') {
1463: $designs{'bgs'}{$item} = $settings->{$item};
1464: $is_custom{$item} = 1;
1465: }
1466: }
1467: foreach my $item (@links) {
1468: if ($settings->{$item} ne '') {
1469: $designs{'links'}{$item} = $settings->{$item};
1470: $is_custom{$item} = 1;
1471: }
1472: }
1473: } else {
1474: if ($designhash{$dom.'.login.font'} ne '') {
1475: $designs{'font'} = $designhash{$dom.'.login.font'};
1476: $is_custom{'font'} = 1;
1477: }
1478: foreach my $item (@images) {
1479: if ($designhash{$dom.'.login.'.$item} ne '') {
1480: $designs{$item} = $designhash{$dom.'.login.'.$item};
1481: $is_custom{$item} = 1;
1482: }
1483: }
1484: foreach my $item (@bgs) {
1485: if ($designhash{$dom.'.login.'.$item} ne '') {
1486: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1487: $is_custom{$item} = 1;
1488: }
1.6 raeburn 1489: }
1.168 raeburn 1490: foreach my $item (@links) {
1491: if ($designhash{$dom.'.login.'.$item} ne '') {
1492: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1493: $is_custom{$item} = 1;
1494: }
1.6 raeburn 1495: }
1496: }
1.168 raeburn 1497: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1498: logo => 'Institution Logo',
1499: domlogo => 'Domain Logo',
1500: login => 'Login box');
1501: my $itemcount = 1;
1502: foreach my $item (@toggles) {
1503: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1504: $datatable .=
1505: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1506: '</td><td>'.
1507: '<span class="LC_nobreak"><label><input type="radio" name="'.
1508: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1509: '</label> <label><input type="radio" name="'.$item.'"'.
1510: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1511: '</tr>';
1512: $itemcount ++;
1.6 raeburn 1513: }
1.168 raeburn 1514: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1515: $datatable .= '</tr></table></td></tr>';
1516: } elsif ($caller eq 'help') {
1.386 raeburn 1517: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1518: my $itemcount = 1;
1519: $defaulturl = '/adm/loginproblems.html';
1520: $defaulttype = 'default';
1521: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1522: my @currlangs;
1523: if (ref($settings) eq 'HASH') {
1524: if (ref($settings->{'helpurl'}) eq 'HASH') {
1525: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1526: next if ($settings->{'helpurl'}{$key} eq '');
1527: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1528: $type{$key} = 'custom';
1529: unless ($key eq 'nolang') {
1530: push(@currlangs,$key);
1531: }
1532: }
1533: } elsif ($settings->{'helpurl'} ne '') {
1534: $type{'nolang'} = 'custom';
1535: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1536: }
1537: }
1.168 raeburn 1538: foreach my $lang ('nolang',sort(@currlangs)) {
1539: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1540: $datatable .= '<tr'.$css_class.'>';
1541: if ($url{$lang} eq '') {
1542: $url{$lang} = $defaulturl;
1543: }
1544: if ($type{$lang} eq '') {
1545: $type{$lang} = $defaulttype;
1546: }
1547: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1548: if ($lang eq 'nolang') {
1549: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1550: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1551: } else {
1552: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1553: $langchoices{$lang},
1554: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1555: }
1556: $datatable .= '</span></td>'."\n".
1557: '<td class="LC_left_item">';
1558: if ($type{$lang} eq 'custom') {
1559: $datatable .= '<span class="LC_nobreak"><label>'.
1560: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1561: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1562: } else {
1563: $datatable .= $lt{'upl'};
1564: }
1565: $datatable .='<br />';
1566: if ($switchserver) {
1567: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1568: } else {
1569: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1570: }
1.168 raeburn 1571: $datatable .= '</td></tr>';
1572: $itemcount ++;
1.6 raeburn 1573: }
1.168 raeburn 1574: my @addlangs;
1575: foreach my $lang (sort(keys(%langchoices))) {
1576: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1577: push(@addlangs,$lang);
1578: }
1579: if (@addlangs > 0) {
1580: my %toadd;
1581: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1582: $toadd{''} = &mt('Select');
1583: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1584: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1585: &mt('Add log-in help page for a specific language:').' '.
1586: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1587: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1588: if ($switchserver) {
1589: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1590: } else {
1591: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1592: }
1.168 raeburn 1593: $datatable .= '</td></tr>';
1.169 raeburn 1594: $itemcount ++;
1.6 raeburn 1595: }
1.169 raeburn 1596: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1597: } elsif ($caller eq 'headtag') {
1598: my %domservers = &Apache::lonnet::get_servers($dom);
1599: my $choice = $choices{'headtag'};
1600: $css_class = ' class="LC_odd_row"';
1601: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1602: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1603: '<th>'.$choices{'current'}.'</th>'.
1604: '<th>'.$choices{'action'}.'</th>'.
1605: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1606: my (%currurls,%currexempt);
1607: if (ref($settings) eq 'HASH') {
1608: if (ref($settings->{'headtag'}) eq 'HASH') {
1609: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1610: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1611: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1612: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1613: }
1614: }
1615: }
1616: }
1617: foreach my $lonhost (sort(keys(%domservers))) {
1618: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1619: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1620: if ($currurls{$lonhost}) {
1621: $datatable .= '<td class="LC_right_item"><a href="'.
1622: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1623: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1624: '">'.$lt{'curr'}.'</a></td>'.
1625: '<td><span class="LC_nobreak"><label>'.
1626: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1627: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1628: } else {
1629: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1630: }
1631: $datatable .='<br />';
1632: if ($switchserver) {
1633: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1634: } else {
1635: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1636: }
1.330 raeburn 1637: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1638: }
1639: $datatable .= '</table></td></tr>';
1.386 raeburn 1640: } elsif ($caller eq 'saml') {
1641: my %domservers = &Apache::lonnet::get_servers($dom);
1642: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1643: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1644: '<th>'.$choices{'samllanding'}.'</th>'.
1645: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1646: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1647: foreach my $lonhost (keys(%domservers)) {
1648: $samlurl{$lonhost} = '/adm/sso';
1649: $styleon{$lonhost} = 'display:none';
1650: $styleoff{$lonhost} = '';
1651: }
1.411 raeburn 1652: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1653: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1654: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1655: $saml{$lonhost} = 1;
1656: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1657: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1658: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1659: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1660: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1661: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1662: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1663: $styleon{$lonhost} = '';
1664: $styleoff{$lonhost} = 'display:none';
1665: } else {
1666: $styleon{$lonhost} = 'display:none';
1667: $styleoff{$lonhost} = '';
1668: }
1669: }
1670: }
1671: my $itemcount = 1;
1672: foreach my $lonhost (sort(keys(%domservers))) {
1673: my $samlon = ' ';
1674: my $samloff = ' checked="checked" ';
1675: if ($saml{$lonhost}) {
1676: $samlon = $samloff;
1677: $samloff = ' ';
1678: }
1.412 raeburn 1679: my $samlwinon = '';
1680: my $samlwinoff = ' checked="checked"';
1681: if ($samlwindow{$lonhost}) {
1682: $samlwinon = $samlwinoff;
1683: $samlwinoff = '';
1684: }
1.386 raeburn 1685: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1686: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1687: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1688: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1689: &mt('No').'</label>'.(' 'x2).
1690: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1691: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1692: &mt('Yes').'</label></span></td>'.
1693: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1694: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1695: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1696: '<th>'.&mt('Alt Text').'</th></tr>'.
1697: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1698: $samltext{$lonhost}.'" /></td><td>';
1699: if ($samlimg{$lonhost}) {
1700: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1701: '<span class="LC_nobreak"><label>'.
1702: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1703: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1704: } else {
1705: $datatable .= $lt{'upl'};
1706: }
1707: $datatable .='<br />';
1708: if ($switchserver) {
1709: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1710: } else {
1711: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1712: }
1713: $datatable .= '</td>'.
1.412 raeburn 1714: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1715: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1716: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1717: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1718: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1719: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1720: '<tr'.$css_class.'>'.
1721: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1722: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1723: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1724: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1725: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1726: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1727: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1728: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1729: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1730: '</table></td>'.
1731: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1732: $itemcount ++;
1733: }
1734: $datatable .= '</table></td></tr>';
1.1 raeburn 1735: }
1.6 raeburn 1736: return $datatable;
1737: }
1738:
1739: sub login_choices {
1740: my %choices =
1741: &Apache::lonlocal::texthash (
1.116 bisitz 1742: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1743: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1744: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1745: disallowlogin => "Login page requests redirected",
1746: hostid => "Server",
1.128 raeburn 1747: server => "Redirect to:",
1748: serverpath => "Path",
1749: custompath => "Custom",
1750: exempt => "Exempt IP(s)",
1.110 raeburn 1751: directlogin => "No redirect",
1752: newuser => "Link to create a user account",
1753: img => "Header",
1754: logo => "Main Logo",
1755: domlogo => "Domain Logo",
1756: login => "Log-in Header",
1757: textcol => "Text color",
1758: bgcol => "Box color",
1759: bgs => "Background colors",
1760: links => "Link colors",
1761: font => "Font color",
1762: pgbg => "Header",
1763: mainbg => "Page",
1764: sidebg => "Login box",
1765: link => "Link",
1766: alink => "Active link",
1767: vlink => "Visited link",
1.256 raeburn 1768: headtag => "Custom markup",
1769: action => "Action",
1770: current => "Current",
1.386 raeburn 1771: samllanding => "Dual login?",
1772: samloptions => "Options",
1.402 raeburn 1773: alttext => "Alt text",
1.6 raeburn 1774: );
1775: return %choices;
1776: }
1777:
1.386 raeburn 1778: sub login_file_options {
1779: return &Apache::lonlocal::texthash(
1780: del => 'Delete?',
1781: rep => 'Replace:',
1782: upl => 'Upload:',
1783: curr => 'View contents',
1784: default => 'Default',
1785: custom => 'Custom',
1786: none => 'None',
1787: );
1788: }
1789:
1.394 raeburn 1790: sub print_ipaccess {
1791: my ($dom,$settings,$rowtotal) = @_;
1792: my $css_class;
1793: my $itemcount = 0;
1794: my $datatable;
1795: my %ordered;
1796: if (ref($settings) eq 'HASH') {
1797: foreach my $item (keys(%{$settings})) {
1798: if (ref($settings->{$item}) eq 'HASH') {
1799: my $num = $settings->{$item}{'order'};
1800: if ($num eq '') {
1801: $num = scalar(keys(%{$settings}));
1802: }
1803: $ordered{$num} = $item;
1804: }
1805: }
1806: }
1807: my $maxnum = scalar(keys(%ordered));
1808: if (keys(%ordered)) {
1809: my @items = sort { $a <=> $b } keys(%ordered);
1810: for (my $i=0; $i<@items; $i++) {
1811: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1812: my $item = $ordered{$items[$i]};
1813: my ($name,$ipranges,%commblocks,%courses);
1814: if (ref($settings->{$item}) eq 'HASH') {
1815: $name = $settings->{$item}->{'name'};
1816: $ipranges = $settings->{$item}->{'ip'};
1817: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1818: %commblocks = %{$settings->{$item}->{'commblocks'}};
1819: }
1820: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1821: %courses = %{$settings->{$item}->{'courses'}};
1822: }
1823: }
1824: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1825: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1826: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1827: for (my $k=0; $k<=$maxnum; $k++) {
1828: my $vpos = $k+1;
1829: my $selstr;
1830: if ($k == $i) {
1831: $selstr = ' selected="selected" ';
1832: }
1833: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1834: }
1835: $datatable .= '</select>'.(' 'x2).
1836: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1837: &mt('Delete?').'</label></span></td>'.
1838: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1839: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1840: '</td></tr>';
1841: $itemcount ++;
1842: }
1843: }
1844: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1845: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1846: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1847: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1848: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1849: for (my $k=0; $k<$maxnum+1; $k++) {
1850: my $vpos = $k+1;
1851: my $selstr;
1852: if ($k == $maxnum) {
1853: $selstr = ' selected="selected" ';
1854: }
1855: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1856: }
1857: $datatable .= '</select> '."\n".
1858: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1859: '<td colspan="2">'.
1860: &ipaccess_options('add',$itemcount,$dom).
1861: '</td>'."\n".
1862: '</tr>'."\n";
1863: $$rowtotal ++;
1864: return $datatable;
1865: }
1866:
1867: sub ipaccess_options {
1868: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1869: my (%currblocks,%currcourses,$output);
1870: if (ref($blocksref) eq 'HASH') {
1871: %currblocks = %{$blocksref};
1872: }
1873: if (ref($coursesref) eq 'HASH') {
1874: %currcourses = %{$coursesref};
1875: }
1876: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1877: '<span class="LC_nobreak">'.&mt('Name').': '.
1878: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1879: '</span></fieldset>'.
1880: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1881: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1882: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1883: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1884: $ipranges.'</textarea></fieldset>'.
1885: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1886: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1887: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1888: '<table>';
1889: foreach my $cid (sort(keys(%currcourses))) {
1890: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1891: $output .= '<tr><td><span class="LC_nobreak">'.
1892: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1893: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1894: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1895: }
1896: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1897: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1898: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1899: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1900: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1901: '</span></td></tr></table>'."\n".
1902: '</fieldset>';
1903: return $output;
1904: }
1905:
1906: sub blocker_checkboxes {
1907: my ($num,$blocks) = @_;
1908: my ($typeorder,$types) = &commblocktype_text();
1909: my $numinrow = 6;
1910: my $output = '<table>';
1911: for (my $i=0; $i<@{$typeorder}; $i++) {
1912: my $block = $typeorder->[$i];
1913: my $blockstatus;
1914: if (ref($blocks) eq 'HASH') {
1915: if ($blocks->{$block} eq 'on') {
1916: $blockstatus = 'checked="checked"';
1917: }
1918: }
1919: my $rem = $i%($numinrow);
1920: if ($rem == 0) {
1921: if ($i > 0) {
1922: $output .= '</tr>';
1923: }
1924: $output .= '<tr>';
1925: }
1926: if ($i == scalar(@{$typeorder})-1) {
1927: my $colsleft = $numinrow-$rem;
1928: if ($colsleft > 1) {
1929: $output .= '<td colspan="'.$colsleft.'">';
1930: } else {
1931: $output .= '<td>';
1932: }
1933: } else {
1934: $output .= '<td>';
1935: }
1936: my $item = 'ipaccess_block_'.$num;
1937: if ($blockstatus) {
1938: $blockstatus = ' '.$blockstatus;
1939: }
1940: $output .= '<span class="LC_nobreak"><label>'."\n".
1941: '<input type="checkbox" name="'.$item.'"'.
1942: $blockstatus.' value="'.$block.'"'.' />'.
1943: $types->{$block}.'</label></span>'."\n".
1944: '<br /></td>';
1945: }
1946: $output .= '</tr></table>';
1947: return $output;
1948: }
1949:
1950: sub commblocktype_text {
1951: my %types = &Apache::lonlocal::texthash(
1952: 'com' => 'Messaging',
1953: 'chat' => 'Chat Room',
1954: 'boards' => 'Discussion',
1955: 'port' => 'Portfolio',
1956: 'groups' => 'Groups',
1957: 'blogs' => 'Blogs',
1958: 'about' => 'User Information',
1959: 'printout' => 'Printouts',
1960: 'passwd' => 'Change Password',
1961: 'grades' => 'Gradebook',
1.397 raeburn 1962: 'search' => 'Course search',
1963: 'wishlist' => 'Stored links',
1964: 'annotate' => 'Annotations',
1.394 raeburn 1965: );
1.397 raeburn 1966: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1967: return ($typeorder,\%types);
1968: }
1969:
1.6 raeburn 1970: sub print_rolecolors {
1.30 raeburn 1971: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1972: my %choices = &color_font_choices();
1973: my @bgs = ('pgbg','tabbg','sidebg');
1974: my @links = ('link','alink','vlink');
1975: my @images = ('img');
1976: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1977: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1978: my %defaultdesign = %Apache::loncommon::defaultdesign;
1979: my (%is_custom,%designs);
1.200 raeburn 1980: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1981: if (ref($settings) eq 'HASH') {
1982: if (ref($settings->{$role}) eq 'HASH') {
1983: if ($settings->{$role}->{'img'} ne '') {
1984: $designs{'img'} = $settings->{$role}->{'img'};
1985: $is_custom{'img'} = 1;
1986: }
1987: if ($settings->{$role}->{'font'} ne '') {
1988: $designs{'font'} = $settings->{$role}->{'font'};
1989: $is_custom{'font'} = 1;
1990: }
1.97 tempelho 1991: if ($settings->{$role}->{'fontmenu'} ne '') {
1992: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1993: $is_custom{'fontmenu'} = 1;
1994: }
1.6 raeburn 1995: foreach my $item (@bgs) {
1996: if ($settings->{$role}->{$item} ne '') {
1997: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1998: $is_custom{$item} = 1;
1999: }
2000: }
2001: foreach my $item (@links) {
2002: if ($settings->{$role}->{$item} ne '') {
2003: $designs{'links'}{$item} = $settings->{$role}->{$item};
2004: $is_custom{$item} = 1;
2005: }
2006: }
2007: }
2008: } else {
2009: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2010: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2011: $is_custom{'img'} = 1;
2012: }
1.97 tempelho 2013: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2014: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2015: $is_custom{'fontmenu'} = 1;
2016: }
1.6 raeburn 2017: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2018: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2019: $is_custom{'font'} = 1;
2020: }
2021: foreach my $item (@bgs) {
2022: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2023: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2024: $is_custom{$item} = 1;
2025:
2026: }
2027: }
2028: foreach my $item (@links) {
2029: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2030: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2031: $is_custom{$item} = 1;
2032: }
2033: }
2034: }
2035: my $itemcount = 1;
1.30 raeburn 2036: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2037: $datatable .= '</tr></table></td></tr>';
2038: return $datatable;
2039: }
2040:
1.200 raeburn 2041: sub role_defaults {
2042: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2043: my %defaults;
2044: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2045: return %defaults;
2046: }
2047: my %defaultdesign = %Apache::loncommon::defaultdesign;
2048: if ($role eq 'login') {
2049: %defaults = (
2050: font => $defaultdesign{$role.'.font'},
2051: );
2052: if (ref($logintext) eq 'ARRAY') {
2053: foreach my $item (@{$logintext}) {
2054: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2055: }
2056: }
2057: foreach my $item (@{$images}) {
2058: $defaults{'showlogo'}{$item} = 1;
2059: }
2060: } else {
2061: %defaults = (
2062: img => $defaultdesign{$role.'.img'},
2063: font => $defaultdesign{$role.'.font'},
2064: fontmenu => $defaultdesign{$role.'.fontmenu'},
2065: );
2066: }
2067: foreach my $item (@{$bgs}) {
2068: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2069: }
2070: foreach my $item (@{$links}) {
2071: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2072: }
2073: foreach my $item (@{$images}) {
2074: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2075: }
2076: return %defaults;
2077: }
2078:
1.6 raeburn 2079: sub display_color_options {
1.9 raeburn 2080: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2081: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2082: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2083: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2084: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2085: '<td>'.$choices->{'font'}.'</td>';
2086: if (!$is_custom->{'font'}) {
1.329 raeburn 2087: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2088: } else {
2089: $datatable .= '<td> </td>';
2090: }
1.174 foxr 2091: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2092:
1.8 raeburn 2093: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2094: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2095: ' value="'.$current_color.'" /> '.
1.329 raeburn 2096: ' </span></td></tr>';
1.107 raeburn 2097: unless ($role eq 'login') {
2098: $datatable .= '<tr'.$css_class.'>'.
2099: '<td>'.$choices->{'fontmenu'}.'</td>';
2100: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2101: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2102: } else {
2103: $datatable .= '<td> </td>';
2104: }
1.202 raeburn 2105: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2106: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2107: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2108: '<input class="colorchooser" type="text" size="10" name="'
2109: .$role.'_fontmenu"'.
2110: ' value="'.$current_color.'" /> '.
1.329 raeburn 2111: ' </span></td></tr>';
1.97 tempelho 2112: }
1.9 raeburn 2113: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2114: foreach my $img (@{$images}) {
1.18 albertel 2115: $itemcount ++;
1.6 raeburn 2116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2117: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2118: '<td>'.$choices->{$img};
1.402 raeburn 2119: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2120: if ($role eq 'login') {
2121: if ($img eq 'login') {
2122: $login_hdr_pick =
1.135 bisitz 2123: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2124: $logincolors =
2125: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2126: $designs,$defaults);
1.402 raeburn 2127: } else {
2128: if ($img ne 'domlogo') {
2129: $datatable.= &logo_display_options($img,$defaults,$designs);
2130: }
2131: if (ref($designs->{'alttext'}) eq 'HASH') {
2132: $alttext = $designs->{'alttext'}{$img};
2133: }
1.70 raeburn 2134: }
2135: }
2136: $datatable .= '</td>';
1.6 raeburn 2137: if ($designs->{$img} ne '') {
2138: $imgfile = $designs->{$img};
1.18 albertel 2139: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2140: } else {
2141: $imgfile = $defaults->{$img};
2142: }
2143: if ($imgfile) {
1.9 raeburn 2144: my ($showfile,$fullsize);
2145: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2146: my $urldir = $1;
2147: my $filename = $2;
2148: my @info = &Apache::lonnet::stat_file($designs->{$img});
2149: if (@info) {
2150: my $thumbfile = 'tn-'.$filename;
2151: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2152: if (@thumb) {
2153: $showfile = $urldir.'/'.$thumbfile;
2154: } else {
2155: $showfile = $imgfile;
2156: }
2157: } else {
2158: $showfile = '';
2159: }
2160: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2161: $showfile = $imgfile;
1.6 raeburn 2162: my $imgdir = $1;
2163: my $filename = $2;
1.159 raeburn 2164: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2165: $showfile = "/$imgdir/tn-".$filename;
2166: } else {
1.159 raeburn 2167: my $input = $londocroot.$imgfile;
2168: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2169: if (!-e $output) {
1.9 raeburn 2170: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2171: my ($fullwidth,$fullheight) = &check_dimensions($input);
2172: if ($fullwidth ne '' && $fullheight ne '') {
2173: if ($fullwidth > $width && $fullheight > $height) {
2174: my $size = $width.'x'.$height;
1.316 raeburn 2175: my @args = ('convert','-sample',$size,$input,$output);
2176: system({$args[0]} @args);
1.159 raeburn 2177: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2178: }
2179: }
1.6 raeburn 2180: }
2181: }
1.16 raeburn 2182: }
1.6 raeburn 2183: if ($showfile) {
1.40 raeburn 2184: if ($showfile =~ m{^/(adm|res)/}) {
2185: if ($showfile =~ m{^/res/}) {
2186: my $local_showfile =
2187: &Apache::lonnet::filelocation('',$showfile);
2188: &Apache::lonnet::repcopy($local_showfile);
2189: }
2190: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2191: }
2192: if ($imgfile) {
2193: if ($imgfile =~ m{^/(adm|res)/}) {
2194: if ($imgfile =~ m{^/res/}) {
2195: my $local_imgfile =
2196: &Apache::lonnet::filelocation('',$imgfile);
2197: &Apache::lonnet::repcopy($local_imgfile);
2198: }
2199: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2200: } else {
2201: $fullsize = $imgfile;
2202: }
2203: }
1.41 raeburn 2204: $datatable .= '<td>';
2205: if ($img eq 'login') {
1.135 bisitz 2206: $datatable .= $login_hdr_pick;
2207: }
1.41 raeburn 2208: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2209: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2210: } else {
1.201 raeburn 2211: $datatable .= '<td> </td><td class="LC_left_item">'.
2212: &mt('Upload:').'<br />';
1.6 raeburn 2213: }
2214: } else {
1.201 raeburn 2215: $datatable .= '<td> </td><td class="LC_left_item">'.
2216: &mt('Upload:').'<br />';
1.6 raeburn 2217: }
1.9 raeburn 2218: if ($switchserver) {
2219: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2220: } else {
1.135 bisitz 2221: if ($img ne 'login') { # suppress file selection for Log-in header
2222: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2223: }
1.9 raeburn 2224: }
1.402 raeburn 2225: if (($role eq 'login') && ($img ne 'login')) {
2226: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2227: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2228: '</label></span>';
2229: }
1.9 raeburn 2230: $datatable .= '</td></tr>';
1.6 raeburn 2231: }
2232: $itemcount ++;
2233: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2234: $datatable .= '<tr'.$css_class.'>'.
2235: '<td>'.$choices->{'bgs'}.'</td>';
2236: my $bgs_def;
2237: foreach my $item (@{$bgs}) {
2238: if (!$is_custom->{$item}) {
1.329 raeburn 2239: $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 2240: }
2241: }
2242: if ($bgs_def) {
1.8 raeburn 2243: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2244: } else {
2245: $datatable .= '<td> </td>';
2246: }
2247: $datatable .= '<td class="LC_right_item">'.
2248: '<table border="0"><tr>';
1.174 foxr 2249:
1.6 raeburn 2250: foreach my $item (@{$bgs}) {
1.306 raeburn 2251: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2252: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2253: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2254: $datatable .= ' ';
1.6 raeburn 2255: }
1.174 foxr 2256: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2257: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2258: }
2259: $datatable .= '</tr></table></td></tr>';
2260: $itemcount ++;
2261: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2262: $datatable .= '<tr'.$css_class.'>'.
2263: '<td>'.$choices->{'links'}.'</td>';
2264: my $links_def;
2265: foreach my $item (@{$links}) {
2266: if (!$is_custom->{$item}) {
1.329 raeburn 2267: $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 2268: }
2269: }
2270: if ($links_def) {
1.8 raeburn 2271: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2272: } else {
2273: $datatable .= '<td> </td>';
2274: }
2275: $datatable .= '<td class="LC_right_item">'.
2276: '<table border="0"><tr>';
2277: foreach my $item (@{$links}) {
1.234 raeburn 2278: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2279: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2280: if ($designs->{'links'}{$item}) {
1.174 foxr 2281: $datatable.=' ';
1.6 raeburn 2282: }
1.174 foxr 2283: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2284: '" /></td>';
2285: }
1.30 raeburn 2286: $$rowtotal += $itemcount;
1.3 raeburn 2287: return $datatable;
2288: }
2289:
1.70 raeburn 2290: sub logo_display_options {
2291: my ($img,$defaults,$designs) = @_;
2292: my $checkedon;
2293: if (ref($defaults) eq 'HASH') {
2294: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2295: if ($defaults->{'showlogo'}{$img}) {
2296: $checkedon = 'checked="checked" ';
2297: }
2298: }
2299: }
2300: if (ref($designs) eq 'HASH') {
2301: if (ref($designs->{'showlogo'}) eq 'HASH') {
2302: if (defined($designs->{'showlogo'}{$img})) {
2303: if ($designs->{'showlogo'}{$img} == 0) {
2304: $checkedon = '';
2305: } elsif ($designs->{'showlogo'}{$img} == 1) {
2306: $checkedon = 'checked="checked" ';
2307: }
2308: }
2309: }
2310: }
2311: return '<br /><label> <input type="checkbox" name="'.
2312: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2313: &mt('show').'</label>'."\n";
2314: }
2315:
1.41 raeburn 2316: sub login_header_options {
1.135 bisitz 2317: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2318: my $output = '';
1.41 raeburn 2319: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2320: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2321: if (!$is_custom->{'textcol'}) {
2322: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2323: ' ';
2324: }
2325: if (!$is_custom->{'bgcol'}) {
2326: $output .= $choices->{'bgcol'}.': '.
2327: '<span id="css_'.$role.'_font" style="background-color: '.
2328: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2329: }
2330: $output .= '<br />';
2331: }
2332: $output .='<br />';
2333: return $output;
2334: }
2335:
2336: sub login_text_colors {
1.201 raeburn 2337: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2338: my $color_menu = '<table border="0"><tr>';
2339: foreach my $item (@{$logintext}) {
1.306 raeburn 2340: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2341: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2342: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2343: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2344: }
2345: $color_menu .= '</tr></table><br />';
2346: return $color_menu;
2347: }
2348:
2349: sub image_changes {
2350: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2351: my $output;
1.135 bisitz 2352: if ($img eq 'login') {
1.331 raeburn 2353: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2354: } elsif (!$is_custom) {
1.70 raeburn 2355: if ($img ne 'domlogo') {
1.331 raeburn 2356: $output = &mt('Default image:').'<br />';
1.41 raeburn 2357: } else {
1.331 raeburn 2358: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2359: }
2360: }
1.331 raeburn 2361: if ($img ne 'login') {
1.135 bisitz 2362: if ($img_import) {
2363: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2364: }
2365: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2366: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2367: if ($is_custom) {
2368: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2369: '<input type="checkbox" name="'.
2370: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2371: '</label> '.&mt('Replace:').'</span><br />';
2372: } else {
1.306 raeburn 2373: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2374: }
1.41 raeburn 2375: }
2376: return $output;
2377: }
2378:
1.3 raeburn 2379: sub print_quotas {
1.86 raeburn 2380: my ($dom,$settings,$rowtotal,$action) = @_;
2381: my $context;
2382: if ($action eq 'quotas') {
2383: $context = 'tools';
2384: } else {
2385: $context = $action;
2386: }
1.197 raeburn 2387: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2388: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2389: my $typecount = 0;
1.101 raeburn 2390: my ($css_class,%titles);
1.86 raeburn 2391: if ($context eq 'requestcourses') {
1.325 raeburn 2392: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2393: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2394: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2395: %titles = &courserequest_titles();
1.163 raeburn 2396: } elsif ($context eq 'requestauthor') {
2397: @usertools = ('author');
2398: @options = ('norequest','approval','automatic');
1.210 raeburn 2399: %titles = &authorrequest_titles();
1.86 raeburn 2400: } else {
1.413 raeburn 2401: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2402: %titles = &tool_titles();
1.86 raeburn 2403: }
1.26 raeburn 2404: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2405: foreach my $type (@{$types}) {
1.197 raeburn 2406: my ($currdefquota,$currauthorquota);
1.163 raeburn 2407: unless (($context eq 'requestcourses') ||
2408: ($context eq 'requestauthor')) {
1.86 raeburn 2409: if (ref($settings) eq 'HASH') {
2410: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2411: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2412: } else {
2413: $currdefquota = $settings->{$type};
2414: }
1.197 raeburn 2415: if (ref($settings->{authorquota}) eq 'HASH') {
2416: $currauthorquota = $settings->{authorquota}->{$type};
2417: }
1.78 raeburn 2418: }
1.72 raeburn 2419: }
1.3 raeburn 2420: if (defined($usertypes->{$type})) {
2421: $typecount ++;
2422: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2423: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2424: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2425: '<td class="LC_left_item">';
1.101 raeburn 2426: if ($context eq 'requestcourses') {
2427: $datatable .= '<table><tr>';
2428: }
2429: my %cell;
1.72 raeburn 2430: foreach my $item (@usertools) {
1.101 raeburn 2431: if ($context eq 'requestcourses') {
2432: my ($curroption,$currlimit);
2433: if (ref($settings) eq 'HASH') {
2434: if (ref($settings->{$item}) eq 'HASH') {
2435: $curroption = $settings->{$item}->{$type};
2436: if ($curroption =~ /^autolimit=(\d*)$/) {
2437: $currlimit = $1;
2438: }
2439: }
2440: }
2441: if (!$curroption) {
2442: $curroption = 'norequest';
2443: }
2444: $datatable .= '<th>'.$titles{$item}.'</th>';
2445: foreach my $option (@options) {
2446: my $val = $option;
2447: if ($option eq 'norequest') {
2448: $val = 0;
2449: }
2450: if ($option eq 'validate') {
2451: my $canvalidate = 0;
2452: if (ref($validations{$item}) eq 'HASH') {
2453: if ($validations{$item}{$type}) {
2454: $canvalidate = 1;
2455: }
2456: }
2457: next if (!$canvalidate);
2458: }
2459: my $checked = '';
2460: if ($option eq $curroption) {
2461: $checked = ' checked="checked"';
2462: } elsif ($option eq 'autolimit') {
2463: if ($curroption =~ /^autolimit/) {
2464: $checked = ' checked="checked"';
2465: }
2466: }
2467: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2468: '<input type="radio" name="crsreq_'.$item.
2469: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2470: $titles{$option}.'</label>';
1.101 raeburn 2471: if ($option eq 'autolimit') {
1.127 raeburn 2472: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2473: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2474: 'value="'.$currlimit.'" />';
1.101 raeburn 2475: }
1.127 raeburn 2476: $cell{$item} .= '</span> ';
1.103 raeburn 2477: if ($option eq 'autolimit') {
1.127 raeburn 2478: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2479: }
1.101 raeburn 2480: }
1.163 raeburn 2481: } elsif ($context eq 'requestauthor') {
2482: my $curroption;
2483: if (ref($settings) eq 'HASH') {
2484: $curroption = $settings->{$type};
2485: }
2486: if (!$curroption) {
2487: $curroption = 'norequest';
2488: }
2489: foreach my $option (@options) {
2490: my $val = $option;
2491: if ($option eq 'norequest') {
2492: $val = 0;
2493: }
2494: my $checked = '';
2495: if ($option eq $curroption) {
2496: $checked = ' checked="checked"';
2497: }
2498: $datatable .= '<span class="LC_nobreak"><label>'.
2499: '<input type="radio" name="authorreq_'.$type.
2500: '" value="'.$val.'"'.$checked.' />'.
2501: $titles{$option}.'</label></span> ';
2502: }
1.101 raeburn 2503: } else {
2504: my $checked = 'checked="checked" ';
1.413 raeburn 2505: if ($item eq 'timezone') {
2506: $checked = '';
2507: }
1.101 raeburn 2508: if (ref($settings) eq 'HASH') {
2509: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2510: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2511: $checked = '';
2512: } elsif ($settings->{$item}->{$type} == 1) {
2513: $checked = 'checked="checked" ';
2514: }
1.78 raeburn 2515: }
1.72 raeburn 2516: }
1.101 raeburn 2517: $datatable .= '<span class="LC_nobreak"><label>'.
2518: '<input type="checkbox" name="'.$context.'_'.$item.
2519: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2520: '</label></span> ';
1.72 raeburn 2521: }
1.101 raeburn 2522: }
2523: if ($context eq 'requestcourses') {
2524: $datatable .= '</tr><tr>';
2525: foreach my $item (@usertools) {
1.106 raeburn 2526: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2527: }
2528: $datatable .= '</tr></table>';
1.72 raeburn 2529: }
1.86 raeburn 2530: $datatable .= '</td>';
1.163 raeburn 2531: unless (($context eq 'requestcourses') ||
2532: ($context eq 'requestauthor')) {
1.86 raeburn 2533: $datatable .=
1.197 raeburn 2534: '<td class="LC_right_item">'.
2535: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2536: '<input type="text" name="quota_'.$type.
1.72 raeburn 2537: '" value="'.$currdefquota.
1.197 raeburn 2538: '" size="5" /></span>'.(' ' x 2).
2539: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2540: '<input type="text" name="authorquota_'.$type.
2541: '" value="'.$currauthorquota.
2542: '" size="5" /></span></td>';
1.86 raeburn 2543: }
2544: $datatable .= '</tr>';
1.3 raeburn 2545: }
2546: }
2547: }
1.163 raeburn 2548: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2549: $defaultquota = '20';
1.197 raeburn 2550: $authorquota = '500';
1.86 raeburn 2551: if (ref($settings) eq 'HASH') {
2552: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2553: $defaultquota = $settings->{'defaultquota'}->{'default'};
2554: } elsif (defined($settings->{'default'})) {
2555: $defaultquota = $settings->{'default'};
2556: }
1.197 raeburn 2557: if (ref($settings->{'authorquota'}) eq 'HASH') {
2558: $authorquota = $settings->{'authorquota'}->{'default'};
2559: }
1.3 raeburn 2560: }
2561: }
2562: $typecount ++;
2563: $css_class = $typecount%2?' class="LC_odd_row"':'';
2564: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2565: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2566: '<td class="LC_left_item">';
1.101 raeburn 2567: if ($context eq 'requestcourses') {
2568: $datatable .= '<table><tr>';
2569: }
2570: my %defcell;
1.72 raeburn 2571: foreach my $item (@usertools) {
1.101 raeburn 2572: if ($context eq 'requestcourses') {
2573: my ($curroption,$currlimit);
2574: if (ref($settings) eq 'HASH') {
2575: if (ref($settings->{$item}) eq 'HASH') {
2576: $curroption = $settings->{$item}->{'default'};
2577: if ($curroption =~ /^autolimit=(\d*)$/) {
2578: $currlimit = $1;
2579: }
2580: }
2581: }
2582: if (!$curroption) {
2583: $curroption = 'norequest';
2584: }
2585: $datatable .= '<th>'.$titles{$item}.'</th>';
2586: foreach my $option (@options) {
2587: my $val = $option;
2588: if ($option eq 'norequest') {
2589: $val = 0;
2590: }
2591: if ($option eq 'validate') {
2592: my $canvalidate = 0;
2593: if (ref($validations{$item}) eq 'HASH') {
2594: if ($validations{$item}{'default'}) {
2595: $canvalidate = 1;
2596: }
2597: }
2598: next if (!$canvalidate);
2599: }
2600: my $checked = '';
2601: if ($option eq $curroption) {
2602: $checked = ' checked="checked"';
2603: } elsif ($option eq 'autolimit') {
2604: if ($curroption =~ /^autolimit/) {
2605: $checked = ' checked="checked"';
2606: }
2607: }
2608: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2609: '<input type="radio" name="crsreq_'.$item.
2610: '_default" value="'.$val.'"'.$checked.' />'.
2611: $titles{$option}.'</label>';
2612: if ($option eq 'autolimit') {
1.127 raeburn 2613: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2614: $item.'_limit_default" size="1" '.
2615: 'value="'.$currlimit.'" />';
2616: }
1.127 raeburn 2617: $defcell{$item} .= '</span> ';
1.104 raeburn 2618: if ($option eq 'autolimit') {
1.127 raeburn 2619: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2620: }
1.101 raeburn 2621: }
1.163 raeburn 2622: } elsif ($context eq 'requestauthor') {
2623: my $curroption;
2624: if (ref($settings) eq 'HASH') {
1.172 raeburn 2625: $curroption = $settings->{'default'};
1.163 raeburn 2626: }
2627: if (!$curroption) {
2628: $curroption = 'norequest';
2629: }
2630: foreach my $option (@options) {
2631: my $val = $option;
2632: if ($option eq 'norequest') {
2633: $val = 0;
2634: }
2635: my $checked = '';
2636: if ($option eq $curroption) {
2637: $checked = ' checked="checked"';
2638: }
2639: $datatable .= '<span class="LC_nobreak"><label>'.
2640: '<input type="radio" name="authorreq_default"'.
2641: ' value="'.$val.'"'.$checked.' />'.
2642: $titles{$option}.'</label></span> ';
2643: }
1.101 raeburn 2644: } else {
2645: my $checked = 'checked="checked" ';
2646: if (ref($settings) eq 'HASH') {
2647: if (ref($settings->{$item}) eq 'HASH') {
2648: if ($settings->{$item}->{'default'} == 0) {
2649: $checked = '';
2650: } elsif ($settings->{$item}->{'default'} == 1) {
2651: $checked = 'checked="checked" ';
2652: }
1.78 raeburn 2653: }
1.72 raeburn 2654: }
1.101 raeburn 2655: $datatable .= '<span class="LC_nobreak"><label>'.
2656: '<input type="checkbox" name="'.$context.'_'.$item.
2657: '" value="default" '.$checked.'/>'.$titles{$item}.
2658: '</label></span> ';
2659: }
2660: }
2661: if ($context eq 'requestcourses') {
2662: $datatable .= '</tr><tr>';
2663: foreach my $item (@usertools) {
1.106 raeburn 2664: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2665: }
1.101 raeburn 2666: $datatable .= '</tr></table>';
1.72 raeburn 2667: }
1.86 raeburn 2668: $datatable .= '</td>';
1.163 raeburn 2669: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2670: $datatable .= '<td class="LC_right_item">'.
2671: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2672: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2673: $defaultquota.'" size="5" /></span>'.(' ' x2).
2674: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2675: '<input type="text" name="authorquota" value="'.
2676: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2677: }
2678: $datatable .= '</tr>';
1.72 raeburn 2679: $typecount ++;
2680: $css_class = $typecount%2?' class="LC_odd_row"':'';
2681: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2682: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2683: if ($context eq 'requestcourses') {
1.109 raeburn 2684: $datatable .= &mt('(overrides affiliation, if set)').
2685: '</td>'.
2686: '<td class="LC_left_item">'.
2687: '<table><tr>';
1.101 raeburn 2688: } else {
1.109 raeburn 2689: $datatable .= &mt('(overrides affiliation, if checked)').
2690: '</td>'.
2691: '<td class="LC_left_item" colspan="2">'.
2692: '<br />';
1.101 raeburn 2693: }
2694: my %advcell;
1.72 raeburn 2695: foreach my $item (@usertools) {
1.101 raeburn 2696: if ($context eq 'requestcourses') {
2697: my ($curroption,$currlimit);
2698: if (ref($settings) eq 'HASH') {
2699: if (ref($settings->{$item}) eq 'HASH') {
2700: $curroption = $settings->{$item}->{'_LC_adv'};
2701: if ($curroption =~ /^autolimit=(\d*)$/) {
2702: $currlimit = $1;
2703: }
2704: }
2705: }
2706: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2707: my $checked = '';
2708: if ($curroption eq '') {
2709: $checked = ' checked="checked"';
2710: }
2711: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2712: '<input type="radio" name="crsreq_'.$item.
2713: '__LC_adv" value=""'.$checked.' />'.
2714: &mt('No override set').'</label></span> ';
1.101 raeburn 2715: foreach my $option (@options) {
2716: my $val = $option;
2717: if ($option eq 'norequest') {
2718: $val = 0;
2719: }
2720: if ($option eq 'validate') {
2721: my $canvalidate = 0;
2722: if (ref($validations{$item}) eq 'HASH') {
2723: if ($validations{$item}{'_LC_adv'}) {
2724: $canvalidate = 1;
2725: }
2726: }
2727: next if (!$canvalidate);
2728: }
2729: my $checked = '';
1.104 raeburn 2730: if ($val eq $curroption) {
1.101 raeburn 2731: $checked = ' checked="checked"';
2732: } elsif ($option eq 'autolimit') {
2733: if ($curroption =~ /^autolimit/) {
2734: $checked = ' checked="checked"';
2735: }
2736: }
2737: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2738: '<input type="radio" name="crsreq_'.$item.
2739: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2740: $titles{$option}.'</label>';
2741: if ($option eq 'autolimit') {
1.127 raeburn 2742: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2743: $item.'_limit__LC_adv" size="1" '.
2744: 'value="'.$currlimit.'" />';
2745: }
1.127 raeburn 2746: $advcell{$item} .= '</span> ';
1.104 raeburn 2747: if ($option eq 'autolimit') {
1.127 raeburn 2748: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2749: }
1.101 raeburn 2750: }
1.163 raeburn 2751: } elsif ($context eq 'requestauthor') {
2752: my $curroption;
2753: if (ref($settings) eq 'HASH') {
2754: $curroption = $settings->{'_LC_adv'};
2755: }
2756: my $checked = '';
2757: if ($curroption eq '') {
2758: $checked = ' checked="checked"';
2759: }
2760: $datatable .= '<span class="LC_nobreak"><label>'.
2761: '<input type="radio" name="authorreq__LC_adv"'.
2762: ' value=""'.$checked.' />'.
2763: &mt('No override set').'</label></span> ';
2764: foreach my $option (@options) {
2765: my $val = $option;
2766: if ($option eq 'norequest') {
2767: $val = 0;
2768: }
2769: my $checked = '';
2770: if ($val eq $curroption) {
2771: $checked = ' checked="checked"';
2772: }
2773: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2774: '<input type="radio" name="authorreq__LC_adv"'.
2775: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2776: $titles{$option}.'</label></span> ';
2777: }
1.101 raeburn 2778: } else {
2779: my $checked = 'checked="checked" ';
2780: if (ref($settings) eq 'HASH') {
2781: if (ref($settings->{$item}) eq 'HASH') {
2782: if ($settings->{$item}->{'_LC_adv'} == 0) {
2783: $checked = '';
2784: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2785: $checked = 'checked="checked" ';
2786: }
1.79 raeburn 2787: }
1.72 raeburn 2788: }
1.101 raeburn 2789: $datatable .= '<span class="LC_nobreak"><label>'.
2790: '<input type="checkbox" name="'.$context.'_'.$item.
2791: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2792: '</label></span> ';
2793: }
2794: }
2795: if ($context eq 'requestcourses') {
2796: $datatable .= '</tr><tr>';
2797: foreach my $item (@usertools) {
1.106 raeburn 2798: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2799: }
1.101 raeburn 2800: $datatable .= '</tr></table>';
1.72 raeburn 2801: }
1.98 raeburn 2802: $datatable .= '</td></tr>';
1.30 raeburn 2803: $$rowtotal += $typecount;
1.3 raeburn 2804: return $datatable;
2805: }
2806:
1.163 raeburn 2807: sub print_requestmail {
1.305 raeburn 2808: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2809: my ($now,$datatable,%currapp);
1.102 raeburn 2810: $now = time;
2811: if (ref($settings) eq 'HASH') {
2812: if (ref($settings->{'notify'}) eq 'HASH') {
2813: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2814: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2815: }
2816: }
2817: }
1.191 raeburn 2818: my $numinrow = 2;
1.224 raeburn 2819: my $css_class;
1.305 raeburn 2820: if ($$rowtotal%2) {
2821: $css_class = 'LC_odd_row';
2822: }
2823: if ($customcss) {
2824: $css_class .= " $customcss";
2825: }
2826: $css_class =~ s/^\s+//;
2827: if ($css_class) {
2828: $css_class = ' class="'.$css_class.'"';
2829: }
2830: if ($rowstyle) {
2831: $css_class .= ' style="'.$rowstyle.'"';
2832: }
1.163 raeburn 2833: my $text;
2834: if ($action eq 'requestcourses') {
2835: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2836: } elsif ($action eq 'requestauthor') {
2837: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2838: } else {
1.224 raeburn 2839: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2840: }
1.224 raeburn 2841: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2842: ' <td>'.$text.'</td>'.
1.102 raeburn 2843: ' <td class="LC_left_item">';
1.191 raeburn 2844: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2845: $action.'notifyapproval',%currapp);
1.191 raeburn 2846: if ($numdc > 0) {
2847: $datatable .= $table;
1.102 raeburn 2848: } else {
2849: $datatable .= &mt('There are no active Domain Coordinators');
2850: }
2851: $datatable .='</td></tr>';
2852: return $datatable;
2853: }
2854:
1.216 raeburn 2855: sub print_studentcode {
2856: my ($settings,$rowtotal) = @_;
2857: my $rownum = 0;
1.218 raeburn 2858: my ($output,%current);
1.325 raeburn 2859: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2860: if (ref($settings) eq 'HASH') {
2861: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2862: foreach my $type (@crstypes) {
2863: $current{$type} = $settings->{'uniquecode'}{$type};
2864: }
1.218 raeburn 2865: }
2866: }
2867: $output .= '<tr>'.
2868: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2869: '<td class="LC_left_item">';
2870: foreach my $type (@crstypes) {
2871: my $check = ' ';
2872: if ($current{$type}) {
2873: $check = ' checked="checked" ';
2874: }
2875: $output .= '<span class="LC_nobreak"><label>'.
2876: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2877: &mt($type).'</label></span>'.(' 'x2).' ';
2878: }
2879: $output .= '</td></tr>';
2880: $$rowtotal ++;
2881: return $output;
1.216 raeburn 2882: }
2883:
2884: sub print_textbookcourses {
1.242 raeburn 2885: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2886: my $rownum = 0;
2887: my $css_class;
2888: my $itemcount = 1;
2889: my $maxnum = 0;
2890: my $bookshash;
2891: if (ref($settings) eq 'HASH') {
1.242 raeburn 2892: $bookshash = $settings->{$type};
1.216 raeburn 2893: }
2894: my %ordered;
2895: if (ref($bookshash) eq 'HASH') {
2896: foreach my $item (keys(%{$bookshash})) {
2897: if (ref($bookshash->{$item}) eq 'HASH') {
2898: my $num = $bookshash->{$item}{'order'};
2899: $ordered{$num} = $item;
2900: }
2901: }
2902: }
2903: my $confname = $dom.'-domainconfig';
2904: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2905: my $maxnum = scalar(keys(%ordered));
2906: my $datatable;
1.216 raeburn 2907: if (keys(%ordered)) {
2908: my @items = sort { $a <=> $b } keys(%ordered);
2909: for (my $i=0; $i<@items; $i++) {
2910: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2911: my $key = $ordered{$items[$i]};
2912: my %coursehash=&Apache::lonnet::coursedescription($key);
2913: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2914: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2915: if (ref($bookshash->{$key}) eq 'HASH') {
2916: $subject = $bookshash->{$key}->{'subject'};
2917: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2918: if ($type eq 'textbooks') {
1.243 raeburn 2919: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2920: $author = $bookshash->{$key}->{'author'};
2921: $image = $bookshash->{$key}->{'image'};
2922: if ($image ne '') {
2923: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2924: my $imagethumb = "$path/tn-".$imagefile;
2925: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2926: }
1.216 raeburn 2927: }
2928: }
1.242 raeburn 2929: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2930: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2931: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2932: for (my $k=0; $k<=$maxnum; $k++) {
2933: my $vpos = $k+1;
2934: my $selstr;
2935: if ($k == $i) {
2936: $selstr = ' selected="selected" ';
2937: }
2938: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2939: }
2940: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2941: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2942: &mt('Delete?').'</label></span></td>'.
2943: '<td colspan="2">'.
1.242 raeburn 2944: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2945: (' 'x2).
1.242 raeburn 2946: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2947: if ($type eq 'textbooks') {
2948: $datatable .= (' 'x2).
1.243 raeburn 2949: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2950: (' 'x2).
1.242 raeburn 2951: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2952: (' 'x2).
2953: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2954: if ($image) {
1.267 raeburn 2955: $datatable .= $imgsrc.
1.242 raeburn 2956: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2957: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2958: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2959: }
2960: if ($switchserver) {
2961: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2962: } else {
2963: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2964: }
1.216 raeburn 2965: }
1.242 raeburn 2966: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2967: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2968: $coursetitle.'</span></td></tr>'."\n";
2969: $itemcount ++;
2970: }
2971: }
2972: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2973: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2974: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2975: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2976: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2977: for (my $k=0; $k<$maxnum+1; $k++) {
2978: my $vpos = $k+1;
2979: my $selstr;
2980: if ($k == $maxnum) {
2981: $selstr = ' selected="selected" ';
2982: }
2983: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2984: }
2985: $datatable .= '</select> '."\n".
1.334 raeburn 2986: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2987: '<td colspan="2">'.
1.242 raeburn 2988: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2989: (' 'x2).
1.242 raeburn 2990: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2991: (' 'x2);
2992: if ($type eq 'textbooks') {
1.243 raeburn 2993: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2994: (' 'x2).
2995: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2996: (' 'x2).
2997: '<span class="LC_nobreak">'.&mt('Image:').' ';
2998: if ($switchserver) {
2999: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3000: } else {
3001: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3002: }
1.334 raeburn 3003: $datatable .= '</span>'."\n";
1.216 raeburn 3004: }
1.334 raeburn 3005: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3006: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3007: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3008: &Apache::loncommon::selectcourse_link
1.334 raeburn 3009: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3010: '</span></td>'."\n".
3011: '</tr>'."\n";
3012: $itemcount ++;
3013: return $datatable;
3014: }
3015:
1.217 raeburn 3016: sub textbookcourses_javascript {
1.242 raeburn 3017: my ($settings) = @_;
3018: return unless(ref($settings) eq 'HASH');
3019: my (%ordered,%total,%jstext);
3020: foreach my $type ('textbooks','templates') {
3021: $total{$type} = 0;
3022: if (ref($settings->{$type}) eq 'HASH') {
3023: foreach my $item (keys(%{$settings->{$type}})) {
3024: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3025: my $num = $settings->{$type}->{$item}{'order'};
3026: $ordered{$type}{$num} = $item;
3027: }
3028: }
3029: $total{$type} = scalar(keys(%{$settings->{$type}}));
3030: }
3031: my @jsarray = ();
3032: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3033: push(@jsarray,$ordered{$type}{$item});
3034: }
3035: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3036: }
3037: return <<"ENDSCRIPT";
3038: <script type="text/javascript">
3039: // <![CDATA[
1.242 raeburn 3040: function reorderBooks(form,item,caller) {
1.217 raeburn 3041: var changedVal;
1.242 raeburn 3042: $jstext{'textbooks'};
3043: $jstext{'templates'};
3044: var newpos;
3045: var maxh;
3046: if (caller == 'textbooks') {
3047: newpos = 'textbooks_addbook_pos';
3048: maxh = 1 + $total{'textbooks'};
3049: } else {
3050: newpos = 'templates_addbook_pos';
3051: maxh = 1 + $total{'templates'};
3052: }
1.217 raeburn 3053: var current = new Array;
3054: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3055: if (item == newpos) {
3056: changedVal = newitemVal;
3057: } else {
3058: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3059: current[newitemVal] = newpos;
3060: }
1.242 raeburn 3061: if (caller == 'textbooks') {
3062: for (var i=0; i<textbooks.length; i++) {
3063: var elementName = 'textbooks_'+textbooks[i];
3064: if (elementName != item) {
3065: if (form.elements[elementName]) {
3066: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3067: current[currVal] = elementName;
3068: }
3069: }
3070: }
3071: }
3072: if (caller == 'templates') {
3073: for (var i=0; i<templates.length; i++) {
3074: var elementName = 'templates_'+templates[i];
3075: if (elementName != item) {
3076: if (form.elements[elementName]) {
3077: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3078: current[currVal] = elementName;
3079: }
1.217 raeburn 3080: }
3081: }
3082: }
3083: var oldVal;
3084: for (var j=0; j<maxh; j++) {
3085: if (current[j] == undefined) {
3086: oldVal = j;
3087: }
3088: }
3089: if (oldVal < changedVal) {
3090: for (var k=oldVal+1; k<=changedVal ; k++) {
3091: var elementName = current[k];
3092: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3093: }
3094: } else {
3095: for (var k=changedVal; k<oldVal; k++) {
3096: var elementName = current[k];
3097: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3098: }
3099: }
3100: return;
3101: }
3102:
3103: // ]]>
3104: </script>
3105:
3106: ENDSCRIPT
3107: }
3108:
1.267 raeburn 3109: sub ltitools_javascript {
3110: my ($settings) = @_;
1.319 raeburn 3111: my $togglejs = <itools_toggle_js();
3112: unless (ref($settings) eq 'HASH') {
3113: return $togglejs;
3114: }
1.267 raeburn 3115: my (%ordered,$total,%jstext);
3116: $total = 0;
3117: foreach my $item (keys(%{$settings})) {
3118: if (ref($settings->{$item}) eq 'HASH') {
3119: my $num = $settings->{$item}{'order'};
3120: $ordered{$num} = $item;
3121: }
3122: }
3123: $total = scalar(keys(%{$settings}));
3124: my @jsarray = ();
3125: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3126: push(@jsarray,$ordered{$item});
3127: }
3128: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3129: return <<"ENDSCRIPT";
3130: <script type="text/javascript">
3131: // <![CDATA[
1.319 raeburn 3132: function reorderLTITools(form,item) {
1.267 raeburn 3133: var changedVal;
3134: $jstext
3135: var newpos = 'ltitools_add_pos';
3136: var maxh = 1 + $total;
3137: var current = new Array;
3138: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3139: if (item == newpos) {
3140: changedVal = newitemVal;
3141: } else {
3142: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3143: current[newitemVal] = newpos;
3144: }
3145: for (var i=0; i<ltitools.length; i++) {
3146: var elementName = 'ltitools_'+ltitools[i];
3147: if (elementName != item) {
3148: if (form.elements[elementName]) {
3149: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3150: current[currVal] = elementName;
3151: }
3152: }
3153: }
3154: var oldVal;
3155: for (var j=0; j<maxh; j++) {
3156: if (current[j] == undefined) {
3157: oldVal = j;
3158: }
3159: }
3160: if (oldVal < changedVal) {
3161: for (var k=oldVal+1; k<=changedVal ; k++) {
3162: var elementName = current[k];
3163: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3164: }
3165: } else {
3166: for (var k=changedVal; k<oldVal; k++) {
3167: var elementName = current[k];
3168: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3169: }
3170: }
3171: return;
3172: }
3173:
3174: // ]]>
3175: </script>
3176:
1.319 raeburn 3177: $togglejs
3178:
3179: ENDSCRIPT
3180: }
3181:
3182: sub ltitools_toggle_js {
3183: return <<"ENDSCRIPT";
3184: <script type="text/javascript">
3185: // <![CDATA[
3186:
3187: function toggleLTITools(form,setting,item) {
3188: var radioname = '';
3189: var divid = '';
3190: if ((setting == 'passback') || (setting == 'roster')) {
3191: radioname = 'ltitools_'+setting+'_'+item;
3192: divid = 'ltitools_'+setting+'time_'+item;
3193: var num = form.elements[radioname].length;
3194: if (num) {
3195: var setvis = '';
3196: for (var i=0; i<num; i++) {
3197: if (form.elements[radioname][i].checked) {
3198: if (form.elements[radioname][i].value == '1') {
3199: if (document.getElementById(divid)) {
3200: document.getElementById(divid).style.display = 'inline-block';
3201: }
3202: setvis = 1;
3203: }
3204: break;
3205: }
3206: }
3207: }
3208: if (!setvis) {
3209: if (document.getElementById(divid)) {
3210: document.getElementById(divid).style.display = 'none';
3211: }
3212: }
3213: }
1.324 raeburn 3214: if (setting == 'user') {
3215: divid = 'ltitools_'+setting+'_div_'+item;
3216: var checkid = 'ltitools_'+setting+'_field_'+item;
3217: if (document.getElementById(divid)) {
3218: if (document.getElementById(checkid)) {
3219: if (document.getElementById(checkid).checked) {
3220: document.getElementById(divid).style.display = 'inline-block';
3221: } else {
3222: document.getElementById(divid).style.display = 'none';
3223: }
3224: }
3225: }
3226: }
1.319 raeburn 3227: return;
3228: }
3229: // ]]>
3230: </script>
3231:
1.267 raeburn 3232: ENDSCRIPT
3233: }
3234:
1.381 raeburn 3235: sub wafproxy_javascript {
3236: my ($dom) = @_;
3237: return <<"ENDSCRIPT";
3238: <script type="text/javascript">
3239: // <![CDATA[
3240: function updateWAF() {
3241: if (document.getElementById('wafproxy_remoteip')) {
3242: var wafremote = 0;
3243: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3244: wafremote = 1;
3245: }
3246: var fields = new Array('header','trust');
3247: for (var i=0; i<fields.length; i++) {
3248: if (document.getElementById('wafproxy_'+fields[i])) {
3249: if (wafremote == 1) {
3250: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3251: }
3252: else {
3253: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3254: }
3255: }
3256: }
3257: if (document.getElementById('wafproxyranges_$dom')) {
3258: if (wafremote == 1) {
3259: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3260: } else {
3261: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3262: if (document.display.wafproxy_vpnaccess[i].checked) {
3263: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3264: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3265: }
3266: }
3267: }
3268: }
3269: }
3270: }
3271: return;
3272: }
3273:
3274: function checkWAF() {
3275: if (document.getElementById('wafproxy_remoteip')) {
3276: var wafvpn = 0;
3277: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3278: if (document.display.wafproxy_vpnaccess[i].checked) {
3279: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3280: wafvpn = 1;
3281: }
3282: break;
3283: }
3284: }
3285: var vpn = new Array('vpnint','vpnext');
3286: for (var i=0; i<vpn.length; i++) {
3287: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3288: if (wafvpn == 1) {
3289: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3290: }
3291: else {
3292: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3293: }
3294: }
3295: }
3296: if (document.getElementById('wafproxyranges_$dom')) {
3297: if (wafvpn == 1) {
3298: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3299: }
3300: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3301: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3302: }
3303: }
3304: }
3305: return;
3306: }
3307:
3308: function toggleWAF() {
3309: if (document.getElementById('wafproxy_table')) {
3310: var wafproxy = 0;
3311: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3312: if (document.display.wafproxy_${dom}[i].checked) {
3313: if (document.display.wafproxy_${dom}[i].value == 1) {
3314: wafproxy = 1;
3315: break;
3316: }
3317: }
3318: }
3319: if (wafproxy == 1) {
3320: document.getElementById('wafproxy_table').style.display='inline';
3321: }
3322: else {
3323: document.getElementById('wafproxy_table').style.display='none';
3324: }
3325: if (document.getElementById('wafproxyrow_${dom}')) {
3326: if (wafproxy == 1) {
3327: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3328: }
3329: else {
3330: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3331: }
3332: }
3333: if (document.getElementById('nowafproxyrow_$dom')) {
3334: if (wafproxy == 1) {
3335: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3336: }
3337: else {
3338: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3339: }
3340: }
3341: }
3342: return;
3343: }
3344: // ]]>
3345: </script>
3346:
3347: ENDSCRIPT
3348: }
3349:
1.372 raeburn 3350: sub proctoring_javascript {
3351: my ($settings) = @_;
3352: my (%ordered,$total,%jstext);
3353: $total = 0;
3354: if (ref($settings) eq 'HASH') {
3355: foreach my $item (keys(%{$settings})) {
3356: if (ref($settings->{$item}) eq 'HASH') {
3357: my $num = $settings->{$item}{'order'};
3358: $ordered{$num} = $item;
3359: }
3360: }
3361: $total = scalar(keys(%{$settings}));
3362: } else {
3363: %ordered = (
3364: 0 => 'proctorio',
3365: 1 => 'examity',
3366: );
3367: $total = 2;
3368: }
3369: my @jsarray = ();
3370: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3371: push(@jsarray,$ordered{$item});
3372: }
3373: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3374: return <<"ENDSCRIPT";
3375: <script type="text/javascript">
3376: // <![CDATA[
3377: function reorderProctoring(form,item) {
3378: var changedVal;
3379: $jstext
3380: var maxh = $total;
3381: var current = new Array;
3382: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3383: for (var i=0; i<proctors.length; i++) {
3384: var elementName = 'proctoring_pos_'+proctors[i];
3385: if (elementName != item) {
3386: if (form.elements[elementName]) {
3387: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3388: current[currVal] = elementName;
3389: }
3390: }
3391: }
3392: var oldVal;
3393: for (var j=0; j<maxh; j++) {
3394: if (current[j] == undefined) {
3395: oldVal = j;
3396: }
3397: }
3398: if (oldVal < changedVal) {
3399: for (var k=oldVal+1; k<=changedVal ; k++) {
3400: var elementName = current[k];
3401: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3402: }
3403: } else {
3404: for (var k=changedVal; k<oldVal; k++) {
3405: var elementName = current[k];
3406: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3407: }
3408: }
3409: return;
3410: }
3411:
3412: function toggleProctoring(form,item) {
3413: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3414: if (fieldsets.length) {
3415: var radioname = 'proctoring_available_'+item;
3416: var num = form.elements[radioname].length;
3417: if (num) {
3418: var setvis = '';
3419: for (var i=0; i<num; i++) {
3420: if (form.elements[radioname][i].checked) {
3421: if (form.elements[radioname][i].value == '1') {
3422: setvis = 1;
3423: break;
3424: }
3425: }
3426: }
3427: for (var j=0; j<fieldsets.length; j++) {
3428: if (setvis) {
3429: fieldsets[j].style.display = 'block';
3430: } else {
3431: fieldsets[j].style.display = 'none';
3432: }
3433: }
3434: }
3435: }
3436: return;
3437: }
3438:
3439: // ]]>
3440: </script>
3441:
3442: ENDSCRIPT
3443: }
3444:
3445:
1.320 raeburn 3446: sub lti_javascript {
1.405 raeburn 3447: my ($dom,$settings) = @_;
3448: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3449: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3450: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3451: return $togglejs.'
3452: <script type="text/javascript">
3453: // <![CDATA[
3454:
3455: '.$linkprot_js.'
3456:
3457: // ]]>
3458: </script>
3459: ';
1.320 raeburn 3460: }
3461: my (%ordered,$total,%jstext);
1.390 raeburn 3462: $total = scalar(keys(%{$settings}));
1.320 raeburn 3463: foreach my $item (keys(%{$settings})) {
3464: if (ref($settings->{$item}) eq 'HASH') {
3465: my $num = $settings->{$item}{'order'};
1.390 raeburn 3466: if ($num eq '') {
3467: $num = $total - 1;
3468: }
1.320 raeburn 3469: $ordered{$num} = $item;
3470: }
3471: }
3472: my @jsarray = ();
3473: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3474: push(@jsarray,$ordered{$item});
3475: }
3476: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3477: return <<"ENDSCRIPT";
3478: <script type="text/javascript">
3479: // <![CDATA[
3480: function reorderLTI(form,item) {
3481: var changedVal;
3482: $jstext
3483: var newpos = 'lti_pos_add';
3484: var maxh = 1 + $total;
3485: var current = new Array;
3486: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3487: if (item == newpos) {
3488: changedVal = newitemVal;
3489: } else {
3490: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3491: current[newitemVal] = newpos;
3492: }
3493: for (var i=0; i<lti.length; i++) {
3494: var elementName = 'lti_pos_'+lti[i];
3495: if (elementName != item) {
3496: if (form.elements[elementName]) {
3497: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3498: current[currVal] = elementName;
3499: }
3500: }
3501: }
3502: var oldVal;
3503: for (var j=0; j<maxh; j++) {
3504: if (current[j] == undefined) {
3505: oldVal = j;
3506: }
3507: }
3508: if (oldVal < changedVal) {
3509: for (var k=oldVal+1; k<=changedVal ; k++) {
3510: var elementName = current[k];
3511: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3512: }
3513: } else {
3514: for (var k=changedVal; k<oldVal; k++) {
3515: var elementName = current[k];
3516: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3517: }
3518: }
3519: return;
3520: }
1.406 raeburn 3521:
3522: $linkprot_js
3523:
1.320 raeburn 3524: // ]]>
3525: </script>
3526:
3527: $togglejs
3528:
3529: ENDSCRIPT
3530: }
3531:
3532: sub lti_toggle_js {
1.405 raeburn 3533: my ($dom) = @_;
1.325 raeburn 3534: my %lcauthparmtext = &Apache::lonlocal::texthash (
3535: localauth => 'Local auth argument',
3536: krb => 'Kerberos domain',
3537: );
1.391 raeburn 3538: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3539: &js_escape(\$crsincalert);
1.405 raeburn 3540: my %servers = &Apache::lonnet::get_servers($dom,'library');
3541: my $primary = &Apache::lonnet::domain($dom,'primary');
3542: my $course_servers = "'".join("','",keys(%servers))."'";
3543:
1.320 raeburn 3544: return <<"ENDSCRIPT";
3545: <script type="text/javascript">
3546: // <![CDATA[
3547:
3548: function toggleLTI(form,setting,item) {
1.391 raeburn 3549: if ((setting == 'requser') || (setting == 'crsinc')) {
3550: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3551: var setvis = '';
3552: var radioname = 'lti_requser_'+item;
3553: var num = form.elements[radioname].length;
3554: if (num) {
3555: for (var i=0; i<num; i++) {
3556: if (form.elements[radioname][i].checked) {
3557: if (form.elements[radioname][i].value == '1') {
3558: setvis = 1;
3559: break;
3560: }
3561: }
3562: }
3563: }
3564: if (usrfieldsets.length) {
3565: for (var j=0; j<usrfieldsets.length; j++) {
3566: if (setvis) {
3567: usrfieldsets[j].style.display = 'block';
3568: } else {
3569: usrfieldsets[j].style.display = 'none';
3570: }
3571: }
3572: }
3573: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3574: if (crsfieldsets.length) {
3575: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3576: var num = form.elements[radioname].length;
3577: if (num) {
1.391 raeburn 3578: var crsvis = '';
1.345 raeburn 3579: for (var i=0; i<num; i++) {
3580: if (form.elements[radioname][i].checked) {
3581: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3582: if (setvis == '') {
3583: if (setting == 'crsinc'){
3584: alert("$crsincalert");
3585: form.elements[radioname][0].checked = true;
3586: }
3587: } else {
3588: crsvis = 1;
3589: }
3590: break;
1.345 raeburn 3591: }
3592: }
3593: }
1.391 raeburn 3594: setvis = crsvis;
3595: }
3596: for (var j=0; j<crsfieldsets.length; j++) {
3597: if (setvis) {
3598: crsfieldsets[j].style.display = 'block';
3599: } else {
3600: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3601: }
3602: }
3603: }
1.363 raeburn 3604: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3605: var radioname = '';
3606: var divid = '';
3607: if (setting == 'user') {
3608: radioname = 'lti_mapuser_'+item;
3609: divid = 'lti_userfield_'+item;
1.343 raeburn 3610: } else if (setting == 'crs') {
1.320 raeburn 3611: radioname = 'lti_mapcrs_'+item;
3612: divid = 'lti_crsfield_'+item;
1.363 raeburn 3613: } else if (setting == 'callback') {
3614: radioname = 'lti_callback_'+item;
3615: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3616: } else {
1.351 raeburn 3617: radioname = 'lti_passback_'+item;
1.337 raeburn 3618: divid = 'lti_passback_'+item;
1.320 raeburn 3619: }
3620: var num = form.elements[radioname].length;
3621: if (num) {
3622: var setvis = '';
3623: for (var i=0; i<num; i++) {
3624: if (form.elements[radioname][i].checked) {
1.363 raeburn 3625: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3626: if (form.elements[radioname][i].value == '1') {
3627: if (document.getElementById(divid)) {
3628: document.getElementById(divid).style.display = 'inline-block';
3629: }
3630: setvis = 1;
3631: break;
3632: }
3633: } else {
3634: if (form.elements[radioname][i].value == 'other') {
3635: if (document.getElementById(divid)) {
3636: document.getElementById(divid).style.display = 'inline-block';
3637: }
3638: setvis = 1;
3639: break;
1.320 raeburn 3640: }
3641: }
3642: }
3643: }
3644: if (!setvis) {
3645: if (document.getElementById(divid)) {
3646: document.getElementById(divid).style.display = 'none';
3647: }
3648: }
3649: }
3650: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3651: var numsec = form.elements['lti_crssec_'+item].length;
3652: if (numsec) {
3653: var setvis = '';
3654: for (var i=0; i<numsec; i++) {
3655: if (form.elements['lti_crssec_'+item][i].checked) {
3656: if (form.elements['lti_crssec_'+item][i].value == '1') {
3657: if (document.getElementById('lti_crssecfield_'+item)) {
3658: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3659: setvis = 1;
3660: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3661: if (numsrcsec) {
3662: var setsrcvis = '';
3663: for (var j=0; j<numsrcsec; j++) {
3664: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3665: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3666: if (document.getElementById('lti_secsrcfield_'+item)) {
3667: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3668: setsrcvis = 1;
3669: }
3670: }
3671: }
3672: }
3673: if (!setsrcvis) {
3674: if (document.getElementById('lti_secsrcfield_'+item)) {
3675: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3676: }
3677: }
3678: }
3679: }
3680: }
3681: }
3682: }
3683: if (!setvis) {
3684: if (document.getElementById('lti_crssecfield_'+item)) {
3685: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3686: }
3687: if (document.getElementById('lti_secsrcfield_'+item)) {
3688: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3689: }
3690: }
3691: }
1.325 raeburn 3692: } else if (setting == 'lcauth') {
3693: var numauth = form.elements['lti_lcauth_'+item].length;
3694: if (numauth) {
3695: for (var i=0; i<numauth; i++) {
3696: if (form.elements['lti_lcauth_'+item][i].checked) {
3697: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3698: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3699: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3700: } else {
3701: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3702: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3703: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3704: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3705: } else {
3706: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3707: }
3708: }
3709: }
3710: }
3711: }
3712: }
3713: }
1.326 raeburn 3714: } else if (setting == 'lcmenu') {
3715: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3716: var divid = 'lti_menufield_'+item;
3717: var setvis = '';
3718: for (var i=0; i<menus.length; i++) {
3719: var radioname = menus[i];
3720: var num = form.elements[radioname].length;
3721: if (num) {
3722: for (var j=0; j<num; j++) {
3723: if (form.elements[radioname][j].checked) {
3724: if (form.elements[radioname][j].value == '1') {
3725: if (document.getElementById(divid)) {
3726: document.getElementById(divid).style.display = 'inline-block';
3727: }
3728: setvis = 1;
3729: break;
3730: }
3731: }
3732: }
3733: }
3734: if (setvis == 1) {
3735: break;
3736: }
3737: }
3738: if (!setvis) {
3739: if (document.getElementById(divid)) {
3740: document.getElementById(divid).style.display = 'none';
3741: }
3742: }
1.320 raeburn 3743: }
3744: return;
3745: }
1.405 raeburn 3746:
1.320 raeburn 3747: // ]]>
3748: </script>
3749:
3750: ENDSCRIPT
3751: }
3752:
1.385 raeburn 3753: sub autoupdate_javascript {
3754: return <<"ENDSCRIPT";
3755: <script type="text/javascript">
3756: // <![CDATA[
3757: function toggleLastActiveDays(form) {
3758: var radioname = 'lastactive';
3759: var divid = 'lastactive_div';
3760: var num = form.elements[radioname].length;
3761: if (num) {
3762: var setvis = '';
3763: for (var i=0; i<num; i++) {
3764: if (form.elements[radioname][i].checked) {
3765: if (form.elements[radioname][i].value == '1') {
3766: if (document.getElementById(divid)) {
3767: document.getElementById(divid).style.display = 'inline-block';
3768: }
3769: setvis = 1;
3770: }
3771: break;
3772: }
3773: }
3774: if (!setvis) {
3775: if (document.getElementById(divid)) {
3776: document.getElementById(divid).style.display = 'none';
3777: }
3778: }
3779: }
3780: return;
3781: }
3782: // ]]>
3783: </script>
3784:
3785: ENDSCRIPT
3786: }
3787:
1.399 raeburn 3788: sub autoenroll_javascript {
3789: return <<"ENDSCRIPT";
3790: <script type="text/javascript">
3791: // <![CDATA[
3792: function toggleFailsafe(form) {
3793: var radioname = 'autoenroll_failsafe';
3794: var divid = 'autoenroll_failsafe_div';
3795: var num = form.elements[radioname].length;
3796: if (num) {
3797: var setvis = '';
3798: for (var i=0; i<num; i++) {
3799: if (form.elements[radioname][i].checked) {
3800: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3801: if (document.getElementById(divid)) {
3802: document.getElementById(divid).style.display = 'inline-block';
3803: }
3804: setvis = 1;
3805: }
3806: break;
3807: }
3808: }
3809: if (!setvis) {
3810: if (document.getElementById(divid)) {
3811: document.getElementById(divid).style.display = 'none';
3812: }
3813: }
3814: }
3815: return;
3816: }
3817: // ]]>
3818: </script>
3819:
3820: ENDSCRIPT
3821: }
3822:
1.386 raeburn 3823: sub saml_javascript {
3824: return <<"ENDSCRIPT";
3825: <script type="text/javascript">
3826: // <![CDATA[
3827: function toggleSamlOptions(form,hostid) {
3828: var radioname = 'saml_'+hostid;
3829: var tablecellon = 'samloptionson_'+hostid;
3830: var tablecelloff = 'samloptionsoff_'+hostid;
3831: var num = form.elements[radioname].length;
3832: if (num) {
3833: var setvis = '';
3834: for (var i=0; i<num; i++) {
3835: if (form.elements[radioname][i].checked) {
3836: if (form.elements[radioname][i].value == '1') {
3837: if (document.getElementById(tablecellon)) {
3838: document.getElementById(tablecellon).style.display='';
3839: }
3840: if (document.getElementById(tablecelloff)) {
3841: document.getElementById(tablecelloff).style.display='none';
3842: }
3843: setvis = 1;
3844: }
3845: break;
3846: }
3847: }
3848: if (!setvis) {
3849: if (document.getElementById(tablecellon)) {
3850: document.getElementById(tablecellon).style.display='none';
3851: }
3852: if (document.getElementById(tablecelloff)) {
3853: document.getElementById(tablecelloff).style.display='';
3854: }
3855: }
3856: }
3857: return;
3858: }
3859: // ]]>
3860: </script>
3861:
3862: ENDSCRIPT
3863: }
3864:
1.394 raeburn 3865: sub ipaccess_javascript {
3866: my ($settings) = @_;
3867: my (%ordered,$total,%jstext);
3868: $total = 0;
3869: if (ref($settings) eq 'HASH') {
3870: foreach my $item (keys(%{$settings})) {
3871: if (ref($settings->{$item}) eq 'HASH') {
3872: my $num = $settings->{$item}{'order'};
3873: $ordered{$num} = $item;
3874: }
3875: }
3876: $total = scalar(keys(%{$settings}));
3877: }
3878: my @jsarray = ();
3879: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3880: push(@jsarray,$ordered{$item});
3881: }
3882: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3883: return <<"ENDSCRIPT";
3884: <script type="text/javascript">
3885: // <![CDATA[
3886: function reorderIPaccess(form,item) {
3887: var changedVal;
3888: $jstext
3889: var newpos = 'ipaccess_pos_add';
3890: var maxh = 1 + $total;
3891: var current = new Array;
3892: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3893: if (item == newpos) {
3894: changedVal = newitemVal;
3895: } else {
3896: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3897: current[newitemVal] = newpos;
3898: }
3899: for (var i=0; i<ipaccess.length; i++) {
3900: var elementName = 'ipaccess_pos_'+ipaccess[i];
3901: if (elementName != item) {
3902: if (form.elements[elementName]) {
3903: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3904: current[currVal] = elementName;
3905: }
3906: }
3907: }
3908: var oldVal;
3909: for (var j=0; j<maxh; j++) {
3910: if (current[j] == undefined) {
3911: oldVal = j;
3912: }
3913: }
3914: if (oldVal < changedVal) {
3915: for (var k=oldVal+1; k<=changedVal ; k++) {
3916: var elementName = current[k];
3917: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3918: }
3919: } else {
3920: for (var k=changedVal; k<oldVal; k++) {
3921: var elementName = current[k];
3922: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3923: }
3924: }
3925: return;
3926: }
3927: // ]]>
3928: </script>
3929:
3930: ENDSCRIPT
3931: }
3932:
1.3 raeburn 3933: sub print_autoenroll {
1.30 raeburn 3934: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3935: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3936: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3937: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3938: $failsafesty = 'none';
3939: %failsafechecked = (
3940: off => ' checked="checked"',
3941: );
1.3 raeburn 3942: if (ref($settings) eq 'HASH') {
3943: if (exists($settings->{'run'})) {
3944: if ($settings->{'run'} eq '0') {
3945: $runoff = ' checked="checked" ';
3946: $runon = ' ';
3947: } else {
3948: $runon = ' checked="checked" ';
3949: $runoff = ' ';
3950: }
3951: } else {
3952: if ($autorun) {
3953: $runon = ' checked="checked" ';
3954: $runoff = ' ';
3955: } else {
3956: $runoff = ' checked="checked" ';
3957: $runon = ' ';
3958: }
3959: }
1.129 raeburn 3960: if (exists($settings->{'co-owners'})) {
3961: if ($settings->{'co-owners'} eq '0') {
3962: $coownersoff = ' checked="checked" ';
3963: $coownerson = ' ';
3964: } else {
3965: $coownerson = ' checked="checked" ';
3966: $coownersoff = ' ';
3967: }
3968: } else {
3969: $coownersoff = ' checked="checked" ';
3970: $coownerson = ' ';
3971: }
1.3 raeburn 3972: if (exists($settings->{'sender_domain'})) {
3973: $defdom = $settings->{'sender_domain'};
3974: }
1.399 raeburn 3975: if (exists($settings->{'failsafe'})) {
3976: $failsafe = $settings->{'failsafe'};
3977: if ($failsafe eq 'zero') {
1.400 raeburn 3978: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 3979: $failsafechecked{'off'} = '';
3980: $failsafesty = 'inline-block';
3981: } elsif ($failsafe eq 'any') {
3982: $failsafechecked{'any'} = ' checked="checked"';
3983: $failsafechecked{'off'} = '';
3984: }
3985: $autofailsafe = $settings->{'autofailsafe'};
3986: } elsif (exists($settings->{'autofailsafe'})) {
3987: $autofailsafe = $settings->{'autofailsafe'};
3988: if ($autofailsafe ne '') {
3989: $failsafechecked{'zero'} = ' checked="checked"';
3990: $failsafe = 'zero';
1.400 raeburn 3991: $failsafechecked{'off'} = '';
1.399 raeburn 3992: }
1.274 raeburn 3993: }
1.14 raeburn 3994: } else {
3995: if ($autorun) {
3996: $runon = ' checked="checked" ';
3997: $runoff = ' ';
3998: } else {
3999: $runoff = ' checked="checked" ';
4000: $runon = ' ';
4001: }
1.3 raeburn 4002: }
4003: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4004: my $notif_sender;
4005: if (ref($settings) eq 'HASH') {
4006: $notif_sender = $settings->{'sender_uname'};
4007: }
1.3 raeburn 4008: my $datatable='<tr class="LC_odd_row">'.
4009: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4010: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4011: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4012: $runon.' value="1" />'.&mt('Yes').'</label> '.
4013: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4014: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4015: '</tr><tr>'.
4016: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4017: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4018: &mt('username').': '.
4019: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4020: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4021: ': '.$domform.'</span></td></tr>'.
4022: '<tr class="LC_odd_row">'.
4023: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4024: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4025: '<input type="radio" name="autoassign_coowners"'.
4026: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4027: '<label><input type="radio" name="autoassign_coowners"'.
4028: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4029: '</tr><tr>'.
4030: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4031: '<td class="LC_left_item"><span class="LC_nobreak">'.
4032: '<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> '.
4033: '<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 />'.
4034: '<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 4035: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4036: '<span class="LC_nobreak">'.
4037: &mt('Threshold for number of students in section to drop: [_1]',
4038: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4039: '</span></div></td></tr>';
1.274 raeburn 4040: $$rowtotal += 4;
1.3 raeburn 4041: return $datatable;
4042: }
4043:
4044: sub print_autoupdate {
1.30 raeburn 4045: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4046: my ($enable,$datatable);
1.3 raeburn 4047: if ($position eq 'top') {
1.385 raeburn 4048: my %choices = &Apache::lonlocal::texthash (
4049: run => 'Auto-update active?',
4050: classlists => 'Update information in classlists?',
4051: unexpired => 'Skip updates for users without active or future roles?',
4052: lastactive => 'Skip updates for inactive users?',
4053: );
4054: my $itemcount = 0;
1.3 raeburn 4055: my $updateon = ' ';
4056: my $updateoff = ' checked="checked" ';
4057: if (ref($settings) eq 'HASH') {
4058: if ($settings->{'run'} eq '1') {
4059: $updateon = $updateoff;
4060: $updateoff = ' ';
4061: }
4062: }
1.385 raeburn 4063: $enable = '<tr class="LC_odd_row">'.
4064: '<td>'.$choices{'run'}.'</td>'.
4065: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4066: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4067: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4068: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4069: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4070: '</tr>';
1.385 raeburn 4071: my @toggles = ('classlists','unexpired');
4072: my %defaultchecked = ('classlists' => 'off',
4073: 'unexpired' => 'off'
4074: );
4075: $$rowtotal ++;
4076: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4077: \%choices,$itemcount,'','','left','no');
4078: $datatable = $enable.$datatable;
4079: $$rowtotal += $itemcount;
4080: my $lastactiveon = ' ';
4081: my $lastactiveoff = ' checked="checked" ';
4082: my $lastactivestyle = 'none';
4083: my $lastactivedays;
4084: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4085: if (ref($settings) eq 'HASH') {
4086: if ($settings->{'lastactive'} =~ /^\d+$/) {
4087: $lastactiveon = $lastactiveoff;
4088: $lastactiveoff = ' ';
4089: $lastactivestyle = 'inline-block';
4090: $lastactivedays = $settings->{'lastactive'};
4091: }
4092: }
4093: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4094: $datatable .= '<tr'.$css_class.'>'.
4095: '<td>'.$choices{'lastactive'}.'</td>'.
4096: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4097: '<input type="radio" name="lastactive"'.
4098: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4099: ' <label>'.
4100: '<input type="radio" name="lastactive"'.
4101: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4102: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4103: ': '.&mt('inactive = no activity in last [_1] days',
4104: '<input type="text" size="5" name="lastactivedays" value="'.
4105: $lastactivedays.'" />').
4106: '</span></td>'.
4107: '</tr>';
4108: $$rowtotal ++;
1.131 raeburn 4109: } elsif ($position eq 'middle') {
4110: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4111: my $numinrow = 3;
4112: my $locknamesettings;
4113: $datatable .= &insttypes_row($settings,$types,$usertypes,
4114: $dom,$numinrow,$othertitle,
1.305 raeburn 4115: 'lockablenames',$rowtotal);
1.131 raeburn 4116: $$rowtotal ++;
1.3 raeburn 4117: } else {
1.44 raeburn 4118: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4119: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4120: 'permanentemail','id');
1.33 raeburn 4121: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4122: my $numrows = 0;
1.26 raeburn 4123: if (ref($types) eq 'ARRAY') {
4124: if (@{$types} > 0) {
4125: $datatable =
4126: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4127: \@fields,$types,\$numrows);
1.30 raeburn 4128: $$rowtotal += @{$types};
1.26 raeburn 4129: }
1.3 raeburn 4130: }
4131: $datatable .=
4132: &usertype_update_row($settings,{'default' => $othertitle},
4133: \%fieldtitles,\@fields,['default'],
4134: \$numrows);
1.30 raeburn 4135: $$rowtotal ++;
1.3 raeburn 4136: }
4137: return $datatable;
4138: }
4139:
1.125 raeburn 4140: sub print_autocreate {
4141: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4142: my (%createon,%createoff,%currhash);
1.125 raeburn 4143: my @types = ('xml','req');
4144: if (ref($settings) eq 'HASH') {
4145: foreach my $item (@types) {
4146: $createoff{$item} = ' checked="checked" ';
4147: $createon{$item} = ' ';
4148: if (exists($settings->{$item})) {
4149: if ($settings->{$item}) {
4150: $createon{$item} = ' checked="checked" ';
4151: $createoff{$item} = ' ';
4152: }
4153: }
4154: }
1.210 raeburn 4155: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4156: $currhash{$settings->{'xmldc'}} = 1;
4157: }
1.125 raeburn 4158: } else {
4159: foreach my $item (@types) {
4160: $createoff{$item} = ' checked="checked" ';
4161: $createon{$item} = ' ';
4162: }
4163: }
4164: $$rowtotal += 2;
1.191 raeburn 4165: my $numinrow = 2;
1.125 raeburn 4166: my $datatable='<tr class="LC_odd_row">'.
4167: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4168: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4169: '<input type="radio" name="autocreate_xml"'.
4170: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4171: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4172: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4173: '</td></tr><tr>'.
4174: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4175: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4176: '<input type="radio" name="autocreate_req"'.
4177: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4178: '<label><input type="radio" name="autocreate_req"'.
4179: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4180: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4181: 'autocreate_xmldc',%currhash);
1.247 raeburn 4182: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4183: if ($numdc > 1) {
1.247 raeburn 4184: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4185: '</td><td class="LC_left_item">';
1.125 raeburn 4186: } else {
1.247 raeburn 4187: $datatable .= &mt('Course creation processed as:').
4188: '</td><td class="LC_right_item">';
1.125 raeburn 4189: }
1.247 raeburn 4190: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4191: $$rowtotal += $rows;
1.125 raeburn 4192: return $datatable;
4193: }
4194:
1.23 raeburn 4195: sub print_directorysrch {
1.277 raeburn 4196: my ($position,$dom,$settings,$rowtotal) = @_;
4197: my $datatable;
4198: if ($position eq 'top') {
4199: my $instsrchon = ' ';
4200: my $instsrchoff = ' checked="checked" ';
4201: my ($exacton,$containson,$beginson);
4202: my $instlocalon = ' ';
4203: my $instlocaloff = ' checked="checked" ';
4204: if (ref($settings) eq 'HASH') {
4205: if ($settings->{'available'} eq '1') {
4206: $instsrchon = $instsrchoff;
4207: $instsrchoff = ' ';
4208: }
4209: if ($settings->{'localonly'} eq '1') {
4210: $instlocalon = $instlocaloff;
4211: $instlocaloff = ' ';
4212: }
4213: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4214: foreach my $type (@{$settings->{'searchtypes'}}) {
4215: if ($type eq 'exact') {
4216: $exacton = ' checked="checked" ';
4217: } elsif ($type eq 'contains') {
4218: $containson = ' checked="checked" ';
4219: } elsif ($type eq 'begins') {
4220: $beginson = ' checked="checked" ';
4221: }
4222: }
4223: } else {
4224: if ($settings->{'searchtypes'} eq 'exact') {
4225: $exacton = ' checked="checked" ';
4226: } elsif ($settings->{'searchtypes'} eq 'contains') {
4227: $containson = ' checked="checked" ';
4228: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4229: $exacton = ' checked="checked" ';
4230: $containson = ' checked="checked" ';
4231: }
4232: }
1.277 raeburn 4233: }
4234: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4235: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4236:
4237: my $numinrow = 4;
4238: my $cansrchrow = 0;
4239: $datatable='<tr class="LC_odd_row">'.
4240: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4241: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4242: '<input type="radio" name="dirsrch_available"'.
4243: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4244: '<label><input type="radio" name="dirsrch_available"'.
4245: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4246: '</tr><tr>'.
4247: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4248: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4249: '<input type="radio" name="dirsrch_instlocalonly"'.
4250: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4251: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4252: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4253: '</tr>';
4254: $$rowtotal += 2;
4255: if (ref($usertypes) eq 'HASH') {
4256: if (keys(%{$usertypes}) > 0) {
4257: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4258: $numinrow,$othertitle,'cansearch',
4259: $rowtotal);
1.277 raeburn 4260: $cansrchrow = 1;
1.25 raeburn 4261: }
1.23 raeburn 4262: }
1.277 raeburn 4263: if ($cansrchrow) {
4264: $$rowtotal ++;
4265: $datatable .= '<tr>';
4266: } else {
4267: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4268: }
1.277 raeburn 4269: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4270: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4271: foreach my $title (@{$titleorder}) {
4272: if (defined($searchtitles->{$title})) {
4273: my $check = ' ';
4274: if (ref($settings) eq 'HASH') {
4275: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4276: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4277: $check = ' checked="checked" ';
4278: }
1.39 raeburn 4279: }
1.25 raeburn 4280: }
1.277 raeburn 4281: $datatable .= '<td class="LC_left_item">'.
4282: '<span class="LC_nobreak"><label>'.
4283: '<input type="checkbox" name="searchby" '.
4284: 'value="'.$title.'"'.$check.'/>'.
4285: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4286: }
4287: }
1.277 raeburn 4288: $datatable .= '</tr></table></td></tr>';
4289: $$rowtotal ++;
4290: if ($cansrchrow) {
4291: $datatable .= '<tr class="LC_odd_row">';
4292: } else {
4293: $datatable .= '<tr>';
4294: }
4295: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4296: '<td class="LC_left_item" colspan="2">'.
4297: '<span class="LC_nobreak"><label>'.
4298: '<input type="checkbox" name="searchtypes" '.
4299: $exacton.' value="exact" />'.&mt('Exact match').
4300: '</label> '.
4301: '<label><input type="checkbox" name="searchtypes" '.
4302: $beginson.' value="begins" />'.&mt('Begins with').
4303: '</label> '.
4304: '<label><input type="checkbox" name="searchtypes" '.
4305: $containson.' value="contains" />'.&mt('Contains').
4306: '</label></span></td></tr>';
4307: $$rowtotal ++;
1.26 raeburn 4308: } else {
1.277 raeburn 4309: my $domsrchon = ' checked="checked" ';
4310: my $domsrchoff = ' ';
4311: my $domlocalon = ' ';
4312: my $domlocaloff = ' checked="checked" ';
4313: if (ref($settings) eq 'HASH') {
4314: if ($settings->{'lclocalonly'} eq '1') {
4315: $domlocalon = $domlocaloff;
4316: $domlocaloff = ' ';
4317: }
4318: if ($settings->{'lcavailable'} eq '0') {
4319: $domsrchoff = $domsrchon;
4320: $domsrchon = ' ';
4321: }
4322: }
4323: $datatable='<tr class="LC_odd_row">'.
4324: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4325: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4326: '<input type="radio" name="dirsrch_domavailable"'.
4327: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4328: '<label><input type="radio" name="dirsrch_domavailable"'.
4329: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4330: '</tr><tr>'.
4331: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4332: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4333: '<input type="radio" name="dirsrch_domlocalonly"'.
4334: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4335: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4336: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4337: '</tr>';
4338: $$rowtotal += 2;
1.26 raeburn 4339: }
1.25 raeburn 4340: return $datatable;
4341: }
4342:
1.28 raeburn 4343: sub print_contacts {
1.286 raeburn 4344: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4345: my $datatable;
4346: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4347: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4348: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4349: if ($position eq 'top') {
4350: if (ref($settings) eq 'HASH') {
4351: foreach my $item (@contacts) {
4352: if (exists($settings->{$item})) {
4353: $to{$item} = $settings->{$item};
4354: }
4355: }
4356: }
4357: } elsif ($position eq 'middle') {
4358: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4359: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4360: foreach my $type (@mailings) {
4361: $otheremails{$type} = '';
4362: }
1.340 raeburn 4363: } elsif ($position eq 'lower') {
4364: if (ref($settings) eq 'HASH') {
4365: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4366: %lonstatus = %{$settings->{'lonstatus'}};
4367: }
4368: }
1.286 raeburn 4369: } else {
4370: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4371: foreach my $type (@mailings) {
4372: $otheremails{$type} = '';
4373: }
1.286 raeburn 4374: $bccemails{'helpdeskmail'} = '';
4375: $bccemails{'otherdomsmail'} = '';
4376: $includestr{'helpdeskmail'} = '';
4377: $includestr{'otherdomsmail'} = '';
4378: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4379: }
1.28 raeburn 4380: if (ref($settings) eq 'HASH') {
1.340 raeburn 4381: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4382: foreach my $type (@mailings) {
4383: if (exists($settings->{$type})) {
4384: if (ref($settings->{$type}) eq 'HASH') {
4385: foreach my $item (@contacts) {
4386: if ($settings->{$type}{$item}) {
4387: $checked{$type}{$item} = ' checked="checked" ';
4388: }
4389: }
4390: $otheremails{$type} = $settings->{$type}{'others'};
4391: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4392: $bccemails{$type} = $settings->{$type}{'bcc'};
4393: if ($settings->{$type}{'include'} ne '') {
4394: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4395: $includestr{$type} = &unescape($includestr{$type});
4396: }
4397: }
4398: }
4399: } elsif ($type eq 'lonstatusmail') {
4400: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4401: }
1.28 raeburn 4402: }
4403: }
1.286 raeburn 4404: if ($position eq 'bottom') {
4405: foreach my $type (@mailings) {
4406: $bccemails{$type} = $settings->{$type}{'bcc'};
4407: if ($settings->{$type}{'include'} ne '') {
4408: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4409: $includestr{$type} = &unescape($includestr{$type});
4410: }
4411: }
4412: if (ref($settings->{'helpform'}) eq 'HASH') {
4413: if (ref($fields) eq 'ARRAY') {
4414: foreach my $field (@{$fields}) {
4415: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4416: }
1.286 raeburn 4417: }
4418: if (exists($settings->{'helpform'}{'maxsize'})) {
4419: $maxsize = $settings->{'helpform'}{'maxsize'};
4420: } else {
1.289 raeburn 4421: $maxsize = '1.0';
1.286 raeburn 4422: }
4423: } else {
4424: if (ref($fields) eq 'ARRAY') {
4425: foreach my $field (@{$fields}) {
4426: $currfield{$field} = 'yes';
1.134 raeburn 4427: }
1.28 raeburn 4428: }
1.286 raeburn 4429: $maxsize = '1.0';
1.28 raeburn 4430: }
4431: }
4432: } else {
1.286 raeburn 4433: if ($position eq 'top') {
4434: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4435: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4436: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4437: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4438: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4439: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4440: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4441: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4442: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4443: } elsif ($position eq 'bottom') {
4444: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4445: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4446: if (ref($fields) eq 'ARRAY') {
4447: foreach my $field (@{$fields}) {
4448: $currfield{$field} = 'yes';
4449: }
4450: }
4451: $maxsize = '1.0';
4452: }
1.28 raeburn 4453: }
4454: my ($titles,$short_titles) = &contact_titles();
4455: my $rownum = 0;
4456: my $css_class;
1.286 raeburn 4457: if ($position eq 'top') {
4458: foreach my $item (@contacts) {
4459: $css_class = $rownum%2?' class="LC_odd_row"':'';
4460: $datatable .= '<tr'.$css_class.'>'.
4461: '<td><span class="LC_nobreak">'.$titles->{$item}.
4462: '</span></td><td class="LC_right_item">'.
4463: '<input type="text" name="'.$item.'" value="'.
4464: $to{$item}.'" /></td></tr>';
4465: $rownum ++;
4466: }
1.315 raeburn 4467: } elsif ($position eq 'bottom') {
4468: $css_class = $rownum%2?' class="LC_odd_row"':'';
4469: $datatable .= '<tr'.$css_class.'>'.
4470: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4471: &mt('(e-mail, subject, and description always shown)').
4472: '</td><td class="LC_left_item">';
4473: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4474: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4475: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4476: foreach my $field (@{$fields}) {
4477: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4478: if (($field eq 'screenshot') || ($field eq 'cc')) {
4479: $datatable .= ' '.&mt('(logged-in users)');
4480: }
4481: $datatable .='</td><td>';
4482: my $clickaction;
4483: if ($field eq 'screenshot') {
4484: $clickaction = ' onclick="screenshotSize(this);"';
4485: }
4486: if (ref($possoptions->{$field}) eq 'ARRAY') {
4487: foreach my $option (@{$possoptions->{$field}}) {
4488: my $checked;
4489: if ($currfield{$field} eq $option) {
4490: $checked = ' checked="checked"';
4491: }
4492: $datatable .= '<span class="LC_nobreak"><label>'.
4493: '<input type="radio" name="helpform_'.$field.'" '.
4494: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4495: '</label></span>'.(' 'x2);
4496: }
4497: }
4498: if ($field eq 'screenshot') {
4499: my $display;
4500: if ($currfield{$field} eq 'no') {
4501: $display = ' style="display:none"';
4502: }
1.334 raeburn 4503: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4504: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4505: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4506: }
4507: $datatable .= '</td></tr>';
4508: }
4509: $datatable .= '</table>';
4510: }
4511: $datatable .= '</td></tr>'."\n";
4512: $rownum ++;
4513: }
1.340 raeburn 4514: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4515: foreach my $type (@mailings) {
4516: $css_class = $rownum%2?' class="LC_odd_row"':'';
4517: $datatable .= '<tr'.$css_class.'>'.
4518: '<td><span class="LC_nobreak">'.
4519: $titles->{$type}.': </span></td>'.
4520: '<td class="LC_left_item">';
4521: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4522: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4523: }
4524: $datatable .= '<span class="LC_nobreak">';
4525: foreach my $item (@contacts) {
4526: $datatable .= '<label>'.
4527: '<input type="checkbox" name="'.$type.'"'.
4528: $checked{$type}{$item}.
4529: ' value="'.$item.'" />'.$short_titles->{$item}.
4530: '</label> ';
4531: }
4532: $datatable .= '</span><br />'.&mt('Others').': '.
4533: '<input type="text" name="'.$type.'_others" '.
4534: 'value="'.$otheremails{$type}.'" />';
4535: my %locchecked;
4536: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4537: foreach my $loc ('s','b') {
4538: if ($includeloc{$type} eq $loc) {
4539: $locchecked{$loc} = ' checked="checked"';
4540: last;
4541: }
4542: }
4543: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4544: '<input type="text" name="'.$type.'_bcc" '.
4545: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4546: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4547: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4548: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4549: '<span class="LC_nobreak">'.&mt('Location:').' '.
4550: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4551: (' 'x2).
4552: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4553: '</span></fieldset>';
4554: }
4555: $datatable .= '</td></tr>'."\n";
4556: $rownum ++;
4557: }
1.28 raeburn 4558: }
1.286 raeburn 4559: if ($position eq 'middle') {
4560: my %choices;
1.340 raeburn 4561: my $corelink = &core_link_msu();
4562: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4563: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4564: $corelink);
4565: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4566: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4567: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4568: 'reportupdates' => 'on',
4569: 'reportstatus' => 'on');
1.286 raeburn 4570: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4571: \%choices,$rownum);
4572: $datatable .= $reports;
1.340 raeburn 4573: } elsif ($position eq 'lower') {
1.378 raeburn 4574: my (%current,%excluded,%weights);
1.340 raeburn 4575: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4576: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4577: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4578: } else {
1.378 raeburn 4579: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4580: }
4581: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4582: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4583: } else {
1.378 raeburn 4584: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4585: }
4586: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4587: foreach my $type ('E','W','N','U') {
1.340 raeburn 4588: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4589: $weights{$type} = $lonstatus{'weights'}{$type};
4590: } else {
4591: $weights{$type} = $defaults->{$type};
4592: }
4593: }
4594: } else {
1.341 raeburn 4595: foreach my $type ('E','W','N','U') {
1.340 raeburn 4596: $weights{$type} = $defaults->{$type};
4597: }
4598: }
4599: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4600: if (@{$lonstatus{'excluded'}} > 0) {
4601: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4602: }
4603: }
1.378 raeburn 4604: foreach my $item ('errorthreshold','errorsysmail') {
4605: $css_class = $rownum%2?' class="LC_odd_row"':'';
4606: $datatable .= '<tr'.$css_class.'>'.
4607: '<td class="LC_left_item"><span class="LC_nobreak">'.
4608: $titles->{$item}.
4609: '</span></td><td class="LC_left_item">'.
4610: '<input type="text" name="'.$item.'" value="'.
4611: $current{$item}.'" size="5" /></td></tr>';
4612: $rownum ++;
4613: }
1.340 raeburn 4614: $css_class = $rownum%2?' class="LC_odd_row"':'';
4615: $datatable .= '<tr'.$css_class.'>'.
4616: '<td class="LC_left_item">'.
4617: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4618: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4619: foreach my $type ('E','W','N','U') {
1.340 raeburn 4620: $datatable .= '<td>'.$names->{$type}.'<br />'.
4621: '<input type="text" name="errorweights_'.$type.'" value="'.
4622: $weights{$type}.'" size="5" /></td>';
4623: }
4624: $datatable .= '</tr></table></tr>';
4625: $rownum ++;
4626: $css_class = $rownum%2?' class="LC_odd_row"':'';
4627: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4628: $titles->{'errorexcluded'}.'</td>'.
4629: '<td class="LC_left_item"><table>';
4630: my $numinrow = 4;
4631: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4632: for (my $i=0; $i<@ids; $i++) {
4633: my $rem = $i%($numinrow);
4634: if ($rem == 0) {
4635: if ($i > 0) {
4636: $datatable .= '</tr>';
4637: }
4638: $datatable .= '<tr>';
4639: }
4640: my $check;
4641: if ($excluded{$ids[$i]}) {
4642: $check = ' checked="checked" ';
4643: }
4644: $datatable .= '<td class="LC_left_item">'.
4645: '<span class="LC_nobreak"><label>'.
4646: '<input type="checkbox" name="errorexcluded" '.
4647: 'value="'.$ids[$i].'"'.$check.' />'.
4648: $ids[$i].'</label></span></td>';
4649: }
4650: my $colsleft = $numinrow - @ids%($numinrow);
4651: if ($colsleft > 1 ) {
4652: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4653: ' </td>';
4654: } elsif ($colsleft == 1) {
4655: $datatable .= '<td class="LC_left_item"> </td>';
4656: }
4657: $datatable .= '</tr></table></td></tr>';
4658: $rownum ++;
1.286 raeburn 4659: } elsif ($position eq 'bottom') {
1.315 raeburn 4660: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4661: my (@posstypes,%usertypeshash);
4662: if (ref($types) eq 'ARRAY') {
4663: @posstypes = @{$types};
4664: }
4665: if (@posstypes) {
4666: if (ref($usertypes) eq 'HASH') {
4667: %usertypeshash = %{$usertypes};
4668: }
4669: my @overridden;
4670: my $numinrow = 4;
4671: if (ref($settings) eq 'HASH') {
4672: if (ref($settings->{'overrides'}) eq 'HASH') {
4673: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4674: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4675: push(@overridden,$key);
4676: foreach my $item (@contacts) {
4677: if ($settings->{'overrides'}{$key}{$item}) {
4678: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4679: }
4680: }
4681: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4682: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4683: $includeloc{'override_'.$key} = '';
4684: $includestr{'override_'.$key} = '';
4685: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4686: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4687: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4688: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4689: }
1.286 raeburn 4690: }
4691: }
4692: }
1.315 raeburn 4693: }
4694: my $customclass = 'LC_helpdesk_override';
4695: my $optionsprefix = 'LC_options_helpdesk_';
4696:
4697: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4698:
4699: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4700: $numinrow,$othertitle,'overrides',
4701: \$rownum,$onclicktypes,$customclass);
4702: $rownum ++;
4703: $usertypeshash{'default'} = $othertitle;
4704: foreach my $status (@posstypes) {
4705: my $css_class;
4706: if ($rownum%2) {
4707: $css_class = 'LC_odd_row ';
4708: }
4709: $css_class .= $customclass;
4710: my $rowid = $optionsprefix.$status;
4711: my $hidden = 1;
4712: my $currstyle = 'display:none';
4713: if (grep(/^\Q$status\E$/,@overridden)) {
4714: $currstyle = 'display:table-row';
4715: $hidden = 0;
4716: }
4717: my $key = 'override_'.$status;
4718: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4719: $includeloc{$key},$includestr{$key},$status,$rowid,
4720: $usertypeshash{$status},$css_class,$currstyle,
4721: \@contacts,$short_titles);
4722: unless ($hidden) {
4723: $rownum ++;
1.286 raeburn 4724: }
4725: }
1.134 raeburn 4726: }
1.28 raeburn 4727: }
1.30 raeburn 4728: $$rowtotal += $rownum;
1.28 raeburn 4729: return $datatable;
4730: }
4731:
1.340 raeburn 4732: sub core_link_msu {
4733: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4734: &mt('LON-CAPA core group - MSU'),600,500);
4735: }
4736:
1.315 raeburn 4737: sub overridden_helpdesk {
4738: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4739: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4740: my $class = 'LC_left_item';
4741: if ($css_class) {
4742: $css_class = ' class="'.$css_class.'"';
4743: }
4744: if ($rowid) {
4745: $rowid = ' id="'.$rowid.'"';
4746: }
4747: if ($rowstyle) {
4748: $rowstyle = ' style="'.$rowstyle.'"';
4749: }
4750: my ($output,$description);
4751: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4752: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4753: "<td>$description</td>\n".
4754: '<td class="'.$class.'" colspan="2">'.
4755: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4756: '<span class="LC_nobreak">';
4757: if (ref($contacts) eq 'ARRAY') {
4758: foreach my $item (@{$contacts}) {
4759: my $check;
4760: if (ref($checked) eq 'HASH') {
4761: $check = $checked->{$item};
4762: }
4763: my $title;
4764: if (ref($short_titles) eq 'HASH') {
4765: $title = $short_titles->{$item};
4766: }
4767: $output .= '<label>'.
4768: '<input type="checkbox" name="override_'.$type.'"'.$check.
4769: ' value="'.$item.'" />'.$title.'</label> ';
4770: }
4771: }
4772: $output .= '</span><br />'.&mt('Others').': '.
4773: '<input type="text" name="override_'.$type.'_others" '.
4774: 'value="'.$otheremails.'" />';
4775: my %locchecked;
4776: foreach my $loc ('s','b') {
4777: if ($includeloc eq $loc) {
4778: $locchecked{$loc} = ' checked="checked"';
4779: last;
4780: }
4781: }
4782: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4783: '<input type="text" name="override_'.$type.'_bcc" '.
4784: 'value="'.$bccemails.'" /></fieldset>'.
4785: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4786: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4787: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4788: '<span class="LC_nobreak">'.&mt('Location:').' '.
4789: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4790: (' 'x2).
4791: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4792: '</span></fieldset>'.
4793: '</td></tr>'."\n";
4794: return $output;
4795: }
4796:
1.286 raeburn 4797: sub contacts_javascript {
4798: return <<"ENDSCRIPT";
4799:
4800: <script type="text/javascript">
4801: // <![CDATA[
4802:
4803: function screenshotSize(field) {
4804: if (document.getElementById('help_screenshotsize')) {
4805: if (field.value == 'no') {
1.289 raeburn 4806: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4807: } else {
4808: document.getElementById('help_screenshotsize').style.display="";
4809: }
4810: }
4811: return;
4812: }
4813:
1.315 raeburn 4814: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4815: if (form.elements[checkbox].length != undefined) {
4816: var count = 0;
4817: if (docount) {
4818: for (var i=0; i<form.elements[checkbox].length; i++) {
4819: if (form.elements[checkbox][i].checked) {
4820: count ++;
4821: }
4822: }
4823: }
4824: for (var i=0; i<form.elements[checkbox].length; i++) {
4825: var type = form.elements[checkbox][i].value;
4826: if (document.getElementById(prefix+type)) {
4827: if (form.elements[checkbox][i].checked) {
4828: document.getElementById(prefix+type).style.display = 'table-row';
4829: if (count % 2 == 1) {
4830: document.getElementById(prefix+type).className = target+' LC_odd_row';
4831: } else {
4832: document.getElementById(prefix+type).className = target;
4833: }
4834: count ++;
4835: } else {
4836: document.getElementById(prefix+type).style.display = 'none';
4837: }
4838: }
4839: }
4840: }
4841: return;
4842: }
4843:
4844:
1.286 raeburn 4845: // ]]>
4846: </script>
4847:
4848: ENDSCRIPT
4849: }
4850:
1.118 jms 4851: sub print_helpsettings {
1.282 raeburn 4852: my ($position,$dom,$settings,$rowtotal) = @_;
4853: my $confname = $dom.'-domainconfig';
1.285 raeburn 4854: my $formname = 'display';
1.168 raeburn 4855: my ($datatable,$itemcount);
1.282 raeburn 4856: if ($position eq 'top') {
4857: $itemcount = 1;
4858: my (%choices,%defaultchecked,@toggles);
4859: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4860: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4861: &mt('LON-CAPA bug tracker'),600,500));
4862: %defaultchecked = ('submitbugs' => 'on');
4863: @toggles = ('submitbugs');
4864: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4865: \%choices,$itemcount);
4866: $$rowtotal ++;
4867: } else {
4868: my $css_class;
4869: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4870: my (%customroles,%ordered,%current);
1.301 raeburn 4871: if (ref($settings) eq 'HASH') {
4872: if (ref($settings->{'adhoc'}) eq 'HASH') {
4873: %current = %{$settings->{'adhoc'}};
4874: }
1.285 raeburn 4875: }
4876: my $count = 0;
4877: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4878: if ($key=~/^rolesdef\_(\w+)$/) {
4879: my $rolename = $1;
1.285 raeburn 4880: my (%privs,$order);
1.282 raeburn 4881: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4882: $customroles{$rolename} = \%privs;
1.285 raeburn 4883: if (ref($current{$rolename}) eq 'HASH') {
4884: $order = $current{$rolename}{'order'};
4885: }
4886: if ($order eq '') {
4887: $order = $count;
4888: }
4889: $ordered{$order} = $rolename;
4890: $count++;
4891: }
4892: }
4893: my $maxnum = scalar(keys(%ordered));
4894: my @roles_by_num = ();
4895: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4896: push(@roles_by_num,$item);
4897: }
4898: my $context = 'domprefs';
4899: my $crstype = 'Course';
4900: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4901: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4902: my ($numstatustypes,@jsarray);
4903: if (ref($types) eq 'ARRAY') {
4904: if (@{$types} > 0) {
4905: $numstatustypes = scalar(@{$types});
4906: push(@accesstypes,'status');
4907: @jsarray = ('bystatus');
1.282 raeburn 4908: }
4909: }
1.290 raeburn 4910: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4911: if (keys(%domhelpdesk)) {
4912: push(@accesstypes,('inc','exc'));
4913: push(@jsarray,('notinc','notexc'));
4914: }
4915: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4916: my $context = 'domprefs';
4917: my $crstype = 'Course';
1.285 raeburn 4918: my $prefix = 'helproles_';
4919: my $add_class = 'LC_hidden';
4920: foreach my $num (@roles_by_num) {
4921: my $role = $ordered{$num};
4922: my ($desc,$access,@statuses);
4923: if (ref($current{$role}) eq 'HASH') {
4924: $desc = $current{$role}{'desc'};
4925: $access = $current{$role}{'access'};
4926: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4927: @statuses = @{$current{$role}{'insttypes'}};
4928: }
4929: }
4930: if ($desc eq '') {
4931: $desc = $role;
4932: }
4933: my $identifier = 'custhelp'.$num;
1.282 raeburn 4934: my %full=();
4935: my %levels= (
4936: course => {},
4937: domain => {},
4938: system => {},
4939: );
4940: my %levelscurrent=(
4941: course => {},
4942: domain => {},
4943: system => {},
4944: );
4945: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4946: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4947: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4948: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4949: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4950: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4951: for (my $k=0; $k<=$maxnum; $k++) {
4952: my $vpos = $k+1;
4953: my $selstr;
4954: if ($k == $num) {
4955: $selstr = ' selected="selected" ';
4956: }
4957: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4958: }
4959: $datatable .= '</select>'.(' 'x2).
4960: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4961: '</td>'.
4962: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4963: &mt('Name shown to users:').
4964: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4965: '</fieldset>'.
4966: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4967: $othertitle,$usertypes,$types,\%domhelpdesk).
4968: '<fieldset>'.
4969: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4970: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4971: \%levelscurrent,$identifier,
4972: 'LC_hidden',$prefix.$num.'_privs').
4973: '</fieldset></td>';
1.282 raeburn 4974: $itemcount ++;
4975: }
4976: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4977: my $newcust = 'custhelp'.$count;
4978: my (%privs,%levelscurrent);
4979: my %full=();
4980: my %levels= (
4981: course => {},
4982: domain => {},
4983: system => {},
4984: );
4985: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4986: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4987: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4988: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4989: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4990: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4991: for (my $k=0; $k<$maxnum+1; $k++) {
4992: my $vpos = $k+1;
4993: my $selstr;
4994: if ($k == $maxnum) {
4995: $selstr = ' selected="selected" ';
4996: }
4997: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4998: }
4999: $datatable .= '</select> '."\n".
1.282 raeburn 5000: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5001: '</label></span></td>'.
1.285 raeburn 5002: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5003: '<span class="LC_nobreak">'.
5004: &mt('Internal name:').
5005: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5006: '</span>'.(' 'x4).
5007: '<span class="LC_nobreak">'.
5008: &mt('Name shown to users:').
5009: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5010: '</span></fieldset>'.
5011: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5012: $usertypes,$types,\%domhelpdesk).
5013: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5014: &Apache::lonuserutils::custom_role_header($context,$crstype,
5015: \@templateroles,$newcust).
5016: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5017: \%levelscurrent,$newcust).
1.334 raeburn 5018: '</fieldset>'.
5019: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5020: '</td></tr>';
1.282 raeburn 5021: $count ++;
5022: $$rowtotal += $count;
5023: }
1.166 raeburn 5024: return $datatable;
1.121 raeburn 5025: }
5026:
1.285 raeburn 5027: sub adhocbutton {
5028: my ($prefix,$num,$field,$visibility) = @_;
5029: my %lt = &Apache::lonlocal::texthash(
5030: show => 'Show details',
5031: hide => 'Hide details',
5032: );
5033: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5034: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5035: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5036: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5037: }
5038:
5039: sub helpsettings_javascript {
5040: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5041: return unless(ref($roles_by_num) eq 'ARRAY');
5042: my %html_js_lt = &Apache::lonlocal::texthash(
5043: show => 'Show details',
5044: hide => 'Hide details',
5045: );
5046: &html_escape(\%html_js_lt);
5047: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5048: return <<"ENDSCRIPT";
5049: <script type="text/javascript">
5050: // <![CDATA[
5051:
5052: function reorderHelpRoles(form,item) {
5053: var changedVal;
5054: $jstext
5055: var newpos = 'helproles_${total}_pos';
5056: var maxh = 1 + $total;
5057: var current = new Array();
5058: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5059: if (item == newpos) {
5060: changedVal = newitemVal;
5061: } else {
5062: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5063: current[newitemVal] = newpos;
5064: }
5065: for (var i=0; i<helproles.length; i++) {
5066: var elementName = 'helproles_'+helproles[i]+'_pos';
5067: if (elementName != item) {
5068: if (form.elements[elementName]) {
5069: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5070: current[currVal] = elementName;
5071: }
5072: }
5073: }
5074: var oldVal;
5075: for (var j=0; j<maxh; j++) {
5076: if (current[j] == undefined) {
5077: oldVal = j;
5078: }
5079: }
5080: if (oldVal < changedVal) {
5081: for (var k=oldVal+1; k<=changedVal ; k++) {
5082: var elementName = current[k];
5083: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5084: }
5085: } else {
5086: for (var k=changedVal; k<oldVal; k++) {
5087: var elementName = current[k];
5088: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5089: }
5090: }
5091: return;
5092: }
5093:
5094: function helpdeskAccess(num) {
5095: var curraccess = null;
5096: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5097: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5098: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5099: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5100: }
5101: }
5102: }
5103: var shown = Array();
5104: var hidden = Array();
5105: if (curraccess == 'none') {
5106: hidden = Array('$hiddenstr');
5107: } else {
5108: if (curraccess == 'status') {
5109: shown = Array('bystatus');
5110: hidden = Array('notinc','notexc');
5111: } else {
5112: if (curraccess == 'exc') {
5113: shown = Array('notexc');
5114: hidden = Array('notinc','bystatus');
5115: }
5116: if (curraccess == 'inc') {
5117: shown = Array('notinc');
5118: hidden = Array('notexc','bystatus');
5119: }
1.293 raeburn 5120: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5121: hidden = Array('notinc','notexc','bystatus');
5122: }
5123: }
5124: }
5125: if (hidden.length > 0) {
5126: for (var i=0; i<hidden.length; i++) {
5127: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5128: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5129: }
5130: }
5131: }
5132: if (shown.length > 0) {
5133: for (var i=0; i<shown.length; i++) {
5134: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5135: if (shown[i] == 'privs') {
5136: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5137: } else {
5138: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5139: }
5140: }
5141: }
5142: }
5143: return;
5144: }
5145:
5146: function toggleHelpdeskItem(num,field) {
5147: if (document.getElementById('helproles_'+num+'_'+field)) {
5148: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5149: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5150: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5151: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5152: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5153: }
5154: } else {
5155: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5156: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5157: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5158: }
5159: }
5160: }
5161: return;
5162: }
5163:
5164: // ]]>
5165: </script>
5166:
5167: ENDSCRIPT
5168: }
5169:
5170: sub helpdeskroles_access {
5171: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5172: $usertypes,$types,$domhelpdesk) = @_;
5173: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5174: my %lt = &Apache::lonlocal::texthash(
5175: 'rou' => 'Role usage',
5176: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5177: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5178: 'dh' => 'All with domain helpdesk role',
5179: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5180: 'none' => 'None',
5181: 'status' => 'Determined based on institutional status',
5182: 'inc' => 'Include all, but exclude specific personnel',
5183: 'exc' => 'Exclude all, but include specific personnel',
5184: );
5185: my %usecheck = (
5186: all => ' checked="checked"',
5187: );
5188: my %displaydiv = (
5189: status => 'none',
5190: inc => 'none',
5191: exc => 'none',
5192: priv => 'block',
5193: );
5194: my $output;
5195: if (ref($current) eq 'HASH') {
5196: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5197: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5198: $usecheck{$current->{access}} = $usecheck{'all'};
5199: delete($usecheck{'all'});
5200: if ($current->{access} =~ /^(status|inc|exc)$/) {
5201: my $access = $1;
5202: $displaydiv{$access} = 'inline';
5203: } elsif ($current->{access} eq 'none') {
5204: $displaydiv{'priv'} = 'none';
5205: }
5206: }
5207: }
5208: }
5209: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5210: '<p>'.$lt{'whi'}.'</p>';
5211: foreach my $access (@{$accesstypes}) {
5212: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5213: ' onclick="helpdeskAccess('."'$num'".');" />'.
5214: $lt{$access}.'</label>';
5215: if ($access eq 'status') {
5216: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5217: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5218: $othertitle,$usertypes,$types).
5219: '</div>';
5220: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5221: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5222: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5223: '</div>';
5224: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5225: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5226: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5227: '</div>';
5228: }
5229: $output .= '</p>';
5230: }
5231: $output .= '</fieldset>';
5232: return $output;
5233: }
5234:
1.121 raeburn 5235: sub radiobutton_prefs {
1.192 raeburn 5236: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5237: $additional,$align,$firstval) = @_;
1.121 raeburn 5238: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5239: (ref($choices) eq 'HASH'));
5240:
1.170 raeburn 5241: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5242:
5243: foreach my $item (@{$toggles}) {
5244: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5245: $checkedon{$item} = ' checked="checked" ';
5246: $checkedoff{$item} = ' ';
1.121 raeburn 5247: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5248: $checkedoff{$item} = ' checked="checked" ';
5249: $checkedon{$item} = ' ';
5250: }
5251: }
5252: if (ref($settings) eq 'HASH') {
1.121 raeburn 5253: foreach my $item (@{$toggles}) {
1.118 jms 5254: if ($settings->{$item} eq '1') {
5255: $checkedon{$item} = ' checked="checked" ';
5256: $checkedoff{$item} = ' ';
5257: } elsif ($settings->{$item} eq '0') {
5258: $checkedoff{$item} = ' checked="checked" ';
5259: $checkedon{$item} = ' ';
5260: }
5261: }
1.121 raeburn 5262: }
1.192 raeburn 5263: if ($onclick) {
5264: $onclick = ' onclick="'.$onclick.'"';
5265: }
1.121 raeburn 5266: foreach my $item (@{$toggles}) {
1.118 jms 5267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5268: $datatable .=
1.306 raeburn 5269: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5270: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5271: '</span></td>';
5272: if ($align eq 'left') {
5273: $datatable .= '<td class="LC_left_item">';
5274: } else {
5275: $datatable .= '<td class="LC_right_item">';
5276: }
1.385 raeburn 5277: $datatable .= '<span class="LC_nobreak">';
5278: if ($firstval eq 'no') {
5279: $datatable .=
5280: '<label><input type="radio" name="'.
5281: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5282: '</label> <label><input type="radio" name="'.$item.'" '.
5283: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5284: } else {
5285: $datatable .=
5286: '<label><input type="radio" name="'.
5287: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5288: '</label> <label><input type="radio" name="'.$item.'" '.
5289: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5290: }
5291: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5292: $itemcount ++;
1.121 raeburn 5293: }
5294: return ($datatable,$itemcount);
5295: }
5296:
1.267 raeburn 5297: sub print_ltitools {
1.421 raeburn 5298: my ($position,$dom,$settings,$rowtotal) = @_;
5299: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5300: if (ref($settings) eq 'HASH') {
1.421 raeburn 5301: if ($position eq 'top') {
5302: if (exists($settings->{'encrypt'})) {
5303: if (ref($settings->{'encrypt'}) eq 'HASH') {
5304: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5305: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5306: }
5307: }
1.267 raeburn 5308: }
1.421 raeburn 5309: if (exists($settings->{'private'})) {
5310: if (ref($settings->{'private'}) eq 'HASH') {
5311: if (ref($settings->{'private'}) eq 'HASH') {
5312: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5313: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5314: }
5315: }
5316: }
5317: }
1.421 raeburn 5318: } elsif ($position eq 'middle') {
5319: if (exists($settings->{'rules'})) {
5320: if (ref($settings->{'rules'}) eq 'HASH') {
5321: %rules = %{$settings->{'rules'}};
1.273 raeburn 5322: }
5323: }
1.421 raeburn 5324: } else {
5325: foreach my $key ('encrypt','private','rules') {
5326: if (exists($settings->{$key})) {
5327: delete($settings->{$key});
1.267 raeburn 5328: }
5329: }
5330: }
5331: }
1.421 raeburn 5332: my $datatable;
5333: my $itemcount = 1;
5334: if ($position eq 'top') {
5335: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5336: } elsif ($position eq 'middle') {
5337: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5338: $$rowtotal += $itemcount;
5339: } else {
5340: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5341: }
5342: return $datatable;
5343: }
5344:
5345: sub ltitools_names {
5346: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5347: 'title' => 'Title',
5348: 'version' => 'Version',
5349: 'msgtype' => 'Message Type',
1.323 raeburn 5350: 'sigmethod' => 'Signature Method',
1.296 raeburn 5351: 'url' => 'URL',
5352: 'key' => 'Key',
1.322 raeburn 5353: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5354: 'secret' => 'Secret',
5355: 'icon' => 'Icon',
1.324 raeburn 5356: 'user' => 'User',
1.296 raeburn 5357: 'fullname' => 'Full Name',
5358: 'firstname' => 'First Name',
5359: 'lastname' => 'Last Name',
5360: 'email' => 'E-mail',
5361: 'roles' => 'Role',
1.298 raeburn 5362: 'window' => 'Window',
5363: 'tab' => 'Tab',
1.296 raeburn 5364: 'iframe' => 'iFrame',
5365: 'height' => 'Height',
5366: 'width' => 'Width',
5367: 'linktext' => 'Default Link Text',
5368: 'explanation' => 'Default Explanation',
5369: 'passback' => 'Tool can return grades:',
5370: 'roster' => 'Tool can retrieve roster:',
5371: 'crstarget' => 'Display target',
5372: 'crslabel' => 'Course label',
5373: 'crstitle' => 'Course title',
5374: 'crslinktext' => 'Link Text',
5375: 'crsexplanation' => 'Explanation',
1.318 raeburn 5376: 'crsappend' => 'Provider URL',
1.267 raeburn 5377: );
5378: return %lt;
5379: }
5380:
1.421 raeburn 5381: sub secrets_form {
5382: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5383: my @ids=&Apache::lonnet::current_machine_ids();
5384: my %servers = &Apache::lonnet::get_servers($dom,'library');
5385: my $primary = &Apache::lonnet::domain($dom,'primary');
5386: my ($css_class,$extra,$numshown,$itemcount,$output);
5387: $itemcount = 0;
5388: foreach my $hostid (sort(keys(%servers))) {
5389: my ($showextra,$divsty,$switch);
5390: if ($hostid eq $primary) {
5391: if ($context eq 'ltisec') {
5392: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5393: $showextra = 1;
5394: }
5395: if ($encrypt->{'ltisec_crslinkprot'}) {
5396: $showextra = 1;
5397: }
5398: } else {
5399: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5400: $showextra = 1;
5401: }
5402: }
5403: unless (grep(/^\Q$hostid\E$/,@ids)) {
5404: $switch = 1;
5405: }
5406: if ($showextra) {
5407: $numshown ++;
5408: $divsty = 'display:inline-block';
5409: } else {
5410: $divsty = 'display:none';
5411: }
5412: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5413: '<legend>'.$hostid.'</legend>';
5414: if ($switch) {
5415: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5416: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5417: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5418: if (exists($privkeys->{$hostid})) {
5419: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5420: '<span class="LC_nobreak">'.
5421: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5422: '<span class="LC_nobreak">'.&mt('Change?').
5423: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5424: (' 'x2).
5425: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5426: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5427: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5428: '</span></div>';
5429: } else {
5430: $extra .= '<span class="LC_nobreak">'.
5431: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5432: '</span>'."\n";
5433: }
5434: } elsif (exists($privkeys->{$hostid})) {
5435: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5436: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5437: '<span class="LC_nobreak">'.&mt('Change?').
5438: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5439: (' 'x2).
5440: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5441: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5442: '<span class="LC_nobreak">'.&mt('New Key').':'.
5443: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5444: '<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>'.
5445: '</span></div>';
5446: } else {
5447: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5448: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5449: '<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>';
5450: }
5451: $extra .= '</fieldset>';
5452: }
5453: }
5454: my (%choices,@toggles,%defaultchecked);
5455: if ($context eq 'ltisec') {
5456: %choices = &Apache::lonlocal::texthash (
5457: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5458: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5459: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5460: );
5461: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5462: %defaultchecked = (
5463: 'ltisec_crslinkprot' => 'off',
5464: 'ltisec_domlinkprot' => 'off',
5465: 'ltisec_consumers' => 'off',
5466: );
5467: } else {
5468: %choices = &Apache::lonlocal::texthash (
5469: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5470: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5471: );
5472: @toggles = qw(toolsec_crs toolsec_dom);
5473: %defaultchecked = (
5474: 'toolsec_crs' => 'off',
5475: 'toolsec_dom' => 'off',
5476: );
5477: }
5478: my ($onclick,$itemcount);
5479: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5480: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5481: \%choices,$itemcount,$onclick,'','left','no');
5482:
5483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5484: my $noprivkeysty = 'display:inline-block';
5485: if ($numshown) {
5486: $noprivkeysty = 'display:none';
5487: }
5488: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5489: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5490: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5491: $extra.
5492: '</td></tr>';
5493: $itemcount ++;
5494: $$rowtotal += $itemcount;
5495: return $output;
5496: }
5497:
1.372 raeburn 5498: sub print_proctoring {
5499: my ($dom,$settings,$rowtotal) = @_;
5500: my $itemcount = 1;
5501: my (%ordered,%providernames,%current,%currentdef);
5502: my $confname = $dom.'-domainconfig';
5503: my $switchserver = &check_switchserver($dom,$confname);
5504: if (ref($settings) eq 'HASH') {
5505: foreach my $item (keys(%{$settings})) {
5506: if (ref($settings->{$item}) eq 'HASH') {
5507: my $num = $settings->{$item}{'order'};
5508: $ordered{$num} = $item;
5509: }
5510: }
5511: } else {
5512: %ordered = (
5513: 1 => 'proctorio',
5514: 2 => 'examity',
5515: );
5516: }
5517: %providernames = &proctoring_providernames();
5518: my $maxnum = scalar(keys(%ordered));
5519: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5520: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5521: if (ref($requref) eq 'HASH') {
5522: %requserfields = %{$requref};
5523: }
5524: if (ref($opturef) eq 'HASH') {
5525: %optuserfields = %{$opturef};
5526: }
5527: if (ref($defref) eq 'HASH') {
5528: %defaults = %{$defref};
5529: }
5530: if (ref($extref) eq 'HASH') {
5531: %extended = %{$extref};
5532: }
5533: if (ref($crsref) eq 'HASH') {
5534: %crsconf = %{$crsref};
5535: }
5536: if (ref($rolesref) eq 'ARRAY') {
5537: @courseroles = @{$rolesref};
5538: }
5539: if (ref($ltiref) eq 'ARRAY') {
5540: @ltiroles = @{$ltiref};
5541: }
5542: my $datatable;
5543: my $css_class;
5544: if (keys(%ordered)) {
5545: my @items = sort { $a <=> $b } keys(%ordered);
5546: for (my $i=0; $i<@items; $i++) {
5547: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5548: my $provider = $ordered{$items[$i]};
5549: my $optionsty = 'none';
5550: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5551: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5552: if (ref($settings) eq 'HASH') {
5553: if (ref($settings->{$provider}) eq 'HASH') {
5554: %current = %{$settings->{$provider}};
5555: if ($current{'available'}) {
5556: $optionsty = 'block';
5557: $available = 1;
5558: }
5559: if ($current{'lifetime'} =~ /^\d+$/) {
5560: $lifetime = $current{'lifetime'};
5561: }
5562: if ($current{'version'} =~ /^\d+\.\d+$/) {
5563: $version = $current{'version'};
5564: }
5565: if ($current{'image'} ne '') {
5566: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5567: }
5568: if (ref($current{'fields'}) eq 'ARRAY') {
5569: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5570: }
5571: $userincdom = $current{'incdom'};
5572: if (ref($current{'roles'}) eq 'HASH') {
5573: %rolemaps = %{$current{'roles'}};
5574: $checkedfields{'roles'} = 1;
5575: }
5576: if (ref($current{'defaults'}) eq 'ARRAY') {
5577: foreach my $val (@{$current{'defaults'}}) {
5578: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5579: $inuse{$val} = 1;
5580: } else {
5581: foreach my $poss (keys(%{$extended{$provider}})) {
5582: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5583: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5584: $inuse{$poss} = $val;
5585: last;
5586: }
5587: }
5588: }
5589: }
5590: }
5591: } elsif (ref($current{'defaults'}) eq 'HASH') {
5592: foreach my $key (keys(%{$current{'defaults'}})) {
5593: my $currval = $current{'defaults'}{$key};
5594: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5595: $inuse{$key} = 1;
5596: } else {
5597: my $match;
5598: foreach my $poss (keys(%{$extended{$provider}})) {
5599: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5600: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5601: $inuse{$poss} = $key;
5602: last;
5603: }
5604: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5605: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5606: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5607: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5608: $currentdef{$inner} = $currval;
5609: $match = 1;
5610: last;
5611: }
5612: } elsif ($inner eq $key) {
5613: $currentdef{$key} = $currval;
5614: $match = 1;
5615: last;
5616: }
5617: }
5618: }
5619: last if ($match);
5620: }
5621: }
5622: }
5623: }
5624: if (ref($current{'crsconf'}) eq 'ARRAY') {
5625: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5626: }
5627: }
5628: }
5629: my %lt = &proctoring_titles($provider);
5630: my %fieldtitles = &proctoring_fieldtitles($provider);
5631: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5632: my %checkedavailable = (
5633: yes => '',
5634: no => ' checked="checked"',
5635: );
5636: if ($available) {
5637: $checkedavailable{'yes'} = $checkedavailable{'no'};
5638: $checkedavailable{'no'} = '';
5639: }
5640: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5641: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5642: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5643: for (my $k=0; $k<$maxnum; $k++) {
5644: my $vpos = $k+1;
5645: my $selstr;
5646: if ($k == $i) {
5647: $selstr = ' selected="selected" ';
5648: }
5649: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5650: }
5651: if ($version eq '') {
5652: if ($provider eq 'proctorio') {
5653: $version = '1.0';
5654: } elsif ($provider eq 'examity') {
5655: $version = '1.1';
5656: }
5657: }
5658: if ($lifetime eq '') {
5659: $lifetime = '300';
5660: }
5661: $datatable .=
5662: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5663: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5664: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5665: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5666: '</td>'.
5667: '<td colspan="2">'.
5668: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5669: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5670: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5671: (' 'x2).
5672: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5673: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5674: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5675: (' 'x2).
5676: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5677: '<br />'.
5678: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5679: '<br />'.
5680: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5681: (' 'x2).
5682: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5683: '<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";
5684: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5685: if ($imgsrc) {
5686: $datatable .= $imgsrc.
5687: '<label><input type="checkbox" name="proctoring_image_del"'.
5688: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5689: '<span class="LC_nobreak"> '.&mt('Replace:');
5690: }
5691: $datatable .= ' ';
5692: if ($switchserver) {
5693: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5694: } else {
5695: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5696: }
5697: unless ($imgsrc) {
5698: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5699: }
5700: $datatable .= '</fieldset>'."\n";
5701: if (ref($requserfields{$provider}) eq 'ARRAY') {
5702: if (@{$requserfields{$provider}} > 0) {
5703: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5704: foreach my $field (@{$requserfields{$provider}}) {
5705: $datatable .= '<span class="LC_nobreak">'.
5706: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5707: $lt{$field}.'</label>';
5708: if ($field eq 'user') {
5709: my $seluserdom = '';
5710: my $unseluserdom = ' selected="selected"';
5711: if ($userincdom) {
5712: $seluserdom = $unseluserdom;
5713: $unseluserdom = '';
5714: }
5715: $datatable .= ': '.
5716: '<select name="proctoring_userincdom_'.$provider.'">'.
5717: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5718: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5719: '</select> ';
5720: } else {
5721: $datatable .= ' ';
5722: if ($field eq 'roles') {
5723: $showroles = 1;
5724: }
5725: }
5726: $datatable .= '</span> ';
5727: }
5728: }
5729: $datatable .= '</fieldset>'."\n";
5730: }
5731: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5732: if (@{$optuserfields{$provider}} > 0) {
5733: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5734: foreach my $field (@{$optuserfields{$provider}}) {
5735: my $checked;
5736: if ($checkedfields{$field}) {
5737: $checked = ' checked="checked"';
5738: }
5739: $datatable .= '<span class="LC_nobreak">'.
5740: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5741: }
5742: $datatable .= '</fieldset>'."\n";
5743: }
5744: }
5745: if (ref($defaults{$provider}) eq 'ARRAY') {
5746: if (@{$defaults{$provider}}) {
5747: my (%options,@selectboxes);
5748: if (ref($extended{$provider}) eq 'HASH') {
5749: %options = %{$extended{$provider}};
5750: }
5751: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5752: my ($rem,$numinrow,$dropdowns);
5753: if ($provider eq 'proctorio') {
5754: $datatable .= '<table>';
5755: $numinrow = 4;
5756: }
5757: my $i = 0;
5758: foreach my $field (@{$defaults{$provider}}) {
5759: my $checked;
5760: if ($inuse{$field}) {
5761: $checked = ' checked="checked"';
5762: }
5763: if ($provider eq 'examity') {
5764: if ($field eq 'display') {
5765: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5766: foreach my $option ('iframe','tab','window') {
5767: my $checkdisp;
5768: if ($currentdef{'target'} eq $option) {
5769: $checkdisp = ' checked="checked"';
5770: }
5771: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5772: $fieldtitles{$option}.'</label>'.(' 'x2);
5773: }
5774: $datatable .= (' 'x4);
5775: foreach my $dimen ('width','height') {
5776: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5777: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5778: 'value="'.$currentdef{$dimen}.'" /></label>'.
5779: (' 'x2);
5780: }
5781: $datatable .= '</span><br />'.
5782: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5783: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5784: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5785: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5786: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5787: $currentdef{'explanation'}.
5788: '</textarea></div><div style=""></div><br />';
5789: }
5790: } else {
5791: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5792: my ($output,$selnone);
5793: unless ($checked) {
5794: $selnone = ' selected="selected"';
5795: }
5796: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5797: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5798: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5799: foreach my $option (@{$options{$field}}) {
5800: my $sel;
5801: if ($inuse{$field} eq $option) {
5802: $sel = ' selected="selected"';
5803: }
5804: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5805: }
5806: $output .= '</select></span>';
5807: push(@selectboxes,$output);
5808: } else {
5809: $rem = $i%($numinrow);
5810: if ($rem == 0) {
5811: if ($i > 0) {
5812: $datatable .= '</tr>';
5813: }
5814: $datatable .= '<tr>';
5815: }
5816: $datatable .= '<td class="LC_left_item">'.
5817: '<span class="LC_nobreak">'.
5818: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5819: $fieldtitles{$field}.'</label></span></td>';
5820: $i++;
5821: }
5822: }
5823: }
5824: if ($provider eq 'proctorio') {
5825: if ($numinrow) {
5826: $rem = $i%$numinrow;
5827: }
5828: my $colsleft = $numinrow - $rem;
5829: if ($colsleft > 1) {
5830: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5831: } else {
5832: $datatable .= '<td class="LC_left_item">';
5833: }
5834: $datatable .= ' '.
5835: '</td></tr></table>';
5836: if (@selectboxes) {
5837: $datatable .= '<hr /><table>';
5838: $numinrow = 2;
5839: for (my $i=0; $i<@selectboxes; $i++) {
5840: $rem = $i%($numinrow);
5841: if ($rem == 0) {
5842: if ($i > 0) {
5843: $datatable .= '</tr>';
5844: }
5845: $datatable .= '<tr>';
5846: }
5847: $datatable .= '<td class="LC_left_item">'.
5848: $selectboxes[$i].'</td>';
5849: }
5850: if ($numinrow) {
5851: $rem = $i%$numinrow;
5852: }
5853: $colsleft = $numinrow - $rem;
5854: if ($colsleft > 1) {
5855: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5856: } else {
5857: $datatable .= '<td class="LC_left_item">';
5858: }
5859: $datatable .= ' '.
5860: '</td></tr></table>';
5861: }
5862: }
5863: $datatable .= '</fieldset>';
5864: }
5865: if (ref($crsconf{$provider}) eq 'ARRAY') {
5866: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5867: '<legend>'.&mt('Configurable in course').'</legend>';
5868: my ($rem,$numinrow);
5869: if ($provider eq 'proctorio') {
5870: $datatable .= '<table>';
5871: $numinrow = 4;
5872: }
5873: my $i = 0;
5874: foreach my $item (@{$crsconf{$provider}}) {
5875: my $name;
5876: if ($provider eq 'examity') {
5877: $name = $lt{'crs'.$item};
5878: } elsif ($provider eq 'proctorio') {
5879: $name = $fieldtitles{$item};
5880: $rem = $i%($numinrow);
5881: if ($rem == 0) {
5882: if ($i > 0) {
5883: $datatable .= '</tr>';
5884: }
5885: $datatable .= '<tr>';
5886: }
5887: $datatable .= '<td class="LC_left_item>';
5888: }
5889: my $checked;
5890: if ($crsconfig{$item}) {
5891: $checked = ' checked="checked"';
5892: }
5893: $datatable .= '<span class="LC_nobreak"><label>'.
5894: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5895: $name.'</label></span>';
5896: if ($provider eq 'examity') {
5897: $datatable .= ' ';
5898: }
5899: $datatable .= "\n";
5900: $i++;
5901: }
5902: if ($provider eq 'proctorio') {
5903: if ($numinrow) {
5904: $rem = $i%$numinrow;
5905: }
5906: my $colsleft = $numinrow - $rem;
5907: if ($colsleft > 1) {
5908: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5909: } else {
5910: $datatable .= '<td class="LC_left_item">';
5911: }
5912: $datatable .= ' '.
5913: '</td></tr></table>';
5914: }
5915: $datatable .= '</fieldset>';
5916: }
5917: if ($showroles) {
5918: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5919: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5920: foreach my $role (@courseroles) {
5921: my ($selected,$selectnone);
5922: if (!$rolemaps{$role}) {
5923: $selectnone = ' selected="selected"';
5924: }
5925: $datatable .= '<td style="text-align: center">'.
5926: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5927: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5928: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5929: foreach my $ltirole (@ltiroles) {
5930: unless ($selectnone) {
5931: if ($rolemaps{$role} eq $ltirole) {
5932: $selected = ' selected="selected"';
5933: } else {
5934: $selected = '';
5935: }
5936: }
5937: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5938: }
5939: $datatable .= '</select></td>';
5940: }
5941: $datatable .= '</tr></table></fieldset>'.
5942: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5943: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5944: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5945: '<tr><td></td><td>lms</td>'.
5946: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5947: ' value="Loncapa" disabled="disabled"/></td></tr>';
5948: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5949: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5950: my %custom = %{$settings->{$provider}->{'custom'}};
5951: if (keys(%custom) > 0) {
5952: foreach my $key (sort(keys(%custom))) {
5953: next if ($key eq 'lms');
5954: $datatable .= '<tr><td><span class="LC_nobreak">'.
5955: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5956: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5957: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5958: ' value="'.$custom{$key}.'" /></td></tr>';
5959: }
5960: }
5961: }
5962: $datatable .= '<tr><td><span class="LC_nobreak">'.
5963: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5964: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5965: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5966: '</table></fieldset></td></tr>'."\n";
5967: }
5968: $datatable .= '</td></tr>';
5969: }
5970: $itemcount ++;
5971: }
5972: }
5973: return $datatable;
5974: }
5975:
5976: sub proctoring_data {
5977: my $requserfields = {
5978: proctorio => ['user'],
5979: examity => ['roles','user'],
5980: };
5981: my $optuserfields = {
5982: proctorio => ['fullname'],
5983: examity => ['fullname','firstname','lastname','email'],
5984: };
5985: my $defaults = {
5986: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5987: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5988: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5989: 'closetabs','onescreen','print','downloads','cache','rightclick',
5990: 'reentry','calculator','whiteboard'],
5991: examity => ['display'],
5992: };
5993: my $extended = {
5994: proctorio => {
5995: verifyid => ['verifyidauto','verifyidlive'],
5996: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5997: tabslinks => ['notabs','linksonly'],
5998: reentry => ['noreentry','agentreentry'],
5999: calculator => ['calculatorbasic','calculatorsci'],
6000: },
6001: examity => {
6002: display => {
6003: target => ['iframe','tab','window'],
6004: width => '',
6005: height => '',
6006: linktext => '',
6007: explanation => '',
6008: },
6009: },
6010: };
6011: my $crsconf = {
6012: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6013: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6014: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6015: 'closetabs','onescreen','print','downloads','cache','rightclick',
6016: 'reentry','calculator','whiteboard'],
6017: examity => ['label','title','target','linktext','explanation','append'],
6018: };
6019: my $courseroles = ['cc','in','ta','ep','st'];
6020: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6021: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6022: }
6023:
6024: sub proctoring_titles {
6025: my ($item) = @_;
6026: my (%common_lt,%custom_lt);
6027: %common_lt = &Apache::lonlocal::texthash (
6028: 'avai' => 'Available?',
6029: 'base' => 'Basic Settings',
6030: 'requ' => 'User data required to be sent on launch',
6031: 'optu' => 'User data optionally sent on launch',
6032: 'udsl' => 'User data sent on launch',
6033: 'defa' => 'Defaults for items configurable in course',
6034: 'sigmethod' => 'Signature Method',
6035: 'key' => 'Key',
6036: 'lifetime' => 'Nonce lifetime (s)',
6037: 'secret' => 'Secret',
6038: 'icon' => 'Icon',
6039: 'fullname' => 'Full Name',
6040: 'visible' => 'Visible input',
6041: 'username' => 'username',
6042: 'user' => 'User',
6043: );
6044: if ($item eq 'proctorio') {
6045: %custom_lt = &Apache::lonlocal::texthash (
6046: 'version' => 'OAuth version',
6047: 'url' => 'API URL',
6048: 'uname:dom' => 'username-domain',
6049: );
6050: } elsif ($item eq 'examity') {
6051: %custom_lt = &Apache::lonlocal::texthash (
6052: 'version' => 'LTI Version',
6053: 'url' => 'URL',
6054: 'uname:dom' => 'username:domain',
6055: 'msgtype' => 'Message Type',
6056: 'firstname' => 'First Name',
6057: 'lastname' => 'Last Name',
6058: 'email' => 'E-mail',
6059: 'roles' => 'Role',
6060: 'crstarget' => 'Display target',
6061: 'crslabel' => 'Course label',
6062: 'crstitle' => 'Course title',
6063: 'crslinktext' => 'Link Text',
6064: 'crsexplanation' => 'Explanation',
6065: 'crsappend' => 'Provider URL',
6066: );
6067: }
6068: my %lt = (%common_lt,%custom_lt);
6069: return %lt;
6070: }
6071:
6072: sub proctoring_fieldtitles {
6073: my ($item) = @_;
6074: if ($item eq 'proctorio') {
6075: return &Apache::lonlocal::texthash (
6076: 'recordvideo' => 'Record video',
6077: 'recordaudio' => 'Record audio',
6078: 'recordscreen' => 'Record screen',
6079: 'recordwebtraffic' => 'Record web traffic',
6080: 'recordroomstart' => 'Record room scan',
6081: 'verifyvideo' => 'Verify webcam',
6082: 'verifyaudio' => 'Verify microphone',
6083: 'verifydesktop' => 'Verify desktop recording',
6084: 'verifyid' => 'Photo ID verification',
6085: 'verifysignature' => 'Require signature',
6086: 'fullscreen' => 'Fullscreen',
6087: 'clipboard' => 'Disable copy/paste',
6088: 'tabslinks' => 'New tabs/windows',
6089: 'closetabs' => 'Close other tabs',
6090: 'onescreen' => 'Limit to single screen',
6091: 'print' => 'Disable Printing',
6092: 'downloads' => 'Disable Downloads',
6093: 'cache' => 'Empty cache after exam',
6094: 'rightclick' => 'Disable right click',
6095: 'reentry' => 'Re-entry to exam',
6096: 'calculator' => 'Onscreen calculator',
6097: 'whiteboard' => 'Onscreen whiteboard',
6098: 'verifyidauto' => 'Automated verification',
6099: 'verifyidlive' => 'Live agent verification',
6100: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6101: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6102: 'fullscreensever' => 'Forced, navigation away ends exam',
6103: 'notabs' => 'Disaallowed',
6104: 'linksonly' => 'Allowed from links in exam',
6105: 'noreentry' => 'Disallowed',
6106: 'agentreentry' => 'Agent required for re-entry',
6107: 'calculatorbasic' => 'Basic',
6108: 'calculatorsci' => 'Scientific',
6109: );
6110: } elsif ($item eq 'examity') {
6111: return &Apache::lonlocal::texthash (
6112: 'target' => 'Display target',
6113: 'window' => 'Window',
6114: 'tab' => 'Tab',
6115: 'iframe' => 'iFrame',
6116: 'height' => 'Height (pixels)',
6117: 'width' => 'Width (pixels)',
6118: 'linktext' => 'Default Link Text',
6119: 'explanation' => 'Default Explanation',
6120: 'append' => 'Provider URL',
6121: );
6122: }
6123: }
6124:
6125: sub proctoring_providernames {
6126: return (
6127: proctorio => 'Proctorio',
6128: examity => 'Examity',
6129: );
6130: }
6131:
1.320 raeburn 6132: sub print_lti {
1.405 raeburn 6133: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6134: my $itemcount = 1;
1.405 raeburn 6135: my ($datatable,$css_class);
6136: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6137: if (ref($settings) eq 'HASH') {
1.405 raeburn 6138: if ($position eq 'top') {
6139: if (exists($settings->{'encrypt'})) {
6140: if (ref($settings->{'encrypt'}) eq 'HASH') {
6141: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6142: if ($key eq 'consumers') {
6143: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6144: } else {
6145: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6146: }
6147: }
6148: }
6149: }
6150: if (exists($settings->{'private'})) {
6151: if (ref($settings->{'private'}) eq 'HASH') {
6152: if (ref($settings->{'private'}) eq 'HASH') {
6153: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6154: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6155: }
6156: }
6157: }
6158: }
6159: } elsif ($position eq 'middle') {
6160: if (exists($settings->{'rules'})) {
6161: if (ref($settings->{'rules'}) eq 'HASH') {
6162: %rules = %{$settings->{'rules'}};
6163: }
6164: }
6165: } elsif ($position eq 'lower') {
6166: if (exists($settings->{'linkprot'})) {
6167: if (ref($settings->{'linkprot'}) eq 'HASH') {
6168: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6169: if ($linkprot{'lock'}) {
6170: delete($linkprot{'lock'});
6171: }
1.405 raeburn 6172: }
6173: }
6174: } else {
6175: foreach my $key ('encrypt','private','rules','linkprot') {
6176: if (exists($settings->{$key})) {
6177: delete($settings->{$key});
1.390 raeburn 6178: }
1.320 raeburn 6179: }
6180: }
6181: }
1.405 raeburn 6182: if ($position eq 'top') {
1.421 raeburn 6183: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
6184: } elsif ($position eq 'middle') {
6185: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6186: $$rowtotal += $itemcount;
6187: } elsif ($position eq 'lower') {
6188: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
6189: } else {
6190: my $maxnum = 0;
6191: my %ordered;
6192: if (ref($settings) eq 'HASH') {
6193: foreach my $item (keys(%{$settings})) {
6194: if (ref($settings->{$item}) eq 'HASH') {
6195: my $num = $settings->{$item}{'order'};
6196: if ($num eq '') {
6197: $num = scalar(keys(%{$settings}));
6198: }
6199: $ordered{$num} = $item;
1.405 raeburn 6200: }
1.352 raeburn 6201: }
1.405 raeburn 6202: }
6203: $maxnum = scalar(keys(%ordered));
6204: my %lt = <i_names();
6205: if (keys(%ordered)) {
6206: my @items = sort { $a <=> $b } keys(%ordered);
6207: for (my $i=0; $i<@items; $i++) {
6208: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6209: my $item = $ordered{$items[$i]};
6210: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
6211: if (ref($settings->{$item}) eq 'HASH') {
6212: $key = $settings->{$item}->{'key'};
6213: $secret = $settings->{$item}->{'secret'};
6214: $lifetime = $settings->{$item}->{'lifetime'};
6215: $consumer = $settings->{$item}->{'consumer'};
6216: $requser = $settings->{$item}->{'requser'};
6217: $crsinc = $settings->{$item}->{'crsinc'};
6218: $current = $settings->{$item};
6219: }
6220: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6221: my %checkedrequser = (
6222: yes => ' checked="checked"',
6223: no => '',
6224: );
6225: if (!$requser) {
6226: $checkedrequser{'no'} = $checkedrequser{'yes'};
6227: $checkedrequser{'yes'} = '';
6228: }
6229: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6230: my %checkedcrsinc = (
1.391 raeburn 6231: yes => ' checked="checked"',
6232: no => '',
1.405 raeburn 6233: );
6234: if (!$crsinc) {
6235: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6236: $checkedcrsinc{'yes'} = '';
6237: }
6238: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6239: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6240: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6241: for (my $k=0; $k<=$maxnum; $k++) {
6242: my $vpos = $k+1;
6243: my $selstr;
6244: if ($k == $i) {
6245: $selstr = ' selected="selected" ';
6246: }
6247: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6248: }
1.405 raeburn 6249: $datatable .= '</select>'.(' 'x2).
6250: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6251: &mt('Delete?').'</label></span></td>'.
6252: '<td colspan="2">'.
6253: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6254: '<span class="LC_nobreak">'.$lt{'consumer'}.
6255: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6256: (' 'x2).
6257: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6258: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6259: (' 'x2).
6260: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
6261: 'value="'.$lifetime.'" size="3" /></span>'.
6262: (' 'x2).
6263: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6264: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6265: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6266: '<br /><br />'.
6267: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6268: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6269: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6270: (' 'x4).
6271: '<span class="LC_nobreak">'.$lt{'key'}.
6272: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6273: (' 'x2).
6274: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6275: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6276: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
6277: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6278: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6279: $itemcount ++;
1.320 raeburn 6280: }
6281: }
1.405 raeburn 6282: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6283: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6284: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6285: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6286: '<select name="lti_pos_add"'.$chgstr.'>';
6287: for (my $k=0; $k<$maxnum+1; $k++) {
6288: my $vpos = $k+1;
6289: my $selstr;
6290: if ($k == $maxnum) {
6291: $selstr = ' selected="selected" ';
6292: }
6293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6294: }
1.405 raeburn 6295: $datatable .= '</select> '."\n".
6296: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6297: '<td colspan="2">'.
6298: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6299: '<span class="LC_nobreak">'.$lt{'consumer'}.
6300: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6301: (' 'x2).
6302: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6303: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6304: (' 'x2).
6305: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6306: (' 'x2).
6307: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6308: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6309: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6310: '<br /><br />'.
6311: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6312: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6313: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6314: (' 'x4).
6315: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6316: (' 'x2).
6317: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6318: '<label><input type="checkbox" name="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".
6319: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6320: '</td>'."\n".
6321: '</tr>'."\n";
6322: $itemcount ++;
1.320 raeburn 6323: }
1.405 raeburn 6324: $$rowtotal += $itemcount;
6325: return $datatable;
1.320 raeburn 6326: }
6327:
6328: sub lti_names {
6329: my %lt = &Apache::lonlocal::texthash(
6330: 'version' => 'LTI Version',
6331: 'url' => 'URL',
6332: 'key' => 'Key',
1.322 raeburn 6333: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6334: 'consumer' => 'Consumer',
1.320 raeburn 6335: 'secret' => 'Secret',
1.345 raeburn 6336: 'requser' => "User's identity sent",
1.391 raeburn 6337: 'crsinc' => "Course's identity sent",
1.320 raeburn 6338: 'email' => 'Email address',
6339: 'sourcedid' => 'User ID',
6340: 'other' => 'Other',
6341: 'passback' => 'Can return grades to Consumer:',
6342: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6343: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6344: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6345: );
6346: return %lt;
6347: }
6348:
6349: sub lti_options {
1.325 raeburn 6350: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6351: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6352: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6353: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6354: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6355: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6356: $checked{'mapcrstype'} = {};
6357: $checked{'makeuser'} = {};
6358: $checked{'selfenroll'} = {};
6359: $checked{'crssec'} = {};
6360: $checked{'crssecsrc'} = {};
1.325 raeburn 6361: $checked{'lcauth'} = {};
1.326 raeburn 6362: $checked{'menuitem'} = {};
1.325 raeburn 6363: if ($num eq 'add') {
6364: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6365: }
1.320 raeburn 6366: my $userfieldsty = 'none';
6367: my $crsfieldsty = 'none';
6368: my $crssecfieldsty = 'none';
6369: my $secsrcfieldsty = 'none';
1.363 raeburn 6370: my $callbacksty = 'none';
1.337 raeburn 6371: my $passbacksty = 'none';
1.345 raeburn 6372: my $optionsty = 'block';
1.391 raeburn 6373: my $crssty = 'block';
1.325 raeburn 6374: my $lcauthparm;
6375: my $lcauthparmstyle = 'display:none';
6376: my $lcauthparmtext;
1.326 raeburn 6377: my $menusty;
1.325 raeburn 6378: my $numinrow = 4;
1.326 raeburn 6379: my %menutitles = <imenu_titles();
1.320 raeburn 6380:
6381: if (ref($current) eq 'HASH') {
1.345 raeburn 6382: if (!$current->{'requser'}) {
6383: $optionsty = 'none';
1.391 raeburn 6384: $crssty = 'none';
6385: } elsif (!$current->{'crsinc'}) {
6386: $crssty = 'none';
1.345 raeburn 6387: }
1.320 raeburn 6388: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6389: $checked{'mapuser'}{'sourcedid'} = '';
6390: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6391: $checked{'mapuser'}{'email'} = ' checked="checked"';
6392: } else {
6393: $checked{'mapuser'}{'other'} = ' checked="checked"';
6394: $userfield = $current->{'mapuser'};
6395: $userfieldsty = 'inline-block';
6396: }
6397: }
6398: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6399: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6400: if ($current->{'mapcrs'} eq 'context_id') {
6401: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6402: } else {
6403: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6404: $cidfield = $current->{'mapcrs'};
6405: $crsfieldsty = 'inline-block';
6406: }
6407: }
6408: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6409: foreach my $type (@{$current->{'mapcrstype'}}) {
6410: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6411: }
6412: }
1.392 raeburn 6413: if (!$current->{'storecrs'}) {
6414: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6415: $checked{'storecrs'}{'Y'} = '';
6416: }
1.345 raeburn 6417: if ($current->{'makecrs'}) {
1.320 raeburn 6418: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6419: }
1.320 raeburn 6420: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6421: foreach my $role (@{$current->{'makeuser'}}) {
6422: $checked{'makeuser'}{$role} = ' checked="checked"';
6423: }
6424: }
1.325 raeburn 6425: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6426: $checked{'lcauth'}{$1} = ' checked="checked"';
6427: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6428: $lcauthparm = $current->{'lcauthparm'};
6429: $lcauthparmstyle = 'display:table-row';
6430: if ($current->{'lcauth'} eq 'localauth') {
6431: $lcauthparmtext = &mt('Local auth argument');
6432: } else {
6433: $lcauthparmtext = &mt('Kerberos domain');
6434: }
6435: }
6436: }
1.320 raeburn 6437: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6438: foreach my $role (@{$current->{'selfenroll'}}) {
6439: $checked{'selfenroll'}{$role} = ' checked="checked"';
6440: }
6441: }
6442: if (ref($current->{'maproles'}) eq 'HASH') {
6443: %rolemaps = %{$current->{'maproles'}};
6444: }
6445: if ($current->{'section'} ne '') {
6446: $checked{'crssec'}{'Y'} = ' checked="checked"';
6447: $crssecfieldsty = 'inline-block';
6448: if ($current->{'section'} eq 'course_section_sourcedid') {
6449: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6450: } else {
6451: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6452: $crssecsrc = $current->{'section'};
6453: $secsrcfieldsty = 'inline-block';
6454: }
6455: } else {
6456: $checked{'crssec'}{'N'} = ' checked="checked"';
6457: }
1.363 raeburn 6458: if ($current->{'callback'} ne '') {
6459: $callback = $current->{'callback'};
6460: $checked{'callback'}{'Y'} = ' checked="checked"';
6461: $callbacksty = 'inline-block';
6462: } else {
6463: $checked{'callback'}{'N'} = ' checked="checked"';
6464: }
1.326 raeburn 6465: if ($current->{'topmenu'}) {
6466: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6467: } else {
6468: $checked{'topmenu'}{'N'} = ' checked="checked"';
6469: }
6470: if ($current->{'inlinemenu'}) {
6471: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6472: } else {
6473: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6474: }
6475: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6476: $menusty = 'inline-block';
6477: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6478: foreach my $item (@{$current->{'lcmenu'}}) {
6479: if (exists($menutitles{$item})) {
6480: $checked{'menuitem'}{$item} = ' checked="checked"';
6481: }
6482: }
6483: }
6484: } else {
6485: $menusty = 'none';
6486: }
1.320 raeburn 6487: } else {
6488: $checked{'makecrs'}{'N'} = ' checked="checked"';
6489: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6490: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6491: $checked{'topmenu'}{'N'} = ' checked="checked"';
6492: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6493: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6494: $menusty = 'inline-block';
1.320 raeburn 6495: }
1.325 raeburn 6496: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6497: my %coursetypetitles = &Apache::lonlocal::texthash (
6498: official => 'Official',
6499: unofficial => 'Unofficial',
6500: community => 'Community',
6501: textbook => 'Textbook',
6502: placement => 'Placement Test',
1.325 raeburn 6503: lti => 'LTI Provider',
1.320 raeburn 6504: );
1.325 raeburn 6505: my @authtypes = ('internal','krb4','krb5','localauth');
6506: my %shortauth = (
6507: internal => 'int',
6508: krb4 => 'krb4',
6509: krb5 => 'krb5',
6510: localauth => 'loc'
6511: );
6512: my %authnames = &authtype_names();
1.320 raeburn 6513: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6514: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6515: my @courseroles = ('cc','in','ta','ep','st');
6516: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6517: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6518: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6519: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6520: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6521: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6522: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6523: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6524: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6525: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6526: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6527: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6528: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6529: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6530: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6531: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6532: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6533: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6534: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6535: foreach my $option ('sourcedid','email','other') {
6536: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6537: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6538: ($option eq 'other' ? '' : (' 'x2) );
6539: }
6540: $output .= '</span></div>'.
6541: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6542: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6543: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6544: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6545: foreach my $ltirole (@ltiroles) {
6546: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6547: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6548: }
6549: $output .= '</fieldset>'.
1.391 raeburn 6550: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6551: '<table>'.
6552: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6553: '</table>'.
6554: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6555: '<td class="LC_left_item">';
6556: foreach my $auth ('lti',@authtypes) {
6557: my $authtext;
6558: if ($auth eq 'lti') {
6559: $authtext = &mt('None');
6560: } else {
6561: $authtext = $authnames{$shortauth{$auth}};
6562: }
6563: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6564: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6565: $authtext.'</label></span> ';
6566: }
6567: $output .= '</td></tr>'.
6568: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6569: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6570: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6571: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6572: '</table></fieldset>'.
1.391 raeburn 6573: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6574: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6575: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6576: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6577: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6578: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6579: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6580: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6581: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6582: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6583: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6584: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6585: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6586: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6587: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6588: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6589: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6590: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6591: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6592: (' 'x2);
6593: }
6594: $output .= '</span></div></fieldset>'.
6595: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6596: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6597: &mt('Unique course identifier').': ';
6598: foreach my $option ('course_offering_sourcedid','context_id','other') {
6599: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6600: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6601: ($option eq 'other' ? '' : (' 'x2) );
6602: }
1.334 raeburn 6603: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6604: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6605: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6606: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6607: foreach my $type (@coursetypes) {
6608: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6609: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6610: (' 'x2);
6611: }
1.392 raeburn 6612: $output .= '</span><br /><br />'.
6613: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6614: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6615: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6616: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6617: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6618: '</fieldset>'.
1.391 raeburn 6619: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6620: foreach my $ltirole (@lticourseroles) {
6621: my ($selected,$selectnone);
6622: if ($rolemaps{$ltirole} eq '') {
6623: $selectnone = ' selected="selected"';
6624: }
6625: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6626: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6627: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6628: foreach my $role (@courseroles) {
6629: unless ($selectnone) {
6630: if ($rolemaps{$ltirole} eq $role) {
6631: $selected = ' selected="selected"';
6632: } else {
6633: $selected = '';
6634: }
6635: }
6636: $output .= '<option value="'.$role.'"'.$selected.'>'.
6637: &Apache::lonnet::plaintext($role,'Course').
6638: '</option>';
6639: }
6640: $output .= '</select></td>';
6641: }
6642: $output .= '</tr></table></fieldset>'.
6643: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6644: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6645: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6646: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6647: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6648: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6649: '</fieldset>'.
1.391 raeburn 6650: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6651: foreach my $lticrsrole (@lticourseroles) {
6652: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6653: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6654: }
6655: $output .= '</fieldset>'.
1.391 raeburn 6656: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6657: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6658: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6659: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6660: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6661: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6662: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6663: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6664: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6665: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6666: &mt('Standard field').'</label>'.(' 'x2).
6667: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6668: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6669: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6670: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6671: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6672: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6673: foreach my $extra ('roster','passback') {
1.320 raeburn 6674: my $checkedon = '';
6675: my $checkedoff = ' checked="checked"';
1.337 raeburn 6676: if ($extra eq 'passback') {
6677: $pb1p1chk = ' checked="checked"';
6678: $pb1p0chk = '';
6679: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6680: } else {
6681: $onclickpb = '';
6682: }
1.320 raeburn 6683: if (ref($current) eq 'HASH') {
6684: if (($current->{$extra})) {
6685: $checkedon = $checkedoff;
6686: $checkedoff = '';
1.337 raeburn 6687: if ($extra eq 'passback') {
6688: $passbacksty = 'inline-block';
6689: }
6690: if ($current->{'passbackformat'} eq '1.0') {
6691: $pb1p0chk = ' checked="checked"';
6692: $pb1p1chk = '';
6693: }
1.320 raeburn 6694: }
6695: }
6696: $output .= $lt{$extra}.' '.
1.337 raeburn 6697: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6698: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6699: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6700: &mt('Yes').'</label><br />';
6701: }
1.337 raeburn 6702: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6703: '<span class="LC_nobreak">'.&mt('Grade format').
6704: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6705: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6706: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6707: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6708: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6709: $output .= '</span></div></fieldset>';
1.320 raeburn 6710: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6711: #
6712: # $output .= '</fieldset>'.
6713: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6714: return $output;
6715: }
6716:
1.326 raeburn 6717: sub ltimenu_titles {
6718: return &Apache::lonlocal::texthash(
6719: fullname => 'Full name',
6720: coursetitle => 'Course title',
6721: role => 'Role',
6722: logout => 'Logout',
6723: grades => 'Grades',
6724: );
6725: }
6726:
1.405 raeburn 6727: sub check_switchserver {
6728: my ($home) = @_;
6729: my $switchserver;
6730: if ($home ne '') {
6731: my $allowed;
6732: my @ids=&Apache::lonnet::current_machine_ids();
6733: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6734: if (!$allowed) {
6735: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
6736: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
6737: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6738: }
6739: }
6740: return $switchserver;
6741: }
6742:
1.121 raeburn 6743: sub print_coursedefaults {
1.139 raeburn 6744: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6745: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6746: my $itemcount = 1;
1.192 raeburn 6747: my %choices = &Apache::lonlocal::texthash (
6748: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6749: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6750: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6751: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6752: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6753: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6754: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6755: texengine => 'Default method to display mathematics',
1.257 raeburn 6756: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6757: canclone => "People who may clone a course (besides course's owner and coordinators)",
6758: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6759: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6760: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6761: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.192 raeburn 6762: );
1.198 raeburn 6763: my %staticdefaults = (
6764: anonsurvey_threshold => 10,
6765: uploadquota => 500,
1.257 raeburn 6766: postsubmit => 60,
1.276 raeburn 6767: mysqltables => 172800,
1.422 raeburn 6768: domexttool => 1,
6769: exttool => 0,
1.198 raeburn 6770: );
1.139 raeburn 6771: if ($position eq 'top') {
1.257 raeburn 6772: %defaultchecked = (
6773: 'canuse_pdfforms' => 'off',
6774: 'uselcmath' => 'on',
6775: 'usejsme' => 'on',
1.398 raeburn 6776: 'inline_chem' => 'on',
1.289 raeburn 6777: 'canclone' => 'none',
1.257 raeburn 6778: );
1.398 raeburn 6779: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6780: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6781: if (ref($settings) eq 'HASH') {
6782: if ($settings->{'texengine'}) {
6783: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6784: $deftex = $settings->{'texengine'};
6785: }
6786: }
6787: }
6788: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6789: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6790: '<span class="LC_nobreak">'.$choices{'texengine'}.
6791: '</span></td><td class="LC_right_item">'.
6792: '<select name="texengine">'."\n";
6793: my %texoptions = (
6794: MathJax => 'MathJax',
6795: mimetex => &mt('Convert to Images'),
6796: tth => &mt('TeX to HTML'),
6797: );
6798: foreach my $renderer ('MathJax','mimetex','tth') {
6799: my $selected = '';
6800: if ($renderer eq $deftex) {
6801: $selected = ' selected="selected"';
6802: }
6803: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6804: }
6805: $mathdisp .= '</select></td></tr>'."\n";
6806: $itemcount ++;
1.139 raeburn 6807: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6808: \%choices,$itemcount);
1.314 raeburn 6809: $datatable = $mathdisp.$datatable;
1.264 raeburn 6810: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6811: $datatable .=
1.306 raeburn 6812: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6813: '<span class="LC_nobreak">'.$choices{'canclone'}.
6814: '</span></td><td class="LC_left_item">';
6815: my $currcanclone = 'none';
6816: my $onclick;
6817: my @cloneoptions = ('none','domain');
1.380 raeburn 6818: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6819: none => 'No additional course requesters',
6820: domain => "Any course requester in course's domain",
6821: instcode => 'Course requests for official courses ...',
6822: );
6823: my (%codedefaults,@code_order,@posscodes);
6824: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6825: \@code_order) eq 'ok') {
6826: if (@code_order > 0) {
6827: push(@cloneoptions,'instcode');
6828: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6829: }
6830: }
6831: if (ref($settings) eq 'HASH') {
6832: if ($settings->{'canclone'}) {
6833: if (ref($settings->{'canclone'}) eq 'HASH') {
6834: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6835: if (@code_order > 0) {
6836: $currcanclone = 'instcode';
6837: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6838: }
6839: }
6840: } elsif ($settings->{'canclone'} eq 'domain') {
6841: $currcanclone = $settings->{'canclone'};
6842: }
6843: }
1.289 raeburn 6844: }
1.264 raeburn 6845: foreach my $option (@cloneoptions) {
6846: my ($checked,$additional);
6847: if ($currcanclone eq $option) {
6848: $checked = ' checked="checked"';
6849: }
6850: if ($option eq 'instcode') {
6851: if (@code_order) {
6852: my $show = 'none';
6853: if ($checked) {
6854: $show = 'block';
6855: }
1.317 raeburn 6856: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6857: &mt('Institutional codes for new and cloned course have identical:').
6858: '<br />';
6859: foreach my $item (@code_order) {
6860: my $codechk;
6861: if ($checked) {
6862: if (grep(/^\Q$item\E$/,@posscodes)) {
6863: $codechk = ' checked="checked"';
6864: }
6865: }
6866: $additional .= '<label>'.
6867: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6868: $item.'</label>';
6869: }
6870: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6871: }
6872: }
6873: $datatable .=
6874: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6875: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6876: '</label> '.$additional.'</span><br />';
6877: }
6878: $datatable .= '</td>'.
6879: '</tr>';
6880: $itemcount ++;
1.139 raeburn 6881: } else {
6882: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6883: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6884: my $currusecredits = 0;
1.257 raeburn 6885: my $postsubmitclient = 1;
1.405 raeburn 6886: my $ltiauth = 0;
1.422 raeburn 6887: my %domexttool;
6888: my %exttool;
1.271 raeburn 6889: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6890: if (ref($settings) eq 'HASH') {
1.404 raeburn 6891: if ($settings->{'ltiauth'}) {
6892: $ltiauth = 1;
1.405 raeburn 6893: }
1.422 raeburn 6894: if (ref($settings->{'domexttool'}) eq 'HASH') {
6895: foreach my $type (@types) {
6896: if ($settings->{'domexttool'}->{$type}) {
6897: $domexttool{$type} = ' checked="checked"';
6898: }
6899: }
6900: } else {
6901: foreach my $type (@types) {
6902: if ($staticdefaults{'domexttool'}) {
6903: $domexttool{$type} = ' checked="checked"';
6904: }
6905: }
6906: }
6907: if (ref($settings->{'exttool'}) eq 'HASH') {
6908: foreach my $type (@types) {
6909: if ($settings->{'exttool'}->{$type}) {
6910: $exttool{$type} = ' checked="checked"';
6911: }
6912: }
6913: }
1.139 raeburn 6914: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6915: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6916: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6917: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6918: }
6919: }
1.192 raeburn 6920: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6921: foreach my $type (@types) {
6922: next if ($type eq 'community');
6923: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6924: if ($defcredits{$type} ne '') {
6925: $currusecredits = 1;
6926: }
6927: }
6928: }
6929: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6930: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6931: $postsubmitclient = 0;
6932: foreach my $type (@types) {
6933: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6934: }
6935: } else {
6936: foreach my $type (@types) {
6937: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6938: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6939: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6940: } else {
6941: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6942: }
6943: } else {
6944: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6945: }
6946: }
6947: }
6948: } else {
6949: foreach my $type (@types) {
6950: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6951: }
6952: }
1.276 raeburn 6953: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6954: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6955: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6956: }
6957: } else {
6958: foreach my $type (@types) {
6959: $currmysql{$type} = $staticdefaults{'mysqltables'};
6960: }
6961: }
1.258 raeburn 6962: } else {
6963: foreach my $type (@types) {
6964: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 6965: if ($staticdefaults{'domexttool'}) {
6966: $domexttool{$type} = ' checked="checked"';
6967: }
1.258 raeburn 6968: }
1.139 raeburn 6969: }
6970: if (!$currdefresponder) {
1.198 raeburn 6971: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6972: } elsif ($currdefresponder < 1) {
6973: $currdefresponder = 1;
6974: }
1.198 raeburn 6975: foreach my $type (@types) {
6976: if ($curruploadquota{$type} eq '') {
6977: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6978: }
6979: }
1.139 raeburn 6980: $datatable .=
1.192 raeburn 6981: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6982: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6983: '</span></td>'.
6984: '<td class="LC_right_item"><span class="LC_nobreak">'.
6985: '<input type="text" name="anonsurvey_threshold"'.
6986: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6987: '</td></tr>'."\n";
6988: $itemcount ++;
6989: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6990: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6991: $choices{'uploadquota'}.
6992: '</span></td>'.
1.306 raeburn 6993: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6994: '<table><tr>';
1.198 raeburn 6995: foreach my $type (@types) {
1.306 raeburn 6996: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6997: '<input type="text" name="uploadquota_'.$type.'"'.
6998: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6999: }
7000: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7001: $itemcount ++;
1.236 raeburn 7002: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7003: my $display = 'none';
1.192 raeburn 7004: if ($currusecredits) {
7005: $display = 'block';
7006: }
7007: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7008: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7009: foreach my $type (@types) {
7010: next if ($type eq 'community');
1.306 raeburn 7011: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7012: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7013: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7014: }
7015: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7016: %defaultchecked = ('coursecredits' => 'off');
7017: @toggles = ('coursecredits');
7018: my $current = {
7019: 'coursecredits' => $currusecredits,
7020: };
7021: (my $table,$itemcount) =
7022: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7023: \%choices,$itemcount,$onclick,$additional,'left');
7024: $datatable .= $table;
7025: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7026: my $display = 'none';
7027: if ($postsubmitclient) {
7028: $display = 'block';
7029: }
7030: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7031: &mt('Number of seconds submit is disabled').'<br />'.
7032: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7033: '<table><tr>';
1.257 raeburn 7034: foreach my $type (@types) {
1.306 raeburn 7035: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7036: '<input type="text" name="'.$type.'_timeout" value="'.
7037: $deftimeout{$type}.'" size="5" /></td>';
7038: }
7039: $additional .= '</tr></table></div>'."\n";
7040: %defaultchecked = ('postsubmit' => 'on');
7041: @toggles = ('postsubmit');
1.280 raeburn 7042: $current = {
7043: 'postsubmit' => $postsubmitclient,
7044: };
1.257 raeburn 7045: ($table,$itemcount) =
7046: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7047: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7048: $datatable .= $table;
1.276 raeburn 7049: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7050: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7051: $choices{'mysqltables'}.
7052: '</span></td>'.
1.306 raeburn 7053: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7054: '<table><tr>';
7055: foreach my $type (@types) {
1.306 raeburn 7056: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7057: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7058: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7059: }
7060: $datatable .= '</tr></table></td></tr>'."\n";
7061: $itemcount ++;
1.404 raeburn 7062: %defaultchecked = ('ltiauth' => 'off');
7063: @toggles = ('ltiauth');
7064: $current = {
7065: 'ltiauth' => $ltiauth,
7066: };
7067: ($table,$itemcount) =
7068: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7069: \%choices,$itemcount,undef,undef,'left');
7070: $datatable .= $table;
1.422 raeburn 7071: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7072: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7073: $choices{'domexttool'}.
7074: '</span></td>'.
7075: '<td style="text-align: right" class="LC_right_item">'.
7076: '<table><tr>';
7077: foreach my $type (@types) {
7078: $datatable .= '<td style="text-align: left">'.
7079: '<span class="LC_nobreak">'.
7080: '<input type="checkbox" name="domexttool"'.
7081: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7082: &mt($type).'</span></td>'."\n";
7083: }
7084: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7085: $itemcount ++;
1.422 raeburn 7086: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7087: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7088: $choices{'exttool'}.
7089: '</span></td>'.
7090: '<td style="text-align: right" class="LC_right_item">'.
7091: '<table><tr>';
7092: foreach my $type (@types) {
7093: $datatable .= '<td style="text-align: left">'.
7094: '<span class="LC_nobreak">'.
7095: '<input type="checkbox" name="exttool"'.
7096: ' value="'.$type.'"'.$exttool{$type}.' />'.
7097: &mt($type).'</span></td>'."\n";
7098: }
7099: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7100: }
1.192 raeburn 7101: $$rowtotal += $itemcount;
1.121 raeburn 7102: return $datatable;
1.118 jms 7103: }
7104:
1.231 raeburn 7105: sub print_selfenrollment {
7106: my ($position,$dom,$settings,$rowtotal) = @_;
7107: my ($css_class,$datatable);
7108: my $itemcount = 1;
1.271 raeburn 7109: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7110: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7111: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7112: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7113: my @rows;
7114: my $key;
7115: if ($position eq 'top') {
7116: $key = 'admin';
7117: if (ref($rowsref) eq 'ARRAY') {
7118: @rows = @{$rowsref};
7119: }
7120: } elsif ($position eq 'middle') {
7121: $key = 'default';
7122: @rows = ('types','registered','approval','limit');
7123: }
7124: foreach my $row (@rows) {
7125: if (defined($titlesref->{$row})) {
7126: $itemcount ++;
7127: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7128: $datatable .= '<tr'.$css_class.'>'.
7129: '<td>'.$titlesref->{$row}.'</td>'.
7130: '<td class="LC_left_item">'.
7131: '<table><tr>';
7132: my (%current,%currentcap);
7133: if (ref($settings) eq 'HASH') {
7134: if (ref($settings->{$key}) eq 'HASH') {
7135: foreach my $type (@types) {
7136: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7137: $current{$type} = $settings->{$key}->{$type}->{$row};
7138: }
7139: if (($row eq 'limit') && ($key eq 'default')) {
7140: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7141: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7142: }
7143: }
7144: }
7145: }
7146: }
7147: my %roles = (
7148: '0' => &Apache::lonnet::plaintext('dc'),
7149: );
7150:
7151: foreach my $type (@types) {
7152: unless (($row eq 'registered') && ($key eq 'default')) {
7153: $datatable .= '<th>'.&mt($type).'</th>';
7154: }
7155: }
7156: unless (($row eq 'registered') && ($key eq 'default')) {
7157: $datatable .= '</tr><tr>';
7158: }
7159: foreach my $type (@types) {
7160: if ($type eq 'community') {
7161: $roles{'1'} = &mt('Community personnel');
7162: } else {
7163: $roles{'1'} = &mt('Course personnel');
7164: }
7165: $datatable .= '<td style="vertical-align: top">';
7166: if ($position eq 'top') {
7167: my %checked;
7168: if ($current{$type} eq '0') {
7169: $checked{'0'} = ' checked="checked"';
7170: } else {
7171: $checked{'1'} = ' checked="checked"';
7172: }
7173: foreach my $role ('1','0') {
7174: $datatable .= '<span class="LC_nobreak"><label>'.
7175: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7176: 'value="'.$role.'"'.$checked{$role}.' />'.
7177: $roles{$role}.'</label></span> ';
7178: }
7179: } else {
7180: if ($row eq 'types') {
7181: my %checked;
7182: if ($current{$type} =~ /^(all|dom)$/) {
7183: $checked{$1} = ' checked="checked"';
7184: } else {
7185: $checked{''} = ' checked="checked"';
7186: }
7187: foreach my $val ('','dom','all') {
7188: $datatable .= '<span class="LC_nobreak"><label>'.
7189: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7190: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7191: }
7192: } elsif ($row eq 'registered') {
7193: my %checked;
7194: if ($current{$type} eq '1') {
7195: $checked{'1'} = ' checked="checked"';
7196: } else {
7197: $checked{'0'} = ' checked="checked"';
7198: }
7199: foreach my $val ('0','1') {
7200: $datatable .= '<span class="LC_nobreak"><label>'.
7201: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7202: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7203: }
7204: } elsif ($row eq 'approval') {
7205: my %checked;
7206: if ($current{$type} =~ /^([12])$/) {
7207: $checked{$1} = ' checked="checked"';
7208: } else {
7209: $checked{'0'} = ' checked="checked"';
7210: }
7211: for my $val (0..2) {
7212: $datatable .= '<span class="LC_nobreak"><label>'.
7213: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7214: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7215: }
7216: } elsif ($row eq 'limit') {
7217: my %checked;
7218: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7219: $checked{$1} = ' checked="checked"';
7220: } else {
7221: $checked{'none'} = ' checked="checked"';
7222: }
7223: my $cap;
7224: if ($currentcap{$type} =~ /^\d+$/) {
7225: $cap = $currentcap{$type};
7226: }
7227: foreach my $val ('none','allstudents','selfenrolled') {
7228: $datatable .= '<span class="LC_nobreak"><label>'.
7229: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7230: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7231: }
7232: $datatable .= '<br />'.
7233: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7234: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7235: '</span>';
7236: }
7237: }
7238: $datatable .= '</td>';
7239: }
7240: $datatable .= '</tr>';
7241: }
7242: $datatable .= '</table></td></tr>';
7243: }
7244: } elsif ($position eq 'bottom') {
1.235 raeburn 7245: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7246: }
7247: $$rowtotal += $itemcount;
7248: return $datatable;
7249: }
7250:
7251: sub print_validation_rows {
7252: my ($caller,$dom,$settings,$rowtotal) = @_;
7253: my ($itemsref,$namesref,$fieldsref);
7254: if ($caller eq 'selfenroll') {
7255: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7256: } elsif ($caller eq 'requestcourses') {
7257: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7258: }
7259: my %currvalidation;
7260: if (ref($settings) eq 'HASH') {
7261: if (ref($settings->{'validation'}) eq 'HASH') {
7262: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7263: }
1.235 raeburn 7264: }
7265: my $datatable;
7266: my $itemcount = 0;
7267: foreach my $item (@{$itemsref}) {
7268: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7269: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7270: $namesref->{$item}.
7271: '</span></td>'.
7272: '<td class="LC_left_item">';
7273: if (($item eq 'url') || ($item eq 'button')) {
7274: $datatable .= '<span class="LC_nobreak">'.
7275: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7276: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7277: } elsif ($item eq 'fields') {
7278: my @currfields;
7279: if (ref($currvalidation{$item}) eq 'ARRAY') {
7280: @currfields = @{$currvalidation{$item}};
7281: }
7282: foreach my $field (@{$fieldsref}) {
7283: my $check = '';
7284: if (grep(/^\Q$field\E$/,@currfields)) {
7285: $check = ' checked="checked"';
7286: }
7287: $datatable .= '<span class="LC_nobreak"><label>'.
7288: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7289: ' value="'.$field.'"'.$check.' />'.$field.
7290: '</label></span> ';
7291: }
7292: } elsif ($item eq 'markup') {
1.334 raeburn 7293: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7294: $currvalidation{$item}.
1.231 raeburn 7295: '</textarea>';
1.235 raeburn 7296: }
7297: $datatable .= '</td></tr>'."\n";
7298: if (ref($rowtotal)) {
1.231 raeburn 7299: $itemcount ++;
7300: }
7301: }
1.235 raeburn 7302: if ($caller eq 'requestcourses') {
7303: my %currhash;
1.248 raeburn 7304: if (ref($settings) eq 'HASH') {
7305: if (ref($settings->{'validation'}) eq 'HASH') {
7306: if ($settings->{'validation'}{'dc'} ne '') {
7307: $currhash{$settings->{'validation'}{'dc'}} = 1;
7308: }
1.235 raeburn 7309: }
7310: }
7311: my $numinrow = 2;
7312: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7313: 'validationdc',%currhash);
1.247 raeburn 7314: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7315: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7316: if ($numdc > 1) {
1.247 raeburn 7317: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7318: } else {
1.247 raeburn 7319: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7320: }
1.247 raeburn 7321: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7322: $itemcount ++;
7323: }
7324: if (ref($rowtotal)) {
7325: $$rowtotal += $itemcount;
7326: }
1.231 raeburn 7327: return $datatable;
7328: }
7329:
1.357 raeburn 7330: sub print_privacy {
7331: my ($position,$dom,$settings,$rowtotal) = @_;
7332: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7333: my $itemcount = 0;
1.417 raeburn 7334: if ($position eq 'top') {
7335: $numinrow = 2;
7336: } else {
1.357 raeburn 7337: @items = ('domain','author','course','community');
7338: %names = &Apache::lonlocal::texthash (
7339: domain => 'Assigned domain role(s)',
7340: author => 'Assigned co-author role(s)',
7341: course => 'Assigned course role(s)',
1.416 raeburn 7342: community => 'Assigned community role(s)',
1.357 raeburn 7343: );
7344: $numinrow = 4;
7345: ($othertitle,$usertypes,$types) =
7346: &Apache::loncommon::sorted_inst_types($dom);
7347: }
7348: if (($position eq 'top') || ($position eq 'middle')) {
7349: my (%by_ip,%by_location,@intdoms,@instdoms);
7350: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7351: if ($position eq 'top') {
7352: my %curr;
7353: my @options = ('none','user','domain','auto');
7354: my %titles = &Apache::lonlocal::texthash (
7355: none => 'Not allowed',
7356: user => 'User authorizes',
7357: domain => 'DC authorizes',
7358: auto => 'Unrestricted',
7359: instdom => 'Other domain shares institution/provider',
7360: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7361: notify => 'Notify when role needs authorization',
1.357 raeburn 7362: );
7363: my %names = &Apache::lonlocal::texthash (
7364: domain => 'Domain role',
7365: author => 'Co-author role',
7366: course => 'Course role',
7367: community => 'Community role',
7368: );
7369: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7370: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7371: foreach my $domtype ('instdom','extdom') {
7372: my (%checked,$skip);
7373: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7374: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7375: '<td class="LC_left_item">';
7376: if ($domtype eq 'instdom') {
7377: unless (@instdoms > 1) {
7378: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7379: $skip = 1;
7380: }
7381: } elsif ($domtype eq 'extdom') {
7382: if (keys(%by_location) == 0) {
7383: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7384: $skip = 1;
7385: }
7386: }
7387: unless ($skip) {
7388: foreach my $roletype ('domain','author','course','community') {
7389: $checked{'auto'} = ' checked="checked"';
7390: if (ref($settings) eq 'HASH') {
7391: if (ref($settings->{approval}) eq 'HASH') {
7392: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7393: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7394: $checked{$1} = ' checked="checked"';
7395: $checked{'auto'} = '';
7396: }
7397: }
7398: }
7399: }
7400: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7401: foreach my $option (@options) {
7402: $datatable .= '<span class="LC_nobreak"><label>'.
7403: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7404: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7405: '</label></span> ';
7406: }
7407: $datatable .= '</fieldset>';
7408: }
7409: }
7410: $datatable .= '</td></tr>';
7411: $itemcount ++;
7412: }
1.417 raeburn 7413: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7414: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7415: '<td class="LC_left_item">';
7416: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7417: my %curr;
7418: if (ref($settings) eq 'HASH') {
7419: if ($settings->{'notify'} ne '') {
7420: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7421: }
7422: }
7423: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7424: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7425: 'privacy_notify',%curr);
7426: if ($numdc > 0) {
7427: $datatable .= $table;
7428: } else {
7429: $datatable .= &mt('There are no active Domain Coordinators');
7430: }
7431: } else {
7432: $datatable .= &mt('Nothing to set here, as there are no other domains');
7433: }
7434: $datatable .='</td></tr>';
1.357 raeburn 7435: } elsif ($position eq 'middle') {
7436: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7437: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7438: foreach my $item (@{$types}) {
7439: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7440: $numinrow,$itemcount,'','','','','',
7441: '',$usertypes->{$item});
7442: $itemcount ++;
7443: }
7444: }
7445: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7446: $numinrow,$itemcount,'','','','','',
7447: '',$othertitle);
7448: $itemcount ++;
7449: } else {
1.360 raeburn 7450: my (@insttypes,%insttitles);
7451: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7452: @insttypes = @{$types};
7453: %insttitles = %{$usertypes};
7454: }
7455: foreach my $item (@insttypes,'default') {
7456: my $title;
7457: if ($item eq 'default') {
7458: $title = $othertitle;
7459: } else {
7460: $title = $insttitles{$item};
7461: }
7462: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7463: $datatable .= '<tr'.$css_class.'>'.
7464: '<td class="LC_left_item">'.$title.'</td>'.
7465: '<td class="LC_left_item">'.
7466: &mt('Nothing to set here, as there are no other domains').
7467: '</td></tr>';
7468: $itemcount ++;
7469: }
1.357 raeburn 7470: }
7471: }
7472: } else {
7473: my $prefix;
7474: if ($position eq 'lower') {
7475: $prefix = 'priv';
7476: } else {
7477: $prefix = 'unpriv';
7478: }
7479: foreach my $item (@items) {
7480: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7481: $numinrow,$itemcount,'','','','','',
7482: '',$names{$item});
7483: $itemcount ++;
7484: }
7485: }
7486: if (ref($rowtotal)) {
7487: $$rowtotal += $itemcount;
7488: }
7489: return $datatable;
7490: }
7491:
1.354 raeburn 7492: sub print_passwords {
7493: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7494: my ($datatable,$css_class);
7495: my $itemcount = 0;
7496: my %titles = &Apache::lonlocal::texthash (
7497: captcha => '"Forgot Password" CAPTCHA validation',
7498: link => 'Reset link expiration (hours)',
7499: case => 'Case-sensitive usernames/e-mail',
7500: prelink => 'Information required (form 1)',
7501: postlink => 'Information required (form 2)',
7502: emailsrc => 'LON-CAPA e-mail address type(s)',
7503: customtext => 'Domain specific text (HTML)',
7504: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7505: intauth_check => 'Check bcrypt cost if authenticated',
7506: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7507: permanent => 'Permanent e-mail address',
7508: critical => 'Critical notification address',
7509: notify => 'Notification address',
7510: min => 'Minimum password length',
7511: max => 'Maximum password length',
7512: chars => 'Required characters',
7513: expire => 'Password expiration (days)',
1.356 raeburn 7514: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7515: );
7516: if ($position eq 'top') {
7517: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7518: my $shownlinklife = 2;
7519: my $prelink = 'both';
7520: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7521: if (ref($settings) eq 'HASH') {
7522: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7523: $shownlinklife = $settings->{resetlink};
7524: }
7525: if (ref($settings->{resetcase}) eq 'ARRAY') {
7526: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7527: }
7528: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7529: $prelink = $settings->{resetprelink};
7530: }
7531: if (ref($settings->{resetpostlink}) eq 'HASH') {
7532: %postlink = %{$settings->{resetpostlink}};
7533: }
7534: if (ref($settings->{resetemail}) eq 'ARRAY') {
7535: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7536: }
7537: if ($settings->{resetremove}) {
7538: $nostdtext = 1;
7539: }
7540: if ($settings->{resetcustom}) {
7541: $customurl = $settings->{resetcustom};
7542: }
7543: } else {
7544: if (ref($types) eq 'ARRAY') {
7545: foreach my $item (@{$types}) {
7546: $casesens{$item} = 1;
7547: $postlink{$item} = ['username','email'];
7548: }
7549: }
7550: $casesens{'default'} = 1;
7551: $postlink{'default'} = ['username','email'];
7552: $prelink = 'both';
7553: %emailsrc = (
7554: permanent => 1,
7555: critical => 1,
7556: notify => 1,
7557: );
7558: }
7559: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7560: $itemcount ++;
7561: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7562: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7563: '<td class="LC_left_item">'.
7564: '<input type="textbox" value="'.$shownlinklife.'" '.
7565: 'name="passwords_link" size="3" /></td></tr>';
7566: $itemcount ++;
7567: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7568: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7569: '<td class="LC_left_item">';
7570: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7571: foreach my $item (@{$types}) {
7572: my $checkedcase;
7573: if ($casesens{$item}) {
7574: $checkedcase = ' checked="checked"';
7575: }
7576: $datatable .= '<span class="LC_nobreak"><label>'.
7577: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7578: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7579: '</span> ';
1.354 raeburn 7580: }
7581: }
7582: my $checkedcase;
7583: if ($casesens{'default'}) {
7584: $checkedcase = ' checked="checked"';
7585: }
7586: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7587: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7588: $othertitle.'</label></span></td>';
7589: $itemcount ++;
7590: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7591: my %checkedpre = (
7592: both => ' checked="checked"',
7593: either => '',
7594: );
7595: if ($prelink eq 'either') {
7596: $checkedpre{either} = ' checked="checked"';
7597: $checkedpre{both} = '';
7598: }
7599: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7600: '<td class="LC_left_item"><span class="LC_nobreak">'.
7601: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7602: &mt('Both username and e-mail address').'</label></span> '.
7603: '<span class="LC_nobreak"><label>'.
7604: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7605: &mt('Either username or e-mail address').'</label></span></td></tr>';
7606: $itemcount ++;
7607: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7608: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7609: '<td class="LC_left_item">';
7610: my %postlinked;
7611: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7612: foreach my $item (@{$types}) {
7613: undef(%postlinked);
7614: $datatable .= '<fieldset style="display: inline-block;">'.
7615: '<legend>'.$usertypes->{$item}.'</legend>';
7616: if (ref($postlink{$item}) eq 'ARRAY') {
7617: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7618: }
7619: foreach my $field ('email','username') {
7620: my $checked;
7621: if ($postlinked{$field}) {
7622: $checked = ' checked="checked"';
7623: }
7624: $datatable .= '<span class="LC_nobreak"><label>'.
7625: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7626: $field.'"'.$checked.' />'.$field.'</label>'.
7627: '<span> ';
7628: }
7629: $datatable .= '</fieldset>';
7630: }
7631: }
7632: if (ref($postlink{'default'}) eq 'ARRAY') {
7633: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7634: }
7635: $datatable .= '<fieldset style="display: inline-block;">'.
7636: '<legend>'.$othertitle.'</legend>';
7637: foreach my $field ('email','username') {
7638: my $checked;
7639: if ($postlinked{$field}) {
7640: $checked = ' checked="checked"';
7641: }
7642: $datatable .= '<span class="LC_nobreak"><label>'.
7643: '<input type="checkbox" name="passwords_postlink_default" value="'.
7644: $field.'"'.$checked.' />'.$field.'</label>'.
7645: '<span> ';
7646: }
7647: $datatable .= '</fieldset></td></tr>';
7648: $itemcount ++;
7649: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7650: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7651: '<td class="LC_left_item">';
7652: foreach my $type ('permanent','critical','notify') {
7653: my $checkedemail;
7654: if ($emailsrc{$type}) {
7655: $checkedemail = ' checked="checked"';
7656: }
7657: $datatable .= '<span class="LC_nobreak"><label>'.
7658: '<input type="checkbox" name="passwords_emailsrc" value="'.
7659: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7660: '<span> ';
7661: }
7662: $datatable .= '</td></tr>';
7663: $itemcount ++;
7664: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7665: my $switchserver = &check_switchserver($dom,$confname);
7666: my ($showstd,$noshowstd);
7667: if ($nostdtext) {
7668: $noshowstd = ' checked="checked"';
7669: } else {
7670: $showstd = ' checked="checked"';
7671: }
7672: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7673: '<td class="LC_left_item"><span class="LC_nobreak">'.
7674: &mt('Retain standard text:').
7675: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7676: &mt('Yes').'</label>'.' '.
7677: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7678: &mt('No').'</label></span><br />'.
7679: '<span class="LC_fontsize_small">'.
7680: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7681: &mt('Include custom text:');
7682: if ($customurl) {
1.369 raeburn 7683: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7684: undef,undef,undef,undef,'background-color:#ffffff');
7685: $datatable .= '<span class="LC_nobreak"> '.$link.
7686: '<label><input type="checkbox" name="passwords_custom_del"'.
7687: ' value="1" />'.&mt('Delete?').'</label></span>'.
7688: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7689: }
7690: if ($switchserver) {
7691: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7692: } else {
7693: $datatable .='<span class="LC_nobreak"> '.
7694: '<input type="file" name="passwords_customfile" /></span>';
7695: }
7696: $datatable .= '</td></tr>';
7697: } elsif ($position eq 'middle') {
7698: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7699: my @items = ('intauth_cost','intauth_check','intauth_switch');
7700: my %defaults;
7701: if (ref($domconf{'defaults'}) eq 'HASH') {
7702: %defaults = %{$domconf{'defaults'}};
7703: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7704: $defaults{'intauth_cost'} = 10;
7705: }
7706: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7707: $defaults{'intauth_check'} = 0;
7708: }
7709: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7710: $defaults{'intauth_switch'} = 0;
7711: }
7712: } else {
7713: %defaults = (
7714: 'intauth_cost' => 10,
7715: 'intauth_check' => 0,
7716: 'intauth_switch' => 0,
7717: );
7718: }
7719: foreach my $item (@items) {
7720: if ($itemcount%2) {
7721: $css_class = '';
7722: } else {
7723: $css_class = ' class="LC_odd_row" ';
7724: }
7725: $datatable .= '<tr'.$css_class.'>'.
7726: '<td><span class="LC_nobreak">'.$titles{$item}.
7727: '</span></td><td class="LC_left_item" colspan="3">';
7728: if ($item eq 'intauth_switch') {
7729: my @options = (0,1,2);
7730: my %optiondesc = &Apache::lonlocal::texthash (
7731: 0 => 'No',
7732: 1 => 'Yes',
7733: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7734: );
7735: $datatable .= '<table width="100%">';
7736: foreach my $option (@options) {
7737: my $checked = ' ';
7738: if ($defaults{$item} eq $option) {
7739: $checked = ' checked="checked"';
7740: }
7741: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7742: '<label><input type="radio" name="'.$item.
7743: '" value="'.$option.'"'.$checked.' />'.
7744: $optiondesc{$option}.'</label></span></td></tr>';
7745: }
7746: $datatable .= '</table>';
7747: } elsif ($item eq 'intauth_check') {
7748: my @options = (0,1,2);
7749: my %optiondesc = &Apache::lonlocal::texthash (
7750: 0 => 'No',
7751: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7752: 2 => 'Yes, disallow login if stored cost is less than domain default',
7753: );
7754: $datatable .= '<table width="100%">';
7755: foreach my $option (@options) {
7756: my $checked = ' ';
7757: my $onclick;
7758: if ($defaults{$item} eq $option) {
7759: $checked = ' checked="checked"';
7760: }
7761: if ($option == 2) {
7762: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7763: }
7764: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7765: '<label><input type="radio" name="'.$item.
7766: '" value="'.$option.'"'.$checked.$onclick.' />'.
7767: $optiondesc{$option}.'</label></span></td></tr>';
7768: }
7769: $datatable .= '</table>';
7770: } else {
7771: $datatable .= '<input type="text" name="'.$item.'" value="'.
7772: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7773: }
7774: $datatable .= '</td></tr>';
7775: $itemcount ++;
7776: }
7777: } elsif ($position eq 'lower') {
1.405 raeburn 7778: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 7779: } else {
1.359 raeburn 7780: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7781: my %ownerchg = (
7782: by => {},
7783: for => {},
7784: );
7785: my %ownertitles = &Apache::lonlocal::texthash (
7786: by => 'Course owner status(es) allowed',
7787: for => 'Student status(es) allowed',
7788: );
1.354 raeburn 7789: if (ref($settings) eq 'HASH') {
1.359 raeburn 7790: if (ref($settings->{crsownerchg}) eq 'HASH') {
7791: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7792: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7793: }
7794: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7795: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7796: }
1.354 raeburn 7797: }
7798: }
7799: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7800: $datatable .= '<tr '.$css_class.'>'.
7801: '<td>'.
7802: &mt('Requirements').'<ul>'.
1.359 raeburn 7803: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7804: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7805: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7806: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7807: '</ul>'.
7808: '</td>'.
1.359 raeburn 7809: '<td class="LC_left_item">';
7810: foreach my $item ('by','for') {
7811: $datatable .= '<fieldset style="display: inline-block;">'.
7812: '<legend>'.$ownertitles{$item}.'</legend>';
7813: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7814: foreach my $type (@{$types}) {
7815: my $checked;
7816: if ($ownerchg{$item}{$type}) {
7817: $checked = ' checked="checked"';
7818: }
7819: $datatable .= '<span class="LC_nobreak"><label>'.
7820: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7821: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7822: '</span> ';
1.359 raeburn 7823: }
7824: }
7825: my $checked;
7826: if ($ownerchg{$item}{'default'}) {
7827: $checked = ' checked="checked"';
7828: }
7829: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7830: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7831: $othertitle.'</label></span></fieldset>';
7832: }
7833: $datatable .= '</td></tr>';
1.354 raeburn 7834: }
7835: return $datatable;
7836: }
7837:
1.405 raeburn 7838: sub password_rules {
7839: my ($prefix,$itemcountref,$settings) = @_;
7840: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
7841: my %titles;
7842: if ($prefix eq 'passwords') {
7843: %titles = &Apache::lonlocal::texthash (
7844: min => 'Minimum password length',
7845: max => 'Maximum password length',
7846: chars => 'Required characters',
7847: );
1.421 raeburn 7848: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 7849: %titles = &Apache::lonlocal::texthash (
7850: min => 'Minimum secret length',
7851: max => 'Maximum secret length',
7852: chars => 'Required characters',
7853: );
7854: }
7855: $min = $Apache::lonnet::passwdmin;
7856: my $datatable;
7857: my $itemcount;
7858: if (ref($itemcountref)) {
7859: $itemcount = $$itemcountref;
7860: }
7861: if (ref($settings) eq 'HASH') {
7862: if ($settings->{min}) {
7863: $min = $settings->{min};
7864: }
7865: if ($settings->{max}) {
7866: $max = $settings->{max};
7867: }
7868: if (ref($settings->{chars}) eq 'ARRAY') {
7869: map { $chars{$_} = 1; } (@{$settings->{chars}});
7870: }
7871: if ($prefix eq 'passwords') {
7872: if ($settings->{expire}) {
7873: $expire = $settings->{expire};
7874: }
7875: if ($settings->{numsaved}) {
7876: $numsaved = $settings->{numsaved};
7877: }
7878: }
7879: }
7880: my %rulenames = &Apache::lonlocal::texthash(
7881: uc => 'At least one upper case letter',
7882: lc => 'At least one lower case letter',
7883: num => 'At least one number',
7884: spec => 'At least one non-alphanumeric',
7885: );
7886: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7887: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7888: '<td class="LC_left_item"><span class="LC_nobreak">'.
7889: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7890: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7891: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7892: '</span></td></tr>';
7893: $itemcount ++;
7894: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7895: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7896: '<td class="LC_left_item"><span class="LC_nobreak">'.
7897: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7898: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7899: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7900: '</span></td></tr>';
7901: $itemcount ++;
7902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7903: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7904: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7905: '</span></td>';
7906: my $numinrow = 2;
7907: my @possrules = ('uc','lc','num','spec');
7908: $datatable .= '<td class="LC_left_item"><table>';
7909: for (my $i=0; $i<@possrules; $i++) {
7910: my ($rem,$checked);
7911: if ($chars{$possrules[$i]}) {
7912: $checked = ' checked="checked"';
7913: }
7914: $rem = $i%($numinrow);
7915: if ($rem == 0) {
7916: if ($i > 0) {
7917: $datatable .= '</tr>';
7918: }
7919: $datatable .= '<tr>';
7920: }
7921: $datatable .= '<td><span class="LC_nobreak"><label>'.
7922: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7923: $rulenames{$possrules[$i]}.'</label></span></td>';
7924: }
7925: my $rem = @possrules%($numinrow);
7926: my $colsleft = $numinrow - $rem;
7927: if ($colsleft > 1 ) {
7928: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7929: ' </td>';
7930: } elsif ($colsleft == 1) {
7931: $datatable .= '<td class="LC_left_item"> </td>';
7932: }
7933: $datatable .='</table></td></tr>';
7934: $itemcount ++;
7935: if ($prefix eq 'passwords') {
7936: $titles{'expire'} = &mt('Password expiration (days)');
7937: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7939: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7940: '<td class="LC_left_item"><span class="LC_nobreak">'.
7941: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
7942: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7943: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7944: '</span></td></tr>';
7945: $itemcount ++;
7946: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7947: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7948: '<td class="LC_left_item"><span class="LC_nobreak">'.
7949: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7950: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7951: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7952: '</span></td></tr>';
7953: $itemcount ++;
7954: }
7955: if (ref($itemcountref)) {
7956: $$itemcountref += $itemcount;
7957: }
7958: return $datatable;
7959: }
7960:
1.373 raeburn 7961: sub print_wafproxy {
7962: my ($position,$dom,$settings,$rowtotal) = @_;
7963: my $css_class;
7964: my $itemcount = 0;
7965: my $datatable;
7966: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7967: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7968: my %lt = &wafproxy_titles();
1.373 raeburn 7969: foreach my $server (sort(keys(%servers))) {
7970: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7971: next if ($serverhome eq '');
1.373 raeburn 7972: my $serverdom;
7973: if ($serverhome ne $server) {
7974: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7975: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7976: $othercontrol{$server} = $serverdom;
7977: }
1.373 raeburn 7978: } else {
7979: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7980: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7981: if ($serverdom ne $dom) {
7982: $othercontrol{$server} = $serverdom;
7983: } else {
7984: $setdom = 1;
7985: if (ref($settings) eq 'HASH') {
7986: if (ref($settings->{'alias'}) eq 'HASH') {
7987: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7988: if ($aliases{$dom} ne '') {
7989: $showdom = 1;
7990: }
1.373 raeburn 7991: }
1.388 raeburn 7992: if (ref($settings->{'saml'}) eq 'HASH') {
7993: $saml{$dom} = $settings->{'saml'};
7994: }
1.373 raeburn 7995: }
7996: }
7997: }
7998: }
1.381 raeburn 7999: if ($setdom) {
8000: %{$values{$dom}} = ();
8001: if (ref($settings) eq 'HASH') {
8002: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8003: $values{$dom}{$item} = $settings->{$item};
8004: }
8005: }
8006: }
1.373 raeburn 8007: if (keys(%othercontrol)) {
8008: %otherdoms = reverse(%othercontrol);
8009: foreach my $domain (keys(%otherdoms)) {
8010: %{$values{$domain}} = ();
8011: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8012: if (ref($config{'wafproxy'}) eq 'HASH') {
8013: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 8014: if (exists($config{'wafproxy'}{'saml'})) {
8015: $saml{$domain} = $config{'wafproxy'}{'saml'};
8016: }
1.383 raeburn 8017: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8018: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8019: }
8020: }
8021: }
8022: }
8023: if ($position eq 'top') {
8024: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8025: my %aliasinfo;
1.373 raeburn 8026: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8027: $itemcount ++;
8028: my $dom_in_effect;
8029: my $aliasrows = '<tr>'.
1.383 raeburn 8030: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8031: &mt('Hostname').': '.
8032: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8033: if ($othercontrol{$server}) {
1.381 raeburn 8034: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8035: my ($current,$forsaml);
1.383 raeburn 8036: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8037: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8038: }
1.388 raeburn 8039: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8040: if ($saml{$dom_in_effect}{$server}) {
8041: $forsaml = 1;
8042: }
8043: }
1.383 raeburn 8044: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8045: &mt('Alias').': ';
1.373 raeburn 8046: if ($current) {
1.381 raeburn 8047: $aliasrows .= $current;
1.388 raeburn 8048: if ($forsaml) {
1.396 raeburn 8049: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8050: }
1.373 raeburn 8051: } else {
1.383 raeburn 8052: $aliasrows .= &mt('None');
1.373 raeburn 8053: }
1.383 raeburn 8054: $aliasrows .= ' <span class="LC_small">('.
8055: &mt('controlled by domain: [_1]',
8056: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8057: } else {
1.381 raeburn 8058: $dom_in_effect = $dom;
1.388 raeburn 8059: my ($current,$samlon,$samloff);
8060: $samloff = ' checked="checked"';
1.373 raeburn 8061: if (ref($aliases{$dom}) eq 'HASH') {
8062: if ($aliases{$dom}{$server}) {
8063: $current = $aliases{$dom}{$server};
8064: }
8065: }
1.388 raeburn 8066: if (ref($saml{$dom}) eq 'HASH') {
8067: if ($saml{$dom}{$server}) {
8068: $samlon = $samloff;
8069: undef($samloff);
8070: }
8071: }
1.383 raeburn 8072: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8073: &mt('Alias').': '.
1.381 raeburn 8074: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8075: 'value="'.$current.'" size="30" />'.
8076: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8077: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8078: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
8079: &mt('No').'</label> <label>'.
8080: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8081: &mt('Yes').'</label></span>'.
8082: '</td>';
1.381 raeburn 8083: }
8084: $aliasrows .= '</tr>';
8085: $aliasinfo{$dom_in_effect} .= $aliasrows;
8086: }
8087: if ($aliasinfo{$dom}) {
8088: my ($onclick,$wafon,$wafoff,$showtable);
8089: $onclick = ' onclick="javascript:toggleWAF();"';
8090: $wafoff = ' checked="checked"';
8091: $showtable = ' style="display:none";';
8092: if ($showdom) {
8093: $wafon = $wafoff;
8094: $wafoff = '';
8095: $showtable = ' style="display:inline;"';
8096: }
8097: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8098: $datatable = '<tr'.$css_class.'>'.
8099: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8100: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8101: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8102: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8103: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8104: &mt('No').'</label></span></td>'.
8105: '<td class="LC_left_item">'.
8106: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8107: '</table></td></tr>';
8108: $itemcount++;
8109: }
1.383 raeburn 8110: if (keys(%otherdoms)) {
8111: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8112: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8113: $datatable .= '<tr'.$css_class.'>'.
8114: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8115: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8116: '</table></td></tr>';
1.381 raeburn 8117: $itemcount++;
1.373 raeburn 8118: }
8119: }
8120: } else {
1.383 raeburn 8121: my %ip_methods = &remoteip_methods();
1.373 raeburn 8122: if ($setdom) {
8123: $itemcount ++;
8124: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8125: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8126: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8127: $wafstyle = ' style="display:none;"';
8128: $nowafstyle = ' style="display:table-row;"';
8129: $currwafdisplay = ' style="display: none"';
8130: $wafrangestyle = ' style="display: none"';
8131: $curr_remotip = 'n';
1.382 raeburn 8132: $ssltossl = ' checked="checked"';
1.381 raeburn 8133: if ($showdom) {
8134: $wafstyle = ' style="display:table-row;"';
8135: $nowafstyle = ' style="display:none;"';
8136: if (keys(%{$values{$dom}})) {
8137: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8138: $curr_remotip = $values{$dom}{remoteip};
8139: }
8140: if ($curr_remotip eq 'h') {
8141: $currwafdisplay = ' style="display:table-row"';
8142: $wafrangestyle = ' style="display:inline-block;"';
8143: }
1.382 raeburn 8144: if ($values{$dom}{'sslopt'}) {
8145: $alltossl = ' checked="checked"';
8146: $ssltossl = '';
8147: }
1.381 raeburn 8148: }
8149: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8150: $vpndircheck = ' checked="checked"';
8151: $currwafvpn = ' style="display:table-row;"';
8152: $wafrangestyle = ' style="display:inline-block;"';
8153: } else {
8154: $vpnaliascheck = ' checked="checked"';
8155: $currwafvpn = ' style="display:none;"';
8156: }
8157: }
8158: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8159: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8160: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8161: '</tr>'.
8162: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8163: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8164: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8165: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8166: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8167: '<td class="LC_left_item"><table>'.
8168: '<tr>'.
8169: '<td valign="top">'.$lt{'remoteip'}.': '.
8170: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8171: foreach my $option ('m','h','n') {
8172: my $sel;
8173: if ($option eq $curr_remotip) {
8174: $sel = ' selected="selected"';
8175: }
8176: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8177: $ip_methods{$option}.'</option>';
8178: }
8179: $datatable .= '</select></td></tr>'."\n".
8180: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8181: $lt{'ipheader'}.': '.
8182: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8183: 'name="wafproxy_ipheader" />'.
8184: '</td></tr>'."\n".
8185: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8186: $lt{'trusted'}.':<br />'.
1.381 raeburn 8187: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8188: $values{$dom}{'trusted'}.'</textarea>'.
8189: '</td></tr>'."\n".
8190: '<tr><td><hr /></td></tr>'."\n".
8191: '<tr>'.
8192: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8193: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8194: $lt{'vpndirect'}.'</label>'.(' 'x2).
8195: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8196: $lt{'vpnaliased'}.'</label></span></td></tr>';
8197: foreach my $item ('vpnint','vpnext') {
8198: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8199: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8200: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8201: $values{$dom}{$item}.'</textarea>'.
8202: '</td></tr>'."\n";
1.373 raeburn 8203: }
1.382 raeburn 8204: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8205: '<tr>'.
8206: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8207: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8208: $lt{'alltossl'}.'</label>'.(' 'x2).
8209: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8210: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8211: '</table></td></tr>';
1.373 raeburn 8212: }
8213: if (keys(%otherdoms)) {
8214: foreach my $domain (sort(keys(%otherdoms))) {
8215: $itemcount ++;
8216: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8217: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8218: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8219: '<td class="LC_left_item"><table>';
1.382 raeburn 8220: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8221: my $showval = &mt('None');
1.382 raeburn 8222: if ($item eq 'ssl') {
8223: $showval = $lt{'ssltossl'};
8224: }
1.373 raeburn 8225: if ($values{$domain}{$item}) {
1.381 raeburn 8226: $showval = $values{$domain}{$item};
1.382 raeburn 8227: if ($item eq 'ssl') {
8228: $showval = $lt{'alltossl'};
1.383 raeburn 8229: } elsif ($item eq 'remoteip') {
8230: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8231: }
1.373 raeburn 8232: }
8233: $datatable .= '<tr>'.
8234: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8235: }
1.381 raeburn 8236: $datatable .= '</table></td></tr>';
1.373 raeburn 8237: }
8238: }
8239: }
8240: $$rowtotal += $itemcount;
8241: return $datatable;
8242: }
8243:
8244: sub wafproxy_titles {
8245: return &Apache::lonlocal::texthash(
1.381 raeburn 8246: remoteip => "Method for determining user's IP",
8247: ipheader => 'Request header containing remote IP',
8248: trusted => 'Trusted IP range(s)',
8249: vpnaccess => 'Access from institutional VPN',
8250: vpndirect => 'via regular hostname (no WAF)',
8251: vpnaliased => 'via aliased hostname (WAF)',
8252: vpnint => 'Internal IP Range(s) for VPN sessions',
8253: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8254: sslopt => 'Forwarding http/https',
1.381 raeburn 8255: alltossl => 'WAF forwards both http and https requests to https',
8256: ssltossl => 'WAF forwards http requests to http and https to https',
8257: );
8258: }
8259:
8260: sub remoteip_methods {
8261: return &Apache::lonlocal::texthash(
8262: m => 'Use Apache mod_remoteip',
8263: h => 'Use headers parsed by LON-CAPA',
8264: n => 'Not in use',
1.373 raeburn 8265: );
8266: }
8267:
1.137 raeburn 8268: sub print_usersessions {
8269: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8270: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8271: my (%by_ip,%by_location,@intdoms,@instdoms);
8272: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8273:
8274: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8275: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8276: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8277: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8278: if ($position eq 'top') {
1.152 raeburn 8279: if (keys(%serverhomes) > 1) {
1.145 raeburn 8280: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8281: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8282: if (ref($settings) eq 'HASH') {
8283: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8284: $curroffloadnow = $settings->{'offloadnow'};
8285: }
1.371 raeburn 8286: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8287: $curroffloadoth = $settings->{'offloadoth'};
8288: }
1.261 raeburn 8289: }
1.371 raeburn 8290: my $other_insts = scalar(keys(%by_location));
8291: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8292: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8293: } else {
1.140 raeburn 8294: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8295: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8296: '</td></tr>';
1.140 raeburn 8297: }
1.137 raeburn 8298: } else {
1.279 raeburn 8299: my %titles = &usersession_titles();
8300: my ($prefix,@types);
8301: if ($position eq 'bottom') {
8302: $prefix = 'remote';
8303: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8304: } else {
1.279 raeburn 8305: $prefix = 'hosted';
8306: @types = ('excludedomain','includedomain');
8307: }
8308: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8309: }
8310: $$rowtotal += $itemcount;
8311: return $datatable;
8312: }
8313:
8314: sub rules_by_location {
8315: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8316: my ($datatable,$itemcount,$css_class);
8317: if (keys(%{$by_location}) == 0) {
8318: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8319: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8320: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8321: '</td></tr>';
8322: $itemcount = 1;
8323: } else {
8324: $itemcount = 0;
8325: my $numinrow = 5;
8326: my (%current,%checkedon,%checkedoff);
8327: my @locations = sort(keys(%{$by_location}));
8328: foreach my $type (@{$types}) {
8329: $checkedon{$type} = '';
8330: $checkedoff{$type} = ' checked="checked"';
8331: }
8332: if (ref($settings) eq 'HASH') {
8333: if (ref($settings->{$prefix}) eq 'HASH') {
8334: foreach my $key (keys(%{$settings->{$prefix}})) {
8335: $current{$key} = $settings->{$prefix}{$key};
8336: if ($key eq 'version') {
8337: if ($current{$key} ne '') {
1.145 raeburn 8338: $checkedon{$key} = ' checked="checked"';
8339: $checkedoff{$key} = '';
8340: }
1.279 raeburn 8341: } elsif (ref($current{$key}) eq 'ARRAY') {
8342: $checkedon{$key} = ' checked="checked"';
8343: $checkedoff{$key} = '';
1.137 raeburn 8344: }
8345: }
8346: }
1.279 raeburn 8347: }
8348: foreach my $type (@{$types}) {
8349: next if ($type ne 'version' && !@locations);
8350: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8351: $datatable .= '<tr'.$css_class.'>
8352: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8353: <span class="LC_nobreak">
8354: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8355: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8356: if ($type eq 'version') {
8357: my @lcversions = &Apache::lonnet::all_loncaparevs();
8358: my $selector = '<select name="'.$prefix.'_version">';
8359: foreach my $version (@lcversions) {
8360: my $selected = '';
8361: if ($current{'version'} eq $version) {
8362: $selected = ' selected="selected"';
1.145 raeburn 8363: }
1.279 raeburn 8364: $selector .= ' <option value="'.$version.'"'.
8365: $selected.'>'.$version.'</option>';
8366: }
8367: $selector .= '</select> ';
8368: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8369: } else {
8370: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8371: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8372: ' />'.(' 'x2).
8373: '<input type="button" value="'.&mt('uncheck all').'" '.
8374: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8375: "\n".
8376: '</div><div><table>';
8377: my $rem;
8378: for (my $i=0; $i<@locations; $i++) {
8379: my ($showloc,$value,$checkedtype);
8380: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8381: my $ip = $by_location->{$locations[$i]}->[0];
8382: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8383: $value = join(':',@{$by_ip->{$ip}});
8384: $showloc = join(', ',@{$by_ip->{$ip}});
8385: if (ref($current{$type}) eq 'ARRAY') {
8386: foreach my $loc (@{$by_ip->{$ip}}) {
8387: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8388: $checkedtype = ' checked="checked"';
8389: last;
1.145 raeburn 8390: }
1.138 raeburn 8391: }
8392: }
8393: }
1.137 raeburn 8394: }
1.279 raeburn 8395: $rem = $i%($numinrow);
8396: if ($rem == 0) {
8397: if ($i > 0) {
8398: $datatable .= '</tr>';
8399: }
8400: $datatable .= '<tr>';
8401: }
8402: $datatable .= '<td class="LC_left_item">'.
8403: '<span class="LC_nobreak"><label>'.
8404: '<input type="checkbox" name="'.$prefix.'_'.$type.
8405: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8406: '</label></span></td>';
8407: }
8408: $rem = @locations%($numinrow);
8409: my $colsleft = $numinrow - $rem;
8410: if ($colsleft > 1 ) {
8411: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8412: ' </td>';
8413: } elsif ($colsleft == 1) {
8414: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8415: }
1.279 raeburn 8416: $datatable .= '</tr></table>';
1.137 raeburn 8417: }
1.279 raeburn 8418: $datatable .= '</td></tr>';
8419: $itemcount ++;
1.137 raeburn 8420: }
8421: }
1.279 raeburn 8422: return ($datatable,$itemcount);
1.137 raeburn 8423: }
8424:
1.275 raeburn 8425: sub print_ssl {
8426: my ($position,$dom,$settings,$rowtotal) = @_;
8427: my ($css_class,$datatable);
8428: my $itemcount = 1;
8429: if ($position eq 'top') {
1.281 raeburn 8430: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8431: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8432: my $same_institution;
8433: if ($intdom ne '') {
8434: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8435: if (ref($internet_names) eq 'ARRAY') {
8436: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8437: $same_institution = 1;
8438: }
8439: }
8440: }
1.275 raeburn 8441: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8442: $datatable = '<tr'.$css_class.'><td colspan="2">';
8443: if ($same_institution) {
8444: my %domservers = &Apache::lonnet::get_servers($dom);
8445: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8446: } else {
8447: $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.");
8448: }
8449: $datatable .= '</td></tr>';
1.275 raeburn 8450: $itemcount ++;
8451: } else {
8452: my %titles = &ssl_titles();
8453: my (%by_ip,%by_location,@intdoms,@instdoms);
8454: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8455: my @alldoms = &Apache::lonnet::all_domains();
8456: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8457: my @domservers = &Apache::lonnet::get_servers($dom);
8458: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8459: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8460: if (($position eq 'connto') || ($position eq 'connfrom')) {
8461: my $legacy;
8462: unless (ref($settings) eq 'HASH') {
8463: my $name;
8464: if ($position eq 'connto') {
8465: $name = 'loncAllowInsecure';
8466: } else {
8467: $name = 'londAllowInsecure';
8468: }
8469: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8470: my @ids=&Apache::lonnet::current_machine_ids();
8471: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8472: my %what = (
8473: $name => 1,
8474: );
8475: my ($result,$returnhash) =
8476: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8477: if ($result eq 'ok') {
8478: if (ref($returnhash) eq 'HASH') {
8479: $legacy = $returnhash->{$name};
8480: }
8481: }
8482: } else {
8483: $legacy = $Apache::lonnet::perlvar{$name};
8484: }
8485: }
1.275 raeburn 8486: foreach my $type ('dom','intdom','other') {
8487: my %checked;
8488: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8489: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8490: '<td class="LC_right_item">';
8491: my $skip;
8492: if ($type eq 'dom') {
8493: unless (keys(%servers) > 1) {
8494: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8495: $skip = 1;
8496: }
8497: }
8498: if ($type eq 'intdom') {
8499: unless (@instdoms > 1) {
8500: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8501: $skip = 1;
8502: }
8503: } elsif ($type eq 'other') {
8504: if (keys(%by_location) == 0) {
8505: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8506: $skip = 1;
8507: }
8508: }
8509: unless ($skip) {
8510: $checked{'yes'} = ' checked="checked"';
8511: if (ref($settings) eq 'HASH') {
1.293 raeburn 8512: if (ref($settings->{$position}) eq 'HASH') {
8513: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8514: $checked{$1} = $checked{'yes'};
8515: delete($checked{'yes'});
8516: }
8517: }
1.293 raeburn 8518: } else {
8519: if ($legacy == 0) {
8520: $checked{'req'} = $checked{'yes'};
8521: delete($checked{'yes'});
8522: }
1.275 raeburn 8523: }
8524: foreach my $option ('no','yes','req') {
8525: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8526: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8527: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8528: '</label></span>'.(' 'x2);
8529: }
8530: }
8531: $datatable .= '</td></tr>';
8532: $itemcount ++;
8533: }
8534: } else {
8535: my $prefix = 'replication';
8536: my @types = ('certreq','nocertreq');
1.279 raeburn 8537: if (keys(%by_location) == 0) {
8538: $datatable .= '<tr'.$css_class.'><td>'.
8539: &mt('Nothing to set here, as there are no other institutions').
8540: '</td></tr>';
8541: $itemcount ++;
1.275 raeburn 8542: } else {
1.279 raeburn 8543: ($datatable,$itemcount) =
8544: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8545: }
8546: }
8547: }
8548: $$rowtotal += $itemcount;
8549: return $datatable;
8550: }
8551:
8552: sub ssl_titles {
8553: return &Apache::lonlocal::texthash (
8554: dom => 'LON-CAPA servers/VMs from same domain',
8555: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8556: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8557: connto => 'Connections to other servers',
8558: connfrom => 'Connections from other servers',
1.275 raeburn 8559: replication => 'Replicating content to other institutions',
8560: certreq => 'Client certificate required, but specific domains exempt',
8561: nocertreq => 'No client certificate required, except for specific domains',
8562: no => 'SSL not used',
8563: yes => 'SSL Optional (used if available)',
8564: req => 'SSL Required',
8565: );
1.279 raeburn 8566: }
8567:
8568: sub print_trust {
8569: my ($prefix,$dom,$settings,$rowtotal) = @_;
8570: my ($css_class,$datatable,%checked,%choices);
8571: my (%by_ip,%by_location,@intdoms,@instdoms);
8572: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8573: my $itemcount = 1;
8574: my %titles = &trust_titles();
8575: my @types = ('exc','inc');
8576: if ($prefix eq 'top') {
8577: $prefix = 'content';
8578: } elsif ($prefix eq 'bottom') {
8579: $prefix = 'msg';
8580: }
8581: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8582: $$rowtotal += $itemcount;
8583: return $datatable;
8584: }
8585:
8586: sub trust_titles {
8587: return &Apache::lonlocal::texthash(
8588: content => "Access to this domain's content by others",
8589: shared => "Access to other domain's content by this domain",
8590: enroll => "Enrollment in this domain's courses by others",
8591: othcoau => "Co-author roles in this domain for others",
8592: coaurem => "Co-author roles for this domain's users elsewhere",
8593: domroles => "Domain roles in this domain assignable to others",
8594: catalog => "Course Catalog for this domain displayed elsewhere",
8595: reqcrs => "Requests for creation of courses in this domain by others",
8596: msg => "Users in other domains can send messages to this domain",
8597: exc => "Allow all, but exclude specific domains",
8598: inc => "Deny all, but include specific domains",
8599: );
1.275 raeburn 8600: }
8601:
1.138 raeburn 8602: sub build_location_hashes {
1.275 raeburn 8603: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8604: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8605: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8606: my %iphost = &Apache::lonnet::get_iphost();
8607: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8608: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8609: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8610: foreach my $id (@{$iphost{$primary_ip}}) {
8611: my $intdom = &Apache::lonnet::internet_dom($id);
8612: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8613: push(@{$intdoms},$intdom);
8614: }
8615: }
8616: }
8617: foreach my $ip (keys(%iphost)) {
8618: if (ref($iphost{$ip}) eq 'ARRAY') {
8619: foreach my $id (@{$iphost{$ip}}) {
8620: my $location = &Apache::lonnet::internet_dom($id);
8621: if ($location) {
1.275 raeburn 8622: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8623: my $dom = &Apache::lonnet::host_domain($id);
8624: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8625: push(@{$instdoms},$dom);
8626: }
8627: next;
8628: }
1.138 raeburn 8629: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8630: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8631: push(@{$by_ip->{$ip}},$location);
8632: }
8633: } else {
8634: $by_ip->{$ip} = [$location];
8635: }
8636: }
8637: }
8638: }
8639: }
8640: foreach my $ip (sort(keys(%{$by_ip}))) {
8641: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8642: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8643: my $first = $by_ip->{$ip}->[0];
8644: if (ref($by_location->{$first}) eq 'ARRAY') {
8645: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8646: push(@{$by_location->{$first}},$ip);
8647: }
8648: } else {
8649: $by_location->{$first} = [$ip];
8650: }
8651: }
8652: }
8653: return;
8654: }
8655:
1.145 raeburn 8656: sub current_offloads_to {
8657: my ($dom,$settings,$servers) = @_;
8658: my (%spareid,%otherdomconfigs);
1.152 raeburn 8659: if (ref($servers) eq 'HASH') {
1.145 raeburn 8660: foreach my $lonhost (sort(keys(%{$servers}))) {
8661: my $gotspares;
1.152 raeburn 8662: if (ref($settings) eq 'HASH') {
8663: if (ref($settings->{'spares'}) eq 'HASH') {
8664: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8665: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8666: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8667: $gotspares = 1;
8668: }
1.145 raeburn 8669: }
8670: }
8671: unless ($gotspares) {
8672: my $gotspares;
8673: my $serverhomeID =
8674: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8675: my $serverhomedom =
8676: &Apache::lonnet::host_domain($serverhomeID);
8677: if ($serverhomedom ne $dom) {
8678: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8679: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8680: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8681: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8682: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8683: $gotspares = 1;
8684: }
8685: }
8686: } else {
8687: $otherdomconfigs{$serverhomedom} =
8688: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8689: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8690: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8691: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8692: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8693: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8694: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8695: $gotspares = 1;
8696: }
8697: }
8698: }
8699: }
8700: }
8701: }
8702: }
8703: unless ($gotspares) {
8704: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8705: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8706: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8707: } else {
8708: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8709: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8710: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8711: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8712: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8713: } else {
1.150 raeburn 8714: my %what = (
8715: spareid => 1,
8716: );
8717: my ($result,$returnhash) =
8718: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8719: if ($result eq 'ok') {
8720: if (ref($returnhash) eq 'HASH') {
8721: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8722: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8723: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8724: }
8725: }
1.145 raeburn 8726: }
8727: }
8728: }
8729: }
8730: }
8731: }
8732: return %spareid;
8733: }
8734:
8735: sub spares_row {
1.371 raeburn 8736: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8737: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8738: my $css_class;
8739: my $numinrow = 4;
8740: my $itemcount = 1;
8741: my $datatable;
1.152 raeburn 8742: my %typetitles = &sparestype_titles();
8743: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8744: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8745: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8746: my ($othercontrol,$serverdom);
8747: if ($serverhome ne $server) {
8748: $serverdom = &Apache::lonnet::host_domain($serverhome);
8749: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8750: } else {
8751: $serverdom = &Apache::lonnet::host_domain($server);
8752: if ($serverdom ne $dom) {
8753: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8754: }
8755: }
8756: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8757: my ($checkednow,$checkedoth);
1.261 raeburn 8758: if (ref($curroffloadnow) eq 'HASH') {
8759: if ($curroffloadnow->{$server}) {
8760: $checkednow = ' checked="checked"';
8761: }
8762: }
1.371 raeburn 8763: if (ref($curroffloadoth) eq 'HASH') {
8764: if ($curroffloadoth->{$server}) {
8765: $checkedoth = ' checked="checked"';
8766: }
8767: }
1.145 raeburn 8768: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8769: $datatable .= '<tr'.$css_class.'>
8770: <td rowspan="2">
1.183 bisitz 8771: <span class="LC_nobreak">'.
8772: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8773: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8774: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8775: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8776: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8777: "\n";
1.371 raeburn 8778: if ($other_insts) {
8779: $datatable .= '<br />'.
8780: '<span class="LC_nobreak">'."\n".
8781: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8782: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8783: "\n";
8784: }
1.145 raeburn 8785: my (%current,%canselect);
1.152 raeburn 8786: my @choices =
8787: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8788: foreach my $type ('primary','default') {
8789: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8790: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8791: my @spares = @{$spareid->{$server}{$type}};
8792: if (@spares > 0) {
1.152 raeburn 8793: if ($othercontrol) {
8794: $current{$type} = join(', ',@spares);
8795: } else {
8796: $current{$type} .= '<table>';
8797: my $numspares = scalar(@spares);
8798: for (my $i=0; $i<@spares; $i++) {
8799: my $rem = $i%($numinrow);
8800: if ($rem == 0) {
8801: if ($i > 0) {
8802: $current{$type} .= '</tr>';
8803: }
8804: $current{$type} .= '<tr>';
1.145 raeburn 8805: }
1.152 raeburn 8806: $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'".');" /> '.
8807: $spareid->{$server}{$type}[$i].
8808: '</label></td>'."\n";
8809: }
8810: my $rem = @spares%($numinrow);
8811: my $colsleft = $numinrow - $rem;
8812: if ($colsleft > 1 ) {
8813: $current{$type} .= '<td colspan="'.$colsleft.
8814: '" class="LC_left_item">'.
8815: ' </td>';
8816: } elsif ($colsleft == 1) {
8817: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8818: }
1.152 raeburn 8819: $current{$type} .= '</tr></table>';
1.150 raeburn 8820: }
1.145 raeburn 8821: }
8822: }
8823: if ($current{$type} eq '') {
8824: $current{$type} = &mt('None specified');
8825: }
1.152 raeburn 8826: if ($othercontrol) {
8827: if ($type eq 'primary') {
8828: $canselect{$type} = $othercontrol;
8829: }
8830: } else {
8831: $canselect{$type} =
8832: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8833: '<select name="newspare_'.$type.'_'.$server.'" '.
8834: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8835: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8836: if (@choices > 0) {
8837: foreach my $lonhost (@choices) {
8838: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8839: }
8840: }
8841: $canselect{$type} .= '</select>'."\n";
8842: }
8843: } else {
8844: $current{$type} = &mt('Could not be determined');
8845: if ($type eq 'primary') {
8846: $canselect{$type} = $othercontrol;
8847: }
1.145 raeburn 8848: }
1.152 raeburn 8849: if ($type eq 'default') {
8850: $datatable .= '<tr'.$css_class.'>';
8851: }
8852: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8853: '<td>'.$current{$type}.'</td>'."\n".
8854: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8855: }
8856: $itemcount ++;
8857: }
8858: }
8859: $$rowtotal += $itemcount;
8860: return $datatable;
8861: }
8862:
1.152 raeburn 8863: sub possible_newspares {
8864: my ($server,$currspares,$serverhomes,$altids) = @_;
8865: my $serverhostname = &Apache::lonnet::hostname($server);
8866: my %excluded;
8867: if ($serverhostname ne '') {
8868: %excluded = (
8869: $serverhostname => 1,
8870: );
8871: }
8872: if (ref($currspares) eq 'HASH') {
8873: foreach my $type (keys(%{$currspares})) {
8874: if (ref($currspares->{$type}) eq 'ARRAY') {
8875: if (@{$currspares->{$type}} > 0) {
8876: foreach my $curr (@{$currspares->{$type}}) {
8877: my $hostname = &Apache::lonnet::hostname($curr);
8878: $excluded{$hostname} = 1;
8879: }
8880: }
8881: }
8882: }
8883: }
8884: my @choices;
8885: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8886: if (keys(%{$serverhomes}) > 1) {
8887: foreach my $name (sort(keys(%{$serverhomes}))) {
8888: unless ($excluded{$name}) {
8889: if (exists($altids->{$serverhomes->{$name}})) {
8890: push(@choices,$altids->{$serverhomes->{$name}});
8891: } else {
8892: push(@choices,$serverhomes->{$name});
1.145 raeburn 8893: }
8894: }
8895: }
8896: }
8897: }
1.152 raeburn 8898: return sort(@choices);
1.145 raeburn 8899: }
8900:
1.150 raeburn 8901: sub print_loadbalancing {
8902: my ($dom,$settings,$rowtotal) = @_;
8903: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8904: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8905: my $numinrow = 1;
8906: my $datatable;
8907: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8908: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8909: if (ref($settings) eq 'HASH') {
8910: %existing = %{$settings};
8911: }
8912: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8913: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8914: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8915: } else {
8916: return;
8917: }
8918: my ($othertitle,$usertypes,$types) =
8919: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8920: my $rownum = 8;
1.150 raeburn 8921: if (ref($types) eq 'ARRAY') {
8922: $rownum += scalar(@{$types});
8923: }
1.171 raeburn 8924: my @css_class = ('LC_odd_row','LC_even_row');
8925: my $balnum = 0;
8926: my $islast;
8927: my (@toshow,$disabledtext);
8928: if (keys(%currbalancer) > 0) {
8929: @toshow = sort(keys(%currbalancer));
8930: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8931: push(@toshow,'');
8932: }
8933: } else {
8934: @toshow = ('');
8935: $disabledtext = &mt('No existing load balancer');
8936: }
8937: foreach my $lonhost (@toshow) {
8938: if ($balnum == scalar(@toshow)-1) {
8939: $islast = 1;
8940: } else {
8941: $islast = 0;
8942: }
8943: my $cssidx = $balnum%2;
8944: my $targets_div_style = 'display: none';
8945: my $disabled_div_style = 'display: block';
8946: my $homedom_div_style = 'display: none';
8947: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8948: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8949: '<p>';
8950: if ($lonhost eq '') {
1.210 raeburn 8951: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8952: if (keys(%currbalancer) > 0) {
8953: $datatable .= &mt('Add balancer:');
8954: } else {
8955: $datatable .= &mt('Enable balancer:');
8956: }
8957: $datatable .= ' '.
8958: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8959: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8960: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8961: '<option value="" selected="selected">'.&mt('None').
8962: '</option>'."\n";
8963: foreach my $server (sort(keys(%servers))) {
8964: next if ($currbalancer{$server});
8965: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8966: }
1.210 raeburn 8967: $datatable .=
1.171 raeburn 8968: '</select>'."\n".
8969: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8970: } else {
8971: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8972: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8973: &mt('Stop balancing').'</label>'.
8974: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8975: $targets_div_style = 'display: block';
8976: $disabled_div_style = 'display: none';
8977: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8978: $homedom_div_style = 'display: block';
8979: }
8980: }
1.306 raeburn 8981: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8982: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8983: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8984: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8985: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8986: my @sparestypes = ('primary','default');
8987: my %typetitles = &sparestype_titles();
1.284 raeburn 8988: my %hostherechecked = (
8989: no => ' checked="checked"',
8990: );
1.342 raeburn 8991: my %balcookiechecked = (
8992: no => ' checked="checked"',
8993: );
1.171 raeburn 8994: foreach my $sparetype (@sparestypes) {
8995: my $targettable;
8996: for (my $i=0; $i<$numspares; $i++) {
8997: my $checked;
8998: if (ref($currtargets{$lonhost}) eq 'HASH') {
8999: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9000: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9001: $checked = ' checked="checked"';
9002: }
9003: }
9004: }
9005: my ($chkboxval,$disabled);
9006: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9007: $chkboxval = $spares[$i];
9008: }
9009: if (exists($currbalancer{$spares[$i]})) {
9010: $disabled = ' disabled="disabled"';
9011: }
1.210 raeburn 9012: $targettable .=
1.253 raeburn 9013: '<td><span class="LC_nobreak"><label>'.
9014: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9015: $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 9016: '</span></label></span></td>';
1.171 raeburn 9017: my $rem = $i%($numinrow);
9018: if ($rem == 0) {
9019: if (($i > 0) && ($i < $numspares-1)) {
9020: $targettable .= '</tr>';
9021: }
9022: if ($i < $numspares-1) {
9023: $targettable .= '<tr>';
1.150 raeburn 9024: }
9025: }
9026: }
1.171 raeburn 9027: if ($targettable ne '') {
9028: my $rem = $numspares%($numinrow);
9029: my $colsleft = $numinrow - $rem;
9030: if ($colsleft > 1 ) {
9031: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9032: ' </td>';
9033: } elsif ($colsleft == 1) {
9034: $targettable .= '<td class="LC_left_item"> </td>';
9035: }
9036: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9037: '<table><tr>'.$targettable.'</tr></table><br />';
9038: }
1.284 raeburn 9039: $hostherechecked{$sparetype} = '';
9040: if (ref($currtargets{$lonhost}) eq 'HASH') {
9041: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9042: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9043: $hostherechecked{$sparetype} = ' checked="checked"';
9044: $hostherechecked{'no'} = '';
9045: }
9046: }
9047: }
9048: }
1.342 raeburn 9049: if ($currcookies{$lonhost}) {
9050: %balcookiechecked = (
9051: yes => ' checked="checked"',
9052: );
9053: }
1.284 raeburn 9054: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9055: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9056: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9057: foreach my $sparetype (@sparestypes) {
9058: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9059: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9060: '</i></label><br />';
1.171 raeburn 9061: }
1.342 raeburn 9062: $datatable .= &mt('Use balancer cookie').'<br />'.
9063: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9064: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9065: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9066: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9067: '</div></td></tr>'.
1.171 raeburn 9068: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9069: $othertitle,$usertypes,$types,\%servers,
9070: \%currbalancer,$lonhost,
9071: $targets_div_style,$homedom_div_style,
9072: $css_class[$cssidx],$balnum,$islast);
9073: $$rowtotal += $rownum;
9074: $balnum ++;
9075: }
9076: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9077: return $datatable;
9078: }
9079:
9080: sub get_loadbalancers_config {
1.342 raeburn 9081: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9082: return unless ((ref($servers) eq 'HASH') &&
9083: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9084: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9085: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9086: if (keys(%{$existing}) > 0) {
9087: my $oldlonhost;
9088: foreach my $key (sort(keys(%{$existing}))) {
9089: if ($key eq 'lonhost') {
9090: $oldlonhost = $existing->{'lonhost'};
9091: $currbalancer->{$oldlonhost} = 1;
9092: } elsif ($key eq 'targets') {
9093: if ($oldlonhost) {
9094: $currtargets->{$oldlonhost} = $existing->{'targets'};
9095: }
9096: } elsif ($key eq 'rules') {
9097: if ($oldlonhost) {
9098: $currrules->{$oldlonhost} = $existing->{'rules'};
9099: }
9100: } elsif (ref($existing->{$key}) eq 'HASH') {
9101: $currbalancer->{$key} = 1;
9102: $currtargets->{$key} = $existing->{$key}{'targets'};
9103: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9104: if ($existing->{$key}{'cookie'}) {
9105: $currcookies->{$key} = 1;
9106: }
1.150 raeburn 9107: }
9108: }
1.171 raeburn 9109: } else {
9110: my ($balancerref,$targetsref) =
9111: &Apache::lonnet::get_lonbalancer_config($servers);
9112: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9113: foreach my $server (sort(keys(%{$balancerref}))) {
9114: $currbalancer->{$server} = 1;
9115: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9116: }
9117: }
9118: }
1.171 raeburn 9119: return;
1.150 raeburn 9120: }
9121:
9122: sub loadbalancing_rules {
9123: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9124: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9125: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9126: my $output;
1.171 raeburn 9127: my $num = 0;
1.210 raeburn 9128: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9129: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9130: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9131: foreach my $type (@{$alltypes}) {
1.171 raeburn 9132: $num ++;
1.150 raeburn 9133: my $current;
9134: if (ref($currrules) eq 'HASH') {
9135: $current = $currrules->{$type};
9136: }
1.253 raeburn 9137: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9138: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9139: $current = '';
9140: }
9141: }
9142: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9143: $servers,$currbalancer,$lonhost,$dom,
9144: $targets_div_style,$homedom_div_style,
9145: $css_class,$balnum,$num,$islast);
1.150 raeburn 9146: }
9147: }
9148: return $output;
9149: }
9150:
9151: sub loadbalancing_titles {
9152: my ($dom,$intdom,$usertypes,$types) = @_;
9153: my %othertypes = (
9154: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9155: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9156: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9157: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9158: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9159: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9160: );
1.209 raeburn 9161: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9162: my @available;
1.150 raeburn 9163: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9164: @available = @{$types};
1.150 raeburn 9165: }
1.302 raeburn 9166: unless (grep(/^default$/,@available)) {
9167: push(@available,'default');
9168: }
9169: unshift(@alltypes,@available);
1.150 raeburn 9170: my %titles;
9171: foreach my $type (@alltypes) {
9172: if ($type =~ /^_LC_/) {
9173: $titles{$type} = $othertypes{$type};
9174: } elsif ($type eq 'default') {
9175: $titles{$type} = &mt('All users from [_1]',$dom);
9176: if (ref($types) eq 'ARRAY') {
9177: if (@{$types} > 0) {
9178: $titles{$type} = &mt('Other users from [_1]',$dom);
9179: }
9180: }
9181: } elsif (ref($usertypes) eq 'HASH') {
9182: $titles{$type} = $usertypes->{$type};
9183: }
9184: }
9185: return (\@alltypes,\%othertypes,\%titles);
9186: }
9187:
9188: sub loadbalance_rule_row {
1.171 raeburn 9189: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9190: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9191: my @rulenames;
1.150 raeburn 9192: my %ruletitles = &offloadtype_text();
1.209 raeburn 9193: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9194: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9195: } else {
1.209 raeburn 9196: @rulenames = ('default','homeserver');
9197: if ($type eq '_LC_external') {
9198: push(@rulenames,'externalbalancer');
9199: } else {
9200: push(@rulenames,'specific');
9201: }
9202: push(@rulenames,'none');
1.150 raeburn 9203: }
9204: my $style = $targets_div_style;
1.253 raeburn 9205: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9206: $style = $homedom_div_style;
9207: }
1.171 raeburn 9208: my $space;
9209: if ($islast && $num == 1) {
1.317 raeburn 9210: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9211: }
1.210 raeburn 9212: my $output =
1.306 raeburn 9213: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9214: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9215: '<td valaign="top">'.$space.
9216: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9217: for (my $i=0; $i<@rulenames; $i++) {
9218: my $rule = $rulenames[$i];
9219: my ($checked,$extra);
9220: if ($rulenames[$i] eq 'default') {
9221: $rule = '';
9222: }
9223: if ($rulenames[$i] eq 'specific') {
9224: if (ref($servers) eq 'HASH') {
9225: my $default;
9226: if (($current ne '') && (exists($servers->{$current}))) {
9227: $checked = ' checked="checked"';
9228: }
9229: unless ($checked) {
9230: $default = ' selected="selected"';
9231: }
1.210 raeburn 9232: $extra =
1.171 raeburn 9233: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9234: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9235: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9236: '<option value=""'.$default.'></option>'."\n";
9237: foreach my $server (sort(keys(%{$servers}))) {
9238: if (ref($currbalancer) eq 'HASH') {
9239: next if (exists($currbalancer->{$server}));
9240: }
1.150 raeburn 9241: my $selected;
1.171 raeburn 9242: if ($server eq $current) {
1.150 raeburn 9243: $selected = ' selected="selected"';
9244: }
1.171 raeburn 9245: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9246: }
9247: $extra .= '</select>';
9248: }
9249: } elsif ($rule eq $current) {
9250: $checked = ' checked="checked"';
9251: }
9252: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9253: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9254: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9255: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9256: ')"'.$checked.' /> ';
9257: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9258: $output .= $ruletitles{'particular'};
9259: } else {
9260: $output .= $ruletitles{$rulenames[$i]};
9261: }
9262: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9263: }
9264: $output .= '</div></td></tr>'."\n";
9265: return $output;
9266: }
9267:
9268: sub offloadtype_text {
9269: my %ruletitles = &Apache::lonlocal::texthash (
9270: 'default' => 'Offloads to default destinations',
9271: 'homeserver' => "Offloads to user's home server",
9272: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9273: 'specific' => 'Offloads to specific server',
1.161 raeburn 9274: 'none' => 'No offload',
1.209 raeburn 9275: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9276: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9277: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9278: );
9279: return %ruletitles;
9280: }
9281:
9282: sub sparestype_titles {
9283: my %typestitles = &Apache::lonlocal::texthash (
9284: 'primary' => 'primary',
9285: 'default' => 'default',
9286: );
9287: return %typestitles;
9288: }
9289:
1.28 raeburn 9290: sub contact_titles {
9291: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9292: 'supportemail' => 'Support E-mail address',
9293: 'adminemail' => 'Default Server Admin E-mail address',
9294: 'errormail' => 'Error reports to be e-mailed to',
9295: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9296: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9297: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9298: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9299: 'requestsmail' => 'E-mail from course requests requiring approval',
9300: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9301: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9302: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9303: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9304: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9305: 'errorweights' => 'Weights used to compute error count',
9306: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9307: );
9308: my %short_titles = &Apache::lonlocal::texthash (
9309: adminemail => 'Admin E-mail address',
9310: supportemail => 'Support E-mail',
9311: );
9312: return (\%titles,\%short_titles);
9313: }
9314:
1.286 raeburn 9315: sub helpform_fields {
9316: my %titles = &Apache::lonlocal::texthash (
9317: 'username' => 'Name',
9318: 'user' => 'Username/domain',
9319: 'phone' => 'Phone',
9320: 'cc' => 'Cc e-mail',
9321: 'course' => 'Course Details',
9322: 'section' => 'Sections',
1.289 raeburn 9323: 'screenshot' => 'File upload',
1.286 raeburn 9324: );
9325: my @fields = ('username','phone','user','course','section','cc','screenshot');
9326: my %possoptions = (
9327: username => ['yes','no','req'],
1.289 raeburn 9328: phone => ['yes','no','req'],
1.286 raeburn 9329: user => ['yes','no'],
1.289 raeburn 9330: cc => ['yes','no'],
1.286 raeburn 9331: course => ['yes','no'],
9332: section => ['yes','no'],
9333: screenshot => ['yes','no'],
9334: );
9335: my %fieldoptions = &Apache::lonlocal::texthash (
9336: 'yes' => 'Optional',
9337: 'req' => 'Required',
9338: 'no' => "Not shown",
9339: );
9340: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9341: }
9342:
1.72 raeburn 9343: sub tool_titles {
9344: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9345: aboutme => 'Personal web page',
1.86 raeburn 9346: blog => 'Blog',
1.162 raeburn 9347: webdav => 'WebDAV',
1.86 raeburn 9348: portfolio => 'Portfolio',
1.413 raeburn 9349: timezone => 'Can set time zone',
1.88 bisitz 9350: official => 'Official courses (with institutional codes)',
9351: unofficial => 'Unofficial courses',
1.98 raeburn 9352: community => 'Communities',
1.216 raeburn 9353: textbook => 'Textbook courses',
1.271 raeburn 9354: placement => 'Placement tests',
1.86 raeburn 9355: );
1.72 raeburn 9356: return %titles;
9357: }
9358:
1.101 raeburn 9359: sub courserequest_titles {
9360: my %titles = &Apache::lonlocal::texthash (
9361: official => 'Official',
9362: unofficial => 'Unofficial',
9363: community => 'Communities',
1.216 raeburn 9364: textbook => 'Textbook',
1.271 raeburn 9365: placement => 'Placement tests',
1.325 raeburn 9366: lti => 'LTI Provider',
1.101 raeburn 9367: norequest => 'Not allowed',
1.325 raeburn 9368: approval => 'Approval by DC',
1.101 raeburn 9369: validate => 'With validation',
9370: autolimit => 'Numerical limit',
1.103 raeburn 9371: unlimited => '(blank for unlimited)',
1.101 raeburn 9372: );
9373: return %titles;
9374: }
9375:
1.163 raeburn 9376: sub authorrequest_titles {
9377: my %titles = &Apache::lonlocal::texthash (
9378: norequest => 'Not allowed',
9379: approval => 'Approval by Dom. Coord.',
9380: automatic => 'Automatic approval',
9381: );
9382: return %titles;
1.210 raeburn 9383: }
1.163 raeburn 9384:
1.101 raeburn 9385: sub courserequest_conditions {
9386: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9387: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9388: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9389: );
9390: return %conditions;
9391: }
9392:
9393:
1.27 raeburn 9394: sub print_usercreation {
1.30 raeburn 9395: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9396: my $numinrow = 4;
1.28 raeburn 9397: my $datatable;
9398: if ($position eq 'top') {
1.30 raeburn 9399: $$rowtotal ++;
1.34 raeburn 9400: my $rowcount = 0;
1.32 raeburn 9401: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9402: if (ref($rules) eq 'HASH') {
9403: if (keys(%{$rules}) > 0) {
1.32 raeburn 9404: $datatable .= &user_formats_row('username',$settings,$rules,
9405: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9406: $$rowtotal ++;
1.32 raeburn 9407: $rowcount ++;
9408: }
9409: }
9410: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9411: if (ref($idrules) eq 'HASH') {
9412: if (keys(%{$idrules}) > 0) {
9413: $datatable .= &user_formats_row('id',$settings,$idrules,
9414: $idruleorder,$numinrow,$rowcount);
9415: $$rowtotal ++;
9416: $rowcount ++;
1.28 raeburn 9417: }
9418: }
1.39 raeburn 9419: if ($rowcount == 0) {
9420: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9421: $$rowtotal ++;
9422: $rowcount ++;
9423: }
1.34 raeburn 9424: } elsif ($position eq 'middle') {
1.224 raeburn 9425: my @creators = ('author','course','requestcrs');
1.37 raeburn 9426: my ($rules,$ruleorder) =
9427: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9428: my %lt = &usercreation_types();
9429: my %checked;
9430: if (ref($settings) eq 'HASH') {
9431: if (ref($settings->{'cancreate'}) eq 'HASH') {
9432: foreach my $item (@creators) {
9433: $checked{$item} = $settings->{'cancreate'}{$item};
9434: }
9435: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9436: foreach my $item (@creators) {
9437: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9438: $checked{$item} = 'none';
9439: }
9440: }
9441: }
9442: }
9443: my $rownum = 0;
9444: foreach my $item (@creators) {
9445: $rownum ++;
1.224 raeburn 9446: if ($checked{$item} eq '') {
9447: $checked{$item} = 'any';
1.34 raeburn 9448: }
9449: my $css_class;
9450: if ($rownum%2) {
9451: $css_class = '';
9452: } else {
9453: $css_class = ' class="LC_odd_row" ';
9454: }
9455: $datatable .= '<tr'.$css_class.'>'.
9456: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9457: '</span></td><td style="text-align: right">';
1.224 raeburn 9458: my @options = ('any');
9459: if (ref($rules) eq 'HASH') {
9460: if (keys(%{$rules}) > 0) {
9461: push(@options,('official','unofficial'));
1.37 raeburn 9462: }
9463: }
1.224 raeburn 9464: push(@options,'none');
1.37 raeburn 9465: foreach my $option (@options) {
1.50 raeburn 9466: my $type = 'radio';
1.34 raeburn 9467: my $check = ' ';
1.224 raeburn 9468: if ($checked{$item} eq $option) {
9469: $check = ' checked="checked" ';
1.34 raeburn 9470: }
9471: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9472: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9473: $item.'" value="'.$option.'"'.$check.'/> '.
9474: $lt{$option}.'</label> </span>';
9475: }
9476: $datatable .= '</td></tr>';
9477: }
1.28 raeburn 9478: } else {
9479: my @contexts = ('author','course','domain');
1.325 raeburn 9480: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9481: my %checked;
9482: if (ref($settings) eq 'HASH') {
9483: if (ref($settings->{'authtypes'}) eq 'HASH') {
9484: foreach my $item (@contexts) {
9485: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9486: foreach my $auth (@authtypes) {
9487: if ($settings->{'authtypes'}{$item}{$auth}) {
9488: $checked{$item}{$auth} = ' checked="checked" ';
9489: }
9490: }
9491: }
9492: }
1.27 raeburn 9493: }
1.35 raeburn 9494: } else {
9495: foreach my $item (@contexts) {
1.36 raeburn 9496: foreach my $auth (@authtypes) {
1.35 raeburn 9497: $checked{$item}{$auth} = ' checked="checked" ';
9498: }
9499: }
1.27 raeburn 9500: }
1.28 raeburn 9501: my %title = &context_names();
9502: my %authname = &authtype_names();
9503: my $rownum = 0;
9504: my $css_class;
9505: foreach my $item (@contexts) {
9506: if ($rownum%2) {
9507: $css_class = '';
9508: } else {
9509: $css_class = ' class="LC_odd_row" ';
9510: }
1.30 raeburn 9511: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9512: '<td>'.$title{$item}.
9513: '</td><td class="LC_left_item">'.
9514: '<span class="LC_nobreak">';
9515: foreach my $auth (@authtypes) {
9516: $datatable .= '<label>'.
9517: '<input type="checkbox" name="'.$item.'_auth" '.
9518: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9519: $authname{$auth}.'</label> ';
9520: }
9521: $datatable .= '</span></td></tr>';
9522: $rownum ++;
1.27 raeburn 9523: }
1.30 raeburn 9524: $$rowtotal += $rownum;
1.27 raeburn 9525: }
9526: return $datatable;
9527: }
9528:
1.224 raeburn 9529: sub print_selfcreation {
9530: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9531: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9532: $emaildomain,$datatable);
1.224 raeburn 9533: if (ref($settings) eq 'HASH') {
9534: if (ref($settings->{'cancreate'}) eq 'HASH') {
9535: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9536: if (ref($createsettings) eq 'HASH') {
9537: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9538: @selfcreate = @{$createsettings->{'selfcreate'}};
9539: } elsif ($createsettings->{'selfcreate'} ne '') {
9540: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9541: @selfcreate = ('email','login','sso');
9542: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9543: @selfcreate = ($createsettings->{'selfcreate'});
9544: }
9545: }
9546: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9547: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9548: }
1.305 raeburn 9549: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9550: $emailoptions = $createsettings->{'emailoptions'};
9551: }
1.303 raeburn 9552: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9553: $emailverified = $createsettings->{'emailverified'};
9554: }
9555: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9556: $emaildomain = $createsettings->{'emaildomain'};
9557: }
1.224 raeburn 9558: }
9559: }
9560: }
9561: my %radiohash;
9562: my $numinrow = 4;
9563: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9564: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9565: if ($position eq 'top') {
9566: my %choices = &Apache::lonlocal::texthash (
9567: cancreate_login => 'Institutional Login',
9568: cancreate_sso => 'Institutional Single Sign On',
9569: );
9570: my @toggles = sort(keys(%choices));
9571: my %defaultchecked = (
9572: 'cancreate_login' => 'off',
9573: 'cancreate_sso' => 'off',
9574: );
1.228 raeburn 9575: my ($onclick,$itemcount);
1.224 raeburn 9576: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9577: \%choices,$itemcount,$onclick);
1.228 raeburn 9578: $$rowtotal += $itemcount;
9579:
1.224 raeburn 9580: if (ref($usertypes) eq 'HASH') {
9581: if (keys(%{$usertypes}) > 0) {
9582: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9583: $dom,$numinrow,$othertitle,
1.305 raeburn 9584: 'statustocreate',$rowtotal);
1.224 raeburn 9585: $$rowtotal ++;
9586: }
9587: }
1.240 raeburn 9588: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9589: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9590: $fieldtitles{'inststatus'} = &mt('Institutional status');
9591: my $rem;
9592: my $numperrow = 2;
9593: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9594: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9595: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9596: '<td class="LC_left_item">'."\n".
1.334 raeburn 9597: '<table>'."\n";
1.240 raeburn 9598: for (my $i=0; $i<@fields; $i++) {
9599: $rem = $i%($numperrow);
9600: if ($rem == 0) {
9601: if ($i > 0) {
9602: $datatable .= '</tr>';
9603: }
9604: $datatable .= '<tr>';
9605: }
9606: my $currval;
1.248 raeburn 9607: if (ref($createsettings) eq 'HASH') {
9608: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9609: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9610: }
1.240 raeburn 9611: }
9612: $datatable .= '<td class="LC_left_item">'.
9613: '<span class="LC_nobreak">'.
9614: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9615: 'value="'.$currval.'" size="10" /> '.
9616: $fieldtitles{$fields[$i]}.'</span></td>';
9617: }
9618: my $colsleft = $numperrow - $rem;
9619: if ($colsleft > 1 ) {
9620: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9621: ' </td>';
9622: } elsif ($colsleft == 1) {
9623: $datatable .= '<td class="LC_left_item"> </td>';
9624: }
9625: $datatable .= '</tr></table></td></tr>';
9626: $$rowtotal ++;
1.224 raeburn 9627: } elsif ($position eq 'middle') {
9628: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9629: my @posstypes;
1.224 raeburn 9630: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9631: @posstypes = @{$types};
9632: }
9633: unless (grep(/^default$/,@posstypes)) {
9634: push(@posstypes,'default');
9635: }
9636: my %usertypeshash;
9637: if (ref($usertypes) eq 'HASH') {
9638: %usertypeshash = %{$usertypes};
9639: }
9640: $usertypeshash{'default'} = $othertitle;
9641: foreach my $status (@posstypes) {
9642: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9643: $numinrow,$$rowtotal,\%usertypeshash);
9644: $$rowtotal ++;
1.224 raeburn 9645: }
9646: } else {
1.236 raeburn 9647: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9648: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9649: );
9650: my @toggles = sort(keys(%choices));
9651: my %defaultchecked = (
9652: 'cancreate_email' => 'off',
9653: );
1.305 raeburn 9654: my $customclass = 'LC_selfcreate_email';
9655: my $classprefix = 'LC_canmodify_emailusername_';
9656: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9657: my $display = 'none';
1.305 raeburn 9658: my $rowstyle = 'display:none';
1.236 raeburn 9659: if (grep(/^\Qemail\E$/,@selfcreate)) {
9660: $display = 'block';
1.305 raeburn 9661: $rowstyle = 'display:table-row';
1.236 raeburn 9662: }
1.305 raeburn 9663: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9664: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9665: \%choices,$$rowtotal,$onclick);
9666: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9667: $rowstyle);
9668: $$rowtotal ++;
9669: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9670: $rowstyle);
9671: $$rowtotal ++;
9672: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9673: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9674: my ($emailrules,$emailruleorder) =
9675: &Apache::lonnet::inst_userrules($dom,'email');
9676: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9677: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9678: if (ref($types) eq 'ARRAY') {
9679: @posstypes = @{$types};
9680: }
9681: if (@posstypes) {
9682: unless (grep(/^default$/,@posstypes)) {
9683: push(@posstypes,'default');
1.302 raeburn 9684: }
9685: if (ref($usertypes) eq 'HASH') {
9686: %usertypeshash = %{$usertypes};
9687: }
1.305 raeburn 9688: my $currassign;
9689: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9690: $currassign = {
9691: selfassign => $domdefaults{'inststatusguest'},
9692: };
9693: @ordered = @{$domdefaults{'inststatusguest'}};
9694: } else {
9695: $currassign = { selfassign => [] };
9696: }
9697: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9698: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9699: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9700: $numinrow,$othertitle,'selfassign',
9701: $rowtotal,$onclicktypes,$customclass,
9702: $rowstyle);
9703: $$rowtotal ++;
1.302 raeburn 9704: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9705: foreach my $status (@posstypes) {
9706: my $css_class;
9707: if ($$rowtotal%2) {
9708: $css_class = 'LC_odd_row ';
9709: }
9710: $css_class .= $customclass;
9711: my $rowid = $optionsprefix.$status;
9712: my $hidden = 1;
9713: my $currstyle = 'display:none';
9714: if (grep(/^\Q$status\E$/,@ordered)) {
9715: $currstyle = $rowstyle;
9716: $hidden = 0;
9717: }
9718: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9719: $emailrules,$emailruleorder,$settings,$status,$rowid,
9720: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9721: unless ($hidden) {
9722: $$rowtotal ++;
9723: }
1.224 raeburn 9724: }
1.302 raeburn 9725: } else {
1.305 raeburn 9726: my $css_class;
9727: if ($$rowtotal%2) {
9728: $css_class = 'LC_odd_row ';
9729: }
9730: $css_class .= $customclass;
1.302 raeburn 9731: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9732: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9733: $emailrules,$emailruleorder,$settings,'default','',
9734: $othertitle,$css_class,$rowstyle,$intdom);
9735: $$rowtotal ++;
1.224 raeburn 9736: }
9737: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9738: $numinrow = 1;
1.305 raeburn 9739: if (@posstypes) {
9740: foreach my $status (@posstypes) {
9741: my $rowid = $classprefix.$status;
9742: my $datarowstyle = 'display:none';
9743: if (grep(/^\Q$status\E$/,@ordered)) {
9744: $datarowstyle = $rowstyle;
9745: }
9746: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9747: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9748: $infotitles,$rowid,$customclass,$datarowstyle);
9749: unless ($datarowstyle eq 'display:none') {
9750: $$rowtotal ++;
9751: }
1.224 raeburn 9752: }
1.305 raeburn 9753: } else {
9754: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9755: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9756: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9757: }
9758: }
9759: return $datatable;
9760: }
9761:
1.305 raeburn 9762: sub selfcreate_javascript {
9763: return <<"ENDSCRIPT";
9764:
9765: <script type="text/javascript">
9766: // <![CDATA[
9767:
9768: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9769: var x = document.getElementsByClassName(target);
9770: var insttypes = 0;
9771: var insttypeRegExp = new RegExp(prefix);
9772: if ((x.length != undefined) && (x.length > 0)) {
9773: if (form.elements[radio].length != undefined) {
9774: for (var i=0; i<form.elements[radio].length; i++) {
9775: if (form.elements[radio][i].checked) {
9776: if (form.elements[radio][i].value == 1) {
9777: for (var j=0; j<x.length; j++) {
9778: if (x[j].id == 'undefined') {
9779: x[j].style.display = 'table-row';
9780: } else if (insttypeRegExp.test(x[j].id)) {
9781: insttypes ++;
9782: } else {
9783: x[j].style.display = 'table-row';
9784: }
9785: }
9786: } else {
9787: for (var j=0; j<x.length; j++) {
9788: x[j].style.display = 'none';
9789: }
1.236 raeburn 9790: }
1.305 raeburn 9791: break;
9792: }
9793: }
9794: if (insttypes > 0) {
9795: toggleDataRow(form,checkbox,target,altprefix);
9796: toggleDataRow(form,checkbox,target,prefix,1);
9797: }
9798: }
9799: }
9800: return;
9801: }
9802:
9803: function toggleDataRow(form,checkbox,target,prefix,docount) {
9804: if (form.elements[checkbox].length != undefined) {
9805: var count = 0;
9806: if (docount) {
9807: for (var i=0; i<form.elements[checkbox].length; i++) {
9808: if (form.elements[checkbox][i].checked) {
9809: count ++;
1.236 raeburn 9810: }
1.305 raeburn 9811: }
9812: }
9813: for (var i=0; i<form.elements[checkbox].length; i++) {
9814: var type = form.elements[checkbox][i].value;
9815: if (document.getElementById(prefix+type)) {
9816: if (form.elements[checkbox][i].checked) {
9817: document.getElementById(prefix+type).style.display = 'table-row';
9818: if (count % 2 == 1) {
9819: document.getElementById(prefix+type).className = target+' LC_odd_row';
9820: } else {
9821: document.getElementById(prefix+type).className = target;
1.236 raeburn 9822: }
1.305 raeburn 9823: count ++;
1.236 raeburn 9824: } else {
1.305 raeburn 9825: document.getElementById(prefix+type).style.display = 'none';
9826: }
9827: }
9828: }
9829: }
9830: return;
9831: }
9832:
9833: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9834: var caller = radio+'_'+status;
9835: if (form.elements[caller].length != undefined) {
9836: for (var i=0; i<form.elements[caller].length; i++) {
9837: if (form.elements[caller][i].checked) {
9838: if (document.getElementById(altprefix+'_inst_'+status)) {
9839: var curr = form.elements[caller][i].value;
9840: if (prefix) {
9841: document.getElementById(prefix+'_'+status).style.display = 'none';
9842: }
9843: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9844: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9845: if (curr == 'custom') {
9846: if (prefix) {
9847: document.getElementById(prefix+'_'+status).style.display = 'inline';
9848: }
9849: } else if (curr == 'inst') {
9850: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9851: } else if (curr == 'noninst') {
9852: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9853: }
1.305 raeburn 9854: break;
1.236 raeburn 9855: }
9856: }
9857: }
9858: }
9859: }
9860:
1.305 raeburn 9861: // ]]>
9862: </script>
9863:
9864: ENDSCRIPT
9865: }
9866:
9867: sub noninst_users {
9868: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9869: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9870: my $class = 'LC_left_item';
9871: if ($css_class) {
9872: $css_class = ' class="'.$css_class.'"';
9873: }
9874: if ($rowid) {
9875: $rowid = ' id="'.$rowid.'"';
9876: }
9877: if ($rowstyle) {
9878: $rowstyle = ' style="'.$rowstyle.'"';
9879: }
9880: my ($output,$description);
9881: if ($type eq 'default') {
9882: $description = &mt('Requests for: [_1]',$typetitle);
9883: } else {
9884: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9885: }
9886: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9887: "<td>$description</td>\n".
9888: '<td class="'.$class.'" colspan="2">'.
9889: '<table><tr>';
9890: my %headers = &Apache::lonlocal::texthash(
9891: approve => 'Processing',
9892: email => 'E-mail',
9893: username => 'Username',
9894: );
9895: foreach my $item ('approve','email','username') {
9896: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9897: }
1.305 raeburn 9898: $output .= '</tr><tr>';
9899: foreach my $item ('approve','email','username') {
1.306 raeburn 9900: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9901: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9902: if ($item eq 'approve') {
9903: %choices = &Apache::lonlocal::texthash (
9904: automatic => 'Automatically approved',
9905: approval => 'Queued for approval',
9906: );
9907: @options = ('automatic','approval');
9908: $hashref = $processing;
9909: $defoption = 'automatic';
9910: $name = 'cancreate_emailprocess_'.$type;
9911: } elsif ($item eq 'email') {
9912: %choices = &Apache::lonlocal::texthash (
9913: any => 'Any e-mail',
9914: inst => 'Institutional only',
9915: noninst => 'Non-institutional only',
9916: custom => 'Custom restrictions',
9917: );
9918: @options = ('any','inst','noninst');
9919: my $showcustom;
9920: if (ref($emailrules) eq 'HASH') {
9921: if (keys(%{$emailrules}) > 0) {
9922: push(@options,'custom');
9923: $showcustom = 'cancreate_emailrule';
9924: if (ref($settings) eq 'HASH') {
9925: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9926: foreach my $rule (@{$settings->{'email_rule'}}) {
9927: if (exists($emailrules->{$rule})) {
9928: $hascustom ++;
9929: }
9930: }
9931: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9932: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9933: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9934: if (exists($emailrules->{$rule})) {
9935: $hascustom ++;
9936: }
9937: }
9938: }
9939: }
9940: }
9941: }
9942: }
9943: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9944: "'cancreate_emaildomain','$type'".');"';
9945: $hashref = $emailoptions;
9946: $defoption = 'any';
9947: $name = 'cancreate_emailoptions_'.$type;
9948: } elsif ($item eq 'username') {
9949: %choices = &Apache::lonlocal::texthash (
9950: all => 'Same as e-mail',
9951: first => 'Omit @domain',
9952: free => 'Free to choose',
9953: );
9954: @options = ('all','first','free');
9955: $hashref = $emailverified;
9956: $defoption = 'all';
9957: $name = 'cancreate_usernameoptions_'.$type;
9958: }
9959: foreach my $option (@options) {
9960: my $checked;
9961: if (ref($hashref) eq 'HASH') {
9962: if ($type eq '') {
9963: if (!exists($hashref->{'default'})) {
9964: if ($option eq $defoption) {
9965: $checked = ' checked="checked"';
9966: }
9967: } else {
9968: if ($hashref->{'default'} eq $option) {
9969: $checked = ' checked="checked"';
9970: }
1.303 raeburn 9971: }
9972: } else {
1.305 raeburn 9973: if (!exists($hashref->{$type})) {
9974: if ($option eq $defoption) {
9975: $checked = ' checked="checked"';
9976: }
9977: } else {
9978: if ($hashref->{$type} eq $option) {
9979: $checked = ' checked="checked"';
9980: }
1.303 raeburn 9981: }
9982: }
1.305 raeburn 9983: } elsif (($item eq 'email') && ($hascustom)) {
9984: if ($option eq 'custom') {
9985: $checked = ' checked="checked"';
9986: }
9987: } elsif ($option eq $defoption) {
9988: $checked = ' checked="checked"';
9989: }
9990: $output .= '<span class="LC_nobreak"><label>'.
9991: '<input type="radio" name="'.$name.'"'.
9992: $checked.' value="'.$option.'"'.$onclick.' />'.
9993: $choices{$option}.'</label></span><br />';
9994: if ($item eq 'email') {
9995: if ($option eq 'custom') {
9996: my $id = 'cancreate_emailrule_'.$type;
9997: my $display = 'none';
9998: if ($checked) {
9999: $display = 'inline';
1.303 raeburn 10000: }
1.305 raeburn 10001: my $numinrow = 2;
10002: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10003: '<legend>'.&mt('Disallow').'</legend><table>'.
10004: &user_formats_row('email',$settings,$emailrules,
10005: $emailruleorder,$numinrow,'',$type);
10006: '</table></fieldset>';
10007: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10008: my %text = &Apache::lonlocal::texthash (
10009: inst => 'must end:',
10010: noninst => 'cannot end:',
10011: );
10012: my $value;
10013: if (ref($emaildomain) eq 'HASH') {
10014: if (ref($emaildomain->{$type}) eq 'HASH') {
10015: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10016: }
10017: }
1.305 raeburn 10018: if ($value eq '') {
10019: $value = '@'.$intdom;
10020: }
10021: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10022: my $display = 'none';
10023: if ($checked) {
10024: $display = 'inline';
10025: }
10026: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10027: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10028: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10029: '</div>';
1.303 raeburn 10030: }
10031: }
10032: }
1.305 raeburn 10033: $output .= '</td>'."\n";
1.303 raeburn 10034: }
1.305 raeburn 10035: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10036: return $output;
10037: }
10038:
1.165 raeburn 10039: sub captcha_choice {
1.305 raeburn 10040: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10041: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10042: $vertext,$currver);
1.165 raeburn 10043: my %lt = &captcha_phrases();
10044: $keyentry = 'hidden';
1.354 raeburn 10045: my $colspan=2;
1.165 raeburn 10046: if ($context eq 'cancreate') {
1.224 raeburn 10047: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10048: } elsif ($context eq 'login') {
10049: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10050: } elsif ($context eq 'passwords') {
10051: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10052: $colspan=1;
1.165 raeburn 10053: }
10054: if (ref($settings) eq 'HASH') {
10055: if ($settings->{'captcha'}) {
10056: $checked{$settings->{'captcha'}} = ' checked="checked"';
10057: } else {
10058: $checked{'original'} = ' checked="checked"';
10059: }
10060: if ($settings->{'captcha'} eq 'recaptcha') {
10061: $pubtext = $lt{'pub'};
10062: $privtext = $lt{'priv'};
10063: $keyentry = 'text';
1.269 raeburn 10064: $vertext = $lt{'ver'};
10065: $currver = $settings->{'recaptchaversion'};
10066: if ($currver ne '2') {
10067: $currver = 1;
10068: }
1.165 raeburn 10069: }
10070: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10071: $currpub = $settings->{'recaptchakeys'}{'public'};
10072: $currpriv = $settings->{'recaptchakeys'}{'private'};
10073: }
10074: } else {
10075: $checked{'original'} = ' checked="checked"';
10076: }
1.305 raeburn 10077: my $css_class;
10078: if ($itemcount%2) {
10079: $css_class = 'LC_odd_row';
10080: }
10081: if ($customcss) {
10082: $css_class .= " $customcss";
10083: }
10084: $css_class =~ s/^\s+//;
10085: if ($css_class) {
10086: $css_class = ' class="'.$css_class.'"';
10087: }
10088: if ($rowstyle) {
10089: $css_class .= ' style="'.$rowstyle.'"';
10090: }
1.169 raeburn 10091: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10092: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10093: '<table><tr><td>'."\n";
10094: foreach my $option ('original','recaptcha','notused') {
10095: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10096: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10097: $lt{$option}.'</label></span>';
10098: unless ($option eq 'notused') {
10099: $output .= (' 'x2)."\n";
10100: }
10101: }
10102: #
10103: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10104: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10105: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10106: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10107: #
1.165 raeburn 10108: $output .= '</td></tr>'."\n".
1.305 raeburn 10109: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10110: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10111: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10112: $currpub.'" size="40" /></span><br />'."\n".
10113: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10114: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10115: $currpriv.'" size="40" /></span><br />'.
10116: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10117: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10118: $currver.'" size="3" /></span><br />'.
10119: '</td></tr></table>'."\n".
1.165 raeburn 10120: '</td></tr>';
10121: return $output;
10122: }
10123:
1.32 raeburn 10124: sub user_formats_row {
1.305 raeburn 10125: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10126: my $output;
10127: my %text = (
10128: 'username' => 'new usernames',
10129: 'id' => 'IDs',
10130: );
1.409 raeburn 10131: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10132: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10133: $output = '<tr '.$css_class.'>'.
10134: '<td><span class="LC_nobreak">'.
10135: &mt("Format rules to check for $text{$type}: ").
10136: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10137: }
1.27 raeburn 10138: my $rem;
10139: if (ref($ruleorder) eq 'ARRAY') {
10140: for (my $i=0; $i<@{$ruleorder}; $i++) {
10141: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10142: my $rem = $i%($numinrow);
10143: if ($rem == 0) {
10144: if ($i > 0) {
10145: $output .= '</tr>';
10146: }
10147: $output .= '<tr>';
10148: }
10149: my $check = ' ';
1.39 raeburn 10150: if (ref($settings) eq 'HASH') {
10151: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10152: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10153: $check = ' checked="checked" ';
10154: }
1.305 raeburn 10155: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10156: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10157: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10158: $check = ' checked="checked" ';
10159: }
10160: }
1.27 raeburn 10161: }
10162: }
1.305 raeburn 10163: my $name = $type.'_rule';
10164: if ($type eq 'email') {
10165: $name .= '_'.$status;
10166: }
1.27 raeburn 10167: $output .= '<td class="LC_left_item">'.
10168: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10169: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10170: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10171: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10172: }
10173: }
10174: $rem = @{$ruleorder}%($numinrow);
10175: }
1.305 raeburn 10176: my $colsleft;
10177: if ($rem) {
10178: $colsleft = $numinrow - $rem;
10179: }
1.27 raeburn 10180: if ($colsleft > 1 ) {
10181: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10182: ' </td>';
10183: } elsif ($colsleft == 1) {
10184: $output .= '<td class="LC_left_item"> </td>';
10185: }
1.409 raeburn 10186: $output .= '</tr>';
10187: unless (($type eq 'email') || ($type eq 'unamemap')) {
10188: $output .= '</table></td></tr>';
1.305 raeburn 10189: }
1.27 raeburn 10190: return $output;
10191: }
10192:
1.34 raeburn 10193: sub usercreation_types {
10194: my %lt = &Apache::lonlocal::texthash (
10195: author => 'When adding a co-author',
10196: course => 'When adding a user to a course',
1.100 raeburn 10197: requestcrs => 'When requesting a course',
1.34 raeburn 10198: any => 'Any',
10199: official => 'Institutional only ',
10200: unofficial => 'Non-institutional only',
10201: none => 'None',
10202: );
10203: return %lt;
1.48 raeburn 10204: }
1.34 raeburn 10205:
1.224 raeburn 10206: sub selfcreation_types {
10207: my %lt = &Apache::lonlocal::texthash (
10208: selfcreate => 'User creates own account',
10209: any => 'Any',
10210: official => 'Institutional only ',
10211: unofficial => 'Non-institutional only',
10212: email => 'E-mail address',
10213: login => 'Institutional Login',
10214: sso => 'SSO',
10215: );
10216: }
10217:
1.28 raeburn 10218: sub authtype_names {
10219: my %lt = &Apache::lonlocal::texthash(
10220: int => 'Internal',
10221: krb4 => 'Kerberos 4',
10222: krb5 => 'Kerberos 5',
10223: loc => 'Local',
1.325 raeburn 10224: lti => 'LTI',
1.28 raeburn 10225: );
10226: return %lt;
10227: }
10228:
10229: sub context_names {
10230: my %context_title = &Apache::lonlocal::texthash(
10231: author => 'Creating users when an Author',
10232: course => 'Creating users when in a course',
10233: domain => 'Creating users when a Domain Coordinator',
10234: );
10235: return %context_title;
10236: }
10237:
1.33 raeburn 10238: sub print_usermodification {
10239: my ($position,$dom,$settings,$rowtotal) = @_;
10240: my $numinrow = 4;
10241: my ($context,$datatable,$rowcount);
10242: if ($position eq 'top') {
10243: $rowcount = 0;
10244: $context = 'author';
10245: foreach my $role ('ca','aa') {
10246: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10247: $numinrow,$rowcount);
10248: $$rowtotal ++;
10249: $rowcount ++;
10250: }
1.230 raeburn 10251: } elsif ($position eq 'bottom') {
1.33 raeburn 10252: $context = 'course';
10253: $rowcount = 0;
10254: foreach my $role ('st','ep','ta','in','cr') {
10255: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10256: $numinrow,$rowcount);
10257: $$rowtotal ++;
10258: $rowcount ++;
10259: }
10260: }
10261: return $datatable;
10262: }
10263:
1.43 raeburn 10264: sub print_defaults {
1.236 raeburn 10265: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10266: my $rownum = 0;
1.294 raeburn 10267: my ($datatable,$css_class,$titles);
10268: unless ($position eq 'bottom') {
10269: $titles = &defaults_titles($dom);
10270: }
1.236 raeburn 10271: if ($position eq 'top') {
10272: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10273: 'datelocale_def','portal_def');
10274: my %defaults;
10275: if (ref($settings) eq 'HASH') {
10276: %defaults = %{$settings};
1.43 raeburn 10277: } else {
1.236 raeburn 10278: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10279: foreach my $item (@items) {
10280: $defaults{$item} = $domdefaults{$item};
10281: }
1.43 raeburn 10282: }
1.236 raeburn 10283: foreach my $item (@items) {
10284: if ($rownum%2) {
10285: $css_class = '';
10286: } else {
10287: $css_class = ' class="LC_odd_row" ';
10288: }
10289: $datatable .= '<tr'.$css_class.'>'.
10290: '<td><span class="LC_nobreak">'.$titles->{$item}.
10291: '</span></td><td class="LC_right_item" colspan="3">';
10292: if ($item eq 'auth_def') {
1.325 raeburn 10293: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10294: my %shortauth = (
10295: internal => 'int',
10296: krb4 => 'krb4',
10297: krb5 => 'krb5',
1.325 raeburn 10298: localauth => 'loc',
10299: lti => 'lti',
1.236 raeburn 10300: );
10301: my %authnames = &authtype_names();
10302: foreach my $auth (@authtypes) {
10303: my $checked = ' ';
10304: if ($defaults{$item} eq $auth) {
10305: $checked = ' checked="checked" ';
10306: }
10307: $datatable .= '<label><input type="radio" name="'.$item.
10308: '" value="'.$auth.'"'.$checked.'/>'.
10309: $authnames{$shortauth{$auth}}.'</label> ';
10310: }
10311: } elsif ($item eq 'timezone_def') {
10312: my $includeempty = 1;
10313: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10314: } elsif ($item eq 'datelocale_def') {
10315: my $includeempty = 1;
10316: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10317: } elsif ($item eq 'lang_def') {
1.263 raeburn 10318: my $includeempty = 1;
10319: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10320: } elsif ($item eq 'portal_def') {
10321: $datatable .= '<input type="text" name="'.$item.'" value="'.
10322: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10323: my $portalsty = 'none';
10324: if ($defaults{$item}) {
10325: $portalsty = 'block';
10326: }
10327: foreach my $field ('email','web') {
10328: my $checkedoff = ' checked="checked"';
10329: my $checkedon;
10330: if ($defaults{$item.'_'.$field}) {
10331: $checkedon = $checkedoff;
10332: $checkedoff = '';
10333: }
10334: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10335: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10336: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10337: (' 'x2).
10338: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10339: '</div>';
10340: }
1.236 raeburn 10341: } else {
1.414 raeburn 10342: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10343: }
1.236 raeburn 10344: $datatable .= '</td></tr>';
10345: $rownum ++;
10346: }
1.409 raeburn 10347: } elsif ($position eq 'middle') {
1.294 raeburn 10348: my %defaults;
10349: if (ref($settings) eq 'HASH') {
1.354 raeburn 10350: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10351: my $maxnum = @{$settings->{'inststatusorder'}};
10352: for (my $i=0; $i<$maxnum; $i++) {
10353: $css_class = $rownum%2?' class="LC_odd_row"':'';
10354: my $item = $settings->{'inststatusorder'}->[$i];
10355: my $title = $settings->{'inststatustypes'}->{$item};
10356: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10357: $datatable .= '<tr'.$css_class.'>'.
10358: '<td><span class="LC_nobreak">'.
10359: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10360: for (my $k=0; $k<=$maxnum; $k++) {
10361: my $vpos = $k+1;
10362: my $selstr;
10363: if ($k == $i) {
10364: $selstr = ' selected="selected" ';
10365: }
10366: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10367: }
10368: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10369: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10370: &mt('delete').'</span></td>'.
1.380 raeburn 10371: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10372: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10373: '</span></td></tr>';
10374: }
10375: $css_class = $rownum%2?' class="LC_odd_row"':'';
10376: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10377: $datatable .= '<tr '.$css_class.'>'.
10378: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10379: for (my $k=0; $k<=$maxnum; $k++) {
10380: my $vpos = $k+1;
10381: my $selstr;
10382: if ($k == $maxnum) {
10383: $selstr = ' selected="selected" ';
10384: }
10385: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10386: }
10387: $datatable .= '</select> '.&mt('Internal ID:').
10388: '<input type="text" size="10" name="addinststatus" value="" />'.
10389: ' '.&mt('(new)').
10390: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10391: &mt('Name displayed').':'.
1.354 raeburn 10392: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10393: '</tr>'."\n";
10394: $rownum ++;
1.294 raeburn 10395: }
1.354 raeburn 10396: }
1.409 raeburn 10397: } else {
10398: my ($unamemaprules,$ruleorder) =
10399: &Apache::lonnet::inst_userrules($dom,'unamemap');
10400: $css_class = $rownum%2?' class="LC_odd_row"':'';
10401: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10402: my $numinrow = 2;
10403: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10404: &user_formats_row('unamemap',$settings,$unamemaprules,
10405: $ruleorder,$numinrow).
10406: '</table></td></tr>';
10407: }
10408: if ($datatable eq '') {
10409: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10410: &mt('No rules set for domain in customized localenroll.pm').
10411: '</td></tr>';
10412: }
1.354 raeburn 10413: }
10414: $$rowtotal += $rownum;
1.43 raeburn 10415: return $datatable;
10416: }
10417:
1.168 raeburn 10418: sub get_languages_hash {
10419: my %langchoices;
10420: foreach my $id (&Apache::loncommon::languageids()) {
10421: my $code = &Apache::loncommon::supportedlanguagecode($id);
10422: if ($code ne '') {
10423: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10424: }
10425: }
10426: return %langchoices;
10427: }
10428:
1.43 raeburn 10429: sub defaults_titles {
1.141 raeburn 10430: my ($dom) = @_;
1.43 raeburn 10431: my %titles = &Apache::lonlocal::texthash (
10432: 'auth_def' => 'Default authentication type',
10433: 'auth_arg_def' => 'Default authentication argument',
10434: 'lang_def' => 'Default language',
1.54 raeburn 10435: 'timezone_def' => 'Default timezone',
1.68 raeburn 10436: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10437: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10438: 'email' => 'Email links use portal URL',
10439: 'web' => 'Public web links use portal URL',
1.294 raeburn 10440: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10441: 'intauth_check' => 'Check bcrypt cost if authenticated',
10442: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10443: );
1.141 raeburn 10444: if ($dom) {
10445: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10446: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10447: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10448: $protocol = 'http' if ($protocol ne 'https');
10449: if ($uint_dom) {
10450: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10451: $uint_dom);
10452: }
10453: }
1.43 raeburn 10454: return (\%titles);
10455: }
10456:
1.346 raeburn 10457: sub print_scantron {
10458: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10459: if ($position eq 'top') {
10460: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10461: } else {
10462: return &print_scantronconfig($dom,$settings,\$rowtotal);
10463: }
10464: }
10465:
10466: sub scantron_javascript {
10467: return <<"ENDSCRIPT";
10468:
10469: <script type="text/javascript">
10470: // <![CDATA[
10471:
10472: function toggleScantron(form) {
1.347 raeburn 10473: var csvfieldset = new Array();
1.346 raeburn 10474: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10475: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10476: }
10477: if (document.getElementById('scantroncsv_options')) {
10478: csvfieldset.push(document.getElementById('scantroncsv_options'));
10479: }
10480: if (csvfieldset.length) {
1.346 raeburn 10481: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10482: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10483: if (scantroncsv.checked) {
1.347 raeburn 10484: for (var i=0; i<csvfieldset.length; i++) {
10485: csvfieldset[i].style.display = 'block';
10486: }
1.346 raeburn 10487: } else {
1.347 raeburn 10488: for (var i=0; i<csvfieldset.length; i++) {
10489: csvfieldset[i].style.display = 'none';
10490: }
1.346 raeburn 10491: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10492: if (csvselects.length) {
10493: for (var j=0; j<csvselects.length; j++) {
10494: csvselects[j].selectedIndex = 0;
10495: }
10496: }
10497: }
10498: }
10499: }
10500: return;
10501: }
10502: // ]]>
10503: </script>
10504:
10505: ENDSCRIPT
10506:
10507: }
10508:
1.46 raeburn 10509: sub print_scantronformat {
10510: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10511: my $itemcount = 1;
1.60 raeburn 10512: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10513: %confhash);
1.46 raeburn 10514: my $switchserver = &check_switchserver($dom,$confname);
10515: my %lt = &Apache::lonlocal::texthash (
1.95 www 10516: default => 'Default bubblesheet format file error',
10517: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10518: );
10519: my %scantronfiles = (
10520: default => 'default.tab',
10521: custom => 'custom.tab',
10522: );
10523: foreach my $key (keys(%scantronfiles)) {
10524: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10525: .$scantronfiles{$key};
10526: }
10527: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10528: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10529: if (!$switchserver) {
10530: my $servadm = $r->dir_config('lonAdmEMail');
10531: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10532: if ($configuserok eq 'ok') {
10533: if ($author_ok eq 'ok') {
10534: my %legacyfile = (
1.346 raeburn 10535: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10536: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10537: );
10538: my %md5chk;
10539: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10540: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10541: chomp($md5chk{$type});
1.46 raeburn 10542: }
10543: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10544: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10545: ($scantronurls{$type},my $error) =
1.46 raeburn 10546: &legacy_scantronformat($r,$dom,$confname,
10547: $type,$legacyfile{$type},
10548: $scantronurls{$type},
10549: $scantronfiles{$type});
1.60 raeburn 10550: if ($error ne '') {
10551: $error{$type} = $error;
10552: }
10553: }
10554: if (keys(%error) == 0) {
10555: $is_custom = 1;
1.346 raeburn 10556: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10557: $scantronurls{'custom'};
1.346 raeburn 10558: my $putresult =
1.60 raeburn 10559: &Apache::lonnet::put_dom('configuration',
10560: \%confhash,$dom);
10561: if ($putresult ne 'ok') {
1.346 raeburn 10562: $error{'custom'} =
1.60 raeburn 10563: '<span class="LC_error">'.
10564: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10565: }
1.46 raeburn 10566: }
10567: } else {
1.60 raeburn 10568: ($scantronurls{'default'},my $error) =
1.46 raeburn 10569: &legacy_scantronformat($r,$dom,$confname,
10570: 'default',$legacyfile{'default'},
10571: $scantronurls{'default'},
10572: $scantronfiles{'default'});
1.60 raeburn 10573: if ($error eq '') {
10574: $confhash{'scantron'}{'scantronformat'} = '';
10575: my $putresult =
10576: &Apache::lonnet::put_dom('configuration',
10577: \%confhash,$dom);
10578: if ($putresult ne 'ok') {
10579: $error{'default'} =
10580: '<span class="LC_error">'.
10581: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10582: }
10583: } else {
10584: $error{'default'} = $error;
10585: }
1.46 raeburn 10586: }
10587: }
10588: }
10589: } else {
1.95 www 10590: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10591: }
10592: }
10593: if (ref($settings) eq 'HASH') {
10594: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10595: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10596: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10597: $scantronurl = '';
10598: } else {
10599: $scantronurl = $settings->{'scantronformat'};
10600: }
10601: $is_custom = 1;
10602: } else {
10603: $scantronurl = $scantronurls{'default'};
10604: }
10605: } else {
1.60 raeburn 10606: if ($is_custom) {
10607: $scantronurl = $scantronurls{'custom'};
10608: } else {
10609: $scantronurl = $scantronurls{'default'};
10610: }
1.46 raeburn 10611: }
10612: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10613: $datatable .= '<tr'.$css_class.'>';
10614: if (!$is_custom) {
1.65 raeburn 10615: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10616: '<span class="LC_nobreak">';
1.46 raeburn 10617: if ($scantronurl) {
1.199 raeburn 10618: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10619: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10620: } else {
10621: $datatable = &mt('File unavailable for display');
10622: }
1.65 raeburn 10623: $datatable .= '</span></td>';
1.60 raeburn 10624: if (keys(%error) == 0) {
1.306 raeburn 10625: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10626: if (!$switchserver) {
10627: $datatable .= &mt('Upload:').'<br />';
10628: }
10629: } else {
10630: my $errorstr;
10631: foreach my $key (sort(keys(%error))) {
10632: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10633: }
10634: $datatable .= '<td>'.$errorstr;
10635: }
1.46 raeburn 10636: } else {
10637: if (keys(%error) > 0) {
10638: my $errorstr;
10639: foreach my $key (sort(keys(%error))) {
10640: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10641: }
1.60 raeburn 10642: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10643: } elsif ($scantronurl) {
1.199 raeburn 10644: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10645: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10646: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10647: $link.
10648: '<label><input type="checkbox" name="scantronformat_del"'.
10649: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10650: '<td><span class="LC_nobreak"> '.
10651: &mt('Replace:').'</span><br />';
1.46 raeburn 10652: }
10653: }
10654: if (keys(%error) == 0) {
10655: if ($switchserver) {
10656: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10657: } else {
1.65 raeburn 10658: $datatable .='<span class="LC_nobreak"> '.
10659: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10660: }
10661: }
10662: $datatable .= '</td></tr>';
10663: $$rowtotal ++;
10664: return $datatable;
10665: }
10666:
10667: sub legacy_scantronformat {
10668: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10669: my ($url,$error);
10670: my @statinfo = &Apache::lonnet::stat_file($newurl);
10671: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 10672: my $modified = [];
1.46 raeburn 10673: (my $result,$url) =
1.421 raeburn 10674: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
10675: 'scantron','','',$newfile,$modified);
10676: if ($result eq 'ok') {
10677: &update_modify_urls($r,$modified);
10678: } else {
1.130 raeburn 10679: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10680: }
10681: }
10682: return ($url,$error);
10683: }
1.43 raeburn 10684:
1.346 raeburn 10685: sub print_scantronconfig {
10686: my ($dom,$settings,$rowtotal) = @_;
10687: my $itemcount = 2;
10688: my $is_checked = ' checked="checked"';
1.347 raeburn 10689: my %optionson = (
10690: hdr => ' checked="checked"',
10691: pad => ' checked="checked"',
10692: rem => ' checked="checked"',
10693: );
10694: my %optionsoff = (
10695: hdr => '',
10696: pad => '',
10697: rem => '',
10698: );
1.346 raeburn 10699: my $currcsvsty = 'none';
1.347 raeburn 10700: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10701: my @fields = &scantroncsv_fields();
10702: my %titles = &scantronconfig_titles();
10703: if (ref($settings) eq 'HASH') {
10704: if (ref($settings->{config}) eq 'HASH') {
10705: if ($settings->{config}->{dat}) {
10706: $checked{'dat'} = $is_checked;
10707: }
10708: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10709: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10710: %csvfields = %{$settings->{config}->{csv}->{fields}};
10711: if (keys(%csvfields) > 0) {
10712: $checked{'csv'} = $is_checked;
10713: $currcsvsty = 'block';
10714: }
10715: }
10716: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10717: %csvoptions = %{$settings->{config}->{csv}->{options}};
10718: foreach my $option (keys(%optionson)) {
10719: unless ($csvoptions{$option}) {
10720: $optionsoff{$option} = $optionson{$option};
10721: $optionson{$option} = '';
10722: }
10723: }
1.346 raeburn 10724: }
10725: }
10726: } else {
10727: $checked{'dat'} = $is_checked;
10728: }
10729: } else {
10730: $checked{'dat'} = $is_checked;
10731: }
10732: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10733: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10734: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10735: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10736: foreach my $item ('dat','csv') {
10737: my $id;
10738: if ($item eq 'csv') {
10739: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10740: }
1.346 raeburn 10741: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10742: $titles{$item}.'</label>'.(' 'x3);
10743: if ($item eq 'csv') {
10744: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10745: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10746: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10747: foreach my $col (@fields) {
10748: my $selnone;
10749: if ($csvfields{$col} eq '') {
10750: $selnone = ' selected="selected"';
10751: }
10752: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10753: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10754: '<option value=""'.$selnone.'></option>';
10755: for (my $i=0; $i<20; $i++) {
10756: my $shown = $i+1;
10757: my $sel;
10758: unless ($selnone) {
10759: if (exists($csvfields{$col})) {
10760: if ($csvfields{$col} == $i) {
10761: $sel = ' selected="selected"';
10762: }
10763: }
10764: }
10765: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10766: }
10767: $datatable .= '</select></td></tr>';
10768: }
1.347 raeburn 10769: $datatable .= '</table></fieldset>'.
10770: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10771: '<legend>'.&mt('CSV Options').'</legend>';
10772: foreach my $option ('hdr','pad','rem') {
10773: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10774: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10775: &mt('Yes').'</label>'.(' 'x2)."\n".
10776: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10777: }
10778: $datatable .= '</fieldset>';
1.346 raeburn 10779: $itemcount ++;
10780: }
10781: }
10782: $datatable .= '</td></tr>';
10783: $$rowtotal ++;
10784: return $datatable;
10785: }
10786:
10787: sub scantronconfig_titles {
10788: return &Apache::lonlocal::texthash(
10789: dat => 'Standard format (.dat)',
10790: csv => 'Comma separated values (.csv)',
1.347 raeburn 10791: hdr => 'Remove first line in file (contains column titles)',
10792: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10793: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10794: CODE => 'CODE',
10795: ID => 'Student ID',
10796: PaperID => 'Paper ID',
10797: FirstName => 'First Name',
10798: LastName => 'Last Name',
10799: FirstQuestion => 'First Question Response',
10800: Section => 'Section',
10801: );
10802: }
10803:
10804: sub scantroncsv_fields {
10805: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10806: }
10807:
1.49 raeburn 10808: sub print_coursecategories {
1.57 raeburn 10809: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10810: my $datatable;
10811: if ($position eq 'top') {
1.238 raeburn 10812: my (%checked);
10813: my @catitems = ('unauth','auth');
10814: my @cattypes = ('std','domonly','codesrch','none');
10815: $checked{'unauth'} = 'std';
10816: $checked{'auth'} = 'std';
10817: if (ref($settings) eq 'HASH') {
10818: foreach my $type (@cattypes) {
10819: if ($type eq $settings->{'unauth'}) {
10820: $checked{'unauth'} = $type;
10821: }
10822: if ($type eq $settings->{'auth'}) {
10823: $checked{'auth'} = $type;
10824: }
10825: }
10826: }
10827: my %lt = &Apache::lonlocal::texthash (
10828: unauth => 'Catalog type for unauthenticated users',
10829: auth => 'Catalog type for authenticated users',
10830: none => 'No catalog',
10831: std => 'Standard catalog',
10832: domonly => 'Domain-only catalog',
10833: codesrch => "Code search form",
10834: );
10835: my $itemcount = 0;
10836: foreach my $item (@catitems) {
10837: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10838: $datatable .= '<tr '.$css_class.'>'.
10839: '<td>'.$lt{$item}.'</td>'.
10840: '<td class="LC_right_item"><span class="LC_nobreak">';
10841: foreach my $type (@cattypes) {
10842: my $ischecked;
10843: if ($checked{$item} eq $type) {
10844: $ischecked=' checked="checked"';
10845: }
10846: $datatable .= '<label>'.
10847: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10848: ' />'.$lt{$type}.'</label> ';
10849: }
1.327 raeburn 10850: $datatable .= '</span></td></tr>';
1.238 raeburn 10851: $itemcount ++;
10852: }
10853: $$rowtotal += $itemcount;
10854: } elsif ($position eq 'middle') {
1.57 raeburn 10855: my $toggle_cats_crs = ' ';
10856: my $toggle_cats_dom = ' checked="checked" ';
10857: my $can_cat_crs = ' ';
10858: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10859: my $toggle_catscomm_comm = ' ';
10860: my $toggle_catscomm_dom = ' checked="checked" ';
10861: my $can_catcomm_comm = ' ';
10862: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10863: my $toggle_catsplace_place = ' ';
10864: my $toggle_catsplace_dom = ' checked="checked" ';
10865: my $can_catplace_place = ' ';
10866: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10867:
1.57 raeburn 10868: if (ref($settings) eq 'HASH') {
10869: if ($settings->{'togglecats'} eq 'crs') {
10870: $toggle_cats_crs = $toggle_cats_dom;
10871: $toggle_cats_dom = ' ';
10872: }
10873: if ($settings->{'categorize'} eq 'crs') {
10874: $can_cat_crs = $can_cat_dom;
10875: $can_cat_dom = ' ';
10876: }
1.120 raeburn 10877: if ($settings->{'togglecatscomm'} eq 'comm') {
10878: $toggle_catscomm_comm = $toggle_catscomm_dom;
10879: $toggle_catscomm_dom = ' ';
10880: }
10881: if ($settings->{'categorizecomm'} eq 'comm') {
10882: $can_catcomm_comm = $can_catcomm_dom;
10883: $can_catcomm_dom = ' ';
10884: }
1.272 raeburn 10885: if ($settings->{'togglecatsplace'} eq 'place') {
10886: $toggle_catsplace_place = $toggle_catsplace_dom;
10887: $toggle_catsplace_dom = ' ';
10888: }
10889: if ($settings->{'categorizeplace'} eq 'place') {
10890: $can_catplace_place = $can_catplace_dom;
10891: $can_catplace_dom = ' ';
10892: }
1.57 raeburn 10893: }
10894: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10895: togglecats => 'Show/Hide a course in catalog',
10896: togglecatscomm => 'Show/Hide a community in catalog',
10897: togglecatsplace => 'Show/Hide a placement test in catalog',
10898: categorize => 'Assign a category to a course',
10899: categorizecomm => 'Assign a category to a community',
10900: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10901: );
10902: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10903: dom => 'Set in Domain',
10904: crs => 'Set in Course',
10905: comm => 'Set in Community',
10906: place => 'Set in Placement Test',
1.57 raeburn 10907: );
10908: $datatable = '<tr class="LC_odd_row">'.
10909: '<td>'.$title{'togglecats'}.'</td>'.
10910: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10911: '<input type="radio" name="togglecats"'.
10912: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10913: '<label><input type="radio" name="togglecats"'.
10914: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10915: '</tr><tr>'.
10916: '<td>'.$title{'categorize'}.'</td>'.
10917: '<td class="LC_right_item"><span class="LC_nobreak">'.
10918: '<label><input type="radio" name="categorize"'.
10919: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10920: '<label><input type="radio" name="categorize"'.
10921: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10922: '</tr><tr class="LC_odd_row">'.
10923: '<td>'.$title{'togglecatscomm'}.'</td>'.
10924: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10925: '<input type="radio" name="togglecatscomm"'.
10926: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10927: '<label><input type="radio" name="togglecatscomm"'.
10928: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10929: '</tr><tr>'.
10930: '<td>'.$title{'categorizecomm'}.'</td>'.
10931: '<td class="LC_right_item"><span class="LC_nobreak">'.
10932: '<label><input type="radio" name="categorizecomm"'.
10933: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10934: '<label><input type="radio" name="categorizecomm"'.
10935: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10936: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10937: '<td>'.$title{'togglecatsplace'}.'</td>'.
10938: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10939: '<input type="radio" name="togglecatsplace"'.
10940: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10941: '<label><input type="radio" name="togglecatscomm"'.
10942: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10943: '</tr><tr>'.
10944: '<td>'.$title{'categorizeplace'}.'</td>'.
10945: '<td class="LC_right_item"><span class="LC_nobreak">'.
10946: '<label><input type="radio" name="categorizeplace"'.
10947: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10948: '<label><input type="radio" name="categorizeplace"'.
10949: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10950: '</tr>';
1.272 raeburn 10951: $$rowtotal += 6;
1.57 raeburn 10952: } else {
10953: my $css_class;
10954: my $itemcount = 1;
10955: my $cathash;
10956: if (ref($settings) eq 'HASH') {
10957: $cathash = $settings->{'cats'};
10958: }
10959: if (ref($cathash) eq 'HASH') {
10960: my (@cats,@trails,%allitems,%idx,@jsarray);
10961: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10962: \%allitems,\%idx,\@jsarray);
10963: my $maxdepth = scalar(@cats);
10964: my $colattrib = '';
10965: if ($maxdepth > 2) {
10966: $colattrib = ' colspan="2" ';
10967: }
10968: my @path;
10969: if (@cats > 0) {
10970: if (ref($cats[0]) eq 'ARRAY') {
10971: my $numtop = @{$cats[0]};
10972: my $maxnum = $numtop;
1.120 raeburn 10973: my %default_names = (
10974: instcode => &mt('Official courses'),
10975: communities => &mt('Communities'),
1.272 raeburn 10976: placement => &mt('Placement Tests'),
1.120 raeburn 10977: );
10978:
10979: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10980: ($cathash->{'instcode::0'} eq '') ||
10981: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10982: ($cathash->{'communities::0'} eq '') ||
10983: (!grep(/^placement$/,@{$cats[0]})) ||
10984: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10985: $maxnum ++;
10986: }
10987: my $lastidx;
10988: for (my $i=0; $i<$numtop; $i++) {
10989: my $parent = $cats[0][$i];
10990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10991: my $item = &escape($parent).'::0';
10992: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10993: $lastidx = $idx{$item};
10994: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10995: .'<select name="'.$item.'"'.$chgstr.'>';
10996: for (my $k=0; $k<=$maxnum; $k++) {
10997: my $vpos = $k+1;
10998: my $selstr;
10999: if ($k == $i) {
11000: $selstr = ' selected="selected" ';
11001: }
11002: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11003: }
1.214 raeburn 11004: $datatable .= '</select></span></td><td>';
1.272 raeburn 11005: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11006: $datatable .= '<span class="LC_nobreak">'
11007: .$default_names{$parent}.'</span>';
11008: if ($parent eq 'instcode') {
11009: $datatable .= '<br /><span class="LC_nobreak">('
11010: .&mt('with institutional codes')
11011: .')</span></td><td'.$colattrib.'>';
11012: } else {
11013: $datatable .= '<table><tr><td>';
11014: }
11015: $datatable .= '<span class="LC_nobreak">'
11016: .'<label><input type="radio" name="'
11017: .$parent.'" value="1" checked="checked" />'
11018: .&mt('Display').'</label>';
11019: if ($parent eq 'instcode') {
11020: $datatable .= ' ';
11021: } else {
11022: $datatable .= '</span></td></tr><tr><td>'
11023: .'<span class="LC_nobreak">';
11024: }
11025: $datatable .= '<label><input type="radio" name="'
11026: .$parent.'" value="0" />'
11027: .&mt('Do not display').'</label></span>';
1.272 raeburn 11028: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11029: $datatable .= '</td></tr></table>';
11030: }
11031: $datatable .= '</td>';
1.57 raeburn 11032: } else {
11033: $datatable .= $parent
1.214 raeburn 11034: .' <span class="LC_nobreak"><label>'
11035: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11036: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11037: }
11038: my $depth = 1;
11039: push(@path,$parent);
11040: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11041: pop(@path);
11042: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11043: $itemcount ++;
11044: }
1.48 raeburn 11045: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11046: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11047: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11048: for (my $k=0; $k<=$maxnum; $k++) {
11049: my $vpos = $k+1;
11050: my $selstr;
1.57 raeburn 11051: if ($k == $numtop) {
1.48 raeburn 11052: $selstr = ' selected="selected" ';
11053: }
11054: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11055: }
1.59 bisitz 11056: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11057: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11058: .'</tr>'."\n";
1.48 raeburn 11059: $itemcount ++;
1.272 raeburn 11060: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11061: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11063: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11064: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11065: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11066: for (my $k=0; $k<=$maxnum; $k++) {
11067: my $vpos = $k+1;
11068: my $selstr;
11069: if ($k == $maxnum) {
11070: $selstr = ' selected="selected" ';
11071: }
11072: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11073: }
1.120 raeburn 11074: $datatable .= '</select></span></td>'.
11075: '<td><span class="LC_nobreak">'.
11076: $default_names{$default}.'</span>';
11077: if ($default eq 'instcode') {
11078: $datatable .= '<br /><span class="LC_nobreak">('
11079: .&mt('with institutional codes').')</span>';
11080: }
11081: $datatable .= '</td>'
11082: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11083: .&mt('Display').'</label> '
11084: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11085: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11086: }
11087: }
11088: }
1.57 raeburn 11089: } else {
11090: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11091: }
11092: } else {
1.327 raeburn 11093: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11094: .&initialize_categories($itemcount);
1.48 raeburn 11095: }
1.57 raeburn 11096: $$rowtotal += $itemcount;
1.48 raeburn 11097: }
11098: return $datatable;
11099: }
11100:
1.69 raeburn 11101: sub print_serverstatuses {
11102: my ($dom,$settings,$rowtotal) = @_;
11103: my $datatable;
11104: my @pages = &serverstatus_pages();
11105: my (%namedaccess,%machineaccess);
11106: foreach my $type (@pages) {
11107: $namedaccess{$type} = '';
11108: $machineaccess{$type}= '';
11109: }
11110: if (ref($settings) eq 'HASH') {
11111: foreach my $type (@pages) {
11112: if (exists($settings->{$type})) {
11113: if (ref($settings->{$type}) eq 'HASH') {
11114: foreach my $key (keys(%{$settings->{$type}})) {
11115: if ($key eq 'namedusers') {
11116: $namedaccess{$type} = $settings->{$type}->{$key};
11117: } elsif ($key eq 'machines') {
11118: $machineaccess{$type} = $settings->{$type}->{$key};
11119: }
11120: }
11121: }
11122: }
11123: }
11124: }
1.81 raeburn 11125: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11126: my $rownum = 0;
11127: my $css_class;
11128: foreach my $type (@pages) {
11129: $rownum ++;
11130: $css_class = $rownum%2?' class="LC_odd_row"':'';
11131: $datatable .= '<tr'.$css_class.'>'.
11132: '<td><span class="LC_nobreak">'.
11133: $titles->{$type}.'</span></td>'.
11134: '<td class="LC_left_item">'.
11135: '<input type="text" name="'.$type.'_namedusers" '.
11136: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11137: '<td class="LC_right_item">'.
11138: '<span class="LC_nobreak">'.
11139: '<input type="text" name="'.$type.'_machines" '.
11140: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11141: '</span></td></tr>'."\n";
1.69 raeburn 11142: }
11143: $$rowtotal += $rownum;
11144: return $datatable;
11145: }
11146:
11147: sub serverstatus_pages {
11148: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11149: 'checksums','clusterstatus','certstatus','metadata_keywords',
11150: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11151: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11152: }
11153:
1.236 raeburn 11154: sub defaults_javascript {
11155: my ($settings) = @_;
1.354 raeburn 11156: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11157: my $portal_js = <<"ENDPORTAL";
11158:
11159: function portalExtras(caller) {
11160: var x = caller.value;
11161: var y = new Array('email','web');
11162: for (var i=0; i<y.length; i++) {
11163: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11164: var z = document.getElementById('portal_def_'+y[i]+'_div');
11165: if (x.length > 0) {
11166: z.style.display = 'block';
11167: } else {
11168: z.style.display = 'none';
11169: }
11170: }
11171: }
11172: }
11173: ENDPORTAL
1.236 raeburn 11174: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11175: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11176: if ($maxnum eq '') {
11177: $maxnum = 0;
11178: }
11179: $maxnum ++;
1.249 raeburn 11180: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11181: return <<"ENDSCRIPT";
11182: <script type="text/javascript">
11183: // <![CDATA[
11184: function reorderTypes(form,caller) {
11185: var changedVal;
11186: $jstext
11187: var newpos = 'addinststatus_pos';
11188: var current = new Array;
11189: var maxh = $maxnum;
11190: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11191: var oldVal;
11192: if (caller == newpos) {
11193: changedVal = newitemVal;
11194: } else {
11195: var curritem = 'inststatus_pos_'+caller;
11196: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11197: current[newitemVal] = newpos;
11198: }
11199: for (var i=0; i<inststatuses.length; i++) {
11200: if (inststatuses[i] != caller) {
11201: var elementName = 'inststatus_pos_'+inststatuses[i];
11202: if (form.elements[elementName]) {
11203: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11204: current[currVal] = elementName;
11205: }
11206: }
11207: }
11208: for (var j=0; j<maxh; j++) {
11209: if (current[j] == undefined) {
11210: oldVal = j;
11211: }
11212: }
11213: if (oldVal < changedVal) {
11214: for (var k=oldVal+1; k<=changedVal ; k++) {
11215: var elementName = current[k];
11216: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11217: }
11218: } else {
11219: for (var k=changedVal; k<oldVal; k++) {
11220: var elementName = current[k];
11221: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11222: }
11223: }
11224: return;
11225: }
11226:
1.414 raeburn 11227: $portal_js
11228:
11229: // ]]>
11230: </script>
11231:
11232: ENDSCRIPT
11233: } else {
11234: return <<"ENDSCRIPT";
11235: <script type="text/javascript">
11236: // <![CDATA[
11237: $portal_js
1.236 raeburn 11238: // ]]>
11239: </script>
11240:
11241: ENDSCRIPT
11242: }
1.354 raeburn 11243: return;
11244: }
11245:
11246: sub passwords_javascript {
1.405 raeburn 11247: my ($prefix) = @_;
11248: my %intalert;
11249: if ($prefix eq 'passwords') {
11250: %intalert = &Apache::lonlocal::texthash (
11251: 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.',
11252: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11253: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11254: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11255: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11256: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11257: );
1.421 raeburn 11258: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11259: %intalert = &Apache::lonlocal::texthash (
11260: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11261: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11262: );
11263: }
1.365 raeburn 11264: &js_escape(\%intalert);
11265: my $defmin = $Apache::lonnet::passwdmin;
1.405 raeburn 11266: my $intauthjs;
11267: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11268:
11269: function warnIntAuth(field) {
11270: if (field.name == 'intauth_check') {
11271: if (field.value == '2') {
1.365 raeburn 11272: alert('$intalert{authcheck}');
1.354 raeburn 11273: }
11274: }
11275: if (field.name == 'intauth_cost') {
11276: field.value.replace(/\s/g,'');
11277: if (field.value != '') {
11278: var regexdigit=/^\\d+\$/;
11279: if (!regexdigit.test(field.value)) {
1.365 raeburn 11280: alert('$intalert{authcost}');
11281: }
11282: }
11283: }
11284: return;
11285: }
11286:
1.405 raeburn 11287: ENDSCRIPT
11288:
11289: }
11290:
11291: $intauthjs .= <<"ENDSCRIPT";
11292:
11293: function warnInt$prefix(field) {
1.365 raeburn 11294: field.value.replace(/^\s+/,'');
11295: field.value.replace(/\s+\$/,'');
11296: var regexdigit=/^\\d+\$/;
1.408 raeburn 11297: if (field.name == '${prefix}_min') {
1.365 raeburn 11298: if (field.value == '') {
11299: alert('$intalert{passmin}');
11300: field.value = '$defmin';
11301: } else {
11302: if (!regexdigit.test(field.value)) {
11303: alert('$intalert{passmin}');
11304: field.value = '$defmin';
11305: }
1.366 raeburn 11306: var minval = parseInt(field.value,10);
1.365 raeburn 11307: if (minval < $defmin) {
11308: alert('$intalert{passmin}');
11309: field.value = '$defmin';
11310: }
11311: }
11312: } else {
11313: if (field.value == '0') {
11314: field.value = '';
11315: }
11316: if (field.value != '') {
1.408 raeburn 11317: if (field.name == '${prefix}_expire') {
1.365 raeburn 11318: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11319: if (!regexpposnum.test(field.value)) {
11320: alert('$intalert{passexp}');
11321: field.value = '';
11322: } else {
11323: var expval = parseFloat(field.value);
11324: if (expval == 0) {
11325: alert('$intalert{passexp}');
11326: field.value = '';
11327: }
11328: }
11329: } else {
11330: if (!regexdigit.test(field.value)) {
1.408 raeburn 11331: if (field.name == '${prefix}_max') {
1.365 raeburn 11332: alert('$intalert{passmax}');
11333: } else {
1.408 raeburn 11334: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11335: alert('$intalert{passnum}');
11336: }
11337: }
1.370 raeburn 11338: field.value = '';
1.365 raeburn 11339: }
1.354 raeburn 11340: }
11341: }
11342: }
11343: return;
11344: }
11345:
11346: ENDSCRIPT
11347: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11348: }
11349:
1.49 raeburn 11350: sub coursecategories_javascript {
11351: my ($settings) = @_;
1.57 raeburn 11352: my ($output,$jstext,$cathash);
1.49 raeburn 11353: if (ref($settings) eq 'HASH') {
1.57 raeburn 11354: $cathash = $settings->{'cats'};
11355: }
11356: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11357: my (@cats,@jsarray,%idx);
1.57 raeburn 11358: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11359: if (@jsarray > 0) {
11360: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11361: for (my $i=0; $i<@jsarray; $i++) {
11362: if (ref($jsarray[$i]) eq 'ARRAY') {
11363: my $catstr = join('","',@{$jsarray[$i]});
11364: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11365: }
11366: }
11367: }
11368: } else {
11369: $jstext = ' var categories = Array(1);'."\n".
11370: ' categories[0] = Array("instcode_pos");'."\n";
11371: }
1.237 bisitz 11372: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11373: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11374: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11375: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11376: &js_escape(\$instcode_reserved);
11377: &js_escape(\$communities_reserved);
1.272 raeburn 11378: &js_escape(\$placement_reserved);
1.265 damieng 11379: &js_escape(\$choose_again);
1.49 raeburn 11380: $output = <<"ENDSCRIPT";
11381: <script type="text/javascript">
1.109 raeburn 11382: // <![CDATA[
1.49 raeburn 11383: function reorderCats(form,parent,item,idx) {
11384: var changedVal;
11385: $jstext
11386: var newpos = 'addcategory_pos';
11387: if (parent == '') {
11388: var has_instcode = 0;
11389: var maxtop = categories[idx].length;
11390: for (var j=0; j<maxtop; j++) {
11391: if (categories[idx][j] == 'instcode::0') {
11392: has_instcode == 1;
11393: }
11394: }
11395: if (has_instcode == 0) {
11396: categories[idx][maxtop] = 'instcode_pos';
11397: }
11398: } else {
11399: newpos += '_'+parent;
11400: }
11401: var maxh = 1 + categories[idx].length;
11402: var current = new Array;
11403: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11404: if (item == newpos) {
11405: changedVal = newitemVal;
11406: } else {
11407: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11408: current[newitemVal] = newpos;
11409: }
11410: for (var i=0; i<categories[idx].length; i++) {
11411: var elementName = categories[idx][i];
11412: if (elementName != item) {
11413: if (form.elements[elementName]) {
11414: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11415: current[currVal] = elementName;
11416: }
11417: }
11418: }
11419: var oldVal;
11420: for (var j=0; j<maxh; j++) {
11421: if (current[j] == undefined) {
11422: oldVal = j;
11423: }
11424: }
11425: if (oldVal < changedVal) {
11426: for (var k=oldVal+1; k<=changedVal ; k++) {
11427: var elementName = current[k];
11428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11429: }
11430: } else {
11431: for (var k=changedVal; k<oldVal; k++) {
11432: var elementName = current[k];
11433: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11434: }
11435: }
11436: return;
11437: }
1.120 raeburn 11438:
11439: function categoryCheck(form) {
11440: if (form.elements['addcategory_name'].value == 'instcode') {
11441: alert('$instcode_reserved\\n$choose_again');
11442: return false;
11443: }
11444: if (form.elements['addcategory_name'].value == 'communities') {
11445: alert('$communities_reserved\\n$choose_again');
11446: return false;
11447: }
1.272 raeburn 11448: if (form.elements['addcategory_name'].value == 'placement') {
11449: alert('$placement_reserved\\n$choose_again');
11450: return false;
11451: }
1.120 raeburn 11452: return true;
11453: }
11454:
1.109 raeburn 11455: // ]]>
1.49 raeburn 11456: </script>
11457:
11458: ENDSCRIPT
11459: return $output;
11460: }
11461:
1.48 raeburn 11462: sub initialize_categories {
11463: my ($itemcount) = @_;
1.120 raeburn 11464: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11465: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11466: instcode => 'Official courses (with institutional codes)',
11467: communities => 'Communities',
1.272 raeburn 11468: placement => 'Placement Tests',
1.120 raeburn 11469: );
1.328 raeburn 11470: my %selnum = (
11471: instcode => '0',
11472: communities => '1',
11473: placement => '2',
11474: );
11475: my %selected;
1.272 raeburn 11476: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11478: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11479: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11480: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11481: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11482: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11483: .'<option value="0"'.$selected{'0'}.'>1</option>'
11484: .'<option value="1"'.$selected{'1'}.'>2</option>'
11485: .'<option value="2"'.$selected{'2'}.'>3</option>'
11486: .'<option value="3">4</option></select> '
1.120 raeburn 11487: .$default_names{$default}
11488: .'</span></td><td><span class="LC_nobreak">'
11489: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11490: .&mt('Display').'</label> <label>'
11491: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11492: .'</label></span></td></tr>';
1.120 raeburn 11493: $itemcount ++;
11494: }
1.48 raeburn 11495: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11496: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11497: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11498: .'<select name="addcategory_pos"'.$chgstr.'>'
11499: .'<option value="0">1</option>'
11500: .'<option value="1">2</option>'
1.328 raeburn 11501: .'<option value="2">3</option>'
11502: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11503: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11504: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11505: .'</td></tr>';
1.48 raeburn 11506: return $datatable;
11507: }
11508:
11509: sub build_category_rows {
1.49 raeburn 11510: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11511: my ($text,$name,$item,$chgstr);
1.48 raeburn 11512: if (ref($cats) eq 'ARRAY') {
11513: my $maxdepth = scalar(@{$cats});
11514: if (ref($cats->[$depth]) eq 'HASH') {
11515: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11516: my $numchildren = @{$cats->[$depth]{$parent}};
11517: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11518: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11519: my ($idxnum,$parent_name,$parent_item);
11520: my $higher = $depth - 1;
11521: if ($higher == 0) {
11522: $parent_name = &escape($parent).'::'.$higher;
11523: } else {
11524: if (ref($path) eq 'ARRAY') {
11525: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11526: }
11527: }
11528: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11529: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11530: if ($j < $numchildren) {
1.48 raeburn 11531: $name = $cats->[$depth]{$parent}[$j];
11532: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11533: $idxnum = $idx->{$item};
11534: } else {
11535: $name = $parent_name;
11536: $item = $parent_item;
1.48 raeburn 11537: }
1.49 raeburn 11538: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11539: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11540: for (my $i=0; $i<=$numchildren; $i++) {
11541: my $vpos = $i+1;
11542: my $selstr;
11543: if ($j == $i) {
11544: $selstr = ' selected="selected" ';
11545: }
11546: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11547: }
11548: $text .= '</select> ';
11549: if ($j < $numchildren) {
11550: my $deeper = $depth+1;
11551: $text .= $name.' '
11552: .'<label><input type="checkbox" name="deletecategory" value="'
11553: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11554: if(ref($path) eq 'ARRAY') {
11555: push(@{$path},$name);
1.49 raeburn 11556: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11557: pop(@{$path});
11558: }
11559: } else {
1.330 raeburn 11560: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11561: if ($j == $numchildren) {
11562: $text .= $name;
11563: } else {
11564: $text .= $item;
11565: }
11566: $text .= '" value="" />';
11567: }
11568: $text .= '</td></tr>';
11569: }
11570: $text .= '</table></td>';
11571: } else {
11572: my $higher = $depth-1;
11573: if ($higher == 0) {
11574: $name = &escape($parent).'::'.$higher;
11575: } else {
11576: if (ref($path) eq 'ARRAY') {
11577: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11578: }
11579: }
11580: my $colspan;
11581: if ($parent ne 'instcode') {
11582: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11583: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11584: }
11585: }
11586: }
11587: }
11588: return $text;
11589: }
11590:
1.33 raeburn 11591: sub modifiable_userdata_row {
1.305 raeburn 11592: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11593: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11594: my ($role,$rolename,$statustype);
11595: $role = $item;
1.224 raeburn 11596: if ($context eq 'cancreate') {
1.305 raeburn 11597: if ($item =~ /^(emailusername)_(.+)$/) {
11598: $role = $1;
11599: $statustype = $2;
1.228 raeburn 11600: if (ref($usertypes) eq 'HASH') {
11601: if ($usertypes->{$statustype}) {
11602: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11603: } else {
11604: $rolename = &mt('Data provided by user');
11605: }
11606: }
1.224 raeburn 11607: }
11608: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11609: if (ref($usertypes) eq 'HASH') {
11610: $rolename = $usertypes->{$role};
11611: } else {
11612: $rolename = $role;
11613: }
1.325 raeburn 11614: } elsif ($context eq 'lti') {
11615: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11616: } elsif ($context eq 'privacy') {
11617: $rolename = $itemdesc;
1.33 raeburn 11618: } else {
1.63 raeburn 11619: if ($role eq 'cr') {
11620: $rolename = &mt('Custom role');
11621: } else {
11622: $rolename = &Apache::lonnet::plaintext($role);
11623: }
1.33 raeburn 11624: }
1.224 raeburn 11625: my (@fields,%fieldtitles);
11626: if (ref($fieldsref) eq 'ARRAY') {
11627: @fields = @{$fieldsref};
11628: } else {
11629: @fields = ('lastname','firstname','middlename','generation',
11630: 'permanentemail','id');
11631: }
11632: if ((ref($titlesref) eq 'HASH')) {
11633: %fieldtitles = %{$titlesref};
11634: } else {
11635: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11636: }
1.33 raeburn 11637: my $output;
1.305 raeburn 11638: my $css_class;
11639: if ($rowcount%2) {
11640: $css_class = 'LC_odd_row';
11641: }
11642: if ($customcss) {
11643: $css_class .= " $customcss";
11644: }
11645: $css_class =~ s/^\s+//;
11646: if ($css_class) {
11647: $css_class = ' class="'.$css_class.'"';
11648: }
11649: if ($rowstyle) {
11650: $css_class .= ' style="'.$rowstyle.'"';
11651: }
11652: if ($rowid) {
11653: $rowid = ' id="'.$rowid.'"';
11654: }
11655: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11656: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11657: '<td class="LC_left_item" colspan="2"><table>';
11658: my $rem;
11659: my %checks;
1.325 raeburn 11660: my %current;
1.33 raeburn 11661: if (ref($settings) eq 'HASH') {
1.325 raeburn 11662: my $hashref;
11663: if ($context eq 'lti') {
11664: if (ref($settings) eq 'HASH') {
11665: $hashref = $settings->{'instdata'};
11666: }
1.357 raeburn 11667: } elsif ($context eq 'privacy') {
11668: my ($key,$inner) = split(/_/,$role);
11669: if (ref($settings) eq 'HASH') {
11670: if (ref($settings->{$key}) eq 'HASH') {
11671: $hashref = $settings->{$key}->{$inner};
11672: }
11673: }
1.325 raeburn 11674: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11675: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11676: $hashref = $settings->{'lti_instdata'};
11677: }
11678: if ($role eq 'emailusername') {
11679: if ($statustype) {
11680: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11681: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11682: }
1.325 raeburn 11683: }
11684: }
11685: }
11686: if (ref($hashref) eq 'HASH') {
11687: foreach my $field (@fields) {
11688: if ($hashref->{$field}) {
11689: if ($role eq 'emailusername') {
11690: $checks{$field} = $hashref->{$field};
11691: } else {
11692: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11693: }
11694: }
11695: }
11696: }
11697: }
1.305 raeburn 11698:
11699: my $total = scalar(@fields);
11700: for (my $i=0; $i<$total; $i++) {
11701: $rem = $i%($numinrow);
1.33 raeburn 11702: if ($rem == 0) {
11703: if ($i > 0) {
11704: $output .= '</tr>';
11705: }
11706: $output .= '<tr>';
11707: }
11708: my $check = ' ';
1.228 raeburn 11709: unless ($role eq 'emailusername') {
11710: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11711: $check = $checks{$fields[$i]};
1.357 raeburn 11712: } elsif ($context eq 'privacy') {
11713: if ($role =~ /^priv_(domain|course)$/) {
11714: if (ref($settings) ne 'HASH') {
11715: $check = ' checked="checked" ';
11716: }
11717: } elsif ($role =~ /^priv_(author|community)$/) {
11718: if (ref($settings) ne 'HASH') {
11719: unless ($fields[$i] eq 'id') {
11720: $check = ' checked="checked" ';
11721: }
11722: }
11723: } elsif ($role =~ /^(unpriv|othdom)_/) {
11724: if (ref($settings) ne 'HASH') {
11725: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11726: $check = ' checked="checked" ';
11727: }
11728: }
11729: }
1.325 raeburn 11730: } elsif ($context ne 'lti') {
1.228 raeburn 11731: if ($role eq 'st') {
11732: if (ref($settings) ne 'HASH') {
11733: $check = ' checked="checked" ';
11734: }
1.33 raeburn 11735: }
11736: }
11737: }
11738: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11739: '<span class="LC_nobreak">';
1.325 raeburn 11740: my $prefix = 'canmodify';
1.228 raeburn 11741: if ($role eq 'emailusername') {
11742: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11743: $checks{$fields[$i]} = 'omit';
11744: }
11745: foreach my $option ('required','optional','omit') {
11746: my $checked='';
11747: if ($checks{$fields[$i]} eq $option) {
11748: $checked='checked="checked" ';
11749: }
11750: $output .= '<label>'.
1.325 raeburn 11751: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11752: &mt($option).'</label>'.(' ' x2);
11753: }
11754: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11755: } else {
1.325 raeburn 11756: if ($context eq 'lti') {
11757: $prefix = 'lti';
1.357 raeburn 11758: } elsif ($context eq 'privacy') {
11759: $prefix = 'privacy';
1.325 raeburn 11760: }
1.228 raeburn 11761: $output .= '<label>'.
1.325 raeburn 11762: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11763: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11764: '</label>';
11765: }
11766: $output .= '</span></td>';
1.33 raeburn 11767: }
1.305 raeburn 11768: $rem = $total%$numinrow;
11769: my $colsleft;
11770: if ($rem) {
11771: $colsleft = $numinrow - $rem;
11772: }
11773: if ($colsleft > 1) {
1.33 raeburn 11774: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11775: ' </td>';
11776: } elsif ($colsleft == 1) {
11777: $output .= '<td class="LC_left_item"> </td>';
11778: }
11779: $output .= '</tr></table></td></tr>';
11780: return $output;
11781: }
1.28 raeburn 11782:
1.93 raeburn 11783: sub insttypes_row {
1.305 raeburn 11784: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11785: $customcss,$rowstyle) = @_;
1.93 raeburn 11786: my %lt = &Apache::lonlocal::texthash (
11787: cansearch => 'Users allowed to search',
11788: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11789: lockablenames => 'User preference to lock name',
1.305 raeburn 11790: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11791: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11792: );
11793: my $showdom;
11794: if ($context eq 'cansearch') {
11795: $showdom = ' ('.$dom.')';
11796: }
1.165 raeburn 11797: my $class = 'LC_left_item';
11798: if ($context eq 'statustocreate') {
11799: $class = 'LC_right_item';
11800: }
1.305 raeburn 11801: my $css_class;
11802: if ($$rowtotal%2) {
11803: $css_class = 'LC_odd_row';
11804: }
11805: if ($customcss) {
11806: $css_class .= ' '.$customcss;
11807: }
11808: $css_class =~ s/^\s+//;
11809: if ($css_class) {
11810: $css_class = ' class="'.$css_class.'"';
11811: }
11812: if ($rowstyle) {
11813: $css_class .= ' style="'.$rowstyle.'"';
11814: }
11815: if ($onclick) {
11816: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11817: }
11818: my $output = '<tr'.$css_class.'>'.
11819: '<td>'.$lt{$context}.$showdom.
11820: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11821: my $rem;
11822: if (ref($types) eq 'ARRAY') {
11823: for (my $i=0; $i<@{$types}; $i++) {
11824: if (defined($usertypes->{$types->[$i]})) {
11825: my $rem = $i%($numinrow);
11826: if ($rem == 0) {
11827: if ($i > 0) {
11828: $output .= '</tr>';
11829: }
11830: $output .= '<tr>';
1.23 raeburn 11831: }
1.26 raeburn 11832: my $check = ' ';
1.99 raeburn 11833: if (ref($settings) eq 'HASH') {
11834: if (ref($settings->{$context}) eq 'ARRAY') {
11835: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11836: $check = ' checked="checked" ';
11837: }
1.315 raeburn 11838: } elsif (ref($settings->{$context}) eq 'HASH') {
11839: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11840: $check = ' checked="checked" ';
11841: }
1.99 raeburn 11842: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11843: $check = ' checked="checked" ';
11844: }
1.23 raeburn 11845: }
1.26 raeburn 11846: $output .= '<td class="LC_left_item">'.
11847: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11848: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11849: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11850: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11851: }
11852: }
1.26 raeburn 11853: $rem = @{$types}%($numinrow);
1.23 raeburn 11854: }
11855: my $colsleft = $numinrow - $rem;
1.315 raeburn 11856: if ($context eq 'overrides') {
11857: if ($colsleft > 1) {
11858: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11859: } else {
11860: $output .= '<td class="LC_left_item">';
11861: }
11862: $output .= ' ';
1.23 raeburn 11863: } else {
1.334 raeburn 11864: if ($rem == 0) {
1.315 raeburn 11865: $output .= '<tr>';
11866: }
11867: if ($colsleft > 1) {
11868: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11869: } else {
11870: $output .= '<td class="LC_left_item">';
11871: }
11872: my $defcheck = ' ';
11873: if (ref($settings) eq 'HASH') {
11874: if (ref($settings->{$context}) eq 'ARRAY') {
11875: if (grep(/^default$/,@{$settings->{$context}})) {
11876: $defcheck = ' checked="checked" ';
11877: }
11878: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11879: $defcheck = ' checked="checked" ';
11880: }
1.26 raeburn 11881: }
1.315 raeburn 11882: $output .= '<span class="LC_nobreak"><label>'.
11883: '<input type="checkbox" name="'.$context.'" '.
11884: 'value="default"'.$defcheck.$onclick.' />'.
11885: $othertitle.'</label></span>';
1.23 raeburn 11886: }
1.315 raeburn 11887: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11888: return $output;
1.23 raeburn 11889: }
11890:
11891: sub sorted_searchtitles {
11892: my %searchtitles = &Apache::lonlocal::texthash(
11893: 'uname' => 'username',
11894: 'lastname' => 'last name',
11895: 'lastfirst' => 'last name, first name',
11896: );
11897: my @titleorder = ('uname','lastname','lastfirst');
11898: return (\%searchtitles,\@titleorder);
11899: }
11900:
1.25 raeburn 11901: sub sorted_searchtypes {
11902: my %srchtypes_desc = (
11903: exact => 'is exact match',
11904: contains => 'contains ..',
11905: begins => 'begins with ..',
11906: );
11907: my @srchtypeorder = ('exact','begins','contains');
11908: return (\%srchtypes_desc,\@srchtypeorder);
11909: }
11910:
1.3 raeburn 11911: sub usertype_update_row {
11912: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11913: my $datatable;
11914: my $numinrow = 4;
11915: foreach my $type (@{$types}) {
11916: if (defined($usertypes->{$type})) {
11917: $$rownums ++;
11918: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11919: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11920: '</td><td class="LC_left_item"><table>';
11921: for (my $i=0; $i<@{$fields}; $i++) {
11922: my $rem = $i%($numinrow);
11923: if ($rem == 0) {
11924: if ($i > 0) {
11925: $datatable .= '</tr>';
11926: }
11927: $datatable .= '<tr>';
11928: }
11929: my $check = ' ';
1.39 raeburn 11930: if (ref($settings) eq 'HASH') {
11931: if (ref($settings->{'fields'}) eq 'HASH') {
11932: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11933: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11934: $check = ' checked="checked" ';
11935: }
1.3 raeburn 11936: }
11937: }
11938: }
11939:
11940: if ($i == @{$fields}-1) {
11941: my $colsleft = $numinrow - $rem;
11942: if ($colsleft > 1) {
11943: $datatable .= '<td colspan="'.$colsleft.'">';
11944: } else {
11945: $datatable .= '<td>';
11946: }
11947: } else {
11948: $datatable .= '<td>';
11949: }
1.8 raeburn 11950: $datatable .= '<span class="LC_nobreak"><label>'.
11951: '<input type="checkbox" name="updateable_'.$type.
11952: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11953: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11954: }
11955: $datatable .= '</tr></table></td></tr>';
11956: }
11957: }
11958: return $datatable;
1.1 raeburn 11959: }
11960:
11961: sub modify_login {
1.205 raeburn 11962: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11963: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11964: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 11965: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 11966: %title = ( coursecatalog => 'Display course catalog',
11967: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11968: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11969: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11970: loginheader => 'Log-in box header',
11971: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11972: @offon = ('off','on');
1.112 raeburn 11973: if (ref($domconfig{login}) eq 'HASH') {
11974: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11975: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11976: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11977: }
11978: }
1.386 raeburn 11979: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11980: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11981: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11982: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11983: $saml{$lonhost} = 1;
11984: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11985: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11986: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11987: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11988: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 11989: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 11990: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11991: }
11992: }
11993: }
1.112 raeburn 11994: }
1.9 raeburn 11995: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11996: \%domconfig,\%loginhash);
1.188 raeburn 11997: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11998: foreach my $item (@toggles) {
11999: $loginhash{login}{$item} = $env{'form.'.$item};
12000: }
1.41 raeburn 12001: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12002: if (ref($colchanges{'login'}) eq 'HASH') {
12003: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12004: \%loginhash);
12005: }
1.110 raeburn 12006:
1.149 raeburn 12007: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12008: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12009: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12010: if (keys(%servers) > 1) {
12011: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12012: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12013: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12014: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12015: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12016: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12017: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12018: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12019: $changes{'loginvia'}{$lonhost} = 1;
12020: } else {
12021: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12022: $changes{'loginvia'}{$lonhost} = 1;
12023: }
12024: } else {
12025: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12026: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12027: $changes{'loginvia'}{$lonhost} = 1;
12028: }
12029: }
12030: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12031: foreach my $item (@loginvia_attribs) {
12032: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12033: }
12034: } else {
12035: foreach my $item (@loginvia_attribs) {
12036: my $new = $env{'form.'.$lonhost.'_'.$item};
12037: if (($item eq 'serverpath') && ($new eq 'custom')) {
12038: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12039: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12040: $new = '/';
12041: }
12042: }
12043: if (($item eq 'custompath') &&
12044: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12045: $new = '';
12046: }
12047: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12048: $changes{'loginvia'}{$lonhost} = 1;
12049: }
12050: if ($item eq 'exempt') {
1.256 raeburn 12051: $new = &check_exempt_addresses($new);
1.128 raeburn 12052: }
12053: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12054: }
12055: }
1.112 raeburn 12056: } else {
1.128 raeburn 12057: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12058: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12059: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12060: foreach my $item (@loginvia_attribs) {
12061: my $new = $env{'form.'.$lonhost.'_'.$item};
12062: if (($item eq 'serverpath') && ($new eq 'custom')) {
12063: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12064: $new = '/';
12065: }
12066: }
12067: if (($item eq 'custompath') &&
12068: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12069: $new = '';
12070: }
12071: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12072: }
1.110 raeburn 12073: }
12074: }
12075: }
12076: }
1.119 raeburn 12077:
1.168 raeburn 12078: my $servadm = $r->dir_config('lonAdmEMail');
12079: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12080: if (ref($domconfig{'login'}) eq 'HASH') {
12081: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12082: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12083: if ($lang eq 'nolang') {
12084: push(@currlangs,$lang);
12085: } elsif (defined($langchoices{$lang})) {
12086: push(@currlangs,$lang);
12087: } else {
12088: next;
12089: }
12090: }
12091: }
12092: }
12093: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12094: if (@currlangs > 0) {
12095: foreach my $lang (@currlangs) {
12096: if (grep(/^\Q$lang\E$/,@delurls)) {
12097: $changes{'helpurl'}{$lang} = 1;
12098: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12099: $changes{'helpurl'}{$lang} = 1;
12100: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12101: push(@newlangs,$lang);
12102: } else {
12103: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12104: }
12105: }
12106: }
12107: unless (grep(/^nolang$/,@currlangs)) {
12108: if ($env{'form.loginhelpurl_nolang.filename'}) {
12109: $changes{'helpurl'}{'nolang'} = 1;
12110: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12111: push(@newlangs,'nolang');
12112: }
12113: }
12114: if ($env{'form.loginhelpurl_add_lang'}) {
12115: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12116: ($env{'form.loginhelpurl_add_file.filename'})) {
12117: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12118: $addedfile = $env{'form.loginhelpurl_add_lang'};
12119: }
12120: }
12121: if ((@newlangs > 0) || ($addedfile)) {
12122: my $error;
12123: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12124: if ($configuserok eq 'ok') {
12125: if ($switchserver) {
12126: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12127: } elsif ($author_ok eq 'ok') {
12128: my @allnew = @newlangs;
12129: if ($addedfile ne '') {
12130: push(@allnew,$addedfile);
12131: }
1.421 raeburn 12132: my $modified = [];
1.168 raeburn 12133: foreach my $lang (@allnew) {
12134: my $formelem = 'loginhelpurl_'.$lang;
12135: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12136: $formelem = 'loginhelpurl_add_file';
12137: }
1.421 raeburn 12138: (my $result,$newurl{$lang}) =
12139: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12140: "help/$lang",'','',$newfile{$lang},
12141: $modified);
1.168 raeburn 12142: if ($result eq 'ok') {
12143: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12144: $changes{'helpurl'}{$lang} = 1;
12145: } else {
12146: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12147: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12148: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12149: (!grep(/^\Q$lang\E$/,@delurls))) {
12150: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12151: }
12152: }
12153: }
1.421 raeburn 12154: &update_modify_urls($r,$modified);
1.168 raeburn 12155: } else {
12156: $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);
12157: }
12158: } else {
12159: $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);
12160: }
12161: if ($error) {
12162: &Apache::lonnet::logthis($error);
12163: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12164: }
12165: }
1.256 raeburn 12166:
12167: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12168: if (ref($domconfig{'login'}) eq 'HASH') {
12169: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12170: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12171: if ($domservers{$lonhost}) {
12172: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12173: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12174: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12175: }
12176: }
12177: }
12178: }
12179: }
12180: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12181: foreach my $lonhost (sort(keys(%domservers))) {
12182: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12183: $changes{'headtag'}{$lonhost} = 1;
12184: } else {
12185: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12186: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12187: }
12188: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12189: push(@newhosts,$lonhost);
12190: } elsif ($currheadtagurls{$lonhost}) {
12191: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12192: if ($currexempt{$lonhost}) {
1.289 raeburn 12193: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12194: $changes{'headtag'}{$lonhost} = 1;
12195: }
12196: } elsif ($possexempt{$lonhost}) {
12197: $changes{'headtag'}{$lonhost} = 1;
12198: }
12199: if ($possexempt{$lonhost}) {
12200: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12201: }
12202: }
12203: }
12204: }
12205: if (@newhosts) {
12206: my $error;
12207: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12208: if ($configuserok eq 'ok') {
12209: if ($switchserver) {
12210: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12211: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12212: my $modified = [];
1.256 raeburn 12213: foreach my $lonhost (@newhosts) {
12214: my $formelem = 'loginheadtag_'.$lonhost;
1.421 raeburn 12215: (my $result,$newheadtagurls{$lonhost}) =
12216: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12217: "login/headtag/$lonhost",'','',
12218: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12219: $modified);
1.256 raeburn 12220: if ($result eq 'ok') {
12221: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12222: $changes{'headtag'}{$lonhost} = 1;
12223: if ($possexempt{$lonhost}) {
12224: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12225: }
12226: } else {
12227: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12228: $newheadtagurls{$lonhost},$result);
12229: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12230: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12231: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12232: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12233: }
12234: }
12235: }
1.421 raeburn 12236: &update_modify_urls($r,$modified);
1.256 raeburn 12237: } else {
12238: $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);
12239: }
12240: } else {
12241: $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);
12242: }
12243: if ($error) {
12244: &Apache::lonnet::logthis($error);
12245: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12246: }
12247: }
1.386 raeburn 12248: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12249: my @newsamlimgs;
12250: foreach my $lonhost (keys(%domservers)) {
12251: if ($env{'form.saml_'.$lonhost}) {
12252: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12253: push(@newsamlimgs,$lonhost);
12254: }
1.412 raeburn 12255: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12256: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12257: }
12258: if ($saml{$lonhost}) {
1.412 raeburn 12259: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12260: $env{'form.saml_window_'.$lonhost} = '';
12261: }
1.386 raeburn 12262: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12263: #FIXME Need to obsolete published image
12264: delete($currsaml{$lonhost}{'img'});
12265: $changes{'saml'}{$lonhost} = 1;
12266: }
12267: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12268: $changes{'saml'}{$lonhost} = 1;
12269: }
12270: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12271: $changes{'saml'}{$lonhost} = 1;
12272: }
12273: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12274: $changes{'saml'}{$lonhost} = 1;
12275: }
12276: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12277: $changes{'saml'}{$lonhost} = 1;
12278: }
1.412 raeburn 12279: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12280: $changes{'saml'}{$lonhost} = 1;
12281: }
1.386 raeburn 12282: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12283: $changes{'saml'}{$lonhost} = 1;
12284: }
12285: } else {
12286: $changes{'saml'}{$lonhost} = 1;
12287: }
1.412 raeburn 12288: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12289: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12290: }
12291: } else {
1.389 raeburn 12292: if ($saml{$lonhost}) {
12293: $changes{'saml'}{$lonhost} = 1;
12294: delete($currsaml{$lonhost});
12295: }
1.386 raeburn 12296: }
12297: }
12298: foreach my $posshost (keys(%currsaml)) {
12299: unless (exists($domservers{$posshost})) {
12300: delete($currsaml{$posshost});
12301: }
12302: }
12303: %{$loginhash{'login'}{'saml'}} = %currsaml;
12304: if (@newsamlimgs) {
12305: my $error;
12306: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12307: if ($configuserok eq 'ok') {
12308: if ($switchserver) {
12309: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12310: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12311: my $modified = [];
1.386 raeburn 12312: foreach my $lonhost (@newsamlimgs) {
12313: my $formelem = 'saml_img_'.$lonhost;
1.421 raeburn 12314: my ($result,$imgurl) =
12315: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12316: "login/saml/$lonhost",'','',
12317: $env{'form.saml_img_'.$lonhost.'.filename'},
12318: $modified);
1.386 raeburn 12319: if ($result eq 'ok') {
12320: $currsaml{$lonhost}{'img'} = $imgurl;
12321: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12322: $changes{'saml'}{$lonhost} = 1;
12323: } else {
12324: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12325: $lonhost,$result);
12326: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12327: }
12328: }
1.421 raeburn 12329: &update_modify_urls($r,$modified);
1.386 raeburn 12330: } else {
12331: $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);
12332: }
12333: } else {
12334: $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);
12335: }
12336: if ($error) {
12337: &Apache::lonnet::logthis($error);
12338: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12339: }
12340: }
1.169 raeburn 12341: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12342:
12343: my $defaulthelpfile = '/adm/loginproblems.html';
12344: my $defaulttext = &mt('Default in use');
12345:
1.1 raeburn 12346: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12347: $dom);
12348: if ($putresult eq 'ok') {
1.188 raeburn 12349: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12350: my %defaultchecked = (
12351: 'coursecatalog' => 'on',
1.188 raeburn 12352: 'helpdesk' => 'on',
1.42 raeburn 12353: 'adminmail' => 'off',
1.43 raeburn 12354: 'newuser' => 'off',
1.42 raeburn 12355: );
1.55 raeburn 12356: if (ref($domconfig{'login'}) eq 'HASH') {
12357: foreach my $item (@toggles) {
12358: if ($defaultchecked{$item} eq 'on') {
12359: if (($domconfig{'login'}{$item} eq '0') &&
12360: ($env{'form.'.$item} eq '1')) {
12361: $changes{$item} = 1;
12362: } elsif (($domconfig{'login'}{$item} eq '' ||
12363: $domconfig{'login'}{$item} eq '1') &&
12364: ($env{'form.'.$item} eq '0')) {
12365: $changes{$item} = 1;
12366: }
12367: } elsif ($defaultchecked{$item} eq 'off') {
12368: if (($domconfig{'login'}{$item} eq '1') &&
12369: ($env{'form.'.$item} eq '0')) {
12370: $changes{$item} = 1;
12371: } elsif (($domconfig{'login'}{$item} eq '' ||
12372: $domconfig{'login'}{$item} eq '0') &&
12373: ($env{'form.'.$item} eq '1')) {
12374: $changes{$item} = 1;
12375: }
1.42 raeburn 12376: }
12377: }
1.41 raeburn 12378: }
1.6 raeburn 12379: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12380: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12381: if (exists($changes{'saml'})) {
12382: my $hostid_in_use;
12383: my @hosts = &Apache::lonnet::current_machine_ids();
12384: if (@hosts > 1) {
12385: foreach my $hostid (@hosts) {
12386: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12387: $hostid_in_use = $hostid;
12388: last;
12389: }
12390: }
12391: } else {
12392: $hostid_in_use = $r->dir_config('lonHostID');
12393: }
12394: if (($hostid_in_use) &&
12395: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12396: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12397: }
12398: if (ref($lastactref) eq 'HASH') {
12399: if (ref($changes{'saml'}) eq 'HASH') {
12400: my %updates;
12401: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12402: $lastactref->{'samllanding'} = \%updates;
12403: }
12404: }
12405: }
1.212 raeburn 12406: if (ref($lastactref) eq 'HASH') {
12407: $lastactref->{'domainconfig'} = 1;
12408: }
1.1 raeburn 12409: $resulttext = &mt('Changes made:').'<ul>';
12410: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12411: if ($item eq 'loginvia') {
1.112 raeburn 12412: if (ref($changes{$item}) eq 'HASH') {
12413: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12414: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12415: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12416: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12417: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12418: $protocol = 'http' if ($protocol ne 'https');
12419: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12420:
12421: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12422: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12423: } else {
12424: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12425: }
12426: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12427: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12428: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12429: }
12430: $resulttext .= '</li>';
12431: } else {
12432: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12433: }
1.112 raeburn 12434: } else {
1.128 raeburn 12435: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12436: }
12437: }
1.128 raeburn 12438: $resulttext .= '</ul></li>';
1.112 raeburn 12439: }
1.168 raeburn 12440: } elsif ($item eq 'helpurl') {
12441: if (ref($changes{$item}) eq 'HASH') {
12442: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12443: if (grep(/^\Q$lang\E$/,@delurls)) {
12444: my ($chg,$link);
12445: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12446: if ($lang eq 'nolang') {
12447: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12448: } else {
12449: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12450: }
12451: $resulttext .= '<li>'.$chg.'</li>';
12452: } else {
12453: my $chg;
12454: if ($lang eq 'nolang') {
12455: $chg = &mt('custom log-in help file for no preferred language');
12456: } else {
12457: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12458: }
12459: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12460: $loginhash{'login'}{'helpurl'}{$lang}.
12461: '?inhibitmenu=yes',$chg,600,500).
12462: '</li>';
12463: }
12464: }
12465: }
1.256 raeburn 12466: } elsif ($item eq 'headtag') {
12467: if (ref($changes{$item}) eq 'HASH') {
12468: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12469: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12470: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12471: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12472: $resulttext .= '<li><a href="'.
12473: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12474: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12475: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12476: if ($possexempt{$lonhost}) {
12477: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12478: } else {
12479: $resulttext .= &mt('included for any client IP');
12480: }
12481: $resulttext .= '</li>';
12482: }
12483: }
12484: }
1.386 raeburn 12485: } elsif ($item eq 'saml') {
12486: if (ref($changes{$item}) eq 'HASH') {
12487: my %notlt = (
12488: text => 'Text for log-in by SSO',
12489: img => 'SSO button image',
12490: alt => 'Alt text for button image',
12491: url => 'SSO URL',
12492: title => 'Tooltip for SSO link',
1.412 raeburn 12493: window => 'Pop-up window if iframe',
1.386 raeburn 12494: notsso => 'Text for non-SSO log-in',
12495: );
12496: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12497: if (ref($currsaml{$lonhost}) eq 'HASH') {
12498: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12499: '<ul>';
1.412 raeburn 12500: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12501: if ($currsaml{$lonhost}{$key} eq '') {
12502: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12503: } else {
12504: my $value = "'$currsaml{$lonhost}{$key}'";
12505: if ($key eq 'img') {
12506: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12507: } elsif ($key eq 'window') {
12508: $value = 'On';
1.386 raeburn 12509: }
12510: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12511: $value).'</li>';
12512: }
12513: }
12514: $resulttext .= '</ul></li>';
12515: } else {
12516: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12517: }
12518: }
12519: }
1.169 raeburn 12520: } elsif ($item eq 'captcha') {
12521: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12522: my $chgtxt;
1.169 raeburn 12523: if ($loginhash{'login'}{$item} eq 'notused') {
12524: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12525: } else {
12526: my %captchas = &captcha_phrases();
12527: if ($captchas{$loginhash{'login'}{$item}}) {
12528: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12529: } else {
12530: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12531: }
12532: }
12533: $resulttext .= '<li>'.$chgtxt.'</li>';
12534: }
12535: } elsif ($item eq 'recaptchakeys') {
12536: if (ref($loginhash{'login'}) eq 'HASH') {
12537: my ($privkey,$pubkey);
12538: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12539: $pubkey = $loginhash{'login'}{$item}{'public'};
12540: $privkey = $loginhash{'login'}{$item}{'private'};
12541: }
12542: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12543: if (!$pubkey) {
12544: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12545: } else {
12546: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12547: }
12548: if (!$privkey) {
12549: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12550: } else {
1.251 raeburn 12551: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12552: }
12553: $chgtxt .= '</ul>';
12554: $resulttext .= '<li>'.$chgtxt.'</li>';
12555: }
1.269 raeburn 12556: } elsif ($item eq 'recaptchaversion') {
12557: if (ref($loginhash{'login'}) eq 'HASH') {
12558: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12559: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12560: '</li>';
12561: }
12562: }
1.41 raeburn 12563: } else {
12564: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12565: }
1.1 raeburn 12566: }
1.6 raeburn 12567: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12568: } else {
12569: $resulttext = &mt('No changes made to log-in page settings');
12570: }
12571: } else {
1.11 albertel 12572: $resulttext = '<span class="LC_error">'.
12573: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12574: }
1.6 raeburn 12575: if ($errors) {
1.9 raeburn 12576: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12577: $errors.'</ul>';
12578: }
12579: return $resulttext;
12580: }
12581:
1.256 raeburn 12582: sub check_exempt_addresses {
12583: my ($iplist) = @_;
12584: $iplist =~ s/^\s+//;
12585: $iplist =~ s/\s+$//;
12586: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12587: my (@okips,$new);
12588: foreach my $ip (@poss_ips) {
12589: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12590: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12591: push(@okips,$ip);
12592: }
12593: }
12594: }
12595: if (@okips > 0) {
12596: $new = join(',',@okips);
12597: } else {
12598: $new = '';
12599: }
12600: return $new;
12601: }
12602:
1.6 raeburn 12603: sub color_font_choices {
12604: my %choices =
12605: &Apache::lonlocal::texthash (
12606: img => "Header",
12607: bgs => "Background colors",
12608: links => "Link colors",
1.55 raeburn 12609: images => "Images",
1.6 raeburn 12610: font => "Font color",
1.201 raeburn 12611: fontmenu => "Font menu",
1.76 raeburn 12612: pgbg => "Page",
1.6 raeburn 12613: tabbg => "Header",
12614: sidebg => "Border",
12615: link => "Link",
12616: alink => "Active link",
12617: vlink => "Visited link",
12618: );
12619: return %choices;
12620: }
12621:
1.394 raeburn 12622: sub modify_ipaccess {
12623: my ($dom,$lastactref,%domconfig) = @_;
12624: my (@allpos,%changes,%confhash,$errors,$resulttext);
12625: my (@items,%deletions,%itemids,@warnings);
12626: my ($typeorder,$types) = &commblocktype_text();
12627: if ($env{'form.ipaccess_add'}) {
12628: my $name = $env{'form.ipaccess_name_add'};
12629: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12630: if ($newid) {
12631: $itemids{'add'} = $newid;
12632: push(@items,'add');
12633: $changes{$newid} = 1;
12634: } else {
12635: $error = &mt('Failed to acquire unique ID for new IP access control item');
12636: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12637: }
12638: }
12639: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12640: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12641: if (@todelete) {
12642: map { $deletions{$_} = 1; } @todelete;
12643: }
12644: my $maxnum = $env{'form.ipaccess_maxnum'};
12645: for (my $i=0; $i<$maxnum; $i++) {
12646: my $itemid = $env{'form.ipaccess_id_'.$i};
12647: $itemid =~ s/\D+//g;
12648: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12649: if ($deletions{$itemid}) {
12650: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12651: } else {
12652: push(@items,$i);
12653: $itemids{$i} = $itemid;
12654: }
12655: }
12656: }
12657: }
12658: foreach my $idx (@items) {
12659: my $itemid = $itemids{$idx};
12660: next unless ($itemid);
12661: my %current;
12662: unless ($idx eq 'add') {
12663: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12664: %current = %{$domconfig{'ipaccess'}{$itemid}};
12665: }
12666: }
12667: my $position = $env{'form.ipaccess_pos_'.$itemid};
12668: $position =~ s/\D+//g;
12669: if ($position ne '') {
12670: $allpos[$position] = $itemid;
12671: }
12672: my $name = $env{'form.ipaccess_name_'.$idx};
12673: $name =~ s/^\s+|\s+$//g;
12674: $confhash{$itemid}{'name'} = $name;
12675: my $possrange = $env{'form.ipaccess_range_'.$idx};
12676: $possrange =~ s/^\s+|\s+$//g;
12677: unless ($possrange eq '') {
12678: $possrange =~ s/[\r\n]+/\s/g;
12679: $possrange =~ s/\s*-\s*/-/g;
12680: $possrange =~ s/\s+/,/g;
12681: $possrange =~ s/,+/,/g;
12682: if ($possrange ne '') {
12683: my (@ok,$count);
12684: $count = 0;
12685: foreach my $poss (split(/\,/,$possrange)) {
12686: $count ++;
12687: $poss = &validate_ip_pattern($poss);
12688: if ($poss ne '') {
12689: push(@ok,$poss);
12690: }
12691: }
12692: my $diff = $count - scalar(@ok);
12693: if ($diff) {
12694: $errors .= '<li><span class="LC_error">'.
12695: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
12696: $diff,$name).
12697: '</span></li>';
12698: }
12699: if (@ok) {
12700: my @cidr_list;
12701: foreach my $item (@ok) {
12702: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
12703: }
12704: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
12705: }
12706: }
12707: }
12708: foreach my $field ('name','ip') {
12709: unless (($idx eq 'add') || ($changes{$itemid})) {
12710: if ($current{$field} ne $confhash{$itemid}{$field}) {
12711: $changes{$itemid} = 1;
12712: last;
12713: }
12714: }
12715: }
12716: $confhash{$itemid}{'commblocks'} = {};
12717:
12718: my %commblocks;
12719: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
12720: foreach my $type (@{$typeorder}) {
12721: if ($commblocks{$type}) {
12722: $confhash{$itemid}{'commblocks'}{$type} = 'on';
12723: }
12724: unless (($idx eq 'add') || ($changes{$itemid})) {
12725: if (ref($current{'commblocks'}) eq 'HASH') {
12726: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
12727: $changes{$itemid} = 1;
12728: }
12729: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
12730: $changes{$itemid} = 1;
12731: }
12732: }
12733: }
12734: $confhash{$itemid}{'courses'} = {};
12735: my %crsdeletions;
12736: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
12737: if (@delcrs) {
12738: map { $crsdeletions{$_} = 1; } @delcrs;
12739: }
12740: if (ref($current{'courses'}) eq 'HASH') {
12741: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
12742: if ($crsdeletions{$cid}) {
12743: $changes{$itemid} = 1;
12744: } else {
12745: $confhash{$itemid}{'courses'}{$cid} = 1;
12746: }
12747: }
12748: }
12749: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
12750: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
12751: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
12752: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
12753: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
12754: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
12755: $errors .= '<li><span class="LC_error">'.
12756: &mt('Invalid courseID [_1] omitted from list of allowed courses',
12757: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
12758: '</span></li>';
12759: } else {
12760: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
12761: $changes{$itemid} = 1;
12762: }
12763: }
12764: }
12765: if (@allpos > 0) {
12766: my $idx = 0;
12767: foreach my $itemid (@allpos) {
12768: if ($itemid ne '') {
12769: $confhash{$itemid}{'order'} = $idx;
12770: unless ($changes{$itemid}) {
12771: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12772: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12773: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
12774: $changes{$itemid} = 1;
12775: }
12776: }
12777: }
12778: }
12779: $idx ++;
12780: }
12781: }
12782: }
12783: if (keys(%changes)) {
12784: my %defaultshash = (
12785: ipaccess => \%confhash,
12786: );
12787: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12788: $dom);
12789: if ($putresult eq 'ok') {
12790: my $cachetime = 1800;
12791: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
12792: if (ref($lastactref) eq 'HASH') {
12793: $lastactref->{'ipaccess'} = 1;
12794: }
12795: $resulttext = &mt('Changes made:').'<ul>';
12796: my %bynum;
12797: foreach my $itemid (sort(keys(%changes))) {
12798: if (ref($confhash{$itemid}) eq 'HASH') {
12799: my $position = $confhash{$itemid}{'order'};
12800: if ($position =~ /^\d+$/) {
12801: $bynum{$position} = $itemid;
12802: }
12803: }
12804: }
12805: if (keys(%deletions)) {
12806: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
12807: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12808: }
12809: }
12810: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12811: my $itemid = $bynum{$pos};
12812: if (ref($confhash{$itemid}) eq 'HASH') {
12813: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
12814: my $position = $pos + 1;
12815: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12816: if ($confhash{$itemid}{'ip'} eq '') {
12817: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
12818: } else {
12819: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
12820: }
12821: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
12822: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
12823: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
12824: '</li>';
12825: } else {
12826: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
12827: }
12828: if (keys(%{$confhash{$itemid}{'courses'}})) {
12829: my @courses;
12830: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
12831: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
12832: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
12833: }
12834: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
12835: join('</li><li>',@courses).'</li></ul>';
12836: } else {
12837: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
12838: }
1.395 raeburn 12839: $resulttext .= '</ul></li>';
1.394 raeburn 12840: }
12841: }
1.395 raeburn 12842: $resulttext .= '</ul>';
1.394 raeburn 12843: } else {
12844: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12845: }
12846: } else {
12847: $resulttext = &mt('No changes made');
12848: }
12849: if ($errors) {
12850: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12851: $errors.'</ul></p>';
12852: }
12853: return $resulttext;
12854: }
12855:
12856: sub get_ipaccess_id {
12857: my ($domain,$location) = @_;
12858: # get lock on ipaccess db
12859: my $lockhash = {
12860: lock => $env{'user.name'}.
12861: ':'.$env{'user.domain'},
12862: };
12863: my $tries = 0;
12864: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12865: my ($id,$error);
12866:
12867: while (($gotlock ne 'ok') && ($tries<10)) {
12868: $tries ++;
12869: sleep (0.1);
12870: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12871: }
12872: if ($gotlock eq 'ok') {
12873: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12874: if ($currids{'lock'}) {
12875: delete($currids{'lock'});
12876: if (keys(%currids)) {
12877: my @curr = sort { $a <=> $b } keys(%currids);
12878: if ($curr[-1] =~ /^\d+$/) {
12879: $id = 1 + $curr[-1];
12880: }
12881: } else {
12882: $id = 1;
12883: }
12884: if ($id) {
12885: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12886: $error = 'nostore';
12887: }
12888: } else {
12889: $error = 'nonumber';
12890: }
12891: }
12892: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12893: } else {
12894: $error = 'nolock';
12895: }
12896: return ($id,$error);
12897: }
12898:
1.6 raeburn 12899: sub modify_rolecolors {
1.205 raeburn 12900: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12901: my ($resulttext,%rolehash);
12902: $rolehash{'rolecolors'} = {};
1.55 raeburn 12903: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12904: if ($domconfig{'rolecolors'} eq '') {
12905: $domconfig{'rolecolors'} = {};
12906: }
12907: }
1.9 raeburn 12908: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12909: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12910: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12911: $dom);
12912: if ($putresult eq 'ok') {
12913: if (keys(%changes) > 0) {
1.41 raeburn 12914: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12915: if (ref($lastactref) eq 'HASH') {
12916: $lastactref->{'domainconfig'} = 1;
12917: }
1.6 raeburn 12918: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12919: $rolehash{'rolecolors'});
12920: } else {
12921: $resulttext = &mt('No changes made to default color schemes');
12922: }
12923: } else {
1.11 albertel 12924: $resulttext = '<span class="LC_error">'.
12925: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12926: }
12927: if ($errors) {
12928: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12929: $errors.'</ul>';
12930: }
12931: return $resulttext;
12932: }
12933:
12934: sub modify_colors {
1.9 raeburn 12935: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12936: my (%changes,%choices);
1.51 raeburn 12937: my @bgs;
1.6 raeburn 12938: my @links = ('link','alink','vlink');
1.41 raeburn 12939: my @logintext;
1.6 raeburn 12940: my @images;
12941: my $servadm = $r->dir_config('lonAdmEMail');
12942: my $errors;
1.200 raeburn 12943: my %defaults;
1.6 raeburn 12944: foreach my $role (@{$roles}) {
12945: if ($role eq 'login') {
1.12 raeburn 12946: %choices = &login_choices();
1.41 raeburn 12947: @logintext = ('textcol','bgcol');
1.12 raeburn 12948: } else {
12949: %choices = &color_font_choices();
12950: }
12951: if ($role eq 'login') {
1.41 raeburn 12952: @images = ('img','logo','domlogo','login');
1.51 raeburn 12953: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12954: } else {
12955: @images = ('img');
1.200 raeburn 12956: @bgs = ('pgbg','tabbg','sidebg');
12957: }
12958: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12959: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12960: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12961: }
12962: if ($role eq 'login') {
12963: foreach my $item (@logintext) {
1.234 raeburn 12964: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12965: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12966: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12967: }
12968: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12969: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12970: }
12971: }
12972: } else {
1.234 raeburn 12973: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12974: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12975: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12976: }
12977: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12978: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12979: }
1.6 raeburn 12980: }
1.200 raeburn 12981: foreach my $item (@bgs) {
1.234 raeburn 12982: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12983: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12984: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12985: }
12986: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12987: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12988: }
12989: }
12990: foreach my $item (@links) {
1.234 raeburn 12991: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12992: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12993: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12994: }
12995: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12996: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12997: }
1.6 raeburn 12998: }
1.46 raeburn 12999: my ($configuserok,$author_ok,$switchserver) =
13000: &config_check($dom,$confname,$servadm);
1.9 raeburn 13001: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13002: if (ref($domconfig->{$role}) ne 'HASH') {
13003: $domconfig->{$role} = {};
13004: }
1.8 raeburn 13005: foreach my $img (@images) {
1.402 raeburn 13006: if ($role eq 'login') {
13007: if (($img eq 'img') || ($img eq 'logo')) {
13008: if (defined($env{'form.login_showlogo_'.$img})) {
13009: $confhash->{$role}{'showlogo'}{$img} = 1;
13010: } else {
13011: $confhash->{$role}{'showlogo'}{$img} = 0;
13012: }
13013: }
13014: if ($env{'form.login_alt_'.$img} ne '') {
13015: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13016: }
1.402 raeburn 13017: }
1.18 albertel 13018: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13019: && !defined($domconfig->{$role}{$img})
13020: && !$env{'form.'.$role.'_del_'.$img}
13021: && $env{'form.'.$role.'_import_'.$img}) {
13022: # import the old configured image from the .tab setting
13023: # if they haven't provided a new one
13024: $domconfig->{$role}{$img} =
13025: $env{'form.'.$role.'_import_'.$img};
13026: }
1.6 raeburn 13027: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13028: my $error;
1.6 raeburn 13029: if ($configuserok eq 'ok') {
1.9 raeburn 13030: if ($switchserver) {
1.12 raeburn 13031: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13032: } else {
13033: if ($author_ok eq 'ok') {
1.421 raeburn 13034: my $modified = [];
1.9 raeburn 13035: my ($result,$logourl) =
1.421 raeburn 13036: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13037: $dom,$confname,$img,$width,$height,
13038: '',$modified);
1.9 raeburn 13039: if ($result eq 'ok') {
13040: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13041: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13042: &update_modify_urls($r,$modified);
1.9 raeburn 13043: } else {
1.12 raeburn 13044: $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 13045: }
13046: } else {
1.46 raeburn 13047: $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 13048: }
13049: }
13050: } else {
1.46 raeburn 13051: $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 13052: }
13053: if ($error) {
1.8 raeburn 13054: &Apache::lonnet::logthis($error);
1.11 albertel 13055: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13056: }
13057: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13058: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13059: my $error;
13060: if ($configuserok eq 'ok') {
13061: # is confname an author?
13062: if ($switchserver eq '') {
13063: if ($author_ok eq 'ok') {
1.421 raeburn 13064: my $modified = [];
1.9 raeburn 13065: my ($result,$logourl) =
1.421 raeburn 13066: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13067: $dom,$confname,$img,$width,$height,
13068: '',$modified);
1.9 raeburn 13069: if ($result eq 'ok') {
13070: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13071: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13072: &update_modify_urls($r,$modified);
1.9 raeburn 13073: }
13074: }
13075: }
13076: }
1.6 raeburn 13077: }
13078: }
13079: }
13080: if (ref($domconfig) eq 'HASH') {
13081: if (ref($domconfig->{$role}) eq 'HASH') {
13082: foreach my $img (@images) {
13083: if ($domconfig->{$role}{$img} ne '') {
13084: if ($env{'form.'.$role.'_del_'.$img}) {
13085: $confhash->{$role}{$img} = '';
1.12 raeburn 13086: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13087: } else {
1.9 raeburn 13088: if ($confhash->{$role}{$img} eq '') {
13089: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13090: }
1.6 raeburn 13091: }
13092: } else {
13093: if ($env{'form.'.$role.'_del_'.$img}) {
13094: $confhash->{$role}{$img} = '';
1.12 raeburn 13095: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13096: }
13097: }
1.402 raeburn 13098: if ($role eq 'login') {
13099: if (($img eq 'logo') || ($img eq 'img')) {
13100: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13101: if ($confhash->{$role}{'showlogo'}{$img} ne
13102: $domconfig->{$role}{'showlogo'}{$img}) {
13103: $changes{$role}{'showlogo'}{$img} = 1;
13104: }
13105: } else {
13106: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13107: $changes{$role}{'showlogo'}{$img} = 1;
13108: }
1.70 raeburn 13109: }
1.402 raeburn 13110: }
13111: if ($img ne 'login') {
13112: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13113: if ($confhash->{$role}{'alttext'}{$img} ne
13114: $domconfig->{$role}{'alttext'}{$img}) {
13115: $changes{$role}{'alttext'}{$img} = 1;
13116: }
13117: } else {
13118: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13119: $changes{$role}{'alttext'}{$img} = 1;
13120: }
1.70 raeburn 13121: }
13122: }
13123: }
13124: }
1.6 raeburn 13125: if ($domconfig->{$role}{'font'} ne '') {
13126: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13127: $changes{$role}{'font'} = 1;
13128: }
13129: } else {
13130: if ($confhash->{$role}{'font'}) {
13131: $changes{$role}{'font'} = 1;
13132: }
13133: }
1.107 raeburn 13134: if ($role ne 'login') {
13135: if ($domconfig->{$role}{'fontmenu'} ne '') {
13136: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13137: $changes{$role}{'fontmenu'} = 1;
13138: }
13139: } else {
13140: if ($confhash->{$role}{'fontmenu'}) {
13141: $changes{$role}{'fontmenu'} = 1;
13142: }
1.97 tempelho 13143: }
13144: }
1.6 raeburn 13145: foreach my $item (@bgs) {
13146: if ($domconfig->{$role}{$item} ne '') {
13147: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13148: $changes{$role}{'bgs'}{$item} = 1;
13149: }
13150: } else {
13151: if ($confhash->{$role}{$item}) {
13152: $changes{$role}{'bgs'}{$item} = 1;
13153: }
13154: }
13155: }
13156: foreach my $item (@links) {
13157: if ($domconfig->{$role}{$item} ne '') {
13158: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13159: $changes{$role}{'links'}{$item} = 1;
13160: }
13161: } else {
13162: if ($confhash->{$role}{$item}) {
13163: $changes{$role}{'links'}{$item} = 1;
13164: }
13165: }
13166: }
1.41 raeburn 13167: foreach my $item (@logintext) {
13168: if ($domconfig->{$role}{$item} ne '') {
13169: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13170: $changes{$role}{'logintext'}{$item} = 1;
13171: }
13172: } else {
13173: if ($confhash->{$role}{$item}) {
13174: $changes{$role}{'logintext'}{$item} = 1;
13175: }
13176: }
13177: }
1.6 raeburn 13178: } else {
13179: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13180: \@logintext,$confhash,\%changes);
1.6 raeburn 13181: }
13182: } else {
13183: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13184: \@logintext,$confhash,\%changes);
1.6 raeburn 13185: }
13186: }
13187: return ($errors,%changes);
13188: }
13189:
1.46 raeburn 13190: sub config_check {
13191: my ($dom,$confname,$servadm) = @_;
13192: my ($configuserok,$author_ok,$switchserver,%currroles);
13193: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13194: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13195: $confname,$servadm);
13196: if ($configuserok eq 'ok') {
13197: $switchserver = &check_switchserver($dom,$confname);
13198: if ($switchserver eq '') {
13199: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13200: }
13201: }
13202: return ($configuserok,$author_ok,$switchserver);
13203: }
13204:
1.6 raeburn 13205: sub default_change_checker {
1.41 raeburn 13206: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13207: foreach my $item (@{$links}) {
13208: if ($confhash->{$role}{$item}) {
13209: $changes->{$role}{'links'}{$item} = 1;
13210: }
13211: }
13212: foreach my $item (@{$bgs}) {
13213: if ($confhash->{$role}{$item}) {
13214: $changes->{$role}{'bgs'}{$item} = 1;
13215: }
13216: }
1.41 raeburn 13217: foreach my $item (@{$logintext}) {
13218: if ($confhash->{$role}{$item}) {
13219: $changes->{$role}{'logintext'}{$item} = 1;
13220: }
13221: }
1.6 raeburn 13222: foreach my $img (@{$images}) {
13223: if ($env{'form.'.$role.'_del_'.$img}) {
13224: $confhash->{$role}{$img} = '';
1.12 raeburn 13225: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13226: }
1.70 raeburn 13227: if ($role eq 'login') {
13228: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13229: $changes->{$role}{'showlogo'}{$img} = 1;
13230: }
1.402 raeburn 13231: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13232: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13233: $changes->{$role}{'alttext'}{$img} = 1;
13234: }
13235: }
1.70 raeburn 13236: }
1.6 raeburn 13237: }
13238: if ($confhash->{$role}{'font'}) {
13239: $changes->{$role}{'font'} = 1;
13240: }
1.48 raeburn 13241: }
1.6 raeburn 13242:
13243: sub display_colorchgs {
13244: my ($dom,$changes,$roles,$confhash) = @_;
13245: my (%choices,$resulttext);
13246: if (!grep(/^login$/,@{$roles})) {
13247: $resulttext = &mt('Changes made:').'<br />';
13248: }
13249: foreach my $role (@{$roles}) {
13250: if ($role eq 'login') {
13251: %choices = &login_choices();
13252: } else {
13253: %choices = &color_font_choices();
13254: }
13255: if (ref($changes->{$role}) eq 'HASH') {
13256: if ($role ne 'login') {
13257: $resulttext .= '<h4>'.&mt($role).'</h4>';
13258: }
13259: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13260: if ($role ne 'login') {
13261: $resulttext .= '<ul>';
13262: }
13263: if (ref($changes->{$role}{$key}) eq 'HASH') {
13264: if ($role ne 'login') {
13265: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13266: }
13267: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13268: if (($role eq 'login') && ($key eq 'showlogo')) {
13269: if ($confhash->{$role}{$key}{$item}) {
13270: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13271: } else {
13272: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13273: }
1.402 raeburn 13274: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13275: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13276: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13277: $confhash->{$role}{$key}{$item}).'</li>';
13278: } else {
13279: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13280: }
1.70 raeburn 13281: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13282: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13283: } else {
1.12 raeburn 13284: my $newitem = $confhash->{$role}{$item};
13285: if ($key eq 'images') {
1.306 raeburn 13286: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13287: }
13288: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13289: }
13290: }
13291: if ($role ne 'login') {
13292: $resulttext .= '</ul></li>';
13293: }
13294: } else {
13295: if ($confhash->{$role}{$key} eq '') {
13296: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13297: } else {
13298: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13299: }
13300: }
13301: if ($role ne 'login') {
13302: $resulttext .= '</ul>';
13303: }
13304: }
13305: }
13306: }
1.3 raeburn 13307: return $resulttext;
1.1 raeburn 13308: }
13309:
1.9 raeburn 13310: sub thumb_dimensions {
13311: return ('200','50');
13312: }
13313:
1.16 raeburn 13314: sub check_dimensions {
13315: my ($inputfile) = @_;
13316: my ($fullwidth,$fullheight);
13317: if ($inputfile =~ m|^[/\w.\-]+$|) {
13318: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13319: my $imageinfo = <PIPE>;
13320: if (!close(PIPE)) {
13321: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13322: }
13323: chomp($imageinfo);
13324: my ($fullsize) =
1.21 raeburn 13325: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13326: if ($fullsize) {
13327: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13328: }
13329: }
13330: }
13331: return ($fullwidth,$fullheight);
13332: }
13333:
1.9 raeburn 13334: sub check_configuser {
13335: my ($uhome,$dom,$confname,$servadm) = @_;
13336: my ($configuserok,%currroles);
13337: if ($uhome eq 'no_host') {
13338: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13339: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13340: $configuserok =
13341: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13342: $configpass,'','','','','',undef,$servadm);
13343: } else {
13344: $configuserok = 'ok';
13345: %currroles =
13346: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13347: }
13348: return ($configuserok,%currroles);
13349: }
13350:
13351: sub check_authorstatus {
13352: my ($dom,$confname,%currroles) = @_;
13353: my $author_ok;
1.40 raeburn 13354: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13355: my $start = time;
13356: my $end = 0;
13357: $author_ok =
13358: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13359: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13360: } else {
13361: $author_ok = 'ok';
13362: }
13363: return $author_ok;
13364: }
13365:
1.421 raeburn 13366: sub update_modify_urls {
13367: my ($r,$modified) = @_;
13368: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
13369: push(@{$modified_urls},$modified);
13370: unless ($registered_cleanup) {
13371: my $handlers = $r->get_handlers('PerlCleanupHandler');
13372: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13373: $registered_cleanup=1;
1.9 raeburn 13374: }
13375: }
1.155 raeburn 13376: }
13377:
13378: sub notifysubscribed {
13379: foreach my $targetsource (@{$modified_urls}){
13380: next unless (ref($targetsource) eq 'ARRAY');
13381: my ($target,$source)=@{$targetsource};
13382: if ($source ne '') {
1.316 raeburn 13383: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13384: print $logfh "\nCleanup phase: Notifications\n";
13385: my @subscribed=&subscribed_hosts($target);
13386: foreach my $subhost (@subscribed) {
13387: print $logfh "\nNotifying host ".$subhost.':';
13388: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13389: print $logfh $reply;
13390: }
13391: my @subscribedmeta=&subscribed_hosts("$target.meta");
13392: foreach my $subhost (@subscribedmeta) {
13393: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13394: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13395: $subhost);
13396: print $logfh $reply;
13397: }
13398: print $logfh "\n============ Done ============\n";
1.160 raeburn 13399: close($logfh);
1.155 raeburn 13400: }
13401: }
13402: }
13403: return OK;
13404: }
13405:
13406: sub subscribed_hosts {
13407: my ($target) = @_;
13408: my @subscribed;
1.316 raeburn 13409: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13410: while (my $subline=<$fh>) {
13411: if ($subline =~ /^($match_lonid):/) {
13412: my $host = $1;
13413: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13414: unless (grep(/^\Q$host\E$/,@subscribed)) {
13415: push(@subscribed,$host);
13416: }
13417: }
13418: }
13419: }
13420: }
13421: return @subscribed;
1.9 raeburn 13422: }
13423:
13424: sub check_switchserver {
13425: my ($dom,$confname) = @_;
13426: my ($allowed,$switchserver);
13427: my $home = &Apache::lonnet::homeserver($confname,$dom);
13428: if ($home eq 'no_host') {
13429: $home = &Apache::lonnet::domain($dom,'primary');
13430: }
13431: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 13432: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
13433: if (!$allowed) {
1.180 raeburn 13434: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 13435: }
13436: return $switchserver;
13437: }
13438:
1.1 raeburn 13439: sub modify_quotas {
1.216 raeburn 13440: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 13441: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 13442: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 13443: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
13444: $validationfieldsref);
1.86 raeburn 13445: if ($action eq 'quotas') {
13446: $context = 'tools';
1.163 raeburn 13447: } else {
1.86 raeburn 13448: $context = $action;
13449: }
13450: if ($context eq 'requestcourses') {
1.325 raeburn 13451: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 13452: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 13453: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
13454: %titles = &courserequest_titles();
13455: $toolregexp = join('|',@usertools);
13456: %conditions = &courserequest_conditions();
1.216 raeburn 13457: $confname = $dom.'-domainconfig';
13458: my $servadm = $r->dir_config('lonAdmEMail');
13459: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 13460: ($validationitemsref,$validationnamesref,$validationfieldsref) =
13461: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 13462: } elsif ($context eq 'requestauthor') {
13463: @usertools = ('author');
13464: %titles = &authorrequest_titles();
1.86 raeburn 13465: } else {
1.413 raeburn 13466: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 13467: %titles = &tool_titles();
1.86 raeburn 13468: }
1.212 raeburn 13469: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 13470: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13471: foreach my $key (keys(%env)) {
1.101 raeburn 13472: if ($context eq 'requestcourses') {
13473: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
13474: my $item = $1;
13475: my $type = $2;
13476: if ($type =~ /^limit_(.+)/) {
13477: $limithash{$item}{$1} = $env{$key};
13478: } else {
13479: $confhash{$item}{$type} = $env{$key};
13480: }
13481: }
1.163 raeburn 13482: } elsif ($context eq 'requestauthor') {
13483: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
13484: $confhash{$1} = $env{$key};
13485: }
1.101 raeburn 13486: } else {
1.86 raeburn 13487: if ($key =~ /^form\.quota_(.+)$/) {
13488: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 13489: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
13490: $confhash{'authorquota'}{$1} = $env{$key};
13491: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 13492: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
13493: }
1.72 raeburn 13494: }
13495: }
1.163 raeburn 13496: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 13497: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 13498: @approvalnotify = sort(@approvalnotify);
13499: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 13500: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 13501: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
13502: foreach my $type (@hasuniquecode) {
13503: if (grep(/^\Q$type\E$/,@crstypes)) {
13504: $confhash{'uniquecode'}{$type} = 1;
13505: }
1.216 raeburn 13506: }
1.242 raeburn 13507: my (%newbook,%allpos);
1.216 raeburn 13508: if ($context eq 'requestcourses') {
1.242 raeburn 13509: foreach my $type ('textbooks','templates') {
13510: @{$allpos{$type}} = ();
13511: my $invalid;
13512: if ($type eq 'textbooks') {
13513: $invalid = &mt('Invalid LON-CAPA course for textbook');
13514: } else {
13515: $invalid = &mt('Invalid LON-CAPA course for template');
13516: }
13517: if ($env{'form.'.$type.'_addbook'}) {
13518: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
13519: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
13520: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
13521: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
13522: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
13523: } else {
13524: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
13525: my $position = $env{'form.'.$type.'_addbook_pos'};
13526: $position =~ s/\D+//g;
13527: if ($position ne '') {
13528: $allpos{$type}[$position] = $newbook{$type};
13529: }
1.216 raeburn 13530: }
1.242 raeburn 13531: } else {
13532: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 13533: }
13534: }
1.242 raeburn 13535: }
1.216 raeburn 13536: }
1.102 raeburn 13537: if (ref($domconfig{$action}) eq 'HASH') {
13538: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
13539: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
13540: $changes{'notify'}{'approval'} = 1;
13541: }
13542: } else {
1.144 raeburn 13543: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13544: $changes{'notify'}{'approval'} = 1;
13545: }
13546: }
1.218 raeburn 13547: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
13548: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13549: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
13550: unless ($confhash{'uniquecode'}{$crstype}) {
13551: $changes{'uniquecode'} = 1;
13552: }
13553: }
13554: unless ($changes{'uniquecode'}) {
13555: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
13556: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
13557: $changes{'uniquecode'} = 1;
13558: }
13559: }
13560: }
13561: } else {
13562: $changes{'uniquecode'} = 1;
13563: }
13564: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
13565: $changes{'uniquecode'} = 1;
1.216 raeburn 13566: }
13567: if ($context eq 'requestcourses') {
1.242 raeburn 13568: foreach my $type ('textbooks','templates') {
13569: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13570: my %deletions;
13571: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
13572: if (@todelete) {
13573: map { $deletions{$_} = 1; } @todelete;
13574: }
13575: my %imgdeletions;
13576: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
13577: if (@todeleteimages) {
13578: map { $imgdeletions{$_} = 1; } @todeleteimages;
13579: }
13580: my $maxnum = $env{'form.'.$type.'_maxnum'};
13581: for (my $i=0; $i<=$maxnum; $i++) {
13582: my $itemid = $env{'form.'.$type.'_id_'.$i};
13583: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13584: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13585: if ($deletions{$key}) {
13586: if ($domconfig{$action}{$type}{$key}{'image'}) {
13587: #FIXME need to obsolete item in RES space
13588: }
13589: next;
13590: } else {
13591: my $newpos = $env{'form.'.$itemid};
13592: $newpos =~ s/\D+//g;
1.243 raeburn 13593: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13594: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13595: ($type eq 'templates'));
1.242 raeburn 13596: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13597: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13598: $changes{$type}{$key} = 1;
13599: }
13600: }
13601: $allpos{$type}[$newpos] = $key;
13602: }
13603: if ($imgdeletions{$key}) {
13604: $changes{$type}{$key} = 1;
1.216 raeburn 13605: #FIXME need to obsolete item in RES space
1.242 raeburn 13606: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13607: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13608: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13609: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13610: } else {
13611: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13612: $cdom,$cnum,$type,$configuserok,
13613: $switchserver,$author_ok);
13614: if ($imgurl) {
13615: $confhash{$type}{$key}{'image'} = $imgurl;
13616: $changes{$type}{$key} = 1;
13617: }
13618: if ($error) {
13619: &Apache::lonnet::logthis($error);
13620: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13621: }
13622: }
1.242 raeburn 13623: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13624: $confhash{$type}{$key}{'image'} =
13625: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13626: }
13627: }
13628: }
13629: }
13630: }
13631: }
1.102 raeburn 13632: } else {
1.144 raeburn 13633: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13634: $changes{'notify'}{'approval'} = 1;
13635: }
1.218 raeburn 13636: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13637: $changes{'uniquecode'} = 1;
13638: }
13639: }
13640: if ($context eq 'requestcourses') {
1.242 raeburn 13641: foreach my $type ('textbooks','templates') {
13642: if ($newbook{$type}) {
13643: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13644: foreach my $item ('subject','title','publisher','author') {
13645: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13646: ($type eq 'template'));
1.242 raeburn 13647: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13648: if ($env{'form.'.$type.'_addbook_'.$item}) {
13649: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13650: }
13651: }
13652: if ($type eq 'textbooks') {
13653: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13654: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13655: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13656: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13657: } else {
13658: my ($imageurl,$error) =
13659: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13660: $configuserok,$switchserver,$author_ok);
13661: if ($imageurl) {
13662: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13663: }
13664: if ($error) {
13665: &Apache::lonnet::logthis($error);
13666: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13667: }
1.242 raeburn 13668: }
13669: }
1.216 raeburn 13670: }
13671: }
1.242 raeburn 13672: if (@{$allpos{$type}} > 0) {
13673: my $idx = 0;
13674: foreach my $item (@{$allpos{$type}}) {
13675: if ($item ne '') {
13676: $confhash{$type}{$item}{'order'} = $idx;
13677: if (ref($domconfig{$action}) eq 'HASH') {
13678: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13679: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13680: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13681: $changes{$type}{$item} = 1;
13682: }
1.216 raeburn 13683: }
13684: }
13685: }
1.242 raeburn 13686: $idx ++;
1.216 raeburn 13687: }
13688: }
13689: }
13690: }
1.235 raeburn 13691: if (ref($validationitemsref) eq 'ARRAY') {
13692: foreach my $item (@{$validationitemsref}) {
13693: if ($item eq 'fields') {
13694: my @changed;
13695: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13696: if (@{$confhash{'validation'}{$item}} > 0) {
13697: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13698: }
1.266 raeburn 13699: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13700: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13701: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13702: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13703: $domconfig{'requestcourses'}{'validation'}{$item});
13704: } else {
13705: @changed = @{$confhash{'validation'}{$item}};
13706: }
1.235 raeburn 13707: } else {
13708: @changed = @{$confhash{'validation'}{$item}};
13709: }
13710: } else {
13711: @changed = @{$confhash{'validation'}{$item}};
13712: }
13713: if (@changed) {
13714: if ($confhash{'validation'}{$item}) {
13715: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13716: } else {
13717: $changes{'validation'}{$item} = &mt('None');
13718: }
13719: }
13720: } else {
13721: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13722: if ($item eq 'markup') {
13723: if ($env{'form.requestcourses_validation_'.$item}) {
13724: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13725: }
13726: }
1.266 raeburn 13727: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13728: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13729: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13730: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13731: }
13732: } else {
13733: if ($confhash{'validation'}{$item} ne '') {
13734: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13735: }
1.235 raeburn 13736: }
13737: } else {
13738: if ($confhash{'validation'}{$item} ne '') {
13739: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13740: }
13741: }
13742: }
13743: }
13744: }
13745: if ($env{'form.validationdc'}) {
13746: my $newval = $env{'form.validationdc'};
1.285 raeburn 13747: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13748: if (exists($domcoords{$newval})) {
13749: $confhash{'validation'}{'dc'} = $newval;
13750: }
13751: }
13752: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13753: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13754: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13755: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13756: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13757: if ($confhash{'validation'}{'dc'} eq '') {
13758: $changes{'validation'}{'dc'} = &mt('None');
13759: } else {
13760: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13761: }
1.235 raeburn 13762: }
1.266 raeburn 13763: } elsif ($confhash{'validation'}{'dc'} ne '') {
13764: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13765: }
13766: } elsif ($confhash{'validation'}{'dc'} ne '') {
13767: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13768: }
13769: } elsif ($confhash{'validation'}{'dc'} ne '') {
13770: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13771: }
1.266 raeburn 13772: } else {
13773: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13774: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13775: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13776: $changes{'validation'}{'dc'} = &mt('None');
13777: }
13778: }
1.235 raeburn 13779: }
13780: }
1.102 raeburn 13781: }
13782: } else {
1.86 raeburn 13783: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13784: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13785: }
1.72 raeburn 13786: foreach my $item (@usertools) {
13787: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13788: my $unset;
1.101 raeburn 13789: if ($context eq 'requestcourses') {
1.104 raeburn 13790: $unset = '0';
13791: if ($type eq '_LC_adv') {
13792: $unset = '';
13793: }
1.101 raeburn 13794: if ($confhash{$item}{$type} eq 'autolimit') {
13795: $confhash{$item}{$type} .= '=';
13796: unless ($limithash{$item}{$type} =~ /\D/) {
13797: $confhash{$item}{$type} .= $limithash{$item}{$type};
13798: }
13799: }
1.163 raeburn 13800: } elsif ($context eq 'requestauthor') {
13801: $unset = '0';
13802: if ($type eq '_LC_adv') {
13803: $unset = '';
13804: }
1.72 raeburn 13805: } else {
1.101 raeburn 13806: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13807: $confhash{$item}{$type} = 1;
13808: } else {
13809: $confhash{$item}{$type} = 0;
13810: }
1.72 raeburn 13811: }
1.86 raeburn 13812: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13813: if ($action eq 'requestauthor') {
13814: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13815: $changes{$type} = 1;
13816: }
13817: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13818: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13819: $changes{$item}{$type} = 1;
13820: }
13821: } else {
13822: if ($context eq 'requestcourses') {
1.104 raeburn 13823: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13824: $changes{$item}{$type} = 1;
13825: }
13826: } else {
13827: if (!$confhash{$item}{$type}) {
13828: $changes{$item}{$type} = 1;
13829: }
13830: }
13831: }
13832: } else {
13833: if ($context eq 'requestcourses') {
1.104 raeburn 13834: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13835: $changes{$item}{$type} = 1;
13836: }
1.163 raeburn 13837: } elsif ($context eq 'requestauthor') {
13838: if ($confhash{$type} ne $unset) {
13839: $changes{$type} = 1;
13840: }
1.72 raeburn 13841: } else {
13842: if (!$confhash{$item}{$type}) {
13843: $changes{$item}{$type} = 1;
13844: }
13845: }
13846: }
1.1 raeburn 13847: }
13848: }
1.163 raeburn 13849: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13850: if (ref($domconfig{'quotas'}) eq 'HASH') {
13851: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13852: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13853: if (exists($confhash{'defaultquota'}{$key})) {
13854: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13855: $changes{'defaultquota'}{$key} = 1;
13856: }
13857: } else {
13858: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13859: }
13860: }
1.86 raeburn 13861: } else {
13862: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13863: if (exists($confhash{'defaultquota'}{$key})) {
13864: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13865: $changes{'defaultquota'}{$key} = 1;
13866: }
13867: } else {
13868: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13869: }
1.1 raeburn 13870: }
13871: }
1.197 raeburn 13872: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13873: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13874: if (exists($confhash{'authorquota'}{$key})) {
13875: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13876: $changes{'authorquota'}{$key} = 1;
13877: }
13878: } else {
13879: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13880: }
13881: }
13882: }
1.1 raeburn 13883: }
1.86 raeburn 13884: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13885: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13886: if (ref($domconfig{'quotas'}) eq 'HASH') {
13887: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13888: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13889: $changes{'defaultquota'}{$key} = 1;
13890: }
13891: } else {
13892: if (!exists($domconfig{'quotas'}{$key})) {
13893: $changes{'defaultquota'}{$key} = 1;
13894: }
1.72 raeburn 13895: }
13896: } else {
1.86 raeburn 13897: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13898: }
1.1 raeburn 13899: }
13900: }
1.197 raeburn 13901: if (ref($confhash{'authorquota'}) eq 'HASH') {
13902: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13903: if (ref($domconfig{'quotas'}) eq 'HASH') {
13904: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13905: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13906: $changes{'authorquota'}{$key} = 1;
13907: }
13908: } else {
13909: $changes{'authorquota'}{$key} = 1;
13910: }
13911: } else {
13912: $changes{'authorquota'}{$key} = 1;
13913: }
13914: }
13915: }
1.1 raeburn 13916: }
1.72 raeburn 13917:
1.163 raeburn 13918: if ($context eq 'requestauthor') {
13919: $domdefaults{'requestauthor'} = \%confhash;
13920: } else {
13921: foreach my $key (keys(%confhash)) {
1.242 raeburn 13922: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13923: $domdefaults{$key} = $confhash{$key};
13924: }
1.163 raeburn 13925: }
1.72 raeburn 13926: }
1.163 raeburn 13927:
1.1 raeburn 13928: my %quotahash = (
1.86 raeburn 13929: $action => { %confhash }
1.1 raeburn 13930: );
13931: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13932: $dom);
13933: if ($putresult eq 'ok') {
13934: if (keys(%changes) > 0) {
1.72 raeburn 13935: my $cachetime = 24*60*60;
13936: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13937: if (ref($lastactref) eq 'HASH') {
13938: $lastactref->{'domdefaults'} = 1;
13939: }
1.1 raeburn 13940: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13941: unless (($context eq 'requestcourses') ||
1.163 raeburn 13942: ($context eq 'requestauthor')) {
1.86 raeburn 13943: if (ref($changes{'defaultquota'}) eq 'HASH') {
13944: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13945: foreach my $type (@{$types},'default') {
13946: if (defined($changes{'defaultquota'}{$type})) {
13947: my $typetitle = $usertypes->{$type};
13948: if ($type eq 'default') {
13949: $typetitle = $othertitle;
13950: }
1.213 raeburn 13951: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13952: }
13953: }
1.86 raeburn 13954: $resulttext .= '</ul></li>';
1.72 raeburn 13955: }
1.197 raeburn 13956: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13957: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13958: foreach my $type (@{$types},'default') {
13959: if (defined($changes{'authorquota'}{$type})) {
13960: my $typetitle = $usertypes->{$type};
13961: if ($type eq 'default') {
13962: $typetitle = $othertitle;
13963: }
1.213 raeburn 13964: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13965: }
13966: }
13967: $resulttext .= '</ul></li>';
13968: }
1.72 raeburn 13969: }
1.80 raeburn 13970: my %newenv;
1.72 raeburn 13971: foreach my $item (@usertools) {
1.163 raeburn 13972: my (%haschgs,%inconf);
13973: if ($context eq 'requestauthor') {
13974: %haschgs = %changes;
1.210 raeburn 13975: %inconf = %confhash;
1.163 raeburn 13976: } else {
13977: if (ref($changes{$item}) eq 'HASH') {
13978: %haschgs = %{$changes{$item}};
13979: }
13980: if (ref($confhash{$item}) eq 'HASH') {
13981: %inconf = %{$confhash{$item}};
13982: }
13983: }
13984: if (keys(%haschgs) > 0) {
1.80 raeburn 13985: my $newacc =
13986: &Apache::lonnet::usertools_access($env{'user.name'},
13987: $env{'user.domain'},
1.86 raeburn 13988: $item,'reload',$context);
1.210 raeburn 13989: if (($context eq 'requestcourses') ||
1.163 raeburn 13990: ($context eq 'requestauthor')) {
1.108 raeburn 13991: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13992: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13993: }
13994: } else {
13995: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13996: $newenv{'environment.availabletools.'.$item} = $newacc;
13997: }
1.80 raeburn 13998: }
1.163 raeburn 13999: unless ($context eq 'requestauthor') {
14000: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14001: }
1.72 raeburn 14002: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14003: if ($haschgs{$type}) {
1.72 raeburn 14004: my $typetitle = $usertypes->{$type};
14005: if ($type eq 'default') {
14006: $typetitle = $othertitle;
14007: } elsif ($type eq '_LC_adv') {
14008: $typetitle = 'LON-CAPA Advanced Users';
14009: }
1.163 raeburn 14010: if ($inconf{$type}) {
1.101 raeburn 14011: if ($context eq 'requestcourses') {
14012: my $cond;
1.163 raeburn 14013: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14014: if ($1 eq '') {
14015: $cond = &mt('(Automatic processing of any request).');
14016: } else {
14017: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14018: }
14019: } else {
1.163 raeburn 14020: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14021: }
14022: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14023: } elsif ($context eq 'requestauthor') {
14024: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14025: $titles{$inconf{$type}},$typetitle);
14026:
1.101 raeburn 14027: } else {
14028: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14029: }
1.72 raeburn 14030: } else {
1.104 raeburn 14031: if ($type eq '_LC_adv') {
1.163 raeburn 14032: if ($inconf{$type} eq '0') {
1.104 raeburn 14033: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14034: } else {
14035: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14036: }
14037: } else {
14038: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14039: }
1.72 raeburn 14040: }
14041: }
1.26 raeburn 14042: }
1.163 raeburn 14043: unless ($context eq 'requestauthor') {
14044: $resulttext .= '</ul></li>';
14045: }
1.26 raeburn 14046: }
1.1 raeburn 14047: }
1.163 raeburn 14048: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14049: if (ref($changes{'notify'}) eq 'HASH') {
14050: if ($changes{'notify'}{'approval'}) {
14051: if (ref($confhash{'notify'}) eq 'HASH') {
14052: if ($confhash{'notify'}{'approval'}) {
14053: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14054: } else {
1.163 raeburn 14055: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14056: }
14057: }
14058: }
14059: }
14060: }
1.216 raeburn 14061: if ($action eq 'requestcourses') {
14062: my @offon = ('off','on');
14063: if ($changes{'uniquecode'}) {
1.218 raeburn 14064: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14065: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14066: $resulttext .= '<li>'.
14067: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14068: '</li>';
14069: } else {
14070: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14071: '</li>';
14072: }
1.216 raeburn 14073: }
1.242 raeburn 14074: foreach my $type ('textbooks','templates') {
14075: if (ref($changes{$type}) eq 'HASH') {
14076: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14077: foreach my $key (sort(keys(%{$changes{$type}}))) {
14078: my %coursehash = &Apache::lonnet::coursedescription($key);
14079: my $coursetitle = $coursehash{'description'};
14080: my $position = $confhash{$type}{$key}{'order'} + 1;
14081: $resulttext .= '<li>';
1.243 raeburn 14082: foreach my $item ('subject','title','publisher','author') {
14083: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14084: ($type eq 'templates'));
1.242 raeburn 14085: my $name = $item.':';
14086: $name =~ s/^(\w)/\U$1/;
14087: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14088: }
14089: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14090: if ($type eq 'textbooks') {
14091: if ($confhash{$type}{$key}{'image'}) {
14092: $resulttext .= ' '.&mt('Image: [_1]',
14093: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14094: ' alt="Textbook cover" />').'<br />';
14095: }
14096: }
14097: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14098: }
1.242 raeburn 14099: $resulttext .= '</ul></li>';
1.216 raeburn 14100: }
14101: }
1.235 raeburn 14102: if (ref($changes{'validation'}) eq 'HASH') {
14103: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14104: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14105: foreach my $item (@{$validationitemsref}) {
14106: if (exists($changes{'validation'}{$item})) {
14107: if ($item eq 'markup') {
14108: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14109: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14110: } else {
14111: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14112: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14113: }
14114: }
14115: }
14116: if (exists($changes{'validation'}{'dc'})) {
14117: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14118: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14119: }
14120: }
14121: }
1.216 raeburn 14122: }
1.1 raeburn 14123: $resulttext .= '</ul>';
1.80 raeburn 14124: if (keys(%newenv)) {
14125: &Apache::lonnet::appenv(\%newenv);
14126: }
1.1 raeburn 14127: } else {
1.86 raeburn 14128: if ($context eq 'requestcourses') {
14129: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14130: } elsif ($context eq 'requestauthor') {
14131: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14132: } else {
1.90 weissno 14133: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14134: }
1.1 raeburn 14135: }
14136: } else {
1.11 albertel 14137: $resulttext = '<span class="LC_error">'.
14138: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14139: }
1.216 raeburn 14140: if ($errors) {
14141: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14142: '<ul>'.$errors.'</ul></p>';
14143: }
1.3 raeburn 14144: return $resulttext;
1.1 raeburn 14145: }
14146:
1.216 raeburn 14147: sub process_textbook_image {
1.242 raeburn 14148: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14149: my $filename = $env{'form.'.$caller.'.filename'};
14150: my ($error,$url);
14151: my ($width,$height) = (50,50);
14152: if ($configuserok eq 'ok') {
14153: if ($switchserver) {
14154: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14155: $switchserver);
14156: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14157: my $modified = [];
1.216 raeburn 14158: my ($result,$imageurl) =
1.421 raeburn 14159: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14160: "$type/$cdom/$cnum/cover",$width,$height,
14161: '',$modified);
1.216 raeburn 14162: if ($result eq 'ok') {
14163: $url = $imageurl;
1.421 raeburn 14164: &update_modify_urls($r,$modified);
1.216 raeburn 14165: } else {
14166: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14167: }
14168: } else {
14169: $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);
14170: }
14171: } else {
14172: $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);
14173: }
14174: return ($url,$error);
14175: }
14176:
1.267 raeburn 14177: sub modify_ltitools {
14178: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14179: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14180: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14181:
1.267 raeburn 14182: my $confname = $dom.'-domainconfig';
14183: my $servadm = $r->dir_config('lonAdmEMail');
14184: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14185:
14186: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14187: my $toolserror =
14188: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14189: $lastactref,$configuserok,$switchserver,$author_ok);
14190:
14191: my $home = &Apache::lonnet::domain($dom,'primary');
14192: unless (($home eq 'no_host') || ($home eq '')) {
14193: my @ids=&Apache::lonnet::current_machine_ids();
14194: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14195: }
14196:
14197: if (keys(%ltitoolschg)) {
14198: foreach my $id (keys(%ltitoolschg)) {
14199: if (ref($ltitoolschg{$id}) eq 'HASH') {
14200: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14201: if (($inner eq 'secret') || ($inner eq 'key')) {
14202: if ($is_home) {
14203: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14204: }
14205: }
14206: }
1.267 raeburn 14207: }
1.421 raeburn 14208: }
14209: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14210: if (keys(%ltitoolschg)) {
14211: %newltitools = %ltitoolschg;
14212: }
14213: }
14214: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14215: foreach my $id (%{$domconfig{'ltitools'}}) {
14216: next if ($id !~ /^\d+$/);
14217: unless (exists($ltitoolschg{$id})) {
14218: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14219: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14220: if (($inner eq 'secret') || ($inner eq 'key')) {
14221: if ($is_home) {
14222: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14223: }
14224: } else {
14225: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14226: }
14227: }
14228: } else {
14229: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14230: }
1.421 raeburn 14231: }
14232: }
14233: }
14234: if ($toolserror) {
14235: $errors = '<li>'.$toolserror.'</li>';
14236: }
14237: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14238: $resulttext = &mt('No changes made.');
14239: if ($errors) {
14240: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14241: $errors.'</ul>';
14242: }
14243: return $resulttext;
14244: }
14245: my %ltitoolshash = (
14246: $action => { %newltitools }
14247: );
14248: if (keys(%secchanges)) {
14249: $ltitoolshash{'toolsec'} = \%newtoolsec;
14250: }
14251: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14252: if ($putresult eq 'ok') {
14253: my %keystore;
14254: if ($is_home) {
14255: my %toolsenchash = (
14256: $action => { %newtoolsenc }
14257: );
14258: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 ! raeburn 14259: my $cachetime = 24*60*60;
! 14260: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14261: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14262: }
14263: $resulttext = &mt('Changes made:').'<ul>';
14264: if (keys(%secchanges) > 0) {
1.423 ! raeburn 14265: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14266: }
14267: if (keys(%ltitoolschg) > 0) {
14268: $resulttext .= $ltitoolsoutput;
14269: }
1.423 ! raeburn 14270: my $cachetime = 24*60*60;
! 14271: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
! 14272: if (ref($lastactref) eq 'HASH') {
! 14273: $lastactref->{'ltitools'} = 1;
! 14274: }
1.421 raeburn 14275: } else {
14276: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14277: }
14278: if ($errors) {
14279: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14280: $errors.'</ul></p>';
14281: }
14282: return $resulttext;
14283: }
14284:
14285: sub fetch_secrets {
14286: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14287: my %keyset;
14288: %{$currsec} = ();
14289: $newsec->{'private'}{'keys'} = [];
14290: $newsec->{'encrypt'} = {};
14291: $newsec->{'rules'} = {};
14292: if ($context eq 'ltisec') {
14293: $newsec->{'linkprot'} = {};
14294: }
14295: if (ref($domconfig->{$context}) eq 'HASH') {
14296: %{$currsec} = %{$domconfig->{$context}};
14297: if ($context eq 'ltisec') {
14298: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14299: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14300: unless ($id =~ /^\d+$/) {
14301: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14302: }
1.267 raeburn 14303: }
14304: }
1.421 raeburn 14305: }
14306: if (ref($currsec->{'private'}) eq 'HASH') {
14307: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14308: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14309: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14310: }
1.421 raeburn 14311: }
14312: }
14313: my @items= ('crs','dom');
14314: if ($context eq 'ltisec') {
14315: push(@items,'consumers');
14316: }
14317: foreach my $item (@items) {
14318: my $formelement;
14319: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14320: $formelement = 'form.'.$context.'_'.$item;
14321: } else {
14322: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14323: }
14324: if ($env{$formelement}) {
14325: $newsec->{'encrypt'}{$item} = 1;
14326: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14327: unless ($currsec->{'encrypt'}{$item}) {
14328: $secchanges->{'encrypt'} = 1;
14329: }
14330: } else {
14331: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14332: }
1.421 raeburn 14333: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14334: if ($currsec->{'encrypt'}{$item}) {
14335: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14336: }
1.421 raeburn 14337: }
14338: }
14339: my $secrets;
14340: if ($context eq 'ltisec') {
14341: $secrets = 'ltisecrets';
14342: } else {
14343: $secrets = 'toolsecrets';
14344: }
14345: unless (exists($currsec->{'rules'})) {
14346: $currsec->{'rules'} = {};
14347: }
14348: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14349:
14350: my @ids=&Apache::lonnet::current_machine_ids();
14351: my %servers = &Apache::lonnet::get_servers($dom,'library');
14352:
14353: foreach my $hostid (keys(%servers)) {
14354: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14355: my $newkey;
14356: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
14357: if (exists($env{$keyitem})) {
14358: $env{$keyitem} =~ s/(`)/'/g;
14359: if ($keyset{$hostid}) {
14360: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
14361: if ($env{$keyitem} ne '') {
14362: $secchanges->{'private'} = 1;
14363: $newkeyset->{$hostid} = $env{$keyitem};
14364: }
1.296 raeburn 14365: }
1.421 raeburn 14366: } elsif ($env{$keyitem} ne '') {
14367: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
14368: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14369: }
1.421 raeburn 14370: $secchanges->{'private'} = 1;
14371: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14372: }
14373: }
1.421 raeburn 14374: }
14375: }
14376: }
14377:
14378: sub store_security {
14379: my ($dom,$context,$secchanges,$newkeyset,$keystore,$lastactref) = @_;
14380: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
14381: (ref($keystore) eq 'HASH'));
14382: if (keys(%{$secchanges})) {
14383: if ($secchanges->{'private'}) {
14384: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
14385: foreach my $hostid (keys(%{$newkeyset})) {
14386: my $storehash = {
14387: key => $newkeyset->{$hostid},
14388: who => $env{'user.name'}.':'.$env{'user.domain'},
14389: };
14390: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
14391: $dom,$hostid);
14392: }
14393: }
14394: if (ref($lastactref) eq 'HASH') {
14395: if (($secchanges->{'encrypt'}) || ($secchanges->{'private'})) {
14396: $lastactref->{'domdefaults'} = 1;
14397: }
14398: }
14399: }
14400: }
14401:
14402: sub lti_security_results {
1.423 ! raeburn 14403: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 14404: my $output;
1.423 ! raeburn 14405: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 14406: my $needs_update;
1.421 raeburn 14407: foreach my $item (keys(%{$secchanges})) {
14408: if ($item eq 'encrypt') {
1.423 ! raeburn 14409: $needs_update = 1;
1.421 raeburn 14410: my %encrypted;
14411: if ($context eq 'lti') {
14412: %encrypted = (
14413: crs => {
14414: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
14415: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
14416: },
14417: dom => {
14418: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
14419: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
14420: },
14421: consumers => {
14422: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
14423: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
14424: },
14425: );
1.267 raeburn 14426: } else {
1.421 raeburn 14427: %encrypted = (
14428: crs => {
14429: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
14430: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
14431: },
14432: dom => {
14433: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
14434: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
14435: },
14436: );
14437:
14438: }
14439: my @types= ('crs','dom');
14440: if ($context eq 'lti') {
1.423 ! raeburn 14441: foreach my $type (@types) {
! 14442: undef($domdefaults{'linkprotenc_'.$type});
! 14443: }
1.421 raeburn 14444: push(@types,'consumers');
1.423 ! raeburn 14445: undef($domdefaults{'ltienc_consumers'});
! 14446: } elsif ($context eq 'ltitools') {
! 14447: foreach my $type (@types) {
! 14448: undef($domdefaults{'toolenc_'.$type});
! 14449: }
1.267 raeburn 14450: }
1.421 raeburn 14451: foreach my $type (@types) {
14452: my $shown = $encrypted{$type}{'off'};
14453: if (ref($newsec->{$item}) eq 'HASH') {
14454: if ($newsec->{$item}{$type}) {
1.423 ! raeburn 14455: if ($context eq 'lti') {
! 14456: if ($type eq 'consumers') {
! 14457: $domdefaults{'ltienc_consumers'} = 1;
! 14458: } else {
! 14459: $domdefaults{'linkprotenc_'.$type} = 1;
! 14460: }
! 14461: } elsif ($context eq 'ltitools') {
! 14462: $domdefaults{'toolenc_'.$type} = 1;
! 14463: }
1.421 raeburn 14464: $shown = $encrypted{$type}{'on'};
1.319 raeburn 14465: }
1.267 raeburn 14466: }
1.421 raeburn 14467: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 14468: }
1.421 raeburn 14469: } elsif ($item eq 'rules') {
14470: my %titles = &Apache::lonlocal::texthash(
14471: min => 'Minimum password length',
14472: max => 'Maximum password length',
14473: chars => 'Required characters',
14474: );
14475: foreach my $rule ('min','max') {
14476: if ($newsec->{rules}{$rule} eq '') {
14477: if ($rule eq 'min') {
14478: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
14479: ' '.&mt('Default of [_1] will be used',
14480: $Apache::lonnet::passwdmin).'</li>';
14481: } else {
14482: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14483: }
14484: } else {
14485: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
14486: }
14487: }
14488: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
14489: if (@{$newsec->{'rules'}{'chars'}} > 0) {
14490: my %rulenames = &Apache::lonlocal::texthash(
14491: uc => 'At least one upper case letter',
14492: lc => 'At least one lower case letter',
14493: num => 'At least one number',
14494: spec => 'At least one non-alphanumeric',
14495: );
14496: my $needed = '<ul><li>'.
14497: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
14498: '</li></ul>';
14499: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14500: } else {
14501: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 14502: }
1.421 raeburn 14503: } else {
14504: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 14505: }
1.421 raeburn 14506: } elsif ($item eq 'private') {
1.423 ! raeburn 14507: $needs_update = 1;
! 14508: if ($context eq 'lti') {
! 14509: undef($domdefaults{'ltiprivhosts'});
! 14510: } elsif ($context eq 'ltitools') {
! 14511: undef($domdefaults{'toolprivhosts'});
! 14512: }
1.421 raeburn 14513: if (keys(%{$newkeyset})) {
1.423 ! raeburn 14514: my @privhosts;
1.421 raeburn 14515: foreach my $hostid (sort(keys(%{$newkeyset}))) {
14516: if ($keystore->{$hostid} eq 'ok') {
14517: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 ! raeburn 14518: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
! 14519: push(@privhosts,$hostid);
! 14520: }
! 14521: }
! 14522: }
! 14523: if (@privhosts) {
! 14524: if ($context eq 'lti') {
! 14525: $domdefaults{'ltiprivhosts'} = \@privhosts;
! 14526: } elsif ($context eq 'ltitools') {
! 14527: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 14528: }
14529: }
14530: }
1.421 raeburn 14531: } elsif ($item eq 'linkprot') {
14532: next;
1.267 raeburn 14533: }
14534: }
1.423 ! raeburn 14535: if ($needs_update) {
! 14536: my $cachetime = 24*60*60;
! 14537: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 14538: }
1.421 raeburn 14539: return $output;
14540: }
14541:
14542: sub modify_proctoring {
14543: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14544: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14545: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14546: my $confname = $dom.'-domainconfig';
14547: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 14548: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14549: my %providernames = &proctoring_providernames();
14550: my $maxnum = scalar(keys(%providernames));
14551:
14552: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14553: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14554: if (ref($requref) eq 'HASH') {
14555: %requserfields = %{$requref};
14556: }
14557: if (ref($opturef) eq 'HASH') {
14558: %optuserfields = %{$opturef};
14559: }
14560: if (ref($defref) eq 'HASH') {
14561: %defaults = %{$defref};
14562: }
14563: if (ref($extref) eq 'HASH') {
14564: %extended = %{$extref};
14565: }
14566: if (ref($crsref) eq 'HASH') {
14567: %crsconf = %{$crsref};
14568: }
14569: if (ref($rolesref) eq 'ARRAY') {
14570: @courseroles = @{$rolesref};
14571: }
14572: if (ref($ltiref) eq 'ARRAY') {
14573: @ltiroles = @{$ltiref};
14574: }
14575:
14576: if (ref($domconfig{$action}) eq 'HASH') {
14577: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14578: if (@todeleteimages) {
14579: map { $imgdeletions{$_} = 1; } @todeleteimages;
14580: }
14581: }
14582: my %customadds;
14583: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14584: if (@newcustom) {
14585: map { $customadds{$_} = 1; } @newcustom;
14586: }
14587: foreach my $provider (sort(keys(%providernames))) {
14588: $confhash{$provider} = {};
14589: my $pos = $env{'form.proctoring_pos_'.$provider};
14590: $pos =~ s/\D+//g;
14591: $allpos[$pos] = $provider;
14592: my (%current,%currentenc);
14593: my $showroles = 0;
14594: if (ref($domconfig{$action}) eq 'HASH') {
14595: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14596: %current = %{$domconfig{$action}{$provider}};
14597: foreach my $item ('key','secret') {
14598: $currentenc{$item} = $current{$item};
14599: delete($current{$item});
14600: }
14601: }
14602: }
14603: if ($env{'form.proctoring_available_'.$provider}) {
14604: $confhash{$provider}{'available'} = 1;
14605: unless ($current{'available'}) {
14606: $changes{$provider} = 1;
14607: }
14608: } else {
14609: %{$confhash{$provider}} = %current;
14610: %{$encconfhash{$provider}} = %currentenc;
14611: $confhash{$provider}{'available'} = 0;
14612: if ($current{'available'}) {
14613: $changes{$provider} = 1;
14614: }
14615: }
14616: if ($confhash{$provider}{'available'}) {
14617: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14618: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14619: if ($field eq 'lifetime') {
14620: if ($possval =~ /^\d+$/) {
14621: $confhash{$provider}{$field} = $possval;
14622: }
14623: } elsif ($field eq 'version') {
14624: if ($possval =~ /^\d+\.\d+$/) {
14625: $confhash{$provider}{$field} = $possval;
14626: }
14627: } elsif ($field eq 'sigmethod') {
14628: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14629: $confhash{$provider}{$field} = $possval;
14630: }
14631: } elsif ($field eq 'url') {
14632: $confhash{$provider}{$field} = $possval;
14633: } elsif (($field eq 'key') || ($field eq 'secret')) {
14634: $encconfhash{$provider}{$field} = $possval;
14635: unless ($currentenc{$field} eq $possval) {
14636: $changes{$provider} = 1;
14637: }
14638: }
14639: unless (($field eq 'key') || ($field eq 'secret')) {
14640: unless ($current{$field} eq $confhash{$provider}{$field}) {
14641: $changes{$provider} = 1;
14642: }
14643: }
14644: }
14645: if ($imgdeletions{$provider}) {
14646: $changes{$provider} = 1;
14647: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14648: my ($imageurl,$error) =
14649: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14650: $configuserok,$switchserver,$author_ok);
14651: if ($imageurl) {
14652: $confhash{$provider}{'image'} = $imageurl;
14653: $changes{$provider} = 1;
14654: }
14655: if ($error) {
14656: &Apache::lonnet::logthis($error);
14657: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14658: }
14659: } elsif (exists($current{'image'})) {
14660: $confhash{$provider}{'image'} = $current{'image'};
14661: }
14662: if (ref($requserfields{$provider}) eq 'ARRAY') {
14663: if (@{$requserfields{$provider}} > 0) {
14664: if (grep(/^user$/,@{$requserfields{$provider}})) {
14665: if ($env{'form.proctoring_userincdom_'.$provider}) {
14666: $confhash{$provider}{'incdom'} = 1;
14667: }
14668: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14669: $changes{$provider} = 1;
14670: }
14671: }
14672: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14673: $showroles = 1;
14674: }
14675: }
14676: }
14677: $confhash{$provider}{'fields'} = [];
14678: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14679: if (@{$optuserfields{$provider}} > 0) {
14680: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14681: foreach my $field (@{$optuserfields{$provider}}) {
14682: if (grep(/^\Q$field\E$/,@optfields)) {
14683: push(@{$confhash{$provider}{'fields'}},$field);
14684: }
14685: }
14686: }
14687: if (ref($current{'fields'}) eq 'ARRAY') {
14688: unless ($changes{$provider}) {
14689: my @new = sort(@{$confhash{$provider}{'fields'}});
14690: my @old = sort(@{$current{'fields'}});
14691: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14692: if (@diffs) {
14693: $changes{$provider} = 1;
14694: }
14695: }
14696: } elsif (@{$confhash{$provider}{'fields'}}) {
14697: $changes{$provider} = 1;
14698: }
14699: }
14700: if (ref($defaults{$provider}) eq 'ARRAY') {
14701: if (@{$defaults{$provider}} > 0) {
14702: my %options;
14703: if (ref($extended{$provider}) eq 'HASH') {
14704: %options = %{$extended{$provider}};
14705: }
14706: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14707: foreach my $field (@{$defaults{$provider}}) {
14708: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14709: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14710: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14711: push(@{$confhash{$provider}{'defaults'}},$poss);
14712: }
14713: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14714: foreach my $inner (keys(%{$options{$field}})) {
14715: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14716: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14717: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14718: $confhash{$provider}{'defaults'}{$inner} = $poss;
14719: }
14720: } else {
14721: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14722: }
14723: }
14724: } else {
14725: if (grep(/^\Q$field\E$/,@checked)) {
14726: push(@{$confhash{$provider}{'defaults'}},$field);
14727: }
14728: }
14729: }
14730: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14731: if (ref($current{'defaults'}) eq 'ARRAY') {
14732: unless ($changes{$provider}) {
14733: my @new = sort(@{$confhash{$provider}{'defaults'}});
14734: my @old = sort(@{$current{'defaults'}});
14735: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14736: if (@diffs) {
14737: $changes{$provider} = 1;
14738: }
14739: }
14740: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14741: if (@{$current{'defaults'}}) {
14742: $changes{$provider} = 1;
14743: }
14744: }
14745: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14746: if (ref($current{'defaults'}) eq 'HASH') {
14747: unless ($changes{$provider}) {
14748: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14749: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14750: $changes{$provider} = 1;
14751: last;
14752: }
14753: }
14754: }
14755: unless ($changes{$provider}) {
14756: foreach my $key (keys(%{$current{'defaults'}})) {
14757: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14758: $changes{$provider} = 1;
14759: last;
14760: }
14761: }
14762: }
14763: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14764: $changes{$provider} = 1;
14765: }
14766: }
14767: }
14768: }
14769: if (ref($crsconf{$provider}) eq 'ARRAY') {
14770: if (@{$crsconf{$provider}} > 0) {
14771: $confhash{$provider}{'crsconf'} = [];
14772: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14773: foreach my $crsfield (@{$crsconf{$provider}}) {
14774: if (grep(/^\Q$crsfield\E$/,@checked)) {
14775: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14776: }
14777: }
14778: if (ref($current{'crsconf'}) eq 'ARRAY') {
14779: unless ($changes{$provider}) {
14780: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14781: my @old = sort(@{$current{'crsconf'}});
14782: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14783: if (@diffs) {
14784: $changes{$provider} = 1;
14785: }
14786: }
14787: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14788: $changes{$provider} = 1;
14789: }
14790: }
14791: }
14792: if ($showroles) {
14793: $confhash{$provider}{'roles'} = {};
14794: foreach my $role (@courseroles) {
14795: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14796: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14797: $confhash{$provider}{'roles'}{$role} = $poss;
14798: }
14799: }
14800: unless ($changes{$provider}) {
14801: if (ref($current{'roles'}) eq 'HASH') {
14802: foreach my $role (keys(%{$current{'roles'}})) {
14803: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14804: $changes{$provider} = 1;
14805: last
14806: }
14807: }
14808: unless ($changes{$provider}) {
14809: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14810: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14811: $changes{$provider} = 1;
14812: last;
14813: }
14814: }
14815: }
14816: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14817: $changes{$provider} = 1;
14818: }
14819: }
14820: }
14821: if (ref($current{'custom'}) eq 'HASH') {
14822: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14823: foreach my $key (keys(%{$current{'custom'}})) {
14824: if (grep(/^\Q$key\E$/,@customdels)) {
14825: $changes{$provider} = 1;
14826: } else {
14827: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14828: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14829: $changes{$provider} = 1;
14830: }
14831: }
14832: }
14833: }
14834: if ($customadds{$provider}) {
14835: my $name = $env{'form.proctoring_custom_name_'.$provider};
14836: $name =~ s/(`)/'/g;
14837: $name =~ s/^\s+//;
14838: $name =~ s/\s+$//;
14839: my $value = $env{'form.proctoring_custom_value_'.$provider};
14840: $value =~ s/(`)/'/g;
14841: $value =~ s/^\s+//;
14842: $value =~ s/\s+$//;
14843: if ($name ne '') {
14844: $confhash{$provider}{'custom'}{$name} = $value;
14845: $changes{$provider} = 1;
14846: }
14847: }
14848: }
14849: }
14850: if (@allpos > 0) {
14851: my $idx = 0;
14852: foreach my $provider (@allpos) {
14853: if ($provider ne '') {
14854: $confhash{$provider}{'order'} = $idx;
14855: unless ($changes{$provider}) {
14856: if (ref($domconfig{$action}) eq 'HASH') {
14857: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14858: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14859: $changes{$provider} = 1;
14860: }
14861: }
14862: }
14863: }
14864: $idx ++;
14865: }
14866: }
14867: }
14868: my %proc_hash = (
14869: $action => { %confhash }
14870: );
14871: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14872: $dom);
14873: if ($putresult eq 'ok') {
14874: my %proc_enchash = (
14875: $action => { %encconfhash }
14876: );
1.384 raeburn 14877: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14878: if (keys(%changes) > 0) {
14879: my $cachetime = 24*60*60;
14880: my %procall = %confhash;
14881: foreach my $provider (keys(%procall)) {
14882: if (ref($encconfhash{$provider}) eq 'HASH') {
14883: foreach my $key ('key','secret') {
14884: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14885: }
14886: }
14887: }
14888: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14889: if (ref($lastactref) eq 'HASH') {
14890: $lastactref->{'proctoring'} = 1;
14891: }
14892: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14893: my %bynum;
14894: foreach my $provider (sort(keys(%changes))) {
14895: my $position = $confhash{$provider}{'order'};
14896: $bynum{$position} = $provider;
14897: }
14898: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14899: my $provider = $bynum{$pos};
14900: my %lt = &proctoring_titles($provider);
14901: my %fieldtitles = &proctoring_fieldtitles($provider);
14902: if (!$confhash{$provider}{'available'}) {
14903: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14904: } else {
14905: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14906: if ($confhash{$provider}{'image'}) {
14907: $resulttext .= ' '.
14908: '<img src="'.$confhash{$provider}{'image'}.'"'.
14909: ' alt="'.&mt('Proctoring icon').'" />';
14910: }
14911: $resulttext .= '<ul>';
14912: my $position = $pos + 1;
14913: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14914: foreach my $key ('version','sigmethod','url','lifetime') {
14915: if ($confhash{$provider}{$key} ne '') {
14916: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14917: }
14918: }
14919: if ($encconfhash{$provider}{'key'} ne '') {
14920: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14921: }
14922: if ($encconfhash{$provider}{'secret'} ne '') {
14923: $resulttext .= '<li>'.$lt{'secret'}.': ';
14924: my $num = length($encconfhash{$provider}{'secret'});
14925: $resulttext .= ('*'x$num).'</li>';
14926: }
14927: my (@fields,$showroles);
14928: if (ref($requserfields{$provider}) eq 'ARRAY') {
14929: push(@fields,@{$requserfields{$provider}});
14930: }
14931: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14932: push(@fields,@{$confhash{$provider}{'fields'}});
14933: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14934: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14935: }
14936: if (@fields) {
14937: if (grep(/^roles$/,@fields)) {
14938: $showroles = 1;
14939: }
14940: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14941: join('", "', map { $lt{$_}; } @fields).'"</li>';
14942: }
14943: if (ref($requserfields{$provider}) eq 'ARRAY') {
14944: if (grep(/^user$/,@{$requserfields{$provider}})) {
14945: if ($confhash{$provider}{'incdom'}) {
14946: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14947: } else {
14948: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14949: }
14950: }
14951: }
14952: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14953: if (@{$confhash{$provider}{'defaults'}} > 0) {
14954: $resulttext .= '<li>'.$lt{'defa'};
14955: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14956: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14957: }
14958: $resulttext =~ s/,$//;
14959: $resulttext .= '</li>';
14960: }
14961: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14962: if (keys(%{$confhash{$provider}{'defaults'}})) {
14963: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14964: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14965: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14966: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14967: }
14968: }
14969: $resulttext .= '</ul></li>';
14970: }
14971: }
14972: if (ref($crsconf{$provider}) eq 'ARRAY') {
14973: if (@{$crsconf{$provider}} > 0) {
14974: $resulttext .= '<li>'.&mt('Configurable in course:');
14975: my $numconfig = 0;
14976: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14977: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14978: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14979: $numconfig ++;
14980: if ($provider eq 'examity') {
14981: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14982: } else {
14983: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14984: }
14985: }
14986: $resulttext =~ s/,$//;
14987: }
14988: }
14989: if (!$numconfig) {
14990: $resulttext .= ' '.&mt('None');
14991: }
14992: $resulttext .= '</li>';
14993: }
14994: }
14995: if ($showroles) {
14996: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14997: my $rolemaps;
14998: foreach my $role (@courseroles) {
14999: if ($confhash{$provider}{'roles'}{$role}) {
15000: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15001: $confhash{$provider}{'roles'}{$role}.',';
15002: }
15003: }
15004: if ($rolemaps) {
15005: $rolemaps =~ s/,$//;
15006: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15007: }
15008: }
15009: }
15010: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15011: my $customlist;
15012: if (keys(%{$confhash{$provider}{'custom'}})) {
15013: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15014: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15015: }
15016: $customlist =~ s/,$//;
15017: }
15018: if ($customlist) {
15019: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15020: }
15021: }
15022: $resulttext .= '</ul></li>';
15023: }
15024: }
15025: $resulttext .= '</ul>';
15026: } else {
15027: $resulttext = &mt('No changes made.');
15028: }
15029: } else {
15030: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15031: }
15032: if ($errors) {
15033: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15034: $errors.'</ul>';
15035: }
15036: return $resulttext;
15037: }
15038:
15039: sub process_proctoring_image {
15040: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15041: my $filename = $env{'form.'.$caller.'.filename'};
15042: my ($error,$url);
15043: my ($width,$height) = (21,21);
15044: if ($configuserok eq 'ok') {
15045: if ($switchserver) {
15046: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15047: $switchserver);
15048: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15049: my $modified = [];
1.372 raeburn 15050: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15051: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15052: "proctoring/$provider/icon",$width,$height,
15053: '',$modified);
1.372 raeburn 15054: if ($result eq 'ok') {
15055: if ($madethumb) {
15056: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15057: my $imagethumb = "$path/tn-".$imagefile;
15058: $url = $imagethumb;
15059: } else {
15060: $url = $imageurl;
15061: }
1.421 raeburn 15062: &update_modify_urls($r,$modified);
1.372 raeburn 15063: } else {
15064: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15065: }
15066: } else {
15067: $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);
15068: }
15069: } else {
15070: $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);
15071: }
15072: return ($url,$error);
15073: }
15074:
1.320 raeburn 15075: sub modify_lti {
15076: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15077: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15078: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
15079: my (%posslti,%posslticrs,%posscrstype);
15080: my @courseroles = ('cc','in','ta','ep','st');
15081: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15082: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15083: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15084: my %coursetypetitles = &Apache::lonlocal::texthash (
15085: official => 'Official',
15086: unofficial => 'Unofficial',
15087: community => 'Community',
15088: textbook => 'Textbook',
15089: placement => 'Placement Test',
1.392 raeburn 15090: lti => 'LTI Provider',
1.320 raeburn 15091: );
1.325 raeburn 15092: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15093: my %lt = <i_names();
15094: map { $posslti{$_} = 1; } @ltiroles;
15095: map { $posslticrs{$_} = 1; } @lticourseroles;
15096: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15097:
1.326 raeburn 15098: my %menutitles = <imenu_titles();
1.421 raeburn 15099: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15100:
1.421 raeburn 15101: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15102:
1.406 raeburn 15103: my (%linkprotchg,$linkprotoutput,$is_home);
15104: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15105: \%linkprotchg,'domain');
15106: my $home = &Apache::lonnet::domain($dom,'primary');
15107: unless (($home eq 'no_host') || ($home eq '')) {
15108: my @ids=&Apache::lonnet::current_machine_ids();
15109: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15110: }
15111:
15112: if (keys(%linkprotchg)) {
15113: $secchanges{'linkprot'} = 1;
15114: my %oldlinkprot;
15115: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15116: %oldlinkprot = %{$currltisec{'linkprot'}};
15117: }
15118: foreach my $id (keys(%linkprotchg)) {
15119: if (ref($linkprotchg{$id}) eq 'HASH') {
15120: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15121: if (($inner eq 'secret') || ($inner eq 'key')) {
15122: if ($is_home) {
15123: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15124: }
15125: }
15126: }
15127: } else {
15128: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15129: }
15130: }
15131: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15132: if (keys(%linkprotchg)) {
15133: %{$newltisec{'linkprot'}} = %linkprotchg;
15134: }
15135: }
15136: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15137: foreach my $id (%{$currltisec{'linkprot'}}) {
15138: next if ($id !~ /^\d+$/);
15139: unless (exists($linkprotchg{$id})) {
15140: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15141: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15142: if (($inner eq 'secret') || ($inner eq 'key')) {
15143: if ($is_home) {
15144: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15145: }
15146: } else {
15147: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15148: }
15149: }
15150: } else {
15151: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15152: }
15153: }
15154: }
15155: }
15156: if ($proterror) {
15157: $errors .= '<li>'.$proterror.'</li>';
15158: }
1.320 raeburn 15159: my (@items,%deletions,%itemids);
15160: if ($env{'form.lti_add'}) {
15161: my $consumer = $env{'form.lti_consumer_add'};
15162: $consumer =~ s/(`)/'/g;
15163: ($newid,my $error) = &get_lti_id($dom,$consumer);
15164: if ($newid) {
15165: $itemids{'add'} = $newid;
15166: push(@items,'add');
15167: $changes{$newid} = 1;
15168: } else {
15169: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15170: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15171: }
15172: }
15173: if (ref($domconfig{$action}) eq 'HASH') {
15174: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15175: if (@todelete) {
15176: map { $deletions{$_} = 1; } @todelete;
15177: }
15178: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15179: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15180: my $itemid = $env{'form.lti_id_'.$i};
15181: $itemid =~ s/\D+//g;
15182: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15183: if ($deletions{$itemid}) {
15184: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15185: } else {
1.390 raeburn 15186: push(@items,$i);
15187: $itemids{$i} = $itemid;
1.320 raeburn 15188: }
15189: }
15190: }
15191: }
15192: foreach my $idx (@items) {
15193: my $itemid = $itemids{$idx};
15194: next unless ($itemid);
1.390 raeburn 15195: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15196: $position =~ s/\D+//g;
15197: if ($position ne '') {
15198: $allpos[$position] = $itemid;
15199: }
1.391 raeburn 15200: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 15201: my $formitem = 'form.lti_'.$item.'_'.$idx;
15202: $env{$formitem} =~ s/(`)/'/g;
15203: if ($item eq 'lifetime') {
15204: $env{$formitem} =~ s/[^\d.]//g;
15205: }
15206: if ($env{$formitem} ne '') {
15207: if (($item eq 'key') || ($item eq 'secret')) {
15208: $encconfig{$itemid}{$item} = $env{$formitem};
15209: } else {
15210: $confhash{$itemid}{$item} = $env{$formitem};
15211: unless (($idx eq 'add') || ($changes{$itemid})) {
15212: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
15213: $changes{$itemid} = 1;
15214: }
15215: }
15216: }
15217: }
15218: }
15219: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15220: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15221: }
1.345 raeburn 15222: if ($confhash{$itemid}{'requser'}) {
15223: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15224: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15225: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15226: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15227: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15228: my $mapuser = $env{'form.lti_customuser_'.$idx};
15229: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15230: $mapuser =~ s/^\s+|\s+$//g;
15231: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15232: }
15233: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15234: my @makeuser;
15235: foreach my $ltirole (sort(@possmakeuser)) {
15236: if ($posslti{$ltirole}) {
15237: push(@makeuser,$ltirole);
15238: }
15239: }
15240: $confhash{$itemid}{'makeuser'} = \@makeuser;
15241: if (@makeuser) {
15242: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15243: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15244: $confhash{$itemid}{'lcauth'} = $lcauth;
15245: if ($lcauth ne 'internal') {
15246: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15247: $lcauthparm =~ s/^(\s+|\s+)$//g;
15248: $lcauthparm =~ s/`//g;
15249: if ($lcauthparm ne '') {
15250: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15251: }
15252: }
15253: } else {
15254: $confhash{$itemid}{'lcauth'} = 'lti';
15255: }
1.320 raeburn 15256: }
1.345 raeburn 15257: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15258: if (@possinstdata) {
15259: foreach my $field (@possinstdata) {
15260: if (exists($fieldtitles{$field})) {
15261: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15262: }
15263: }
15264: }
1.363 raeburn 15265: if ($env{'form.lti_callback_'.$idx}) {
15266: if ($env{'form.lti_callbackparam_'.$idx}) {
15267: my $callback = $env{'form.lti_callbackparam_'.$idx};
15268: $callback =~ s/^\s+|\s+$//g;
15269: $confhash{$itemid}{'callback'} = $callback;
15270: }
15271: }
1.391 raeburn 15272: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15273: if ($env{'form.lti_'.$field.'_'.$idx}) {
15274: $confhash{$itemid}{$field} = 1;
15275: }
1.320 raeburn 15276: }
1.345 raeburn 15277: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15278: $confhash{$itemid}{lcmenu} = [];
15279: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15280: foreach my $field (@possmenu) {
15281: if (exists($menutitles{$field})) {
15282: if ($field eq 'grades') {
15283: next unless ($env{'form.lti_inlinemenu_'.$idx});
15284: }
15285: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15286: }
15287: }
15288: }
1.391 raeburn 15289: if ($confhash{$itemid}{'crsinc'}) {
15290: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15291: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15292: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15293: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15294: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15295: $mapcrs =~ s/(`)/'/g;
15296: $mapcrs =~ s/^\s+|\s+$//g;
15297: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15298: }
15299: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15300: my @crstypes;
15301: foreach my $type (sort(@posstypes)) {
15302: if ($posscrstype{$type}) {
15303: push(@crstypes,$type);
15304: }
15305: }
15306: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15307: if ($env{'form.lti_storecrs_'.$idx}) {
15308: $confhash{$itemid}{'storecrs'} = 1;
15309: }
1.391 raeburn 15310: if ($env{'form.lti_makecrs_'.$idx}) {
15311: $confhash{$itemid}{'makecrs'} = 1;
15312: }
15313: foreach my $ltirole (@lticourseroles) {
15314: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15315: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15316: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15317: }
15318: }
15319: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15320: my @selfenroll;
15321: foreach my $type (sort(@possenroll)) {
15322: if ($posslticrs{$type}) {
15323: push(@selfenroll,$type);
15324: }
15325: }
15326: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15327: if ($env{'form.lti_crssec_'.$idx}) {
15328: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15329: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15330: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15331: my $section = $env{'form.lti_customsection_'.$idx};
15332: $section =~ s/(`)/'/g;
15333: $section =~ s/^\s+|\s+$//g;
15334: if ($section ne '') {
15335: $confhash{$itemid}{'section'} = $section;
15336: }
15337: }
15338: }
15339: foreach my $field ('passback','roster') {
15340: if ($env{'form.lti_'.$field.'_'.$idx}) {
15341: $confhash{$itemid}{$field} = 1;
15342: }
15343: }
15344: if ($env{'form.lti_passback_'.$idx}) {
15345: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15346: $confhash{$itemid}{'passbackformat'} = '1.0';
15347: } else {
15348: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15349: }
15350: }
1.391 raeburn 15351: }
15352: unless (($idx eq 'add') || ($changes{$itemid})) {
15353: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15354: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 15355: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15356: $changes{$itemid} = 1;
15357: }
1.345 raeburn 15358: }
15359: unless ($changes{$itemid}) {
1.391 raeburn 15360: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
15361: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15362: $changes{$itemid} = 1;
15363: }
15364: }
1.345 raeburn 15365: }
1.391 raeburn 15366: foreach my $field ('mapcrstype','selfenroll') {
15367: unless ($changes{$itemid}) {
15368: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15369: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15370: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15371: $confhash{$itemid}{$field});
15372: if (@diffs) {
15373: $changes{$itemid} = 1;
15374: }
15375: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15376: $changes{$itemid} = 1;
15377: }
15378: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15379: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15380: $changes{$itemid} = 1;
15381: }
15382: }
1.391 raeburn 15383: }
15384: }
15385: unless ($changes{$itemid}) {
15386: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
15387: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15388: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
15389: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
15390: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15391: $changes{$itemid} = 1;
15392: last;
15393: }
15394: }
1.391 raeburn 15395: unless ($changes{$itemid}) {
15396: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15397: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
15398: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
15399: $changes{$itemid} = 1;
15400: last;
15401: }
15402: }
15403: }
15404: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
15405: $changes{$itemid} = 1;
1.345 raeburn 15406: }
1.391 raeburn 15407: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15408: unless ($changes{$itemid}) {
15409: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15410: $changes{$itemid} = 1;
15411: }
15412: }
15413: }
15414: }
15415: }
15416: unless ($changes{$itemid}) {
15417: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
15418: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15419: $changes{$itemid} = 1;
1.320 raeburn 15420: }
1.391 raeburn 15421: }
15422: unless ($changes{$itemid}) {
15423: foreach my $field ('makeuser','lcmenu') {
15424: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15425: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15426: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15427: $confhash{$itemid}{$field});
15428: if (@diffs) {
15429: $changes{$itemid} = 1;
15430: }
15431: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15432: $changes{$itemid} = 1;
15433: }
15434: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15435: if (@{$confhash{$itemid}{$field}} > 0) {
15436: $changes{$itemid} = 1;
15437: }
1.345 raeburn 15438: }
1.320 raeburn 15439: }
15440: }
15441: }
15442: }
15443: }
15444: }
15445: if (@allpos > 0) {
15446: my $idx = 0;
15447: foreach my $itemid (@allpos) {
15448: if ($itemid ne '') {
15449: $confhash{$itemid}{'order'} = $idx;
15450: if (ref($domconfig{$action}) eq 'HASH') {
15451: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15452: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15453: $changes{$itemid} = 1;
15454: }
15455: }
15456: }
15457: $idx ++;
15458: }
15459: }
15460: }
15461: my %ltihash = (
1.405 raeburn 15462: $action => { %confhash }
15463: );
1.406 raeburn 15464: my %ltienchash = (
15465: $action => { %encconfig }
15466: );
1.405 raeburn 15467: if (keys(%secchanges)) {
15468: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 15469: if ($secchanges{'linkprot'}) {
15470: if ($is_home) {
15471: $ltienchash{'linkprot'} = \%newltienc;
15472: }
15473: }
1.405 raeburn 15474: }
15475: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 15476: if ($putresult eq 'ok') {
1.405 raeburn 15477: my %keystore;
1.421 raeburn 15478: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore,$lastactref);
1.384 raeburn 15479: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 15480: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
15481: return &mt('No changes made.');
15482: }
15483: $resulttext = &mt('Changes made:').'<ul>';
15484: if (keys(%secchanges) > 0) {
1.423 ! raeburn 15485: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 15486: if (exists($secchanges{'linkprot'})) {
15487: $resulttext .= $linkprotoutput;
1.405 raeburn 15488: }
15489: }
1.320 raeburn 15490: if (keys(%changes) > 0) {
15491: my $cachetime = 24*60*60;
15492: my %ltiall = %confhash;
15493: foreach my $id (keys(%ltiall)) {
15494: if (ref($encconfig{$id}) eq 'HASH') {
15495: foreach my $item ('key','secret') {
15496: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15497: }
15498: }
15499: }
15500: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15501: if (ref($lastactref) eq 'HASH') {
15502: $lastactref->{'lti'} = 1;
15503: }
15504: my %bynum;
15505: foreach my $itemid (sort(keys(%changes))) {
15506: my $position = $confhash{$itemid}{'order'};
15507: $bynum{$position} = $itemid;
15508: }
15509: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15510: my $itemid = $bynum{$pos};
15511: if (ref($confhash{$itemid}) ne 'HASH') {
15512: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15513: } else {
1.390 raeburn 15514: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15515: my $position = $pos + 1;
15516: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15517: foreach my $item ('version','lifetime') {
15518: if ($confhash{$itemid}{$item} ne '') {
15519: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15520: }
15521: }
15522: if ($encconfig{$itemid}{'key'} ne '') {
15523: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15524: }
15525: if ($encconfig{$itemid}{'secret'} ne '') {
15526: $resulttext .= '<li>'.$lt{'secret'}.': ';
15527: my $num = length($encconfig{$itemid}{'secret'});
15528: $resulttext .= ('*'x$num).'</li>';
15529: }
1.345 raeburn 15530: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 15531: if ($confhash{$itemid}{'callback'}) {
15532: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15533: } else {
1.392 raeburn 15534: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 15535: }
1.345 raeburn 15536: if ($confhash{$itemid}{'mapuser'}) {
15537: my $shownmapuser;
15538: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15539: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15540: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15541: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15542: } else {
15543: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15544: }
1.345 raeburn 15545: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15546: }
1.345 raeburn 15547: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15548: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15549: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15550: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15551: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15552: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15553: } else {
15554: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15555: $confhash{$itemid}{'lcauth'});
15556: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15557: $resulttext .= '; '.&mt('a randomly generated password will be created');
15558: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15559: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15560: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15561: }
15562: } else {
15563: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15564: }
15565: }
15566: $resulttext .= '</li>';
15567: } else {
15568: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15569: }
1.320 raeburn 15570: }
1.345 raeburn 15571: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15572: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15573: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15574: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15575: } else {
1.345 raeburn 15576: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15577: }
1.320 raeburn 15578: }
1.391 raeburn 15579: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15580: $resulttext .= '<li>'.$lt{$item}.': ';
15581: if ($confhash{$itemid}{$item}) {
15582: $resulttext .= &mt('Yes');
15583: } else {
15584: $resulttext .= &mt('No');
1.337 raeburn 15585: }
1.345 raeburn 15586: $resulttext .= '</li>';
1.320 raeburn 15587: }
1.345 raeburn 15588: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15589: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15590: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 15591: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15592: } else {
15593: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15594: }
15595: }
15596: if ($confhash{$itemid}{'crsinc'}) {
15597: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15598: my $rolemaps;
15599: foreach my $role (@ltiroles) {
15600: if ($confhash{$itemid}{'maproles'}{$role}) {
15601: $rolemaps .= (' 'x2).$role.'='.
15602: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15603: 'Course').',';
15604: }
15605: }
15606: if ($rolemaps) {
15607: $rolemaps =~ s/,$//;
15608: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15609: }
15610: }
15611: if ($confhash{$itemid}{'mapcrs'}) {
15612: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15613: }
15614: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15615: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15616: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15617: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15618: '</li>';
15619: } else {
15620: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15621: }
15622: }
1.392 raeburn 15623: if ($confhash{$itemid}{'storecrs'}) {
15624: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
15625: }
1.391 raeburn 15626: if ($confhash{$itemid}{'makecrs'}) {
15627: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
15628: } else {
15629: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
15630: }
15631: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15632: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15633: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15634: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15635: '</li>';
15636: } else {
15637: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15638: }
15639: }
15640: if ($confhash{$itemid}{'section'}) {
15641: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15642: $resulttext .= '<li>'.&mt('User section from standard field:').
15643: ' (course_section_sourcedid)'.'</li>';
15644: } else {
15645: $resulttext .= '<li>'.&mt('User section from:').' '.
15646: $confhash{$itemid}{'section'}.'</li>';
15647: }
1.345 raeburn 15648: } else {
1.391 raeburn 15649: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
15650: }
15651: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15652: $resulttext .= '<li>'.$lt{$item}.': ';
15653: if ($confhash{$itemid}{$item}) {
15654: $resulttext .= &mt('Yes');
15655: if ($item eq 'passback') {
15656: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15657: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15658: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15659: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15660: }
15661: }
15662: } else {
15663: $resulttext .= &mt('No');
15664: }
15665: $resulttext .= '</li>';
15666: }
15667: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15668: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15669: $resulttext .= '<li>'.&mt('Menu items:').' '.
15670: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15671: } else {
15672: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15673: }
1.345 raeburn 15674: }
1.326 raeburn 15675: }
15676: }
1.320 raeburn 15677: $resulttext .= '</ul></li>';
15678: }
15679: }
15680: }
1.405 raeburn 15681: $resulttext .= '</ul>';
1.320 raeburn 15682: } else {
15683: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15684: }
15685: if ($errors) {
15686: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15687: $errors.'</ul>';
15688: }
15689: return $resulttext;
15690: }
15691:
15692: sub get_lti_id {
15693: my ($domain,$consumer) = @_;
15694: # get lock on lti db
15695: my $lockhash = {
15696: lock => $env{'user.name'}.
15697: ':'.$env{'user.domain'},
15698: };
15699: my $tries = 0;
15700: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15701: my ($id,$error);
15702:
15703: while (($gotlock ne 'ok') && ($tries<10)) {
15704: $tries ++;
15705: sleep (0.1);
15706: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15707: }
15708: if ($gotlock eq 'ok') {
15709: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15710: if ($currids{'lock'}) {
15711: delete($currids{'lock'});
15712: if (keys(%currids)) {
15713: my @curr = sort { $a <=> $b } keys(%currids);
15714: if ($curr[-1] =~ /^\d+$/) {
15715: $id = 1 + $curr[-1];
15716: }
15717: } else {
15718: $id = 1;
15719: }
15720: if ($id) {
15721: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15722: $error = 'nostore';
15723: }
15724: } else {
15725: $error = 'nonumber';
15726: }
15727: }
15728: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15729: } else {
15730: $error = 'nolock';
15731: }
15732: return ($id,$error);
15733: }
15734:
1.3 raeburn 15735: sub modify_autoenroll {
1.205 raeburn 15736: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15737: my ($resulttext,%changes);
15738: my %currautoenroll;
15739: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15740: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15741: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15742: }
15743: }
15744: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15745: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15746: sender => 'Sender for notification messages',
1.274 raeburn 15747: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 15748: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15749: my @offon = ('off','on');
1.17 raeburn 15750: my $sender_uname = $env{'form.sender_uname'};
15751: my $sender_domain = $env{'form.sender_domain'};
15752: if ($sender_domain eq '') {
15753: $sender_uname = '';
15754: } elsif ($sender_uname eq '') {
15755: $sender_domain = '';
15756: }
1.129 raeburn 15757: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 15758: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
15759: $autofailsafe =~ s{^\s+|\s+$}{}g;
15760: if ($autofailsafe =~ /\D/) {
15761: undef($autofailsafe);
15762: }
1.274 raeburn 15763: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 15764: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
15765: $failsafe = 'off';
1.400 raeburn 15766: undef($autofailsafe);
1.274 raeburn 15767: }
1.1 raeburn 15768: my %autoenrollhash = (
1.129 raeburn 15769: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15770: 'sender_uname' => $sender_uname,
15771: 'sender_domain' => $sender_domain,
15772: 'co-owners' => $coowners,
1.399 raeburn 15773: 'autofailsafe' => $autofailsafe,
1.400 raeburn 15774: 'failsafe' => $failsafe,
1.1 raeburn 15775: }
15776: );
1.4 raeburn 15777: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15778: $dom);
1.1 raeburn 15779: if ($putresult eq 'ok') {
15780: if (exists($currautoenroll{'run'})) {
15781: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15782: $changes{'run'} = 1;
15783: }
15784: } elsif ($autorun) {
15785: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15786: $changes{'run'} = 1;
1.1 raeburn 15787: }
15788: }
1.17 raeburn 15789: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15790: $changes{'sender'} = 1;
15791: }
1.17 raeburn 15792: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15793: $changes{'sender'} = 1;
15794: }
1.129 raeburn 15795: if ($currautoenroll{'co-owners'} ne '') {
15796: if ($currautoenroll{'co-owners'} ne $coowners) {
15797: $changes{'coowners'} = 1;
15798: }
15799: } elsif ($coowners) {
15800: $changes{'coowners'} = 1;
1.274 raeburn 15801: }
1.399 raeburn 15802: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 15803: $changes{'autofailsafe'} = 1;
15804: }
1.399 raeburn 15805: if ($currautoenroll{'failsafe'} ne $failsafe) {
15806: $changes{'failsafe'} = 1;
15807: }
1.1 raeburn 15808: if (keys(%changes) > 0) {
15809: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15810: if ($changes{'run'}) {
1.1 raeburn 15811: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15812: }
15813: if ($changes{'sender'}) {
1.17 raeburn 15814: if ($sender_uname eq '' || $sender_domain eq '') {
15815: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15816: } else {
15817: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15818: }
1.1 raeburn 15819: }
1.129 raeburn 15820: if ($changes{'coowners'}) {
15821: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15822: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15823: if (ref($lastactref) eq 'HASH') {
15824: $lastactref->{'domainconfig'} = 1;
15825: }
1.129 raeburn 15826: }
1.274 raeburn 15827: if ($changes{'autofailsafe'}) {
1.399 raeburn 15828: if ($autofailsafe ne '') {
15829: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 15830: } else {
1.399 raeburn 15831: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 15832: }
1.399 raeburn 15833: }
15834: if ($changes{'failsafe'}) {
15835: if ($failsafe eq 'off') {
15836: unless ($changes{'autofailsafe'}) {
15837: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
15838: }
15839: } elsif ($failsafe eq 'zero') {
15840: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
15841: } else {
15842: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
15843: }
15844: }
15845: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 15846: &Apache::lonnet::get_domain_defaults($dom,1);
15847: if (ref($lastactref) eq 'HASH') {
15848: $lastactref->{'domdefaults'} = 1;
15849: }
15850: }
1.1 raeburn 15851: $resulttext .= '</ul>';
15852: } else {
15853: $resulttext = &mt('No changes made to auto-enrollment settings');
15854: }
15855: } else {
1.11 albertel 15856: $resulttext = '<span class="LC_error">'.
15857: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15858: }
1.3 raeburn 15859: return $resulttext;
1.1 raeburn 15860: }
15861:
15862: sub modify_autoupdate {
1.3 raeburn 15863: my ($dom,%domconfig) = @_;
1.1 raeburn 15864: my ($resulttext,%currautoupdate,%fields,%changes);
15865: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
15866: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
15867: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
15868: }
15869: }
15870: my @offon = ('off','on');
15871: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 15872: run => 'Auto-update:',
15873: classlists => 'Updates to user information in classlists?',
15874: unexpired => 'Skip updates for users without active or future roles?',
15875: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 15876: );
1.44 raeburn 15877: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 15878: my %fieldtitles = &Apache::lonlocal::texthash (
15879: id => 'Student/Employee ID',
1.20 raeburn 15880: permanentemail => 'E-mail address',
1.1 raeburn 15881: lastname => 'Last Name',
15882: firstname => 'First Name',
15883: middlename => 'Middle Name',
1.132 raeburn 15884: generation => 'Generation',
1.1 raeburn 15885: );
1.142 raeburn 15886: $othertitle = &mt('All users');
1.1 raeburn 15887: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 15888: $othertitle = &mt('Other users');
1.1 raeburn 15889: }
15890: foreach my $key (keys(%env)) {
15891: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 15892: my ($usertype,$item) = ($1,$2);
15893: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
15894: if ($usertype eq 'default') {
15895: push(@{$fields{$1}},$2);
15896: } elsif (ref($types) eq 'ARRAY') {
15897: if (grep(/^\Q$usertype\E$/,@{$types})) {
15898: push(@{$fields{$1}},$2);
15899: }
15900: }
15901: }
1.1 raeburn 15902: }
15903: }
1.131 raeburn 15904: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
15905: @lockablenames = sort(@lockablenames);
15906: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
15907: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15908: if (@changed) {
15909: $changes{'lockablenames'} = 1;
15910: }
15911: } else {
15912: if (@lockablenames) {
15913: $changes{'lockablenames'} = 1;
15914: }
15915: }
1.1 raeburn 15916: my %updatehash = (
15917: autoupdate => { run => $env{'form.autoupdate_run'},
15918: classlists => $env{'form.classlists'},
1.385 raeburn 15919: unexpired => $env{'form.unexpired'},
1.1 raeburn 15920: fields => {%fields},
1.131 raeburn 15921: lockablenames => \@lockablenames,
1.1 raeburn 15922: }
15923: );
1.385 raeburn 15924: my $lastactivedays;
15925: if ($env{'form.lastactive'}) {
15926: $lastactivedays = $env{'form.lastactivedays'};
15927: $lastactivedays =~ s/^\s+|\s+$//g;
15928: unless ($lastactivedays =~ /^\d+$/) {
15929: undef($lastactivedays);
15930: $env{'form.lastactive'} = 0;
15931: }
15932: }
15933: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 15934: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 15935: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 15936: if (exists($updatehash{autoupdate}{$key})) {
15937: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
15938: $changes{$key} = 1;
15939: }
15940: }
15941: } elsif ($key eq 'fields') {
15942: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 15943: foreach my $item (@{$types},'default') {
1.1 raeburn 15944: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
15945: my $change = 0;
15946: foreach my $type (@{$currautoupdate{$key}{$item}}) {
15947: if (!exists($fields{$item})) {
15948: $change = 1;
1.132 raeburn 15949: last;
1.1 raeburn 15950: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15951: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15952: $change = 1;
1.132 raeburn 15953: last;
1.1 raeburn 15954: }
15955: }
15956: }
15957: if ($change) {
15958: push(@{$changes{$key}},$item);
15959: }
1.26 raeburn 15960: }
1.1 raeburn 15961: }
15962: }
1.131 raeburn 15963: } elsif ($key eq 'lockablenames') {
15964: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15965: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15966: if (@changed) {
15967: $changes{'lockablenames'} = 1;
15968: }
15969: } else {
15970: if (@lockablenames) {
15971: $changes{'lockablenames'} = 1;
15972: }
15973: }
15974: }
15975: }
15976: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15977: if (@lockablenames) {
15978: $changes{'lockablenames'} = 1;
1.1 raeburn 15979: }
15980: }
1.385 raeburn 15981: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15982: if ($updatehash{'autoupdate'}{'unexpired'}) {
15983: $changes{'unexpired'} = 1;
15984: }
15985: }
15986: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15987: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15988: $changes{'lastactive'} = 1;
15989: }
15990: }
1.26 raeburn 15991: foreach my $item (@{$types},'default') {
15992: if (defined($fields{$item})) {
15993: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15994: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15995: my $change = 0;
15996: if (ref($fields{$item}) eq 'ARRAY') {
15997: foreach my $type (@{$fields{$item}}) {
15998: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15999: $change = 1;
16000: last;
16001: }
16002: }
16003: }
16004: if ($change) {
16005: push(@{$changes{'fields'}},$item);
16006: }
16007: } else {
1.26 raeburn 16008: push(@{$changes{'fields'}},$item);
16009: }
16010: } else {
16011: push(@{$changes{'fields'}},$item);
1.1 raeburn 16012: }
16013: }
16014: }
16015: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16016: $dom);
16017: if ($putresult eq 'ok') {
16018: if (keys(%changes) > 0) {
16019: $resulttext = &mt('Changes made:').'<ul>';
16020: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16021: if ($key eq 'lockablenames') {
16022: $resulttext .= '<li>';
16023: if (@lockablenames) {
16024: $usertypes->{'default'} = $othertitle;
16025: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16026: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16027: } else {
16028: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16029: }
16030: $resulttext .= '</li>';
16031: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16032: foreach my $item (@{$changes{$key}}) {
16033: my @newvalues;
16034: foreach my $type (@{$fields{$item}}) {
16035: push(@newvalues,$fieldtitles{$type});
16036: }
1.3 raeburn 16037: my $newvaluestr;
16038: if (@newvalues > 0) {
16039: $newvaluestr = join(', ',@newvalues);
16040: } else {
16041: $newvaluestr = &mt('none');
1.6 raeburn 16042: }
1.1 raeburn 16043: if ($item eq 'default') {
1.26 raeburn 16044: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16045: } else {
1.26 raeburn 16046: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16047: }
16048: }
16049: } else {
16050: my $newvalue;
16051: if ($key eq 'run') {
16052: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16053: } elsif ($key eq 'lastactive') {
16054: $newvalue = $offon[$env{'form.lastactive'}];
16055: unless ($lastactivedays eq '') {
16056: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16057: }
1.1 raeburn 16058: } else {
16059: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16060: }
1.1 raeburn 16061: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16062: }
16063: }
16064: $resulttext .= '</ul>';
16065: } else {
1.3 raeburn 16066: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16067: }
16068: } else {
1.11 albertel 16069: $resulttext = '<span class="LC_error">'.
16070: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16071: }
1.3 raeburn 16072: return $resulttext;
1.1 raeburn 16073: }
16074:
1.125 raeburn 16075: sub modify_autocreate {
16076: my ($dom,%domconfig) = @_;
16077: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16078: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16079: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16080: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16081: }
16082: }
16083: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16084: req => 'Auto-creation of validated requests for official courses',
16085: xmldc => 'Identity of course creator of courses from XML files',
16086: );
16087: my @types = ('xml','req');
16088: foreach my $item (@types) {
16089: $newvals{$item} = $env{'form.autocreate_'.$item};
16090: $newvals{$item} =~ s/\D//g;
16091: $newvals{$item} = 0 if ($newvals{$item} eq '');
16092: }
16093: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16094: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16095: unless (exists($domcoords{$newvals{'xmldc'}})) {
16096: $newvals{'xmldc'} = '';
16097: }
16098: %autocreatehash = (
16099: autocreate => { xml => $newvals{'xml'},
16100: req => $newvals{'req'},
16101: }
16102: );
16103: if ($newvals{'xmldc'} ne '') {
16104: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16105: }
16106: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16107: $dom);
16108: if ($putresult eq 'ok') {
16109: my @items = @types;
16110: if ($newvals{'xml'}) {
16111: push(@items,'xmldc');
16112: }
16113: foreach my $item (@items) {
16114: if (exists($currautocreate{$item})) {
16115: if ($currautocreate{$item} ne $newvals{$item}) {
16116: $changes{$item} = 1;
16117: }
16118: } elsif ($newvals{$item}) {
16119: $changes{$item} = 1;
16120: }
16121: }
16122: if (keys(%changes) > 0) {
16123: my @offon = ('off','on');
16124: $resulttext = &mt('Changes made:').'<ul>';
16125: foreach my $item (@types) {
16126: if ($changes{$item}) {
16127: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16128: $resulttext .= '<li>'.
16129: &mt("$title{$item} set to [_1]$newtxt [_2]",
16130: '<b>','</b>').
16131: '</li>';
1.125 raeburn 16132: }
16133: }
16134: if ($changes{'xmldc'}) {
16135: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16136: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16137: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16138: }
16139: $resulttext .= '</ul>';
16140: } else {
16141: $resulttext = &mt('No changes made to auto-creation settings');
16142: }
16143: } else {
16144: $resulttext = '<span class="LC_error">'.
16145: &mt('An error occurred: [_1]',$putresult).'</span>';
16146: }
16147: return $resulttext;
16148: }
16149:
1.23 raeburn 16150: sub modify_directorysrch {
1.295 raeburn 16151: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16152: my ($resulttext,%changes);
16153: my %currdirsrch;
16154: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16155: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16156: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16157: }
16158: }
1.277 raeburn 16159: my %title = ( available => 'Institutional directory search available',
16160: localonly => 'Other domains can search institution',
16161: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16162: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16163: searchby => 'Search types',
16164: searchtypes => 'Search latitude');
16165: my @offon = ('off','on');
1.24 raeburn 16166: my @otherdoms = ('Yes','No');
1.23 raeburn 16167:
1.25 raeburn 16168: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16169: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16170: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16171:
1.44 raeburn 16172: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16173: if (keys(%{$usertypes}) == 0) {
16174: @cansearch = ('default');
16175: } else {
16176: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16177: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16178: if (!grep(/^\Q$type\E$/,@cansearch)) {
16179: push(@{$changes{'cansearch'}},$type);
16180: }
1.23 raeburn 16181: }
1.26 raeburn 16182: foreach my $type (@cansearch) {
16183: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16184: push(@{$changes{'cansearch'}},$type);
16185: }
1.23 raeburn 16186: }
1.26 raeburn 16187: } else {
16188: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16189: }
16190: }
16191:
16192: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16193: foreach my $by (@{$currdirsrch{'searchby'}}) {
16194: if (!grep(/^\Q$by\E$/,@searchby)) {
16195: push(@{$changes{'searchby'}},$by);
16196: }
16197: }
16198: foreach my $by (@searchby) {
16199: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16200: push(@{$changes{'searchby'}},$by);
16201: }
16202: }
16203: } else {
16204: push(@{$changes{'searchby'}},@searchby);
16205: }
1.25 raeburn 16206:
16207: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16208: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16209: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16210: push(@{$changes{'searchtypes'}},$type);
16211: }
16212: }
16213: foreach my $type (@searchtypes) {
16214: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16215: push(@{$changes{'searchtypes'}},$type);
16216: }
16217: }
16218: } else {
16219: if (exists($currdirsrch{'searchtypes'})) {
16220: foreach my $type (@searchtypes) {
16221: if ($type ne $currdirsrch{'searchtypes'}) {
16222: push(@{$changes{'searchtypes'}},$type);
16223: }
16224: }
16225: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16226: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16227: }
16228: } else {
16229: push(@{$changes{'searchtypes'}},@searchtypes);
16230: }
16231: }
16232:
1.23 raeburn 16233: my %dirsrch_hash = (
16234: directorysrch => { available => $env{'form.dirsrch_available'},
16235: cansearch => \@cansearch,
1.277 raeburn 16236: localonly => $env{'form.dirsrch_instlocalonly'},
16237: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16238: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16239: searchby => \@searchby,
1.25 raeburn 16240: searchtypes => \@searchtypes,
1.23 raeburn 16241: }
16242: );
16243: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16244: $dom);
16245: if ($putresult eq 'ok') {
16246: if (exists($currdirsrch{'available'})) {
16247: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16248: $changes{'available'} = 1;
16249: }
16250: } else {
16251: if ($env{'form.dirsrch_available'} eq '1') {
16252: $changes{'available'} = 1;
16253: }
16254: }
1.277 raeburn 16255: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16256: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16257: $changes{'lcavailable'} = 1;
16258: }
1.277 raeburn 16259: } else {
16260: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16261: $changes{'lcavailable'} = 1;
16262: }
16263: }
1.24 raeburn 16264: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16265: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16266: $changes{'localonly'} = 1;
16267: }
1.24 raeburn 16268: } else {
1.277 raeburn 16269: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16270: $changes{'localonly'} = 1;
16271: }
16272: }
1.277 raeburn 16273: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16274: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16275: $changes{'lclocalonly'} = 1;
16276: }
1.277 raeburn 16277: } else {
16278: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16279: $changes{'lclocalonly'} = 1;
16280: }
16281: }
1.23 raeburn 16282: if (keys(%changes) > 0) {
16283: $resulttext = &mt('Changes made:').'<ul>';
16284: if ($changes{'available'}) {
16285: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16286: }
1.277 raeburn 16287: if ($changes{'lcavailable'}) {
16288: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16289: }
1.24 raeburn 16290: if ($changes{'localonly'}) {
1.277 raeburn 16291: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16292: }
1.277 raeburn 16293: if ($changes{'lclocalonly'}) {
16294: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16295: }
1.23 raeburn 16296: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16297: my $chgtext;
1.26 raeburn 16298: if (ref($usertypes) eq 'HASH') {
16299: if (keys(%{$usertypes}) > 0) {
16300: foreach my $type (@{$types}) {
16301: if (grep(/^\Q$type\E$/,@cansearch)) {
16302: $chgtext .= $usertypes->{$type}.'; ';
16303: }
16304: }
16305: if (grep(/^default$/,@cansearch)) {
16306: $chgtext .= $othertitle;
16307: } else {
16308: $chgtext =~ s/\; $//;
16309: }
1.210 raeburn 16310: $resulttext .=
1.178 raeburn 16311: '<li>'.
16312: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16313: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16314: '</li>';
1.23 raeburn 16315: }
16316: }
16317: }
16318: if (ref($changes{'searchby'}) eq 'ARRAY') {
16319: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16320: my $chgtext;
16321: foreach my $type (@{$titleorder}) {
16322: if (grep(/^\Q$type\E$/,@searchby)) {
16323: if (defined($searchtitles->{$type})) {
16324: $chgtext .= $searchtitles->{$type}.'; ';
16325: }
16326: }
16327: }
16328: $chgtext =~ s/\; $//;
16329: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16330: }
1.25 raeburn 16331: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16332: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16333: my $chgtext;
16334: foreach my $type (@{$srchtypeorder}) {
16335: if (grep(/^\Q$type\E$/,@searchtypes)) {
16336: if (defined($srchtypes_desc->{$type})) {
16337: $chgtext .= $srchtypes_desc->{$type}.'; ';
16338: }
16339: }
16340: }
16341: $chgtext =~ s/\; $//;
1.178 raeburn 16342: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16343: }
16344: $resulttext .= '</ul>';
1.295 raeburn 16345: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
16346: if (ref($lastactref) eq 'HASH') {
16347: $lastactref->{'directorysrch'} = 1;
16348: }
1.23 raeburn 16349: } else {
1.277 raeburn 16350: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 16351: }
16352: } else {
16353: $resulttext = '<span class="LC_error">'.
1.27 raeburn 16354: &mt('An error occurred: [_1]',$putresult).'</span>';
16355: }
16356: return $resulttext;
16357: }
16358:
1.28 raeburn 16359: sub modify_contacts {
1.205 raeburn 16360: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 16361: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
16362: if (ref($domconfig{'contacts'}) eq 'HASH') {
16363: foreach my $key (keys(%{$domconfig{'contacts'}})) {
16364: $currsetting{$key} = $domconfig{'contacts'}{$key};
16365: }
16366: }
1.286 raeburn 16367: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 16368: my @contacts = ('supportemail','adminemail');
1.286 raeburn 16369: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 16370: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 16371: my @toggles = ('reporterrors','reportupdates','reportstatus');
16372: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 16373: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 16374: foreach my $type (@mailings) {
16375: @{$newsetting{$type}} =
16376: &Apache::loncommon::get_env_multiple('form.'.$type);
16377: foreach my $item (@contacts) {
16378: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
16379: $contacts_hash{contacts}{$type}{$item} = 1;
16380: } else {
16381: $contacts_hash{contacts}{$type}{$item} = 0;
16382: }
1.289 raeburn 16383: }
1.28 raeburn 16384: $others{$type} = $env{'form.'.$type.'_others'};
16385: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 16386: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16387: $bcc{$type} = $env{'form.'.$type.'_bcc'};
16388: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 16389: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
16390: $includestr{$type} = $env{'form.'.$type.'_includestr'};
16391: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
16392: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16393: }
1.134 raeburn 16394: }
1.28 raeburn 16395: }
16396: foreach my $item (@contacts) {
16397: $to{$item} = $env{'form.'.$item};
16398: $contacts_hash{'contacts'}{$item} = $to{$item};
16399: }
1.203 raeburn 16400: foreach my $item (@toggles) {
16401: if ($env{'form.'.$item} =~ /^(0|1)$/) {
16402: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
16403: }
16404: }
1.340 raeburn 16405: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
16406: foreach my $item (@lonstatus) {
16407: if ($item eq 'excluded') {
16408: my (%serverhomes,@excluded);
16409: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16410: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16411: if (@possexcluded) {
16412: foreach my $id (sort(@possexcluded)) {
16413: if ($serverhomes{$id}) {
16414: push(@excluded,$id);
16415: }
16416: }
16417: }
16418: if (@excluded) {
16419: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16420: }
16421: } elsif ($item eq 'weights') {
1.377 raeburn 16422: foreach my $type ('E','W','N','U') {
1.340 raeburn 16423: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16424: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16425: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16426: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16427: $env{'form.error'.$item.'_'.$type};
16428: }
16429: }
16430: }
16431: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16432: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16433: if ($env{'form.error'.$item} =~ /^\d+$/) {
16434: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16435: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16436: }
16437: }
16438: }
16439: }
1.286 raeburn 16440: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16441: foreach my $field (@{$fields}) {
16442: if (ref($possoptions->{$field}) eq 'ARRAY') {
16443: my $value = $env{'form.helpform_'.$field};
16444: $value =~ s/^\s+|\s+$//g;
16445: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16446: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16447: if ($field eq 'screenshot') {
16448: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16449: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16450: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16451: }
16452: }
16453: }
16454: }
16455: }
16456: }
1.315 raeburn 16457: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16458: my (@statuses,%usertypeshash,@overrides);
16459: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16460: @statuses = @{$types};
16461: if (ref($usertypes) eq 'HASH') {
16462: %usertypeshash = %{$usertypes};
16463: }
16464: }
16465: if (@statuses) {
16466: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16467: foreach my $type (@possoverrides) {
16468: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16469: push(@overrides,$type);
16470: }
16471: }
16472: if (@overrides) {
16473: foreach my $type (@overrides) {
16474: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16475: foreach my $item (@contacts) {
16476: if (grep(/^\Q$item\E$/,@standard)) {
16477: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16478: $newsetting{'override_'.$type}{$item} = 1;
16479: } else {
16480: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16481: $newsetting{'override_'.$type}{$item} = 0;
16482: }
16483: }
16484: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16485: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16486: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16487: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16488: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16489: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16490: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16491: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16492: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16493: }
16494: }
16495: }
16496: }
1.28 raeburn 16497: if (keys(%currsetting) > 0) {
16498: foreach my $item (@contacts) {
16499: if ($to{$item} ne $currsetting{$item}) {
16500: $changes{$item} = 1;
16501: }
16502: }
16503: foreach my $type (@mailings) {
16504: foreach my $item (@contacts) {
16505: if (ref($currsetting{$type}) eq 'HASH') {
16506: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16507: push(@{$changes{$type}},$item);
16508: }
16509: } else {
16510: push(@{$changes{$type}},@{$newsetting{$type}});
16511: }
16512: }
16513: if ($others{$type} ne $currsetting{$type}{'others'}) {
16514: push(@{$changes{$type}},'others');
16515: }
1.289 raeburn 16516: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16517: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16518: push(@{$changes{$type}},'bcc');
16519: }
1.286 raeburn 16520: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16521: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16522: push(@{$changes{$type}},'include');
16523: }
16524: }
16525: }
16526: if (ref($fields) eq 'ARRAY') {
16527: if (ref($currsetting{'helpform'}) eq 'HASH') {
16528: foreach my $field (@{$fields}) {
16529: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16530: push(@{$changes{'helpform'}},$field);
16531: }
16532: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16533: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16534: push(@{$changes{'helpform'}},'maxsize');
16535: }
16536: }
16537: }
16538: } else {
16539: foreach my $field (@{$fields}) {
16540: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16541: push(@{$changes{'helpform'}},$field);
16542: }
16543: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16544: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16545: push(@{$changes{'helpform'}},'maxsize');
16546: }
16547: }
16548: }
1.134 raeburn 16549: }
1.28 raeburn 16550: }
1.315 raeburn 16551: if (@statuses) {
16552: if (ref($currsetting{'overrides'}) eq 'HASH') {
16553: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16554: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16555: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16556: foreach my $item (@contacts,'bcc','others','include') {
16557: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16558: push(@{$changes{'overrides'}},$key);
16559: last;
16560: }
16561: }
16562: } else {
16563: push(@{$changes{'overrides'}},$key);
16564: }
16565: }
16566: }
16567: foreach my $key (@overrides) {
16568: unless (exists($currsetting{'overrides'}{$key})) {
16569: push(@{$changes{'overrides'}},$key);
16570: }
16571: }
16572: } else {
16573: foreach my $key (@overrides) {
16574: push(@{$changes{'overrides'}},$key);
16575: }
16576: }
16577: }
1.340 raeburn 16578: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16579: foreach my $key ('excluded','weights','threshold','sysmail') {
16580: if ($key eq 'excluded') {
16581: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16582: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16583: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16584: (@{$currsetting{'lonstatus'}{$key}})) {
16585: my @diffs =
16586: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16587: $currsetting{'lonstatus'}{$key});
16588: if (@diffs) {
16589: push(@{$changes{'lonstatus'}},$key);
16590: }
16591: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16592: push(@{$changes{'lonstatus'}},$key);
16593: }
16594: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16595: (@{$currsetting{'lonstatus'}{$key}})) {
16596: push(@{$changes{'lonstatus'}},$key);
16597: }
16598: } elsif ($key eq 'weights') {
16599: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16600: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16601: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16602: foreach my $type ('E','W','N','U') {
1.340 raeburn 16603: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16604: $currsetting{'lonstatus'}{$key}{$type}) {
16605: push(@{$changes{'lonstatus'}},$key);
16606: last;
16607: }
16608: }
16609: } else {
1.341 raeburn 16610: foreach my $type ('E','W','N','U') {
1.340 raeburn 16611: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16612: push(@{$changes{'lonstatus'}},$key);
16613: last;
16614: }
16615: }
16616: }
16617: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16618: foreach my $type ('E','W','N','U') {
1.340 raeburn 16619: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16620: push(@{$changes{'lonstatus'}},$key);
16621: last;
16622: }
16623: }
16624: }
16625: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16626: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16627: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16628: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16629: push(@{$changes{'lonstatus'}},$key);
16630: }
16631: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16632: push(@{$changes{'lonstatus'}},$key);
16633: }
16634: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16635: push(@{$changes{'lonstatus'}},$key);
16636: }
16637: }
16638: }
16639: } else {
16640: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16641: foreach my $key ('excluded','weights','threshold','sysmail') {
16642: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16643: push(@{$changes{'lonstatus'}},$key);
16644: }
16645: }
16646: }
16647: }
1.28 raeburn 16648: } else {
16649: my %default;
16650: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16651: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16652: $default{'errormail'} = 'adminemail';
16653: $default{'packagesmail'} = 'adminemail';
16654: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16655: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16656: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16657: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16658: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16659: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16660: foreach my $item (@contacts) {
16661: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16662: $changes{$item} = 1;
1.203 raeburn 16663: }
1.28 raeburn 16664: }
16665: foreach my $type (@mailings) {
16666: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16667: push(@{$changes{$type}},@{$newsetting{$type}});
16668: }
16669: if ($others{$type} ne '') {
16670: push(@{$changes{$type}},'others');
1.134 raeburn 16671: }
1.286 raeburn 16672: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16673: if ($bcc{$type} ne '') {
16674: push(@{$changes{$type}},'bcc');
16675: }
1.286 raeburn 16676: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16677: push(@{$changes{$type}},'include');
16678: }
1.134 raeburn 16679: }
1.28 raeburn 16680: }
1.286 raeburn 16681: if (ref($fields) eq 'ARRAY') {
16682: foreach my $field (@{$fields}) {
16683: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16684: push(@{$changes{'helpform'}},$field);
16685: }
16686: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16687: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16688: push(@{$changes{'helpform'}},'maxsize');
16689: }
16690: }
16691: }
1.289 raeburn 16692: }
1.340 raeburn 16693: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16694: foreach my $key ('excluded','weights','threshold','sysmail') {
16695: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16696: push(@{$changes{'lonstatus'}},$key);
16697: }
16698: }
16699: }
1.28 raeburn 16700: }
1.203 raeburn 16701: foreach my $item (@toggles) {
16702: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16703: $changes{$item} = 1;
16704: } elsif ((!$env{'form.'.$item}) &&
16705: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16706: $changes{$item} = 1;
16707: }
16708: }
1.28 raeburn 16709: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16710: $dom);
16711: if ($putresult eq 'ok') {
16712: if (keys(%changes) > 0) {
1.205 raeburn 16713: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16714: if (ref($lastactref) eq 'HASH') {
16715: $lastactref->{'domainconfig'} = 1;
16716: }
1.28 raeburn 16717: my ($titles,$short_titles) = &contact_titles();
16718: $resulttext = &mt('Changes made:').'<ul>';
16719: foreach my $item (@contacts) {
16720: if ($changes{$item}) {
16721: $resulttext .= '<li>'.$titles->{$item}.
16722: &mt(' set to: ').
16723: '<span class="LC_cusr_emph">'.
16724: $to{$item}.'</span></li>';
16725: }
16726: }
16727: foreach my $type (@mailings) {
16728: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16729: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16730: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16731: } else {
16732: $resulttext .= '<li>'.$titles->{$type}.': ';
16733: }
1.28 raeburn 16734: my @text;
16735: foreach my $item (@{$newsetting{$type}}) {
16736: push(@text,$short_titles->{$item});
16737: }
16738: if ($others{$type} ne '') {
16739: push(@text,$others{$type});
16740: }
1.286 raeburn 16741: if (@text) {
16742: $resulttext .= '<span class="LC_cusr_emph">'.
16743: join(', ',@text).'</span>';
16744: }
16745: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16746: if ($bcc{$type} ne '') {
1.286 raeburn 16747: my $bcctext;
16748: if (@text) {
1.289 raeburn 16749: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16750: } else {
16751: $bcctext = '(Bcc)';
16752: }
16753: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16754: } elsif (!@text) {
16755: $resulttext .= &mt('No one');
16756: }
1.289 raeburn 16757: if ($includestr{$type} ne '') {
1.286 raeburn 16758: if ($includeloc{$type} eq 'b') {
16759: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16760: } elsif ($includeloc{$type} eq 's') {
16761: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16762: }
1.134 raeburn 16763: }
1.286 raeburn 16764: } elsif (!@text) {
16765: $resulttext .= &mt('No recipients');
1.134 raeburn 16766: }
16767: $resulttext .= '</li>';
1.28 raeburn 16768: }
16769: }
1.315 raeburn 16770: if (ref($changes{'overrides'}) eq 'ARRAY') {
16771: my @deletions;
16772: foreach my $type (@{$changes{'overrides'}}) {
16773: if ($usertypeshash{$type}) {
16774: if (grep(/^\Q$type\E/,@overrides)) {
16775: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16776: $usertypeshash{$type}).'<ul><li>';
16777: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16778: my @text;
16779: foreach my $item (@contacts) {
16780: if ($newsetting{'override_'.$type}{$item}) {
16781: push(@text,$short_titles->{$item});
16782: }
16783: }
16784: if ($newsetting{'override_'.$type}{'others'} ne '') {
16785: push(@text,$newsetting{'override_'.$type}{'others'});
16786: }
16787:
16788: if (@text) {
16789: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16790: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16791: }
16792: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16793: my $bcctext;
16794: if (@text) {
16795: $bcctext = ' '.&mt('with Bcc to');
16796: } else {
16797: $bcctext = '(Bcc)';
16798: }
16799: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16800: } elsif (!@text) {
16801: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16802: }
16803: $resulttext .= '</li>';
16804: if ($newsetting{'override_'.$type}{'include'} ne '') {
16805: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16806: if ($loc eq 'b') {
16807: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16808: } elsif ($loc eq 's') {
16809: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16810: }
16811: }
16812: }
16813: $resulttext .= '</li></ul></li>';
16814: } else {
16815: push(@deletions,$usertypeshash{$type});
16816: }
16817: }
16818: }
16819: if (@deletions) {
16820: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16821: join(', ',@deletions)).'</li>';
16822: }
16823: }
1.203 raeburn 16824: my @offon = ('off','on');
1.340 raeburn 16825: my $corelink = &core_link_msu();
1.203 raeburn 16826: if ($changes{'reporterrors'}) {
16827: $resulttext .= '<li>'.
16828: &mt('E-mail error reports to [_1] set to "'.
16829: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16830: $corelink).
1.203 raeburn 16831: '</li>';
16832: }
16833: if ($changes{'reportupdates'}) {
16834: $resulttext .= '<li>'.
16835: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16836: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16837: $corelink).
1.203 raeburn 16838: '</li>';
16839: }
1.340 raeburn 16840: if ($changes{'reportstatus'}) {
16841: $resulttext .= '<li>'.
16842: &mt('E-mail status if errors above threshold to [_1] set to "'.
16843: $offon[$env{'form.reportstatus'}].'".',
16844: $corelink).
16845: '</li>';
16846: }
16847: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16848: $resulttext .= '<li>'.
16849: &mt('Nightly status check e-mail settings').':<ul>';
16850: my (%defval,%use_def,%shown);
16851: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
16852: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
16853: $defval{'weights'} =
1.341 raeburn 16854: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 16855: $defval{'excluded'} = &mt('None');
16856: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
16857: foreach my $item ('threshold','sysmail','weights','excluded') {
16858: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
16859: if (($item eq 'threshold') || ($item eq 'sysmail')) {
16860: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
16861: } elsif ($item eq 'weights') {
16862: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 16863: foreach my $type ('E','W','N','U') {
1.340 raeburn 16864: $shown{$item} .= $lonstatus_names->{$type}.'=';
16865: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
16866: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
16867: } else {
16868: $shown{$item} .= $lonstatus_defs->{$type};
16869: }
16870: $shown{$item} .= ', ';
16871: }
16872: $shown{$item} =~ s/, $//;
16873: } else {
16874: $shown{$item} = $defval{$item};
16875: }
16876: } elsif ($item eq 'excluded') {
16877: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
16878: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
16879: } else {
16880: $shown{$item} = $defval{$item};
16881: }
16882: }
16883: } else {
16884: $shown{$item} = $defval{$item};
16885: }
16886: }
16887: } else {
16888: foreach my $item ('threshold','weights','excluded','sysmail') {
16889: $shown{$item} = $defval{$item};
16890: }
16891: }
16892: foreach my $item ('threshold','weights','excluded','sysmail') {
16893: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
16894: $shown{$item}).'</li>';
16895: }
16896: $resulttext .= '</ul></li>';
16897: }
1.286 raeburn 16898: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
16899: my (@optional,@required,@unused,$maxsizechg);
16900: foreach my $field (@{$changes{'helpform'}}) {
16901: if ($field eq 'maxsize') {
16902: $maxsizechg = 1;
16903: next;
16904: }
16905: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 16906: push(@optional,$field);
1.286 raeburn 16907: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
16908: push(@unused,$field);
16909: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 16910: push(@required,$field);
1.286 raeburn 16911: }
16912: }
16913: if (@optional) {
16914: $resulttext .= '<li>'.
16915: &mt('Help form fields changed to "Optional": [_1].',
16916: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
16917: '</li>';
16918: }
16919: if (@required) {
16920: $resulttext .= '<li>'.
16921: &mt('Help form fields changed to "Required": [_1].',
16922: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
16923: '</li>';
16924: }
16925: if (@unused) {
16926: $resulttext .= '<li>'.
16927: &mt('Help form fields changed to "Not shown": [_1].',
16928: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
16929: '</li>';
16930: }
16931: if ($maxsizechg) {
16932: $resulttext .= '<li>'.
16933: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
16934: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
16935: '</li>';
16936: }
16937: }
1.28 raeburn 16938: $resulttext .= '</ul>';
16939: } else {
1.288 raeburn 16940: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 16941: }
16942: } else {
16943: $resulttext = '<span class="LC_error">'.
16944: &mt('An error occurred: [_1].',$putresult).'</span>';
16945: }
16946: return $resulttext;
16947: }
16948:
1.357 raeburn 16949: sub modify_privacy {
16950: my ($dom,%domconfig) = @_;
16951: my ($resulttext,%current,%changes);
16952: if (ref($domconfig{'privacy'}) eq 'HASH') {
16953: %current = %{$domconfig{'privacy'}};
16954: }
16955: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
16956: my @items = ('domain','author','course','community');
16957: my %names = &Apache::lonlocal::texthash (
16958: domain => 'Assigned domain role(s)',
16959: author => 'Assigned co-author role(s)',
16960: course => 'Assigned course role(s)',
1.416 raeburn 16961: community => 'Assigned community role(s)',
1.357 raeburn 16962: );
16963: my %roles = &Apache::lonlocal::texthash (
16964: domain => 'Domain role',
16965: author => 'Co-author role',
16966: course => 'Course role',
16967: community => 'Community role',
16968: );
16969: my %titles = &Apache::lonlocal::texthash (
16970: approval => 'Approval for role in different domain',
16971: othdom => 'User information available in other domain',
16972: priv => 'Information viewable by privileged user in same domain',
16973: unpriv => 'Information viewable by unprivileged user in same domain',
16974: instdom => 'Other domain shares institution/provider',
16975: extdom => 'Other domain has different institution/provider',
16976: none => 'Not allowed',
16977: user => 'User authorizes',
16978: domain => 'Domain Coordinator authorizes',
16979: auto => 'Unrestricted',
1.418 raeburn 16980: notify => 'Notify when role needs authorization',
1.357 raeburn 16981: );
16982: my %fieldnames = &Apache::lonlocal::texthash (
16983: id => 'Student/Employee ID',
16984: permanentemail => 'E-mail address',
16985: lastname => 'Last Name',
16986: firstname => 'First Name',
16987: middlename => 'Middle Name',
16988: generation => 'Generation',
16989: );
16990: my ($othertitle,$usertypes,$types) =
16991: &Apache::loncommon::sorted_inst_types($dom);
16992: my (%by_ip,%by_location,@intdoms,@instdoms);
16993: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16994:
16995: my %privacyhash = (
16996: 'approval' => {
16997: instdom => {},
16998: extdom => {},
16999: },
17000: 'othdom' => {},
17001: 'priv' => {},
17002: 'unpriv' => {},
17003: );
17004: foreach my $item (@items) {
17005: if (@instdoms > 1) {
1.416 raeburn 17006: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17007: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17008: }
17009: if (ref($current{'approval'}) eq 'HASH') {
17010: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17011: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17012: $changes{'approval'} = 1;
17013: }
17014: }
17015: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17016: $changes{'approval'} = 1;
17017: }
17018: }
17019: if (keys(%by_location) > 0) {
17020: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17021: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17022: }
17023: if (ref($current{'approval'}) eq 'HASH') {
17024: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17025: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17026: $changes{'approval'} = 1;
17027: }
17028: }
17029: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17030: $changes{'approval'} = 1;
17031: }
17032: }
17033: foreach my $status ('priv','unpriv') {
17034: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17035: my @newvalues;
17036: foreach my $field (@possibles) {
17037: if (grep(/^\Q$field\E$/,@fields)) {
17038: $privacyhash{$status}{$item}{$field} = 1;
17039: push(@newvalues,$field);
17040: }
17041: }
17042: @newvalues = sort(@newvalues);
17043: if (ref($current{$status}) eq 'HASH') {
17044: if (ref($current{$status}{$item}) eq 'HASH') {
17045: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17046: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17047: if (@diffs > 0) {
17048: $changes{$status} = 1;
17049: }
17050: }
17051: } else {
17052: my @stdfields;
17053: foreach my $field (@fields) {
17054: if ($field eq 'id') {
17055: next if ($status eq 'unpriv');
17056: next if (($status eq 'priv') && ($item eq 'community'));
17057: }
17058: push(@stdfields,$field);
17059: }
17060: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17061: if (@diffs > 0) {
17062: $changes{$status} = 1;
17063: }
17064: }
17065: }
17066: }
17067: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17068: my @statuses;
17069: if (ref($types) eq 'ARRAY') {
17070: @statuses = @{$types};
17071: }
17072: foreach my $type (@statuses,'default') {
17073: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17074: my @newvalues;
17075: foreach my $field (sort(@possfields)) {
17076: if (grep(/^\Q$field\E$/,@fields)) {
17077: $privacyhash{'othdom'}{$type}{$field} = 1;
17078: push(@newvalues,$field);
17079: }
17080: }
17081: @newvalues = sort(@newvalues);
17082: if (ref($current{'othdom'}) eq 'HASH') {
17083: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17084: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17085: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17086: if (@diffs > 0) {
17087: $changes{'othdom'} = 1;
17088: }
17089: }
17090: } else {
17091: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17092: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17093: if (@diffs > 0) {
17094: $changes{'othdom'} = 1;
17095: }
17096: }
17097: }
1.417 raeburn 17098: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17099: my %notify;
17100: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17101: if (exists($domcoords{$possdc})) {
17102: $notify{$possdc} = 1;
17103: }
17104: }
17105: my $notify = join(',',sort(keys(%notify)));
17106: if ($current{'notify'} ne $notify) {
17107: $changes{'notify'} = 1;
17108: }
17109: $privacyhash{'notify'} = $notify;
1.357 raeburn 17110: }
17111: my %confighash = (
17112: privacy => \%privacyhash,
17113: );
17114: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17115: if ($putresult eq 'ok') {
17116: if (keys(%changes) > 0) {
17117: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17118: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17119: if ($changes{$key}) {
17120: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17121: if ($key eq 'approval') {
17122: if (keys(%{$privacyhash{$key}{instdom}})) {
17123: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17124: foreach my $item (@items) {
17125: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17126: }
17127: $resulttext .= '</ul></li>';
17128: }
17129: if (keys(%{$privacyhash{$key}{extdom}})) {
17130: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17131: foreach my $item (@items) {
17132: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17133: }
17134: $resulttext .= '</ul></li>';
17135: }
1.417 raeburn 17136: } elsif ($key eq 'notify') {
17137: if ($privacyhash{$key}) {
17138: foreach my $dc (split(/,/,$privacyhash{$key})) {
17139: my ($dcname,$dcdom) = split(/:/,$dc);
17140: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17141: }
17142: } else {
17143: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17144: }
1.357 raeburn 17145: } elsif ($key eq 'othdom') {
17146: my @statuses;
17147: if (ref($types) eq 'ARRAY') {
17148: @statuses = @{$types};
17149: }
17150: if (ref($privacyhash{$key}) eq 'HASH') {
17151: foreach my $status (@statuses,'default') {
17152: if ($status eq 'default') {
17153: $resulttext .= '<li>'.$othertitle.': ';
17154: } elsif (ref($usertypes) eq 'HASH') {
17155: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17156: } else {
17157: next;
17158: }
17159: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17160: if (keys(%{$privacyhash{$key}{$status}})) {
17161: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17162: } else {
17163: $resulttext .= &mt('none');
17164: }
17165: }
17166: $resulttext .= '</li>';
17167: }
17168: }
17169: } else {
17170: foreach my $item (@items) {
17171: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17172: $resulttext .= '<li>'.$names{$item}.': ';
17173: if (keys(%{$privacyhash{$key}{$item}})) {
17174: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17175: } else {
17176: $resulttext .= &mt('none');
17177: }
17178: $resulttext .= '</li>';
17179: }
17180: }
17181: }
17182: $resulttext .= '</ul></li>';
17183: }
17184: }
1.421 raeburn 17185: $resulttext .= '</ul>';
1.357 raeburn 17186: } else {
17187: $resulttext = &mt('No changes made to user information settings');
17188: }
17189: } else {
17190: $resulttext = '<span class="LC_error">'.
17191: &mt('An error occurred: [_1]',$putresult).'</span>';
17192: }
17193: return $resulttext;
17194: }
17195:
1.354 raeburn 17196: sub modify_passwords {
17197: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17198: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17199: $updatedefaults,$updateconf);
1.354 raeburn 17200: my $customfn = 'resetpw.html';
17201: if (ref($domconfig{'passwords'}) eq 'HASH') {
17202: %current = %{$domconfig{'passwords'}};
17203: }
17204: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17205: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17206: if (ref($types) eq 'ARRAY') {
17207: @oktypes = @{$types};
17208: }
17209: push(@oktypes,'default');
17210:
17211: my %titles = &Apache::lonlocal::texthash (
17212: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17213: intauth_check => 'Check bcrypt cost if authenticated',
17214: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17215: permanent => 'Permanent e-mail address',
17216: critical => 'Critical notification address',
17217: notify => 'Notification address',
17218: min => 'Minimum password length',
17219: max => 'Maximum password length',
17220: chars => 'Required characters',
17221: expire => 'Password expiration (days)',
1.356 raeburn 17222: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17223: reset => 'Resetting Forgotten Password',
17224: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17225: rules => 'Rules for LON-CAPA Passwords',
17226: crsownerchg => 'Course Owner Changing Student Passwords',
17227: username => 'Username',
17228: email => 'E-mail address',
17229: );
17230:
17231: #
17232: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17233: #
17234: my (%curr_defaults,%save_defaults);
17235: if (ref($domconfig{'defaults'}) eq 'HASH') {
17236: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17237: if ($key =~ /^intauth_(cost|check|switch)$/) {
17238: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17239: } else {
17240: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17241: }
17242: }
17243: }
17244: my %staticdefaults = (
17245: 'resetlink' => 2,
17246: 'resetcase' => \@oktypes,
17247: 'resetprelink' => 'both',
17248: 'resetemail' => ['critical','notify','permanent'],
17249: 'intauth_cost' => 10,
17250: 'intauth_check' => 0,
17251: 'intauth_switch' => 0,
17252: );
1.365 raeburn 17253: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17254: foreach my $type (@oktypes) {
17255: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17256: }
17257: my $linklife = $env{'form.passwords_link'};
17258: $linklife =~ s/^\s+|\s+$//g;
17259: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17260: $newvalues{'resetlink'} = $linklife;
17261: if ($current{'resetlink'}) {
17262: if ($current{'resetlink'} ne $linklife) {
17263: $changes{'reset'} = 1;
17264: }
1.368 raeburn 17265: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17266: if ($staticdefaults{'resetlink'} ne $linklife) {
17267: $changes{'reset'} = 1;
17268: }
17269: }
17270: } elsif ($current{'resetlink'}) {
17271: $changes{'reset'} = 1;
17272: }
17273: my @casesens;
17274: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17275: foreach my $case (sort(@posscase)) {
17276: if (grep(/^\Q$case\E$/,@oktypes)) {
17277: push(@casesens,$case);
17278: }
17279: }
17280: $newvalues{'resetcase'} = \@casesens;
17281: if (ref($current{'resetcase'}) eq 'ARRAY') {
17282: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17283: if (@diffs > 0) {
17284: $changes{'reset'} = 1;
17285: }
1.368 raeburn 17286: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17287: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17288: if (@diffs > 0) {
17289: $changes{'reset'} = 1;
17290: }
17291: }
17292: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17293: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17294: if (exists($current{'resetprelink'})) {
17295: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17296: $changes{'reset'} = 1;
17297: }
1.368 raeburn 17298: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17299: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17300: $changes{'reset'} = 1;
17301: }
17302: }
17303: } elsif ($current{'resetprelink'}) {
17304: $changes{'reset'} = 1;
17305: }
17306: foreach my $type (@oktypes) {
17307: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17308: my @postlink;
17309: foreach my $item (sort(@possplink)) {
17310: if ($item =~ /^(email|username)$/) {
17311: push(@postlink,$item);
17312: }
17313: }
17314: $newvalues{'resetpostlink'}{$type} = \@postlink;
17315: unless ($changes{'reset'}) {
17316: if (ref($current{'resetpostlink'}) eq 'HASH') {
17317: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17318: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17319: if (@diffs > 0) {
17320: $changes{'reset'} = 1;
17321: }
17322: } else {
17323: $changes{'reset'} = 1;
17324: }
1.368 raeburn 17325: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17326: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
17327: if (@diffs > 0) {
17328: $changes{'reset'} = 1;
17329: }
17330: }
17331: }
17332: }
17333: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
17334: my @resetemail;
17335: foreach my $item (sort(@possemailsrc)) {
17336: if ($item =~ /^(permanent|critical|notify)$/) {
17337: push(@resetemail,$item);
17338: }
17339: }
17340: $newvalues{'resetemail'} = \@resetemail;
17341: unless ($changes{'reset'}) {
17342: if (ref($current{'resetemail'}) eq 'ARRAY') {
17343: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
17344: if (@diffs > 0) {
17345: $changes{'reset'} = 1;
17346: }
1.368 raeburn 17347: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17348: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
17349: if (@diffs > 0) {
17350: $changes{'reset'} = 1;
17351: }
17352: }
17353: }
17354: if ($env{'form.passwords_stdtext'} == 0) {
17355: $newvalues{'resetremove'} = 1;
17356: unless ($current{'resetremove'}) {
17357: $changes{'reset'} = 1;
17358: }
17359: } elsif ($current{'resetremove'}) {
17360: $changes{'reset'} = 1;
17361: }
17362: if ($env{'form.passwords_customfile.filename'} ne '') {
17363: my $servadm = $r->dir_config('lonAdmEMail');
17364: my ($configuserok,$author_ok,$switchserver) =
17365: &config_check($dom,$confname,$servadm);
17366: my $error;
17367: if ($configuserok eq 'ok') {
17368: if ($switchserver) {
17369: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
17370: } else {
17371: if ($author_ok eq 'ok') {
1.421 raeburn 17372: my $modified = [];
1.354 raeburn 17373: my ($result,$customurl) =
1.421 raeburn 17374: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
17375: $confname,'customtext/resetpw','','',$customfn,
17376: $modified);
1.354 raeburn 17377: if ($result eq 'ok') {
17378: $newvalues{'resetcustom'} = $customurl;
17379: $changes{'reset'} = 1;
1.421 raeburn 17380: &update_modify_urls($r,$modified);
1.354 raeburn 17381: } else {
17382: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
17383: }
17384: } else {
17385: $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);
17386: }
17387: }
17388: } else {
17389: $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);
17390: }
17391: if ($error) {
17392: &Apache::lonnet::logthis($error);
17393: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17394: }
17395: } elsif ($current{'resetcustom'}) {
17396: if ($env{'form.passwords_custom_del'}) {
17397: $changes{'reset'} = 1;
17398: } else {
17399: $newvalues{'resetcustom'} = $current{'resetcustom'};
17400: }
17401: }
17402: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
17403: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
17404: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
17405: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
17406: $changes{'intauth'} = 1;
17407: }
17408: } else {
17409: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
17410: }
17411: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
17412: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
17413: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
17414: $changes{'intauth'} = 1;
17415: }
17416: } else {
17417: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17418: }
17419: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
17420: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
17421: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
17422: $changes{'intauth'} = 1;
17423: }
17424: } else {
17425: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17426: }
17427: foreach my $item ('cost','check','switch') {
17428: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
17429: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
17430: $updatedefaults = 1;
17431: }
17432: }
1.405 raeburn 17433: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 17434: my %crsownerchg = (
17435: by => [],
17436: for => [],
17437: );
17438: foreach my $item ('by','for') {
17439: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17440: foreach my $type (sort(@posstypes)) {
17441: if (grep(/^\Q$type\E$/,@oktypes)) {
17442: push(@{$crsownerchg{$item}},$type);
17443: }
17444: }
17445: }
17446: $newvalues{'crsownerchg'} = \%crsownerchg;
17447: if (ref($current{'crsownerchg'}) eq 'HASH') {
17448: foreach my $item ('by','for') {
17449: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17450: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17451: if (@diffs > 0) {
17452: $changes{'crsownerchg'} = 1;
17453: last;
17454: }
17455: }
17456: }
1.368 raeburn 17457: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17458: foreach my $item ('by','for') {
17459: if (@{$crsownerchg{$item}} > 0) {
17460: $changes{'crsownerchg'} = 1;
17461: last;
17462: }
1.354 raeburn 17463: }
17464: }
17465:
17466: my %confighash = (
17467: defaults => \%save_defaults,
17468: passwords => \%newvalues,
17469: );
17470: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17471:
17472: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17473: if ($putresult eq 'ok') {
17474: if (keys(%changes) > 0) {
17475: $resulttext = &mt('Changes made: ').'<ul>';
17476: foreach my $key ('reset','intauth','rules','crsownerchg') {
17477: if ($changes{$key}) {
1.355 raeburn 17478: unless ($key eq 'intauth') {
17479: $updateconf = 1;
17480: }
1.354 raeburn 17481: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17482: if ($key eq 'reset') {
17483: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17484: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17485: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17486: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17487: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17488: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17489: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17490: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17491: }
1.354 raeburn 17492: } else {
17493: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17494: }
17495: if ($confighash{'passwords'}{'resetlink'}) {
17496: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17497: } else {
17498: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17499: &mt('Will default to 2 hours').'</li>';
17500: }
17501: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17502: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17503: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17504: } else {
17505: my $casesens;
17506: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17507: if ($type eq 'default') {
17508: $casesens .= $othertitle.', ';
17509: } elsif ($usertypes->{$type} ne '') {
17510: $casesens .= $usertypes->{$type}.', ';
17511: }
17512: }
17513: $casesens =~ s/\Q, \E$//;
17514: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17515: }
17516: } else {
17517: $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>';
17518: }
17519: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17520: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17521: } else {
17522: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17523: }
17524: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17525: my $output;
17526: if (ref($types) eq 'ARRAY') {
17527: foreach my $type (@{$types}) {
17528: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17529: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17530: $output .= $usertypes->{$type}.' -- '.&mt('none');
17531: } else {
17532: $output .= $usertypes->{$type}.' -- '.
17533: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17534: }
17535: }
17536: }
17537: }
17538: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17539: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17540: $output .= $othertitle.' -- '.&mt('none');
17541: } else {
17542: $output .= $othertitle.' -- '.
17543: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17544: }
17545: }
17546: if ($output) {
17547: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17548: } else {
17549: $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>';
17550: }
17551: } else {
17552: $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>';
17553: }
17554: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17555: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17556: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17557: } else {
17558: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17559: }
17560: } else {
1.379 raeburn 17561: $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 17562: }
17563: if ($confighash{'passwords'}{'resetremove'}) {
17564: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17565: } else {
17566: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17567: }
17568: if ($confighash{'passwords'}{'resetcustom'}) {
17569: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17570: &mt('custom text'),600,500,undef,undef,
17571: undef,undef,'background-color:#ffffff');
17572: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17573: } else {
17574: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17575: }
17576: } elsif ($key eq 'intauth') {
17577: foreach my $item ('cost','switch','check') {
17578: my $value = $save_defaults{$key.'_'.$item};
17579: if ($item eq 'switch') {
17580: my %optiondesc = &Apache::lonlocal::texthash (
17581: 0 => 'No',
17582: 1 => 'Yes',
17583: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17584: );
17585: if ($value =~ /^(0|1|2)$/) {
17586: $value = $optiondesc{$value};
17587: } else {
17588: $value = &mt('none -- defaults to No');
17589: }
17590: } elsif ($item eq 'check') {
17591: my %optiondesc = &Apache::lonlocal::texthash (
17592: 0 => 'No',
17593: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17594: 2 => 'Yes, disallow login if stored cost is less than domain default',
17595: );
17596: if ($value =~ /^(0|1|2)$/) {
17597: $value = $optiondesc{$value};
17598: } else {
17599: $value = &mt('none -- defaults to No');
17600: }
17601: }
17602: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17603: }
17604: } elsif ($key eq 'rules') {
1.356 raeburn 17605: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17606: if ($confighash{'passwords'}{$rule} eq '') {
17607: if ($rule eq 'min') {
1.356 raeburn 17608: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17609: ' '.&mt('Default of [_1] will be used',
17610: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17611: } else {
17612: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17613: }
17614: } else {
17615: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17616: }
17617: }
1.370 raeburn 17618: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17619: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17620: my %rulenames = &Apache::lonlocal::texthash(
17621: uc => 'At least one upper case letter',
17622: lc => 'At least one lower case letter',
17623: num => 'At least one number',
17624: spec => 'At least one non-alphanumeric',
17625: );
17626: my $needed = '<ul><li>'.
17627: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17628: '</li></ul>';
17629: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17630: } else {
17631: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17632: }
17633: } else {
17634: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17635: }
1.354 raeburn 17636: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17637: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17638: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17639: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17640: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17641: } else {
17642: my %crsownerstr;
17643: foreach my $item ('by','for') {
17644: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17645: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17646: if ($type eq 'default') {
17647: $crsownerstr{$item} .= $othertitle.', ';
17648: } elsif ($usertypes->{$type} ne '') {
17649: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17650: }
17651: }
17652: $crsownerstr{$item} =~ s/\Q, \E$//;
17653: }
17654: }
17655: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17656: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17657: }
1.354 raeburn 17658: } else {
1.359 raeburn 17659: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17660: }
17661: }
17662: $resulttext .= '</ul></li>';
17663: }
17664: }
17665: $resulttext .= '</ul>';
17666: } else {
17667: $resulttext = &mt('No changes made to password settings');
17668: }
1.355 raeburn 17669: my $cachetime = 24*60*60;
1.354 raeburn 17670: if ($updatedefaults) {
17671: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17672: if (ref($lastactref) eq 'HASH') {
17673: $lastactref->{'domdefaults'} = 1;
17674: }
17675: }
1.355 raeburn 17676: if ($updateconf) {
17677: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17678: if (ref($lastactref) eq 'HASH') {
17679: $lastactref->{'passwdconf'} = 1;
17680: }
17681: }
1.354 raeburn 17682: } else {
17683: $resulttext = '<span class="LC_error">'.
17684: &mt('An error occurred: [_1]',$putresult).'</span>';
17685: }
17686: if ($errors) {
17687: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17688: $errors.'</ul></p>';
17689: }
17690: return $resulttext;
17691: }
17692:
1.405 raeburn 17693: sub password_rule_changes {
17694: my ($prefix,$newvalues,$current,$changes) = @_;
17695: return unless ((ref($newvalues) eq 'HASH') &&
17696: (ref($current) eq 'HASH') &&
17697: (ref($changes) eq 'HASH'));
17698: my (@rules,%staticdefaults);
17699: if ($prefix eq 'passwords') {
17700: @rules = ('min','max','expire','numsaved');
1.421 raeburn 17701: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 17702: @rules = ('min','max');
17703: }
17704: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
17705: foreach my $rule (@rules) {
17706: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
17707: my $ruleok;
17708: if ($rule eq 'expire') {
17709: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17710: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
17711: $ruleok = 1;
17712: }
17713: } elsif ($rule eq 'min') {
17714: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
17715: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
17716: $ruleok = 1;
17717: }
17718: }
17719: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
17720: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
17721: $ruleok = 1;
17722: }
17723: if ($ruleok) {
17724: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
17725: if (exists($current->{$rule})) {
17726: if ($newvalues->{$rule} ne $current->{$rule}) {
17727: $changes->{'rules'} = 1;
17728: }
17729: } elsif ($rule eq 'min') {
17730: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
17731: $changes->{'rules'} = 1;
17732: }
17733: } else {
17734: $changes->{'rules'} = 1;
17735: }
17736: } elsif (exists($current->{$rule})) {
17737: $changes->{'rules'} = 1;
17738: }
17739: }
17740: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
17741: my @chars;
17742: foreach my $item (sort(@posschars)) {
17743: if ($item =~ /^(uc|lc|num|spec)$/) {
17744: push(@chars,$item);
17745: }
17746: }
17747: $newvalues->{'chars'} = \@chars;
17748: unless ($changes->{'rules'}) {
17749: if (ref($current->{'chars'}) eq 'ARRAY') {
17750: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
17751: if (@diffs > 0) {
17752: $changes->{'rules'} = 1;
17753: }
17754: } else {
17755: if (@chars > 0) {
17756: $changes->{'rules'} = 1;
17757: }
17758: }
17759: }
17760: return;
17761: }
17762:
1.28 raeburn 17763: sub modify_usercreation {
1.27 raeburn 17764: my ($dom,%domconfig) = @_;
1.224 raeburn 17765: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17766: my $warningmsg;
1.27 raeburn 17767: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17768: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17769: if ($key eq 'cancreate') {
17770: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17771: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17772: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17773: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17774: } else {
1.224 raeburn 17775: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17776: }
17777: }
17778: }
17779: } elsif ($key eq 'email_rule') {
17780: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17781: } else {
17782: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17783: }
1.27 raeburn 17784: }
17785: }
17786: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17787: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17788: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17789: foreach my $item(@contexts) {
1.224 raeburn 17790: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17791: }
1.34 raeburn 17792: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17793: foreach my $item (@contexts) {
1.224 raeburn 17794: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17795: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17796: }
1.27 raeburn 17797: }
1.34 raeburn 17798: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17799: foreach my $item (@contexts) {
1.43 raeburn 17800: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17801: if ($cancreate{$item} ne 'any') {
17802: push(@{$changes{'cancreate'}},$item);
17803: }
17804: } else {
17805: if ($cancreate{$item} ne 'none') {
17806: push(@{$changes{'cancreate'}},$item);
17807: }
1.27 raeburn 17808: }
17809: }
17810: } else {
1.43 raeburn 17811: foreach my $item (@contexts) {
1.34 raeburn 17812: push(@{$changes{'cancreate'}},$item);
17813: }
1.27 raeburn 17814: }
1.34 raeburn 17815:
1.27 raeburn 17816: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17817: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17818: if (!grep(/^\Q$type\E$/,@username_rule)) {
17819: push(@{$changes{'username_rule'}},$type);
17820: }
17821: }
17822: foreach my $type (@username_rule) {
17823: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17824: push(@{$changes{'username_rule'}},$type);
17825: }
17826: }
17827: } else {
17828: push(@{$changes{'username_rule'}},@username_rule);
17829: }
17830:
1.32 raeburn 17831: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17832: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17833: if (!grep(/^\Q$type\E$/,@id_rule)) {
17834: push(@{$changes{'id_rule'}},$type);
17835: }
17836: }
17837: foreach my $type (@id_rule) {
17838: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17839: push(@{$changes{'id_rule'}},$type);
17840: }
17841: }
17842: } else {
17843: push(@{$changes{'id_rule'}},@id_rule);
17844: }
17845:
1.43 raeburn 17846: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17847: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17848: my %authhash;
1.43 raeburn 17849: foreach my $item (@authen_contexts) {
1.28 raeburn 17850: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17851: foreach my $auth (@authtypes) {
17852: if (grep(/^\Q$auth\E$/,@authallowed)) {
17853: $authhash{$item}{$auth} = 1;
17854: } else {
17855: $authhash{$item}{$auth} = 0;
17856: }
17857: }
17858: }
17859: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17860: foreach my $item (@authen_contexts) {
1.28 raeburn 17861: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17862: foreach my $auth (@authtypes) {
17863: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17864: push(@{$changes{'authtypes'}},$item);
17865: last;
17866: }
17867: }
17868: }
17869: }
17870: } else {
1.43 raeburn 17871: foreach my $item (@authen_contexts) {
1.28 raeburn 17872: push(@{$changes{'authtypes'}},$item);
17873: }
17874: }
17875:
1.224 raeburn 17876: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17877: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17878: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17879: $save_usercreate{'id_rule'} = \@id_rule;
17880: $save_usercreate{'username_rule'} = \@username_rule,
17881: $save_usercreate{'authtypes'} = \%authhash;
17882:
1.27 raeburn 17883: my %usercreation_hash = (
1.224 raeburn 17884: usercreation => \%save_usercreate,
17885: );
1.27 raeburn 17886:
17887: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17888: $dom);
1.50 raeburn 17889:
1.224 raeburn 17890: if ($putresult eq 'ok') {
17891: if (keys(%changes) > 0) {
17892: $resulttext = &mt('Changes made:').'<ul>';
17893: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17894: my %lt = &usercreation_types();
17895: foreach my $type (@{$changes{'cancreate'}}) {
17896: my $chgtext = $lt{$type}.', ';
17897: if ($cancreate{$type} eq 'none') {
17898: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
17899: } elsif ($cancreate{$type} eq 'any') {
17900: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
17901: } elsif ($cancreate{$type} eq 'official') {
17902: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
17903: } elsif ($cancreate{$type} eq 'unofficial') {
17904: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
17905: }
17906: $resulttext .= '<li>'.$chgtext.'</li>';
17907: }
17908: }
17909: if (ref($changes{'username_rule'}) eq 'ARRAY') {
17910: my ($rules,$ruleorder) =
17911: &Apache::lonnet::inst_userrules($dom,'username');
17912: my $chgtext = '<ul>';
17913: foreach my $type (@username_rule) {
17914: if (ref($rules->{$type}) eq 'HASH') {
17915: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
17916: }
17917: }
17918: $chgtext .= '</ul>';
17919: if (@username_rule > 0) {
17920: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17921: } else {
17922: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
17923: }
17924: }
17925: if (ref($changes{'id_rule'}) eq 'ARRAY') {
17926: my ($idrules,$idruleorder) =
17927: &Apache::lonnet::inst_userrules($dom,'id');
17928: my $chgtext = '<ul>';
17929: foreach my $type (@id_rule) {
17930: if (ref($idrules->{$type}) eq 'HASH') {
17931: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
17932: }
17933: }
17934: $chgtext .= '</ul>';
17935: if (@id_rule > 0) {
17936: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17937: } else {
17938: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
17939: }
17940: }
17941: my %authname = &authtype_names();
17942: my %context_title = &context_names();
17943: if (ref($changes{'authtypes'}) eq 'ARRAY') {
17944: my $chgtext = '<ul>';
17945: foreach my $type (@{$changes{'authtypes'}}) {
17946: my @allowed;
17947: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
17948: foreach my $auth (@authtypes) {
17949: if ($authhash{$type}{$auth}) {
17950: push(@allowed,$authname{$auth});
17951: }
17952: }
17953: if (@allowed > 0) {
17954: $chgtext .= join(', ',@allowed).'</li>';
17955: } else {
17956: $chgtext .= &mt('none').'</li>';
17957: }
17958: }
17959: $chgtext .= '</ul>';
17960: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
17961: $resulttext .= '</li>';
17962: }
17963: $resulttext .= '</ul>';
17964: } else {
17965: $resulttext = &mt('No changes made to user creation settings');
17966: }
17967: } else {
17968: $resulttext = '<span class="LC_error">'.
17969: &mt('An error occurred: [_1]',$putresult).'</span>';
17970: }
17971: if ($warningmsg ne '') {
17972: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17973: }
17974: return $resulttext;
17975: }
17976:
17977: sub modify_selfcreation {
1.305 raeburn 17978: my ($dom,$lastactref,%domconfig) = @_;
17979: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
17980: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
17981: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 17982: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
17983: if (ref($typesref) eq 'ARRAY') {
17984: @types = @{$typesref};
17985: }
17986: if (ref($usertypesref) eq 'HASH') {
17987: %usertypes = %{$usertypesref};
1.228 raeburn 17988: }
1.303 raeburn 17989: $usertypes{'default'} = $othertitle;
1.224 raeburn 17990: #
17991: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
17992: #
17993: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17994: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
17995: if ($key eq 'cancreate') {
17996: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17997: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
17998: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 17999: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18000: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18001: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18002: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18003: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18004: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18005: } else {
18006: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18007: }
18008: }
18009: }
18010: } elsif ($key eq 'email_rule') {
18011: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18012: } else {
18013: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18014: }
18015: }
18016: }
18017: #
18018: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18019: #
18020: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18021: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18022: if ($key eq 'selfcreate') {
18023: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18024: } else {
18025: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18026: }
18027: }
18028: }
1.305 raeburn 18029: #
18030: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18031: #
18032: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18033: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18034: if ($key eq 'inststatusguest') {
18035: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18036: } else {
18037: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18038: }
18039: }
18040: }
1.224 raeburn 18041:
18042: my @contexts = ('selfcreate');
18043: @{$cancreate{'selfcreate'}} = ();
18044: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18045: if (@types) {
18046: @{$cancreate{'statustocreate'}} = ();
18047: }
1.236 raeburn 18048: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18049: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18050: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18051: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18052: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18053: my %selfcreatetypes = (
18054: sso => 'users authenticated by institutional single sign on',
18055: login => 'users authenticated by institutional log-in',
1.303 raeburn 18056: email => 'users verified by e-mail',
1.50 raeburn 18057: );
1.224 raeburn 18058: #
18059: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18060: # is permitted.
18061: #
1.305 raeburn 18062: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18063:
1.305 raeburn 18064: my (@statuses,%email_rule);
1.228 raeburn 18065: foreach my $item ('login','sso','email') {
1.224 raeburn 18066: if ($item eq 'email') {
1.236 raeburn 18067: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18068: if (@types) {
18069: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18070: foreach my $status (@poss_statuses) {
18071: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18072: push(@statuses,$status);
18073: }
18074: }
18075: $save_inststatus{'inststatusguest'} = \@statuses;
18076: } else {
18077: push(@statuses,'default');
18078: }
18079: if (@statuses) {
18080: my %curr_rule;
18081: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18082: foreach my $type (@statuses) {
18083: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18084: }
1.305 raeburn 18085: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18086: foreach my $type (@statuses) {
18087: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18088: }
18089: }
18090: push(@{$cancreate{'selfcreate'}},'email');
18091: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18092: my %curremaildom;
18093: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18094: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18095: }
18096: foreach my $type (@statuses) {
18097: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18098: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18099: }
18100: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18101: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18102: }
18103: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18104: #
18105: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18106: #
18107: my $chosen = $1;
18108: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18109: my $emaildom;
18110: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
18111: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
18112: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18113: if (ref($curremaildom{$type}) eq 'HASH') {
18114: if (exists($curremaildom{$type}{$chosen})) {
18115: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18116: push(@{$changes{'cancreate'}},'emaildomain');
18117: }
18118: } elsif ($emaildom ne '') {
18119: push(@{$changes{'cancreate'}},'emaildomain');
18120: }
18121: } elsif ($emaildom ne '') {
18122: push(@{$changes{'cancreate'}},'emaildomain');
18123: }
18124: }
18125: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18126: } elsif ($chosen eq 'custom') {
18127: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18128: $email_rule{$type} = [];
18129: if (ref($emailrules) eq 'HASH') {
18130: foreach my $rule (@possemail_rules) {
18131: if (exists($emailrules->{$rule})) {
18132: push(@{$email_rule{$type}},$rule);
18133: }
18134: }
18135: }
18136: if (@{$email_rule{$type}}) {
18137: $cancreate{'emailoptions'}{$type} = 'custom';
18138: if (ref($curr_rule{$type}) eq 'ARRAY') {
18139: if (@{$curr_rule{$type}} > 0) {
18140: foreach my $rule (@{$curr_rule{$type}}) {
18141: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18142: push(@{$changes{'email_rule'}},$type);
18143: }
18144: }
18145: }
18146: foreach my $type (@{$email_rule{$type}}) {
18147: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18148: push(@{$changes{'email_rule'}},$type);
18149: }
18150: }
18151: } else {
18152: push(@{$changes{'email_rule'}},$type);
18153: }
18154: }
18155: } else {
18156: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18157: }
18158: }
18159: }
18160: if (@types) {
18161: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18162: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18163: if (@changed) {
18164: push(@{$changes{'inststatus'}},'inststatusguest');
18165: }
18166: } else {
18167: push(@{$changes{'inststatus'}},'inststatusguest');
18168: }
18169: }
18170: } else {
18171: delete($env{'form.cancreate_email'});
18172: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18173: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18174: push(@{$changes{'inststatus'}},'inststatusguest');
18175: }
18176: }
18177: }
18178: } else {
18179: $save_inststatus{'inststatusguest'} = [];
18180: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18181: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18182: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18183: }
18184: }
1.224 raeburn 18185: }
18186: } else {
18187: if ($env{'form.cancreate_'.$item}) {
18188: push(@{$cancreate{'selfcreate'}},$item);
18189: }
18190: }
18191: }
1.305 raeburn 18192: my (%userinfo,%savecaptcha);
1.224 raeburn 18193: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18194: #
1.228 raeburn 18195: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18196: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18197: #
1.236 raeburn 18198:
1.244 raeburn 18199: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18200: push(@contexts,'emailusername');
1.305 raeburn 18201: if (@statuses) {
18202: foreach my $type (@statuses) {
1.228 raeburn 18203: if (ref($infofields) eq 'ARRAY') {
18204: foreach my $field (@{$infofields}) {
18205: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18206: $cancreate{'emailusername'}{$type}{$field} = $1;
18207: }
18208: }
1.224 raeburn 18209: }
18210: }
18211: }
18212: #
18213: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18214: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18215: #
18216:
18217: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18218: @approvalnotify = sort(@approvalnotify);
18219: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18220: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18221: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18222: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18223: push(@{$changes{'cancreate'}},'notify');
18224: }
18225: } else {
18226: if ($cancreate{'notify'}{'approval'}) {
18227: push(@{$changes{'cancreate'}},'notify');
18228: }
18229: }
18230: } elsif ($cancreate{'notify'}{'approval'}) {
18231: push(@{$changes{'cancreate'}},'notify');
18232: }
18233:
18234: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18235: }
18236: #
1.236 raeburn 18237: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18238: # institutional log-in.
18239: #
18240: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18241: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18242: ($domdefaults{'auth_def'} eq 'localauth'))) {
18243: $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.').' '.
18244: &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.');
18245: }
18246: }
18247: my @fields = ('lastname','firstname','middlename','generation',
18248: 'permanentemail','id');
1.240 raeburn 18249: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18250: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18251: #
18252: # Where usernames may created for institutional log-in and/or institutional single sign on:
18253: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18254: # may self-create accounts
18255: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18256: # which the user may supply, if institutional data is unavailable.
18257: #
18258: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18259: if (@types) {
1.305 raeburn 18260: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18261: push(@contexts,'statustocreate');
1.303 raeburn 18262: foreach my $type (@types) {
1.224 raeburn 18263: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18264: foreach my $field (@fields) {
18265: if (grep(/^\Q$field\E$/,@modifiable)) {
18266: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18267: } else {
18268: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18269: }
18270: }
18271: }
18272: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18273: foreach my $type (@types) {
1.224 raeburn 18274: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18275: foreach my $field (@fields) {
18276: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18277: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18278: push(@{$changes{'selfcreate'}},$type);
18279: last;
18280: }
18281: }
18282: }
18283: }
18284: } else {
1.303 raeburn 18285: foreach my $type (@types) {
1.224 raeburn 18286: push(@{$changes{'selfcreate'}},$type);
18287: }
18288: }
18289: }
1.240 raeburn 18290: foreach my $field (@shibfields) {
18291: if ($env{'form.shibenv_'.$field} ne '') {
18292: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18293: }
18294: }
18295: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18296: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18297: foreach my $field (@shibfields) {
18298: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18299: push(@{$changes{'cancreate'}},'shibenv');
18300: }
18301: }
18302: } else {
18303: foreach my $field (@shibfields) {
18304: if ($env{'form.shibenv_'.$field}) {
18305: push(@{$changes{'cancreate'}},'shibenv');
18306: last;
18307: }
18308: }
18309: }
18310: }
1.224 raeburn 18311: }
18312: foreach my $item (@contexts) {
18313: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18314: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18315: if (ref($cancreate{$item}) eq 'ARRAY') {
18316: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18317: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18318: push(@{$changes{'cancreate'}},$item);
18319: }
18320: }
18321: }
18322: }
18323: if (ref($cancreate{$item}) eq 'ARRAY') {
18324: foreach my $type (@{$cancreate{$item}}) {
18325: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
18326: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18327: push(@{$changes{'cancreate'}},$item);
18328: }
18329: }
18330: }
18331: }
18332: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
18333: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 18334: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
18335: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18336: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
18337: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18338: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18339: push(@{$changes{'cancreate'}},$item);
18340: }
18341: }
18342: }
1.305 raeburn 18343: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18344: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18345: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18346: push(@{$changes{'cancreate'}},$item);
18347: }
1.224 raeburn 18348: }
18349: }
18350: }
1.305 raeburn 18351: foreach my $type (keys(%{$cancreate{$item}})) {
18352: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18353: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18354: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18355: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18356: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18357: push(@{$changes{'cancreate'}},$item);
18358: }
18359: }
18360: } else {
18361: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18362: push(@{$changes{'cancreate'}},$item);
18363: }
18364: }
18365: }
1.305 raeburn 18366: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18367: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18368: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18369: push(@{$changes{'cancreate'}},$item);
18370: }
1.224 raeburn 18371: }
18372: }
18373: }
18374: }
18375: } elsif ($curr_usercreation{'cancreate'}{$item}) {
18376: if (ref($cancreate{$item}) eq 'ARRAY') {
18377: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
18378: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18379: push(@{$changes{'cancreate'}},$item);
18380: }
18381: }
1.305 raeburn 18382: }
18383: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18384: if (ref($cancreate{$item}) eq 'HASH') {
18385: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18386: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 18387: }
18388: }
18389: } elsif ($item eq 'emailusername') {
1.228 raeburn 18390: if (ref($cancreate{$item}) eq 'HASH') {
18391: foreach my $type (keys(%{$cancreate{$item}})) {
18392: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18393: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18394: if ($cancreate{$item}{$type}{$field}) {
18395: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18396: push(@{$changes{'cancreate'}},$item);
18397: }
18398: last;
18399: }
18400: }
18401: }
18402: }
1.224 raeburn 18403: }
18404: }
18405: }
18406: #
18407: # Populate %save_usercreate hash with updates to self-creation configuration.
18408: #
18409: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
18410: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 18411: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 18412: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
18413: if (ref($cancreate{'notify'}) eq 'HASH') {
18414: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
18415: }
1.236 raeburn 18416: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
18417: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
18418: }
1.303 raeburn 18419: if (ref($cancreate{'emailverified'}) eq 'HASH') {
18420: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
18421: }
1.305 raeburn 18422: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
18423: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
18424: }
1.303 raeburn 18425: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
18426: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
18427: }
1.224 raeburn 18428: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18429: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
18430: }
1.240 raeburn 18431: if (ref($cancreate{'shibenv'}) eq 'HASH') {
18432: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
18433: }
1.224 raeburn 18434: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 18435: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 18436:
18437: my %userconfig_hash = (
18438: usercreation => \%save_usercreate,
18439: usermodification => \%save_usermodify,
1.305 raeburn 18440: inststatus => \%save_inststatus,
1.224 raeburn 18441: );
1.305 raeburn 18442:
1.224 raeburn 18443: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
18444: $dom);
18445: #
1.305 raeburn 18446: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 18447: #
1.27 raeburn 18448: if ($putresult eq 'ok') {
18449: if (keys(%changes) > 0) {
18450: $resulttext = &mt('Changes made:').'<ul>';
18451: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18452: my %lt = &selfcreation_types();
1.34 raeburn 18453: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18454: my $chgtext = '';
1.45 raeburn 18455: if ($type eq 'selfcreate') {
1.50 raeburn 18456: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18457: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18458: } else {
1.224 raeburn 18459: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18460: '<ul>';
1.50 raeburn 18461: foreach my $case (@{$cancreate{$type}}) {
18462: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18463: }
18464: $chgtext .= '</ul>';
1.100 raeburn 18465: if (ref($cancreate{$type}) eq 'ARRAY') {
18466: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18467: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18468: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18469: $chgtext .= '<span class="LC_warning">'.
18470: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18471: '</span><br />';
18472: }
18473: }
18474: }
18475: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18476: if (!@statuses) {
18477: $chgtext .= '<span class="LC_warning">'.
18478: &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.").
18479: '</span><br />';
1.303 raeburn 18480:
1.100 raeburn 18481: }
18482: }
18483: }
1.43 raeburn 18484: }
1.240 raeburn 18485: } elsif ($type eq 'shibenv') {
18486: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18487: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18488: } else {
18489: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18490: '<ul>';
18491: foreach my $field (@shibfields) {
18492: next if ($cancreate{$type}{$field} eq '');
18493: if ($field eq 'inststatus') {
18494: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18495: } else {
18496: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18497: }
18498: }
18499: $chgtext .= '</ul>';
1.303 raeburn 18500: }
1.93 raeburn 18501: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18502: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18503: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18504: if (@{$cancreate{'selfcreate'}} > 0) {
18505: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18506: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18507: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18508: $chgtext .= '<br />'.
18509: '<span class="LC_warning">'.
18510: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18511: '</span>';
18512: }
1.303 raeburn 18513: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18514: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18515: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18516: } else {
18517: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18518: }
18519: $chgtext .= '<ul>';
18520: foreach my $case (@{$cancreate{$type}}) {
18521: if ($case eq 'default') {
18522: $chgtext .= '<li>'.$othertitle.'</li>';
18523: } else {
1.303 raeburn 18524: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18525: }
18526: }
1.100 raeburn 18527: $chgtext .= '</ul>';
18528: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18529: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18530: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18531: '</span>';
1.100 raeburn 18532: }
18533: }
18534: } else {
18535: if (@{$cancreate{$type}} == 0) {
18536: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18537: } else {
18538: $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 18539: }
18540: }
1.303 raeburn 18541: $chgtext .= '<br />';
1.93 raeburn 18542: }
1.236 raeburn 18543: } elsif ($type eq 'selfcreateprocessing') {
18544: my %choices = &Apache::lonlocal::texthash (
18545: automatic => 'Automatic approval',
18546: approval => 'Queued for approval',
18547: );
1.305 raeburn 18548: if (@types) {
18549: if (@statuses) {
1.303 raeburn 18550: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18551: '<ul>';
1.305 raeburn 18552: foreach my $status (@statuses) {
18553: if ($status eq 'default') {
18554: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18555: } else {
1.305 raeburn 18556: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18557: }
18558: }
18559: $chgtext .= '</ul>';
18560: }
18561: } else {
18562: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18563: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18564: }
18565: } elsif ($type eq 'emailverified') {
18566: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18567: all => 'Same as e-mail',
18568: first => 'Omit @domain',
18569: free => 'Free to choose',
1.303 raeburn 18570: );
1.305 raeburn 18571: if (@types) {
18572: if (@statuses) {
1.303 raeburn 18573: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18574: '<ul>';
1.305 raeburn 18575: foreach my $status (@statuses) {
1.362 raeburn 18576: if ($status eq 'default') {
1.305 raeburn 18577: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18578: } else {
1.305 raeburn 18579: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18580: }
18581: }
18582: $chgtext .= '</ul>';
18583: }
18584: } else {
1.305 raeburn 18585: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18586: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18587: }
1.305 raeburn 18588: } elsif ($type eq 'emailoptions') {
18589: my %options = &Apache::lonlocal::texthash (
18590: any => 'Any e-mail',
18591: inst => 'Institutional only',
18592: noninst => 'Non-institutional only',
18593: custom => 'Custom restrictions',
18594: );
18595: if (@types) {
18596: if (@statuses) {
18597: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18598: '<ul>';
18599: foreach my $status (@statuses) {
18600: if ($type eq 'default') {
18601: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18602: } else {
18603: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18604: }
18605: }
1.305 raeburn 18606: $chgtext .= '</ul>';
18607: }
18608: } else {
18609: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18610: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18611: } else {
18612: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18613: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18614: }
1.305 raeburn 18615: }
18616: } elsif ($type eq 'emaildomain') {
18617: my $output;
18618: if (@statuses) {
18619: foreach my $type (@statuses) {
18620: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18621: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18622: if ($type eq 'default') {
18623: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18624: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18625: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18626: } else {
18627: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18628: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18629: }
1.303 raeburn 18630: } else {
1.305 raeburn 18631: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18632: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18633: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18634: } else {
18635: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 18636: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 18637: }
1.303 raeburn 18638: }
1.305 raeburn 18639: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18640: if ($type eq 'default') {
18641: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18642: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18643: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18644: } else {
18645: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18646: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18647: }
1.303 raeburn 18648: } else {
1.305 raeburn 18649: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18650: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18651: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18652: } else {
18653: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 18654: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 18655: }
1.303 raeburn 18656: }
18657: }
18658: }
18659: }
1.305 raeburn 18660: }
18661: if ($output ne '') {
18662: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18663: '<ul>'.$output.'</ul>';
1.236 raeburn 18664: }
1.165 raeburn 18665: } elsif ($type eq 'captcha') {
1.224 raeburn 18666: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18667: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18668: } else {
18669: my %captchas = &captcha_phrases();
1.224 raeburn 18670: if ($captchas{$savecaptcha{$type}}) {
18671: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18672: } else {
1.210 raeburn 18673: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18674: }
18675: }
18676: } elsif ($type eq 'recaptchakeys') {
18677: my ($privkey,$pubkey);
1.224 raeburn 18678: if (ref($savecaptcha{$type}) eq 'HASH') {
18679: $pubkey = $savecaptcha{$type}{'public'};
18680: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18681: }
18682: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18683: if (!$pubkey) {
18684: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18685: } else {
18686: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18687: }
18688: if (!$privkey) {
18689: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18690: } else {
18691: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18692: }
18693: $chgtext .= '</ul>';
1.269 raeburn 18694: } elsif ($type eq 'recaptchaversion') {
18695: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18696: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18697: }
1.224 raeburn 18698: } elsif ($type eq 'emailusername') {
18699: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18700: if (@statuses) {
18701: foreach my $type (@statuses) {
1.228 raeburn 18702: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18703: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18704: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18705: '<ul>';
18706: foreach my $field (@{$infofields}) {
18707: if ($cancreate{'emailusername'}{$type}{$field}) {
18708: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18709: }
18710: }
1.245 raeburn 18711: $chgtext .= '</ul>';
18712: } else {
1.303 raeburn 18713: $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 18714: }
18715: } else {
1.303 raeburn 18716: $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 18717: }
18718: }
18719: }
18720: }
18721: } elsif ($type eq 'notify') {
1.303 raeburn 18722: my $numapprove = 0;
1.224 raeburn 18723: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18724: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18725: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18726: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18727: $numapprove ++;
1.224 raeburn 18728: }
18729: }
1.43 raeburn 18730: }
1.303 raeburn 18731: unless ($numapprove) {
18732: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18733: }
1.34 raeburn 18734: }
1.224 raeburn 18735: if ($chgtext) {
18736: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18737: }
18738: }
18739: }
1.305 raeburn 18740: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18741: my ($emailrules,$emailruleorder) =
18742: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18743: foreach my $type (@{$changes{'email_rule'}}) {
18744: if (ref($email_rule{$type}) eq 'ARRAY') {
18745: my $chgtext = '<ul>';
18746: foreach my $rule (@{$email_rule{$type}}) {
18747: if (ref($emailrules->{$rule}) eq 'HASH') {
18748: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18749: }
18750: }
18751: $chgtext .= '</ul>';
1.310 raeburn 18752: my $typename;
1.305 raeburn 18753: if (@types) {
18754: if ($type eq 'default') {
18755: $typename = $othertitle;
18756: } else {
18757: $typename = $usertypes{$type};
18758: }
18759: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18760: }
18761: if (@{$email_rule{$type}} > 0) {
18762: $resulttext .= '<li>'.
18763: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18764: $usertypes{$type}).
18765: $chgtext.
18766: '</li>';
18767: } else {
18768: $resulttext .= '<li>'.
1.310 raeburn 18769: &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 18770: '</li>'.
1.310 raeburn 18771: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18772: }
1.43 raeburn 18773: }
18774: }
1.305 raeburn 18775: }
18776: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18777: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18778: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18779: my $chgtext = '<ul>';
18780: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18781: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18782: }
18783: $chgtext .= '</ul>';
18784: $resulttext .= '<li>'.
18785: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18786: $chgtext.
18787: '</li>';
18788: } else {
18789: $resulttext .= '<li>'.
18790: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18791: '</li>';
18792: }
1.43 raeburn 18793: }
18794: }
1.224 raeburn 18795: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18796: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18797: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18798: foreach my $type (@{$changes{'selfcreate'}}) {
18799: my $typename = $type;
1.303 raeburn 18800: if (keys(%usertypes) > 0) {
18801: if ($usertypes{$type} ne '') {
18802: $typename = $usertypes{$type};
1.224 raeburn 18803: }
18804: }
18805: my @modifiable;
18806: $resulttext .= '<li>'.
18807: &mt('Self-creation of account by users with status: [_1]',
18808: '<span class="LC_cusr_emph">'.$typename.'</span>').
18809: ' - '.&mt('modifiable fields (if institutional data blank): ');
18810: foreach my $field (@fields) {
18811: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18812: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18813: }
18814: }
1.224 raeburn 18815: if (@modifiable > 0) {
18816: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18817: } else {
1.224 raeburn 18818: $resulttext .= &mt('none');
1.43 raeburn 18819: }
1.224 raeburn 18820: $resulttext .= '</li>';
1.28 raeburn 18821: }
1.224 raeburn 18822: $resulttext .= '</ul></li>';
1.28 raeburn 18823: }
1.27 raeburn 18824: $resulttext .= '</ul>';
1.305 raeburn 18825: my $cachetime = 24*60*60;
18826: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18827: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18828: if (ref($lastactref) eq 'HASH') {
18829: $lastactref->{'domdefaults'} = 1;
18830: }
1.27 raeburn 18831: } else {
1.224 raeburn 18832: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18833: }
18834: } else {
18835: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18836: &mt('An error occurred: [_1]',$putresult).'</span>';
18837: }
1.43 raeburn 18838: if ($warningmsg ne '') {
18839: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18840: }
1.23 raeburn 18841: return $resulttext;
18842: }
18843:
1.165 raeburn 18844: sub process_captcha {
1.369 raeburn 18845: my ($container,$changes,$newsettings,$currsettings) = @_;
18846: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18847: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18848: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18849: $newsettings->{'captcha'} = 'original';
18850: }
1.369 raeburn 18851: my %current;
18852: if (ref($currsettings) eq 'HASH') {
18853: %current = %{$currsettings};
18854: }
18855: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18856: if ($container eq 'cancreate') {
1.169 raeburn 18857: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18858: push(@{$changes->{'cancreate'}},'captcha');
18859: } elsif (!defined($changes->{'cancreate'})) {
18860: $changes->{'cancreate'} = ['captcha'];
18861: }
1.368 raeburn 18862: } elsif ($container eq 'passwords') {
18863: $changes->{'reset'} = 1;
1.169 raeburn 18864: } else {
18865: $changes->{'captcha'} = 1;
1.165 raeburn 18866: }
18867: }
1.269 raeburn 18868: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18869: if ($newsettings->{'captcha'} eq 'recaptcha') {
18870: $newpub = $env{'form.'.$container.'_recaptchapub'};
18871: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18872: $newpub =~ s/[^\w\-]//g;
18873: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18874: $newsettings->{'recaptchakeys'} = {
18875: public => $newpub,
18876: private => $newpriv,
18877: };
1.269 raeburn 18878: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18879: $newversion =~ s/\D//g;
18880: if ($newversion ne '2') {
18881: $newversion = 1;
18882: }
18883: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18884: }
1.369 raeburn 18885: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18886: $currpub = $current{'recaptchakeys'}{'public'};
18887: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18888: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18889: $newsettings->{'recaptchakeys'} = {
18890: public => '',
18891: private => '',
18892: }
18893: }
1.165 raeburn 18894: }
1.369 raeburn 18895: if ($current{'captcha'} eq 'recaptcha') {
18896: $currversion = $current{'recaptchaversion'};
1.269 raeburn 18897: if ($currversion ne '2') {
18898: $currversion = 1;
18899: }
18900: }
18901: if ($currversion ne $newversion) {
18902: if ($container eq 'cancreate') {
18903: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18904: push(@{$changes->{'cancreate'}},'recaptchaversion');
18905: } elsif (!defined($changes->{'cancreate'})) {
18906: $changes->{'cancreate'} = ['recaptchaversion'];
18907: }
1.368 raeburn 18908: } elsif ($container eq 'passwords') {
18909: $changes->{'reset'} = 1;
1.269 raeburn 18910: } else {
18911: $changes->{'recaptchaversion'} = 1;
18912: }
18913: }
1.165 raeburn 18914: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 18915: if ($container eq 'cancreate') {
18916: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18917: push(@{$changes->{'cancreate'}},'recaptchakeys');
18918: } elsif (!defined($changes->{'cancreate'})) {
18919: $changes->{'cancreate'} = ['recaptchakeys'];
18920: }
1.368 raeburn 18921: } elsif ($container eq 'passwords') {
18922: $changes->{'reset'} = 1;
1.169 raeburn 18923: } else {
1.210 raeburn 18924: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 18925: }
18926: }
18927: return;
18928: }
18929:
1.33 raeburn 18930: sub modify_usermodification {
18931: my ($dom,%domconfig) = @_;
1.224 raeburn 18932: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 18933: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18934: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 18935: if ($key eq 'selfcreate') {
18936: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
18937: } else {
18938: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
18939: }
1.33 raeburn 18940: }
18941: }
1.224 raeburn 18942: my @contexts = ('author','course');
1.33 raeburn 18943: my %context_title = (
18944: author => 'In author context',
18945: course => 'In course context',
18946: );
18947: my @fields = ('lastname','firstname','middlename','generation',
18948: 'permanentemail','id');
18949: my %roles = (
18950: author => ['ca','aa'],
18951: course => ['st','ep','ta','in','cr'],
18952: );
18953: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18954: foreach my $context (@contexts) {
18955: foreach my $role (@{$roles{$context}}) {
18956: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
18957: foreach my $item (@fields) {
18958: if (grep(/^\Q$item\E$/,@modifiable)) {
18959: $modifyhash{$context}{$role}{$item} = 1;
18960: } else {
18961: $modifyhash{$context}{$role}{$item} = 0;
18962: }
18963: }
18964: }
18965: if (ref($curr_usermodification{$context}) eq 'HASH') {
18966: foreach my $role (@{$roles{$context}}) {
18967: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
18968: foreach my $field (@fields) {
18969: if ($modifyhash{$context}{$role}{$field} ne
18970: $curr_usermodification{$context}{$role}{$field}) {
18971: push(@{$changes{$context}},$role);
18972: last;
18973: }
18974: }
18975: }
18976: }
18977: } else {
18978: foreach my $context (@contexts) {
18979: foreach my $role (@{$roles{$context}}) {
18980: push(@{$changes{$context}},$role);
18981: }
18982: }
18983: }
18984: }
18985: my %usermodification_hash = (
18986: usermodification => \%modifyhash,
18987: );
18988: my $putresult = &Apache::lonnet::put_dom('configuration',
18989: \%usermodification_hash,$dom);
18990: if ($putresult eq 'ok') {
18991: if (keys(%changes) > 0) {
18992: $resulttext = &mt('Changes made: ').'<ul>';
18993: foreach my $context (@contexts) {
18994: if (ref($changes{$context}) eq 'ARRAY') {
18995: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
18996: if (ref($changes{$context}) eq 'ARRAY') {
18997: foreach my $role (@{$changes{$context}}) {
18998: my $rolename;
1.224 raeburn 18999: if ($role eq 'cr') {
19000: $rolename = &mt('Custom');
1.33 raeburn 19001: } else {
1.224 raeburn 19002: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19003: }
19004: my @modifiable;
1.224 raeburn 19005: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19006: foreach my $field (@fields) {
19007: if ($modifyhash{$context}{$role}{$field}) {
19008: push(@modifiable,$fieldtitles{$field});
19009: }
19010: }
19011: if (@modifiable > 0) {
19012: $resulttext .= join(', ',@modifiable);
19013: } else {
19014: $resulttext .= &mt('none');
19015: }
19016: $resulttext .= '</li>';
19017: }
19018: $resulttext .= '</ul></li>';
19019: }
19020: }
19021: }
19022: $resulttext .= '</ul>';
19023: } else {
19024: $resulttext = &mt('No changes made to user modification settings');
19025: }
19026: } else {
19027: $resulttext = '<span class="LC_error">'.
19028: &mt('An error occurred: [_1]',$putresult).'</span>';
19029: }
19030: return $resulttext;
19031: }
19032:
1.43 raeburn 19033: sub modify_defaults {
1.212 raeburn 19034: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19035: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19036: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19037: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19038: 'portal_def');
1.325 raeburn 19039: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19040: foreach my $item (@items) {
19041: $newvalues{$item} = $env{'form.'.$item};
19042: if ($item eq 'auth_def') {
19043: if ($newvalues{$item} ne '') {
19044: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19045: push(@errors,$item);
19046: }
19047: }
19048: } elsif ($item eq 'lang_def') {
19049: if ($newvalues{$item} ne '') {
19050: if ($newvalues{$item} =~ /^(\w+)/) {
19051: my $langcode = $1;
1.103 raeburn 19052: if ($langcode ne 'x_chef') {
19053: if (code2language($langcode) eq '') {
19054: push(@errors,$item);
19055: }
1.43 raeburn 19056: }
19057: } else {
19058: push(@errors,$item);
19059: }
19060: }
1.54 raeburn 19061: } elsif ($item eq 'timezone_def') {
19062: if ($newvalues{$item} ne '') {
1.62 raeburn 19063: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19064: push(@errors,$item);
19065: }
19066: }
1.68 raeburn 19067: } elsif ($item eq 'datelocale_def') {
19068: if ($newvalues{$item} ne '') {
19069: my @datelocale_ids = DateTime::Locale->ids();
19070: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19071: push(@errors,$item);
19072: }
19073: }
1.141 raeburn 19074: } elsif ($item eq 'portal_def') {
19075: if ($newvalues{$item} ne '') {
1.414 raeburn 19076: 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])\/?$/) {
19077: foreach my $field ('email','web') {
19078: if ($env{'form.'.$item.'_'.$field}) {
19079: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19080: }
19081: }
19082: } else {
1.141 raeburn 19083: push(@errors,$item);
19084: }
19085: }
1.43 raeburn 19086: }
19087: if (grep(/^\Q$item\E$/,@errors)) {
19088: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19089: if ($item eq 'portal_def') {
19090: if ($domdefaults{$item}) {
19091: foreach my $field ('email','web') {
19092: if (exists($domdefaults{$item.'_'.$field})) {
19093: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19094: }
19095: }
19096: }
19097: }
1.43 raeburn 19098: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19099: $changes{$item} = 1;
19100: }
1.414 raeburn 19101: if ($item eq 'portal_def') {
19102: unless (grep(/^\Q$item\E$/,@errors)) {
19103: if ($newvalues{$item} eq '') {
19104: foreach my $field ('email','web') {
19105: if (exists($domdefaults{$item.'_'.$field})) {
19106: delete($domdefaults{$item.'_'.$field});
19107: }
19108: }
19109: } else {
19110: unless ($changes{$item}) {
19111: foreach my $field ('email','web') {
19112: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19113: $changes{$item} = 1;
19114: last;
19115: }
19116: }
19117: }
19118: foreach my $field ('email','web') {
19119: if ($newvalues{$item.'_'.$field}) {
19120: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19121: } elsif (exists($domdefaults{$item.'_'.$field})) {
19122: delete($domdefaults{$item.'_'.$field});
19123: }
19124: }
19125: }
19126: }
19127: }
1.72 raeburn 19128: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19129: }
1.354 raeburn 19130: my %staticdefaults = (
19131: 'intauth_cost' => 10,
19132: 'intauth_check' => 0,
19133: 'intauth_switch' => 0,
19134: );
19135: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19136: if (exists($domdefaults{$item})) {
19137: $newvalues{$item} = $domdefaults{$item};
19138: } else {
19139: $newvalues{$item} = $staticdefaults{$item};
19140: }
19141: }
1.409 raeburn 19142: my ($unamemaprules,$ruleorder);
19143: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19144: if (@possunamemaprules) {
19145: ($unamemaprules,$ruleorder) =
19146: &Apache::lonnet::inst_userrules($dom,'unamemap');
19147: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19148: if (@{$ruleorder} > 0) {
19149: my %possrules;
19150: map { $possrules{$_} = 1; } @possunamemaprules;
19151: foreach my $rule (@{$ruleorder}) {
19152: if ($possrules{$rule}) {
19153: push(@{$newvalues{'unamemap_rule'}},$rule);
19154: }
19155: }
19156: }
19157: }
19158: }
19159: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19160: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19161: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19162: $newvalues{'unamemap_rule'});
19163: if (@rulediffs) {
19164: $changes{'unamemap_rule'} = 1;
19165: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19166: }
19167: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19168: $changes{'unamemap_rule'} = 1;
19169: delete($domdefaults{'unamemap_rule'});
19170: }
19171: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19172: if (@{$newvalues{'unamemap_rule'}} > 0) {
19173: $changes{'unamemap_rule'} = 1;
19174: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19175: }
19176: }
1.43 raeburn 19177: my %defaults_hash = (
1.72 raeburn 19178: defaults => \%newvalues,
19179: );
1.43 raeburn 19180: my $title = &defaults_titles();
1.236 raeburn 19181:
19182: my $currinststatus;
19183: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19184: $currinststatus = $domconfig{'inststatus'};
19185: } else {
19186: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19187: $currinststatus = {
19188: inststatustypes => $usertypes,
19189: inststatusorder => $types,
19190: inststatusguest => [],
19191: };
19192: }
19193: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19194: my @allpos;
19195: my %alltypes;
1.305 raeburn 19196: my @inststatusguest;
19197: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19198: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19199: unless (grep(/^\Q$type\E$/,@todelete)) {
19200: push(@inststatusguest,$type);
19201: }
19202: }
19203: }
19204: my ($currtitles,$currorder);
1.236 raeburn 19205: if (ref($currinststatus) eq 'HASH') {
19206: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19207: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19208: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19209: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19210: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19211: }
19212: }
19213: unless (grep(/^\Q$type\E$/,@todelete)) {
19214: my $position = $env{'form.inststatus_pos_'.$type};
19215: $position =~ s/\D+//g;
19216: $allpos[$position] = $type;
19217: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19218: $alltypes{$type} =~ s/`//g;
19219: }
19220: }
19221: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19222: $currtitles =~ s/,$//;
19223: }
19224: }
19225: if ($env{'form.addinststatus'}) {
19226: my $newtype = $env{'form.addinststatus'};
19227: $newtype =~ s/\W//g;
19228: unless (exists($alltypes{$newtype})) {
19229: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19230: $alltypes{$newtype} =~ s/`//g;
19231: my $position = $env{'form.addinststatus_pos'};
19232: $position =~ s/\D+//g;
19233: if ($position ne '') {
19234: $allpos[$position] = $newtype;
19235: }
19236: }
19237: }
1.305 raeburn 19238: my @orderedstatus;
1.236 raeburn 19239: foreach my $type (@allpos) {
19240: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19241: push(@orderedstatus,$type);
19242: }
19243: }
19244: foreach my $type (keys(%alltypes)) {
19245: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19246: delete($alltypes{$type});
19247: }
19248: }
19249: $defaults_hash{'inststatus'} = {
19250: inststatustypes => \%alltypes,
19251: inststatusorder => \@orderedstatus,
1.305 raeburn 19252: inststatusguest => \@inststatusguest,
1.236 raeburn 19253: };
19254: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19255: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19256: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19257: }
19258: }
19259: if ($currorder ne join(',',@orderedstatus)) {
19260: $changes{'inststatus'}{'inststatusorder'} = 1;
19261: }
19262: my $newtitles;
19263: foreach my $item (@orderedstatus) {
19264: $newtitles .= $alltypes{$item}.',';
19265: }
19266: $newtitles =~ s/,$//;
19267: if ($currtitles ne $newtitles) {
19268: $changes{'inststatus'}{'inststatustypes'} = 1;
19269: }
1.43 raeburn 19270: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19271: $dom);
19272: if ($putresult eq 'ok') {
19273: if (keys(%changes) > 0) {
19274: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19275: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19276: 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";
19277: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19278: if ($item eq 'inststatus') {
19279: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19280: if (@orderedstatus) {
1.236 raeburn 19281: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19282: foreach my $type (@orderedstatus) {
19283: $resulttext .= $alltypes{$type}.', ';
19284: }
19285: $resulttext =~ s/, $//;
19286: $resulttext .= '</li>';
1.305 raeburn 19287: } else {
19288: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19289: }
19290: }
1.409 raeburn 19291: } elsif ($item eq 'unamemap_rule') {
19292: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19293: my @rulenames;
19294: if (ref($unamemaprules) eq 'HASH') {
19295: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
19296: if (ref($unamemaprules->{$rule}) eq 'HASH') {
19297: push(@rulenames,$unamemaprules->{$rule}->{'name'});
19298: }
19299: }
19300: }
19301: if (@rulenames) {
19302: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
19303: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
19304: '</li>';
19305: } else {
19306: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
19307: }
19308: } else {
19309: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
19310: }
1.236 raeburn 19311: } else {
19312: my $value = $env{'form.'.$item};
19313: if ($value eq '') {
19314: $value = &mt('none');
19315: } elsif ($item eq 'auth_def') {
19316: my %authnames = &authtype_names();
19317: my %shortauth = (
19318: internal => 'int',
19319: krb4 => 'krb4',
19320: krb5 => 'krb5',
19321: localauth => 'loc',
1.325 raeburn 19322: lti => 'lti',
1.236 raeburn 19323: );
19324: $value = $authnames{$shortauth{$value}};
19325: }
19326: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 19327: $mailmsgtext .= "$title->{$item} set to $value\n";
19328: if ($item eq 'portal_def') {
19329: if ($env{'form.'.$item} ne '') {
19330: foreach my $field ('email','web') {
19331: $value = $env{'form.'.$item.'_'.$field};
19332: if ($value) {
19333: $value = &mt('Yes');
19334: } else {
19335: $value = &mt('No');
19336: }
19337: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
19338: }
19339: }
19340: }
1.43 raeburn 19341: }
19342: }
19343: $resulttext .= '</ul>';
19344: $mailmsgtext .= "\n";
19345: my $cachetime = 24*60*60;
1.72 raeburn 19346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19347: if (ref($lastactref) eq 'HASH') {
19348: $lastactref->{'domdefaults'} = 1;
19349: }
1.68 raeburn 19350: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 19351: my $notify = 1;
19352: if (ref($domconfig{'contacts'}) eq 'HASH') {
19353: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
19354: $notify = 0;
19355: }
19356: }
19357: if ($notify) {
19358: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
19359: "LON-CAPA Domain Settings Change - $dom",
19360: $mailmsgtext);
19361: }
1.54 raeburn 19362: }
1.43 raeburn 19363: } else {
1.54 raeburn 19364: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 19365: }
19366: } else {
19367: $resulttext = '<span class="LC_error">'.
19368: &mt('An error occurred: [_1]',$putresult).'</span>';
19369: }
19370: if (@errors > 0) {
19371: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
19372: foreach my $item (@errors) {
19373: $resulttext .= ' "'.$title->{$item}.'",';
19374: }
19375: $resulttext =~ s/,$//;
19376: }
19377: return $resulttext;
19378: }
19379:
1.46 raeburn 19380: sub modify_scantron {
1.205 raeburn 19381: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 19382: my ($resulttext,%confhash,%changes,$errors);
19383: my $custom = 'custom.tab';
19384: my $default = 'default.tab';
19385: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 19386: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 19387: &config_check($dom,$confname,$servadm);
19388: if ($env{'form.scantronformat.filename'} ne '') {
19389: my $error;
19390: if ($configuserok eq 'ok') {
19391: if ($switchserver) {
1.130 raeburn 19392: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 19393: } else {
19394: if ($author_ok eq 'ok') {
1.421 raeburn 19395: my $modified = [];
1.46 raeburn 19396: my ($result,$scantronurl) =
1.421 raeburn 19397: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
19398: $confname,'scantron','','',$custom,
19399: $modified);
1.46 raeburn 19400: if ($result eq 'ok') {
19401: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 19402: $changes{'scantronformat'} = 1;
1.421 raeburn 19403: &update_modify_urls($r,$modified);
1.46 raeburn 19404: } else {
19405: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
19406: }
19407: } else {
19408: $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);
19409: }
19410: }
19411: } else {
19412: $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);
19413: }
19414: if ($error) {
19415: &Apache::lonnet::logthis($error);
19416: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
19417: }
19418: }
1.48 raeburn 19419: if (ref($domconfig{'scantron'}) eq 'HASH') {
19420: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
19421: if ($env{'form.scantronformat_del'}) {
19422: $confhash{'scantron'}{'scantronformat'} = '';
19423: $changes{'scantronformat'} = 1;
1.347 raeburn 19424: } else {
19425: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 19426: }
19427: }
19428: }
1.347 raeburn 19429: my @options = ('hdr','pad','rem');
1.346 raeburn 19430: my @fields = &scantroncsv_fields();
19431: my %titles = &scantronconfig_titles();
1.347 raeburn 19432: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 19433: my ($newdat,$currdat,%newcol,%currcol);
19434: if (grep(/^dat$/,@formats)) {
19435: $confhash{'scantron'}{config}{dat} = 1;
19436: $newdat = 1;
19437: } else {
19438: $newdat = 0;
19439: }
19440: if (grep(/^csv$/,@formats)) {
19441: my %bynum;
19442: foreach my $field (@fields) {
19443: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
19444: my $posscol = $1;
19445: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 19446: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 19447: $bynum{$posscol} = $field;
19448: $newcol{$field} = $posscol;
19449: }
19450: }
19451: }
1.347 raeburn 19452: if (keys(%newcol)) {
19453: foreach my $option (@options) {
19454: if ($env{'form.scantroncsv_'.$option}) {
19455: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
19456: }
19457: }
19458: }
1.346 raeburn 19459: }
19460: $currdat = 1;
19461: if (ref($domconfig{'scantron'}) eq 'HASH') {
19462: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 19463: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 19464: $currdat = 0;
19465: }
19466: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19467: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19468: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
19469: }
1.346 raeburn 19470: }
19471: }
19472: }
19473: if ($currdat != $newdat) {
19474: $changes{'config'} = 1;
19475: } else {
19476: foreach my $field (@fields) {
19477: if ($currcol{$field} ne '') {
19478: if ($currcol{$field} ne $newcol{$field}) {
19479: $changes{'config'} = 1;
19480: last;
1.347 raeburn 19481: }
1.346 raeburn 19482: } elsif ($newcol{$field} ne '') {
19483: $changes{'config'} = 1;
19484: last;
19485: }
19486: }
19487: }
1.46 raeburn 19488: if (keys(%confhash) > 0) {
19489: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
19490: $dom);
19491: if ($putresult eq 'ok') {
19492: if (keys(%changes) > 0) {
1.48 raeburn 19493: if (ref($confhash{'scantron'}) eq 'HASH') {
19494: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 19495: if ($changes{'scantronformat'}) {
19496: if ($confhash{'scantron'}{'scantronformat'} eq '') {
19497: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
19498: } else {
19499: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
19500: }
19501: }
1.347 raeburn 19502: if ($changes{'config'}) {
1.346 raeburn 19503: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
19504: if ($confhash{'scantron'}{'config'}{'dat'}) {
19505: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
19506: }
19507: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19508: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19509: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
19510: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
19511: foreach my $field (@fields) {
19512: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
19513: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
19514: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
19515: }
19516: }
19517: $resulttext .= '</ul></li>';
19518: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
19519: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
19520: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
19521: foreach my $option (@options) {
19522: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
19523: $resulttext .= '<li>'.$titles{$option}.'</li>';
19524: }
19525: }
19526: $resulttext .= '</ul></li>';
19527: }
1.346 raeburn 19528: }
19529: }
19530: }
19531: }
19532: } else {
19533: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
19534: }
1.46 raeburn 19535: }
1.48 raeburn 19536: $resulttext .= '</ul>';
19537: } else {
1.130 raeburn 19538: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 19539: }
19540: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 19541: if (ref($lastactref) eq 'HASH') {
19542: $lastactref->{'domainconfig'} = 1;
19543: }
1.46 raeburn 19544: } else {
1.346 raeburn 19545: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 19546: }
19547: } else {
19548: $resulttext = '<span class="LC_error">'.
19549: &mt('An error occurred: [_1]',$putresult).'</span>';
19550: }
19551: } else {
1.130 raeburn 19552: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 19553: }
19554: if ($errors) {
1.353 raeburn 19555: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
19556: $errors.'</ul></p>';
1.46 raeburn 19557: }
19558: return $resulttext;
19559: }
19560:
1.48 raeburn 19561: sub modify_coursecategories {
1.239 raeburn 19562: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 19563: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19564: $cathash);
1.48 raeburn 19565: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19566: my @catitems = ('unauth','auth');
19567: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19568: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19569: $cathash = $domconfig{'coursecategories'}{'cats'};
19570: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19571: $changes{'togglecats'} = 1;
19572: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19573: }
19574: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19575: $changes{'categorize'} = 1;
19576: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19577: }
1.120 raeburn 19578: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19579: $changes{'togglecatscomm'} = 1;
19580: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19581: }
19582: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19583: $changes{'categorizecomm'} = 1;
19584: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19585:
19586: }
19587: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19588: $changes{'togglecatsplace'} = 1;
19589: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19590: }
19591: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19592: $changes{'categorizeplace'} = 1;
19593: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19594: }
1.238 raeburn 19595: foreach my $item (@catitems) {
19596: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19597: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19598: $changes{$item} = 1;
19599: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19600: }
19601: }
19602: }
1.57 raeburn 19603: } else {
19604: $changes{'togglecats'} = 1;
19605: $changes{'categorize'} = 1;
1.124 raeburn 19606: $changes{'togglecatscomm'} = 1;
19607: $changes{'categorizecomm'} = 1;
1.272 raeburn 19608: $changes{'togglecatsplace'} = 1;
19609: $changes{'categorizeplace'} = 1;
1.87 raeburn 19610: $domconfig{'coursecategories'} = {
19611: togglecats => $env{'form.togglecats'},
19612: categorize => $env{'form.categorize'},
1.124 raeburn 19613: togglecatscomm => $env{'form.togglecatscomm'},
19614: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19615: togglecatsplace => $env{'form.togglecatsplace'},
19616: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19617: };
1.238 raeburn 19618: foreach my $item (@catitems) {
19619: if ($env{'form.coursecat_'.$item} ne 'std') {
19620: $changes{$item} = 1;
19621: }
19622: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19623: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19624: }
19625: }
1.57 raeburn 19626: }
19627: if (ref($cathash) eq 'HASH') {
19628: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19629: push (@deletecategory,'instcode::0');
19630: }
1.120 raeburn 19631: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19632: push(@deletecategory,'communities::0');
19633: }
1.272 raeburn 19634: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19635: push(@deletecategory,'placement::0');
19636: }
1.48 raeburn 19637: }
1.57 raeburn 19638: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19639: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19640: if (@deletecategory > 0) {
19641: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19642: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19643: foreach my $item (@deletecategory) {
1.57 raeburn 19644: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19645: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19646: $deletions{$item} = 1;
1.57 raeburn 19647: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19648: }
19649: }
19650: }
1.57 raeburn 19651: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19652: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19653: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19654: $reorderings{$item} = 1;
1.57 raeburn 19655: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19656: }
19657: if ($env{'form.addcategory_name_'.$item} ne '') {
19658: my $newcat = $env{'form.addcategory_name_'.$item};
19659: my $newdepth = $depth+1;
19660: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19661: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19662: $adds{$newitem} = 1;
19663: }
19664: if ($env{'form.subcat_'.$item} ne '') {
19665: my $newcat = $env{'form.subcat_'.$item};
19666: my $newdepth = $depth+1;
19667: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19668: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19669: $adds{$newitem} = 1;
19670: }
19671: }
19672: }
19673: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19674: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19675: my $newitem = 'instcode::0';
1.57 raeburn 19676: if ($cathash->{$newitem} eq '') {
19677: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19678: $adds{$newitem} = 1;
19679: }
19680: } else {
19681: my $newitem = 'instcode::0';
1.57 raeburn 19682: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19683: $adds{$newitem} = 1;
19684: }
19685: }
1.120 raeburn 19686: if ($env{'form.communities'} eq '1') {
19687: if (ref($cathash) eq 'HASH') {
19688: my $newitem = 'communities::0';
19689: if ($cathash->{$newitem} eq '') {
19690: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19691: $adds{$newitem} = 1;
19692: }
19693: } else {
19694: my $newitem = 'communities::0';
19695: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19696: $adds{$newitem} = 1;
19697: }
19698: }
1.272 raeburn 19699: if ($env{'form.placement'} eq '1') {
19700: if (ref($cathash) eq 'HASH') {
19701: my $newitem = 'placement::0';
19702: if ($cathash->{$newitem} eq '') {
19703: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19704: $adds{$newitem} = 1;
19705: }
19706: } else {
19707: my $newitem = 'placement::0';
19708: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19709: $adds{$newitem} = 1;
19710: }
19711: }
1.48 raeburn 19712: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19713: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19714: ($env{'form.addcategory_name'} ne 'communities') &&
19715: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19716: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19717: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19718: $adds{$newitem} = 1;
19719: }
1.48 raeburn 19720: }
1.57 raeburn 19721: my $putresult;
1.48 raeburn 19722: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19723: if (keys(%deletions) > 0) {
19724: foreach my $key (keys(%deletions)) {
19725: if ($predelallitems{$key} ne '') {
19726: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19727: }
19728: }
19729: }
19730: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19731: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19732: if (ref($chkcats[0]) eq 'ARRAY') {
19733: my $depth = 0;
19734: my $chg = 0;
19735: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19736: my $name = $chkcats[0][$i];
19737: my $item;
19738: if ($name eq '') {
19739: $chg ++;
19740: } else {
19741: $item = &escape($name).'::0';
19742: if ($chg) {
1.57 raeburn 19743: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19744: }
19745: $depth ++;
1.57 raeburn 19746: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19747: $depth --;
19748: }
19749: }
19750: }
1.57 raeburn 19751: }
19752: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19753: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19754: if ($putresult eq 'ok') {
1.57 raeburn 19755: my %title = (
1.120 raeburn 19756: togglecats => 'Show/Hide a course in catalog',
19757: categorize => 'Assign a category to a course',
19758: togglecatscomm => 'Show/Hide a community in catalog',
19759: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19760: );
19761: my %level = (
1.120 raeburn 19762: dom => 'set in Domain ("Modify Course/Community")',
19763: crs => 'set in Course ("Course Configuration")',
19764: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19765: none => 'No catalog',
19766: std => 'Standard catalog',
19767: domonly => 'Domain-only catalog',
19768: codesrch => 'Code search form',
1.57 raeburn 19769: );
1.48 raeburn 19770: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19771: if ($changes{'togglecats'}) {
19772: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19773: }
19774: if ($changes{'categorize'}) {
19775: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19776: }
1.120 raeburn 19777: if ($changes{'togglecatscomm'}) {
19778: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19779: }
19780: if ($changes{'categorizecomm'}) {
19781: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19782: }
1.238 raeburn 19783: if ($changes{'unauth'}) {
19784: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19785: }
19786: if ($changes{'auth'}) {
19787: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19788: }
1.57 raeburn 19789: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19790: my $cathash;
19791: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19792: $cathash = $domconfig{'coursecategories'}{'cats'};
19793: } else {
19794: $cathash = {};
19795: }
19796: my (@cats,@trails,%allitems);
19797: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19798: if (keys(%deletions) > 0) {
19799: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19800: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19801: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19802: }
19803: $resulttext .= '</ul></li>';
19804: }
19805: if (keys(%reorderings) > 0) {
19806: my %sort_by_trail;
19807: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19808: foreach my $key (keys(%reorderings)) {
19809: if ($allitems{$key} ne '') {
19810: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19811: }
1.48 raeburn 19812: }
1.57 raeburn 19813: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19814: $resulttext .= '<li>'.$trails[$trail].'</li>';
19815: }
19816: $resulttext .= '</ul></li>';
1.48 raeburn 19817: }
1.57 raeburn 19818: if (keys(%adds) > 0) {
19819: my %sort_by_trail;
19820: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19821: foreach my $key (keys(%adds)) {
19822: if ($allitems{$key} ne '') {
19823: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19824: }
19825: }
19826: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19827: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19828: }
1.57 raeburn 19829: $resulttext .= '</ul></li>';
1.48 raeburn 19830: }
1.364 raeburn 19831: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19832: if (ref($lastactref) eq 'HASH') {
19833: $lastactref->{'cats'} = 1;
19834: }
1.48 raeburn 19835: }
19836: $resulttext .= '</ul>';
1.239 raeburn 19837: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19838: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19839: if ($changes{'auth'}) {
19840: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19841: }
19842: if ($changes{'unauth'}) {
19843: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19844: }
19845: my $cachetime = 24*60*60;
19846: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19847: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19848: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19849: }
19850: }
1.48 raeburn 19851: } else {
19852: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19853: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19854: }
19855: } else {
1.120 raeburn 19856: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19857: }
19858: return $resulttext;
19859: }
19860:
1.69 raeburn 19861: sub modify_serverstatuses {
19862: my ($dom,%domconfig) = @_;
19863: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19864: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19865: %currserverstatus = %{$domconfig{'serverstatuses'}};
19866: }
19867: my @pages = &serverstatus_pages();
19868: foreach my $type (@pages) {
19869: $newserverstatus{$type}{'namedusers'} = '';
19870: $newserverstatus{$type}{'machines'} = '';
19871: if (defined($env{'form.'.$type.'_namedusers'})) {
19872: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19873: my @okusers;
19874: foreach my $user (@users) {
19875: my ($uname,$udom) = split(/:/,$user);
19876: if (($udom =~ /^$match_domain$/) &&
19877: (&Apache::lonnet::domain($udom)) &&
19878: ($uname =~ /^$match_username$/)) {
19879: if (!grep(/^\Q$user\E/,@okusers)) {
19880: push(@okusers,$user);
19881: }
19882: }
19883: }
19884: if (@okusers > 0) {
19885: @okusers = sort(@okusers);
19886: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19887: }
19888: }
19889: if (defined($env{'form.'.$type.'_machines'})) {
19890: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19891: my @okmachines;
19892: foreach my $ip (@machines) {
19893: my @parts = split(/\./,$ip);
19894: next if (@parts < 4);
19895: my $badip = 0;
19896: for (my $i=0; $i<4; $i++) {
19897: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19898: $badip = 1;
19899: last;
19900: }
19901: }
19902: if (!$badip) {
19903: push(@okmachines,$ip);
19904: }
19905: }
19906: @okmachines = sort(@okmachines);
19907: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19908: }
19909: }
19910: my %serverstatushash = (
19911: serverstatuses => \%newserverstatus,
19912: );
19913: foreach my $type (@pages) {
1.83 raeburn 19914: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19915: my (@current,@new);
1.83 raeburn 19916: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19917: if ($currserverstatus{$type}{$setting} ne '') {
19918: @current = split(/,/,$currserverstatus{$type}{$setting});
19919: }
19920: }
19921: if ($newserverstatus{$type}{$setting} ne '') {
19922: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19923: }
19924: if (@current > 0) {
19925: if (@new > 0) {
19926: foreach my $item (@current) {
19927: if (!grep(/^\Q$item\E$/,@new)) {
19928: $changes{$type}{$setting} = 1;
1.82 raeburn 19929: last;
19930: }
19931: }
1.84 raeburn 19932: foreach my $item (@new) {
19933: if (!grep(/^\Q$item\E$/,@current)) {
19934: $changes{$type}{$setting} = 1;
19935: last;
1.82 raeburn 19936: }
19937: }
19938: } else {
1.83 raeburn 19939: $changes{$type}{$setting} = 1;
1.69 raeburn 19940: }
1.83 raeburn 19941: } elsif (@new > 0) {
19942: $changes{$type}{$setting} = 1;
1.69 raeburn 19943: }
19944: }
19945: }
19946: if (keys(%changes) > 0) {
1.81 raeburn 19947: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19948: my $putresult = &Apache::lonnet::put_dom('configuration',
19949: \%serverstatushash,$dom);
19950: if ($putresult eq 'ok') {
19951: $resulttext .= &mt('Changes made:').'<ul>';
19952: foreach my $type (@pages) {
1.84 raeburn 19953: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19954: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19955: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19956: if ($newserverstatus{$type}{'namedusers'} eq '') {
19957: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19958: } else {
19959: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19960: }
1.84 raeburn 19961: }
19962: if ($changes{$type}{'machines'}) {
1.69 raeburn 19963: if ($newserverstatus{$type}{'machines'} eq '') {
19964: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19965: } else {
19966: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19967: }
19968:
19969: }
19970: $resulttext .= '</ul></li>';
19971: }
19972: }
19973: $resulttext .= '</ul>';
19974: } else {
19975: $resulttext = '<span class="LC_error">'.
19976: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19977:
19978: }
19979: } else {
19980: $resulttext = &mt('No changes made to access to server status pages');
19981: }
19982: return $resulttext;
19983: }
19984:
1.118 jms 19985: sub modify_helpsettings {
1.285 raeburn 19986: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19987: my ($resulttext,$errors,%changes,%helphash);
19988: my %defaultchecked = ('submitbugs' => 'on');
19989: my @offon = ('off','on');
1.118 jms 19990: my @toggles = ('submitbugs');
1.285 raeburn 19991: my %current = ('submitbugs' => '',
19992: 'adhoc' => {},
19993: );
1.118 jms 19994: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19995: %current = %{$domconfig{'helpsettings'}};
19996: }
1.285 raeburn 19997: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19998: foreach my $item (@toggles) {
19999: if ($defaultchecked{$item} eq 'on') {
20000: if ($current{$item} eq '') {
20001: if ($env{'form.'.$item} eq '0') {
20002: $changes{$item} = 1;
20003: }
20004: } elsif ($current{$item} ne $env{'form.'.$item}) {
20005: $changes{$item} = 1;
20006: }
20007: } elsif ($defaultchecked{$item} eq 'off') {
20008: if ($current{$item} eq '') {
20009: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20010: $changes{$item} = 1;
20011: }
1.282 raeburn 20012: } elsif ($current{$item} ne $env{'form.'.$item}) {
20013: $changes{$item} = 1;
20014: }
20015: }
20016: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20017: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20018: }
20019: }
1.285 raeburn 20020: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20021: my $confname = $dom.'-domainconfig';
20022: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20023: my (@allpos,%newsettings,%changedprivs,$newrole);
20024: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20025: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20026: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20027: my %lt = &Apache::lonlocal::texthash(
20028: s => 'system',
20029: d => 'domain',
20030: order => 'Display order',
20031: access => 'Role usage',
1.291 raeburn 20032: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20033: dh => 'All with domain helpdesk role',
20034: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20035: none => 'None',
20036: status => 'Determined based on institutional status',
20037: inc => 'Include all, but exclude specific personnel',
20038: exc => 'Exclude all, but include specific personnel',
20039: );
20040: for (my $num=0; $num<=$maxnum; $num++) {
20041: my ($prefix,$identifier,$rolename,%curr);
20042: if ($num == $maxnum) {
20043: next unless ($env{'form.newcusthelp'} == $maxnum);
20044: $identifier = 'custhelp'.$num;
20045: $prefix = 'helproles_'.$num;
20046: $rolename = $env{'form.custhelpname'.$num};
20047: $rolename=~s/[^A-Za-z0-9]//gs;
20048: next if ($rolename eq '');
20049: next if (exists($existing{'rolesdef_'.$rolename}));
20050: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20051: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20052: $newprivs{'c'},$confname,$dom);
20053: if ($result ne 'ok') {
20054: $errors .= '<li><span class="LC_error">'.
20055: &mt('An error occurred storing the new custom role: [_1]',
20056: $result).'</span></li>';
20057: next;
20058: } else {
20059: $changedprivs{$rolename} = \%newprivs;
20060: $newrole = $rolename;
20061: }
20062: } else {
20063: $prefix = 'helproles_'.$num;
20064: $rolename = $env{'form.'.$prefix};
20065: next if ($rolename eq '');
20066: next unless (exists($existing{'rolesdef_'.$rolename}));
20067: $identifier = 'custhelp'.$num;
20068: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20069: my %currprivs;
1.289 raeburn 20070: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20071: split(/\_/,$existing{'rolesdef_'.$rolename});
20072: foreach my $level ('c','d','s') {
20073: if ($newprivs{$level} ne $currprivs{$level}) {
20074: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20075: $newprivs{'c'},$confname,$dom);
20076: if ($result ne 'ok') {
20077: $errors .= '<li><span class="LC_error">'.
20078: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20079: $rolename,$result).'</span></li>';
20080: } else {
20081: $changedprivs{$rolename} = \%newprivs;
20082: }
20083: last;
20084: }
20085: }
20086: if (ref($current{'adhoc'}) eq 'HASH') {
20087: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20088: %curr = %{$current{'adhoc'}{$rolename}};
20089: }
20090: }
20091: }
20092: my $newpos = $env{'form.'.$prefix.'_pos'};
20093: $newpos =~ s/\D+//g;
20094: $allpos[$newpos] = $rolename;
20095: my $newdesc = $env{'form.'.$prefix.'_desc'};
20096: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20097: if ($curr{'desc'}) {
20098: if ($curr{'desc'} ne $newdesc) {
20099: $changes{'customrole'}{$rolename}{'desc'} = 1;
20100: $newsettings{$rolename}{'desc'} = $newdesc;
20101: }
20102: } elsif ($newdesc ne '') {
20103: $changes{'customrole'}{$rolename}{'desc'} = 1;
20104: $newsettings{$rolename}{'desc'} = $newdesc;
20105: }
20106: my $access = $env{'form.'.$prefix.'_access'};
20107: if (grep(/^\Q$access\E$/,@accesstypes)) {
20108: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20109: if ($access eq 'status') {
20110: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20111: if (scalar(@statuses) == 0) {
1.289 raeburn 20112: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20113: } else {
20114: my (@shownstatus,$numtypes);
20115: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20116: if (ref($types) eq 'ARRAY') {
20117: $numtypes = scalar(@{$types});
20118: foreach my $type (sort(@statuses)) {
20119: if ($type eq 'default') {
20120: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20121: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20122: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20123: push(@shownstatus,$usertypes->{$type});
20124: }
20125: }
20126: }
20127: if (grep(/^default$/,@statuses)) {
20128: push(@shownstatus,$othertitle);
20129: }
20130: if (scalar(@shownstatus) == 1+$numtypes) {
20131: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20132: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20133: } else {
20134: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20135: if (ref($curr{'status'}) eq 'ARRAY') {
20136: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20137: if (@diffs) {
20138: $changes{'customrole'}{$rolename}{$access} = 1;
20139: }
20140: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20141: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20142: }
1.166 raeburn 20143: }
20144: }
1.285 raeburn 20145: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20146: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20147: my @newspecstaff;
20148: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20149: foreach my $person (sort(@personnel)) {
20150: if ($domhelpdesk{$person}) {
20151: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20152: }
20153: }
20154: if (ref($curr{$access}) eq 'ARRAY') {
20155: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20156: if (@diffs) {
20157: $changes{'customrole'}{$rolename}{$access} = 1;
20158: }
20159: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20160: $changes{'customrole'}{$rolename}{$access} = 1;
20161: }
20162: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20163: my ($uname,$udom) = split(/:/,$person);
20164: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20165: }
20166: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20167: }
1.285 raeburn 20168: } else {
20169: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20170: }
20171: unless ($curr{'access'} eq $access) {
20172: $changes{'customrole'}{$rolename}{'access'} = 1;
20173: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20174: }
20175: }
1.285 raeburn 20176: if (@allpos > 0) {
20177: my $idx = 0;
20178: foreach my $rolename (@allpos) {
20179: if ($rolename ne '') {
20180: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20181: if (ref($current{'adhoc'}) eq 'HASH') {
20182: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20183: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20184: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20185: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20186: }
20187: }
1.282 raeburn 20188: }
1.285 raeburn 20189: $idx ++;
1.166 raeburn 20190: }
20191: }
1.118 jms 20192: }
1.123 jms 20193: my $putresult;
20194: if (keys(%changes) > 0) {
1.166 raeburn 20195: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20196: if ($putresult eq 'ok') {
1.285 raeburn 20197: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20198: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20199: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20200: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20201: }
20202: }
20203: my $cachetime = 24*60*60;
20204: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20205: if (ref($lastactref) eq 'HASH') {
20206: $lastactref->{'domdefaults'} = 1;
20207: }
20208: } else {
20209: $errors .= '<li><span class="LC_error">'.
20210: &mt('An error occurred storing the settings: [_1]',
20211: $putresult).'</span></li>';
20212: }
20213: }
20214: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20215: $resulttext = &mt('Changes made:').'<ul>';
20216: my (%shownprivs,@levelorder);
20217: @levelorder = ('c','d','s');
20218: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20219: foreach my $item (sort(keys(%changes))) {
20220: if ($item eq 'submitbugs') {
20221: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20222: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20223: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20224: } elsif ($item eq 'customrole') {
20225: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20226: my @keyorder = ('order','desc','access','status','exc','inc');
20227: my %keytext = &Apache::lonlocal::texthash(
20228: order => 'Order',
20229: desc => 'Role description',
20230: access => 'Role usage',
1.300 droeschl 20231: status => 'Allowed institutional types',
1.285 raeburn 20232: exc => 'Allowed personnel',
20233: inc => 'Disallowed personnel',
20234: );
1.282 raeburn 20235: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20236: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20237: if ($role eq $newrole) {
20238: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20239: $role).'<ul>';
20240: } else {
20241: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20242: $role).'<ul>';
20243: }
20244: foreach my $key (@keyorder) {
20245: if ($changes{'customrole'}{$role}{$key}) {
20246: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20247: $keytext{$key},$newsettings{$role}{$key}).
20248: '</li>';
20249: }
20250: }
20251: if (ref($changedprivs{$role}) eq 'HASH') {
20252: $shownprivs{$role} = 1;
20253: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20254: foreach my $level (@levelorder) {
20255: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20256: next if ($item eq '');
20257: my ($priv) = split(/\&/,$item,2);
20258: if (&Apache::lonnet::plaintext($priv)) {
20259: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20260: unless ($level eq 'c') {
20261: $resulttext .= ' ('.$lt{$level}.')';
20262: }
20263: $resulttext .= '</li>';
20264: }
20265: }
20266: }
20267: $resulttext .= '</ul>';
20268: }
20269: $resulttext .= '</ul></li>';
20270: }
20271: }
20272: }
20273: }
20274: }
20275: }
20276: if (keys(%changedprivs)) {
20277: foreach my $role (sort(keys(%changedprivs))) {
20278: unless ($shownprivs{$role}) {
20279: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20280: $role).'<ul>'.
20281: '<li>'.&mt('Privileges set to :').'<ul>';
20282: foreach my $level (@levelorder) {
20283: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20284: next if ($item eq '');
20285: my ($priv) = split(/\&/,$item,2);
20286: if (&Apache::lonnet::plaintext($priv)) {
20287: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20288: unless ($level eq 'c') {
20289: $resulttext .= ' ('.$lt{$level}.')';
20290: }
20291: $resulttext .= '</li>';
20292: }
1.282 raeburn 20293: }
20294: }
1.285 raeburn 20295: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20296: }
20297: }
20298: }
1.285 raeburn 20299: $resulttext .= '</ul>';
20300: } else {
20301: $resulttext = &mt('No changes made to help settings');
1.118 jms 20302: }
20303: if ($errors) {
1.168 raeburn 20304: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20305: $errors.'</ul>';
1.118 jms 20306: }
20307: return $resulttext;
20308: }
20309:
1.121 raeburn 20310: sub modify_coursedefaults {
1.212 raeburn 20311: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20312: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20313: my %defaultchecked = (
20314: 'canuse_pdfforms' => 'off',
20315: 'uselcmath' => 'on',
1.398 raeburn 20316: 'usejsme' => 'on',
20317: 'inline_chem' => 'on',
1.404 raeburn 20318: 'ltiauth' => 'off',
1.257 raeburn 20319: );
1.404 raeburn 20320: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 20321: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20322: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
20323: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
20324: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 20325: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 20326: my %staticdefaults = (
20327: anonsurvey_threshold => 10,
20328: uploadquota => 500,
1.257 raeburn 20329: postsubmit => 60,
1.276 raeburn 20330: mysqltables => 172800,
1.422 raeburn 20331: domexttool => 1,
1.198 raeburn 20332: );
1.314 raeburn 20333: my %texoptions = (
20334: MathJax => 'MathJax',
20335: mimetex => &mt('Convert to Images'),
20336: tth => &mt('TeX to HTML'),
20337: );
1.121 raeburn 20338: $defaultshash{'coursedefaults'} = {};
20339:
20340: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
20341: if ($domconfig{'coursedefaults'} eq '') {
20342: $domconfig{'coursedefaults'} = {};
20343: }
20344: }
20345:
20346: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
20347: foreach my $item (@toggles) {
20348: if ($defaultchecked{$item} eq 'on') {
20349: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20350: ($env{'form.'.$item} eq '0')) {
20351: $changes{$item} = 1;
1.192 raeburn 20352: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 20353: $changes{$item} = 1;
20354: }
20355: } elsif ($defaultchecked{$item} eq 'off') {
20356: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20357: ($env{'form.'.$item} eq '1')) {
20358: $changes{$item} = 1;
20359: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
20360: $changes{$item} = 1;
20361: }
20362: }
20363: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
20364: }
1.198 raeburn 20365: foreach my $item (@numbers) {
20366: my ($currdef,$newdef);
1.208 raeburn 20367: $newdef = $env{'form.'.$item};
1.198 raeburn 20368: if ($item eq 'anonsurvey_threshold') {
20369: $currdef = $domconfig{'coursedefaults'}{$item};
20370: $newdef =~ s/\D//g;
20371: if ($newdef eq '' || $newdef < 1) {
20372: $newdef = 1;
20373: }
20374: $defaultshash{'coursedefaults'}{$item} = $newdef;
20375: } else {
1.276 raeburn 20376: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
20377: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
20378: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 20379: }
20380: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 20381: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 20382: }
20383: if ($currdef ne $newdef) {
20384: if ($item eq 'anonsurvey_threshold') {
20385: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
20386: $changes{$item} = 1;
20387: }
1.276 raeburn 20388: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 20389: my $setting = $1;
1.276 raeburn 20390: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
20391: $changes{$setting} = 1;
1.198 raeburn 20392: }
20393: }
1.139 raeburn 20394: }
20395: }
1.314 raeburn 20396: my $texengine;
20397: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
20398: $texengine = $env{'form.texengine'};
1.349 raeburn 20399: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
20400: if ($currdef eq '') {
20401: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 20402: $changes{'texengine'} = 1;
20403: }
1.349 raeburn 20404: } elsif ($currdef ne $texengine) {
1.314 raeburn 20405: $changes{'texengine'} = 1;
20406: }
20407: }
20408: if ($texengine ne '') {
20409: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
20410: }
1.264 raeburn 20411: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
20412: my @currclonecode;
20413: if (ref($currclone) eq 'HASH') {
20414: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
20415: @currclonecode = @{$currclone->{'instcode'}};
20416: }
20417: }
20418: my $newclone;
1.289 raeburn 20419: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 20420: $newclone = $env{'form.canclone'};
20421: }
20422: if ($newclone eq 'instcode') {
20423: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
20424: my (%codedefaults,@code_order,@clonecode);
20425: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
20426: \@code_order);
20427: foreach my $item (@code_order) {
20428: if (grep(/^\Q$item\E$/,@newcodes)) {
20429: push(@clonecode,$item);
20430: }
20431: }
20432: if (@clonecode) {
20433: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
20434: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
20435: if (@diffs) {
20436: $changes{'canclone'} = 1;
20437: }
20438: } else {
20439: $newclone eq '';
20440: }
20441: } elsif ($newclone ne '') {
1.289 raeburn 20442: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
20443: }
1.264 raeburn 20444: if ($newclone ne $currclone) {
20445: $changes{'canclone'} = 1;
20446: }
1.257 raeburn 20447: my %credits;
20448: foreach my $type (@types) {
20449: unless ($type eq 'community') {
20450: $credits{$type} = $env{'form.'.$type.'_credits'};
20451: $credits{$type} =~ s/[^\d.]+//g;
20452: }
20453: }
20454: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
20455: ($env{'form.coursecredits'} eq '1')) {
20456: $changes{'coursecredits'} = 1;
20457: foreach my $type (keys(%credits)) {
20458: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20459: }
20460: } else {
1.289 raeburn 20461: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 20462: foreach my $type (@types) {
20463: unless ($type eq 'community') {
1.289 raeburn 20464: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 20465: $changes{'coursecredits'} = 1;
20466: }
20467: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20468: }
20469: }
20470: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20471: foreach my $type (@types) {
20472: unless ($type eq 'community') {
20473: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
20474: $changes{'coursecredits'} = 1;
20475: last;
20476: }
20477: }
20478: }
20479: }
20480: }
20481: if ($env{'form.postsubmit'} eq '1') {
20482: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
20483: my %currtimeout;
20484: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20485: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
20486: $changes{'postsubmit'} = 1;
20487: }
20488: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20489: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
20490: }
20491: } else {
20492: $changes{'postsubmit'} = 1;
20493: }
20494: foreach my $type (@types) {
20495: my $timeout = $env{'form.'.$type.'_timeout'};
20496: $timeout =~ s/\D//g;
20497: if ($timeout == $staticdefaults{'postsubmit'}) {
20498: $timeout = '';
20499: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
20500: $timeout = '0';
20501: }
20502: unless ($timeout eq '') {
20503: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
20504: }
20505: if (exists($currtimeout{$type})) {
20506: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 20507: $changes{'postsubmit'} = 1;
1.257 raeburn 20508: }
20509: } elsif ($timeout ne '') {
20510: $changes{'postsubmit'} = 1;
20511: }
20512: }
20513: } else {
20514: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
20515: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20516: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
20517: $changes{'postsubmit'} = 1;
20518: }
20519: } else {
20520: $changes{'postsubmit'} = 1;
20521: }
1.192 raeburn 20522: }
1.422 raeburn 20523: my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
20524: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
20525: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
20526: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
20527: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
20528: } else {
20529: foreach my $type (@types) {
20530: if ($staticdefaults{'domexttool'}) {
20531: $olddomexttool{$type} = 1;
20532: } else {
20533: $olddomexttool{$type} = 0;
20534: }
20535: }
20536: }
20537: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
20538: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
20539: } else {
20540: foreach my $type (@types) {
20541: if ($staticdefaults{'exttool'}) {
20542: $oldexttool{$type} = 1;
20543: } else {
20544: $oldexttool{$type} = 0;
20545: }
20546: }
20547: }
20548: foreach my $type (@types) {
20549: unless ($newdomexttool{$type}) {
20550: $newdomexttool{$type} = 0;
20551: }
20552: unless ($newexttool{$type}) {
20553: $newexttool{$type} = 0;
20554: }
20555: if ($newdomexttool{$type} != $olddomexttool{$type}) {
20556: $changes{'domexttool'} = 1;
20557: }
20558: if ($newexttool{$type} != $oldexttool{$type}) {
20559: $changes{'exttool'} = 1;
20560: }
20561: }
20562: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
20563: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.121 raeburn 20564: }
20565: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20566: $dom);
20567: if ($putresult eq 'ok') {
20568: if (keys(%changes) > 0) {
1.213 raeburn 20569: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 20570: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 20571: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 20572: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 20573: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
20574: ($changes{'exttool'}) ) {
20575: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
20576: 'ltiauth') {
1.257 raeburn 20577: if ($changes{$item}) {
20578: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
20579: }
1.289 raeburn 20580: }
1.192 raeburn 20581: if ($changes{'coursecredits'}) {
20582: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 20583: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
20584: $domdefaults{$type.'credits'} =
20585: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
20586: }
20587: }
20588: }
20589: if ($changes{'postsubmit'}) {
20590: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20591: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
20592: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20593: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
20594: $domdefaults{$type.'postsubtimeout'} =
20595: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20596: }
20597: }
1.192 raeburn 20598: }
20599: }
1.198 raeburn 20600: if ($changes{'uploadquota'}) {
20601: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20602: foreach my $type (@types) {
20603: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
20604: }
20605: }
20606: }
1.264 raeburn 20607: if ($changes{'canclone'}) {
20608: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20609: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20610: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20611: if (@clonecodes) {
20612: $domdefaults{'canclone'} = join('+',@clonecodes);
20613: }
20614: }
20615: } else {
20616: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20617: }
20618: }
1.422 raeburn 20619: if ($changes{'domexttool'}) {
20620: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
20621: foreach my $type (@types) {
20622: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
20623: }
20624: }
20625: }
20626: if ($changes{'exttool'}) {
20627: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
20628: foreach my $type (@types) {
20629: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
20630: }
20631: }
20632: }
1.121 raeburn 20633: my $cachetime = 24*60*60;
20634: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20635: if (ref($lastactref) eq 'HASH') {
20636: $lastactref->{'domdefaults'} = 1;
20637: }
1.121 raeburn 20638: }
20639: $resulttext = &mt('Changes made:').'<ul>';
20640: foreach my $item (sort(keys(%changes))) {
20641: if ($item eq 'canuse_pdfforms') {
20642: if ($env{'form.'.$item} eq '1') {
20643: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20644: } else {
20645: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20646: }
1.257 raeburn 20647: } elsif ($item eq 'uselcmath') {
20648: if ($env{'form.'.$item} eq '1') {
20649: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20650: } else {
20651: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20652: }
20653: } elsif ($item eq 'usejsme') {
20654: if ($env{'form.'.$item} eq '1') {
20655: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20656: } else {
1.289 raeburn 20657: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20658: }
1.398 raeburn 20659: } elsif ($item eq 'inline_chem') {
20660: if ($env{'form.'.$item} eq '1') {
20661: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
20662: } else {
20663: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
20664: }
1.314 raeburn 20665: } elsif ($item eq 'texengine') {
20666: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20667: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20668: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20669: }
1.139 raeburn 20670: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20671: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20672: } elsif ($item eq 'uploadquota') {
20673: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20674: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20675: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20676: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20677: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20678: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20679: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20680: '</ul>'.
20681: '</li>';
20682: } else {
20683: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20684: }
1.276 raeburn 20685: } elsif ($item eq 'mysqltables') {
20686: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20687: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20688: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20689: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20690: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20691: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20692: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20693: '</ul>'.
20694: '</li>';
20695: } else {
20696: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20697: }
1.257 raeburn 20698: } elsif ($item eq 'postsubmit') {
20699: if ($domdefaults{'postsubmit'} eq 'off') {
20700: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20701: } else {
20702: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20703: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20704: $resulttext .= &mt('durations:').'<ul>';
20705: foreach my $type (@types) {
20706: $resulttext .= '<li>';
20707: my $timeout;
20708: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20709: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20710: }
20711: my $display;
20712: if ($timeout eq '0') {
20713: $display = &mt('unlimited');
20714: } elsif ($timeout eq '') {
20715: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20716: } else {
20717: $display = &mt('[quant,_1,second]',$timeout);
20718: }
20719: if ($type eq 'community') {
20720: $resulttext .= &mt('Communities');
20721: } elsif ($type eq 'official') {
20722: $resulttext .= &mt('Official courses');
20723: } elsif ($type eq 'unofficial') {
20724: $resulttext .= &mt('Unofficial courses');
20725: } elsif ($type eq 'textbook') {
20726: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20727: } elsif ($type eq 'placement') {
20728: $resulttext .= &mt('Placement tests');
1.257 raeburn 20729: }
20730: $resulttext .= ' -- '.$display.'</li>';
20731: }
20732: $resulttext .= '</ul>';
20733: }
1.289 raeburn 20734: $resulttext .= '</li>';
1.257 raeburn 20735: }
1.192 raeburn 20736: } elsif ($item eq 'coursecredits') {
20737: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20738: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20739: ($domdefaults{'unofficialcredits'} eq '') &&
20740: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20741: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20742: } else {
20743: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20744: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20745: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20746: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20747: '</ul>'.
20748: '</li>';
20749: }
20750: } else {
20751: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20752: }
1.264 raeburn 20753: } elsif ($item eq 'canclone') {
20754: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20755: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20756: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20757: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20758: }
20759: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20760: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20761: } else {
1.289 raeburn 20762: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20763: }
1.404 raeburn 20764: } elsif ($item eq 'ltiauth') {
20765: if ($env{'form.'.$item} eq '1') {
20766: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
20767: } else {
20768: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
20769: }
1.422 raeburn 20770: } elsif ($item eq 'domexttool') {
20771: my @noyes = (&mt('no'),&mt('yes'));
20772: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
20773: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
20774: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
20775: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
20776: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
20777: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
20778: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
20779: '</ul>'.
20780: '</li>';
20781: } else {
20782: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
20783: }
20784: } elsif ($item eq 'exttool') {
20785: my @noyes = (&mt('no'),&mt('yes'));
20786: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
20787: $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
20788: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
20789: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
20790: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
20791: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
20792: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
20793: '</ul>'.
20794: '</li>';
20795: } else {
20796: $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
20797: }
1.140 raeburn 20798: }
1.121 raeburn 20799: }
20800: $resulttext .= '</ul>';
20801: } else {
20802: $resulttext = &mt('No changes made to course defaults');
20803: }
20804: } else {
20805: $resulttext = '<span class="LC_error">'.
20806: &mt('An error occurred: [_1]',$putresult).'</span>';
20807: }
20808: return $resulttext;
20809: }
20810:
1.231 raeburn 20811: sub modify_selfenrollment {
20812: my ($dom,$lastactref,%domconfig) = @_;
20813: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20814: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20815: my %titles = &tool_titles();
1.232 raeburn 20816: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20817: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20818: $ordered{'default'} = ['types','registered','approval','limit'];
20819:
20820: my (%roles,%shown,%toplevel);
20821: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20822:
20823: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20824: if ($domconfig{'selfenrollment'} eq '') {
20825: $domconfig{'selfenrollment'} = {};
20826: }
20827: }
20828: %toplevel = (
20829: admin => 'Configuration Rights',
20830: default => 'Default settings',
20831: validation => 'Validation of self-enrollment requests',
20832: );
1.233 raeburn 20833: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20834:
20835: if (ref($ordered{'admin'}) eq 'ARRAY') {
20836: foreach my $item (@{$ordered{'admin'}}) {
20837: foreach my $type (@types) {
20838: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20839: $selfenrollhash{'admin'}{$type}{$item} = 1;
20840: } else {
20841: $selfenrollhash{'admin'}{$type}{$item} = 0;
20842: }
20843: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20844: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20845: if ($selfenrollhash{'admin'}{$type}{$item} ne
20846: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20847: push(@{$changes{'admin'}{$type}},$item);
20848: }
20849: } else {
20850: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20851: push(@{$changes{'admin'}{$type}},$item);
20852: }
20853: }
20854: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20855: push(@{$changes{'admin'}{$type}},$item);
20856: }
20857: }
20858: }
20859: }
20860:
20861: foreach my $item (@{$ordered{'default'}}) {
20862: foreach my $type (@types) {
20863: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20864: if ($item eq 'types') {
20865: unless (($value eq 'all') || ($value eq 'dom')) {
20866: $value = '';
20867: }
20868: } elsif ($item eq 'registered') {
20869: unless ($value eq '1') {
20870: $value = 0;
20871: }
20872: } elsif ($item eq 'approval') {
20873: unless ($value =~ /^[012]$/) {
20874: $value = 0;
20875: }
20876: } else {
20877: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20878: $value = 'none';
20879: }
20880: }
20881: $selfenrollhash{'default'}{$type}{$item} = $value;
20882: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20883: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20884: if ($selfenrollhash{'default'}{$type}{$item} ne
20885: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20886: push(@{$changes{'default'}{$type}},$item);
20887: }
20888: } else {
20889: push(@{$changes{'default'}{$type}},$item);
20890: }
20891: } else {
20892: push(@{$changes{'default'}{$type}},$item);
20893: }
20894: if ($item eq 'limit') {
20895: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20896: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20897: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20898: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20899: }
20900: } else {
20901: $selfenrollhash{'default'}{$type}{'cap'} = '';
20902: }
20903: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20904: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20905: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20906: push(@{$changes{'default'}{$type}},'cap');
20907: }
20908: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20909: push(@{$changes{'default'}{$type}},'cap');
20910: }
20911: }
20912: }
20913: }
20914:
20915: foreach my $item (@{$itemsref}) {
20916: if ($item eq 'fields') {
20917: my @changed;
20918: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20919: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20920: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20921: }
20922: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20923: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20924: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20925: $domconfig{'selfenrollment'}{'validation'}{$item});
20926: } else {
20927: @changed = @{$selfenrollhash{'validation'}{$item}};
20928: }
20929: } else {
20930: @changed = @{$selfenrollhash{'validation'}{$item}};
20931: }
20932: if (@changed) {
20933: if ($selfenrollhash{'validation'}{$item}) {
20934: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20935: } else {
20936: $changes{'validation'}{$item} = &mt('None');
20937: }
20938: }
20939: } else {
20940: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20941: if ($item eq 'markup') {
20942: if ($env{'form.selfenroll_validation_'.$item}) {
20943: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20944: }
20945: }
20946: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20947: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20948: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20949: }
20950: }
20951: }
20952: }
20953:
20954: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20955: $dom);
20956: if ($putresult eq 'ok') {
20957: if (keys(%changes) > 0) {
20958: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20959: $resulttext = &mt('Changes made:').'<ul>';
20960: foreach my $key ('admin','default','validation') {
20961: if (ref($changes{$key}) eq 'HASH') {
20962: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20963: if ($key eq 'validation') {
20964: foreach my $item (@{$itemsref}) {
20965: if (exists($changes{$key}{$item})) {
20966: if ($item eq 'markup') {
20967: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20968: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20969: } else {
20970: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20971: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20972: }
20973: }
20974: }
20975: } else {
20976: foreach my $type (@types) {
20977: if ($type eq 'community') {
20978: $roles{'1'} = &mt('Community personnel');
20979: } else {
20980: $roles{'1'} = &mt('Course personnel');
20981: }
20982: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20983: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20984: if ($key eq 'admin') {
20985: my @mgrdc = ();
20986: if (ref($ordered{$key}) eq 'ARRAY') {
20987: foreach my $item (@{$ordered{'admin'}}) {
20988: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20989: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20990: push(@mgrdc,$item);
20991: }
20992: }
20993: }
20994: if (@mgrdc) {
20995: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20996: } else {
20997: delete($domdefaults{$type.'selfenrolladmdc'});
20998: }
20999: }
21000: } else {
21001: if (ref($ordered{$key}) eq 'ARRAY') {
21002: foreach my $item (@{$ordered{$key}}) {
21003: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21004: $domdefaults{$type.'selfenroll'.$item} =
21005: $selfenrollhash{$key}{$type}{$item};
21006: }
21007: }
21008: }
21009: }
21010: }
1.231 raeburn 21011: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21012: foreach my $item (@{$ordered{$key}}) {
21013: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21014: $resulttext .= '<li>';
21015: if ($key eq 'admin') {
21016: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21017: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21018: } else {
21019: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21020: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21021: }
21022: $resulttext .= '</li>';
21023: }
21024: }
21025: $resulttext .= '</ul></li>';
21026: }
21027: }
21028: $resulttext .= '</ul></li>';
21029: }
21030: }
1.305 raeburn 21031: }
21032: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21033: my $cachetime = 24*60*60;
21034: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21035: if (ref($lastactref) eq 'HASH') {
21036: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21037: }
1.231 raeburn 21038: }
21039: $resulttext .= '</ul>';
21040: } else {
21041: $resulttext = &mt('No changes made to self-enrollment settings');
21042: }
21043: } else {
21044: $resulttext = '<span class="LC_error">'.
21045: &mt('An error occurred: [_1]',$putresult).'</span>';
21046: }
21047: return $resulttext;
21048: }
21049:
1.373 raeburn 21050: sub modify_wafproxy {
21051: my ($dom,$action,$lastactref,%domconfig) = @_;
21052: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21053: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21054: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21055: foreach my $server (sort(keys(%servers))) {
21056: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21057: if ($serverhome eq $server) {
21058: my $serverdom = &Apache::lonnet::host_domain($server);
21059: if ($serverdom eq $dom) {
21060: $canset{$server} = 1;
21061: }
21062: }
21063: }
1.381 raeburn 21064: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21065: %{$values{$dom}} = ();
21066: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21067: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21068: }
1.388 raeburn 21069: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21070: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21071: }
1.382 raeburn 21072: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21073: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21074: }
21075: }
1.373 raeburn 21076: my $output;
21077: if (keys(%canset)) {
21078: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21079: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21080: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21081: if ($env{'form.wafproxy_'.$dom}) {
21082: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21083: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21084: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21085: $changes{'alias'} = 1;
21086: }
1.388 raeburn 21087: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21088: $wafproxy{'saml'}{$key} = 1;
21089: }
21090: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21091: $changes{'saml'} = 1;
21092: }
1.381 raeburn 21093: } else {
21094: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21095: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21096: if ($curralias{$key}) {
21097: $changes{'alias'} = 1;
21098: }
1.388 raeburn 21099: if ($currsaml{$key}) {
21100: $changes{'saml'} = 1;
21101: }
1.373 raeburn 21102: }
21103: if ($wafproxy{'alias'}{$key} eq '') {
21104: if ($curralias{$key}) {
21105: $expirecache{$key} = 1;
21106: }
21107: delete($wafproxy{'alias'}{$key});
21108: }
1.388 raeburn 21109: if ($wafproxy{'saml'}{$key} eq '') {
21110: if ($currsaml{$key}) {
21111: $expiresaml{$key} = 1;
21112: }
21113: delete($wafproxy{'saml'}{$key});
21114: }
1.373 raeburn 21115: }
21116: unless (keys(%{$wafproxy{'alias'}})) {
21117: delete($wafproxy{'alias'});
21118: }
1.388 raeburn 21119: unless (keys(%{$wafproxy{'saml'}})) {
21120: delete($wafproxy{'saml'});
21121: }
21122: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21123: my %warn = (
21124: trusted => 'trusted IP range(s)',
1.381 raeburn 21125: vpnint => 'internal IP range(s) for VPN sessions(s)',
21126: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21127: );
1.382 raeburn 21128: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21129: my $possible = $env{'form.wafproxy_'.$item};
21130: $possible =~ s/^\s+|\s+$//g;
21131: if ($possible ne '') {
1.381 raeburn 21132: if ($item eq 'remoteip') {
21133: if ($possible =~ /^[mhn]$/) {
21134: $wafproxy{$item} = $possible;
21135: }
21136: } elsif ($item eq 'ipheader') {
21137: if ($wafproxy{'remoteip'} eq 'h') {
21138: $wafproxy{$item} = $possible;
21139: }
1.382 raeburn 21140: } elsif ($item eq 'sslopt') {
21141: if ($possible =~ /^0|1$/) {
21142: $wafproxy{$item} = $possible;
21143: }
1.373 raeburn 21144: } else {
21145: my (@ok,$count);
1.381 raeburn 21146: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21147: unless ($env{'form.wafproxy_vpnaccess'}) {
21148: $possible = '';
21149: }
21150: } elsif ($item eq 'trusted') {
21151: unless ($wafproxy{'remoteip'} eq 'h') {
21152: $possible = '';
21153: }
21154: }
21155: unless ($possible eq '') {
21156: $possible =~ s/[\r\n]+/\s/g;
21157: $possible =~ s/\s*-\s*/-/g;
21158: $possible =~ s/\s+/,/g;
1.393 raeburn 21159: $possible =~ s/,+/,/g;
1.381 raeburn 21160: }
1.373 raeburn 21161: $count = 0;
1.381 raeburn 21162: if ($possible ne '') {
1.373 raeburn 21163: foreach my $poss (split(/\,/,$possible)) {
21164: $count ++;
1.393 raeburn 21165: $poss = &validate_ip_pattern($poss);
21166: if ($poss ne '') {
1.373 raeburn 21167: push(@ok,$poss);
21168: }
21169: }
21170: my $diff = $count - scalar(@ok);
21171: if ($diff) {
21172: push(@warnings,'<li>'.
21173: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21174: $diff,$warn{$item}).
21175: '</li>');
21176: }
1.393 raeburn 21177: if (@ok) {
21178: my @cidr_list;
21179: foreach my $item (@ok) {
21180: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21181: }
21182: $wafproxy{$item} = join(',',@cidr_list);
21183: }
1.373 raeburn 21184: }
21185: }
1.381 raeburn 21186: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21187: $changes{$item} = 1;
21188: }
1.381 raeburn 21189: } elsif ($currvalue{$item}) {
21190: $changes{$item} = 1;
21191: }
21192: }
21193: } else {
21194: if (keys(%curralias)) {
21195: $changes{'alias'} = 1;
1.388 raeburn 21196: }
21197: if (keys(%currsaml)) {
21198: $changes{'saml'} = 1;
1.381 raeburn 21199: }
21200: if (keys(%currvalue)) {
21201: foreach my $key (keys(%currvalue)) {
21202: $changes{$key} = 1;
1.373 raeburn 21203: }
21204: }
21205: }
21206: if (keys(%changes)) {
21207: my %defaultshash = (
21208: wafproxy => \%wafproxy,
21209: );
21210: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21211: $dom);
21212: if ($putresult eq 'ok') {
21213: my $cachetime = 24*60*60;
21214: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21215: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21216: if ($changes{$item}) {
21217: unless ($updatedomdefs) {
21218: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21219: $updatedomdefs = 1;
21220: }
21221: if ($wafproxy{$item}) {
21222: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21223: } elsif (exists($domdefaults{'waf_'.$item})) {
21224: delete($domdefaults{'waf_'.$item});
21225: }
21226: }
21227: }
21228: if ($updatedomdefs) {
21229: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21230: if (ref($lastactref) eq 'HASH') {
21231: $lastactref->{'domdefaults'} = 1;
21232: }
21233: }
21234: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21235: my %updates = %expirecache;
21236: foreach my $key (keys(%expirecache)) {
21237: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21238: }
21239: if (ref($wafproxy{'alias'}) eq 'HASH') {
21240: my $cachetime = 24*60*60;
21241: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21242: $updates{$key} = 1;
21243: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21244: $cachetime);
21245: }
21246: }
21247: if (ref($lastactref) eq 'HASH') {
21248: $lastactref->{'proxyalias'} = \%updates;
21249: }
21250: }
1.388 raeburn 21251: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21252: my %samlupdates = %expiresaml;
21253: foreach my $key (keys(%expiresaml)) {
21254: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21255: }
21256: if (ref($wafproxy{'saml'}) eq 'HASH') {
21257: my $cachetime = 24*60*60;
21258: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21259: $samlupdates{$key} = 1;
21260: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21261: $cachetime);
21262: }
21263: }
21264: if (ref($lastactref) eq 'HASH') {
21265: $lastactref->{'proxysaml'} = \%samlupdates;
21266: }
21267: }
1.373 raeburn 21268: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 21269: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21270: if ($changes{$item}) {
21271: if ($item eq 'alias') {
21272: my $numaliased = 0;
21273: if (ref($wafproxy{'alias'}) eq 'HASH') {
21274: my $shown;
21275: if (keys(%{$wafproxy{'alias'}})) {
21276: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21277: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21278: &Apache::lonnet::hostname($server),
21279: $wafproxy{'alias'}{$server}).'</li>';
21280: $numaliased ++;
21281: }
21282: if ($numaliased) {
21283: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21284: '<ul>'.$shown.'</ul>').'</li>';
21285: }
21286: }
21287: }
21288: unless ($numaliased) {
21289: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21290: }
1.388 raeburn 21291: } elsif ($item eq 'saml') {
21292: my $shown;
21293: if (ref($wafproxy{'saml'}) eq 'HASH') {
21294: if (keys(%{$wafproxy{'saml'}})) {
21295: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21296: }
21297: }
21298: if ($shown) {
1.396 raeburn 21299: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 21300: $shown).'</li>';
21301: } else {
1.396 raeburn 21302: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 21303: }
1.373 raeburn 21304: } else {
1.381 raeburn 21305: if ($item eq 'remoteip') {
21306: my %ip_methods = &remoteip_methods();
21307: if ($wafproxy{$item} =~ /^[mh]$/) {
21308: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
21309: $ip_methods{$wafproxy{$item}}).'</li>';
21310: } else {
21311: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
21312: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
21313: '</li>';
21314: } else {
21315: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
21316: }
21317: }
21318: } elsif ($item eq 'ipheader') {
1.373 raeburn 21319: if ($wafproxy{$item}) {
1.381 raeburn 21320: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 21321: $wafproxy{$item}).'</li>';
21322: } else {
1.381 raeburn 21323: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 21324: }
21325: } elsif ($item eq 'trusted') {
21326: if ($wafproxy{$item}) {
1.381 raeburn 21327: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 21328: $wafproxy{$item}).'</li>';
21329: } else {
21330: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
21331: }
1.381 raeburn 21332: } elsif ($item eq 'vpnint') {
21333: if ($wafproxy{$item}) {
21334: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
21335: $wafproxy{$item}).'</li>';
21336: } else {
21337: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
21338: }
21339: } elsif ($item eq 'vpnext') {
1.373 raeburn 21340: if ($wafproxy{$item}) {
1.381 raeburn 21341: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 21342: $wafproxy{$item}).'</li>';
21343: } else {
1.381 raeburn 21344: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 21345: }
1.382 raeburn 21346: } elsif ($item eq 'sslopt') {
21347: if ($wafproxy{$item}) {
21348: $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>';
21349: } else {
21350: $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>';
21351: }
1.373 raeburn 21352: }
21353: }
21354: }
21355: }
1.420 raeburn 21356: $output .= '</ul>';
1.373 raeburn 21357: } else {
21358: $output = '<span class="LC_error">'.
21359: &mt('An error occurred: [_1]',$putresult).'</span>';
21360: }
21361: } elsif (keys(%canset)) {
21362: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
21363: }
21364: if (@warnings) {
21365: $output .= '<br />'.&mt('Warnings:').'<ul>'.
21366: join("\n",@warnings).'</ul>';
21367: }
21368: return $output;
21369: }
21370:
21371: sub validate_ip_pattern {
21372: my ($pattern) = @_;
21373: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
21374: my ($start,$end) = ($1,$2);
21375: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 21376: if (($start !~ m{/}) && ($end !~ m{/})) {
21377: return $start.'-'.$end;
21378: }
21379: }
21380: } elsif ($pattern ne '') {
21381: $pattern = &Net::CIDR::cidrvalidate($pattern);
21382: if ($pattern ne '') {
21383: return $pattern;
1.373 raeburn 21384: }
21385: }
1.393 raeburn 21386: return;
1.373 raeburn 21387: }
21388:
1.137 raeburn 21389: sub modify_usersessions {
1.212 raeburn 21390: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 21391: my @hostingtypes = ('version','excludedomain','includedomain');
21392: my @offloadtypes = ('primary','default');
21393: my %types = (
21394: remote => \@hostingtypes,
21395: hosted => \@hostingtypes,
21396: spares => \@offloadtypes,
21397: );
21398: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 21399: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 21400: my (%by_ip,%by_location,@intdoms,@instdoms);
21401: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 21402: my @locations = sort(keys(%by_location));
1.137 raeburn 21403: my (%defaultshash,%changes);
21404: foreach my $prefix (@prefixes) {
21405: $defaultshash{'usersessions'}{$prefix} = {};
21406: }
1.212 raeburn 21407: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 21408: my $resulttext;
1.138 raeburn 21409: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 21410: foreach my $prefix (@prefixes) {
1.145 raeburn 21411: next if ($prefix eq 'spares');
21412: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 21413: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21414: if ($type eq 'version') {
21415: my $value = $env{'form.'.$prefix.'_'.$type};
21416: my $okvalue;
21417: if ($value ne '') {
21418: if (grep(/^\Q$value\E$/,@lcversions)) {
21419: $okvalue = $value;
21420: }
21421: }
21422: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21423: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21424: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
21425: if ($inuse == 0) {
21426: $changes{$prefix}{$type} = 1;
21427: } else {
21428: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
21429: $changes{$prefix}{$type} = 1;
21430: }
21431: if ($okvalue ne '') {
21432: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21433: }
21434: }
21435: } else {
21436: if (($inuse == 1) && ($okvalue ne '')) {
21437: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21438: $changes{$prefix}{$type} = 1;
21439: }
21440: }
21441: } else {
21442: if (($inuse == 1) && ($okvalue ne '')) {
21443: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21444: $changes{$prefix}{$type} = 1;
21445: }
21446: }
21447: } else {
21448: if (($inuse == 1) && ($okvalue ne '')) {
21449: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21450: $changes{$prefix}{$type} = 1;
21451: }
21452: }
21453: } else {
21454: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21455: my @okvals;
21456: foreach my $val (@vals) {
1.138 raeburn 21457: if ($val =~ /:/) {
21458: my @items = split(/:/,$val);
21459: foreach my $item (@items) {
21460: if (ref($by_location{$item}) eq 'ARRAY') {
21461: push(@okvals,$item);
21462: }
21463: }
21464: } else {
21465: if (ref($by_location{$val}) eq 'ARRAY') {
21466: push(@okvals,$val);
21467: }
1.137 raeburn 21468: }
21469: }
21470: @okvals = sort(@okvals);
21471: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21472: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21473: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21474: if ($inuse == 0) {
21475: $changes{$prefix}{$type} = 1;
21476: } else {
21477: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21478: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
21479: if (@changed > 0) {
21480: $changes{$prefix}{$type} = 1;
21481: }
21482: }
21483: } else {
21484: if ($inuse == 1) {
21485: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21486: $changes{$prefix}{$type} = 1;
21487: }
21488: }
21489: } else {
21490: if ($inuse == 1) {
21491: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21492: $changes{$prefix}{$type} = 1;
21493: }
21494: }
21495: } else {
21496: if ($inuse == 1) {
21497: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21498: $changes{$prefix}{$type} = 1;
21499: }
21500: }
21501: }
21502: }
21503: }
1.145 raeburn 21504:
21505: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 21506: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 21507: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
21508: my $savespares;
21509:
21510: foreach my $lonhost (sort(keys(%servers))) {
21511: my $serverhomeID =
21512: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 21513: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 21514: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
21515: my %spareschg;
21516: foreach my $type (@{$types{'spares'}}) {
21517: my @okspares;
21518: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
21519: foreach my $server (@checked) {
1.152 raeburn 21520: if (&Apache::lonnet::hostname($server) ne '') {
21521: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
21522: unless (grep(/^\Q$server\E$/,@okspares)) {
21523: push(@okspares,$server);
21524: }
1.145 raeburn 21525: }
21526: }
21527: }
21528: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
21529: my $newspare;
1.152 raeburn 21530: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
21531: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 21532: $newspare = $new;
21533: }
21534: }
1.152 raeburn 21535: my @spares;
21536: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
21537: @spares = sort(@okspares,$newspare);
21538: } else {
21539: @spares = sort(@okspares);
21540: }
21541: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 21542: if (ref($spareid{$lonhost}) eq 'HASH') {
21543: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 21544: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 21545: if (@diffs > 0) {
21546: $spareschg{$type} = 1;
21547: }
21548: }
21549: }
21550: }
21551: if (keys(%spareschg) > 0) {
21552: $changes{'spares'}{$lonhost} = \%spareschg;
21553: }
21554: }
1.261 raeburn 21555: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 21556: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 21557: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
21558: my @okoffload;
21559: if (@offloadnow) {
21560: foreach my $server (@offloadnow) {
21561: if (&Apache::lonnet::hostname($server) ne '') {
21562: unless (grep(/^\Q$server\E$/,@okoffload)) {
21563: push(@okoffload,$server);
21564: }
21565: }
21566: }
21567: if (@okoffload) {
21568: foreach my $lonhost (@okoffload) {
21569: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
21570: }
21571: }
21572: }
1.371 raeburn 21573: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
21574: my @okoffloadoth;
21575: if (@offloadoth) {
21576: foreach my $server (@offloadoth) {
21577: if (&Apache::lonnet::hostname($server) ne '') {
21578: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
21579: push(@okoffloadoth,$server);
21580: }
21581: }
21582: }
21583: if (@okoffloadoth) {
21584: foreach my $lonhost (@okoffloadoth) {
21585: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
21586: }
21587: }
21588: }
1.145 raeburn 21589: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21590: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
21591: if (ref($changes{'spares'}) eq 'HASH') {
21592: if (keys(%{$changes{'spares'}}) > 0) {
21593: $savespares = 1;
21594: }
21595: }
21596: } else {
21597: $savespares = 1;
21598: }
1.371 raeburn 21599: foreach my $offload ('offloadnow','offloadoth') {
21600: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
21601: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
21602: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
21603: $changes{$offload} = 1;
21604: last;
21605: }
1.261 raeburn 21606: }
1.371 raeburn 21607: unless ($changes{$offload}) {
21608: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
21609: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
21610: $changes{$offload} = 1;
21611: last;
21612: }
1.261 raeburn 21613: }
21614: }
1.371 raeburn 21615: } else {
21616: if (($offload eq 'offloadnow') && (@okoffload)) {
21617: $changes{'offloadnow'} = 1;
21618: }
21619: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
21620: $changes{'offloadoth'} = 1;
21621: }
21622: }
21623: }
21624: } else {
21625: if (@okoffload) {
1.261 raeburn 21626: $changes{'offloadnow'} = 1;
21627: }
1.371 raeburn 21628: if (@okoffloadoth) {
21629: $changes{'offloadoth'} = 1;
21630: }
1.145 raeburn 21631: }
1.147 raeburn 21632: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
21633: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 21634: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21635: $dom);
21636: if ($putresult eq 'ok') {
21637: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21638: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
21639: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
21640: }
21641: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
21642: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
21643: }
1.261 raeburn 21644: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21645: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
21646: }
1.371 raeburn 21647: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21648: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
21649: }
1.137 raeburn 21650: }
21651: my $cachetime = 24*60*60;
21652: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 21653: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 21654: if (ref($lastactref) eq 'HASH') {
21655: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 21656: $lastactref->{'usersessions'} = 1;
1.212 raeburn 21657: }
1.147 raeburn 21658: if (keys(%changes) > 0) {
21659: my %lt = &usersession_titles();
21660: $resulttext = &mt('Changes made:').'<ul>';
21661: foreach my $prefix (@prefixes) {
21662: if (ref($changes{$prefix}) eq 'HASH') {
21663: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21664: if ($prefix eq 'spares') {
21665: if (ref($changes{$prefix}) eq 'HASH') {
21666: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
21667: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 21668: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 21669: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
21670: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 21671: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
21672: foreach my $type (@{$types{$prefix}}) {
21673: if ($changes{$prefix}{$lonhost}{$type}) {
21674: my $offloadto = &mt('None');
21675: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
21676: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21677: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21678: }
1.145 raeburn 21679: }
1.147 raeburn 21680: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21681: }
1.137 raeburn 21682: }
21683: }
1.147 raeburn 21684: $resulttext .= '</li>';
1.137 raeburn 21685: }
21686: }
1.147 raeburn 21687: } else {
21688: foreach my $type (@{$types{$prefix}}) {
21689: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21690: my ($newvalue,$notinuse);
1.147 raeburn 21691: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21692: if (ref($defaultshash{'usersessions'}{$prefix})) {
21693: if ($type eq 'version') {
21694: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21695: } else {
21696: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21697: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21698: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21699: }
21700: } else {
21701: $notinuse = 1;
1.147 raeburn 21702: }
1.145 raeburn 21703: }
21704: }
21705: }
1.147 raeburn 21706: if ($newvalue eq '') {
21707: if ($type eq 'version') {
21708: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21709: } elsif ($notinuse) {
21710: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21711: } else {
21712: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21713: }
1.145 raeburn 21714: } else {
1.147 raeburn 21715: if ($type eq 'version') {
1.344 raeburn 21716: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21717: }
21718: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21719: }
1.137 raeburn 21720: }
21721: }
21722: }
1.147 raeburn 21723: $resulttext .= '</ul>';
1.137 raeburn 21724: }
21725: }
1.261 raeburn 21726: if ($changes{'offloadnow'}) {
21727: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21728: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21729: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21730: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21731: $resulttext .= '<li>'.$lonhost.'</li>';
21732: }
21733: $resulttext .= '</ul>';
21734: } else {
1.371 raeburn 21735: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21736: }
21737: } else {
21738: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21739: }
21740: }
21741: if ($changes{'offloadoth'}) {
21742: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21743: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21744: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21745: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21746: $resulttext .= '<li>'.$lonhost.'</li>';
21747: }
21748: $resulttext .= '</ul>';
21749: } else {
21750: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21751: }
21752: } else {
1.371 raeburn 21753: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21754: }
21755: }
1.147 raeburn 21756: $resulttext .= '</ul>';
21757: } else {
21758: $resulttext = $nochgmsg;
1.137 raeburn 21759: }
21760: } else {
21761: $resulttext = '<span class="LC_error">'.
21762: &mt('An error occurred: [_1]',$putresult).'</span>';
21763: }
21764: } else {
1.147 raeburn 21765: $resulttext = $nochgmsg;
1.137 raeburn 21766: }
21767: return $resulttext;
21768: }
21769:
1.275 raeburn 21770: sub modify_ssl {
21771: my ($dom,$lastactref,%domconfig) = @_;
21772: my (%by_ip,%by_location,@intdoms,@instdoms);
21773: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21774: my @locations = sort(keys(%by_location));
21775: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21776: my (%defaultshash,%changes);
21777: my $action = 'ssl';
1.293 raeburn 21778: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21779: foreach my $prefix (@prefixes) {
21780: $defaultshash{$action}{$prefix} = {};
21781: }
21782: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21783: my $resulttext;
21784: my %iphost = &Apache::lonnet::get_iphost();
21785: my @reptypes = ('certreq','nocertreq');
21786: my @connecttypes = ('dom','intdom','other');
21787: my %types = (
1.293 raeburn 21788: connto => \@connecttypes,
21789: connfrom => \@connecttypes,
21790: replication => \@reptypes,
1.275 raeburn 21791: );
21792: foreach my $prefix (sort(keys(%types))) {
21793: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21794: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21795: my $value = 'yes';
21796: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21797: $value = $env{'form.'.$prefix.'_'.$type};
21798: }
1.335 raeburn 21799: if (ref($domconfig{$action}) eq 'HASH') {
21800: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21801: if ($domconfig{$action}{$prefix}{$type} ne '') {
21802: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21803: $changes{$prefix}{$type} = 1;
21804: }
21805: $defaultshash{$action}{$prefix}{$type} = $value;
21806: } else {
21807: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21808: $changes{$prefix}{$type} = 1;
21809: }
21810: } else {
21811: $defaultshash{$action}{$prefix}{$type} = $value;
21812: $changes{$prefix}{$type} = 1;
21813: }
21814: } else {
21815: $defaultshash{$action}{$prefix}{$type} = $value;
21816: $changes{$prefix}{$type} = 1;
21817: }
21818: if (($type eq 'dom') && (keys(%servers) == 1)) {
21819: delete($changes{$prefix}{$type});
21820: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21821: delete($changes{$prefix}{$type});
21822: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21823: delete($changes{$prefix}{$type});
21824: }
21825: } elsif ($prefix eq 'replication') {
21826: if (@locations > 0) {
21827: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21828: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21829: my @okvals;
21830: foreach my $val (@vals) {
21831: if ($val =~ /:/) {
21832: my @items = split(/:/,$val);
21833: foreach my $item (@items) {
21834: if (ref($by_location{$item}) eq 'ARRAY') {
21835: push(@okvals,$item);
21836: }
21837: }
21838: } else {
21839: if (ref($by_location{$val}) eq 'ARRAY') {
21840: push(@okvals,$val);
21841: }
21842: }
21843: }
21844: @okvals = sort(@okvals);
21845: if (ref($domconfig{$action}) eq 'HASH') {
21846: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21847: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21848: if ($inuse == 0) {
21849: $changes{$prefix}{$type} = 1;
21850: } else {
21851: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21852: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21853: if (@changed > 0) {
21854: $changes{$prefix}{$type} = 1;
21855: }
21856: }
21857: } else {
21858: if ($inuse == 1) {
21859: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21860: $changes{$prefix}{$type} = 1;
21861: }
21862: }
21863: } else {
21864: if ($inuse == 1) {
21865: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21866: $changes{$prefix}{$type} = 1;
21867: }
21868: }
21869: } else {
21870: if ($inuse == 1) {
21871: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21872: $changes{$prefix}{$type} = 1;
21873: }
21874: }
21875: }
21876: }
21877: }
21878: }
1.336 raeburn 21879: if (keys(%changes)) {
21880: foreach my $prefix (keys(%changes)) {
21881: if (ref($changes{$prefix}) eq 'HASH') {
21882: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21883: delete($changes{$prefix});
21884: }
21885: } else {
21886: delete($changes{$prefix});
21887: }
21888: }
21889: }
1.275 raeburn 21890: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21891: if (keys(%changes) > 0) {
21892: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21893: $dom);
21894: if ($putresult eq 'ok') {
21895: if (ref($defaultshash{$action}) eq 'HASH') {
21896: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21897: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21898: }
1.293 raeburn 21899: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21900: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21901: }
21902: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21903: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21904: }
21905: }
21906: my $cachetime = 24*60*60;
21907: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21908: if (ref($lastactref) eq 'HASH') {
21909: $lastactref->{'domdefaults'} = 1;
21910: }
21911: if (keys(%changes) > 0) {
21912: my %titles = &ssl_titles();
21913: $resulttext = &mt('Changes made:').'<ul>';
21914: foreach my $prefix (@prefixes) {
21915: if (ref($changes{$prefix}) eq 'HASH') {
21916: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21917: foreach my $type (@{$types{$prefix}}) {
21918: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21919: my ($newvalue,$notinuse);
1.275 raeburn 21920: if (ref($defaultshash{$action}) eq 'HASH') {
21921: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21922: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21923: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21924: } else {
21925: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21926: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21927: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21928: }
21929: } else {
21930: $notinuse = 1;
1.275 raeburn 21931: }
21932: }
21933: }
1.344 raeburn 21934: if ($notinuse) {
21935: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21936: } elsif ($newvalue eq '') {
1.275 raeburn 21937: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21938: } else {
21939: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21940: }
21941: }
21942: }
21943: }
21944: $resulttext .= '</ul>';
21945: }
21946: }
21947: } else {
21948: $resulttext = $nochgmsg;
21949: }
21950: } else {
21951: $resulttext = '<span class="LC_error">'.
21952: &mt('An error occurred: [_1]',$putresult).'</span>';
21953: }
21954: } else {
21955: $resulttext = $nochgmsg;
21956: }
21957: return $resulttext;
21958: }
21959:
1.279 raeburn 21960: sub modify_trust {
21961: my ($dom,$lastactref,%domconfig) = @_;
21962: my (%by_ip,%by_location,@intdoms,@instdoms);
21963: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21964: my @locations = sort(keys(%by_location));
21965: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21966: my @types = ('exc','inc');
21967: my (%defaultshash,%changes);
21968: foreach my $prefix (@prefixes) {
21969: $defaultshash{'trust'}{$prefix} = {};
21970: }
21971: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21972: my $resulttext;
21973: foreach my $prefix (@prefixes) {
21974: foreach my $type (@types) {
21975: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21976: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21977: my @okvals;
21978: foreach my $val (@vals) {
21979: if ($val =~ /:/) {
21980: my @items = split(/:/,$val);
21981: foreach my $item (@items) {
21982: if (ref($by_location{$item}) eq 'ARRAY') {
21983: push(@okvals,$item);
21984: }
21985: }
21986: } else {
21987: if (ref($by_location{$val}) eq 'ARRAY') {
21988: push(@okvals,$val);
21989: }
21990: }
21991: }
21992: @okvals = sort(@okvals);
21993: if (ref($domconfig{'trust'}) eq 'HASH') {
21994: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21995: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21996: if ($inuse == 0) {
21997: $changes{$prefix}{$type} = 1;
21998: } else {
21999: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22000: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22001: if (@changed > 0) {
22002: $changes{$prefix}{$type} = 1;
22003: }
22004: }
22005: } else {
22006: if ($inuse == 1) {
22007: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22008: $changes{$prefix}{$type} = 1;
22009: }
22010: }
22011: } else {
22012: if ($inuse == 1) {
22013: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22014: $changes{$prefix}{$type} = 1;
22015: }
22016: }
22017: } else {
22018: if ($inuse == 1) {
22019: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22020: $changes{$prefix}{$type} = 1;
22021: }
22022: }
22023: }
22024: }
22025: my $nochgmsg = &mt('No changes made to trust settings.');
22026: if (keys(%changes) > 0) {
22027: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22028: $dom);
22029: if ($putresult eq 'ok') {
22030: if (ref($defaultshash{'trust'}) eq 'HASH') {
22031: foreach my $prefix (@prefixes) {
22032: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22033: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22034: }
22035: }
22036: }
22037: my $cachetime = 24*60*60;
22038: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22039: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22040: if (ref($lastactref) eq 'HASH') {
22041: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22042: $lastactref->{'trust'} = 1;
1.279 raeburn 22043: }
22044: if (keys(%changes) > 0) {
22045: my %lt = &trust_titles();
22046: $resulttext = &mt('Changes made:').'<ul>';
22047: foreach my $prefix (@prefixes) {
22048: if (ref($changes{$prefix}) eq 'HASH') {
22049: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22050: foreach my $type (@types) {
22051: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22052: my ($newvalue,$notinuse);
1.279 raeburn 22053: if (ref($defaultshash{'trust'}) eq 'HASH') {
22054: if (ref($defaultshash{'trust'}{$prefix})) {
22055: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22056: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22057: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22058: }
1.344 raeburn 22059: } else {
22060: $notinuse = 1;
1.279 raeburn 22061: }
22062: }
22063: }
1.344 raeburn 22064: if ($notinuse) {
22065: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22066: } elsif ($newvalue eq '') {
1.279 raeburn 22067: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22068: } else {
22069: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22070: }
22071: }
22072: }
22073: $resulttext .= '</ul>';
22074: }
22075: }
22076: $resulttext .= '</ul>';
22077: } else {
22078: $resulttext = $nochgmsg;
22079: }
22080: } else {
22081: $resulttext = '<span class="LC_error">'.
22082: &mt('An error occurred: [_1]',$putresult).'</span>';
22083: }
22084: } else {
22085: $resulttext = $nochgmsg;
22086: }
22087: return $resulttext;
22088: }
22089:
1.150 raeburn 22090: sub modify_loadbalancing {
22091: my ($dom,%domconfig) = @_;
22092: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22093: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22094: my ($othertitle,$usertypes,$types) =
22095: &Apache::loncommon::sorted_inst_types($dom);
22096: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22097: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22098: my @sparestypes = ('primary','default');
22099: my %typetitles = &sparestype_titles();
22100: my $resulttext;
1.342 raeburn 22101: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22102: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22103: %existing = %{$domconfig{'loadbalancing'}};
22104: }
22105: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22106: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22107: my ($saveloadbalancing,%defaultshash,%changes);
22108: my ($alltypes,$othertypes,$titles) =
22109: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22110: my %ruletitles = &offloadtype_text();
22111: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22112: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22113: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22114: if ($balancer eq '') {
22115: next;
22116: }
1.210 raeburn 22117: if (!exists($servers{$balancer})) {
1.171 raeburn 22118: if (exists($currbalancer{$balancer})) {
22119: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22120: }
1.171 raeburn 22121: next;
22122: }
22123: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22124: push(@{$changes{'delete'}},$balancer);
22125: next;
22126: }
22127: if (!exists($currbalancer{$balancer})) {
22128: push(@{$changes{'add'}},$balancer);
22129: }
22130: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22131: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22132: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22133: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22134: $saveloadbalancing = 1;
22135: }
22136: foreach my $sparetype (@sparestypes) {
22137: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22138: my @offloadto;
22139: foreach my $target (@targets) {
22140: if (($servers{$target}) && ($target ne $balancer)) {
22141: if ($sparetype eq 'default') {
22142: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22143: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22144: }
22145: }
1.171 raeburn 22146: unless(grep(/^\Q$target\E$/,@offloadto)) {
22147: push(@offloadto,$target);
22148: }
1.150 raeburn 22149: }
22150: }
1.284 raeburn 22151: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22152: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22153: push(@offloadto,$balancer);
22154: }
22155: }
22156: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22157: }
1.342 raeburn 22158: if ($env{'form.loadbalancing_cookie_'.$i}) {
22159: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
22160: if (exists($currbalancer{$balancer})) {
22161: unless ($currcookies{$balancer}) {
22162: $changes{'curr'}{$balancer}{'cookie'} = 1;
22163: }
22164: }
22165: } elsif (exists($currbalancer{$balancer})) {
22166: if ($currcookies{$balancer}) {
22167: $changes{'curr'}{$balancer}{'cookie'} = 1;
22168: }
22169: }
1.171 raeburn 22170: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22171: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22172: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22173: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22174: if (@targetdiffs > 0) {
1.171 raeburn 22175: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22176: }
1.171 raeburn 22177: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22178: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22179: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22180: }
22181: }
22182: }
22183: } else {
1.171 raeburn 22184: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22185: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22186: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22187: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22188: $changes{'curr'}{$balancer}{'targets'} = 1;
22189: }
1.150 raeburn 22190: }
22191: }
1.210 raeburn 22192: }
1.150 raeburn 22193: }
22194: my $ishomedom;
1.171 raeburn 22195: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22196: $ishomedom = 1;
1.150 raeburn 22197: }
22198: if (ref($alltypes) eq 'ARRAY') {
22199: foreach my $type (@{$alltypes}) {
22200: my $rule;
1.210 raeburn 22201: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22202: (!$ishomedom)) {
1.171 raeburn 22203: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22204: }
22205: if ($rule eq 'specific') {
1.255 raeburn 22206: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22207: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22208: $rule = $specifiedhost;
22209: }
1.150 raeburn 22210: }
1.171 raeburn 22211: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22212: if (ref($currrules{$balancer}) eq 'HASH') {
22213: if ($rule ne $currrules{$balancer}{$type}) {
22214: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22215: }
22216: } elsif ($rule ne '') {
1.171 raeburn 22217: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22218: }
22219: }
22220: }
1.171 raeburn 22221: }
22222: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22223: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22224: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22225: $defaultshash{'loadbalancing'} = {};
22226: }
22227: my $putresult = &Apache::lonnet::put_dom('configuration',
22228: \%defaultshash,$dom);
22229: if ($putresult eq 'ok') {
22230: if (keys(%changes) > 0) {
1.252 raeburn 22231: my %toupdate;
1.171 raeburn 22232: if (ref($changes{'delete'}) eq 'ARRAY') {
22233: foreach my $balancer (sort(@{$changes{'delete'}})) {
22234: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22235: $toupdate{$balancer} = 1;
1.150 raeburn 22236: }
1.171 raeburn 22237: }
22238: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22239: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22240: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22241: $toupdate{$balancer} = 1;
1.171 raeburn 22242: }
22243: }
22244: if (ref($changes{'curr'}) eq 'HASH') {
22245: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22246: $toupdate{$balancer} = 1;
1.171 raeburn 22247: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22248: if ($changes{'curr'}{$balancer}{'targets'}) {
22249: my %offloadstr;
22250: foreach my $sparetype (@sparestypes) {
22251: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22252: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22253: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22254: }
22255: }
1.150 raeburn 22256: }
1.171 raeburn 22257: if (keys(%offloadstr) == 0) {
22258: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22259: } else {
1.171 raeburn 22260: my $showoffload;
22261: foreach my $sparetype (@sparestypes) {
22262: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22263: if (defined($offloadstr{$sparetype})) {
22264: $showoffload .= $offloadstr{$sparetype};
22265: } else {
22266: $showoffload .= &mt('None');
22267: }
22268: $showoffload .= (' 'x3);
22269: }
22270: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22271: }
22272: }
22273: }
1.171 raeburn 22274: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22275: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22276: foreach my $type (@{$alltypes}) {
22277: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22278: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22279: my $balancetext;
22280: if ($rule eq '') {
22281: $balancetext = $ruletitles{'default'};
1.209 raeburn 22282: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22283: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22284: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22285: foreach my $sparetype (@sparestypes) {
22286: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22287: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22288: }
22289: }
1.253 raeburn 22290: foreach my $item (@{$alltypes}) {
22291: next if ($item =~ /^_LC_ipchange/);
22292: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22293: if ($hasrule eq 'homeserver') {
22294: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22295: } else {
22296: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22297: if ($servers{$hasrule}) {
22298: $toupdate{$hasrule} = 1;
22299: }
22300: }
22301: }
22302: }
1.254 raeburn 22303: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
22304: $balancetext = $ruletitles{$rule};
22305: } else {
22306: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22307: $balancetext = $ruletitles{'particular'}.' '.$receiver;
22308: if ($receiver) {
22309: $toupdate{$receiver};
22310: }
22311: }
22312: } else {
22313: $balancetext = $ruletitles{$rule};
1.252 raeburn 22314: }
1.171 raeburn 22315: } else {
22316: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
22317: }
1.210 raeburn 22318: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 22319: }
22320: }
22321: }
22322: }
1.342 raeburn 22323: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 22324: if ($currcookies{$balancer}) {
22325: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
22326: $balancer).'</li>';
22327: } else {
22328: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
22329: $balancer).'</li>';
22330: }
1.342 raeburn 22331: }
1.375 raeburn 22332: }
22333: }
22334: if (keys(%toupdate)) {
22335: my %thismachine;
22336: my $updatedhere;
22337: my $cachetime = 60*60*24;
22338: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
22339: foreach my $lonhost (keys(%toupdate)) {
22340: if ($thismachine{$lonhost}) {
22341: unless ($updatedhere) {
22342: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
22343: $defaultshash{'loadbalancing'},
22344: $cachetime);
22345: $updatedhere = 1;
1.252 raeburn 22346: }
1.375 raeburn 22347: } else {
22348: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
22349: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 22350: }
1.150 raeburn 22351: }
1.171 raeburn 22352: }
22353: if ($resulttext ne '') {
22354: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 22355: } else {
22356: $resulttext = $nochgmsg;
22357: }
22358: } else {
1.171 raeburn 22359: $resulttext = $nochgmsg;
1.150 raeburn 22360: }
22361: } else {
1.171 raeburn 22362: $resulttext = '<span class="LC_error">'.
22363: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 22364: }
22365: } else {
1.171 raeburn 22366: $resulttext = $nochgmsg;
1.150 raeburn 22367: }
22368: return $resulttext;
22369: }
22370:
1.48 raeburn 22371: sub recurse_check {
22372: my ($chkcats,$categories,$depth,$name) = @_;
22373: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
22374: my $chg = 0;
22375: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
22376: my $category = $chkcats->[$depth]{$name}[$j];
22377: my $item;
22378: if ($category eq '') {
22379: $chg ++;
22380: } else {
22381: my $deeper = $depth + 1;
22382: $item = &escape($category).':'.&escape($name).':'.$depth;
22383: if ($chg) {
22384: $categories->{$item} -= $chg;
22385: }
22386: &recurse_check($chkcats,$categories,$deeper,$category);
22387: $deeper --;
22388: }
22389: }
22390: }
22391: return;
22392: }
22393:
22394: sub recurse_cat_deletes {
22395: my ($item,$coursecategories,$deletions) = @_;
22396: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
22397: my $subdepth = $depth + 1;
22398: if (ref($coursecategories) eq 'HASH') {
22399: foreach my $subitem (keys(%{$coursecategories})) {
22400: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
22401: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
22402: delete($coursecategories->{$subitem});
22403: $deletions->{$subitem} = 1;
22404: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 22405: }
1.48 raeburn 22406: }
22407: }
22408: return;
22409: }
22410:
1.125 raeburn 22411: sub active_dc_picker {
1.191 raeburn 22412: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 22413: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 22414: my @domcoord = keys(%domcoords);
22415: if (keys(%currhash)) {
22416: foreach my $dc (keys(%currhash)) {
22417: unless (exists($domcoords{$dc})) {
22418: push(@domcoord,$dc);
22419: }
22420: }
22421: }
22422: @domcoord = sort(@domcoord);
1.210 raeburn 22423: my $numdcs = scalar(@domcoord);
1.191 raeburn 22424: my $rows = 0;
22425: my $table;
1.125 raeburn 22426: if ($numdcs > 1) {
1.191 raeburn 22427: $table = '<table>';
22428: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 22429: my $rem = $i%($numinrow);
22430: if ($rem == 0) {
22431: if ($i > 0) {
1.191 raeburn 22432: $table .= '</tr>';
1.125 raeburn 22433: }
1.191 raeburn 22434: $table .= '<tr>';
22435: $rows ++;
1.125 raeburn 22436: }
1.191 raeburn 22437: my $check = '';
22438: if ($inputtype eq 'radio') {
22439: if (keys(%currhash) == 0) {
22440: if (!$i) {
22441: $check = ' checked="checked"';
22442: }
22443: } elsif (exists($currhash{$domcoord[$i]})) {
22444: $check = ' checked="checked"';
22445: }
22446: } else {
22447: if (exists($currhash{$domcoord[$i]})) {
22448: $check = ' checked="checked"';
1.125 raeburn 22449: }
22450: }
1.191 raeburn 22451: if ($i == @domcoord - 1) {
1.125 raeburn 22452: my $colsleft = $numinrow - $rem;
22453: if ($colsleft > 1) {
1.191 raeburn 22454: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 22455: } else {
1.191 raeburn 22456: $table .= '<td class="LC_left_item">';
1.125 raeburn 22457: }
22458: } else {
1.191 raeburn 22459: $table .= '<td class="LC_left_item">';
22460: }
22461: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
22462: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
22463: $table .= '<span class="LC_nobreak"><label>'.
22464: '<input type="'.$inputtype.'" name="'.$name.'"'.
22465: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
22466: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 22467: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 22468: }
1.219 raeburn 22469: $table .= '</label></span></td>';
1.191 raeburn 22470: }
22471: $table .= '</tr></table>';
22472: } elsif ($numdcs == 1) {
1.219 raeburn 22473: my ($dcname,$dcdom) = split(':',$domcoord[0]);
22474: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 22475: if ($inputtype eq 'radio') {
1.247 raeburn 22476: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 22477: if ($user ne $dcname.':'.$dcdom) {
22478: $table .= ' ('.$dcname.':'.$dcdom.')';
22479: }
1.191 raeburn 22480: } else {
22481: my $check;
22482: if (exists($currhash{$domcoord[0]})) {
22483: $check = ' checked="checked"';
1.125 raeburn 22484: }
1.247 raeburn 22485: $table = '<span class="LC_nobreak"><label>'.
22486: '<input type="checkbox" name="'.$name.'" '.
22487: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 22488: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 22489: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 22490: }
1.220 raeburn 22491: $table .= '</label></span>';
1.191 raeburn 22492: $rows ++;
1.125 raeburn 22493: }
22494: }
1.191 raeburn 22495: return ($numdcs,$table,$rows);
1.125 raeburn 22496: }
22497:
1.137 raeburn 22498: sub usersession_titles {
22499: return &Apache::lonlocal::texthash(
22500: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
22501: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 22502: spares => 'Servers offloaded to, when busy',
1.137 raeburn 22503: version => 'LON-CAPA version requirement',
1.138 raeburn 22504: excludedomain => 'Allow all, but exclude specific domains',
22505: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 22506: primary => 'Primary (checked first)',
1.154 raeburn 22507: default => 'Default',
1.137 raeburn 22508: );
22509: }
22510:
1.152 raeburn 22511: sub id_for_thisdom {
22512: my (%servers) = @_;
22513: my %altids;
22514: foreach my $server (keys(%servers)) {
22515: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22516: if ($serverhome ne $server) {
22517: $altids{$serverhome} = $server;
22518: }
22519: }
22520: return %altids;
22521: }
22522:
1.150 raeburn 22523: sub count_servers {
22524: my ($currbalancer,%servers) = @_;
22525: my (@spares,$numspares);
22526: foreach my $lonhost (sort(keys(%servers))) {
22527: next if ($currbalancer eq $lonhost);
22528: push(@spares,$lonhost);
22529: }
22530: if ($currbalancer) {
22531: $numspares = scalar(@spares);
22532: } else {
22533: $numspares = scalar(@spares) - 1;
22534: }
22535: return ($numspares,@spares);
22536: }
22537:
22538: sub lonbalance_targets_js {
1.171 raeburn 22539: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 22540: my $select = &mt('Select');
22541: my ($alltargets,$allishome,$allinsttypes,@alltypes);
22542: if (ref($servers) eq 'HASH') {
22543: $alltargets = join("','",sort(keys(%{$servers})));
22544: my @homedoms;
22545: foreach my $server (sort(keys(%{$servers}))) {
22546: if (&Apache::lonnet::host_domain($server) eq $dom) {
22547: push(@homedoms,'1');
22548: } else {
22549: push(@homedoms,'0');
22550: }
22551: }
22552: $allishome = join("','",@homedoms);
22553: }
22554: if (ref($types) eq 'ARRAY') {
22555: if (@{$types} > 0) {
22556: @alltypes = @{$types};
22557: }
22558: }
22559: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
22560: $allinsttypes = join("','",@alltypes);
1.342 raeburn 22561: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22562: if (ref($settings) eq 'HASH') {
22563: %existing = %{$settings};
22564: }
22565: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 22566: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 22567: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 22568: return <<"END";
22569:
22570: <script type="text/javascript">
22571: // <![CDATA[
22572:
1.171 raeburn 22573: currBalancers = new Array('$balancers');
22574:
22575: function toggleTargets(balnum) {
22576: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22577: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
22578: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
22579: var prevbalancer = prevhostitem.value;
22580: var baltotal = document.getElementById('loadbalancing_total').value;
22581: prevhostitem.value = balancer;
22582: if (prevbalancer != '') {
22583: var prevIdx = currBalancers.indexOf(prevbalancer);
22584: if (prevIdx != -1) {
22585: currBalancers.splice(prevIdx,1);
22586: }
22587: }
1.150 raeburn 22588: if (balancer == '') {
1.171 raeburn 22589: hideSpares(balnum);
1.150 raeburn 22590: } else {
1.171 raeburn 22591: var currIdx = currBalancers.indexOf(balancer);
22592: if (currIdx == -1) {
22593: currBalancers.push(balancer);
22594: }
1.150 raeburn 22595: var homedoms = new Array('$allishome');
1.171 raeburn 22596: var ishomedom = homedoms[lonhostitem.selectedIndex];
22597: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 22598: }
1.171 raeburn 22599: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 22600: return;
22601: }
22602:
1.171 raeburn 22603: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 22604: var alltargets = new Array('$alltargets');
22605: var insttypes = new Array('$allinsttypes');
1.151 raeburn 22606: var offloadtypes = new Array('primary','default');
22607:
1.171 raeburn 22608: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
22609: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 22610:
1.151 raeburn 22611: for (var i=0; i<offloadtypes.length; i++) {
22612: var count = 0;
22613: for (var j=0; j<alltargets.length; j++) {
22614: if (alltargets[j] != balancer) {
1.171 raeburn 22615: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
22616: item.value = alltargets[j];
22617: item.style.textAlign='left';
22618: item.style.textFace='normal';
22619: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
22620: if (currBalancers.indexOf(alltargets[j]) == -1) {
22621: item.disabled = '';
22622: } else {
22623: item.disabled = 'disabled';
22624: item.checked = false;
22625: }
1.151 raeburn 22626: count ++;
22627: }
1.150 raeburn 22628: }
22629: }
1.151 raeburn 22630: for (var k=0; k<insttypes.length; k++) {
22631: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 22632: if (ishomedom == 1) {
1.171 raeburn 22633: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22634: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22635: } else {
1.171 raeburn 22636: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22637: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 22638: }
22639: } else {
1.171 raeburn 22640: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22641: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22642: }
1.151 raeburn 22643: if ((insttypes[k] != '_LC_external') &&
22644: ((insttypes[k] != '_LC_internetdom') ||
22645: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 22646: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
22647: item.options.length = 0;
22648: item.options[0] = new Option("","",true,true);
1.210 raeburn 22649: var idx = 0;
1.151 raeburn 22650: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 22651: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
22652: idx ++;
22653: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 22654: }
22655: }
22656: }
22657: }
22658: return;
22659: }
22660:
1.171 raeburn 22661: function hideSpares(balnum) {
1.150 raeburn 22662: var alltargets = new Array('$alltargets');
22663: var insttypes = new Array('$allinsttypes');
22664: var offloadtypes = new Array('primary','default');
22665:
1.171 raeburn 22666: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
22667: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 22668:
22669: var total = alltargets.length - 1;
22670: for (var i=0; i<offloadtypes; i++) {
22671: for (var j=0; j<total; j++) {
1.171 raeburn 22672: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
22673: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
22674: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 22675: }
1.150 raeburn 22676: }
22677: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 22678: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22679: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22680: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22681: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22682: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22683: }
22684: }
22685: return;
22686: }
22687:
1.171 raeburn 22688: function checkOffloads(item,balnum,type) {
1.150 raeburn 22689: var alltargets = new Array('$alltargets');
22690: var offloadtypes = new Array('primary','default');
22691: if (item.checked) {
22692: var total = alltargets.length - 1;
22693: var other;
22694: if (type == offloadtypes[0]) {
1.151 raeburn 22695: other = offloadtypes[1];
1.150 raeburn 22696: } else {
1.151 raeburn 22697: other = offloadtypes[0];
1.150 raeburn 22698: }
22699: for (var i=0; i<total; i++) {
1.171 raeburn 22700: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22701: if (server == item.value) {
1.171 raeburn 22702: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22703: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22704: }
22705: }
22706: }
22707: }
22708: return;
22709: }
22710:
1.171 raeburn 22711: function singleServerToggle(balnum,type) {
22712: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22713: if (offloadtoSelIdx == 0) {
1.171 raeburn 22714: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22715: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22716:
22717: } else {
1.171 raeburn 22718: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22719: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22720: }
22721: return;
22722: }
22723:
1.171 raeburn 22724: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22725: if (type == '_LC_external') {
1.171 raeburn 22726: return;
1.150 raeburn 22727: }
1.171 raeburn 22728: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22729: for (var i=0; i<typesRules.length; i++) {
22730: if (formname.elements[typesRules[i]].checked) {
22731: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22732: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22733: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22734: } else {
1.171 raeburn 22735: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22736: }
22737: }
22738: }
22739: return;
22740: }
22741:
22742: function balancerDeleteChange(balnum) {
22743: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22744: var baltotal = document.getElementById('loadbalancing_total').value;
22745: var addtarget;
22746: var removetarget;
22747: var action = 'delete';
22748: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22749: var lonhost = hostitem.value;
22750: var currIdx = currBalancers.indexOf(lonhost);
22751: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22752: if (currIdx != -1) {
22753: currBalancers.splice(currIdx,1);
22754: }
22755: addtarget = lonhost;
22756: } else {
22757: if (currIdx == -1) {
22758: currBalancers.push(lonhost);
22759: }
22760: removetarget = lonhost;
22761: action = 'undelete';
22762: }
22763: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22764: }
22765: return;
22766: }
22767:
22768: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22769: if (baltotal > 1) {
22770: var offloadtypes = new Array('primary','default');
22771: var alltargets = new Array('$alltargets');
22772: var insttypes = new Array('$allinsttypes');
22773: for (var i=0; i<baltotal; i++) {
22774: if (i != balnum) {
22775: for (var j=0; j<offloadtypes.length; j++) {
22776: var total = alltargets.length - 1;
22777: for (var k=0; k<total; k++) {
22778: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22779: var server = serveritem.value;
22780: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22781: if (server == addtarget) {
22782: serveritem.disabled = '';
22783: }
22784: }
22785: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22786: if (server == removetarget) {
22787: serveritem.disabled = 'disabled';
22788: serveritem.checked = false;
22789: }
22790: }
22791: }
22792: }
22793: for (var j=0; j<insttypes.length; j++) {
22794: if (insttypes[j] != '_LC_external') {
22795: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22796: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22797: var currSel = singleserver.selectedIndex;
22798: var currVal = singleserver.options[currSel].value;
22799: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22800: var numoptions = singleserver.options.length;
22801: var needsnew = 1;
22802: for (var k=0; k<numoptions; k++) {
22803: if (singleserver.options[k] == addtarget) {
22804: needsnew = 0;
22805: break;
22806: }
22807: }
22808: if (needsnew == 1) {
22809: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22810: }
22811: }
22812: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22813: singleserver.options.length = 0;
22814: if ((currVal) && (currVal != removetarget)) {
22815: singleserver.options[0] = new Option("","",false,false);
22816: } else {
22817: singleserver.options[0] = new Option("","",true,true);
22818: }
22819: var idx = 0;
22820: for (var m=0; m<alltargets.length; m++) {
22821: if (currBalancers.indexOf(alltargets[m]) == -1) {
22822: idx ++;
22823: if (currVal == alltargets[m]) {
22824: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22825: } else {
22826: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22827: }
22828: }
22829: }
22830: }
22831: }
22832: }
22833: }
1.150 raeburn 22834: }
22835: }
22836: }
22837: return;
22838: }
22839:
1.152 raeburn 22840: // ]]>
22841: </script>
22842:
22843: END
22844: }
22845:
1.372 raeburn 22846:
1.152 raeburn 22847: sub new_spares_js {
22848: my @sparestypes = ('primary','default');
22849: my $types = join("','",@sparestypes);
22850: my $select = &mt('Select');
22851: return <<"END";
22852:
22853: <script type="text/javascript">
22854: // <![CDATA[
22855:
22856: function updateNewSpares(formname,lonhost) {
22857: var types = new Array('$types');
22858: var include = new Array();
22859: var exclude = new Array();
22860: for (var i=0; i<types.length; i++) {
22861: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22862: for (var j=0; j<spareboxes.length; j++) {
22863: if (formname.elements[spareboxes[j]].checked) {
22864: exclude.push(formname.elements[spareboxes[j]].value);
22865: } else {
22866: include.push(formname.elements[spareboxes[j]].value);
22867: }
22868: }
22869: }
22870: for (var i=0; i<types.length; i++) {
22871: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22872: var selIdx = newSpare.selectedIndex;
22873: var currnew = newSpare.options[selIdx].value;
22874: var okSpares = new Array();
22875: for (var j=0; j<newSpare.options.length; j++) {
22876: var possible = newSpare.options[j].value;
22877: if (possible != '') {
22878: if (exclude.indexOf(possible) == -1) {
22879: okSpares.push(possible);
22880: } else {
22881: if (currnew == possible) {
22882: selIdx = 0;
22883: }
22884: }
22885: }
22886: }
22887: for (var k=0; k<include.length; k++) {
22888: if (okSpares.indexOf(include[k]) == -1) {
22889: okSpares.push(include[k]);
22890: }
22891: }
22892: okSpares.sort();
22893: newSpare.options.length = 0;
22894: if (selIdx == 0) {
22895: newSpare.options[0] = new Option("$select","",true,true);
22896: } else {
22897: newSpare.options[0] = new Option("$select","",false,false);
22898: }
22899: for (var m=0; m<okSpares.length; m++) {
22900: var idx = m+1;
22901: var selThis = 0;
22902: if (selIdx != 0) {
22903: if (okSpares[m] == currnew) {
22904: selThis = 1;
22905: }
22906: }
22907: if (selThis == 1) {
22908: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22909: } else {
22910: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22911: }
22912: }
22913: }
22914: return;
22915: }
22916:
22917: function checkNewSpares(lonhost,type) {
22918: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22919: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22920: if (chosen != '') {
1.152 raeburn 22921: var othertype;
22922: var othernewSpare;
22923: if (type == 'primary') {
22924: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22925: }
22926: if (type == 'default') {
22927: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22928: }
22929: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22930: othernewSpare.selectedIndex = 0;
22931: }
22932: }
22933: return;
22934: }
22935:
22936: // ]]>
22937: </script>
22938:
22939: END
22940:
22941: }
22942:
22943: sub common_domprefs_js {
22944: return <<"END";
22945:
22946: <script type="text/javascript">
22947: // <![CDATA[
22948:
1.150 raeburn 22949: function getIndicesByName(formname,item) {
1.152 raeburn 22950: var group = new Array();
1.150 raeburn 22951: for (var i=0;i<formname.elements.length;i++) {
22952: if (formname.elements[i].name == item) {
1.152 raeburn 22953: group.push(formname.elements[i].id);
1.150 raeburn 22954: }
22955: }
1.152 raeburn 22956: return group;
1.150 raeburn 22957: }
22958:
22959: // ]]>
22960: </script>
22961:
22962: END
1.152 raeburn 22963:
1.150 raeburn 22964: }
22965:
1.165 raeburn 22966: sub recaptcha_js {
22967: my %lt = &captcha_phrases();
22968: return <<"END";
22969:
22970: <script type="text/javascript">
22971: // <![CDATA[
22972:
22973: function updateCaptcha(caller,context) {
22974: var privitem;
22975: var pubitem;
22976: var privtext;
22977: var pubtext;
1.269 raeburn 22978: var versionitem;
22979: var versiontext;
1.165 raeburn 22980: if (document.getElementById(context+'_recaptchapub')) {
22981: pubitem = document.getElementById(context+'_recaptchapub');
22982: } else {
22983: return;
22984: }
22985: if (document.getElementById(context+'_recaptchapriv')) {
22986: privitem = document.getElementById(context+'_recaptchapriv');
22987: } else {
22988: return;
22989: }
22990: if (document.getElementById(context+'_recaptchapubtxt')) {
22991: pubtext = document.getElementById(context+'_recaptchapubtxt');
22992: } else {
22993: return;
22994: }
22995: if (document.getElementById(context+'_recaptchaprivtxt')) {
22996: privtext = document.getElementById(context+'_recaptchaprivtxt');
22997: } else {
22998: return;
22999: }
1.269 raeburn 23000: if (document.getElementById(context+'_recaptchaversion')) {
23001: versionitem = document.getElementById(context+'_recaptchaversion');
23002: } else {
23003: return;
23004: }
23005: if (document.getElementById(context+'_recaptchavertxt')) {
23006: versiontext = document.getElementById(context+'_recaptchavertxt');
23007: } else {
23008: return;
23009: }
1.165 raeburn 23010: if (caller.checked) {
23011: if (caller.value == 'recaptcha') {
23012: pubitem.type = 'text';
23013: privitem.type = 'text';
23014: pubitem.size = '40';
23015: privitem.size = '40';
23016: pubtext.innerHTML = "$lt{'pub'}";
23017: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23018: versionitem.type = 'text';
23019: versionitem.size = '3';
1.289 raeburn 23020: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23021: } else {
23022: pubitem.type = 'hidden';
23023: privitem.type = 'hidden';
1.269 raeburn 23024: versionitem.type = 'hidden';
1.165 raeburn 23025: pubtext.innerHTML = '';
23026: privtext.innerHTML = '';
1.269 raeburn 23027: versiontext.innerHTML = '';
1.165 raeburn 23028: }
23029: }
23030: return;
23031: }
23032:
23033: // ]]>
23034: </script>
23035:
23036: END
23037:
23038: }
23039:
1.236 raeburn 23040: sub toggle_display_js {
1.192 raeburn 23041: return <<"END";
23042:
23043: <script type="text/javascript">
23044: // <![CDATA[
23045:
1.236 raeburn 23046: function toggleDisplay(domForm,caller) {
23047: if (document.getElementById(caller)) {
23048: var divitem = document.getElementById(caller);
23049: var optionsElement = domForm.coursecredits;
1.264 raeburn 23050: var checkval = 1;
23051: var dispval = 'block';
1.303 raeburn 23052: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23053: if (caller == 'emailoptions') {
1.372 raeburn 23054: optionsElement = domForm.cancreate_email;
1.236 raeburn 23055: }
1.257 raeburn 23056: if (caller == 'studentsubmission') {
23057: optionsElement = domForm.postsubmit;
23058: }
1.264 raeburn 23059: if (caller == 'cloneinstcode') {
23060: optionsElement = domForm.canclone;
23061: checkval = 'instcode';
23062: }
1.303 raeburn 23063: if (selfcreateRegExp.test(caller)) {
23064: optionsElement = domForm.elements[caller];
23065: checkval = 'other';
23066: dispval = 'inline'
23067: }
1.236 raeburn 23068: if (optionsElement.length) {
1.192 raeburn 23069: var currval;
1.236 raeburn 23070: for (var i=0; i<optionsElement.length; i++) {
23071: if (optionsElement[i].checked) {
23072: currval = optionsElement[i].value;
1.192 raeburn 23073: }
23074: }
1.264 raeburn 23075: if (currval == checkval) {
23076: divitem.style.display = dispval;
1.192 raeburn 23077: } else {
1.236 raeburn 23078: divitem.style.display = 'none';
1.192 raeburn 23079: }
23080: }
23081: }
23082: return;
23083: }
23084:
23085: // ]]>
23086: </script>
23087:
23088: END
23089:
23090: }
23091:
1.165 raeburn 23092: sub captcha_phrases {
23093: return &Apache::lonlocal::texthash (
23094: priv => 'Private key',
23095: pub => 'Public key',
23096: original => 'original (CAPTCHA)',
23097: recaptcha => 'successor (ReCAPTCHA)',
23098: notused => 'unused',
1.289 raeburn 23099: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23100: );
23101: }
23102:
1.205 raeburn 23103: sub devalidate_remote_domconfs {
1.212 raeburn 23104: my ($dom,$cachekeys) = @_;
23105: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23106: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23107: my %thismachine;
23108: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23109: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23110: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23111: 'ipaccess','trust');
1.386 raeburn 23112: my %cache_by_lonhost;
23113: if (exists($cachekeys->{'samllanding'})) {
23114: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23115: my %landing = %{$cachekeys->{'samllanding'}};
23116: my %domservers = &Apache::lonnet::get_servers($dom);
23117: if (keys(%domservers)) {
23118: foreach my $server (keys(%domservers)) {
23119: my @cached;
23120: next if ($thismachine{$server});
23121: if ($landing{$server}) {
23122: push(@cached,&escape('samllanding').':'.&escape($server));
23123: }
23124: if (@cached) {
23125: $cache_by_lonhost{$server} = \@cached;
23126: }
23127: }
23128: }
23129: }
23130: }
1.260 raeburn 23131: if (keys(%servers)) {
1.205 raeburn 23132: foreach my $server (keys(%servers)) {
23133: next if ($thismachine{$server});
1.212 raeburn 23134: my @cached;
23135: foreach my $name (@posscached) {
23136: if ($cachekeys->{$name}) {
1.388 raeburn 23137: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23138: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23139: foreach my $key (keys(%{$cachekeys->{$name}})) {
23140: push(@cached,&escape($name).':'.&escape($key));
23141: }
23142: }
23143: } else {
23144: push(@cached,&escape($name).':'.&escape($dom));
23145: }
1.212 raeburn 23146: }
23147: }
1.386 raeburn 23148: if ((exists($cache_by_lonhost{$server})) &&
23149: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23150: push(@cached,@{$cache_by_lonhost{$server}});
23151: }
1.212 raeburn 23152: if (@cached) {
23153: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23154: }
1.205 raeburn 23155: }
23156: }
23157: return;
23158: }
23159:
1.3 raeburn 23160: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>