Annotation of loncom/interface/domainprefs.pm, revision 1.417
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.417 ! raeburn 4: # $Id: domainprefs.pm,v 1.416 2022/11/11 02:30: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.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.1 raeburn 180:
1.155 raeburn 181: my $registered_cleanup;
182: my $modified_urls;
183:
1.1 raeburn 184: sub handler {
185: my $r=shift;
186: if ($r->header_only) {
187: &Apache::loncommon::content_type($r,'text/html');
188: $r->send_http_header;
189: return OK;
190: }
191:
1.91 raeburn 192: my $context = 'domain';
1.1 raeburn 193: my $dom = $env{'request.role.domain'};
1.5 albertel 194: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 195: if (&Apache::lonnet::allowed('mau',$dom)) {
196: &Apache::loncommon::content_type($r,'text/html');
197: $r->send_http_header;
198: } else {
199: $env{'user.error.msg'}=
200: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
201: return HTTP_NOT_ACCEPTABLE;
202: }
1.155 raeburn 203:
204: $registered_cleanup=0;
205: @{$modified_urls}=();
206:
1.1 raeburn 207: &Apache::lonhtmlcommon::clear_breadcrumbs();
208: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 209: ['phase','actions']);
1.30 raeburn 210: my $phase = 'pickactions';
1.3 raeburn 211: if ( exists($env{'form.phase'}) ) {
212: $phase = $env{'form.phase'};
213: }
1.150 raeburn 214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 215: my %domconfig =
1.6 raeburn 216: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 217: 'quotas','autoenroll','autoupdate','autocreate',
218: 'directorysrch','usercreation','usermodification',
219: 'contacts','defaults','scantron','coursecategories',
220: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 221: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 222: 'requestauthor','selfenrollment','inststatus',
1.405 raeburn 223: 'ltitools','ssl','trust','lti','ltisec','privacy','passwords',
1.394 raeburn 224: 'proctoring','wafproxy','ipaccess'],$dom);
1.320 raeburn 225: my %encconfig =
1.405 raeburn 226: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.297 raeburn 227: if (ref($domconfig{'ltitools'}) eq 'HASH') {
228: if (ref($encconfig{'ltitools'}) eq 'HASH') {
229: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 230: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
231: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 232: foreach my $item ('key','secret') {
233: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
234: }
235: }
236: }
237: }
238: }
1.320 raeburn 239: if (ref($domconfig{'lti'}) eq 'HASH') {
240: if (ref($encconfig{'lti'}) eq 'HASH') {
241: foreach my $id (keys(%{$domconfig{'lti'}})) {
242: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
243: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
244: foreach my $item ('key','secret') {
245: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
246: }
247: }
248: }
249: }
250: }
1.405 raeburn 251: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 252: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 253: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 254: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
255: unless ($id =~ /^\d+$/) {
256: delete($domconfig{'ltisec'}{'linkprot'}{$id});
257: }
258: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 259: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
260: foreach my $item ('key','secret') {
1.406 raeburn 261: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 262: }
263: }
264: }
265: }
266: }
267: }
1.372 raeburn 268: if (ref($domconfig{'proctoring'}) eq 'HASH') {
269: if (ref($encconfig{'proctoring'}) eq 'HASH') {
270: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
271: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
272: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
273: foreach my $item ('key','secret') {
274: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
275: }
276: }
277: }
278: }
279: }
1.394 raeburn 280: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
281: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 282: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 283: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 284: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 285: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
286: 'trust','lti');
1.171 raeburn 287: my %existing;
288: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
289: %existing = %{$domconfig{'loadbalancing'}};
290: }
291: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 292: push(@prefs_order,'loadbalancing');
293: }
1.30 raeburn 294: my %prefs = (
295: 'rolecolors' =>
296: { text => 'Default color schemes',
1.67 raeburn 297: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 298: header => [{col1 => 'Student Settings',
299: col2 => '',},
300: {col1 => 'Coordinator Settings',
301: col2 => '',},
302: {col1 => 'Author Settings',
303: col2 => '',},
304: {col1 => 'Administrator Settings',
305: col2 => '',}],
1.230 raeburn 306: print => \&print_rolecolors,
307: modify => \&modify_rolecolors,
1.30 raeburn 308: },
1.110 raeburn 309: 'login' =>
1.30 raeburn 310: { text => 'Log-in page options',
1.67 raeburn 311: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 312: header => [{col1 => 'Log-in Page Items',
313: col2 => '',},
314: {col1 => 'Log-in Help',
1.256 raeburn 315: col2 => 'Value'},
316: {col1 => 'Custom HTML in document head',
1.386 raeburn 317: col2 => 'Value'},
318: {col1 => 'SSO',
319: col2 => 'Dual login: SSO and non-SSO options'},
320: ],
1.230 raeburn 321: print => \&print_login,
322: modify => \&modify_login,
1.30 raeburn 323: },
1.43 raeburn 324: 'defaults' =>
1.236 raeburn 325: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 326: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 327: header => [{col1 => 'Setting',
1.236 raeburn 328: col2 => 'Value'},
329: {col1 => 'Institutional user types',
1.409 raeburn 330: col2 => 'Name displayed'},
331: {col1 => 'Mapping for missing usernames via standard log-in',
332: col2 => 'Rules in use'}],
1.230 raeburn 333: print => \&print_defaults,
334: modify => \&modify_defaults,
1.43 raeburn 335: },
1.381 raeburn 336: 'wafproxy' =>
337: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 338: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 339: header => [{col1 => 'Domain(s)',
340: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 341: },
1.381 raeburn 342: {col1 => 'Domain(s)',
343: col2 => 'WAF Configuration',}],
1.373 raeburn 344: print => \&print_wafproxy,
1.381 raeburn 345: modify => \&modify_wafproxy,
1.373 raeburn 346: },
1.354 raeburn 347: 'passwords' =>
348: { text => 'Passwords (Internal authentication)',
349: help => 'Domain_Configuration_Passwords',
350: header => [{col1 => 'Resetting Forgotten Password',
351: col2 => 'Settings'},
352: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
353: col2 => 'Settings'},
354: {col1 => 'Rules for LON-CAPA Passwords',
355: col2 => 'Settings'},
356: {col1 => 'Course Owner Changing Student Passwords',
357: col2 => 'Settings'}],
358: print => \&print_passwords,
359: modify => \&modify_passwords,
360: },
1.30 raeburn 361: 'quotas' =>
1.413 raeburn 362: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 363: help => 'Domain_Configuration_Quotas',
1.77 raeburn 364: header => [{col1 => 'User affiliation',
1.72 raeburn 365: col2 => 'Available tools',
1.213 raeburn 366: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 367: print => \&print_quotas,
368: modify => \&modify_quotas,
1.30 raeburn 369: },
370: 'autoenroll' =>
371: { text => 'Auto-enrollment settings',
1.67 raeburn 372: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 373: header => [{col1 => 'Configuration setting',
374: col2 => 'Value(s)'}],
1.230 raeburn 375: print => \&print_autoenroll,
376: modify => \&modify_autoenroll,
1.30 raeburn 377: },
378: 'autoupdate' =>
379: { text => 'Auto-update settings',
1.67 raeburn 380: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 381: header => [{col1 => 'Setting',
382: col2 => 'Value',},
1.131 raeburn 383: {col1 => 'Setting',
384: col2 => 'Affiliation'},
1.43 raeburn 385: {col1 => 'User population',
1.227 bisitz 386: col2 => 'Updatable user data'}],
1.230 raeburn 387: print => \&print_autoupdate,
388: modify => \&modify_autoupdate,
1.30 raeburn 389: },
1.125 raeburn 390: 'autocreate' =>
391: { text => 'Auto-course creation settings',
392: help => 'Domain_Configuration_Auto_Creation',
393: header => [{col1 => 'Configuration Setting',
394: col2 => 'Value',}],
1.230 raeburn 395: print => \&print_autocreate,
396: modify => \&modify_autocreate,
1.125 raeburn 397: },
1.30 raeburn 398: 'directorysrch' =>
1.277 raeburn 399: { text => 'Directory searches',
1.67 raeburn 400: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 401: header => [{col1 => 'Institutional Directory Setting',
402: col2 => 'Value',},
403: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 404: col2 => 'Value',}],
1.230 raeburn 405: print => \&print_directorysrch,
406: modify => \&modify_directorysrch,
1.30 raeburn 407: },
408: 'contacts' =>
1.286 raeburn 409: { text => 'E-mail addresses and helpform',
1.67 raeburn 410: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 411: header => [{col1 => 'Default e-mail addresses',
412: col2 => 'Value',},
413: {col1 => 'Recipient(s) for notifications',
414: col2 => 'Value',},
1.340 raeburn 415: {col1 => 'Nightly status check e-mail',
416: col2 => 'Settings',},
1.286 raeburn 417: {col1 => 'Ask helpdesk form settings',
418: col2 => 'Value',},],
1.230 raeburn 419: print => \&print_contacts,
420: modify => \&modify_contacts,
1.30 raeburn 421: },
422: 'usercreation' =>
423: { text => 'User creation',
1.67 raeburn 424: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 425: header => [{col1 => 'Format rule type',
426: col2 => 'Format rules in force'},
1.34 raeburn 427: {col1 => 'User account creation',
428: col2 => 'Usernames which may be created',},
1.30 raeburn 429: {col1 => 'Context',
1.43 raeburn 430: col2 => 'Assignable authentication types'}],
1.230 raeburn 431: print => \&print_usercreation,
432: modify => \&modify_usercreation,
1.30 raeburn 433: },
1.224 raeburn 434: 'selfcreation' =>
435: { text => 'Users self-creating accounts',
436: help => 'Domain_Configuration_Self_Creation',
437: header => [{col1 => 'Self-creation with institutional username',
438: col2 => 'Enabled?'},
439: {col1 => 'Institutional user type (login/SSO self-creation)',
440: col2 => 'Information user can enter'},
1.303 raeburn 441: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 442: col2 => 'Settings'}],
1.230 raeburn 443: print => \&print_selfcreation,
444: modify => \&modify_selfcreation,
1.224 raeburn 445: },
1.69 raeburn 446: 'usermodification' =>
1.33 raeburn 447: { text => 'User modification',
1.67 raeburn 448: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 449: header => [{col1 => 'Target user has role',
1.227 bisitz 450: col2 => 'User information updatable in author context'},
1.33 raeburn 451: {col1 => 'Target user has role',
1.227 bisitz 452: col2 => 'User information updatable in course context'}],
1.230 raeburn 453: print => \&print_usermodification,
454: modify => \&modify_usermodification,
1.33 raeburn 455: },
1.69 raeburn 456: 'scantron' =>
1.346 raeburn 457: { text => 'Bubblesheet format',
1.67 raeburn 458: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 459: header => [ {col1 => 'Bubblesheet format file',
460: col2 => ''},
461: {col1 => 'Bubblesheet data upload formats',
462: col2 => 'Settings'}],
1.230 raeburn 463: print => \&print_scantron,
464: modify => \&modify_scantron,
1.46 raeburn 465: },
1.86 raeburn 466: 'requestcourses' =>
467: {text => 'Request creation of courses',
468: help => 'Domain_Configuration_Request_Courses',
469: header => [{col1 => 'User affiliation',
1.102 raeburn 470: col2 => 'Availability/Processing of requests',},
471: {col1 => 'Setting',
1.216 raeburn 472: col2 => 'Value'},
473: {col1 => 'Available textbooks',
1.235 raeburn 474: col2 => ''},
1.242 raeburn 475: {col1 => 'Available templates',
476: col2 => ''},
1.235 raeburn 477: {col1 => 'Validation (not official courses)',
478: col2 => 'Value'},],
1.230 raeburn 479: print => \&print_quotas,
480: modify => \&modify_quotas,
1.86 raeburn 481: },
1.163 raeburn 482: 'requestauthor' =>
1.223 bisitz 483: {text => 'Request Authoring Space',
1.163 raeburn 484: help => 'Domain_Configuration_Request_Author',
485: header => [{col1 => 'User affiliation',
486: col2 => 'Availability/Processing of requests',},
487: {col1 => 'Setting',
488: col2 => 'Value'}],
1.230 raeburn 489: print => \&print_quotas,
490: modify => \&modify_quotas,
1.163 raeburn 491: },
1.69 raeburn 492: 'coursecategories' =>
1.120 raeburn 493: { text => 'Cataloging of courses/communities',
1.67 raeburn 494: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 495: header => [{col1 => 'Catalog type/availability',
496: col2 => '',},
497: {col1 => 'Category settings for standard catalog',
1.57 raeburn 498: col2 => '',},
499: {col1 => 'Categories',
500: col2 => '',
501: }],
1.230 raeburn 502: print => \&print_coursecategories,
503: modify => \&modify_coursecategories,
1.69 raeburn 504: },
505: 'serverstatuses' =>
1.77 raeburn 506: {text => 'Access to server status pages',
1.69 raeburn 507: help => 'Domain_Configuration_Server_Status',
508: header => [{col1 => 'Status Page',
509: col2 => 'Other named users',
510: col3 => 'Specific IPs',
511: }],
1.230 raeburn 512: print => \&print_serverstatuses,
513: modify => \&modify_serverstatuses,
1.69 raeburn 514: },
1.118 jms 515: 'helpsettings' =>
1.282 raeburn 516: {text => 'Support settings',
1.118 jms 517: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 518: header => [{col1 => 'Help Page Settings (logged-in users)',
519: col2 => 'Value'},
520: {col1 => 'Helpdesk Roles',
521: col2 => 'Settings'},],
1.230 raeburn 522: print => \&print_helpsettings,
523: modify => \&modify_helpsettings,
1.118 jms 524: },
1.121 raeburn 525: 'coursedefaults' =>
526: {text => 'Course/Community defaults',
527: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 528: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
529: col2 => 'Value',},
530: {col1 => 'Defaults which can be overridden for each course by a DC',
531: col2 => 'Value',},],
1.230 raeburn 532: print => \&print_coursedefaults,
533: modify => \&modify_coursedefaults,
1.121 raeburn 534: },
1.231 raeburn 535: 'selfenrollment' =>
536: {text => 'Self-enrollment in Course/Community',
537: help => 'Domain_Configuration_Selfenrollment',
538: header => [{col1 => 'Configuration Rights',
539: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
540: {col1 => 'Defaults',
541: col2 => 'Value'},
542: {col1 => 'Self-enrollment validation (optional)',
543: col2 => 'Value'},],
544: print => \&print_selfenrollment,
545: modify => \&modify_selfenrollment,
546: },
1.120 raeburn 547: 'privacy' =>
1.357 raeburn 548: {text => 'Availability of User Information',
1.120 raeburn 549: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 550: header => [{col1 => 'Role assigned in different domain',
551: col2 => 'Approval options'},
552: {col1 => 'Role assigned in different domain to user of type',
553: col2 => 'User information available in that domain'},
554: {col1 => "Role assigned in user's domain",
555: col2 => 'Information viewable by privileged user'},
556: {col1 => "Role assigned in user's domain",
557: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 558: print => \&print_privacy,
559: modify => \&modify_privacy,
1.120 raeburn 560: },
1.141 raeburn 561: 'usersessions' =>
1.145 raeburn 562: {text => 'User session hosting/offloading',
1.137 raeburn 563: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 564: header => [{col1 => 'Domain server',
565: col2 => 'Servers to offload sessions to when busy'},
566: {col1 => 'Hosting of users from other domains',
1.137 raeburn 567: col2 => 'Rules'},
568: {col1 => "Hosting domain's own users elsewhere",
569: col2 => 'Rules'}],
1.230 raeburn 570: print => \&print_usersessions,
571: modify => \&modify_usersessions,
1.137 raeburn 572: },
1.279 raeburn 573: 'loadbalancing' =>
1.185 raeburn 574: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 575: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 576: header => [{col1 => 'Balancers',
1.150 raeburn 577: col2 => 'Default destinations',
1.183 bisitz 578: col3 => 'User affiliation',
1.150 raeburn 579: col4 => 'Overrides'},
580: ],
1.230 raeburn 581: print => \&print_loadbalancing,
582: modify => \&modify_loadbalancing,
1.150 raeburn 583: },
1.279 raeburn 584: 'ltitools' =>
1.267 raeburn 585: {text => 'External Tools (LTI)',
1.296 raeburn 586: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 587: header => [{col1 => 'Setting',
588: col2 => 'Value',}],
589: print => \&print_ltitools,
590: modify => \&modify_ltitools,
591: },
1.372 raeburn 592: 'proctoring' =>
593: {text => 'Remote Proctoring Integration',
594: help => 'Domain_Configuration_Proctoring',
595: header => [{col1 => 'Name',
596: col2 => 'Configuration'}],
597: print => \&print_proctoring,
598: modify => \&modify_proctoring,
599: },
1.279 raeburn 600: 'ssl' =>
1.275 raeburn 601: {text => 'LON-CAPA Network (SSL)',
602: help => 'Domain_Configuration_Network_SSL',
603: header => [{col1 => 'Server',
604: col2 => 'Certificate Status'},
605: {col1 => 'Connections to other servers',
606: col2 => 'Rules'},
1.293 raeburn 607: {col1 => 'Connections from other servers',
608: col2 => 'Rules'},
1.275 raeburn 609: {col1 => "Replicating domain's published content",
610: col2 => 'Rules'}],
611: print => \&print_ssl,
612: modify => \&modify_ssl,
613: },
1.279 raeburn 614: 'trust' =>
615: {text => 'Trust Settings',
616: help => 'Domain_Configuration_Trust',
617: header => [{col1 => "Access to this domain's content by others",
618: col2 => 'Rules'},
619: {col1 => "Access to other domain's content by this domain",
620: col2 => 'Rules'},
621: {col1 => "Enrollment in this domain's courses by others",
622: col2 => 'Rules',},
623: {col1 => "Co-author roles in this domain for others",
624: col2 => 'Rules',},
625: {col1 => "Co-author roles for this domain's users elsewhere",
626: col2 => 'Rules',},
627: {col1 => "Domain roles in this domain assignable to others",
628: col2 => 'Rules'},
629: {col1 => "Course catalog for this domain displayed elsewhere",
630: col2 => 'Rules'},
631: {col1 => "Requests for creation of courses in this domain by others",
632: col2 => 'Rules'},
633: {col1 => "Users in other domains can send messages to this domain",
634: col2 => 'Rules'},],
635: print => \&print_trust,
636: modify => \&modify_trust,
637: },
1.320 raeburn 638: 'lti' =>
1.405 raeburn 639: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 640: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 641: header => [{col1 => 'Encryption of shared secrets',
642: col2 => 'Settings'},
643: {col1 => 'Rules for shared secrets',
644: col2 => 'Settings'},
1.406 raeburn 645: {col1 => 'Link Protectors',
1.405 raeburn 646: col2 => 'Settings'},
647: {col1 => 'Consumers',
648: col2 => 'Settings'},],
1.320 raeburn 649: print => \&print_lti,
650: modify => \&modify_lti,
651: },
1.394 raeburn 652: 'ipaccess' =>
653: {text => 'IP-based access control',
654: help => 'Domain_Configuration_IP_Access',
655: header => [{col1 => 'Setting',
656: col2 => 'Value'},],
657: print => \&print_ipaccess,
658: modify => \&modify_ipaccess,
659: },
1.3 raeburn 660: );
1.110 raeburn 661: if (keys(%servers) > 1) {
662: $prefs{'login'} = { text => 'Log-in page options',
663: help => 'Domain_Configuration_Login_Page',
664: header => [{col1 => 'Log-in Service',
665: col2 => 'Server Setting',},
666: {col1 => 'Log-in Page Items',
1.405 raeburn 667: col2 => 'Settings'},
1.168 raeburn 668: {col1 => 'Log-in Help',
1.256 raeburn 669: col2 => 'Value'},
670: {col1 => 'Custom HTML in document head',
1.386 raeburn 671: col2 => 'Value'},
672: {col1 => 'SSO',
673: col2 => 'Dual login: SSO and non-SSO options'},
674: ],
1.230 raeburn 675: print => \&print_login,
676: modify => \&modify_login,
1.110 raeburn 677: };
678: }
1.174 foxr 679:
1.6 raeburn 680: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 681: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 682: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 683: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 684: text=>"Settings to display/modify"});
1.9 raeburn 685: my $confname = $dom.'-domainconfig';
1.174 foxr 686:
1.3 raeburn 687: if ($phase eq 'process') {
1.212 raeburn 688: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
689: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 690: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 691: $r->rflush();
1.212 raeburn 692: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 693: }
1.30 raeburn 694: } elsif ($phase eq 'display') {
1.192 raeburn 695: my $js = &recaptcha_js().
1.236 raeburn 696: &toggle_display_js();
1.171 raeburn 697: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 698: my ($othertitle,$usertypes,$types) =
699: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 700: $js .= &lonbalance_targets_js($dom,$types,\%servers,
701: $domconfig{'loadbalancing'}).
1.170 raeburn 702: &new_spares_js().
703: &common_domprefs_js().
704: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 705: }
1.216 raeburn 706: if (grep(/^requestcourses$/,@actions)) {
707: my $javascript_validations;
708: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
709: $js .= <<END;
710: <script type="text/javascript">
711: $javascript_validations
712: </script>
713: $coursebrowserjs
714: END
1.394 raeburn 715: } elsif (grep(/^ipaccess$/,@actions)) {
716: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 717: }
1.305 raeburn 718: if (grep(/^selfcreation$/,@actions)) {
719: $js .= &selfcreate_javascript();
720: }
1.286 raeburn 721: if (grep(/^contacts$/,@actions)) {
722: $js .= &contacts_javascript();
723: }
1.346 raeburn 724: if (grep(/^scantron$/,@actions)) {
725: $js .= &scantron_javascript();
726: }
1.150 raeburn 727: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 728: } else {
1.180 raeburn 729: # check if domconfig user exists for the domain.
730: my $servadm = $r->dir_config('lonAdmEMail');
731: my ($configuserok,$author_ok,$switchserver) =
732: &config_check($dom,$confname,$servadm);
733: unless ($configuserok eq 'ok') {
1.181 raeburn 734: &Apache::lonconfigsettings::print_header($r,$phase,$context);
735: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 736: $confname).
1.181 raeburn 737: '<br />'
738: );
1.180 raeburn 739: if ($switchserver) {
1.181 raeburn 740: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
741: '<br />'.
742: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
743: '<br />'.
744: &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).
745: '<br />'.
746: &mt('To do that now, use the following link: [_1]',$switchserver)
747: );
748: } else {
749: $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.').
750: '<br />'.
751: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
752: );
1.180 raeburn 753: }
754: $r->print(&Apache::loncommon::end_page());
755: return OK;
756: }
1.21 raeburn 757: if (keys(%domconfig) == 0) {
758: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 759: my @ids=&Apache::lonnet::current_machine_ids();
760: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 761: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 762: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 763: my $custom_img_count = 0;
764: foreach my $img (@loginimages) {
765: if ($designhash{$dom.'.login.'.$img} ne '') {
766: $custom_img_count ++;
767: }
768: }
769: foreach my $role (@roles) {
770: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
771: $custom_img_count ++;
772: }
773: }
774: if ($custom_img_count > 0) {
1.94 raeburn 775: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 776: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 777: $r->print(
778: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
779: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
780: &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 />'.
781: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
782: if ($switch_server) {
1.30 raeburn 783: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 784: }
1.91 raeburn 785: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 786: return OK;
787: }
788: }
789: }
1.91 raeburn 790: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 791: }
792: return OK;
793: }
794:
795: sub process_changes {
1.205 raeburn 796: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 797: my %domconfig;
798: if (ref($values) eq 'HASH') {
799: %domconfig = %{$values};
800: }
1.3 raeburn 801: my $output;
802: if ($action eq 'login') {
1.205 raeburn 803: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 804: } elsif ($action eq 'rolecolors') {
1.9 raeburn 805: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 806: $lastactref,%domconfig);
1.3 raeburn 807: } elsif ($action eq 'quotas') {
1.216 raeburn 808: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 809: } elsif ($action eq 'autoenroll') {
1.205 raeburn 810: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 811: } elsif ($action eq 'autoupdate') {
812: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 813: } elsif ($action eq 'autocreate') {
814: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 815: } elsif ($action eq 'directorysrch') {
1.295 raeburn 816: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 817: } elsif ($action eq 'usercreation') {
1.28 raeburn 818: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 819: } elsif ($action eq 'selfcreation') {
1.305 raeburn 820: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 821: } elsif ($action eq 'usermodification') {
822: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 823: } elsif ($action eq 'contacts') {
1.205 raeburn 824: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 825: } elsif ($action eq 'defaults') {
1.212 raeburn 826: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 827: } elsif ($action eq 'scantron') {
1.205 raeburn 828: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 829: } elsif ($action eq 'coursecategories') {
1.239 raeburn 830: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 831: } elsif ($action eq 'serverstatuses') {
832: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 833: } elsif ($action eq 'requestcourses') {
1.216 raeburn 834: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 835: } elsif ($action eq 'requestauthor') {
1.216 raeburn 836: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 837: } elsif ($action eq 'helpsettings') {
1.285 raeburn 838: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 839: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 840: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 841: } elsif ($action eq 'selfenrollment') {
842: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 843: } elsif ($action eq 'usersessions') {
1.212 raeburn 844: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 845: } elsif ($action eq 'loadbalancing') {
846: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 847: } elsif ($action eq 'ltitools') {
848: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 849: } elsif ($action eq 'proctoring') {
850: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 851: } elsif ($action eq 'ssl') {
852: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 853: } elsif ($action eq 'trust') {
854: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 855: } elsif ($action eq 'lti') {
856: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 857: } elsif ($action eq 'privacy') {
858: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 859: } elsif ($action eq 'passwords') {
860: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 861: } elsif ($action eq 'wafproxy') {
862: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 863: } elsif ($action eq 'ipaccess') {
864: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 865: }
866: return $output;
867: }
868:
869: sub print_config_box {
1.9 raeburn 870: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 871: my $rowtotal = 0;
1.49 raeburn 872: my $output;
873: if ($action eq 'coursecategories') {
874: $output = &coursecategories_javascript($settings);
1.236 raeburn 875: } elsif ($action eq 'defaults') {
876: $output = &defaults_javascript($settings);
1.354 raeburn 877: } elsif ($action eq 'passwords') {
1.405 raeburn 878: $output = &passwords_javascript($action);
1.282 raeburn 879: } elsif ($action eq 'helpsettings') {
880: my (%privs,%levelscurrent);
881: my %full=();
882: my %levels=(
883: course => {},
884: domain => {},
885: system => {},
886: );
887: my $context = 'domain';
888: my $crstype = 'Course';
889: my $formname = 'display';
890: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
891: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
892: $output =
893: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
894: \@templateroles);
1.334 raeburn 895: } elsif ($action eq 'ltitools') {
896: $output .= <itools_javascript($settings);
897: } elsif ($action eq 'lti') {
1.405 raeburn 898: $output .= &passwords_javascript('secrets')."\n".
899: <i_javascript($dom,$settings);
1.372 raeburn 900: } elsif ($action eq 'proctoring') {
901: $output .= &proctoring_javascript($settings);
1.381 raeburn 902: } elsif ($action eq 'wafproxy') {
903: $output .= &wafproxy_javascript($dom);
1.385 raeburn 904: } elsif ($action eq 'autoupdate') {
905: $output .= &autoupdate_javascript();
1.399 raeburn 906: } elsif ($action eq 'autoenroll') {
907: $output .= &autoenroll_javascript();
1.386 raeburn 908: } elsif ($action eq 'login') {
909: $output .= &saml_javascript();
1.394 raeburn 910: } elsif ($action eq 'ipaccess') {
911: $output .= &ipaccess_javascript($settings);
1.91 raeburn 912: }
1.236 raeburn 913: $output .=
1.30 raeburn 914: '<table class="LC_nested_outer">
1.3 raeburn 915: <tr>
1.306 raeburn 916: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 917: &mt($item->{text}).' '.
918: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
919: '</tr>';
1.30 raeburn 920: $rowtotal ++;
1.110 raeburn 921: my $numheaders = 1;
922: if (ref($item->{'header'}) eq 'ARRAY') {
923: $numheaders = scalar(@{$item->{'header'}});
924: }
925: if ($numheaders > 1) {
1.64 raeburn 926: my $colspan = '';
1.145 raeburn 927: my $rightcolspan = '';
1.369 raeburn 928: my $leftnobr = '';
1.238 raeburn 929: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 930: ($action eq 'directorysrch') ||
1.386 raeburn 931: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 932: $colspan = ' colspan="2"';
933: }
1.145 raeburn 934: if ($action eq 'usersessions') {
935: $rightcolspan = ' colspan="3"';
936: }
1.369 raeburn 937: if ($action eq 'passwords') {
938: $leftnobr = ' LC_nobreak';
939: }
1.30 raeburn 940: $output .= '
1.3 raeburn 941: <tr>
942: <td>
943: <table class="LC_nested">
944: <tr class="LC_info_row">
1.369 raeburn 945: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 946: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 947: </tr>';
1.69 raeburn 948: $rowtotal ++;
1.230 raeburn 949: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 950: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 951: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 952: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.405 raeburn 953: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') || ($action eq 'lti')) {
1.230 raeburn 954: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 955: } elsif ($action eq 'passwords') {
956: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 957: } elsif ($action eq 'coursecategories') {
1.230 raeburn 958: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 959: } elsif ($action eq 'scantron') {
960: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 961: } elsif ($action eq 'login') {
1.386 raeburn 962: if ($numheaders == 5) {
1.168 raeburn 963: $colspan = ' colspan="2"';
964: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
965: } else {
966: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
967: }
1.230 raeburn 968: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 969: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 970: } elsif ($action eq 'rolecolors') {
1.30 raeburn 971: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 972: }
1.30 raeburn 973: $output .= '
1.6 raeburn 974: </table>
975: </td>
976: </tr>
977: <tr>
978: <td>
979: <table class="LC_nested">
980: <tr class="LC_info_row">
1.230 raeburn 981: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 982: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 983: </tr>';
984: $rowtotal ++;
1.230 raeburn 985: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
986: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 987: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 988: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.405 raeburn 989: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti')) {
1.238 raeburn 990: if ($action eq 'coursecategories') {
991: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
992: $colspan = ' colspan="2"';
1.279 raeburn 993: } elsif ($action eq 'trust') {
994: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 995: } elsif ($action eq 'passwords') {
996: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 997: } else {
998: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
999: }
1.279 raeburn 1000: if ($action eq 'trust') {
1001: $output .= '
1002: </table>
1003: </td>
1004: </tr>';
1005: my @trusthdrs = qw(2 3 4 5 6 7);
1006: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1007: for (my $i=0; $i<@trusthdrs; $i++) {
1008: $output .= '
1009: <tr>
1010: <td>
1011: <table class="LC_nested">
1012: <tr class="LC_info_row">
1013: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1014: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1015: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1016: </table>
1017: </td>
1018: </tr>';
1019: }
1020: $output .= '
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1026: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1027: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1028: } else {
1029: $output .= '
1.63 raeburn 1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">
1037: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1038: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1039: </tr>'."\n";
1.279 raeburn 1040: if ($action eq 'coursecategories') {
1041: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1042: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1043: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1044: if ($action eq 'passwords') {
1045: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1046: } else {
1047: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1048: }
1049: $output .= '
1.340 raeburn 1050: </tr>
1051: </table>
1052: </td>
1053: </tr>
1054: <tr>
1055: <td>
1056: <table class="LC_nested">
1057: <tr class="LC_info_row">
1.369 raeburn 1058: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1059: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1060: if ($action eq 'passwords') {
1061: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1062: } else {
1063: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1064: }
1065: $output .= '
1.340 raeburn 1066: </table>
1067: </td>
1068: </tr>
1069: <tr>';
1.279 raeburn 1070: } else {
1071: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1072: }
1.238 raeburn 1073: }
1.63 raeburn 1074: $rowtotal ++;
1.236 raeburn 1075: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1076: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1077: ($action eq 'wafproxy')) {
1.230 raeburn 1078: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1079: } elsif ($action eq 'scantron') {
1080: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1081: } elsif ($action eq 'ssl') {
1082: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1083: </table>
1084: </td>
1085: </tr>
1086: <tr>
1087: <td>
1088: <table class="LC_nested">
1089: <tr class="LC_info_row">
1090: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1091: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1092: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1093: </table>
1094: </td>
1095: </tr>
1096: <tr>
1097: <td>
1098: <table class="LC_nested">
1099: <tr class="LC_info_row">
1100: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1101: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1102: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1103: } elsif ($action eq 'login') {
1.386 raeburn 1104: if ($numheaders == 5) {
1.168 raeburn 1105: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1106: </table>
1107: </td>
1108: </tr>
1109: <tr>
1110: <td>
1111: <table class="LC_nested">
1112: <tr class="LC_info_row">
1113: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1114: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1115: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1116: $rowtotal ++;
1117: } else {
1118: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1119: }
1.256 raeburn 1120: $output .= '
1121: </table>
1122: </td>
1123: </tr>
1124: <tr>
1125: <td>
1126: <table class="LC_nested">
1127: <tr class="LC_info_row">';
1.386 raeburn 1128: if ($numheaders == 5) {
1.256 raeburn 1129: $output .= '
1130: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1131: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1132: </tr>';
1133: } else {
1134: $output .= '
1135: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1136: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1137: </tr>';
1138: }
1139: $rowtotal ++;
1.386 raeburn 1140: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1141: </table>
1142: </td>
1143: </tr>
1144: <tr>
1145: <td>
1146: <table class="LC_nested">
1147: <tr class="LC_info_row">';
1148: if ($numheaders == 5) {
1149: $output .= '
1150: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1151: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1152: </tr>';
1153: } else {
1154: $output .= '
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1157: </tr>';
1158: }
1159: $rowtotal ++;
1160: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1161: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1162: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1163: $rowtotal ++;
1164: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1165: </table>
1166: </td>
1167: </tr>
1168: <tr>
1169: <td>
1170: <table class="LC_nested">
1171: <tr class="LC_info_row">
1172: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1173: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1174: &textbookcourses_javascript($settings).
1175: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1176: </table>
1177: </td>
1178: </tr>
1179: <tr>
1180: <td>
1181: <table class="LC_nested">
1182: <tr class="LC_info_row">
1183: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1184: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1185: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">
1.306 raeburn 1193: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1194: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1195: </tr>'.
1196: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1197: } elsif ($action eq 'requestauthor') {
1198: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1199: $rowtotal ++;
1.122 jms 1200: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1201: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 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">'.
1.69 raeburn 1210: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1211: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1212: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1213: </tr>'.
1.30 raeburn 1214: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1215: </table>
1216: </td>
1217: </tr>
1218: <tr>
1219: <td>
1220: <table class="LC_nested">
1221: <tr class="LC_info_row">
1.59 bisitz 1222: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1223: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1224: </tr>'.
1.30 raeburn 1225: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1226: $rowtotal += 2;
1.6 raeburn 1227: }
1.3 raeburn 1228: } else {
1.30 raeburn 1229: $output .= '
1.3 raeburn 1230: <tr>
1231: <td>
1232: <table class="LC_nested">
1.30 raeburn 1233: <tr class="LC_info_row">';
1.277 raeburn 1234: if ($action eq 'login') {
1.30 raeburn 1235: $output .= '
1.59 bisitz 1236: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1237: } elsif ($action eq 'serverstatuses') {
1238: $output .= '
1.306 raeburn 1239: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1240: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1241:
1.6 raeburn 1242: } else {
1.30 raeburn 1243: $output .= '
1.306 raeburn 1244: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1245: }
1.72 raeburn 1246: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1247: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1248: &mt($item->{'header'}->[0]->{'col2'});
1249: if ($action eq 'serverstatuses') {
1250: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1251: }
1.69 raeburn 1252: } else {
1.306 raeburn 1253: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1254: &mt($item->{'header'}->[0]->{'col2'});
1255: }
1256: $output .= '</td>';
1257: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1258: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1259: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1260: &mt($item->{'header'}->[0]->{'col3'});
1261: } else {
1.306 raeburn 1262: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1263: &mt($item->{'header'}->[0]->{'col3'});
1264: }
1.69 raeburn 1265: if ($action eq 'serverstatuses') {
1266: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1267: }
1268: $output .= '</td>';
1.6 raeburn 1269: }
1.150 raeburn 1270: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1271: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1272: &mt($item->{'header'}->[0]->{'col4'});
1273: }
1.69 raeburn 1274: $output .= '</tr>';
1.48 raeburn 1275: $rowtotal ++;
1.168 raeburn 1276: if ($action eq 'quotas') {
1.86 raeburn 1277: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1278: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1279: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.405 raeburn 1280: ($action eq 'ltitools') || ($action eq 'proctoring') ||
1281: ($action eq 'ipaccess')) {
1.230 raeburn 1282: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1283: }
1.3 raeburn 1284: }
1.30 raeburn 1285: $output .= '
1.3 raeburn 1286: </table>
1287: </td>
1288: </tr>
1.30 raeburn 1289: </table><br />';
1290: return ($output,$rowtotal);
1.1 raeburn 1291: }
1292:
1.3 raeburn 1293: sub print_login {
1.168 raeburn 1294: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1295: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1296: my %choices = &login_choices();
1.386 raeburn 1297: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1298: %lt = &login_file_options();
1299: $switchserver = &check_switchserver($dom,$confname);
1300: }
1.168 raeburn 1301: if ($caller eq 'service') {
1.149 raeburn 1302: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1303: my $choice = $choices{'disallowlogin'};
1304: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1305: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1306: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1307: '<th>'.$choices{'server'}.'</th>'.
1308: '<th>'.$choices{'serverpath'}.'</th>'.
1309: '<th>'.$choices{'custompath'}.'</th>'.
1310: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1311: my %disallowed;
1312: if (ref($settings) eq 'HASH') {
1313: if (ref($settings->{'loginvia'}) eq 'HASH') {
1314: %disallowed = %{$settings->{'loginvia'}};
1315: }
1316: }
1317: foreach my $lonhost (sort(keys(%servers))) {
1318: my $direct = 'selected="selected"';
1.128 raeburn 1319: if (ref($disallowed{$lonhost}) eq 'HASH') {
1320: if ($disallowed{$lonhost}{'server'} ne '') {
1321: $direct = '';
1322: }
1.110 raeburn 1323: }
1.115 raeburn 1324: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1325: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1326: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1327: '</option>';
1.184 raeburn 1328: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1329: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1330: my $selected = '';
1.128 raeburn 1331: if (ref($disallowed{$lonhost}) eq 'HASH') {
1332: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1333: $selected = 'selected="selected"';
1334: }
1.110 raeburn 1335: }
1336: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1337: $servers{$hostid}.'</option>';
1338: }
1.128 raeburn 1339: $datatable .= '</select></td>'.
1340: '<td><select name="'.$lonhost.'_serverpath">';
1341: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1342: my $pathname = $path;
1343: if ($path eq 'custom') {
1344: $pathname = &mt('Custom Path').' ->';
1345: }
1346: my $selected = '';
1347: if (ref($disallowed{$lonhost}) eq 'HASH') {
1348: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1349: $selected = 'selected="selected"';
1350: }
1351: } elsif ($path eq '') {
1352: $selected = 'selected="selected"';
1353: }
1354: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1355: }
1356: $datatable .= '</select></td>';
1357: my ($custom,$exempt);
1358: if (ref($disallowed{$lonhost}) eq 'HASH') {
1359: $custom = $disallowed{$lonhost}{'custompath'};
1360: $exempt = $disallowed{$lonhost}{'exempt'};
1361: }
1362: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1363: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1364: '</tr>';
1.110 raeburn 1365: }
1366: $datatable .= '</table></td></tr>';
1367: return $datatable;
1.168 raeburn 1368: } elsif ($caller eq 'page') {
1369: my %defaultchecked = (
1370: 'coursecatalog' => 'on',
1.188 raeburn 1371: 'helpdesk' => 'on',
1.168 raeburn 1372: 'adminmail' => 'off',
1373: 'newuser' => 'off',
1374: );
1.188 raeburn 1375: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1376: my (%checkedon,%checkedoff);
1.42 raeburn 1377: foreach my $item (@toggles) {
1.168 raeburn 1378: if ($defaultchecked{$item} eq 'on') {
1379: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1380: $checkedoff{$item} = ' ';
1.168 raeburn 1381: } elsif ($defaultchecked{$item} eq 'off') {
1382: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1383: $checkedon{$item} = ' ';
1384: }
1.1 raeburn 1385: }
1.168 raeburn 1386: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1387: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1388: my @logintext = ('textcol','bgcol');
1389: my @bgs = ('pgbg','mainbg','sidebg');
1390: my @links = ('link','alink','vlink');
1391: my %designhash = &Apache::loncommon::get_domainconf($dom);
1392: my %defaultdesign = %Apache::loncommon::defaultdesign;
1393: my (%is_custom,%designs);
1394: my %defaults = (
1395: font => $defaultdesign{'login.font'},
1396: );
1.6 raeburn 1397: foreach my $item (@images) {
1.168 raeburn 1398: $defaults{$item} = $defaultdesign{'login.'.$item};
1399: $defaults{'showlogo'}{$item} = 1;
1400: }
1401: foreach my $item (@bgs) {
1402: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1403: }
1.41 raeburn 1404: foreach my $item (@logintext) {
1.168 raeburn 1405: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1406: }
1.168 raeburn 1407: foreach my $item (@links) {
1408: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1409: }
1.168 raeburn 1410: if (ref($settings) eq 'HASH') {
1411: foreach my $item (@toggles) {
1412: if ($settings->{$item} eq '1') {
1413: $checkedon{$item} = ' checked="checked" ';
1414: $checkedoff{$item} = ' ';
1415: } elsif ($settings->{$item} eq '0') {
1416: $checkedoff{$item} = ' checked="checked" ';
1417: $checkedon{$item} = ' ';
1418: }
1419: }
1420: foreach my $item (@images) {
1421: if (defined($settings->{$item})) {
1422: $designs{$item} = $settings->{$item};
1423: $is_custom{$item} = 1;
1424: }
1425: if (defined($settings->{'showlogo'}{$item})) {
1426: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1427: }
1428: }
1.402 raeburn 1429: foreach my $item (@alttext) {
1430: if (ref($settings->{'alttext'}) eq 'HASH') {
1431: if ($settings->{'alttext'}->{$item} ne '') {
1432: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1433: }
1434: }
1435: }
1.168 raeburn 1436: foreach my $item (@logintext) {
1437: if ($settings->{$item} ne '') {
1438: $designs{'logintext'}{$item} = $settings->{$item};
1439: $is_custom{$item} = 1;
1440: }
1441: }
1442: if ($settings->{'font'} ne '') {
1443: $designs{'font'} = $settings->{'font'};
1444: $is_custom{'font'} = 1;
1445: }
1446: foreach my $item (@bgs) {
1447: if ($settings->{$item} ne '') {
1448: $designs{'bgs'}{$item} = $settings->{$item};
1449: $is_custom{$item} = 1;
1450: }
1451: }
1452: foreach my $item (@links) {
1453: if ($settings->{$item} ne '') {
1454: $designs{'links'}{$item} = $settings->{$item};
1455: $is_custom{$item} = 1;
1456: }
1457: }
1458: } else {
1459: if ($designhash{$dom.'.login.font'} ne '') {
1460: $designs{'font'} = $designhash{$dom.'.login.font'};
1461: $is_custom{'font'} = 1;
1462: }
1463: foreach my $item (@images) {
1464: if ($designhash{$dom.'.login.'.$item} ne '') {
1465: $designs{$item} = $designhash{$dom.'.login.'.$item};
1466: $is_custom{$item} = 1;
1467: }
1468: }
1469: foreach my $item (@bgs) {
1470: if ($designhash{$dom.'.login.'.$item} ne '') {
1471: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1472: $is_custom{$item} = 1;
1473: }
1.6 raeburn 1474: }
1.168 raeburn 1475: foreach my $item (@links) {
1476: if ($designhash{$dom.'.login.'.$item} ne '') {
1477: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1478: $is_custom{$item} = 1;
1479: }
1.6 raeburn 1480: }
1481: }
1.168 raeburn 1482: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1483: logo => 'Institution Logo',
1484: domlogo => 'Domain Logo',
1485: login => 'Login box');
1486: my $itemcount = 1;
1487: foreach my $item (@toggles) {
1488: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1489: $datatable .=
1490: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1491: '</td><td>'.
1492: '<span class="LC_nobreak"><label><input type="radio" name="'.
1493: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1494: '</label> <label><input type="radio" name="'.$item.'"'.
1495: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1496: '</tr>';
1497: $itemcount ++;
1.6 raeburn 1498: }
1.168 raeburn 1499: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1500: $datatable .= '</tr></table></td></tr>';
1501: } elsif ($caller eq 'help') {
1.386 raeburn 1502: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1503: my $itemcount = 1;
1504: $defaulturl = '/adm/loginproblems.html';
1505: $defaulttype = 'default';
1506: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1507: my @currlangs;
1508: if (ref($settings) eq 'HASH') {
1509: if (ref($settings->{'helpurl'}) eq 'HASH') {
1510: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1511: next if ($settings->{'helpurl'}{$key} eq '');
1512: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1513: $type{$key} = 'custom';
1514: unless ($key eq 'nolang') {
1515: push(@currlangs,$key);
1516: }
1517: }
1518: } elsif ($settings->{'helpurl'} ne '') {
1519: $type{'nolang'} = 'custom';
1520: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1521: }
1522: }
1.168 raeburn 1523: foreach my $lang ('nolang',sort(@currlangs)) {
1524: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1525: $datatable .= '<tr'.$css_class.'>';
1526: if ($url{$lang} eq '') {
1527: $url{$lang} = $defaulturl;
1528: }
1529: if ($type{$lang} eq '') {
1530: $type{$lang} = $defaulttype;
1531: }
1532: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1533: if ($lang eq 'nolang') {
1534: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1535: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1536: } else {
1537: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1538: $langchoices{$lang},
1539: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1540: }
1541: $datatable .= '</span></td>'."\n".
1542: '<td class="LC_left_item">';
1543: if ($type{$lang} eq 'custom') {
1544: $datatable .= '<span class="LC_nobreak"><label>'.
1545: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1546: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1547: } else {
1548: $datatable .= $lt{'upl'};
1549: }
1550: $datatable .='<br />';
1551: if ($switchserver) {
1552: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1553: } else {
1554: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1555: }
1.168 raeburn 1556: $datatable .= '</td></tr>';
1557: $itemcount ++;
1.6 raeburn 1558: }
1.168 raeburn 1559: my @addlangs;
1560: foreach my $lang (sort(keys(%langchoices))) {
1561: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1562: push(@addlangs,$lang);
1563: }
1564: if (@addlangs > 0) {
1565: my %toadd;
1566: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1567: $toadd{''} = &mt('Select');
1568: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1569: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1570: &mt('Add log-in help page for a specific language:').' '.
1571: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1572: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1573: if ($switchserver) {
1574: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1575: } else {
1576: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1577: }
1.168 raeburn 1578: $datatable .= '</td></tr>';
1.169 raeburn 1579: $itemcount ++;
1.6 raeburn 1580: }
1.169 raeburn 1581: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1582: } elsif ($caller eq 'headtag') {
1583: my %domservers = &Apache::lonnet::get_servers($dom);
1584: my $choice = $choices{'headtag'};
1585: $css_class = ' class="LC_odd_row"';
1586: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1587: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1588: '<th>'.$choices{'current'}.'</th>'.
1589: '<th>'.$choices{'action'}.'</th>'.
1590: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1591: my (%currurls,%currexempt);
1592: if (ref($settings) eq 'HASH') {
1593: if (ref($settings->{'headtag'}) eq 'HASH') {
1594: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1595: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1596: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1597: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1598: }
1599: }
1600: }
1601: }
1602: foreach my $lonhost (sort(keys(%domservers))) {
1603: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1604: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1605: if ($currurls{$lonhost}) {
1606: $datatable .= '<td class="LC_right_item"><a href="'.
1607: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1608: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1609: '">'.$lt{'curr'}.'</a></td>'.
1610: '<td><span class="LC_nobreak"><label>'.
1611: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1612: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1613: } else {
1614: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1615: }
1616: $datatable .='<br />';
1617: if ($switchserver) {
1618: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1619: } else {
1620: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1621: }
1.330 raeburn 1622: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1623: }
1624: $datatable .= '</table></td></tr>';
1.386 raeburn 1625: } elsif ($caller eq 'saml') {
1626: my %domservers = &Apache::lonnet::get_servers($dom);
1627: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1628: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1629: '<th>'.$choices{'samllanding'}.'</th>'.
1630: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1631: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1632: foreach my $lonhost (keys(%domservers)) {
1633: $samlurl{$lonhost} = '/adm/sso';
1634: $styleon{$lonhost} = 'display:none';
1635: $styleoff{$lonhost} = '';
1636: }
1.411 raeburn 1637: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1638: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1639: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1640: $saml{$lonhost} = 1;
1641: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1642: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1643: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1644: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1645: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1646: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1647: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1648: $styleon{$lonhost} = '';
1649: $styleoff{$lonhost} = 'display:none';
1650: } else {
1651: $styleon{$lonhost} = 'display:none';
1652: $styleoff{$lonhost} = '';
1653: }
1654: }
1655: }
1656: my $itemcount = 1;
1657: foreach my $lonhost (sort(keys(%domservers))) {
1658: my $samlon = ' ';
1659: my $samloff = ' checked="checked" ';
1660: if ($saml{$lonhost}) {
1661: $samlon = $samloff;
1662: $samloff = ' ';
1663: }
1.412 raeburn 1664: my $samlwinon = '';
1665: my $samlwinoff = ' checked="checked"';
1666: if ($samlwindow{$lonhost}) {
1667: $samlwinon = $samlwinoff;
1668: $samlwinoff = '';
1669: }
1.386 raeburn 1670: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1671: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1672: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1673: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1674: &mt('No').'</label>'.(' 'x2).
1675: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1676: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1677: &mt('Yes').'</label></span></td>'.
1678: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1679: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1680: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1681: '<th>'.&mt('Alt Text').'</th></tr>'.
1682: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1683: $samltext{$lonhost}.'" /></td><td>';
1684: if ($samlimg{$lonhost}) {
1685: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1686: '<span class="LC_nobreak"><label>'.
1687: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1688: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1689: } else {
1690: $datatable .= $lt{'upl'};
1691: }
1692: $datatable .='<br />';
1693: if ($switchserver) {
1694: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1695: } else {
1696: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1697: }
1698: $datatable .= '</td>'.
1.412 raeburn 1699: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1700: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1701: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1702: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1703: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1704: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1705: '<tr'.$css_class.'>'.
1706: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1707: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1708: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1709: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1710: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1711: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1712: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1713: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1714: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1715: '</table></td>'.
1716: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1717: $itemcount ++;
1718: }
1719: $datatable .= '</table></td></tr>';
1.1 raeburn 1720: }
1.6 raeburn 1721: return $datatable;
1722: }
1723:
1724: sub login_choices {
1725: my %choices =
1726: &Apache::lonlocal::texthash (
1.116 bisitz 1727: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1728: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1729: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1730: disallowlogin => "Login page requests redirected",
1731: hostid => "Server",
1.128 raeburn 1732: server => "Redirect to:",
1733: serverpath => "Path",
1734: custompath => "Custom",
1735: exempt => "Exempt IP(s)",
1.110 raeburn 1736: directlogin => "No redirect",
1737: newuser => "Link to create a user account",
1738: img => "Header",
1739: logo => "Main Logo",
1740: domlogo => "Domain Logo",
1741: login => "Log-in Header",
1742: textcol => "Text color",
1743: bgcol => "Box color",
1744: bgs => "Background colors",
1745: links => "Link colors",
1746: font => "Font color",
1747: pgbg => "Header",
1748: mainbg => "Page",
1749: sidebg => "Login box",
1750: link => "Link",
1751: alink => "Active link",
1752: vlink => "Visited link",
1.256 raeburn 1753: headtag => "Custom markup",
1754: action => "Action",
1755: current => "Current",
1.386 raeburn 1756: samllanding => "Dual login?",
1757: samloptions => "Options",
1.402 raeburn 1758: alttext => "Alt text",
1.6 raeburn 1759: );
1760: return %choices;
1761: }
1762:
1.386 raeburn 1763: sub login_file_options {
1764: return &Apache::lonlocal::texthash(
1765: del => 'Delete?',
1766: rep => 'Replace:',
1767: upl => 'Upload:',
1768: curr => 'View contents',
1769: default => 'Default',
1770: custom => 'Custom',
1771: none => 'None',
1772: );
1773: }
1774:
1.394 raeburn 1775: sub print_ipaccess {
1776: my ($dom,$settings,$rowtotal) = @_;
1777: my $css_class;
1778: my $itemcount = 0;
1779: my $datatable;
1780: my %ordered;
1781: if (ref($settings) eq 'HASH') {
1782: foreach my $item (keys(%{$settings})) {
1783: if (ref($settings->{$item}) eq 'HASH') {
1784: my $num = $settings->{$item}{'order'};
1785: if ($num eq '') {
1786: $num = scalar(keys(%{$settings}));
1787: }
1788: $ordered{$num} = $item;
1789: }
1790: }
1791: }
1792: my $maxnum = scalar(keys(%ordered));
1793: if (keys(%ordered)) {
1794: my @items = sort { $a <=> $b } keys(%ordered);
1795: for (my $i=0; $i<@items; $i++) {
1796: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1797: my $item = $ordered{$items[$i]};
1798: my ($name,$ipranges,%commblocks,%courses);
1799: if (ref($settings->{$item}) eq 'HASH') {
1800: $name = $settings->{$item}->{'name'};
1801: $ipranges = $settings->{$item}->{'ip'};
1802: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1803: %commblocks = %{$settings->{$item}->{'commblocks'}};
1804: }
1805: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1806: %courses = %{$settings->{$item}->{'courses'}};
1807: }
1808: }
1809: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1810: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1811: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1812: for (my $k=0; $k<=$maxnum; $k++) {
1813: my $vpos = $k+1;
1814: my $selstr;
1815: if ($k == $i) {
1816: $selstr = ' selected="selected" ';
1817: }
1818: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1819: }
1820: $datatable .= '</select>'.(' 'x2).
1821: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1822: &mt('Delete?').'</label></span></td>'.
1823: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1824: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1825: '</td></tr>';
1826: $itemcount ++;
1827: }
1828: }
1829: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1830: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1831: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1832: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1833: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1834: for (my $k=0; $k<$maxnum+1; $k++) {
1835: my $vpos = $k+1;
1836: my $selstr;
1837: if ($k == $maxnum) {
1838: $selstr = ' selected="selected" ';
1839: }
1840: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1841: }
1842: $datatable .= '</select> '."\n".
1843: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1844: '<td colspan="2">'.
1845: &ipaccess_options('add',$itemcount,$dom).
1846: '</td>'."\n".
1847: '</tr>'."\n";
1848: $$rowtotal ++;
1849: return $datatable;
1850: }
1851:
1852: sub ipaccess_options {
1853: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1854: my (%currblocks,%currcourses,$output);
1855: if (ref($blocksref) eq 'HASH') {
1856: %currblocks = %{$blocksref};
1857: }
1858: if (ref($coursesref) eq 'HASH') {
1859: %currcourses = %{$coursesref};
1860: }
1861: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1862: '<span class="LC_nobreak">'.&mt('Name').': '.
1863: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1864: '</span></fieldset>'.
1865: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1866: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1867: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1868: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1869: $ipranges.'</textarea></fieldset>'.
1870: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1871: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1872: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1873: '<table>';
1874: foreach my $cid (sort(keys(%currcourses))) {
1875: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1876: $output .= '<tr><td><span class="LC_nobreak">'.
1877: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1878: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1879: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1880: }
1881: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1882: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1883: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1884: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1885: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1886: '</span></td></tr></table>'."\n".
1887: '</fieldset>';
1888: return $output;
1889: }
1890:
1891: sub blocker_checkboxes {
1892: my ($num,$blocks) = @_;
1893: my ($typeorder,$types) = &commblocktype_text();
1894: my $numinrow = 6;
1895: my $output = '<table>';
1896: for (my $i=0; $i<@{$typeorder}; $i++) {
1897: my $block = $typeorder->[$i];
1898: my $blockstatus;
1899: if (ref($blocks) eq 'HASH') {
1900: if ($blocks->{$block} eq 'on') {
1901: $blockstatus = 'checked="checked"';
1902: }
1903: }
1904: my $rem = $i%($numinrow);
1905: if ($rem == 0) {
1906: if ($i > 0) {
1907: $output .= '</tr>';
1908: }
1909: $output .= '<tr>';
1910: }
1911: if ($i == scalar(@{$typeorder})-1) {
1912: my $colsleft = $numinrow-$rem;
1913: if ($colsleft > 1) {
1914: $output .= '<td colspan="'.$colsleft.'">';
1915: } else {
1916: $output .= '<td>';
1917: }
1918: } else {
1919: $output .= '<td>';
1920: }
1921: my $item = 'ipaccess_block_'.$num;
1922: if ($blockstatus) {
1923: $blockstatus = ' '.$blockstatus;
1924: }
1925: $output .= '<span class="LC_nobreak"><label>'."\n".
1926: '<input type="checkbox" name="'.$item.'"'.
1927: $blockstatus.' value="'.$block.'"'.' />'.
1928: $types->{$block}.'</label></span>'."\n".
1929: '<br /></td>';
1930: }
1931: $output .= '</tr></table>';
1932: return $output;
1933: }
1934:
1935: sub commblocktype_text {
1936: my %types = &Apache::lonlocal::texthash(
1937: 'com' => 'Messaging',
1938: 'chat' => 'Chat Room',
1939: 'boards' => 'Discussion',
1940: 'port' => 'Portfolio',
1941: 'groups' => 'Groups',
1942: 'blogs' => 'Blogs',
1943: 'about' => 'User Information',
1944: 'printout' => 'Printouts',
1945: 'passwd' => 'Change Password',
1946: 'grades' => 'Gradebook',
1.397 raeburn 1947: 'search' => 'Course search',
1948: 'wishlist' => 'Stored links',
1949: 'annotate' => 'Annotations',
1.394 raeburn 1950: );
1.397 raeburn 1951: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1952: return ($typeorder,\%types);
1953: }
1954:
1.6 raeburn 1955: sub print_rolecolors {
1.30 raeburn 1956: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1957: my %choices = &color_font_choices();
1958: my @bgs = ('pgbg','tabbg','sidebg');
1959: my @links = ('link','alink','vlink');
1960: my @images = ('img');
1961: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1962: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1963: my %defaultdesign = %Apache::loncommon::defaultdesign;
1964: my (%is_custom,%designs);
1.200 raeburn 1965: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1966: if (ref($settings) eq 'HASH') {
1967: if (ref($settings->{$role}) eq 'HASH') {
1968: if ($settings->{$role}->{'img'} ne '') {
1969: $designs{'img'} = $settings->{$role}->{'img'};
1970: $is_custom{'img'} = 1;
1971: }
1972: if ($settings->{$role}->{'font'} ne '') {
1973: $designs{'font'} = $settings->{$role}->{'font'};
1974: $is_custom{'font'} = 1;
1975: }
1.97 tempelho 1976: if ($settings->{$role}->{'fontmenu'} ne '') {
1977: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1978: $is_custom{'fontmenu'} = 1;
1979: }
1.6 raeburn 1980: foreach my $item (@bgs) {
1981: if ($settings->{$role}->{$item} ne '') {
1982: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1983: $is_custom{$item} = 1;
1984: }
1985: }
1986: foreach my $item (@links) {
1987: if ($settings->{$role}->{$item} ne '') {
1988: $designs{'links'}{$item} = $settings->{$role}->{$item};
1989: $is_custom{$item} = 1;
1990: }
1991: }
1992: }
1993: } else {
1994: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1995: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1996: $is_custom{'img'} = 1;
1997: }
1.97 tempelho 1998: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1999: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2000: $is_custom{'fontmenu'} = 1;
2001: }
1.6 raeburn 2002: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2003: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2004: $is_custom{'font'} = 1;
2005: }
2006: foreach my $item (@bgs) {
2007: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2008: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2009: $is_custom{$item} = 1;
2010:
2011: }
2012: }
2013: foreach my $item (@links) {
2014: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2015: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2016: $is_custom{$item} = 1;
2017: }
2018: }
2019: }
2020: my $itemcount = 1;
1.30 raeburn 2021: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2022: $datatable .= '</tr></table></td></tr>';
2023: return $datatable;
2024: }
2025:
1.200 raeburn 2026: sub role_defaults {
2027: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2028: my %defaults;
2029: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2030: return %defaults;
2031: }
2032: my %defaultdesign = %Apache::loncommon::defaultdesign;
2033: if ($role eq 'login') {
2034: %defaults = (
2035: font => $defaultdesign{$role.'.font'},
2036: );
2037: if (ref($logintext) eq 'ARRAY') {
2038: foreach my $item (@{$logintext}) {
2039: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2040: }
2041: }
2042: foreach my $item (@{$images}) {
2043: $defaults{'showlogo'}{$item} = 1;
2044: }
2045: } else {
2046: %defaults = (
2047: img => $defaultdesign{$role.'.img'},
2048: font => $defaultdesign{$role.'.font'},
2049: fontmenu => $defaultdesign{$role.'.fontmenu'},
2050: );
2051: }
2052: foreach my $item (@{$bgs}) {
2053: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2054: }
2055: foreach my $item (@{$links}) {
2056: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2057: }
2058: foreach my $item (@{$images}) {
2059: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2060: }
2061: return %defaults;
2062: }
2063:
1.6 raeburn 2064: sub display_color_options {
1.9 raeburn 2065: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2066: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2067: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2068: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2069: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2070: '<td>'.$choices->{'font'}.'</td>';
2071: if (!$is_custom->{'font'}) {
1.329 raeburn 2072: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2073: } else {
2074: $datatable .= '<td> </td>';
2075: }
1.174 foxr 2076: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2077:
1.8 raeburn 2078: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2079: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2080: ' value="'.$current_color.'" /> '.
1.329 raeburn 2081: ' </span></td></tr>';
1.107 raeburn 2082: unless ($role eq 'login') {
2083: $datatable .= '<tr'.$css_class.'>'.
2084: '<td>'.$choices->{'fontmenu'}.'</td>';
2085: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2086: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2087: } else {
2088: $datatable .= '<td> </td>';
2089: }
1.202 raeburn 2090: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2091: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2092: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2093: '<input class="colorchooser" type="text" size="10" name="'
2094: .$role.'_fontmenu"'.
2095: ' value="'.$current_color.'" /> '.
1.329 raeburn 2096: ' </span></td></tr>';
1.97 tempelho 2097: }
1.9 raeburn 2098: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2099: foreach my $img (@{$images}) {
1.18 albertel 2100: $itemcount ++;
1.6 raeburn 2101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2102: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2103: '<td>'.$choices->{$img};
1.402 raeburn 2104: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2105: if ($role eq 'login') {
2106: if ($img eq 'login') {
2107: $login_hdr_pick =
1.135 bisitz 2108: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2109: $logincolors =
2110: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2111: $designs,$defaults);
1.402 raeburn 2112: } else {
2113: if ($img ne 'domlogo') {
2114: $datatable.= &logo_display_options($img,$defaults,$designs);
2115: }
2116: if (ref($designs->{'alttext'}) eq 'HASH') {
2117: $alttext = $designs->{'alttext'}{$img};
2118: }
1.70 raeburn 2119: }
2120: }
2121: $datatable .= '</td>';
1.6 raeburn 2122: if ($designs->{$img} ne '') {
2123: $imgfile = $designs->{$img};
1.18 albertel 2124: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2125: } else {
2126: $imgfile = $defaults->{$img};
2127: }
2128: if ($imgfile) {
1.9 raeburn 2129: my ($showfile,$fullsize);
2130: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2131: my $urldir = $1;
2132: my $filename = $2;
2133: my @info = &Apache::lonnet::stat_file($designs->{$img});
2134: if (@info) {
2135: my $thumbfile = 'tn-'.$filename;
2136: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2137: if (@thumb) {
2138: $showfile = $urldir.'/'.$thumbfile;
2139: } else {
2140: $showfile = $imgfile;
2141: }
2142: } else {
2143: $showfile = '';
2144: }
2145: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2146: $showfile = $imgfile;
1.6 raeburn 2147: my $imgdir = $1;
2148: my $filename = $2;
1.159 raeburn 2149: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2150: $showfile = "/$imgdir/tn-".$filename;
2151: } else {
1.159 raeburn 2152: my $input = $londocroot.$imgfile;
2153: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2154: if (!-e $output) {
1.9 raeburn 2155: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2156: my ($fullwidth,$fullheight) = &check_dimensions($input);
2157: if ($fullwidth ne '' && $fullheight ne '') {
2158: if ($fullwidth > $width && $fullheight > $height) {
2159: my $size = $width.'x'.$height;
1.316 raeburn 2160: my @args = ('convert','-sample',$size,$input,$output);
2161: system({$args[0]} @args);
1.159 raeburn 2162: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2163: }
2164: }
1.6 raeburn 2165: }
2166: }
1.16 raeburn 2167: }
1.6 raeburn 2168: if ($showfile) {
1.40 raeburn 2169: if ($showfile =~ m{^/(adm|res)/}) {
2170: if ($showfile =~ m{^/res/}) {
2171: my $local_showfile =
2172: &Apache::lonnet::filelocation('',$showfile);
2173: &Apache::lonnet::repcopy($local_showfile);
2174: }
2175: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2176: }
2177: if ($imgfile) {
2178: if ($imgfile =~ m{^/(adm|res)/}) {
2179: if ($imgfile =~ m{^/res/}) {
2180: my $local_imgfile =
2181: &Apache::lonnet::filelocation('',$imgfile);
2182: &Apache::lonnet::repcopy($local_imgfile);
2183: }
2184: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2185: } else {
2186: $fullsize = $imgfile;
2187: }
2188: }
1.41 raeburn 2189: $datatable .= '<td>';
2190: if ($img eq 'login') {
1.135 bisitz 2191: $datatable .= $login_hdr_pick;
2192: }
1.41 raeburn 2193: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2194: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2195: } else {
1.201 raeburn 2196: $datatable .= '<td> </td><td class="LC_left_item">'.
2197: &mt('Upload:').'<br />';
1.6 raeburn 2198: }
2199: } else {
1.201 raeburn 2200: $datatable .= '<td> </td><td class="LC_left_item">'.
2201: &mt('Upload:').'<br />';
1.6 raeburn 2202: }
1.9 raeburn 2203: if ($switchserver) {
2204: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2205: } else {
1.135 bisitz 2206: if ($img ne 'login') { # suppress file selection for Log-in header
2207: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2208: }
1.9 raeburn 2209: }
1.402 raeburn 2210: if (($role eq 'login') && ($img ne 'login')) {
2211: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2212: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2213: '</label></span>';
2214: }
1.9 raeburn 2215: $datatable .= '</td></tr>';
1.6 raeburn 2216: }
2217: $itemcount ++;
2218: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2219: $datatable .= '<tr'.$css_class.'>'.
2220: '<td>'.$choices->{'bgs'}.'</td>';
2221: my $bgs_def;
2222: foreach my $item (@{$bgs}) {
2223: if (!$is_custom->{$item}) {
1.329 raeburn 2224: $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 2225: }
2226: }
2227: if ($bgs_def) {
1.8 raeburn 2228: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2229: } else {
2230: $datatable .= '<td> </td>';
2231: }
2232: $datatable .= '<td class="LC_right_item">'.
2233: '<table border="0"><tr>';
1.174 foxr 2234:
1.6 raeburn 2235: foreach my $item (@{$bgs}) {
1.306 raeburn 2236: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2237: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2238: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2239: $datatable .= ' ';
1.6 raeburn 2240: }
1.174 foxr 2241: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2242: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2243: }
2244: $datatable .= '</tr></table></td></tr>';
2245: $itemcount ++;
2246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2247: $datatable .= '<tr'.$css_class.'>'.
2248: '<td>'.$choices->{'links'}.'</td>';
2249: my $links_def;
2250: foreach my $item (@{$links}) {
2251: if (!$is_custom->{$item}) {
1.329 raeburn 2252: $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 2253: }
2254: }
2255: if ($links_def) {
1.8 raeburn 2256: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2257: } else {
2258: $datatable .= '<td> </td>';
2259: }
2260: $datatable .= '<td class="LC_right_item">'.
2261: '<table border="0"><tr>';
2262: foreach my $item (@{$links}) {
1.234 raeburn 2263: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2264: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2265: if ($designs->{'links'}{$item}) {
1.174 foxr 2266: $datatable.=' ';
1.6 raeburn 2267: }
1.174 foxr 2268: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2269: '" /></td>';
2270: }
1.30 raeburn 2271: $$rowtotal += $itemcount;
1.3 raeburn 2272: return $datatable;
2273: }
2274:
1.70 raeburn 2275: sub logo_display_options {
2276: my ($img,$defaults,$designs) = @_;
2277: my $checkedon;
2278: if (ref($defaults) eq 'HASH') {
2279: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2280: if ($defaults->{'showlogo'}{$img}) {
2281: $checkedon = 'checked="checked" ';
2282: }
2283: }
2284: }
2285: if (ref($designs) eq 'HASH') {
2286: if (ref($designs->{'showlogo'}) eq 'HASH') {
2287: if (defined($designs->{'showlogo'}{$img})) {
2288: if ($designs->{'showlogo'}{$img} == 0) {
2289: $checkedon = '';
2290: } elsif ($designs->{'showlogo'}{$img} == 1) {
2291: $checkedon = 'checked="checked" ';
2292: }
2293: }
2294: }
2295: }
2296: return '<br /><label> <input type="checkbox" name="'.
2297: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2298: &mt('show').'</label>'."\n";
2299: }
2300:
1.41 raeburn 2301: sub login_header_options {
1.135 bisitz 2302: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2303: my $output = '';
1.41 raeburn 2304: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2305: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2306: if (!$is_custom->{'textcol'}) {
2307: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2308: ' ';
2309: }
2310: if (!$is_custom->{'bgcol'}) {
2311: $output .= $choices->{'bgcol'}.': '.
2312: '<span id="css_'.$role.'_font" style="background-color: '.
2313: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2314: }
2315: $output .= '<br />';
2316: }
2317: $output .='<br />';
2318: return $output;
2319: }
2320:
2321: sub login_text_colors {
1.201 raeburn 2322: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2323: my $color_menu = '<table border="0"><tr>';
2324: foreach my $item (@{$logintext}) {
1.306 raeburn 2325: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2326: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2327: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2328: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2329: }
2330: $color_menu .= '</tr></table><br />';
2331: return $color_menu;
2332: }
2333:
2334: sub image_changes {
2335: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2336: my $output;
1.135 bisitz 2337: if ($img eq 'login') {
1.331 raeburn 2338: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2339: } elsif (!$is_custom) {
1.70 raeburn 2340: if ($img ne 'domlogo') {
1.331 raeburn 2341: $output = &mt('Default image:').'<br />';
1.41 raeburn 2342: } else {
1.331 raeburn 2343: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2344: }
2345: }
1.331 raeburn 2346: if ($img ne 'login') {
1.135 bisitz 2347: if ($img_import) {
2348: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2349: }
2350: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2351: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2352: if ($is_custom) {
2353: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2354: '<input type="checkbox" name="'.
2355: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2356: '</label> '.&mt('Replace:').'</span><br />';
2357: } else {
1.306 raeburn 2358: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2359: }
1.41 raeburn 2360: }
2361: return $output;
2362: }
2363:
1.3 raeburn 2364: sub print_quotas {
1.86 raeburn 2365: my ($dom,$settings,$rowtotal,$action) = @_;
2366: my $context;
2367: if ($action eq 'quotas') {
2368: $context = 'tools';
2369: } else {
2370: $context = $action;
2371: }
1.197 raeburn 2372: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2374: my $typecount = 0;
1.101 raeburn 2375: my ($css_class,%titles);
1.86 raeburn 2376: if ($context eq 'requestcourses') {
1.325 raeburn 2377: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2378: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2379: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2380: %titles = &courserequest_titles();
1.163 raeburn 2381: } elsif ($context eq 'requestauthor') {
2382: @usertools = ('author');
2383: @options = ('norequest','approval','automatic');
1.210 raeburn 2384: %titles = &authorrequest_titles();
1.86 raeburn 2385: } else {
1.413 raeburn 2386: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2387: %titles = &tool_titles();
1.86 raeburn 2388: }
1.26 raeburn 2389: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2390: foreach my $type (@{$types}) {
1.197 raeburn 2391: my ($currdefquota,$currauthorquota);
1.163 raeburn 2392: unless (($context eq 'requestcourses') ||
2393: ($context eq 'requestauthor')) {
1.86 raeburn 2394: if (ref($settings) eq 'HASH') {
2395: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2396: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2397: } else {
2398: $currdefquota = $settings->{$type};
2399: }
1.197 raeburn 2400: if (ref($settings->{authorquota}) eq 'HASH') {
2401: $currauthorquota = $settings->{authorquota}->{$type};
2402: }
1.78 raeburn 2403: }
1.72 raeburn 2404: }
1.3 raeburn 2405: if (defined($usertypes->{$type})) {
2406: $typecount ++;
2407: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2408: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2409: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2410: '<td class="LC_left_item">';
1.101 raeburn 2411: if ($context eq 'requestcourses') {
2412: $datatable .= '<table><tr>';
2413: }
2414: my %cell;
1.72 raeburn 2415: foreach my $item (@usertools) {
1.101 raeburn 2416: if ($context eq 'requestcourses') {
2417: my ($curroption,$currlimit);
2418: if (ref($settings) eq 'HASH') {
2419: if (ref($settings->{$item}) eq 'HASH') {
2420: $curroption = $settings->{$item}->{$type};
2421: if ($curroption =~ /^autolimit=(\d*)$/) {
2422: $currlimit = $1;
2423: }
2424: }
2425: }
2426: if (!$curroption) {
2427: $curroption = 'norequest';
2428: }
2429: $datatable .= '<th>'.$titles{$item}.'</th>';
2430: foreach my $option (@options) {
2431: my $val = $option;
2432: if ($option eq 'norequest') {
2433: $val = 0;
2434: }
2435: if ($option eq 'validate') {
2436: my $canvalidate = 0;
2437: if (ref($validations{$item}) eq 'HASH') {
2438: if ($validations{$item}{$type}) {
2439: $canvalidate = 1;
2440: }
2441: }
2442: next if (!$canvalidate);
2443: }
2444: my $checked = '';
2445: if ($option eq $curroption) {
2446: $checked = ' checked="checked"';
2447: } elsif ($option eq 'autolimit') {
2448: if ($curroption =~ /^autolimit/) {
2449: $checked = ' checked="checked"';
2450: }
2451: }
2452: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2453: '<input type="radio" name="crsreq_'.$item.
2454: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2455: $titles{$option}.'</label>';
1.101 raeburn 2456: if ($option eq 'autolimit') {
1.127 raeburn 2457: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2458: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2459: 'value="'.$currlimit.'" />';
1.101 raeburn 2460: }
1.127 raeburn 2461: $cell{$item} .= '</span> ';
1.103 raeburn 2462: if ($option eq 'autolimit') {
1.127 raeburn 2463: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2464: }
1.101 raeburn 2465: }
1.163 raeburn 2466: } elsif ($context eq 'requestauthor') {
2467: my $curroption;
2468: if (ref($settings) eq 'HASH') {
2469: $curroption = $settings->{$type};
2470: }
2471: if (!$curroption) {
2472: $curroption = 'norequest';
2473: }
2474: foreach my $option (@options) {
2475: my $val = $option;
2476: if ($option eq 'norequest') {
2477: $val = 0;
2478: }
2479: my $checked = '';
2480: if ($option eq $curroption) {
2481: $checked = ' checked="checked"';
2482: }
2483: $datatable .= '<span class="LC_nobreak"><label>'.
2484: '<input type="radio" name="authorreq_'.$type.
2485: '" value="'.$val.'"'.$checked.' />'.
2486: $titles{$option}.'</label></span> ';
2487: }
1.101 raeburn 2488: } else {
2489: my $checked = 'checked="checked" ';
1.413 raeburn 2490: if ($item eq 'timezone') {
2491: $checked = '';
2492: }
1.101 raeburn 2493: if (ref($settings) eq 'HASH') {
2494: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2495: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2496: $checked = '';
2497: } elsif ($settings->{$item}->{$type} == 1) {
2498: $checked = 'checked="checked" ';
2499: }
1.78 raeburn 2500: }
1.72 raeburn 2501: }
1.101 raeburn 2502: $datatable .= '<span class="LC_nobreak"><label>'.
2503: '<input type="checkbox" name="'.$context.'_'.$item.
2504: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2505: '</label></span> ';
1.72 raeburn 2506: }
1.101 raeburn 2507: }
2508: if ($context eq 'requestcourses') {
2509: $datatable .= '</tr><tr>';
2510: foreach my $item (@usertools) {
1.106 raeburn 2511: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2512: }
2513: $datatable .= '</tr></table>';
1.72 raeburn 2514: }
1.86 raeburn 2515: $datatable .= '</td>';
1.163 raeburn 2516: unless (($context eq 'requestcourses') ||
2517: ($context eq 'requestauthor')) {
1.86 raeburn 2518: $datatable .=
1.197 raeburn 2519: '<td class="LC_right_item">'.
2520: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2521: '<input type="text" name="quota_'.$type.
1.72 raeburn 2522: '" value="'.$currdefquota.
1.197 raeburn 2523: '" size="5" /></span>'.(' ' x 2).
2524: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2525: '<input type="text" name="authorquota_'.$type.
2526: '" value="'.$currauthorquota.
2527: '" size="5" /></span></td>';
1.86 raeburn 2528: }
2529: $datatable .= '</tr>';
1.3 raeburn 2530: }
2531: }
2532: }
1.163 raeburn 2533: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2534: $defaultquota = '20';
1.197 raeburn 2535: $authorquota = '500';
1.86 raeburn 2536: if (ref($settings) eq 'HASH') {
2537: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2538: $defaultquota = $settings->{'defaultquota'}->{'default'};
2539: } elsif (defined($settings->{'default'})) {
2540: $defaultquota = $settings->{'default'};
2541: }
1.197 raeburn 2542: if (ref($settings->{'authorquota'}) eq 'HASH') {
2543: $authorquota = $settings->{'authorquota'}->{'default'};
2544: }
1.3 raeburn 2545: }
2546: }
2547: $typecount ++;
2548: $css_class = $typecount%2?' class="LC_odd_row"':'';
2549: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2550: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2551: '<td class="LC_left_item">';
1.101 raeburn 2552: if ($context eq 'requestcourses') {
2553: $datatable .= '<table><tr>';
2554: }
2555: my %defcell;
1.72 raeburn 2556: foreach my $item (@usertools) {
1.101 raeburn 2557: if ($context eq 'requestcourses') {
2558: my ($curroption,$currlimit);
2559: if (ref($settings) eq 'HASH') {
2560: if (ref($settings->{$item}) eq 'HASH') {
2561: $curroption = $settings->{$item}->{'default'};
2562: if ($curroption =~ /^autolimit=(\d*)$/) {
2563: $currlimit = $1;
2564: }
2565: }
2566: }
2567: if (!$curroption) {
2568: $curroption = 'norequest';
2569: }
2570: $datatable .= '<th>'.$titles{$item}.'</th>';
2571: foreach my $option (@options) {
2572: my $val = $option;
2573: if ($option eq 'norequest') {
2574: $val = 0;
2575: }
2576: if ($option eq 'validate') {
2577: my $canvalidate = 0;
2578: if (ref($validations{$item}) eq 'HASH') {
2579: if ($validations{$item}{'default'}) {
2580: $canvalidate = 1;
2581: }
2582: }
2583: next if (!$canvalidate);
2584: }
2585: my $checked = '';
2586: if ($option eq $curroption) {
2587: $checked = ' checked="checked"';
2588: } elsif ($option eq 'autolimit') {
2589: if ($curroption =~ /^autolimit/) {
2590: $checked = ' checked="checked"';
2591: }
2592: }
2593: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2594: '<input type="radio" name="crsreq_'.$item.
2595: '_default" value="'.$val.'"'.$checked.' />'.
2596: $titles{$option}.'</label>';
2597: if ($option eq 'autolimit') {
1.127 raeburn 2598: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2599: $item.'_limit_default" size="1" '.
2600: 'value="'.$currlimit.'" />';
2601: }
1.127 raeburn 2602: $defcell{$item} .= '</span> ';
1.104 raeburn 2603: if ($option eq 'autolimit') {
1.127 raeburn 2604: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2605: }
1.101 raeburn 2606: }
1.163 raeburn 2607: } elsif ($context eq 'requestauthor') {
2608: my $curroption;
2609: if (ref($settings) eq 'HASH') {
1.172 raeburn 2610: $curroption = $settings->{'default'};
1.163 raeburn 2611: }
2612: if (!$curroption) {
2613: $curroption = 'norequest';
2614: }
2615: foreach my $option (@options) {
2616: my $val = $option;
2617: if ($option eq 'norequest') {
2618: $val = 0;
2619: }
2620: my $checked = '';
2621: if ($option eq $curroption) {
2622: $checked = ' checked="checked"';
2623: }
2624: $datatable .= '<span class="LC_nobreak"><label>'.
2625: '<input type="radio" name="authorreq_default"'.
2626: ' value="'.$val.'"'.$checked.' />'.
2627: $titles{$option}.'</label></span> ';
2628: }
1.101 raeburn 2629: } else {
2630: my $checked = 'checked="checked" ';
2631: if (ref($settings) eq 'HASH') {
2632: if (ref($settings->{$item}) eq 'HASH') {
2633: if ($settings->{$item}->{'default'} == 0) {
2634: $checked = '';
2635: } elsif ($settings->{$item}->{'default'} == 1) {
2636: $checked = 'checked="checked" ';
2637: }
1.78 raeburn 2638: }
1.72 raeburn 2639: }
1.101 raeburn 2640: $datatable .= '<span class="LC_nobreak"><label>'.
2641: '<input type="checkbox" name="'.$context.'_'.$item.
2642: '" value="default" '.$checked.'/>'.$titles{$item}.
2643: '</label></span> ';
2644: }
2645: }
2646: if ($context eq 'requestcourses') {
2647: $datatable .= '</tr><tr>';
2648: foreach my $item (@usertools) {
1.106 raeburn 2649: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2650: }
1.101 raeburn 2651: $datatable .= '</tr></table>';
1.72 raeburn 2652: }
1.86 raeburn 2653: $datatable .= '</td>';
1.163 raeburn 2654: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2655: $datatable .= '<td class="LC_right_item">'.
2656: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2657: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2658: $defaultquota.'" size="5" /></span>'.(' ' x2).
2659: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2660: '<input type="text" name="authorquota" value="'.
2661: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2662: }
2663: $datatable .= '</tr>';
1.72 raeburn 2664: $typecount ++;
2665: $css_class = $typecount%2?' class="LC_odd_row"':'';
2666: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2667: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2668: if ($context eq 'requestcourses') {
1.109 raeburn 2669: $datatable .= &mt('(overrides affiliation, if set)').
2670: '</td>'.
2671: '<td class="LC_left_item">'.
2672: '<table><tr>';
1.101 raeburn 2673: } else {
1.109 raeburn 2674: $datatable .= &mt('(overrides affiliation, if checked)').
2675: '</td>'.
2676: '<td class="LC_left_item" colspan="2">'.
2677: '<br />';
1.101 raeburn 2678: }
2679: my %advcell;
1.72 raeburn 2680: foreach my $item (@usertools) {
1.101 raeburn 2681: if ($context eq 'requestcourses') {
2682: my ($curroption,$currlimit);
2683: if (ref($settings) eq 'HASH') {
2684: if (ref($settings->{$item}) eq 'HASH') {
2685: $curroption = $settings->{$item}->{'_LC_adv'};
2686: if ($curroption =~ /^autolimit=(\d*)$/) {
2687: $currlimit = $1;
2688: }
2689: }
2690: }
2691: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2692: my $checked = '';
2693: if ($curroption eq '') {
2694: $checked = ' checked="checked"';
2695: }
2696: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2697: '<input type="radio" name="crsreq_'.$item.
2698: '__LC_adv" value=""'.$checked.' />'.
2699: &mt('No override set').'</label></span> ';
1.101 raeburn 2700: foreach my $option (@options) {
2701: my $val = $option;
2702: if ($option eq 'norequest') {
2703: $val = 0;
2704: }
2705: if ($option eq 'validate') {
2706: my $canvalidate = 0;
2707: if (ref($validations{$item}) eq 'HASH') {
2708: if ($validations{$item}{'_LC_adv'}) {
2709: $canvalidate = 1;
2710: }
2711: }
2712: next if (!$canvalidate);
2713: }
2714: my $checked = '';
1.104 raeburn 2715: if ($val eq $curroption) {
1.101 raeburn 2716: $checked = ' checked="checked"';
2717: } elsif ($option eq 'autolimit') {
2718: if ($curroption =~ /^autolimit/) {
2719: $checked = ' checked="checked"';
2720: }
2721: }
2722: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2723: '<input type="radio" name="crsreq_'.$item.
2724: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2725: $titles{$option}.'</label>';
2726: if ($option eq 'autolimit') {
1.127 raeburn 2727: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2728: $item.'_limit__LC_adv" size="1" '.
2729: 'value="'.$currlimit.'" />';
2730: }
1.127 raeburn 2731: $advcell{$item} .= '</span> ';
1.104 raeburn 2732: if ($option eq 'autolimit') {
1.127 raeburn 2733: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2734: }
1.101 raeburn 2735: }
1.163 raeburn 2736: } elsif ($context eq 'requestauthor') {
2737: my $curroption;
2738: if (ref($settings) eq 'HASH') {
2739: $curroption = $settings->{'_LC_adv'};
2740: }
2741: my $checked = '';
2742: if ($curroption eq '') {
2743: $checked = ' checked="checked"';
2744: }
2745: $datatable .= '<span class="LC_nobreak"><label>'.
2746: '<input type="radio" name="authorreq__LC_adv"'.
2747: ' value=""'.$checked.' />'.
2748: &mt('No override set').'</label></span> ';
2749: foreach my $option (@options) {
2750: my $val = $option;
2751: if ($option eq 'norequest') {
2752: $val = 0;
2753: }
2754: my $checked = '';
2755: if ($val eq $curroption) {
2756: $checked = ' checked="checked"';
2757: }
2758: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2759: '<input type="radio" name="authorreq__LC_adv"'.
2760: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2761: $titles{$option}.'</label></span> ';
2762: }
1.101 raeburn 2763: } else {
2764: my $checked = 'checked="checked" ';
2765: if (ref($settings) eq 'HASH') {
2766: if (ref($settings->{$item}) eq 'HASH') {
2767: if ($settings->{$item}->{'_LC_adv'} == 0) {
2768: $checked = '';
2769: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2770: $checked = 'checked="checked" ';
2771: }
1.79 raeburn 2772: }
1.72 raeburn 2773: }
1.101 raeburn 2774: $datatable .= '<span class="LC_nobreak"><label>'.
2775: '<input type="checkbox" name="'.$context.'_'.$item.
2776: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2777: '</label></span> ';
2778: }
2779: }
2780: if ($context eq 'requestcourses') {
2781: $datatable .= '</tr><tr>';
2782: foreach my $item (@usertools) {
1.106 raeburn 2783: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2784: }
1.101 raeburn 2785: $datatable .= '</tr></table>';
1.72 raeburn 2786: }
1.98 raeburn 2787: $datatable .= '</td></tr>';
1.30 raeburn 2788: $$rowtotal += $typecount;
1.3 raeburn 2789: return $datatable;
2790: }
2791:
1.163 raeburn 2792: sub print_requestmail {
1.305 raeburn 2793: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2794: my ($now,$datatable,%currapp);
1.102 raeburn 2795: $now = time;
2796: if (ref($settings) eq 'HASH') {
2797: if (ref($settings->{'notify'}) eq 'HASH') {
2798: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2799: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2800: }
2801: }
2802: }
1.191 raeburn 2803: my $numinrow = 2;
1.224 raeburn 2804: my $css_class;
1.305 raeburn 2805: if ($$rowtotal%2) {
2806: $css_class = 'LC_odd_row';
2807: }
2808: if ($customcss) {
2809: $css_class .= " $customcss";
2810: }
2811: $css_class =~ s/^\s+//;
2812: if ($css_class) {
2813: $css_class = ' class="'.$css_class.'"';
2814: }
2815: if ($rowstyle) {
2816: $css_class .= ' style="'.$rowstyle.'"';
2817: }
1.163 raeburn 2818: my $text;
2819: if ($action eq 'requestcourses') {
2820: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2821: } elsif ($action eq 'requestauthor') {
2822: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2823: } else {
1.224 raeburn 2824: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2825: }
1.224 raeburn 2826: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2827: ' <td>'.$text.'</td>'.
1.102 raeburn 2828: ' <td class="LC_left_item">';
1.191 raeburn 2829: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2830: $action.'notifyapproval',%currapp);
1.191 raeburn 2831: if ($numdc > 0) {
2832: $datatable .= $table;
1.102 raeburn 2833: } else {
2834: $datatable .= &mt('There are no active Domain Coordinators');
2835: }
2836: $datatable .='</td></tr>';
2837: return $datatable;
2838: }
2839:
1.216 raeburn 2840: sub print_studentcode {
2841: my ($settings,$rowtotal) = @_;
2842: my $rownum = 0;
1.218 raeburn 2843: my ($output,%current);
1.325 raeburn 2844: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2845: if (ref($settings) eq 'HASH') {
2846: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2847: foreach my $type (@crstypes) {
2848: $current{$type} = $settings->{'uniquecode'}{$type};
2849: }
1.218 raeburn 2850: }
2851: }
2852: $output .= '<tr>'.
2853: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2854: '<td class="LC_left_item">';
2855: foreach my $type (@crstypes) {
2856: my $check = ' ';
2857: if ($current{$type}) {
2858: $check = ' checked="checked" ';
2859: }
2860: $output .= '<span class="LC_nobreak"><label>'.
2861: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2862: &mt($type).'</label></span>'.(' 'x2).' ';
2863: }
2864: $output .= '</td></tr>';
2865: $$rowtotal ++;
2866: return $output;
1.216 raeburn 2867: }
2868:
2869: sub print_textbookcourses {
1.242 raeburn 2870: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2871: my $rownum = 0;
2872: my $css_class;
2873: my $itemcount = 1;
2874: my $maxnum = 0;
2875: my $bookshash;
2876: if (ref($settings) eq 'HASH') {
1.242 raeburn 2877: $bookshash = $settings->{$type};
1.216 raeburn 2878: }
2879: my %ordered;
2880: if (ref($bookshash) eq 'HASH') {
2881: foreach my $item (keys(%{$bookshash})) {
2882: if (ref($bookshash->{$item}) eq 'HASH') {
2883: my $num = $bookshash->{$item}{'order'};
2884: $ordered{$num} = $item;
2885: }
2886: }
2887: }
2888: my $confname = $dom.'-domainconfig';
2889: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2890: my $maxnum = scalar(keys(%ordered));
2891: my $datatable;
1.216 raeburn 2892: if (keys(%ordered)) {
2893: my @items = sort { $a <=> $b } keys(%ordered);
2894: for (my $i=0; $i<@items; $i++) {
2895: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2896: my $key = $ordered{$items[$i]};
2897: my %coursehash=&Apache::lonnet::coursedescription($key);
2898: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2899: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2900: if (ref($bookshash->{$key}) eq 'HASH') {
2901: $subject = $bookshash->{$key}->{'subject'};
2902: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2903: if ($type eq 'textbooks') {
1.243 raeburn 2904: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2905: $author = $bookshash->{$key}->{'author'};
2906: $image = $bookshash->{$key}->{'image'};
2907: if ($image ne '') {
2908: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2909: my $imagethumb = "$path/tn-".$imagefile;
2910: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2911: }
1.216 raeburn 2912: }
2913: }
1.242 raeburn 2914: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2915: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2916: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2917: for (my $k=0; $k<=$maxnum; $k++) {
2918: my $vpos = $k+1;
2919: my $selstr;
2920: if ($k == $i) {
2921: $selstr = ' selected="selected" ';
2922: }
2923: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2924: }
2925: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2926: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2927: &mt('Delete?').'</label></span></td>'.
2928: '<td colspan="2">'.
1.242 raeburn 2929: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2930: (' 'x2).
1.242 raeburn 2931: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2932: if ($type eq 'textbooks') {
2933: $datatable .= (' 'x2).
1.243 raeburn 2934: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2935: (' 'x2).
1.242 raeburn 2936: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2937: (' 'x2).
2938: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2939: if ($image) {
1.267 raeburn 2940: $datatable .= $imgsrc.
1.242 raeburn 2941: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2942: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2943: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2944: }
2945: if ($switchserver) {
2946: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2947: } else {
2948: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2949: }
1.216 raeburn 2950: }
1.242 raeburn 2951: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2952: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2953: $coursetitle.'</span></td></tr>'."\n";
2954: $itemcount ++;
2955: }
2956: }
2957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2958: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2959: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2960: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2961: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2962: for (my $k=0; $k<$maxnum+1; $k++) {
2963: my $vpos = $k+1;
2964: my $selstr;
2965: if ($k == $maxnum) {
2966: $selstr = ' selected="selected" ';
2967: }
2968: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2969: }
2970: $datatable .= '</select> '."\n".
1.334 raeburn 2971: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2972: '<td colspan="2">'.
1.242 raeburn 2973: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2974: (' 'x2).
1.242 raeburn 2975: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2976: (' 'x2);
2977: if ($type eq 'textbooks') {
1.243 raeburn 2978: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2979: (' 'x2).
2980: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2981: (' 'x2).
2982: '<span class="LC_nobreak">'.&mt('Image:').' ';
2983: if ($switchserver) {
2984: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2985: } else {
2986: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2987: }
1.334 raeburn 2988: $datatable .= '</span>'."\n";
1.216 raeburn 2989: }
1.334 raeburn 2990: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2991: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2992: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2993: &Apache::loncommon::selectcourse_link
1.334 raeburn 2994: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2995: '</span></td>'."\n".
2996: '</tr>'."\n";
2997: $itemcount ++;
2998: return $datatable;
2999: }
3000:
1.217 raeburn 3001: sub textbookcourses_javascript {
1.242 raeburn 3002: my ($settings) = @_;
3003: return unless(ref($settings) eq 'HASH');
3004: my (%ordered,%total,%jstext);
3005: foreach my $type ('textbooks','templates') {
3006: $total{$type} = 0;
3007: if (ref($settings->{$type}) eq 'HASH') {
3008: foreach my $item (keys(%{$settings->{$type}})) {
3009: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3010: my $num = $settings->{$type}->{$item}{'order'};
3011: $ordered{$type}{$num} = $item;
3012: }
3013: }
3014: $total{$type} = scalar(keys(%{$settings->{$type}}));
3015: }
3016: my @jsarray = ();
3017: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3018: push(@jsarray,$ordered{$type}{$item});
3019: }
3020: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3021: }
3022: return <<"ENDSCRIPT";
3023: <script type="text/javascript">
3024: // <![CDATA[
1.242 raeburn 3025: function reorderBooks(form,item,caller) {
1.217 raeburn 3026: var changedVal;
1.242 raeburn 3027: $jstext{'textbooks'};
3028: $jstext{'templates'};
3029: var newpos;
3030: var maxh;
3031: if (caller == 'textbooks') {
3032: newpos = 'textbooks_addbook_pos';
3033: maxh = 1 + $total{'textbooks'};
3034: } else {
3035: newpos = 'templates_addbook_pos';
3036: maxh = 1 + $total{'templates'};
3037: }
1.217 raeburn 3038: var current = new Array;
3039: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3040: if (item == newpos) {
3041: changedVal = newitemVal;
3042: } else {
3043: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3044: current[newitemVal] = newpos;
3045: }
1.242 raeburn 3046: if (caller == 'textbooks') {
3047: for (var i=0; i<textbooks.length; i++) {
3048: var elementName = 'textbooks_'+textbooks[i];
3049: if (elementName != item) {
3050: if (form.elements[elementName]) {
3051: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3052: current[currVal] = elementName;
3053: }
3054: }
3055: }
3056: }
3057: if (caller == 'templates') {
3058: for (var i=0; i<templates.length; i++) {
3059: var elementName = 'templates_'+templates[i];
3060: if (elementName != item) {
3061: if (form.elements[elementName]) {
3062: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3063: current[currVal] = elementName;
3064: }
1.217 raeburn 3065: }
3066: }
3067: }
3068: var oldVal;
3069: for (var j=0; j<maxh; j++) {
3070: if (current[j] == undefined) {
3071: oldVal = j;
3072: }
3073: }
3074: if (oldVal < changedVal) {
3075: for (var k=oldVal+1; k<=changedVal ; k++) {
3076: var elementName = current[k];
3077: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3078: }
3079: } else {
3080: for (var k=changedVal; k<oldVal; k++) {
3081: var elementName = current[k];
3082: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3083: }
3084: }
3085: return;
3086: }
3087:
3088: // ]]>
3089: </script>
3090:
3091: ENDSCRIPT
3092: }
3093:
1.267 raeburn 3094: sub ltitools_javascript {
3095: my ($settings) = @_;
1.319 raeburn 3096: my $togglejs = <itools_toggle_js();
3097: unless (ref($settings) eq 'HASH') {
3098: return $togglejs;
3099: }
1.267 raeburn 3100: my (%ordered,$total,%jstext);
3101: $total = 0;
3102: foreach my $item (keys(%{$settings})) {
3103: if (ref($settings->{$item}) eq 'HASH') {
3104: my $num = $settings->{$item}{'order'};
3105: $ordered{$num} = $item;
3106: }
3107: }
3108: $total = scalar(keys(%{$settings}));
3109: my @jsarray = ();
3110: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3111: push(@jsarray,$ordered{$item});
3112: }
3113: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3114: return <<"ENDSCRIPT";
3115: <script type="text/javascript">
3116: // <![CDATA[
1.319 raeburn 3117: function reorderLTITools(form,item) {
1.267 raeburn 3118: var changedVal;
3119: $jstext
3120: var newpos = 'ltitools_add_pos';
3121: var maxh = 1 + $total;
3122: var current = new Array;
3123: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3124: if (item == newpos) {
3125: changedVal = newitemVal;
3126: } else {
3127: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3128: current[newitemVal] = newpos;
3129: }
3130: for (var i=0; i<ltitools.length; i++) {
3131: var elementName = 'ltitools_'+ltitools[i];
3132: if (elementName != item) {
3133: if (form.elements[elementName]) {
3134: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3135: current[currVal] = elementName;
3136: }
3137: }
3138: }
3139: var oldVal;
3140: for (var j=0; j<maxh; j++) {
3141: if (current[j] == undefined) {
3142: oldVal = j;
3143: }
3144: }
3145: if (oldVal < changedVal) {
3146: for (var k=oldVal+1; k<=changedVal ; k++) {
3147: var elementName = current[k];
3148: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3149: }
3150: } else {
3151: for (var k=changedVal; k<oldVal; k++) {
3152: var elementName = current[k];
3153: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3154: }
3155: }
3156: return;
3157: }
3158:
3159: // ]]>
3160: </script>
3161:
1.319 raeburn 3162: $togglejs
3163:
3164: ENDSCRIPT
3165: }
3166:
3167: sub ltitools_toggle_js {
3168: return <<"ENDSCRIPT";
3169: <script type="text/javascript">
3170: // <![CDATA[
3171:
3172: function toggleLTITools(form,setting,item) {
3173: var radioname = '';
3174: var divid = '';
3175: if ((setting == 'passback') || (setting == 'roster')) {
3176: radioname = 'ltitools_'+setting+'_'+item;
3177: divid = 'ltitools_'+setting+'time_'+item;
3178: var num = form.elements[radioname].length;
3179: if (num) {
3180: var setvis = '';
3181: for (var i=0; i<num; i++) {
3182: if (form.elements[radioname][i].checked) {
3183: if (form.elements[radioname][i].value == '1') {
3184: if (document.getElementById(divid)) {
3185: document.getElementById(divid).style.display = 'inline-block';
3186: }
3187: setvis = 1;
3188: }
3189: break;
3190: }
3191: }
3192: }
3193: if (!setvis) {
3194: if (document.getElementById(divid)) {
3195: document.getElementById(divid).style.display = 'none';
3196: }
3197: }
3198: }
1.324 raeburn 3199: if (setting == 'user') {
3200: divid = 'ltitools_'+setting+'_div_'+item;
3201: var checkid = 'ltitools_'+setting+'_field_'+item;
3202: if (document.getElementById(divid)) {
3203: if (document.getElementById(checkid)) {
3204: if (document.getElementById(checkid).checked) {
3205: document.getElementById(divid).style.display = 'inline-block';
3206: } else {
3207: document.getElementById(divid).style.display = 'none';
3208: }
3209: }
3210: }
3211: }
1.319 raeburn 3212: return;
3213: }
3214: // ]]>
3215: </script>
3216:
1.267 raeburn 3217: ENDSCRIPT
3218: }
3219:
1.381 raeburn 3220: sub wafproxy_javascript {
3221: my ($dom) = @_;
3222: return <<"ENDSCRIPT";
3223: <script type="text/javascript">
3224: // <![CDATA[
3225: function updateWAF() {
3226: if (document.getElementById('wafproxy_remoteip')) {
3227: var wafremote = 0;
3228: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3229: wafremote = 1;
3230: }
3231: var fields = new Array('header','trust');
3232: for (var i=0; i<fields.length; i++) {
3233: if (document.getElementById('wafproxy_'+fields[i])) {
3234: if (wafremote == 1) {
3235: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3236: }
3237: else {
3238: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3239: }
3240: }
3241: }
3242: if (document.getElementById('wafproxyranges_$dom')) {
3243: if (wafremote == 1) {
3244: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3245: } else {
3246: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3247: if (document.display.wafproxy_vpnaccess[i].checked) {
3248: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3249: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3250: }
3251: }
3252: }
3253: }
3254: }
3255: }
3256: return;
3257: }
3258:
3259: function checkWAF() {
3260: if (document.getElementById('wafproxy_remoteip')) {
3261: var wafvpn = 0;
3262: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3263: if (document.display.wafproxy_vpnaccess[i].checked) {
3264: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3265: wafvpn = 1;
3266: }
3267: break;
3268: }
3269: }
3270: var vpn = new Array('vpnint','vpnext');
3271: for (var i=0; i<vpn.length; i++) {
3272: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3273: if (wafvpn == 1) {
3274: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3275: }
3276: else {
3277: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3278: }
3279: }
3280: }
3281: if (document.getElementById('wafproxyranges_$dom')) {
3282: if (wafvpn == 1) {
3283: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3284: }
3285: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3286: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3287: }
3288: }
3289: }
3290: return;
3291: }
3292:
3293: function toggleWAF() {
3294: if (document.getElementById('wafproxy_table')) {
3295: var wafproxy = 0;
3296: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3297: if (document.display.wafproxy_${dom}[i].checked) {
3298: if (document.display.wafproxy_${dom}[i].value == 1) {
3299: wafproxy = 1;
3300: break;
3301: }
3302: }
3303: }
3304: if (wafproxy == 1) {
3305: document.getElementById('wafproxy_table').style.display='inline';
3306: }
3307: else {
3308: document.getElementById('wafproxy_table').style.display='none';
3309: }
3310: if (document.getElementById('wafproxyrow_${dom}')) {
3311: if (wafproxy == 1) {
3312: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3313: }
3314: else {
3315: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3316: }
3317: }
3318: if (document.getElementById('nowafproxyrow_$dom')) {
3319: if (wafproxy == 1) {
3320: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3321: }
3322: else {
3323: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3324: }
3325: }
3326: }
3327: return;
3328: }
3329: // ]]>
3330: </script>
3331:
3332: ENDSCRIPT
3333: }
3334:
1.372 raeburn 3335: sub proctoring_javascript {
3336: my ($settings) = @_;
3337: my (%ordered,$total,%jstext);
3338: $total = 0;
3339: if (ref($settings) eq 'HASH') {
3340: foreach my $item (keys(%{$settings})) {
3341: if (ref($settings->{$item}) eq 'HASH') {
3342: my $num = $settings->{$item}{'order'};
3343: $ordered{$num} = $item;
3344: }
3345: }
3346: $total = scalar(keys(%{$settings}));
3347: } else {
3348: %ordered = (
3349: 0 => 'proctorio',
3350: 1 => 'examity',
3351: );
3352: $total = 2;
3353: }
3354: my @jsarray = ();
3355: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3356: push(@jsarray,$ordered{$item});
3357: }
3358: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3359: return <<"ENDSCRIPT";
3360: <script type="text/javascript">
3361: // <![CDATA[
3362: function reorderProctoring(form,item) {
3363: var changedVal;
3364: $jstext
3365: var maxh = $total;
3366: var current = new Array;
3367: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3368: for (var i=0; i<proctors.length; i++) {
3369: var elementName = 'proctoring_pos_'+proctors[i];
3370: if (elementName != item) {
3371: if (form.elements[elementName]) {
3372: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3373: current[currVal] = elementName;
3374: }
3375: }
3376: }
3377: var oldVal;
3378: for (var j=0; j<maxh; j++) {
3379: if (current[j] == undefined) {
3380: oldVal = j;
3381: }
3382: }
3383: if (oldVal < changedVal) {
3384: for (var k=oldVal+1; k<=changedVal ; k++) {
3385: var elementName = current[k];
3386: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3387: }
3388: } else {
3389: for (var k=changedVal; k<oldVal; k++) {
3390: var elementName = current[k];
3391: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3392: }
3393: }
3394: return;
3395: }
3396:
3397: function toggleProctoring(form,item) {
3398: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3399: if (fieldsets.length) {
3400: var radioname = 'proctoring_available_'+item;
3401: var num = form.elements[radioname].length;
3402: if (num) {
3403: var setvis = '';
3404: for (var i=0; i<num; i++) {
3405: if (form.elements[radioname][i].checked) {
3406: if (form.elements[radioname][i].value == '1') {
3407: setvis = 1;
3408: break;
3409: }
3410: }
3411: }
3412: for (var j=0; j<fieldsets.length; j++) {
3413: if (setvis) {
3414: fieldsets[j].style.display = 'block';
3415: } else {
3416: fieldsets[j].style.display = 'none';
3417: }
3418: }
3419: }
3420: }
3421: return;
3422: }
3423:
3424: // ]]>
3425: </script>
3426:
3427: ENDSCRIPT
3428: }
3429:
3430:
1.320 raeburn 3431: sub lti_javascript {
1.405 raeburn 3432: my ($dom,$settings) = @_;
3433: my $togglejs = <i_toggle_js($dom);
1.320 raeburn 3434: unless (ref($settings) eq 'HASH') {
3435: return $togglejs;
3436: }
3437: my (%ordered,$total,%jstext);
1.390 raeburn 3438: $total = scalar(keys(%{$settings}));
1.320 raeburn 3439: foreach my $item (keys(%{$settings})) {
3440: if (ref($settings->{$item}) eq 'HASH') {
3441: my $num = $settings->{$item}{'order'};
1.390 raeburn 3442: if ($num eq '') {
3443: $num = $total - 1;
3444: }
1.320 raeburn 3445: $ordered{$num} = $item;
3446: }
3447: }
3448: my @jsarray = ();
3449: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3450: push(@jsarray,$ordered{$item});
3451: }
3452: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
1.406 raeburn 3453: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3454: return <<"ENDSCRIPT";
3455: <script type="text/javascript">
3456: // <![CDATA[
3457: function reorderLTI(form,item) {
3458: var changedVal;
3459: $jstext
3460: var newpos = 'lti_pos_add';
3461: var maxh = 1 + $total;
3462: var current = new Array;
3463: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3464: if (item == newpos) {
3465: changedVal = newitemVal;
3466: } else {
3467: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3468: current[newitemVal] = newpos;
3469: }
3470: for (var i=0; i<lti.length; i++) {
3471: var elementName = 'lti_pos_'+lti[i];
3472: if (elementName != item) {
3473: if (form.elements[elementName]) {
3474: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3475: current[currVal] = elementName;
3476: }
3477: }
3478: }
3479: var oldVal;
3480: for (var j=0; j<maxh; j++) {
3481: if (current[j] == undefined) {
3482: oldVal = j;
3483: }
3484: }
3485: if (oldVal < changedVal) {
3486: for (var k=oldVal+1; k<=changedVal ; k++) {
3487: var elementName = current[k];
3488: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3489: }
3490: } else {
3491: for (var k=changedVal; k<oldVal; k++) {
3492: var elementName = current[k];
3493: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3494: }
3495: }
3496: return;
3497: }
1.406 raeburn 3498:
3499: $linkprot_js
3500:
1.320 raeburn 3501: // ]]>
3502: </script>
3503:
3504: $togglejs
3505:
3506: ENDSCRIPT
3507: }
3508:
3509: sub lti_toggle_js {
1.405 raeburn 3510: my ($dom) = @_;
1.325 raeburn 3511: my %lcauthparmtext = &Apache::lonlocal::texthash (
3512: localauth => 'Local auth argument',
3513: krb => 'Kerberos domain',
3514: );
1.391 raeburn 3515: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3516: &js_escape(\$crsincalert);
1.405 raeburn 3517: my %servers = &Apache::lonnet::get_servers($dom,'library');
3518: my $primary = &Apache::lonnet::domain($dom,'primary');
3519: my $course_servers = "'".join("','",keys(%servers))."'";
3520:
1.320 raeburn 3521: return <<"ENDSCRIPT";
3522: <script type="text/javascript">
3523: // <![CDATA[
3524:
3525: function toggleLTI(form,setting,item) {
1.391 raeburn 3526: if ((setting == 'requser') || (setting == 'crsinc')) {
3527: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3528: var setvis = '';
3529: var radioname = 'lti_requser_'+item;
3530: var num = form.elements[radioname].length;
3531: if (num) {
3532: for (var i=0; i<num; i++) {
3533: if (form.elements[radioname][i].checked) {
3534: if (form.elements[radioname][i].value == '1') {
3535: setvis = 1;
3536: break;
3537: }
3538: }
3539: }
3540: }
3541: if (usrfieldsets.length) {
3542: for (var j=0; j<usrfieldsets.length; j++) {
3543: if (setvis) {
3544: usrfieldsets[j].style.display = 'block';
3545: } else {
3546: usrfieldsets[j].style.display = 'none';
3547: }
3548: }
3549: }
3550: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3551: if (crsfieldsets.length) {
3552: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3553: var num = form.elements[radioname].length;
3554: if (num) {
1.391 raeburn 3555: var crsvis = '';
1.345 raeburn 3556: for (var i=0; i<num; i++) {
3557: if (form.elements[radioname][i].checked) {
3558: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3559: if (setvis == '') {
3560: if (setting == 'crsinc'){
3561: alert("$crsincalert");
3562: form.elements[radioname][0].checked = true;
3563: }
3564: } else {
3565: crsvis = 1;
3566: }
3567: break;
1.345 raeburn 3568: }
3569: }
3570: }
1.391 raeburn 3571: setvis = crsvis;
3572: }
3573: for (var j=0; j<crsfieldsets.length; j++) {
3574: if (setvis) {
3575: crsfieldsets[j].style.display = 'block';
3576: } else {
3577: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3578: }
3579: }
3580: }
1.363 raeburn 3581: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3582: var radioname = '';
3583: var divid = '';
3584: if (setting == 'user') {
3585: radioname = 'lti_mapuser_'+item;
3586: divid = 'lti_userfield_'+item;
1.343 raeburn 3587: } else if (setting == 'crs') {
1.320 raeburn 3588: radioname = 'lti_mapcrs_'+item;
3589: divid = 'lti_crsfield_'+item;
1.363 raeburn 3590: } else if (setting == 'callback') {
3591: radioname = 'lti_callback_'+item;
3592: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3593: } else {
1.351 raeburn 3594: radioname = 'lti_passback_'+item;
1.337 raeburn 3595: divid = 'lti_passback_'+item;
1.320 raeburn 3596: }
3597: var num = form.elements[radioname].length;
3598: if (num) {
3599: var setvis = '';
3600: for (var i=0; i<num; i++) {
3601: if (form.elements[radioname][i].checked) {
1.363 raeburn 3602: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3603: if (form.elements[radioname][i].value == '1') {
3604: if (document.getElementById(divid)) {
3605: document.getElementById(divid).style.display = 'inline-block';
3606: }
3607: setvis = 1;
3608: break;
3609: }
3610: } else {
3611: if (form.elements[radioname][i].value == 'other') {
3612: if (document.getElementById(divid)) {
3613: document.getElementById(divid).style.display = 'inline-block';
3614: }
3615: setvis = 1;
3616: break;
1.320 raeburn 3617: }
3618: }
3619: }
3620: }
3621: if (!setvis) {
3622: if (document.getElementById(divid)) {
3623: document.getElementById(divid).style.display = 'none';
3624: }
3625: }
3626: }
3627: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3628: var numsec = form.elements['lti_crssec_'+item].length;
3629: if (numsec) {
3630: var setvis = '';
3631: for (var i=0; i<numsec; i++) {
3632: if (form.elements['lti_crssec_'+item][i].checked) {
3633: if (form.elements['lti_crssec_'+item][i].value == '1') {
3634: if (document.getElementById('lti_crssecfield_'+item)) {
3635: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3636: setvis = 1;
3637: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3638: if (numsrcsec) {
3639: var setsrcvis = '';
3640: for (var j=0; j<numsrcsec; j++) {
3641: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3642: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3643: if (document.getElementById('lti_secsrcfield_'+item)) {
3644: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3645: setsrcvis = 1;
3646: }
3647: }
3648: }
3649: }
3650: if (!setsrcvis) {
3651: if (document.getElementById('lti_secsrcfield_'+item)) {
3652: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3653: }
3654: }
3655: }
3656: }
3657: }
3658: }
3659: }
3660: if (!setvis) {
3661: if (document.getElementById('lti_crssecfield_'+item)) {
3662: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3663: }
3664: if (document.getElementById('lti_secsrcfield_'+item)) {
3665: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3666: }
3667: }
3668: }
1.325 raeburn 3669: } else if (setting == 'lcauth') {
3670: var numauth = form.elements['lti_lcauth_'+item].length;
3671: if (numauth) {
3672: for (var i=0; i<numauth; i++) {
3673: if (form.elements['lti_lcauth_'+item][i].checked) {
3674: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3675: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3676: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3677: } else {
3678: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3679: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3680: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3681: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3682: } else {
3683: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3684: }
3685: }
3686: }
3687: }
3688: }
3689: }
3690: }
1.326 raeburn 3691: } else if (setting == 'lcmenu') {
3692: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3693: var divid = 'lti_menufield_'+item;
3694: var setvis = '';
3695: for (var i=0; i<menus.length; i++) {
3696: var radioname = menus[i];
3697: var num = form.elements[radioname].length;
3698: if (num) {
3699: for (var j=0; j<num; j++) {
3700: if (form.elements[radioname][j].checked) {
3701: if (form.elements[radioname][j].value == '1') {
3702: if (document.getElementById(divid)) {
3703: document.getElementById(divid).style.display = 'inline-block';
3704: }
3705: setvis = 1;
3706: break;
3707: }
3708: }
3709: }
3710: }
3711: if (setvis == 1) {
3712: break;
3713: }
3714: }
3715: if (!setvis) {
3716: if (document.getElementById(divid)) {
3717: document.getElementById(divid).style.display = 'none';
3718: }
3719: }
1.320 raeburn 3720: }
3721: return;
3722: }
1.405 raeburn 3723:
3724: function toggleLTIEncKey(form) {
3725: var shownhosts = new Array();
3726: var hiddenhosts = new Array();
3727: var forcourse = new Array($course_servers);
3728: var fromdomain = '$primary';
3729: var crsradio = form.elements['ltisec_crslinkprot'];
3730: if (crsradio.length) {
3731: for (var i=0; i<crsradio.length; i++) {
3732: if (crsradio[i].checked) {
3733: if (crsradio[i].value == 1) {
3734: if (forcourse.length > 0) {
3735: for (var j=0; j<forcourse.length; j++) {
3736: if (!shownhosts.includes(forcourse[j])) {
3737: shownhosts.push(forcourse[j]);
3738: }
3739: }
3740: }
3741: } else {
3742: if (forcourse.length > 0) {
3743: for (var j=0; j<forcourse.length; j++) {
3744: if (!hiddenhosts.includes(forcourse[j])) {
3745: hiddenhosts.push(forcourse[j]);
3746: }
3747: }
3748: }
3749: }
3750: }
3751: }
3752: }
3753: var domradio = form.elements['ltisec_domlinkprot'];
3754: if (domradio.length) {
3755: for (var i=0; i<domradio.length; i++) {
3756: if (domradio[i].checked) {
3757: if (domradio[i].value == 1) {
3758: if (!shownhosts.includes(fromdomain)) {
3759: shownhosts.push(fromdomain);
3760: }
3761: } else {
3762: if (!hiddenhosts.includes(fromdomain)) {
3763: hiddenhosts.push(fromdomain);
3764: }
3765: }
3766: }
3767: }
3768: }
3769: var consumersradio = form.elements['ltisec_consumers'];
3770: if (consumersradio.length) {
3771: for (var i=0; i<consumersradio.length; i++) {
3772: if (consumersradio[i].checked) {
3773: if (consumersradio[i].value == 1) {
3774: if (!shownhosts.includes(fromdomain)) {
3775: shownhosts.push(fromdomain);
3776: }
3777: } else {
3778: if (!hiddenhosts.includes(fromdomain)) {
3779: hiddenhosts.push(fromdomain);
3780: }
3781: }
3782: }
3783: }
3784: }
3785: if (shownhosts.length > 0) {
3786: for (var i=0; i<shownhosts.length; i++) {
3787: if (document.getElementById('ltisec_info_'+shownhosts[i])) {
3788: document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
3789: }
3790: }
3791: if (document.getElementById('ltisec_noprivkey')) {
3792: document.getElementById('ltisec_noprivkey').style.display = 'none';
3793: }
3794: } else {
3795: if (document.getElementById('ltisec_noprivkey')) {
3796: document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
3797: }
3798: }
3799: if (hiddenhosts.length > 0) {
3800: for (var i=0; i<hiddenhosts.length; i++) {
3801: if (!shownhosts.includes(hiddenhosts[i])) {
3802: if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
3803: document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
3804: }
3805: }
3806: }
3807: }
3808: return;
3809: }
3810:
3811: function togglePrivKey(form,hostid) {
3812: var radioname = '';
3813: var currdivid = '';
3814: var newdivid = '';
3815: if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
3816: (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
3817: currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
3818: newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
3819: radioname = form.elements['ltisec_changeprivkey_'+hostid];
3820: if (radioname) {
3821: if (radioname.length > 0) {
3822: var setvis;
3823: for (var i=0; i<radioname.length; i++) {
3824: if (radioname[i].checked == true) {
3825: if (radioname[i].value == 1) {
3826: newdivid.style.display = 'inline-block';
3827: currdivid.style.display = 'none';
3828: setvis = 1;
3829: }
3830: break;
3831: }
3832: }
3833: if (!setvis) {
3834: newdivid.style.display = 'none';
3835: currdivid.style.display = 'inline-block';
3836: }
3837: }
3838: }
3839: }
3840: }
3841:
1.320 raeburn 3842: // ]]>
3843: </script>
3844:
3845: ENDSCRIPT
3846: }
3847:
1.385 raeburn 3848: sub autoupdate_javascript {
3849: return <<"ENDSCRIPT";
3850: <script type="text/javascript">
3851: // <![CDATA[
3852: function toggleLastActiveDays(form) {
3853: var radioname = 'lastactive';
3854: var divid = 'lastactive_div';
3855: var num = form.elements[radioname].length;
3856: if (num) {
3857: var setvis = '';
3858: for (var i=0; i<num; i++) {
3859: if (form.elements[radioname][i].checked) {
3860: if (form.elements[radioname][i].value == '1') {
3861: if (document.getElementById(divid)) {
3862: document.getElementById(divid).style.display = 'inline-block';
3863: }
3864: setvis = 1;
3865: }
3866: break;
3867: }
3868: }
3869: if (!setvis) {
3870: if (document.getElementById(divid)) {
3871: document.getElementById(divid).style.display = 'none';
3872: }
3873: }
3874: }
3875: return;
3876: }
3877: // ]]>
3878: </script>
3879:
3880: ENDSCRIPT
3881: }
3882:
1.399 raeburn 3883: sub autoenroll_javascript {
3884: return <<"ENDSCRIPT";
3885: <script type="text/javascript">
3886: // <![CDATA[
3887: function toggleFailsafe(form) {
3888: var radioname = 'autoenroll_failsafe';
3889: var divid = 'autoenroll_failsafe_div';
3890: var num = form.elements[radioname].length;
3891: if (num) {
3892: var setvis = '';
3893: for (var i=0; i<num; i++) {
3894: if (form.elements[radioname][i].checked) {
3895: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3896: if (document.getElementById(divid)) {
3897: document.getElementById(divid).style.display = 'inline-block';
3898: }
3899: setvis = 1;
3900: }
3901: break;
3902: }
3903: }
3904: if (!setvis) {
3905: if (document.getElementById(divid)) {
3906: document.getElementById(divid).style.display = 'none';
3907: }
3908: }
3909: }
3910: return;
3911: }
3912: // ]]>
3913: </script>
3914:
3915: ENDSCRIPT
3916: }
3917:
1.386 raeburn 3918: sub saml_javascript {
3919: return <<"ENDSCRIPT";
3920: <script type="text/javascript">
3921: // <![CDATA[
3922: function toggleSamlOptions(form,hostid) {
3923: var radioname = 'saml_'+hostid;
3924: var tablecellon = 'samloptionson_'+hostid;
3925: var tablecelloff = 'samloptionsoff_'+hostid;
3926: var num = form.elements[radioname].length;
3927: if (num) {
3928: var setvis = '';
3929: for (var i=0; i<num; i++) {
3930: if (form.elements[radioname][i].checked) {
3931: if (form.elements[radioname][i].value == '1') {
3932: if (document.getElementById(tablecellon)) {
3933: document.getElementById(tablecellon).style.display='';
3934: }
3935: if (document.getElementById(tablecelloff)) {
3936: document.getElementById(tablecelloff).style.display='none';
3937: }
3938: setvis = 1;
3939: }
3940: break;
3941: }
3942: }
3943: if (!setvis) {
3944: if (document.getElementById(tablecellon)) {
3945: document.getElementById(tablecellon).style.display='none';
3946: }
3947: if (document.getElementById(tablecelloff)) {
3948: document.getElementById(tablecelloff).style.display='';
3949: }
3950: }
3951: }
3952: return;
3953: }
3954: // ]]>
3955: </script>
3956:
3957: ENDSCRIPT
3958: }
3959:
1.394 raeburn 3960: sub ipaccess_javascript {
3961: my ($settings) = @_;
3962: my (%ordered,$total,%jstext);
3963: $total = 0;
3964: if (ref($settings) eq 'HASH') {
3965: foreach my $item (keys(%{$settings})) {
3966: if (ref($settings->{$item}) eq 'HASH') {
3967: my $num = $settings->{$item}{'order'};
3968: $ordered{$num} = $item;
3969: }
3970: }
3971: $total = scalar(keys(%{$settings}));
3972: }
3973: my @jsarray = ();
3974: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3975: push(@jsarray,$ordered{$item});
3976: }
3977: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3978: return <<"ENDSCRIPT";
3979: <script type="text/javascript">
3980: // <![CDATA[
3981: function reorderIPaccess(form,item) {
3982: var changedVal;
3983: $jstext
3984: var newpos = 'ipaccess_pos_add';
3985: var maxh = 1 + $total;
3986: var current = new Array;
3987: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3988: if (item == newpos) {
3989: changedVal = newitemVal;
3990: } else {
3991: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3992: current[newitemVal] = newpos;
3993: }
3994: for (var i=0; i<ipaccess.length; i++) {
3995: var elementName = 'ipaccess_pos_'+ipaccess[i];
3996: if (elementName != item) {
3997: if (form.elements[elementName]) {
3998: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3999: current[currVal] = elementName;
4000: }
4001: }
4002: }
4003: var oldVal;
4004: for (var j=0; j<maxh; j++) {
4005: if (current[j] == undefined) {
4006: oldVal = j;
4007: }
4008: }
4009: if (oldVal < changedVal) {
4010: for (var k=oldVal+1; k<=changedVal ; k++) {
4011: var elementName = current[k];
4012: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4013: }
4014: } else {
4015: for (var k=changedVal; k<oldVal; k++) {
4016: var elementName = current[k];
4017: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4018: }
4019: }
4020: return;
4021: }
4022: // ]]>
4023: </script>
4024:
4025: ENDSCRIPT
4026: }
4027:
1.3 raeburn 4028: sub print_autoenroll {
1.30 raeburn 4029: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 4030: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 4031: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
4032: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
4033: $failsafesty = 'none';
4034: %failsafechecked = (
4035: off => ' checked="checked"',
4036: );
1.3 raeburn 4037: if (ref($settings) eq 'HASH') {
4038: if (exists($settings->{'run'})) {
4039: if ($settings->{'run'} eq '0') {
4040: $runoff = ' checked="checked" ';
4041: $runon = ' ';
4042: } else {
4043: $runon = ' checked="checked" ';
4044: $runoff = ' ';
4045: }
4046: } else {
4047: if ($autorun) {
4048: $runon = ' checked="checked" ';
4049: $runoff = ' ';
4050: } else {
4051: $runoff = ' checked="checked" ';
4052: $runon = ' ';
4053: }
4054: }
1.129 raeburn 4055: if (exists($settings->{'co-owners'})) {
4056: if ($settings->{'co-owners'} eq '0') {
4057: $coownersoff = ' checked="checked" ';
4058: $coownerson = ' ';
4059: } else {
4060: $coownerson = ' checked="checked" ';
4061: $coownersoff = ' ';
4062: }
4063: } else {
4064: $coownersoff = ' checked="checked" ';
4065: $coownerson = ' ';
4066: }
1.3 raeburn 4067: if (exists($settings->{'sender_domain'})) {
4068: $defdom = $settings->{'sender_domain'};
4069: }
1.399 raeburn 4070: if (exists($settings->{'failsafe'})) {
4071: $failsafe = $settings->{'failsafe'};
4072: if ($failsafe eq 'zero') {
1.400 raeburn 4073: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4074: $failsafechecked{'off'} = '';
4075: $failsafesty = 'inline-block';
4076: } elsif ($failsafe eq 'any') {
4077: $failsafechecked{'any'} = ' checked="checked"';
4078: $failsafechecked{'off'} = '';
4079: }
4080: $autofailsafe = $settings->{'autofailsafe'};
4081: } elsif (exists($settings->{'autofailsafe'})) {
4082: $autofailsafe = $settings->{'autofailsafe'};
4083: if ($autofailsafe ne '') {
4084: $failsafechecked{'zero'} = ' checked="checked"';
4085: $failsafe = 'zero';
1.400 raeburn 4086: $failsafechecked{'off'} = '';
1.399 raeburn 4087: }
1.274 raeburn 4088: }
1.14 raeburn 4089: } else {
4090: if ($autorun) {
4091: $runon = ' checked="checked" ';
4092: $runoff = ' ';
4093: } else {
4094: $runoff = ' checked="checked" ';
4095: $runon = ' ';
4096: }
1.3 raeburn 4097: }
4098: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4099: my $notif_sender;
4100: if (ref($settings) eq 'HASH') {
4101: $notif_sender = $settings->{'sender_uname'};
4102: }
1.3 raeburn 4103: my $datatable='<tr class="LC_odd_row">'.
4104: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4105: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4106: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4107: $runon.' value="1" />'.&mt('Yes').'</label> '.
4108: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4109: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4110: '</tr><tr>'.
4111: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4112: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4113: &mt('username').': '.
4114: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4115: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4116: ': '.$domform.'</span></td></tr>'.
4117: '<tr class="LC_odd_row">'.
4118: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4119: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4120: '<input type="radio" name="autoassign_coowners"'.
4121: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4122: '<label><input type="radio" name="autoassign_coowners"'.
4123: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4124: '</tr><tr>'.
4125: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4126: '<td class="LC_left_item"><span class="LC_nobreak">'.
4127: '<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> '.
4128: '<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 />'.
4129: '<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 4130: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4131: '<span class="LC_nobreak">'.
4132: &mt('Threshold for number of students in section to drop: [_1]',
4133: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4134: '</span></div></td></tr>';
1.274 raeburn 4135: $$rowtotal += 4;
1.3 raeburn 4136: return $datatable;
4137: }
4138:
4139: sub print_autoupdate {
1.30 raeburn 4140: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4141: my ($enable,$datatable);
1.3 raeburn 4142: if ($position eq 'top') {
1.385 raeburn 4143: my %choices = &Apache::lonlocal::texthash (
4144: run => 'Auto-update active?',
4145: classlists => 'Update information in classlists?',
4146: unexpired => 'Skip updates for users without active or future roles?',
4147: lastactive => 'Skip updates for inactive users?',
4148: );
4149: my $itemcount = 0;
1.3 raeburn 4150: my $updateon = ' ';
4151: my $updateoff = ' checked="checked" ';
4152: if (ref($settings) eq 'HASH') {
4153: if ($settings->{'run'} eq '1') {
4154: $updateon = $updateoff;
4155: $updateoff = ' ';
4156: }
4157: }
1.385 raeburn 4158: $enable = '<tr class="LC_odd_row">'.
4159: '<td>'.$choices{'run'}.'</td>'.
4160: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4161: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4162: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4163: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4164: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4165: '</tr>';
1.385 raeburn 4166: my @toggles = ('classlists','unexpired');
4167: my %defaultchecked = ('classlists' => 'off',
4168: 'unexpired' => 'off'
4169: );
4170: $$rowtotal ++;
4171: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4172: \%choices,$itemcount,'','','left','no');
4173: $datatable = $enable.$datatable;
4174: $$rowtotal += $itemcount;
4175: my $lastactiveon = ' ';
4176: my $lastactiveoff = ' checked="checked" ';
4177: my $lastactivestyle = 'none';
4178: my $lastactivedays;
4179: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4180: if (ref($settings) eq 'HASH') {
4181: if ($settings->{'lastactive'} =~ /^\d+$/) {
4182: $lastactiveon = $lastactiveoff;
4183: $lastactiveoff = ' ';
4184: $lastactivestyle = 'inline-block';
4185: $lastactivedays = $settings->{'lastactive'};
4186: }
4187: }
4188: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4189: $datatable .= '<tr'.$css_class.'>'.
4190: '<td>'.$choices{'lastactive'}.'</td>'.
4191: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4192: '<input type="radio" name="lastactive"'.
4193: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4194: ' <label>'.
4195: '<input type="radio" name="lastactive"'.
4196: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4197: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4198: ': '.&mt('inactive = no activity in last [_1] days',
4199: '<input type="text" size="5" name="lastactivedays" value="'.
4200: $lastactivedays.'" />').
4201: '</span></td>'.
4202: '</tr>';
4203: $$rowtotal ++;
1.131 raeburn 4204: } elsif ($position eq 'middle') {
4205: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4206: my $numinrow = 3;
4207: my $locknamesettings;
4208: $datatable .= &insttypes_row($settings,$types,$usertypes,
4209: $dom,$numinrow,$othertitle,
1.305 raeburn 4210: 'lockablenames',$rowtotal);
1.131 raeburn 4211: $$rowtotal ++;
1.3 raeburn 4212: } else {
1.44 raeburn 4213: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4214: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4215: 'permanentemail','id');
1.33 raeburn 4216: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4217: my $numrows = 0;
1.26 raeburn 4218: if (ref($types) eq 'ARRAY') {
4219: if (@{$types} > 0) {
4220: $datatable =
4221: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4222: \@fields,$types,\$numrows);
1.30 raeburn 4223: $$rowtotal += @{$types};
1.26 raeburn 4224: }
1.3 raeburn 4225: }
4226: $datatable .=
4227: &usertype_update_row($settings,{'default' => $othertitle},
4228: \%fieldtitles,\@fields,['default'],
4229: \$numrows);
1.30 raeburn 4230: $$rowtotal ++;
1.3 raeburn 4231: }
4232: return $datatable;
4233: }
4234:
1.125 raeburn 4235: sub print_autocreate {
4236: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4237: my (%createon,%createoff,%currhash);
1.125 raeburn 4238: my @types = ('xml','req');
4239: if (ref($settings) eq 'HASH') {
4240: foreach my $item (@types) {
4241: $createoff{$item} = ' checked="checked" ';
4242: $createon{$item} = ' ';
4243: if (exists($settings->{$item})) {
4244: if ($settings->{$item}) {
4245: $createon{$item} = ' checked="checked" ';
4246: $createoff{$item} = ' ';
4247: }
4248: }
4249: }
1.210 raeburn 4250: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4251: $currhash{$settings->{'xmldc'}} = 1;
4252: }
1.125 raeburn 4253: } else {
4254: foreach my $item (@types) {
4255: $createoff{$item} = ' checked="checked" ';
4256: $createon{$item} = ' ';
4257: }
4258: }
4259: $$rowtotal += 2;
1.191 raeburn 4260: my $numinrow = 2;
1.125 raeburn 4261: my $datatable='<tr class="LC_odd_row">'.
4262: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4263: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4264: '<input type="radio" name="autocreate_xml"'.
4265: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4266: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4267: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4268: '</td></tr><tr>'.
4269: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4270: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4271: '<input type="radio" name="autocreate_req"'.
4272: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4273: '<label><input type="radio" name="autocreate_req"'.
4274: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4275: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4276: 'autocreate_xmldc',%currhash);
1.247 raeburn 4277: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4278: if ($numdc > 1) {
1.247 raeburn 4279: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4280: '</td><td class="LC_left_item">';
1.125 raeburn 4281: } else {
1.247 raeburn 4282: $datatable .= &mt('Course creation processed as:').
4283: '</td><td class="LC_right_item">';
1.125 raeburn 4284: }
1.247 raeburn 4285: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4286: $$rowtotal += $rows;
1.125 raeburn 4287: return $datatable;
4288: }
4289:
1.23 raeburn 4290: sub print_directorysrch {
1.277 raeburn 4291: my ($position,$dom,$settings,$rowtotal) = @_;
4292: my $datatable;
4293: if ($position eq 'top') {
4294: my $instsrchon = ' ';
4295: my $instsrchoff = ' checked="checked" ';
4296: my ($exacton,$containson,$beginson);
4297: my $instlocalon = ' ';
4298: my $instlocaloff = ' checked="checked" ';
4299: if (ref($settings) eq 'HASH') {
4300: if ($settings->{'available'} eq '1') {
4301: $instsrchon = $instsrchoff;
4302: $instsrchoff = ' ';
4303: }
4304: if ($settings->{'localonly'} eq '1') {
4305: $instlocalon = $instlocaloff;
4306: $instlocaloff = ' ';
4307: }
4308: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4309: foreach my $type (@{$settings->{'searchtypes'}}) {
4310: if ($type eq 'exact') {
4311: $exacton = ' checked="checked" ';
4312: } elsif ($type eq 'contains') {
4313: $containson = ' checked="checked" ';
4314: } elsif ($type eq 'begins') {
4315: $beginson = ' checked="checked" ';
4316: }
4317: }
4318: } else {
4319: if ($settings->{'searchtypes'} eq 'exact') {
4320: $exacton = ' checked="checked" ';
4321: } elsif ($settings->{'searchtypes'} eq 'contains') {
4322: $containson = ' checked="checked" ';
4323: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4324: $exacton = ' checked="checked" ';
4325: $containson = ' checked="checked" ';
4326: }
4327: }
1.277 raeburn 4328: }
4329: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4330: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4331:
4332: my $numinrow = 4;
4333: my $cansrchrow = 0;
4334: $datatable='<tr class="LC_odd_row">'.
4335: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4336: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4337: '<input type="radio" name="dirsrch_available"'.
4338: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4339: '<label><input type="radio" name="dirsrch_available"'.
4340: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4341: '</tr><tr>'.
4342: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4343: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4344: '<input type="radio" name="dirsrch_instlocalonly"'.
4345: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4346: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4347: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4348: '</tr>';
4349: $$rowtotal += 2;
4350: if (ref($usertypes) eq 'HASH') {
4351: if (keys(%{$usertypes}) > 0) {
4352: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4353: $numinrow,$othertitle,'cansearch',
4354: $rowtotal);
1.277 raeburn 4355: $cansrchrow = 1;
1.25 raeburn 4356: }
1.23 raeburn 4357: }
1.277 raeburn 4358: if ($cansrchrow) {
4359: $$rowtotal ++;
4360: $datatable .= '<tr>';
4361: } else {
4362: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4363: }
1.277 raeburn 4364: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4365: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4366: foreach my $title (@{$titleorder}) {
4367: if (defined($searchtitles->{$title})) {
4368: my $check = ' ';
4369: if (ref($settings) eq 'HASH') {
4370: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4371: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4372: $check = ' checked="checked" ';
4373: }
1.39 raeburn 4374: }
1.25 raeburn 4375: }
1.277 raeburn 4376: $datatable .= '<td class="LC_left_item">'.
4377: '<span class="LC_nobreak"><label>'.
4378: '<input type="checkbox" name="searchby" '.
4379: 'value="'.$title.'"'.$check.'/>'.
4380: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4381: }
4382: }
1.277 raeburn 4383: $datatable .= '</tr></table></td></tr>';
4384: $$rowtotal ++;
4385: if ($cansrchrow) {
4386: $datatable .= '<tr class="LC_odd_row">';
4387: } else {
4388: $datatable .= '<tr>';
4389: }
4390: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4391: '<td class="LC_left_item" colspan="2">'.
4392: '<span class="LC_nobreak"><label>'.
4393: '<input type="checkbox" name="searchtypes" '.
4394: $exacton.' value="exact" />'.&mt('Exact match').
4395: '</label> '.
4396: '<label><input type="checkbox" name="searchtypes" '.
4397: $beginson.' value="begins" />'.&mt('Begins with').
4398: '</label> '.
4399: '<label><input type="checkbox" name="searchtypes" '.
4400: $containson.' value="contains" />'.&mt('Contains').
4401: '</label></span></td></tr>';
4402: $$rowtotal ++;
1.26 raeburn 4403: } else {
1.277 raeburn 4404: my $domsrchon = ' checked="checked" ';
4405: my $domsrchoff = ' ';
4406: my $domlocalon = ' ';
4407: my $domlocaloff = ' checked="checked" ';
4408: if (ref($settings) eq 'HASH') {
4409: if ($settings->{'lclocalonly'} eq '1') {
4410: $domlocalon = $domlocaloff;
4411: $domlocaloff = ' ';
4412: }
4413: if ($settings->{'lcavailable'} eq '0') {
4414: $domsrchoff = $domsrchon;
4415: $domsrchon = ' ';
4416: }
4417: }
4418: $datatable='<tr class="LC_odd_row">'.
4419: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4420: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4421: '<input type="radio" name="dirsrch_domavailable"'.
4422: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4423: '<label><input type="radio" name="dirsrch_domavailable"'.
4424: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4425: '</tr><tr>'.
4426: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4427: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4428: '<input type="radio" name="dirsrch_domlocalonly"'.
4429: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4430: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4431: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4432: '</tr>';
4433: $$rowtotal += 2;
1.26 raeburn 4434: }
1.25 raeburn 4435: return $datatable;
4436: }
4437:
1.28 raeburn 4438: sub print_contacts {
1.286 raeburn 4439: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4440: my $datatable;
4441: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4442: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4443: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4444: if ($position eq 'top') {
4445: if (ref($settings) eq 'HASH') {
4446: foreach my $item (@contacts) {
4447: if (exists($settings->{$item})) {
4448: $to{$item} = $settings->{$item};
4449: }
4450: }
4451: }
4452: } elsif ($position eq 'middle') {
4453: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4454: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4455: foreach my $type (@mailings) {
4456: $otheremails{$type} = '';
4457: }
1.340 raeburn 4458: } elsif ($position eq 'lower') {
4459: if (ref($settings) eq 'HASH') {
4460: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4461: %lonstatus = %{$settings->{'lonstatus'}};
4462: }
4463: }
1.286 raeburn 4464: } else {
4465: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4466: foreach my $type (@mailings) {
4467: $otheremails{$type} = '';
4468: }
1.286 raeburn 4469: $bccemails{'helpdeskmail'} = '';
4470: $bccemails{'otherdomsmail'} = '';
4471: $includestr{'helpdeskmail'} = '';
4472: $includestr{'otherdomsmail'} = '';
4473: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4474: }
1.28 raeburn 4475: if (ref($settings) eq 'HASH') {
1.340 raeburn 4476: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4477: foreach my $type (@mailings) {
4478: if (exists($settings->{$type})) {
4479: if (ref($settings->{$type}) eq 'HASH') {
4480: foreach my $item (@contacts) {
4481: if ($settings->{$type}{$item}) {
4482: $checked{$type}{$item} = ' checked="checked" ';
4483: }
4484: }
4485: $otheremails{$type} = $settings->{$type}{'others'};
4486: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4487: $bccemails{$type} = $settings->{$type}{'bcc'};
4488: if ($settings->{$type}{'include'} ne '') {
4489: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4490: $includestr{$type} = &unescape($includestr{$type});
4491: }
4492: }
4493: }
4494: } elsif ($type eq 'lonstatusmail') {
4495: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4496: }
1.28 raeburn 4497: }
4498: }
1.286 raeburn 4499: if ($position eq 'bottom') {
4500: foreach my $type (@mailings) {
4501: $bccemails{$type} = $settings->{$type}{'bcc'};
4502: if ($settings->{$type}{'include'} ne '') {
4503: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4504: $includestr{$type} = &unescape($includestr{$type});
4505: }
4506: }
4507: if (ref($settings->{'helpform'}) eq 'HASH') {
4508: if (ref($fields) eq 'ARRAY') {
4509: foreach my $field (@{$fields}) {
4510: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4511: }
1.286 raeburn 4512: }
4513: if (exists($settings->{'helpform'}{'maxsize'})) {
4514: $maxsize = $settings->{'helpform'}{'maxsize'};
4515: } else {
1.289 raeburn 4516: $maxsize = '1.0';
1.286 raeburn 4517: }
4518: } else {
4519: if (ref($fields) eq 'ARRAY') {
4520: foreach my $field (@{$fields}) {
4521: $currfield{$field} = 'yes';
1.134 raeburn 4522: }
1.28 raeburn 4523: }
1.286 raeburn 4524: $maxsize = '1.0';
1.28 raeburn 4525: }
4526: }
4527: } else {
1.286 raeburn 4528: if ($position eq 'top') {
4529: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4530: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4531: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4532: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4533: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4534: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4535: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4536: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4537: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4538: } elsif ($position eq 'bottom') {
4539: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4540: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4541: if (ref($fields) eq 'ARRAY') {
4542: foreach my $field (@{$fields}) {
4543: $currfield{$field} = 'yes';
4544: }
4545: }
4546: $maxsize = '1.0';
4547: }
1.28 raeburn 4548: }
4549: my ($titles,$short_titles) = &contact_titles();
4550: my $rownum = 0;
4551: my $css_class;
1.286 raeburn 4552: if ($position eq 'top') {
4553: foreach my $item (@contacts) {
4554: $css_class = $rownum%2?' class="LC_odd_row"':'';
4555: $datatable .= '<tr'.$css_class.'>'.
4556: '<td><span class="LC_nobreak">'.$titles->{$item}.
4557: '</span></td><td class="LC_right_item">'.
4558: '<input type="text" name="'.$item.'" value="'.
4559: $to{$item}.'" /></td></tr>';
4560: $rownum ++;
4561: }
1.315 raeburn 4562: } elsif ($position eq 'bottom') {
4563: $css_class = $rownum%2?' class="LC_odd_row"':'';
4564: $datatable .= '<tr'.$css_class.'>'.
4565: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4566: &mt('(e-mail, subject, and description always shown)').
4567: '</td><td class="LC_left_item">';
4568: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4569: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4570: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4571: foreach my $field (@{$fields}) {
4572: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4573: if (($field eq 'screenshot') || ($field eq 'cc')) {
4574: $datatable .= ' '.&mt('(logged-in users)');
4575: }
4576: $datatable .='</td><td>';
4577: my $clickaction;
4578: if ($field eq 'screenshot') {
4579: $clickaction = ' onclick="screenshotSize(this);"';
4580: }
4581: if (ref($possoptions->{$field}) eq 'ARRAY') {
4582: foreach my $option (@{$possoptions->{$field}}) {
4583: my $checked;
4584: if ($currfield{$field} eq $option) {
4585: $checked = ' checked="checked"';
4586: }
4587: $datatable .= '<span class="LC_nobreak"><label>'.
4588: '<input type="radio" name="helpform_'.$field.'" '.
4589: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4590: '</label></span>'.(' 'x2);
4591: }
4592: }
4593: if ($field eq 'screenshot') {
4594: my $display;
4595: if ($currfield{$field} eq 'no') {
4596: $display = ' style="display:none"';
4597: }
1.334 raeburn 4598: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4599: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4600: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4601: }
4602: $datatable .= '</td></tr>';
4603: }
4604: $datatable .= '</table>';
4605: }
4606: $datatable .= '</td></tr>'."\n";
4607: $rownum ++;
4608: }
1.340 raeburn 4609: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4610: foreach my $type (@mailings) {
4611: $css_class = $rownum%2?' class="LC_odd_row"':'';
4612: $datatable .= '<tr'.$css_class.'>'.
4613: '<td><span class="LC_nobreak">'.
4614: $titles->{$type}.': </span></td>'.
4615: '<td class="LC_left_item">';
4616: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4617: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4618: }
4619: $datatable .= '<span class="LC_nobreak">';
4620: foreach my $item (@contacts) {
4621: $datatable .= '<label>'.
4622: '<input type="checkbox" name="'.$type.'"'.
4623: $checked{$type}{$item}.
4624: ' value="'.$item.'" />'.$short_titles->{$item}.
4625: '</label> ';
4626: }
4627: $datatable .= '</span><br />'.&mt('Others').': '.
4628: '<input type="text" name="'.$type.'_others" '.
4629: 'value="'.$otheremails{$type}.'" />';
4630: my %locchecked;
4631: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4632: foreach my $loc ('s','b') {
4633: if ($includeloc{$type} eq $loc) {
4634: $locchecked{$loc} = ' checked="checked"';
4635: last;
4636: }
4637: }
4638: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4639: '<input type="text" name="'.$type.'_bcc" '.
4640: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4641: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4642: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4643: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4644: '<span class="LC_nobreak">'.&mt('Location:').' '.
4645: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4646: (' 'x2).
4647: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4648: '</span></fieldset>';
4649: }
4650: $datatable .= '</td></tr>'."\n";
4651: $rownum ++;
4652: }
1.28 raeburn 4653: }
1.286 raeburn 4654: if ($position eq 'middle') {
4655: my %choices;
1.340 raeburn 4656: my $corelink = &core_link_msu();
4657: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4658: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4659: $corelink);
4660: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4661: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4662: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4663: 'reportupdates' => 'on',
4664: 'reportstatus' => 'on');
1.286 raeburn 4665: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4666: \%choices,$rownum);
4667: $datatable .= $reports;
1.340 raeburn 4668: } elsif ($position eq 'lower') {
1.378 raeburn 4669: my (%current,%excluded,%weights);
1.340 raeburn 4670: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4671: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4672: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4673: } else {
1.378 raeburn 4674: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4675: }
4676: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4677: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4678: } else {
1.378 raeburn 4679: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4680: }
4681: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4682: foreach my $type ('E','W','N','U') {
1.340 raeburn 4683: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4684: $weights{$type} = $lonstatus{'weights'}{$type};
4685: } else {
4686: $weights{$type} = $defaults->{$type};
4687: }
4688: }
4689: } else {
1.341 raeburn 4690: foreach my $type ('E','W','N','U') {
1.340 raeburn 4691: $weights{$type} = $defaults->{$type};
4692: }
4693: }
4694: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4695: if (@{$lonstatus{'excluded'}} > 0) {
4696: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4697: }
4698: }
1.378 raeburn 4699: foreach my $item ('errorthreshold','errorsysmail') {
4700: $css_class = $rownum%2?' class="LC_odd_row"':'';
4701: $datatable .= '<tr'.$css_class.'>'.
4702: '<td class="LC_left_item"><span class="LC_nobreak">'.
4703: $titles->{$item}.
4704: '</span></td><td class="LC_left_item">'.
4705: '<input type="text" name="'.$item.'" value="'.
4706: $current{$item}.'" size="5" /></td></tr>';
4707: $rownum ++;
4708: }
1.340 raeburn 4709: $css_class = $rownum%2?' class="LC_odd_row"':'';
4710: $datatable .= '<tr'.$css_class.'>'.
4711: '<td class="LC_left_item">'.
4712: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4713: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4714: foreach my $type ('E','W','N','U') {
1.340 raeburn 4715: $datatable .= '<td>'.$names->{$type}.'<br />'.
4716: '<input type="text" name="errorweights_'.$type.'" value="'.
4717: $weights{$type}.'" size="5" /></td>';
4718: }
4719: $datatable .= '</tr></table></tr>';
4720: $rownum ++;
4721: $css_class = $rownum%2?' class="LC_odd_row"':'';
4722: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4723: $titles->{'errorexcluded'}.'</td>'.
4724: '<td class="LC_left_item"><table>';
4725: my $numinrow = 4;
4726: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4727: for (my $i=0; $i<@ids; $i++) {
4728: my $rem = $i%($numinrow);
4729: if ($rem == 0) {
4730: if ($i > 0) {
4731: $datatable .= '</tr>';
4732: }
4733: $datatable .= '<tr>';
4734: }
4735: my $check;
4736: if ($excluded{$ids[$i]}) {
4737: $check = ' checked="checked" ';
4738: }
4739: $datatable .= '<td class="LC_left_item">'.
4740: '<span class="LC_nobreak"><label>'.
4741: '<input type="checkbox" name="errorexcluded" '.
4742: 'value="'.$ids[$i].'"'.$check.' />'.
4743: $ids[$i].'</label></span></td>';
4744: }
4745: my $colsleft = $numinrow - @ids%($numinrow);
4746: if ($colsleft > 1 ) {
4747: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4748: ' </td>';
4749: } elsif ($colsleft == 1) {
4750: $datatable .= '<td class="LC_left_item"> </td>';
4751: }
4752: $datatable .= '</tr></table></td></tr>';
4753: $rownum ++;
1.286 raeburn 4754: } elsif ($position eq 'bottom') {
1.315 raeburn 4755: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4756: my (@posstypes,%usertypeshash);
4757: if (ref($types) eq 'ARRAY') {
4758: @posstypes = @{$types};
4759: }
4760: if (@posstypes) {
4761: if (ref($usertypes) eq 'HASH') {
4762: %usertypeshash = %{$usertypes};
4763: }
4764: my @overridden;
4765: my $numinrow = 4;
4766: if (ref($settings) eq 'HASH') {
4767: if (ref($settings->{'overrides'}) eq 'HASH') {
4768: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4769: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4770: push(@overridden,$key);
4771: foreach my $item (@contacts) {
4772: if ($settings->{'overrides'}{$key}{$item}) {
4773: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4774: }
4775: }
4776: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4777: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4778: $includeloc{'override_'.$key} = '';
4779: $includestr{'override_'.$key} = '';
4780: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4781: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4782: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4783: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4784: }
1.286 raeburn 4785: }
4786: }
4787: }
1.315 raeburn 4788: }
4789: my $customclass = 'LC_helpdesk_override';
4790: my $optionsprefix = 'LC_options_helpdesk_';
4791:
4792: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4793:
4794: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4795: $numinrow,$othertitle,'overrides',
4796: \$rownum,$onclicktypes,$customclass);
4797: $rownum ++;
4798: $usertypeshash{'default'} = $othertitle;
4799: foreach my $status (@posstypes) {
4800: my $css_class;
4801: if ($rownum%2) {
4802: $css_class = 'LC_odd_row ';
4803: }
4804: $css_class .= $customclass;
4805: my $rowid = $optionsprefix.$status;
4806: my $hidden = 1;
4807: my $currstyle = 'display:none';
4808: if (grep(/^\Q$status\E$/,@overridden)) {
4809: $currstyle = 'display:table-row';
4810: $hidden = 0;
4811: }
4812: my $key = 'override_'.$status;
4813: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4814: $includeloc{$key},$includestr{$key},$status,$rowid,
4815: $usertypeshash{$status},$css_class,$currstyle,
4816: \@contacts,$short_titles);
4817: unless ($hidden) {
4818: $rownum ++;
1.286 raeburn 4819: }
4820: }
1.134 raeburn 4821: }
1.28 raeburn 4822: }
1.30 raeburn 4823: $$rowtotal += $rownum;
1.28 raeburn 4824: return $datatable;
4825: }
4826:
1.340 raeburn 4827: sub core_link_msu {
4828: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4829: &mt('LON-CAPA core group - MSU'),600,500);
4830: }
4831:
1.315 raeburn 4832: sub overridden_helpdesk {
4833: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4834: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4835: my $class = 'LC_left_item';
4836: if ($css_class) {
4837: $css_class = ' class="'.$css_class.'"';
4838: }
4839: if ($rowid) {
4840: $rowid = ' id="'.$rowid.'"';
4841: }
4842: if ($rowstyle) {
4843: $rowstyle = ' style="'.$rowstyle.'"';
4844: }
4845: my ($output,$description);
4846: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4847: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4848: "<td>$description</td>\n".
4849: '<td class="'.$class.'" colspan="2">'.
4850: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4851: '<span class="LC_nobreak">';
4852: if (ref($contacts) eq 'ARRAY') {
4853: foreach my $item (@{$contacts}) {
4854: my $check;
4855: if (ref($checked) eq 'HASH') {
4856: $check = $checked->{$item};
4857: }
4858: my $title;
4859: if (ref($short_titles) eq 'HASH') {
4860: $title = $short_titles->{$item};
4861: }
4862: $output .= '<label>'.
4863: '<input type="checkbox" name="override_'.$type.'"'.$check.
4864: ' value="'.$item.'" />'.$title.'</label> ';
4865: }
4866: }
4867: $output .= '</span><br />'.&mt('Others').': '.
4868: '<input type="text" name="override_'.$type.'_others" '.
4869: 'value="'.$otheremails.'" />';
4870: my %locchecked;
4871: foreach my $loc ('s','b') {
4872: if ($includeloc eq $loc) {
4873: $locchecked{$loc} = ' checked="checked"';
4874: last;
4875: }
4876: }
4877: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4878: '<input type="text" name="override_'.$type.'_bcc" '.
4879: 'value="'.$bccemails.'" /></fieldset>'.
4880: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4881: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4882: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4883: '<span class="LC_nobreak">'.&mt('Location:').' '.
4884: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4885: (' 'x2).
4886: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4887: '</span></fieldset>'.
4888: '</td></tr>'."\n";
4889: return $output;
4890: }
4891:
1.286 raeburn 4892: sub contacts_javascript {
4893: return <<"ENDSCRIPT";
4894:
4895: <script type="text/javascript">
4896: // <![CDATA[
4897:
4898: function screenshotSize(field) {
4899: if (document.getElementById('help_screenshotsize')) {
4900: if (field.value == 'no') {
1.289 raeburn 4901: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4902: } else {
4903: document.getElementById('help_screenshotsize').style.display="";
4904: }
4905: }
4906: return;
4907: }
4908:
1.315 raeburn 4909: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4910: if (form.elements[checkbox].length != undefined) {
4911: var count = 0;
4912: if (docount) {
4913: for (var i=0; i<form.elements[checkbox].length; i++) {
4914: if (form.elements[checkbox][i].checked) {
4915: count ++;
4916: }
4917: }
4918: }
4919: for (var i=0; i<form.elements[checkbox].length; i++) {
4920: var type = form.elements[checkbox][i].value;
4921: if (document.getElementById(prefix+type)) {
4922: if (form.elements[checkbox][i].checked) {
4923: document.getElementById(prefix+type).style.display = 'table-row';
4924: if (count % 2 == 1) {
4925: document.getElementById(prefix+type).className = target+' LC_odd_row';
4926: } else {
4927: document.getElementById(prefix+type).className = target;
4928: }
4929: count ++;
4930: } else {
4931: document.getElementById(prefix+type).style.display = 'none';
4932: }
4933: }
4934: }
4935: }
4936: return;
4937: }
4938:
4939:
1.286 raeburn 4940: // ]]>
4941: </script>
4942:
4943: ENDSCRIPT
4944: }
4945:
1.118 jms 4946: sub print_helpsettings {
1.282 raeburn 4947: my ($position,$dom,$settings,$rowtotal) = @_;
4948: my $confname = $dom.'-domainconfig';
1.285 raeburn 4949: my $formname = 'display';
1.168 raeburn 4950: my ($datatable,$itemcount);
1.282 raeburn 4951: if ($position eq 'top') {
4952: $itemcount = 1;
4953: my (%choices,%defaultchecked,@toggles);
4954: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4955: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4956: &mt('LON-CAPA bug tracker'),600,500));
4957: %defaultchecked = ('submitbugs' => 'on');
4958: @toggles = ('submitbugs');
4959: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4960: \%choices,$itemcount);
4961: $$rowtotal ++;
4962: } else {
4963: my $css_class;
4964: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4965: my (%customroles,%ordered,%current);
1.301 raeburn 4966: if (ref($settings) eq 'HASH') {
4967: if (ref($settings->{'adhoc'}) eq 'HASH') {
4968: %current = %{$settings->{'adhoc'}};
4969: }
1.285 raeburn 4970: }
4971: my $count = 0;
4972: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4973: if ($key=~/^rolesdef\_(\w+)$/) {
4974: my $rolename = $1;
1.285 raeburn 4975: my (%privs,$order);
1.282 raeburn 4976: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4977: $customroles{$rolename} = \%privs;
1.285 raeburn 4978: if (ref($current{$rolename}) eq 'HASH') {
4979: $order = $current{$rolename}{'order'};
4980: }
4981: if ($order eq '') {
4982: $order = $count;
4983: }
4984: $ordered{$order} = $rolename;
4985: $count++;
4986: }
4987: }
4988: my $maxnum = scalar(keys(%ordered));
4989: my @roles_by_num = ();
4990: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4991: push(@roles_by_num,$item);
4992: }
4993: my $context = 'domprefs';
4994: my $crstype = 'Course';
4995: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4996: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4997: my ($numstatustypes,@jsarray);
4998: if (ref($types) eq 'ARRAY') {
4999: if (@{$types} > 0) {
5000: $numstatustypes = scalar(@{$types});
5001: push(@accesstypes,'status');
5002: @jsarray = ('bystatus');
1.282 raeburn 5003: }
5004: }
1.290 raeburn 5005: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 5006: if (keys(%domhelpdesk)) {
5007: push(@accesstypes,('inc','exc'));
5008: push(@jsarray,('notinc','notexc'));
5009: }
5010: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 5011: my $context = 'domprefs';
5012: my $crstype = 'Course';
1.285 raeburn 5013: my $prefix = 'helproles_';
5014: my $add_class = 'LC_hidden';
5015: foreach my $num (@roles_by_num) {
5016: my $role = $ordered{$num};
5017: my ($desc,$access,@statuses);
5018: if (ref($current{$role}) eq 'HASH') {
5019: $desc = $current{$role}{'desc'};
5020: $access = $current{$role}{'access'};
5021: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
5022: @statuses = @{$current{$role}{'insttypes'}};
5023: }
5024: }
5025: if ($desc eq '') {
5026: $desc = $role;
5027: }
5028: my $identifier = 'custhelp'.$num;
1.282 raeburn 5029: my %full=();
5030: my %levels= (
5031: course => {},
5032: domain => {},
5033: system => {},
5034: );
5035: my %levelscurrent=(
5036: course => {},
5037: domain => {},
5038: system => {},
5039: );
5040: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5041: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5042: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5043: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5044: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5045: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5046: for (my $k=0; $k<=$maxnum; $k++) {
5047: my $vpos = $k+1;
5048: my $selstr;
5049: if ($k == $num) {
5050: $selstr = ' selected="selected" ';
5051: }
5052: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5053: }
5054: $datatable .= '</select>'.(' 'x2).
5055: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5056: '</td>'.
5057: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5058: &mt('Name shown to users:').
5059: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5060: '</fieldset>'.
5061: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5062: $othertitle,$usertypes,$types,\%domhelpdesk).
5063: '<fieldset>'.
5064: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5065: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5066: \%levelscurrent,$identifier,
5067: 'LC_hidden',$prefix.$num.'_privs').
5068: '</fieldset></td>';
1.282 raeburn 5069: $itemcount ++;
5070: }
5071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5072: my $newcust = 'custhelp'.$count;
5073: my (%privs,%levelscurrent);
5074: my %full=();
5075: my %levels= (
5076: course => {},
5077: domain => {},
5078: system => {},
5079: );
5080: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5081: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5082: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5083: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5084: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5085: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5086: for (my $k=0; $k<$maxnum+1; $k++) {
5087: my $vpos = $k+1;
5088: my $selstr;
5089: if ($k == $maxnum) {
5090: $selstr = ' selected="selected" ';
5091: }
5092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5093: }
5094: $datatable .= '</select> '."\n".
1.282 raeburn 5095: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5096: '</label></span></td>'.
1.285 raeburn 5097: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5098: '<span class="LC_nobreak">'.
5099: &mt('Internal name:').
5100: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5101: '</span>'.(' 'x4).
5102: '<span class="LC_nobreak">'.
5103: &mt('Name shown to users:').
5104: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5105: '</span></fieldset>'.
5106: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5107: $usertypes,$types,\%domhelpdesk).
5108: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5109: &Apache::lonuserutils::custom_role_header($context,$crstype,
5110: \@templateroles,$newcust).
5111: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5112: \%levelscurrent,$newcust).
1.334 raeburn 5113: '</fieldset>'.
5114: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5115: '</td></tr>';
1.282 raeburn 5116: $count ++;
5117: $$rowtotal += $count;
5118: }
1.166 raeburn 5119: return $datatable;
1.121 raeburn 5120: }
5121:
1.285 raeburn 5122: sub adhocbutton {
5123: my ($prefix,$num,$field,$visibility) = @_;
5124: my %lt = &Apache::lonlocal::texthash(
5125: show => 'Show details',
5126: hide => 'Hide details',
5127: );
5128: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5129: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5130: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5131: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5132: }
5133:
5134: sub helpsettings_javascript {
5135: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5136: return unless(ref($roles_by_num) eq 'ARRAY');
5137: my %html_js_lt = &Apache::lonlocal::texthash(
5138: show => 'Show details',
5139: hide => 'Hide details',
5140: );
5141: &html_escape(\%html_js_lt);
5142: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5143: return <<"ENDSCRIPT";
5144: <script type="text/javascript">
5145: // <![CDATA[
5146:
5147: function reorderHelpRoles(form,item) {
5148: var changedVal;
5149: $jstext
5150: var newpos = 'helproles_${total}_pos';
5151: var maxh = 1 + $total;
5152: var current = new Array();
5153: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5154: if (item == newpos) {
5155: changedVal = newitemVal;
5156: } else {
5157: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5158: current[newitemVal] = newpos;
5159: }
5160: for (var i=0; i<helproles.length; i++) {
5161: var elementName = 'helproles_'+helproles[i]+'_pos';
5162: if (elementName != item) {
5163: if (form.elements[elementName]) {
5164: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5165: current[currVal] = elementName;
5166: }
5167: }
5168: }
5169: var oldVal;
5170: for (var j=0; j<maxh; j++) {
5171: if (current[j] == undefined) {
5172: oldVal = j;
5173: }
5174: }
5175: if (oldVal < changedVal) {
5176: for (var k=oldVal+1; k<=changedVal ; k++) {
5177: var elementName = current[k];
5178: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5179: }
5180: } else {
5181: for (var k=changedVal; k<oldVal; k++) {
5182: var elementName = current[k];
5183: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5184: }
5185: }
5186: return;
5187: }
5188:
5189: function helpdeskAccess(num) {
5190: var curraccess = null;
5191: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5192: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5193: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5194: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5195: }
5196: }
5197: }
5198: var shown = Array();
5199: var hidden = Array();
5200: if (curraccess == 'none') {
5201: hidden = Array('$hiddenstr');
5202: } else {
5203: if (curraccess == 'status') {
5204: shown = Array('bystatus');
5205: hidden = Array('notinc','notexc');
5206: } else {
5207: if (curraccess == 'exc') {
5208: shown = Array('notexc');
5209: hidden = Array('notinc','bystatus');
5210: }
5211: if (curraccess == 'inc') {
5212: shown = Array('notinc');
5213: hidden = Array('notexc','bystatus');
5214: }
1.293 raeburn 5215: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5216: hidden = Array('notinc','notexc','bystatus');
5217: }
5218: }
5219: }
5220: if (hidden.length > 0) {
5221: for (var i=0; i<hidden.length; i++) {
5222: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5223: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5224: }
5225: }
5226: }
5227: if (shown.length > 0) {
5228: for (var i=0; i<shown.length; i++) {
5229: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5230: if (shown[i] == 'privs') {
5231: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5232: } else {
5233: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5234: }
5235: }
5236: }
5237: }
5238: return;
5239: }
5240:
5241: function toggleHelpdeskItem(num,field) {
5242: if (document.getElementById('helproles_'+num+'_'+field)) {
5243: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5244: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5245: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5246: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5247: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5248: }
5249: } else {
5250: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5251: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5252: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5253: }
5254: }
5255: }
5256: return;
5257: }
5258:
5259: // ]]>
5260: </script>
5261:
5262: ENDSCRIPT
5263: }
5264:
5265: sub helpdeskroles_access {
5266: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5267: $usertypes,$types,$domhelpdesk) = @_;
5268: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5269: my %lt = &Apache::lonlocal::texthash(
5270: 'rou' => 'Role usage',
5271: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5272: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5273: 'dh' => 'All with domain helpdesk role',
5274: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5275: 'none' => 'None',
5276: 'status' => 'Determined based on institutional status',
5277: 'inc' => 'Include all, but exclude specific personnel',
5278: 'exc' => 'Exclude all, but include specific personnel',
5279: );
5280: my %usecheck = (
5281: all => ' checked="checked"',
5282: );
5283: my %displaydiv = (
5284: status => 'none',
5285: inc => 'none',
5286: exc => 'none',
5287: priv => 'block',
5288: );
5289: my $output;
5290: if (ref($current) eq 'HASH') {
5291: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5292: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5293: $usecheck{$current->{access}} = $usecheck{'all'};
5294: delete($usecheck{'all'});
5295: if ($current->{access} =~ /^(status|inc|exc)$/) {
5296: my $access = $1;
5297: $displaydiv{$access} = 'inline';
5298: } elsif ($current->{access} eq 'none') {
5299: $displaydiv{'priv'} = 'none';
5300: }
5301: }
5302: }
5303: }
5304: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5305: '<p>'.$lt{'whi'}.'</p>';
5306: foreach my $access (@{$accesstypes}) {
5307: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5308: ' onclick="helpdeskAccess('."'$num'".');" />'.
5309: $lt{$access}.'</label>';
5310: if ($access eq 'status') {
5311: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5312: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5313: $othertitle,$usertypes,$types).
5314: '</div>';
5315: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5316: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5317: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5318: '</div>';
5319: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5320: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5321: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5322: '</div>';
5323: }
5324: $output .= '</p>';
5325: }
5326: $output .= '</fieldset>';
5327: return $output;
5328: }
5329:
1.121 raeburn 5330: sub radiobutton_prefs {
1.192 raeburn 5331: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5332: $additional,$align,$firstval) = @_;
1.121 raeburn 5333: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5334: (ref($choices) eq 'HASH'));
5335:
1.170 raeburn 5336: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5337:
5338: foreach my $item (@{$toggles}) {
5339: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5340: $checkedon{$item} = ' checked="checked" ';
5341: $checkedoff{$item} = ' ';
1.121 raeburn 5342: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5343: $checkedoff{$item} = ' checked="checked" ';
5344: $checkedon{$item} = ' ';
5345: }
5346: }
5347: if (ref($settings) eq 'HASH') {
1.121 raeburn 5348: foreach my $item (@{$toggles}) {
1.118 jms 5349: if ($settings->{$item} eq '1') {
5350: $checkedon{$item} = ' checked="checked" ';
5351: $checkedoff{$item} = ' ';
5352: } elsif ($settings->{$item} eq '0') {
5353: $checkedoff{$item} = ' checked="checked" ';
5354: $checkedon{$item} = ' ';
5355: }
5356: }
1.121 raeburn 5357: }
1.192 raeburn 5358: if ($onclick) {
5359: $onclick = ' onclick="'.$onclick.'"';
5360: }
1.121 raeburn 5361: foreach my $item (@{$toggles}) {
1.118 jms 5362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5363: $datatable .=
1.306 raeburn 5364: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5365: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5366: '</span></td>';
5367: if ($align eq 'left') {
5368: $datatable .= '<td class="LC_left_item">';
5369: } else {
5370: $datatable .= '<td class="LC_right_item">';
5371: }
1.385 raeburn 5372: $datatable .= '<span class="LC_nobreak">';
5373: if ($firstval eq 'no') {
5374: $datatable .=
5375: '<label><input type="radio" name="'.
5376: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5377: '</label> <label><input type="radio" name="'.$item.'" '.
5378: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5379: } else {
5380: $datatable .=
5381: '<label><input type="radio" name="'.
5382: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5383: '</label> <label><input type="radio" name="'.$item.'" '.
5384: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5385: }
5386: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5387: $itemcount ++;
1.121 raeburn 5388: }
5389: return ($datatable,$itemcount);
5390: }
5391:
1.267 raeburn 5392: sub print_ltitools {
5393: my ($dom,$settings,$rowtotal) = @_;
5394: my $rownum = 0;
5395: my $css_class;
5396: my $itemcount = 1;
5397: my $maxnum = 0;
5398: my %ordered;
5399: if (ref($settings) eq 'HASH') {
5400: foreach my $item (keys(%{$settings})) {
5401: if (ref($settings->{$item}) eq 'HASH') {
5402: my $num = $settings->{$item}{'order'};
5403: $ordered{$num} = $item;
5404: }
5405: }
5406: }
5407: my $confname = $dom.'-domainconfig';
5408: my $switchserver = &check_switchserver($dom,$confname);
5409: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5410: my $datatable;
1.267 raeburn 5411: my %lt = <itools_names();
5412: my @courseroles = ('cc','in','ta','ep','st');
5413: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 5414: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 5415: if (keys(%ordered)) {
5416: my @items = sort { $a <=> $b } keys(%ordered);
5417: for (my $i=0; $i<@items; $i++) {
5418: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5419: my $item = $ordered{$items[$i]};
1.323 raeburn 5420: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 5421: if (ref($settings->{$item}) eq 'HASH') {
5422: $title = $settings->{$item}->{'title'};
5423: $url = $settings->{$item}->{'url'};
5424: $key = $settings->{$item}->{'key'};
5425: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 5426: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 5427: my $image = $settings->{$item}->{'image'};
5428: if ($image ne '') {
5429: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
5430: }
1.323 raeburn 5431: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
5432: $sigsel{'HMAC-256'} = ' selected="selected"';
5433: } else {
5434: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
5435: }
1.267 raeburn 5436: }
1.319 raeburn 5437: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 5438: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5439: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
5440: for (my $k=0; $k<=$maxnum; $k++) {
5441: my $vpos = $k+1;
5442: my $selstr;
5443: if ($k == $i) {
5444: $selstr = ' selected="selected" ';
5445: }
5446: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5447: }
5448: $datatable .= '</select>'.(' 'x2).
5449: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
5450: &mt('Delete?').'</label></span></td>'.
5451: '<td colspan="2">'.
5452: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5453: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 5454: (' 'x2).
5455: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
5456: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5457: (' 'x2).
5458: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
5459: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5460: (' 'x2).
5461: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
5462: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
5463: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 5464: '<br /><br />'.
1.323 raeburn 5465: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 5466: ' value="'.$url.'" /></span>'.
5467: (' 'x2).
1.319 raeburn 5468: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 5469: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
5470: (' 'x2).
1.322 raeburn 5471: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
5472: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
5473: (' 'x2).
1.267 raeburn 5474: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5475: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
5476: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5477: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
5478: '</fieldset>'.
5479: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5480: '<span class="LC_nobreak">'.&mt('Display target:');
5481: my %currdisp;
5482: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
5483: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
5484: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 5485: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
5486: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 5487: } else {
5488: $currdisp{'iframe'} = ' checked="checked"';
5489: }
5490: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
5491: $currdisp{'width'} = $1;
5492: }
5493: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
5494: $currdisp{'height'} = $1;
5495: }
1.296 raeburn 5496: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
5497: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 5498: } else {
5499: $currdisp{'iframe'} = ' checked="checked"';
5500: }
1.298 raeburn 5501: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5502: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
5503: $lt{$disp}.'</label>'.(' 'x2);
5504: }
5505: $datatable .= (' 'x4);
5506: foreach my $dimen ('width','height') {
5507: $datatable .= '<label>'.$lt{$dimen}.' '.
5508: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
5509: (' 'x2);
5510: }
1.334 raeburn 5511: $datatable .= '</span><br />'.
1.296 raeburn 5512: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5513: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 5514: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5515: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5516: '</textarea></div><div style=""></div><br />';
1.319 raeburn 5517: my %units = (
5518: 'passback' => 'days',
5519: 'roster' => 'seconds',
5520: );
1.267 raeburn 5521: foreach my $extra ('passback','roster') {
1.319 raeburn 5522: my $validsty = 'none';
5523: my $currvalid;
1.267 raeburn 5524: my $checkedon = '';
5525: my $checkedoff = ' checked="checked"';
5526: if ($settings->{$item}->{$extra}) {
5527: $checkedon = $checkedoff;
5528: $checkedoff = '';
1.319 raeburn 5529: $validsty = 'inline-block';
5530: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
5531: $currvalid = $settings->{$item}->{$extra.'valid'};
5532: }
5533: }
5534: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
5535: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5536: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
5537: &mt('No').'</label>'.(' 'x2).
5538: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
5539: &mt('Yes').'</label></span></div>'.
5540: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
5541: '<span class="LC_nobreak">'.
5542: &mt("at least [_1] $units{$extra} after launch",
5543: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
5544: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5545: }
1.319 raeburn 5546: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 5547: if ($imgsrc) {
5548: $datatable .= $imgsrc.
5549: '<label><input type="checkbox" name="ltitools_image_del"'.
5550: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5551: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5552: } else {
5553: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5554: }
5555: if ($switchserver) {
5556: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5557: } else {
5558: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5559: }
5560: $datatable .= '</span></fieldset>';
1.324 raeburn 5561: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5562: if (ref($settings->{$item}) eq 'HASH') {
5563: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5564: %checkedfields = %{$settings->{$item}->{'fields'}};
5565: }
1.324 raeburn 5566: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5567: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5568: %rolemaps = %{$settings->{$item}->{'roles'}};
5569: $checkedfields{'roles'} = 1;
5570: }
5571: }
5572: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5573: '<span class="LC_nobreak">';
1.324 raeburn 5574: my $userfieldstyle = 'display:none;';
5575: my $seluserdom = '';
5576: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5577: foreach my $field (@fields) {
1.324 raeburn 5578: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5579: if ($checkedfields{$field}) {
5580: $checked = ' checked="checked"';
5581: }
1.324 raeburn 5582: if ($field eq 'user') {
5583: $id = ' id="ltitools_user_field_'.$i.'"';
5584: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5585: if ($checked) {
5586: $userfieldstyle = 'display:inline-block';
5587: if ($userincdom) {
5588: $seluserdom = $unseluserdom;
5589: $unseluserdom = '';
5590: }
5591: }
5592: } else {
5593: $spacer = (' ' x2);
5594: }
1.267 raeburn 5595: $datatable .= '<label>'.
1.324 raeburn 5596: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5597: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5598: }
1.324 raeburn 5599: $datatable .= '</span>';
5600: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5601: '<span class="LC_nobreak"> : '.
5602: '<select name="ltitools_userincdom_'.$i.'">'.
5603: '<option value="">'.&mt('Select').'</option>'.
5604: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5605: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5606: '</select></span></div>';
5607: $datatable .= '</fieldset>'.
1.267 raeburn 5608: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5609: foreach my $role (@courseroles) {
5610: my ($selected,$selectnone);
5611: if (!$rolemaps{$role}) {
5612: $selectnone = ' selected="selected"';
5613: }
1.306 raeburn 5614: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5615: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5616: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5617: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5618: foreach my $ltirole (@ltiroles) {
5619: unless ($selectnone) {
5620: if ($rolemaps{$role} eq $ltirole) {
5621: $selected = ' selected="selected"';
5622: } else {
5623: $selected = '';
5624: }
5625: }
5626: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5627: }
5628: $datatable .= '</select></td>';
5629: }
1.273 raeburn 5630: $datatable .= '</tr></table></fieldset>';
5631: my %courseconfig;
5632: if (ref($settings->{$item}) eq 'HASH') {
5633: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5634: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5635: }
5636: }
5637: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5638: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5639: my $checked;
5640: if ($courseconfig{$item}) {
5641: $checked = ' checked="checked"';
5642: }
5643: $datatable .= '<label>'.
5644: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5645: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5646: }
5647: $datatable .= '</span></fieldset>'.
1.267 raeburn 5648: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5649: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5650: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5651: my %custom = %{$settings->{$item}->{'custom'}};
5652: if (keys(%custom) > 0) {
5653: foreach my $key (sort(keys(%custom))) {
5654: $datatable .= '<tr><td><span class="LC_nobreak">'.
5655: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5656: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5657: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5658: ' value="'.$custom{$key}.'" /></td></tr>';
5659: }
5660: }
5661: }
5662: $datatable .= '<tr><td><span class="LC_nobreak">'.
5663: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5664: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5665: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5666: $datatable .= '</table></fieldset></td></tr>'."\n";
5667: $itemcount ++;
5668: }
5669: }
5670: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5671: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5672: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5673: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5674: '<select name="ltitools_add_pos"'.$chgstr.'>';
5675: for (my $k=0; $k<$maxnum+1; $k++) {
5676: my $vpos = $k+1;
5677: my $selstr;
5678: if ($k == $maxnum) {
5679: $selstr = ' selected="selected" ';
5680: }
5681: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5682: }
5683: $datatable .= '</select> '."\n".
1.334 raeburn 5684: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5685: '<td colspan="2">'.
5686: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5687: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5688: (' 'x2).
5689: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5690: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5691: (' 'x2).
5692: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5693: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5694: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5695: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5696: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5697: '<br />'.
1.323 raeburn 5698: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5699: (' 'x2).
5700: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5701: (' 'x2).
1.322 raeburn 5702: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5703: (' 'x2).
1.267 raeburn 5704: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5705: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
5706: '</fieldset>'.
5707: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5708: '<span class="LC_nobreak">'.&mt('Display target:');
5709: my %defaultdisp;
5710: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5711: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5712: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5713: $lt{$disp}.'</label>'.(' 'x2);
5714: }
5715: $datatable .= (' 'x4);
5716: foreach my $dimen ('width','height') {
5717: $datatable .= '<label>'.$lt{$dimen}.' '.
5718: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5719: (' 'x2);
5720: }
1.334 raeburn 5721: $datatable .= '</span><br />'.
1.296 raeburn 5722: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5723: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5724: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5725: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5726: '</div><div style=""></div><br />';
1.319 raeburn 5727: my %units = (
5728: 'passback' => 'days',
5729: 'roster' => 'seconds',
5730: );
5731: my %defaulttimes = (
5732: 'passback' => '7',
1.322 raeburn 5733: 'roster' => '300',
1.319 raeburn 5734: );
1.267 raeburn 5735: foreach my $extra ('passback','roster') {
1.319 raeburn 5736: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5737: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5738: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5739: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5740: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5741: &mt('Yes').'</label></span></div>'.
5742: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5743: '<span class="LC_nobreak">'.
5744: &mt("at least [_1] $units{$extra} after launch",
5745: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5746: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5747: }
1.319 raeburn 5748: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5749: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5750: if ($switchserver) {
5751: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5752: } else {
5753: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5754: }
5755: $datatable .= '</span></fieldset>'.
5756: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5757: '<span class="LC_nobreak">';
5758: foreach my $field (@fields) {
1.324 raeburn 5759: my ($id,$onclick,$spacer);
5760: if ($field eq 'user') {
5761: $id = ' id="ltitools_user_field_add"';
5762: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5763: } else {
5764: $spacer = (' ' x2);
5765: }
1.267 raeburn 5766: $datatable .= '<label>'.
1.324 raeburn 5767: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5768: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5769: }
1.324 raeburn 5770: $datatable .= '</span>'.
5771: '<div style="display:none;" id="ltitools_user_div_add">'.
5772: '<span class="LC_nobreak"> : '.
5773: '<select name="ltitools_userincdom_add">'.
5774: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5775: '<option value="0">'.&mt('username').'</option>'.
5776: '<option value="1">'.&mt('username:domain').'</option>'.
5777: '</select></span></div></fieldset>';
5778: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5779: foreach my $role (@courseroles) {
5780: my ($checked,$checkednone);
1.306 raeburn 5781: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5782: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5783: '<select name="ltitools_add_roles_'.$role.'">'.
5784: '<option value="" selected="selected">'.&mt('Select').'</option>';
5785: foreach my $ltirole (@ltiroles) {
5786: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5787: }
5788: $datatable .= '</select></td>';
5789: }
5790: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5791: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5792: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5793: $datatable .= '<label>'.
5794: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5795: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5796: }
5797: $datatable .= '</span></fieldset>'.
1.267 raeburn 5798: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5799: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5800: '<tr><td><span class="LC_nobreak">'.
5801: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5802: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5803: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5804: '</table></fieldset>'."\n".
1.267 raeburn 5805: '</td>'."\n".
5806: '</tr>'."\n";
5807: $itemcount ++;
5808: return $datatable;
5809: }
5810:
5811: sub ltitools_names {
5812: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5813: 'title' => 'Title',
5814: 'version' => 'Version',
5815: 'msgtype' => 'Message Type',
1.323 raeburn 5816: 'sigmethod' => 'Signature Method',
1.296 raeburn 5817: 'url' => 'URL',
5818: 'key' => 'Key',
1.322 raeburn 5819: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5820: 'secret' => 'Secret',
5821: 'icon' => 'Icon',
1.324 raeburn 5822: 'user' => 'User',
1.296 raeburn 5823: 'fullname' => 'Full Name',
5824: 'firstname' => 'First Name',
5825: 'lastname' => 'Last Name',
5826: 'email' => 'E-mail',
5827: 'roles' => 'Role',
1.298 raeburn 5828: 'window' => 'Window',
5829: 'tab' => 'Tab',
1.296 raeburn 5830: 'iframe' => 'iFrame',
5831: 'height' => 'Height',
5832: 'width' => 'Width',
5833: 'linktext' => 'Default Link Text',
5834: 'explanation' => 'Default Explanation',
5835: 'passback' => 'Tool can return grades:',
5836: 'roster' => 'Tool can retrieve roster:',
5837: 'crstarget' => 'Display target',
5838: 'crslabel' => 'Course label',
5839: 'crstitle' => 'Course title',
5840: 'crslinktext' => 'Link Text',
5841: 'crsexplanation' => 'Explanation',
1.318 raeburn 5842: 'crsappend' => 'Provider URL',
1.267 raeburn 5843: );
5844: return %lt;
5845: }
5846:
1.372 raeburn 5847: sub print_proctoring {
5848: my ($dom,$settings,$rowtotal) = @_;
5849: my $itemcount = 1;
5850: my (%ordered,%providernames,%current,%currentdef);
5851: my $confname = $dom.'-domainconfig';
5852: my $switchserver = &check_switchserver($dom,$confname);
5853: if (ref($settings) eq 'HASH') {
5854: foreach my $item (keys(%{$settings})) {
5855: if (ref($settings->{$item}) eq 'HASH') {
5856: my $num = $settings->{$item}{'order'};
5857: $ordered{$num} = $item;
5858: }
5859: }
5860: } else {
5861: %ordered = (
5862: 1 => 'proctorio',
5863: 2 => 'examity',
5864: );
5865: }
5866: %providernames = &proctoring_providernames();
5867: my $maxnum = scalar(keys(%ordered));
5868: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5869: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5870: if (ref($requref) eq 'HASH') {
5871: %requserfields = %{$requref};
5872: }
5873: if (ref($opturef) eq 'HASH') {
5874: %optuserfields = %{$opturef};
5875: }
5876: if (ref($defref) eq 'HASH') {
5877: %defaults = %{$defref};
5878: }
5879: if (ref($extref) eq 'HASH') {
5880: %extended = %{$extref};
5881: }
5882: if (ref($crsref) eq 'HASH') {
5883: %crsconf = %{$crsref};
5884: }
5885: if (ref($rolesref) eq 'ARRAY') {
5886: @courseroles = @{$rolesref};
5887: }
5888: if (ref($ltiref) eq 'ARRAY') {
5889: @ltiroles = @{$ltiref};
5890: }
5891: my $datatable;
5892: my $css_class;
5893: if (keys(%ordered)) {
5894: my @items = sort { $a <=> $b } keys(%ordered);
5895: for (my $i=0; $i<@items; $i++) {
5896: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5897: my $provider = $ordered{$items[$i]};
5898: my $optionsty = 'none';
5899: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5900: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5901: if (ref($settings) eq 'HASH') {
5902: if (ref($settings->{$provider}) eq 'HASH') {
5903: %current = %{$settings->{$provider}};
5904: if ($current{'available'}) {
5905: $optionsty = 'block';
5906: $available = 1;
5907: }
5908: if ($current{'lifetime'} =~ /^\d+$/) {
5909: $lifetime = $current{'lifetime'};
5910: }
5911: if ($current{'version'} =~ /^\d+\.\d+$/) {
5912: $version = $current{'version'};
5913: }
5914: if ($current{'image'} ne '') {
5915: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5916: }
5917: if (ref($current{'fields'}) eq 'ARRAY') {
5918: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5919: }
5920: $userincdom = $current{'incdom'};
5921: if (ref($current{'roles'}) eq 'HASH') {
5922: %rolemaps = %{$current{'roles'}};
5923: $checkedfields{'roles'} = 1;
5924: }
5925: if (ref($current{'defaults'}) eq 'ARRAY') {
5926: foreach my $val (@{$current{'defaults'}}) {
5927: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5928: $inuse{$val} = 1;
5929: } else {
5930: foreach my $poss (keys(%{$extended{$provider}})) {
5931: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5932: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5933: $inuse{$poss} = $val;
5934: last;
5935: }
5936: }
5937: }
5938: }
5939: }
5940: } elsif (ref($current{'defaults'}) eq 'HASH') {
5941: foreach my $key (keys(%{$current{'defaults'}})) {
5942: my $currval = $current{'defaults'}{$key};
5943: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5944: $inuse{$key} = 1;
5945: } else {
5946: my $match;
5947: foreach my $poss (keys(%{$extended{$provider}})) {
5948: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5949: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5950: $inuse{$poss} = $key;
5951: last;
5952: }
5953: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5954: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5955: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5956: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5957: $currentdef{$inner} = $currval;
5958: $match = 1;
5959: last;
5960: }
5961: } elsif ($inner eq $key) {
5962: $currentdef{$key} = $currval;
5963: $match = 1;
5964: last;
5965: }
5966: }
5967: }
5968: last if ($match);
5969: }
5970: }
5971: }
5972: }
5973: if (ref($current{'crsconf'}) eq 'ARRAY') {
5974: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5975: }
5976: }
5977: }
5978: my %lt = &proctoring_titles($provider);
5979: my %fieldtitles = &proctoring_fieldtitles($provider);
5980: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5981: my %checkedavailable = (
5982: yes => '',
5983: no => ' checked="checked"',
5984: );
5985: if ($available) {
5986: $checkedavailable{'yes'} = $checkedavailable{'no'};
5987: $checkedavailable{'no'} = '';
5988: }
5989: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5990: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5991: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5992: for (my $k=0; $k<$maxnum; $k++) {
5993: my $vpos = $k+1;
5994: my $selstr;
5995: if ($k == $i) {
5996: $selstr = ' selected="selected" ';
5997: }
5998: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5999: }
6000: if ($version eq '') {
6001: if ($provider eq 'proctorio') {
6002: $version = '1.0';
6003: } elsif ($provider eq 'examity') {
6004: $version = '1.1';
6005: }
6006: }
6007: if ($lifetime eq '') {
6008: $lifetime = '300';
6009: }
6010: $datatable .=
6011: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
6012: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
6013: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
6014: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
6015: '</td>'.
6016: '<td colspan="2">'.
6017: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
6018: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
6019: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
6020: (' 'x2).
6021: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
6022: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6023: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6024: (' 'x2).
6025: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
6026: '<br />'.
6027: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
6028: '<br />'.
6029: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
6030: (' 'x2).
6031: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
6032: '<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";
6033: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6034: if ($imgsrc) {
6035: $datatable .= $imgsrc.
6036: '<label><input type="checkbox" name="proctoring_image_del"'.
6037: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
6038: '<span class="LC_nobreak"> '.&mt('Replace:');
6039: }
6040: $datatable .= ' ';
6041: if ($switchserver) {
6042: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6043: } else {
6044: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
6045: }
6046: unless ($imgsrc) {
6047: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
6048: }
6049: $datatable .= '</fieldset>'."\n";
6050: if (ref($requserfields{$provider}) eq 'ARRAY') {
6051: if (@{$requserfields{$provider}} > 0) {
6052: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
6053: foreach my $field (@{$requserfields{$provider}}) {
6054: $datatable .= '<span class="LC_nobreak">'.
6055: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
6056: $lt{$field}.'</label>';
6057: if ($field eq 'user') {
6058: my $seluserdom = '';
6059: my $unseluserdom = ' selected="selected"';
6060: if ($userincdom) {
6061: $seluserdom = $unseluserdom;
6062: $unseluserdom = '';
6063: }
6064: $datatable .= ': '.
6065: '<select name="proctoring_userincdom_'.$provider.'">'.
6066: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
6067: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
6068: '</select> ';
6069: } else {
6070: $datatable .= ' ';
6071: if ($field eq 'roles') {
6072: $showroles = 1;
6073: }
6074: }
6075: $datatable .= '</span> ';
6076: }
6077: }
6078: $datatable .= '</fieldset>'."\n";
6079: }
6080: if (ref($optuserfields{$provider}) eq 'ARRAY') {
6081: if (@{$optuserfields{$provider}} > 0) {
6082: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
6083: foreach my $field (@{$optuserfields{$provider}}) {
6084: my $checked;
6085: if ($checkedfields{$field}) {
6086: $checked = ' checked="checked"';
6087: }
6088: $datatable .= '<span class="LC_nobreak">'.
6089: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
6090: }
6091: $datatable .= '</fieldset>'."\n";
6092: }
6093: }
6094: if (ref($defaults{$provider}) eq 'ARRAY') {
6095: if (@{$defaults{$provider}}) {
6096: my (%options,@selectboxes);
6097: if (ref($extended{$provider}) eq 'HASH') {
6098: %options = %{$extended{$provider}};
6099: }
6100: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
6101: my ($rem,$numinrow,$dropdowns);
6102: if ($provider eq 'proctorio') {
6103: $datatable .= '<table>';
6104: $numinrow = 4;
6105: }
6106: my $i = 0;
6107: foreach my $field (@{$defaults{$provider}}) {
6108: my $checked;
6109: if ($inuse{$field}) {
6110: $checked = ' checked="checked"';
6111: }
6112: if ($provider eq 'examity') {
6113: if ($field eq 'display') {
6114: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
6115: foreach my $option ('iframe','tab','window') {
6116: my $checkdisp;
6117: if ($currentdef{'target'} eq $option) {
6118: $checkdisp = ' checked="checked"';
6119: }
6120: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
6121: $fieldtitles{$option}.'</label>'.(' 'x2);
6122: }
6123: $datatable .= (' 'x4);
6124: foreach my $dimen ('width','height') {
6125: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
6126: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
6127: 'value="'.$currentdef{$dimen}.'" /></label>'.
6128: (' 'x2);
6129: }
6130: $datatable .= '</span><br />'.
6131: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
6132: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
6133: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
6134: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
6135: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
6136: $currentdef{'explanation'}.
6137: '</textarea></div><div style=""></div><br />';
6138: }
6139: } else {
6140: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
6141: my ($output,$selnone);
6142: unless ($checked) {
6143: $selnone = ' selected="selected"';
6144: }
6145: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
6146: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
6147: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
6148: foreach my $option (@{$options{$field}}) {
6149: my $sel;
6150: if ($inuse{$field} eq $option) {
6151: $sel = ' selected="selected"';
6152: }
6153: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
6154: }
6155: $output .= '</select></span>';
6156: push(@selectboxes,$output);
6157: } else {
6158: $rem = $i%($numinrow);
6159: if ($rem == 0) {
6160: if ($i > 0) {
6161: $datatable .= '</tr>';
6162: }
6163: $datatable .= '<tr>';
6164: }
6165: $datatable .= '<td class="LC_left_item">'.
6166: '<span class="LC_nobreak">'.
6167: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
6168: $fieldtitles{$field}.'</label></span></td>';
6169: $i++;
6170: }
6171: }
6172: }
6173: if ($provider eq 'proctorio') {
6174: if ($numinrow) {
6175: $rem = $i%$numinrow;
6176: }
6177: my $colsleft = $numinrow - $rem;
6178: if ($colsleft > 1) {
6179: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6180: } else {
6181: $datatable .= '<td class="LC_left_item">';
6182: }
6183: $datatable .= ' '.
6184: '</td></tr></table>';
6185: if (@selectboxes) {
6186: $datatable .= '<hr /><table>';
6187: $numinrow = 2;
6188: for (my $i=0; $i<@selectboxes; $i++) {
6189: $rem = $i%($numinrow);
6190: if ($rem == 0) {
6191: if ($i > 0) {
6192: $datatable .= '</tr>';
6193: }
6194: $datatable .= '<tr>';
6195: }
6196: $datatable .= '<td class="LC_left_item">'.
6197: $selectboxes[$i].'</td>';
6198: }
6199: if ($numinrow) {
6200: $rem = $i%$numinrow;
6201: }
6202: $colsleft = $numinrow - $rem;
6203: if ($colsleft > 1) {
6204: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6205: } else {
6206: $datatable .= '<td class="LC_left_item">';
6207: }
6208: $datatable .= ' '.
6209: '</td></tr></table>';
6210: }
6211: }
6212: $datatable .= '</fieldset>';
6213: }
6214: if (ref($crsconf{$provider}) eq 'ARRAY') {
6215: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6216: '<legend>'.&mt('Configurable in course').'</legend>';
6217: my ($rem,$numinrow);
6218: if ($provider eq 'proctorio') {
6219: $datatable .= '<table>';
6220: $numinrow = 4;
6221: }
6222: my $i = 0;
6223: foreach my $item (@{$crsconf{$provider}}) {
6224: my $name;
6225: if ($provider eq 'examity') {
6226: $name = $lt{'crs'.$item};
6227: } elsif ($provider eq 'proctorio') {
6228: $name = $fieldtitles{$item};
6229: $rem = $i%($numinrow);
6230: if ($rem == 0) {
6231: if ($i > 0) {
6232: $datatable .= '</tr>';
6233: }
6234: $datatable .= '<tr>';
6235: }
6236: $datatable .= '<td class="LC_left_item>';
6237: }
6238: my $checked;
6239: if ($crsconfig{$item}) {
6240: $checked = ' checked="checked"';
6241: }
6242: $datatable .= '<span class="LC_nobreak"><label>'.
6243: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
6244: $name.'</label></span>';
6245: if ($provider eq 'examity') {
6246: $datatable .= ' ';
6247: }
6248: $datatable .= "\n";
6249: $i++;
6250: }
6251: if ($provider eq 'proctorio') {
6252: if ($numinrow) {
6253: $rem = $i%$numinrow;
6254: }
6255: my $colsleft = $numinrow - $rem;
6256: if ($colsleft > 1) {
6257: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6258: } else {
6259: $datatable .= '<td class="LC_left_item">';
6260: }
6261: $datatable .= ' '.
6262: '</td></tr></table>';
6263: }
6264: $datatable .= '</fieldset>';
6265: }
6266: if ($showroles) {
6267: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6268: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
6269: foreach my $role (@courseroles) {
6270: my ($selected,$selectnone);
6271: if (!$rolemaps{$role}) {
6272: $selectnone = ' selected="selected"';
6273: }
6274: $datatable .= '<td style="text-align: center">'.
6275: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6276: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
6277: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6278: foreach my $ltirole (@ltiroles) {
6279: unless ($selectnone) {
6280: if ($rolemaps{$role} eq $ltirole) {
6281: $selected = ' selected="selected"';
6282: } else {
6283: $selected = '';
6284: }
6285: }
6286: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6287: }
6288: $datatable .= '</select></td>';
6289: }
6290: $datatable .= '</tr></table></fieldset>'.
6291: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6292: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6293: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6294: '<tr><td></td><td>lms</td>'.
6295: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6296: ' value="Loncapa" disabled="disabled"/></td></tr>';
6297: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6298: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6299: my %custom = %{$settings->{$provider}->{'custom'}};
6300: if (keys(%custom) > 0) {
6301: foreach my $key (sort(keys(%custom))) {
6302: next if ($key eq 'lms');
6303: $datatable .= '<tr><td><span class="LC_nobreak">'.
6304: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6305: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6306: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6307: ' value="'.$custom{$key}.'" /></td></tr>';
6308: }
6309: }
6310: }
6311: $datatable .= '<tr><td><span class="LC_nobreak">'.
6312: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6313: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6314: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6315: '</table></fieldset></td></tr>'."\n";
6316: }
6317: $datatable .= '</td></tr>';
6318: }
6319: $itemcount ++;
6320: }
6321: }
6322: return $datatable;
6323: }
6324:
6325: sub proctoring_data {
6326: my $requserfields = {
6327: proctorio => ['user'],
6328: examity => ['roles','user'],
6329: };
6330: my $optuserfields = {
6331: proctorio => ['fullname'],
6332: examity => ['fullname','firstname','lastname','email'],
6333: };
6334: my $defaults = {
6335: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6336: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6337: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6338: 'closetabs','onescreen','print','downloads','cache','rightclick',
6339: 'reentry','calculator','whiteboard'],
6340: examity => ['display'],
6341: };
6342: my $extended = {
6343: proctorio => {
6344: verifyid => ['verifyidauto','verifyidlive'],
6345: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6346: tabslinks => ['notabs','linksonly'],
6347: reentry => ['noreentry','agentreentry'],
6348: calculator => ['calculatorbasic','calculatorsci'],
6349: },
6350: examity => {
6351: display => {
6352: target => ['iframe','tab','window'],
6353: width => '',
6354: height => '',
6355: linktext => '',
6356: explanation => '',
6357: },
6358: },
6359: };
6360: my $crsconf = {
6361: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6362: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6363: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6364: 'closetabs','onescreen','print','downloads','cache','rightclick',
6365: 'reentry','calculator','whiteboard'],
6366: examity => ['label','title','target','linktext','explanation','append'],
6367: };
6368: my $courseroles = ['cc','in','ta','ep','st'];
6369: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6370: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6371: }
6372:
6373: sub proctoring_titles {
6374: my ($item) = @_;
6375: my (%common_lt,%custom_lt);
6376: %common_lt = &Apache::lonlocal::texthash (
6377: 'avai' => 'Available?',
6378: 'base' => 'Basic Settings',
6379: 'requ' => 'User data required to be sent on launch',
6380: 'optu' => 'User data optionally sent on launch',
6381: 'udsl' => 'User data sent on launch',
6382: 'defa' => 'Defaults for items configurable in course',
6383: 'sigmethod' => 'Signature Method',
6384: 'key' => 'Key',
6385: 'lifetime' => 'Nonce lifetime (s)',
6386: 'secret' => 'Secret',
6387: 'icon' => 'Icon',
6388: 'fullname' => 'Full Name',
6389: 'visible' => 'Visible input',
6390: 'username' => 'username',
6391: 'user' => 'User',
6392: );
6393: if ($item eq 'proctorio') {
6394: %custom_lt = &Apache::lonlocal::texthash (
6395: 'version' => 'OAuth version',
6396: 'url' => 'API URL',
6397: 'uname:dom' => 'username-domain',
6398: );
6399: } elsif ($item eq 'examity') {
6400: %custom_lt = &Apache::lonlocal::texthash (
6401: 'version' => 'LTI Version',
6402: 'url' => 'URL',
6403: 'uname:dom' => 'username:domain',
6404: 'msgtype' => 'Message Type',
6405: 'firstname' => 'First Name',
6406: 'lastname' => 'Last Name',
6407: 'email' => 'E-mail',
6408: 'roles' => 'Role',
6409: 'crstarget' => 'Display target',
6410: 'crslabel' => 'Course label',
6411: 'crstitle' => 'Course title',
6412: 'crslinktext' => 'Link Text',
6413: 'crsexplanation' => 'Explanation',
6414: 'crsappend' => 'Provider URL',
6415: );
6416: }
6417: my %lt = (%common_lt,%custom_lt);
6418: return %lt;
6419: }
6420:
6421: sub proctoring_fieldtitles {
6422: my ($item) = @_;
6423: if ($item eq 'proctorio') {
6424: return &Apache::lonlocal::texthash (
6425: 'recordvideo' => 'Record video',
6426: 'recordaudio' => 'Record audio',
6427: 'recordscreen' => 'Record screen',
6428: 'recordwebtraffic' => 'Record web traffic',
6429: 'recordroomstart' => 'Record room scan',
6430: 'verifyvideo' => 'Verify webcam',
6431: 'verifyaudio' => 'Verify microphone',
6432: 'verifydesktop' => 'Verify desktop recording',
6433: 'verifyid' => 'Photo ID verification',
6434: 'verifysignature' => 'Require signature',
6435: 'fullscreen' => 'Fullscreen',
6436: 'clipboard' => 'Disable copy/paste',
6437: 'tabslinks' => 'New tabs/windows',
6438: 'closetabs' => 'Close other tabs',
6439: 'onescreen' => 'Limit to single screen',
6440: 'print' => 'Disable Printing',
6441: 'downloads' => 'Disable Downloads',
6442: 'cache' => 'Empty cache after exam',
6443: 'rightclick' => 'Disable right click',
6444: 'reentry' => 'Re-entry to exam',
6445: 'calculator' => 'Onscreen calculator',
6446: 'whiteboard' => 'Onscreen whiteboard',
6447: 'verifyidauto' => 'Automated verification',
6448: 'verifyidlive' => 'Live agent verification',
6449: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6450: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6451: 'fullscreensever' => 'Forced, navigation away ends exam',
6452: 'notabs' => 'Disaallowed',
6453: 'linksonly' => 'Allowed from links in exam',
6454: 'noreentry' => 'Disallowed',
6455: 'agentreentry' => 'Agent required for re-entry',
6456: 'calculatorbasic' => 'Basic',
6457: 'calculatorsci' => 'Scientific',
6458: );
6459: } elsif ($item eq 'examity') {
6460: return &Apache::lonlocal::texthash (
6461: 'target' => 'Display target',
6462: 'window' => 'Window',
6463: 'tab' => 'Tab',
6464: 'iframe' => 'iFrame',
6465: 'height' => 'Height (pixels)',
6466: 'width' => 'Width (pixels)',
6467: 'linktext' => 'Default Link Text',
6468: 'explanation' => 'Default Explanation',
6469: 'append' => 'Provider URL',
6470: );
6471: }
6472: }
6473:
6474: sub proctoring_providernames {
6475: return (
6476: proctorio => 'Proctorio',
6477: examity => 'Examity',
6478: );
6479: }
6480:
1.320 raeburn 6481: sub print_lti {
1.405 raeburn 6482: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6483: my $itemcount = 1;
1.405 raeburn 6484: my ($datatable,$css_class);
6485: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6486: if (ref($settings) eq 'HASH') {
1.405 raeburn 6487: if ($position eq 'top') {
6488: if (exists($settings->{'encrypt'})) {
6489: if (ref($settings->{'encrypt'}) eq 'HASH') {
6490: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6491: if ($key eq 'consumers') {
6492: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6493: } else {
6494: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6495: }
6496: }
6497: }
6498: }
6499: if (exists($settings->{'private'})) {
6500: if (ref($settings->{'private'}) eq 'HASH') {
6501: if (ref($settings->{'private'}) eq 'HASH') {
6502: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6503: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6504: }
6505: }
6506: }
6507: }
6508: } elsif ($position eq 'middle') {
6509: if (exists($settings->{'rules'})) {
6510: if (ref($settings->{'rules'}) eq 'HASH') {
6511: %rules = %{$settings->{'rules'}};
6512: }
6513: }
6514: } elsif ($position eq 'lower') {
6515: if (exists($settings->{'linkprot'})) {
6516: if (ref($settings->{'linkprot'}) eq 'HASH') {
6517: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6518: if ($linkprot{'lock'}) {
6519: delete($linkprot{'lock'});
6520: }
1.405 raeburn 6521: }
6522: }
6523: } else {
6524: foreach my $key ('encrypt','private','rules','linkprot') {
6525: if (exists($settings->{$key})) {
6526: delete($settings->{$key});
1.390 raeburn 6527: }
1.320 raeburn 6528: }
6529: }
6530: }
1.405 raeburn 6531: if ($position eq 'top') {
6532: my @ids=&Apache::lonnet::current_machine_ids();
6533: my %servers = &Apache::lonnet::get_servers($dom,'library');
6534: my $primary = &Apache::lonnet::domain($dom,'primary');
6535: my ($extra,$numshown);
6536: foreach my $hostid (sort(keys(%servers))) {
6537: my ($showextra,$divsty,$switch);
6538: if ($hostid eq $primary) {
6539: if (($encrypt{'ltisec_consumers'}) || ($encrypt{'ltisec_domlinkprot'})) {
6540: $showextra = 1;
6541: }
6542: }
6543: if ($encrypt{'ltisec_crslinkprot'}) {
6544: $showextra = 1;
6545: }
6546: unless (grep(/^\Q$hostid\E$/,@ids)) {
6547: $switch = 1;
6548: }
6549: if ($showextra) {
6550: $numshown ++;
6551: $divsty = 'display:inline-block';
6552: } else {
6553: $divsty = 'display:none';
6554: }
6555: $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
6556: '<legend>'.$hostid.'</legend>';
6557: if ($switch) {
6558: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
6559: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
6560: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6561: if (exists($privkeys{$hostid})) {
6562: $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
6563: '<span class="LC_nobreak">'.
6564: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6565: '<span class="LC_nobreak">'.&mt('Change?').
6566: '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
6567: (' 'x2).
6568: '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
6569: '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
6570: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
6571: '</span></div>';
6572: } else {
6573: $extra .= '<span class="LC_nobreak">'.
6574: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
6575: '</span>'."\n";
6576: }
6577: } elsif (exists($privkeys{$hostid})) {
6578: $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
6579: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6580: '<span class="LC_nobreak">'.&mt('Change?').
6581: '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
6582: (' 'x2).
6583: '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
6584: '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
6585: '<span class="LC_nobreak">'.&mt('New Key').':'.
1.415 raeburn 6586: '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
1.405 raeburn 6587: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
6588: '</span></div>';
6589: } else {
6590: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
1.415 raeburn 6591: '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
1.405 raeburn 6592: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
6593: }
6594: $extra .= '</fieldset>';
6595: }
6596: my %choices = &Apache::lonlocal::texthash (
6597: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
6598: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
6599: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
6600: );
6601: my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
6602: my %defaultchecked = (
6603: 'ltisec_crslinkprot' => 'off',
6604: 'ltisec_domlinkprot' => 'off',
6605: 'ltisec_consumers' => 'off',
6606: );
6607: my ($onclick,$itemcount);
6608: $onclick = 'javascript:toggleLTIEncKey(this.form);';
6609: ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
6610: \%choices,$itemcount,$onclick,'','left','no');
6611:
6612: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6613: my $noprivkeysty = 'display:inline-block';
6614: if ($numshown) {
6615: $noprivkeysty = 'display:none';
6616: }
6617: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
6618: '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
6619: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
6620: $extra.
6621: '</td></tr>';
6622: $itemcount ++;
6623: $$rowtotal += $itemcount;
6624: } elsif ($position eq 'middle') {
6625: $datatable = &password_rules('secrets',\$itemcount,\%rules);
1.406 raeburn 6626: $$rowtotal += $itemcount;
1.405 raeburn 6627: } elsif ($position eq 'lower') {
1.406 raeburn 6628: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.405 raeburn 6629: } else {
6630: my $maxnum = 0;
6631: my %ordered;
6632: if (ref($settings) eq 'HASH') {
6633: foreach my $item (keys(%{$settings})) {
6634: if (ref($settings->{$item}) eq 'HASH') {
6635: my $num = $settings->{$item}{'order'};
6636: if ($num eq '') {
6637: $num = scalar(keys(%{$settings}));
6638: }
6639: $ordered{$num} = $item;
6640: }
1.352 raeburn 6641: }
1.405 raeburn 6642: }
6643: $maxnum = scalar(keys(%ordered));
6644: my %lt = <i_names();
6645: if (keys(%ordered)) {
6646: my @items = sort { $a <=> $b } keys(%ordered);
6647: for (my $i=0; $i<@items; $i++) {
6648: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6649: my $item = $ordered{$items[$i]};
6650: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
6651: if (ref($settings->{$item}) eq 'HASH') {
6652: $key = $settings->{$item}->{'key'};
6653: $secret = $settings->{$item}->{'secret'};
6654: $lifetime = $settings->{$item}->{'lifetime'};
6655: $consumer = $settings->{$item}->{'consumer'};
6656: $requser = $settings->{$item}->{'requser'};
6657: $crsinc = $settings->{$item}->{'crsinc'};
6658: $current = $settings->{$item};
6659: }
6660: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6661: my %checkedrequser = (
6662: yes => ' checked="checked"',
6663: no => '',
6664: );
6665: if (!$requser) {
6666: $checkedrequser{'no'} = $checkedrequser{'yes'};
6667: $checkedrequser{'yes'} = '';
6668: }
6669: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6670: my %checkedcrsinc = (
1.391 raeburn 6671: yes => ' checked="checked"',
6672: no => '',
1.405 raeburn 6673: );
6674: if (!$crsinc) {
6675: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6676: $checkedcrsinc{'yes'} = '';
6677: }
6678: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6679: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6680: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6681: for (my $k=0; $k<=$maxnum; $k++) {
6682: my $vpos = $k+1;
6683: my $selstr;
6684: if ($k == $i) {
6685: $selstr = ' selected="selected" ';
6686: }
6687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6688: }
1.405 raeburn 6689: $datatable .= '</select>'.(' 'x2).
6690: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6691: &mt('Delete?').'</label></span></td>'.
6692: '<td colspan="2">'.
6693: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6694: '<span class="LC_nobreak">'.$lt{'consumer'}.
6695: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6696: (' 'x2).
6697: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6698: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6699: (' 'x2).
6700: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
6701: 'value="'.$lifetime.'" size="3" /></span>'.
6702: (' 'x2).
6703: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6704: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6705: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6706: '<br /><br />'.
6707: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6708: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6709: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6710: (' 'x4).
6711: '<span class="LC_nobreak">'.$lt{'key'}.
6712: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6713: (' 'x2).
6714: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6715: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6716: '<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>'.
6717: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6718: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6719: $itemcount ++;
1.320 raeburn 6720: }
6721: }
1.405 raeburn 6722: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6723: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6724: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6725: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6726: '<select name="lti_pos_add"'.$chgstr.'>';
6727: for (my $k=0; $k<$maxnum+1; $k++) {
6728: my $vpos = $k+1;
6729: my $selstr;
6730: if ($k == $maxnum) {
6731: $selstr = ' selected="selected" ';
6732: }
6733: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6734: }
1.405 raeburn 6735: $datatable .= '</select> '."\n".
6736: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6737: '<td colspan="2">'.
6738: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6739: '<span class="LC_nobreak">'.$lt{'consumer'}.
6740: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6741: (' 'x2).
6742: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6743: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6744: (' 'x2).
6745: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6746: (' 'x2).
6747: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6748: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6749: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6750: '<br /><br />'.
6751: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6752: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6753: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6754: (' 'x4).
6755: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6756: (' 'x2).
6757: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6758: '<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".
6759: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6760: '</td>'."\n".
6761: '</tr>'."\n";
6762: $itemcount ++;
1.320 raeburn 6763: }
1.405 raeburn 6764: $$rowtotal += $itemcount;
6765: return $datatable;
1.320 raeburn 6766: }
6767:
6768: sub lti_names {
6769: my %lt = &Apache::lonlocal::texthash(
6770: 'version' => 'LTI Version',
6771: 'url' => 'URL',
6772: 'key' => 'Key',
1.322 raeburn 6773: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6774: 'consumer' => 'Consumer',
1.320 raeburn 6775: 'secret' => 'Secret',
1.345 raeburn 6776: 'requser' => "User's identity sent",
1.391 raeburn 6777: 'crsinc' => "Course's identity sent",
1.320 raeburn 6778: 'email' => 'Email address',
6779: 'sourcedid' => 'User ID',
6780: 'other' => 'Other',
6781: 'passback' => 'Can return grades to Consumer:',
6782: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6783: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6784: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6785: );
6786: return %lt;
6787: }
6788:
6789: sub lti_options {
1.325 raeburn 6790: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6791: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6792: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6793: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6794: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6795: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6796: $checked{'mapcrstype'} = {};
6797: $checked{'makeuser'} = {};
6798: $checked{'selfenroll'} = {};
6799: $checked{'crssec'} = {};
6800: $checked{'crssecsrc'} = {};
1.325 raeburn 6801: $checked{'lcauth'} = {};
1.326 raeburn 6802: $checked{'menuitem'} = {};
1.325 raeburn 6803: if ($num eq 'add') {
6804: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6805: }
1.320 raeburn 6806: my $userfieldsty = 'none';
6807: my $crsfieldsty = 'none';
6808: my $crssecfieldsty = 'none';
6809: my $secsrcfieldsty = 'none';
1.363 raeburn 6810: my $callbacksty = 'none';
1.337 raeburn 6811: my $passbacksty = 'none';
1.345 raeburn 6812: my $optionsty = 'block';
1.391 raeburn 6813: my $crssty = 'block';
1.325 raeburn 6814: my $lcauthparm;
6815: my $lcauthparmstyle = 'display:none';
6816: my $lcauthparmtext;
1.326 raeburn 6817: my $menusty;
1.325 raeburn 6818: my $numinrow = 4;
1.326 raeburn 6819: my %menutitles = <imenu_titles();
1.320 raeburn 6820:
6821: if (ref($current) eq 'HASH') {
1.345 raeburn 6822: if (!$current->{'requser'}) {
6823: $optionsty = 'none';
1.391 raeburn 6824: $crssty = 'none';
6825: } elsif (!$current->{'crsinc'}) {
6826: $crssty = 'none';
1.345 raeburn 6827: }
1.320 raeburn 6828: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6829: $checked{'mapuser'}{'sourcedid'} = '';
6830: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6831: $checked{'mapuser'}{'email'} = ' checked="checked"';
6832: } else {
6833: $checked{'mapuser'}{'other'} = ' checked="checked"';
6834: $userfield = $current->{'mapuser'};
6835: $userfieldsty = 'inline-block';
6836: }
6837: }
6838: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6839: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6840: if ($current->{'mapcrs'} eq 'context_id') {
6841: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6842: } else {
6843: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6844: $cidfield = $current->{'mapcrs'};
6845: $crsfieldsty = 'inline-block';
6846: }
6847: }
6848: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6849: foreach my $type (@{$current->{'mapcrstype'}}) {
6850: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6851: }
6852: }
1.392 raeburn 6853: if (!$current->{'storecrs'}) {
6854: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6855: $checked{'storecrs'}{'Y'} = '';
6856: }
1.345 raeburn 6857: if ($current->{'makecrs'}) {
1.320 raeburn 6858: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6859: }
1.320 raeburn 6860: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6861: foreach my $role (@{$current->{'makeuser'}}) {
6862: $checked{'makeuser'}{$role} = ' checked="checked"';
6863: }
6864: }
1.325 raeburn 6865: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6866: $checked{'lcauth'}{$1} = ' checked="checked"';
6867: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6868: $lcauthparm = $current->{'lcauthparm'};
6869: $lcauthparmstyle = 'display:table-row';
6870: if ($current->{'lcauth'} eq 'localauth') {
6871: $lcauthparmtext = &mt('Local auth argument');
6872: } else {
6873: $lcauthparmtext = &mt('Kerberos domain');
6874: }
6875: }
6876: }
1.320 raeburn 6877: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6878: foreach my $role (@{$current->{'selfenroll'}}) {
6879: $checked{'selfenroll'}{$role} = ' checked="checked"';
6880: }
6881: }
6882: if (ref($current->{'maproles'}) eq 'HASH') {
6883: %rolemaps = %{$current->{'maproles'}};
6884: }
6885: if ($current->{'section'} ne '') {
6886: $checked{'crssec'}{'Y'} = ' checked="checked"';
6887: $crssecfieldsty = 'inline-block';
6888: if ($current->{'section'} eq 'course_section_sourcedid') {
6889: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6890: } else {
6891: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6892: $crssecsrc = $current->{'section'};
6893: $secsrcfieldsty = 'inline-block';
6894: }
6895: } else {
6896: $checked{'crssec'}{'N'} = ' checked="checked"';
6897: }
1.363 raeburn 6898: if ($current->{'callback'} ne '') {
6899: $callback = $current->{'callback'};
6900: $checked{'callback'}{'Y'} = ' checked="checked"';
6901: $callbacksty = 'inline-block';
6902: } else {
6903: $checked{'callback'}{'N'} = ' checked="checked"';
6904: }
1.326 raeburn 6905: if ($current->{'topmenu'}) {
6906: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6907: } else {
6908: $checked{'topmenu'}{'N'} = ' checked="checked"';
6909: }
6910: if ($current->{'inlinemenu'}) {
6911: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6912: } else {
6913: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6914: }
6915: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6916: $menusty = 'inline-block';
6917: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6918: foreach my $item (@{$current->{'lcmenu'}}) {
6919: if (exists($menutitles{$item})) {
6920: $checked{'menuitem'}{$item} = ' checked="checked"';
6921: }
6922: }
6923: }
6924: } else {
6925: $menusty = 'none';
6926: }
1.320 raeburn 6927: } else {
6928: $checked{'makecrs'}{'N'} = ' checked="checked"';
6929: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6930: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6931: $checked{'topmenu'}{'N'} = ' checked="checked"';
6932: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6933: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6934: $menusty = 'inline-block';
1.320 raeburn 6935: }
1.325 raeburn 6936: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6937: my %coursetypetitles = &Apache::lonlocal::texthash (
6938: official => 'Official',
6939: unofficial => 'Unofficial',
6940: community => 'Community',
6941: textbook => 'Textbook',
6942: placement => 'Placement Test',
1.325 raeburn 6943: lti => 'LTI Provider',
1.320 raeburn 6944: );
1.325 raeburn 6945: my @authtypes = ('internal','krb4','krb5','localauth');
6946: my %shortauth = (
6947: internal => 'int',
6948: krb4 => 'krb4',
6949: krb5 => 'krb5',
6950: localauth => 'loc'
6951: );
6952: my %authnames = &authtype_names();
1.320 raeburn 6953: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6954: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6955: my @courseroles = ('cc','in','ta','ep','st');
6956: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6957: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6958: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6959: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6960: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6961: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6962: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6963: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6964: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6965: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6966: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6967: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6968: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6969: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6970: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6971: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6972: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6973: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6974: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6975: foreach my $option ('sourcedid','email','other') {
6976: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6977: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6978: ($option eq 'other' ? '' : (' 'x2) );
6979: }
6980: $output .= '</span></div>'.
6981: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6982: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6983: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6984: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6985: foreach my $ltirole (@ltiroles) {
6986: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6987: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6988: }
6989: $output .= '</fieldset>'.
1.391 raeburn 6990: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6991: '<table>'.
6992: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6993: '</table>'.
6994: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6995: '<td class="LC_left_item">';
6996: foreach my $auth ('lti',@authtypes) {
6997: my $authtext;
6998: if ($auth eq 'lti') {
6999: $authtext = &mt('None');
7000: } else {
7001: $authtext = $authnames{$shortauth{$auth}};
7002: }
7003: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
7004: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
7005: $authtext.'</label></span> ';
7006: }
7007: $output .= '</td></tr>'.
7008: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
7009: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
7010: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
7011: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
7012: '</table></fieldset>'.
1.391 raeburn 7013: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
7014: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
7015: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
7016: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
7017: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
7018: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
7019: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
7020: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7021: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
7022: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
7023: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
7024: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
7025: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
7026: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7027: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
7028: '<span class="LC_nobreak">'.&mt('Menu items').': ';
7029: foreach my $type ('fullname','coursetitle','role','logout','grades') {
7030: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
7031: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
7032: (' 'x2);
7033: }
7034: $output .= '</span></div></fieldset>'.
7035: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 7036: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7037: &mt('Unique course identifier').': ';
7038: foreach my $option ('course_offering_sourcedid','context_id','other') {
7039: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
7040: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
7041: ($option eq 'other' ? '' : (' 'x2) );
7042: }
1.334 raeburn 7043: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 7044: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
7045: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
7046: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
7047: foreach my $type (@coursetypes) {
7048: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
7049: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
7050: (' 'x2);
7051: }
1.392 raeburn 7052: $output .= '</span><br /><br />'.
7053: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
7054: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
7055: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
7056: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
7057: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
7058: '</fieldset>'.
1.391 raeburn 7059: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
7060: foreach my $ltirole (@lticourseroles) {
7061: my ($selected,$selectnone);
7062: if ($rolemaps{$ltirole} eq '') {
7063: $selectnone = ' selected="selected"';
7064: }
7065: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
7066: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
7067: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
7068: foreach my $role (@courseroles) {
7069: unless ($selectnone) {
7070: if ($rolemaps{$ltirole} eq $role) {
7071: $selected = ' selected="selected"';
7072: } else {
7073: $selected = '';
7074: }
7075: }
7076: $output .= '<option value="'.$role.'"'.$selected.'>'.
7077: &Apache::lonnet::plaintext($role,'Course').
7078: '</option>';
7079: }
7080: $output .= '</select></td>';
7081: }
7082: $output .= '</tr></table></fieldset>'.
7083: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 7084: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
7085: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
7086: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
7087: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
7088: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
7089: '</fieldset>'.
1.391 raeburn 7090: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 7091: foreach my $lticrsrole (@lticourseroles) {
7092: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
7093: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
7094: }
7095: $output .= '</fieldset>'.
1.391 raeburn 7096: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 7097: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
7098: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
7099: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
7100: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 7101: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 7102: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
7103: '<span class="LC_nobreak">'.&mt('From').':<label>'.
7104: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
7105: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
7106: &mt('Standard field').'</label>'.(' 'x2).
7107: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
7108: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 7109: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 7110: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 7111: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
7112: my ($pb1p1chk,$pb1p0chk,$onclickpb);
7113: foreach my $extra ('roster','passback') {
1.320 raeburn 7114: my $checkedon = '';
7115: my $checkedoff = ' checked="checked"';
1.337 raeburn 7116: if ($extra eq 'passback') {
7117: $pb1p1chk = ' checked="checked"';
7118: $pb1p0chk = '';
7119: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
7120: } else {
7121: $onclickpb = '';
7122: }
1.320 raeburn 7123: if (ref($current) eq 'HASH') {
7124: if (($current->{$extra})) {
7125: $checkedon = $checkedoff;
7126: $checkedoff = '';
1.337 raeburn 7127: if ($extra eq 'passback') {
7128: $passbacksty = 'inline-block';
7129: }
7130: if ($current->{'passbackformat'} eq '1.0') {
7131: $pb1p0chk = ' checked="checked"';
7132: $pb1p1chk = '';
7133: }
1.320 raeburn 7134: }
7135: }
7136: $output .= $lt{$extra}.' '.
1.337 raeburn 7137: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 7138: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 7139: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 7140: &mt('Yes').'</label><br />';
7141: }
1.337 raeburn 7142: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
7143: '<span class="LC_nobreak">'.&mt('Grade format').
7144: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
7145: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7146: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 7147: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 7148: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 7149: $output .= '</span></div></fieldset>';
1.320 raeburn 7150: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
7151: #
7152: # $output .= '</fieldset>'.
7153: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
7154: return $output;
7155: }
7156:
1.326 raeburn 7157: sub ltimenu_titles {
7158: return &Apache::lonlocal::texthash(
7159: fullname => 'Full name',
7160: coursetitle => 'Course title',
7161: role => 'Role',
7162: logout => 'Logout',
7163: grades => 'Grades',
7164: );
7165: }
7166:
1.405 raeburn 7167: sub check_switchserver {
7168: my ($home) = @_;
7169: my $switchserver;
7170: if ($home ne '') {
7171: my $allowed;
7172: my @ids=&Apache::lonnet::current_machine_ids();
7173: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7174: if (!$allowed) {
7175: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7176: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
7177: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
7178: }
7179: }
7180: return $switchserver;
7181: }
7182:
1.121 raeburn 7183: sub print_coursedefaults {
1.139 raeburn 7184: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 7185: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 7186: my $itemcount = 1;
1.192 raeburn 7187: my %choices = &Apache::lonlocal::texthash (
7188: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 7189: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 7190: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
7191: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 7192: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
7193: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 7194: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 7195: texengine => 'Default method to display mathematics',
1.257 raeburn 7196: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 7197: canclone => "People who may clone a course (besides course's owner and coordinators)",
7198: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 7199: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.192 raeburn 7200: );
1.198 raeburn 7201: my %staticdefaults = (
7202: anonsurvey_threshold => 10,
7203: uploadquota => 500,
1.257 raeburn 7204: postsubmit => 60,
1.276 raeburn 7205: mysqltables => 172800,
1.198 raeburn 7206: );
1.139 raeburn 7207: if ($position eq 'top') {
1.257 raeburn 7208: %defaultchecked = (
7209: 'canuse_pdfforms' => 'off',
7210: 'uselcmath' => 'on',
7211: 'usejsme' => 'on',
1.398 raeburn 7212: 'inline_chem' => 'on',
1.289 raeburn 7213: 'canclone' => 'none',
1.257 raeburn 7214: );
1.398 raeburn 7215: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 7216: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 7217: if (ref($settings) eq 'HASH') {
7218: if ($settings->{'texengine'}) {
7219: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
7220: $deftex = $settings->{'texengine'};
7221: }
7222: }
7223: }
7224: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7225: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
7226: '<span class="LC_nobreak">'.$choices{'texengine'}.
7227: '</span></td><td class="LC_right_item">'.
7228: '<select name="texengine">'."\n";
7229: my %texoptions = (
7230: MathJax => 'MathJax',
7231: mimetex => &mt('Convert to Images'),
7232: tth => &mt('TeX to HTML'),
7233: );
7234: foreach my $renderer ('MathJax','mimetex','tth') {
7235: my $selected = '';
7236: if ($renderer eq $deftex) {
7237: $selected = ' selected="selected"';
7238: }
7239: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
7240: }
7241: $mathdisp .= '</select></td></tr>'."\n";
7242: $itemcount ++;
1.139 raeburn 7243: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 7244: \%choices,$itemcount);
1.314 raeburn 7245: $datatable = $mathdisp.$datatable;
1.264 raeburn 7246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7247: $datatable .=
1.306 raeburn 7248: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 7249: '<span class="LC_nobreak">'.$choices{'canclone'}.
7250: '</span></td><td class="LC_left_item">';
7251: my $currcanclone = 'none';
7252: my $onclick;
7253: my @cloneoptions = ('none','domain');
1.380 raeburn 7254: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 7255: none => 'No additional course requesters',
7256: domain => "Any course requester in course's domain",
7257: instcode => 'Course requests for official courses ...',
7258: );
7259: my (%codedefaults,@code_order,@posscodes);
7260: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
7261: \@code_order) eq 'ok') {
7262: if (@code_order > 0) {
7263: push(@cloneoptions,'instcode');
7264: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
7265: }
7266: }
7267: if (ref($settings) eq 'HASH') {
7268: if ($settings->{'canclone'}) {
7269: if (ref($settings->{'canclone'}) eq 'HASH') {
7270: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
7271: if (@code_order > 0) {
7272: $currcanclone = 'instcode';
7273: @posscodes = @{$settings->{'canclone'}{'instcode'}};
7274: }
7275: }
7276: } elsif ($settings->{'canclone'} eq 'domain') {
7277: $currcanclone = $settings->{'canclone'};
7278: }
7279: }
1.289 raeburn 7280: }
1.264 raeburn 7281: foreach my $option (@cloneoptions) {
7282: my ($checked,$additional);
7283: if ($currcanclone eq $option) {
7284: $checked = ' checked="checked"';
7285: }
7286: if ($option eq 'instcode') {
7287: if (@code_order) {
7288: my $show = 'none';
7289: if ($checked) {
7290: $show = 'block';
7291: }
1.317 raeburn 7292: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7293: &mt('Institutional codes for new and cloned course have identical:').
7294: '<br />';
7295: foreach my $item (@code_order) {
7296: my $codechk;
7297: if ($checked) {
7298: if (grep(/^\Q$item\E$/,@posscodes)) {
7299: $codechk = ' checked="checked"';
7300: }
7301: }
7302: $additional .= '<label>'.
7303: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7304: $item.'</label>';
7305: }
7306: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7307: }
7308: }
7309: $datatable .=
7310: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7311: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7312: '</label> '.$additional.'</span><br />';
7313: }
7314: $datatable .= '</td>'.
7315: '</tr>';
7316: $itemcount ++;
1.139 raeburn 7317: } else {
7318: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 7319: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 7320: my $currusecredits = 0;
1.257 raeburn 7321: my $postsubmitclient = 1;
1.405 raeburn 7322: my $ltiauth = 0;
1.271 raeburn 7323: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7324: if (ref($settings) eq 'HASH') {
1.404 raeburn 7325: if ($settings->{'ltiauth'}) {
7326: $ltiauth = 1;
1.405 raeburn 7327: }
1.139 raeburn 7328: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7329: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7330: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7331: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7332: }
7333: }
1.192 raeburn 7334: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7335: foreach my $type (@types) {
7336: next if ($type eq 'community');
7337: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7338: if ($defcredits{$type} ne '') {
7339: $currusecredits = 1;
7340: }
7341: }
7342: }
7343: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7344: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7345: $postsubmitclient = 0;
7346: foreach my $type (@types) {
7347: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7348: }
7349: } else {
7350: foreach my $type (@types) {
7351: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7352: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7353: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7354: } else {
7355: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7356: }
7357: } else {
7358: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7359: }
7360: }
7361: }
7362: } else {
7363: foreach my $type (@types) {
7364: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7365: }
7366: }
1.276 raeburn 7367: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7368: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7369: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7370: }
7371: } else {
7372: foreach my $type (@types) {
7373: $currmysql{$type} = $staticdefaults{'mysqltables'};
7374: }
7375: }
1.258 raeburn 7376: } else {
7377: foreach my $type (@types) {
7378: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7379: }
1.139 raeburn 7380: }
7381: if (!$currdefresponder) {
1.198 raeburn 7382: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7383: } elsif ($currdefresponder < 1) {
7384: $currdefresponder = 1;
7385: }
1.198 raeburn 7386: foreach my $type (@types) {
7387: if ($curruploadquota{$type} eq '') {
7388: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7389: }
7390: }
1.139 raeburn 7391: $datatable .=
1.192 raeburn 7392: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7393: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7394: '</span></td>'.
7395: '<td class="LC_right_item"><span class="LC_nobreak">'.
7396: '<input type="text" name="anonsurvey_threshold"'.
7397: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7398: '</td></tr>'."\n";
7399: $itemcount ++;
7400: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7401: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7402: $choices{'uploadquota'}.
7403: '</span></td>'.
1.306 raeburn 7404: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7405: '<table><tr>';
1.198 raeburn 7406: foreach my $type (@types) {
1.306 raeburn 7407: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7408: '<input type="text" name="uploadquota_'.$type.'"'.
7409: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7410: }
7411: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7412: $itemcount ++;
1.236 raeburn 7413: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7414: my $display = 'none';
1.192 raeburn 7415: if ($currusecredits) {
7416: $display = 'block';
7417: }
7418: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7419: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7420: foreach my $type (@types) {
7421: next if ($type eq 'community');
1.306 raeburn 7422: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7423: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7424: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7425: }
7426: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7427: %defaultchecked = ('coursecredits' => 'off');
7428: @toggles = ('coursecredits');
7429: my $current = {
7430: 'coursecredits' => $currusecredits,
7431: };
7432: (my $table,$itemcount) =
7433: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7434: \%choices,$itemcount,$onclick,$additional,'left');
7435: $datatable .= $table;
7436: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7437: my $display = 'none';
7438: if ($postsubmitclient) {
7439: $display = 'block';
7440: }
7441: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7442: &mt('Number of seconds submit is disabled').'<br />'.
7443: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7444: '<table><tr>';
1.257 raeburn 7445: foreach my $type (@types) {
1.306 raeburn 7446: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7447: '<input type="text" name="'.$type.'_timeout" value="'.
7448: $deftimeout{$type}.'" size="5" /></td>';
7449: }
7450: $additional .= '</tr></table></div>'."\n";
7451: %defaultchecked = ('postsubmit' => 'on');
7452: @toggles = ('postsubmit');
1.280 raeburn 7453: $current = {
7454: 'postsubmit' => $postsubmitclient,
7455: };
1.257 raeburn 7456: ($table,$itemcount) =
7457: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7458: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7459: $datatable .= $table;
1.276 raeburn 7460: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7461: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7462: $choices{'mysqltables'}.
7463: '</span></td>'.
1.306 raeburn 7464: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7465: '<table><tr>';
7466: foreach my $type (@types) {
1.306 raeburn 7467: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7468: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7469: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7470: }
7471: $datatable .= '</tr></table></td></tr>'."\n";
7472: $itemcount ++;
1.404 raeburn 7473: %defaultchecked = ('ltiauth' => 'off');
7474: @toggles = ('ltiauth');
7475: $current = {
7476: 'ltiauth' => $ltiauth,
7477: };
7478: ($table,$itemcount) =
7479: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7480: \%choices,$itemcount,undef,undef,'left');
7481: $datatable .= $table;
7482: $itemcount ++;
1.139 raeburn 7483: }
1.192 raeburn 7484: $$rowtotal += $itemcount;
1.121 raeburn 7485: return $datatable;
1.118 jms 7486: }
7487:
1.231 raeburn 7488: sub print_selfenrollment {
7489: my ($position,$dom,$settings,$rowtotal) = @_;
7490: my ($css_class,$datatable);
7491: my $itemcount = 1;
1.271 raeburn 7492: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7493: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7494: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7495: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7496: my @rows;
7497: my $key;
7498: if ($position eq 'top') {
7499: $key = 'admin';
7500: if (ref($rowsref) eq 'ARRAY') {
7501: @rows = @{$rowsref};
7502: }
7503: } elsif ($position eq 'middle') {
7504: $key = 'default';
7505: @rows = ('types','registered','approval','limit');
7506: }
7507: foreach my $row (@rows) {
7508: if (defined($titlesref->{$row})) {
7509: $itemcount ++;
7510: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7511: $datatable .= '<tr'.$css_class.'>'.
7512: '<td>'.$titlesref->{$row}.'</td>'.
7513: '<td class="LC_left_item">'.
7514: '<table><tr>';
7515: my (%current,%currentcap);
7516: if (ref($settings) eq 'HASH') {
7517: if (ref($settings->{$key}) eq 'HASH') {
7518: foreach my $type (@types) {
7519: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7520: $current{$type} = $settings->{$key}->{$type}->{$row};
7521: }
7522: if (($row eq 'limit') && ($key eq 'default')) {
7523: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7524: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7525: }
7526: }
7527: }
7528: }
7529: }
7530: my %roles = (
7531: '0' => &Apache::lonnet::plaintext('dc'),
7532: );
7533:
7534: foreach my $type (@types) {
7535: unless (($row eq 'registered') && ($key eq 'default')) {
7536: $datatable .= '<th>'.&mt($type).'</th>';
7537: }
7538: }
7539: unless (($row eq 'registered') && ($key eq 'default')) {
7540: $datatable .= '</tr><tr>';
7541: }
7542: foreach my $type (@types) {
7543: if ($type eq 'community') {
7544: $roles{'1'} = &mt('Community personnel');
7545: } else {
7546: $roles{'1'} = &mt('Course personnel');
7547: }
7548: $datatable .= '<td style="vertical-align: top">';
7549: if ($position eq 'top') {
7550: my %checked;
7551: if ($current{$type} eq '0') {
7552: $checked{'0'} = ' checked="checked"';
7553: } else {
7554: $checked{'1'} = ' checked="checked"';
7555: }
7556: foreach my $role ('1','0') {
7557: $datatable .= '<span class="LC_nobreak"><label>'.
7558: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7559: 'value="'.$role.'"'.$checked{$role}.' />'.
7560: $roles{$role}.'</label></span> ';
7561: }
7562: } else {
7563: if ($row eq 'types') {
7564: my %checked;
7565: if ($current{$type} =~ /^(all|dom)$/) {
7566: $checked{$1} = ' checked="checked"';
7567: } else {
7568: $checked{''} = ' checked="checked"';
7569: }
7570: foreach my $val ('','dom','all') {
7571: $datatable .= '<span class="LC_nobreak"><label>'.
7572: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7573: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7574: }
7575: } elsif ($row eq 'registered') {
7576: my %checked;
7577: if ($current{$type} eq '1') {
7578: $checked{'1'} = ' checked="checked"';
7579: } else {
7580: $checked{'0'} = ' checked="checked"';
7581: }
7582: foreach my $val ('0','1') {
7583: $datatable .= '<span class="LC_nobreak"><label>'.
7584: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7585: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7586: }
7587: } elsif ($row eq 'approval') {
7588: my %checked;
7589: if ($current{$type} =~ /^([12])$/) {
7590: $checked{$1} = ' checked="checked"';
7591: } else {
7592: $checked{'0'} = ' checked="checked"';
7593: }
7594: for my $val (0..2) {
7595: $datatable .= '<span class="LC_nobreak"><label>'.
7596: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7597: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7598: }
7599: } elsif ($row eq 'limit') {
7600: my %checked;
7601: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7602: $checked{$1} = ' checked="checked"';
7603: } else {
7604: $checked{'none'} = ' checked="checked"';
7605: }
7606: my $cap;
7607: if ($currentcap{$type} =~ /^\d+$/) {
7608: $cap = $currentcap{$type};
7609: }
7610: foreach my $val ('none','allstudents','selfenrolled') {
7611: $datatable .= '<span class="LC_nobreak"><label>'.
7612: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7613: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7614: }
7615: $datatable .= '<br />'.
7616: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7617: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7618: '</span>';
7619: }
7620: }
7621: $datatable .= '</td>';
7622: }
7623: $datatable .= '</tr>';
7624: }
7625: $datatable .= '</table></td></tr>';
7626: }
7627: } elsif ($position eq 'bottom') {
1.235 raeburn 7628: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7629: }
7630: $$rowtotal += $itemcount;
7631: return $datatable;
7632: }
7633:
7634: sub print_validation_rows {
7635: my ($caller,$dom,$settings,$rowtotal) = @_;
7636: my ($itemsref,$namesref,$fieldsref);
7637: if ($caller eq 'selfenroll') {
7638: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7639: } elsif ($caller eq 'requestcourses') {
7640: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7641: }
7642: my %currvalidation;
7643: if (ref($settings) eq 'HASH') {
7644: if (ref($settings->{'validation'}) eq 'HASH') {
7645: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7646: }
1.235 raeburn 7647: }
7648: my $datatable;
7649: my $itemcount = 0;
7650: foreach my $item (@{$itemsref}) {
7651: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7652: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7653: $namesref->{$item}.
7654: '</span></td>'.
7655: '<td class="LC_left_item">';
7656: if (($item eq 'url') || ($item eq 'button')) {
7657: $datatable .= '<span class="LC_nobreak">'.
7658: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7659: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7660: } elsif ($item eq 'fields') {
7661: my @currfields;
7662: if (ref($currvalidation{$item}) eq 'ARRAY') {
7663: @currfields = @{$currvalidation{$item}};
7664: }
7665: foreach my $field (@{$fieldsref}) {
7666: my $check = '';
7667: if (grep(/^\Q$field\E$/,@currfields)) {
7668: $check = ' checked="checked"';
7669: }
7670: $datatable .= '<span class="LC_nobreak"><label>'.
7671: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7672: ' value="'.$field.'"'.$check.' />'.$field.
7673: '</label></span> ';
7674: }
7675: } elsif ($item eq 'markup') {
1.334 raeburn 7676: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7677: $currvalidation{$item}.
1.231 raeburn 7678: '</textarea>';
1.235 raeburn 7679: }
7680: $datatable .= '</td></tr>'."\n";
7681: if (ref($rowtotal)) {
1.231 raeburn 7682: $itemcount ++;
7683: }
7684: }
1.235 raeburn 7685: if ($caller eq 'requestcourses') {
7686: my %currhash;
1.248 raeburn 7687: if (ref($settings) eq 'HASH') {
7688: if (ref($settings->{'validation'}) eq 'HASH') {
7689: if ($settings->{'validation'}{'dc'} ne '') {
7690: $currhash{$settings->{'validation'}{'dc'}} = 1;
7691: }
1.235 raeburn 7692: }
7693: }
7694: my $numinrow = 2;
7695: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7696: 'validationdc',%currhash);
1.247 raeburn 7697: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7698: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7699: if ($numdc > 1) {
1.247 raeburn 7700: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7701: } else {
1.247 raeburn 7702: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7703: }
1.247 raeburn 7704: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7705: $itemcount ++;
7706: }
7707: if (ref($rowtotal)) {
7708: $$rowtotal += $itemcount;
7709: }
1.231 raeburn 7710: return $datatable;
7711: }
7712:
1.357 raeburn 7713: sub print_privacy {
7714: my ($position,$dom,$settings,$rowtotal) = @_;
7715: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7716: my $itemcount = 0;
1.417 ! raeburn 7717: if ($position eq 'top') {
! 7718: $numinrow = 2;
! 7719: } else {
1.357 raeburn 7720: @items = ('domain','author','course','community');
7721: %names = &Apache::lonlocal::texthash (
7722: domain => 'Assigned domain role(s)',
7723: author => 'Assigned co-author role(s)',
7724: course => 'Assigned course role(s)',
1.416 raeburn 7725: community => 'Assigned community role(s)',
1.357 raeburn 7726: );
7727: $numinrow = 4;
7728: ($othertitle,$usertypes,$types) =
7729: &Apache::loncommon::sorted_inst_types($dom);
7730: }
7731: if (($position eq 'top') || ($position eq 'middle')) {
7732: my (%by_ip,%by_location,@intdoms,@instdoms);
7733: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7734: if ($position eq 'top') {
7735: my %curr;
7736: my @options = ('none','user','domain','auto');
7737: my %titles = &Apache::lonlocal::texthash (
7738: none => 'Not allowed',
7739: user => 'User authorizes',
7740: domain => 'DC authorizes',
7741: auto => 'Unrestricted',
7742: instdom => 'Other domain shares institution/provider',
7743: extdom => 'Other domain has different institution/provider',
1.417 ! raeburn 7744: notify => 'Receive notification of role requests requiring DC authorization',
1.357 raeburn 7745: );
7746: my %names = &Apache::lonlocal::texthash (
7747: domain => 'Domain role',
7748: author => 'Co-author role',
7749: course => 'Course role',
7750: community => 'Community role',
7751: );
7752: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7753: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7754: foreach my $domtype ('instdom','extdom') {
7755: my (%checked,$skip);
7756: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7757: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7758: '<td class="LC_left_item">';
7759: if ($domtype eq 'instdom') {
7760: unless (@instdoms > 1) {
7761: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7762: $skip = 1;
7763: }
7764: } elsif ($domtype eq 'extdom') {
7765: if (keys(%by_location) == 0) {
7766: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7767: $skip = 1;
7768: }
7769: }
7770: unless ($skip) {
7771: foreach my $roletype ('domain','author','course','community') {
7772: $checked{'auto'} = ' checked="checked"';
7773: if (ref($settings) eq 'HASH') {
7774: if (ref($settings->{approval}) eq 'HASH') {
7775: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7776: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7777: $checked{$1} = ' checked="checked"';
7778: $checked{'auto'} = '';
7779: }
7780: }
7781: }
7782: }
7783: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7784: foreach my $option (@options) {
7785: $datatable .= '<span class="LC_nobreak"><label>'.
7786: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7787: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7788: '</label></span> ';
7789: }
7790: $datatable .= '</fieldset>';
7791: }
7792: }
7793: $datatable .= '</td></tr>';
7794: $itemcount ++;
7795: }
1.417 ! raeburn 7796: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 7797: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
! 7798: '<td class="LC_left_item">';
! 7799: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
! 7800: my %curr;
! 7801: if (ref($settings) eq 'HASH') {
! 7802: if ($settings->{'notify'} ne '') {
! 7803: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
! 7804: }
! 7805: }
! 7806: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 7807: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
! 7808: 'privacy_notify',%curr);
! 7809: if ($numdc > 0) {
! 7810: $datatable .= $table;
! 7811: } else {
! 7812: $datatable .= &mt('There are no active Domain Coordinators');
! 7813: }
! 7814: } else {
! 7815: $datatable .= &mt('Nothing to set here, as there are no other domains');
! 7816: }
! 7817: $datatable .='</td></tr>';
1.357 raeburn 7818: } elsif ($position eq 'middle') {
7819: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7820: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7821: foreach my $item (@{$types}) {
7822: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7823: $numinrow,$itemcount,'','','','','',
7824: '',$usertypes->{$item});
7825: $itemcount ++;
7826: }
7827: }
7828: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7829: $numinrow,$itemcount,'','','','','',
7830: '',$othertitle);
7831: $itemcount ++;
7832: } else {
1.360 raeburn 7833: my (@insttypes,%insttitles);
7834: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7835: @insttypes = @{$types};
7836: %insttitles = %{$usertypes};
7837: }
7838: foreach my $item (@insttypes,'default') {
7839: my $title;
7840: if ($item eq 'default') {
7841: $title = $othertitle;
7842: } else {
7843: $title = $insttitles{$item};
7844: }
7845: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7846: $datatable .= '<tr'.$css_class.'>'.
7847: '<td class="LC_left_item">'.$title.'</td>'.
7848: '<td class="LC_left_item">'.
7849: &mt('Nothing to set here, as there are no other domains').
7850: '</td></tr>';
7851: $itemcount ++;
7852: }
1.357 raeburn 7853: }
7854: }
7855: } else {
7856: my $prefix;
7857: if ($position eq 'lower') {
7858: $prefix = 'priv';
7859: } else {
7860: $prefix = 'unpriv';
7861: }
7862: foreach my $item (@items) {
7863: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7864: $numinrow,$itemcount,'','','','','',
7865: '',$names{$item});
7866: $itemcount ++;
7867: }
7868: }
7869: if (ref($rowtotal)) {
7870: $$rowtotal += $itemcount;
7871: }
7872: return $datatable;
7873: }
7874:
1.354 raeburn 7875: sub print_passwords {
7876: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7877: my ($datatable,$css_class);
7878: my $itemcount = 0;
7879: my %titles = &Apache::lonlocal::texthash (
7880: captcha => '"Forgot Password" CAPTCHA validation',
7881: link => 'Reset link expiration (hours)',
7882: case => 'Case-sensitive usernames/e-mail',
7883: prelink => 'Information required (form 1)',
7884: postlink => 'Information required (form 2)',
7885: emailsrc => 'LON-CAPA e-mail address type(s)',
7886: customtext => 'Domain specific text (HTML)',
7887: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7888: intauth_check => 'Check bcrypt cost if authenticated',
7889: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7890: permanent => 'Permanent e-mail address',
7891: critical => 'Critical notification address',
7892: notify => 'Notification address',
7893: min => 'Minimum password length',
7894: max => 'Maximum password length',
7895: chars => 'Required characters',
7896: expire => 'Password expiration (days)',
1.356 raeburn 7897: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7898: );
7899: if ($position eq 'top') {
7900: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7901: my $shownlinklife = 2;
7902: my $prelink = 'both';
7903: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7904: if (ref($settings) eq 'HASH') {
7905: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7906: $shownlinklife = $settings->{resetlink};
7907: }
7908: if (ref($settings->{resetcase}) eq 'ARRAY') {
7909: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7910: }
7911: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7912: $prelink = $settings->{resetprelink};
7913: }
7914: if (ref($settings->{resetpostlink}) eq 'HASH') {
7915: %postlink = %{$settings->{resetpostlink}};
7916: }
7917: if (ref($settings->{resetemail}) eq 'ARRAY') {
7918: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7919: }
7920: if ($settings->{resetremove}) {
7921: $nostdtext = 1;
7922: }
7923: if ($settings->{resetcustom}) {
7924: $customurl = $settings->{resetcustom};
7925: }
7926: } else {
7927: if (ref($types) eq 'ARRAY') {
7928: foreach my $item (@{$types}) {
7929: $casesens{$item} = 1;
7930: $postlink{$item} = ['username','email'];
7931: }
7932: }
7933: $casesens{'default'} = 1;
7934: $postlink{'default'} = ['username','email'];
7935: $prelink = 'both';
7936: %emailsrc = (
7937: permanent => 1,
7938: critical => 1,
7939: notify => 1,
7940: );
7941: }
7942: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7943: $itemcount ++;
7944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7945: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7946: '<td class="LC_left_item">'.
7947: '<input type="textbox" value="'.$shownlinklife.'" '.
7948: 'name="passwords_link" size="3" /></td></tr>';
7949: $itemcount ++;
7950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7951: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7952: '<td class="LC_left_item">';
7953: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7954: foreach my $item (@{$types}) {
7955: my $checkedcase;
7956: if ($casesens{$item}) {
7957: $checkedcase = ' checked="checked"';
7958: }
7959: $datatable .= '<span class="LC_nobreak"><label>'.
7960: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7961: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7962: '</span> ';
1.354 raeburn 7963: }
7964: }
7965: my $checkedcase;
7966: if ($casesens{'default'}) {
7967: $checkedcase = ' checked="checked"';
7968: }
7969: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7970: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7971: $othertitle.'</label></span></td>';
7972: $itemcount ++;
7973: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7974: my %checkedpre = (
7975: both => ' checked="checked"',
7976: either => '',
7977: );
7978: if ($prelink eq 'either') {
7979: $checkedpre{either} = ' checked="checked"';
7980: $checkedpre{both} = '';
7981: }
7982: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7983: '<td class="LC_left_item"><span class="LC_nobreak">'.
7984: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7985: &mt('Both username and e-mail address').'</label></span> '.
7986: '<span class="LC_nobreak"><label>'.
7987: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7988: &mt('Either username or e-mail address').'</label></span></td></tr>';
7989: $itemcount ++;
7990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7991: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7992: '<td class="LC_left_item">';
7993: my %postlinked;
7994: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7995: foreach my $item (@{$types}) {
7996: undef(%postlinked);
7997: $datatable .= '<fieldset style="display: inline-block;">'.
7998: '<legend>'.$usertypes->{$item}.'</legend>';
7999: if (ref($postlink{$item}) eq 'ARRAY') {
8000: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8001: }
8002: foreach my $field ('email','username') {
8003: my $checked;
8004: if ($postlinked{$field}) {
8005: $checked = ' checked="checked"';
8006: }
8007: $datatable .= '<span class="LC_nobreak"><label>'.
8008: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8009: $field.'"'.$checked.' />'.$field.'</label>'.
8010: '<span> ';
8011: }
8012: $datatable .= '</fieldset>';
8013: }
8014: }
8015: if (ref($postlink{'default'}) eq 'ARRAY') {
8016: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8017: }
8018: $datatable .= '<fieldset style="display: inline-block;">'.
8019: '<legend>'.$othertitle.'</legend>';
8020: foreach my $field ('email','username') {
8021: my $checked;
8022: if ($postlinked{$field}) {
8023: $checked = ' checked="checked"';
8024: }
8025: $datatable .= '<span class="LC_nobreak"><label>'.
8026: '<input type="checkbox" name="passwords_postlink_default" value="'.
8027: $field.'"'.$checked.' />'.$field.'</label>'.
8028: '<span> ';
8029: }
8030: $datatable .= '</fieldset></td></tr>';
8031: $itemcount ++;
8032: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8033: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8034: '<td class="LC_left_item">';
8035: foreach my $type ('permanent','critical','notify') {
8036: my $checkedemail;
8037: if ($emailsrc{$type}) {
8038: $checkedemail = ' checked="checked"';
8039: }
8040: $datatable .= '<span class="LC_nobreak"><label>'.
8041: '<input type="checkbox" name="passwords_emailsrc" value="'.
8042: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8043: '<span> ';
8044: }
8045: $datatable .= '</td></tr>';
8046: $itemcount ++;
8047: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8048: my $switchserver = &check_switchserver($dom,$confname);
8049: my ($showstd,$noshowstd);
8050: if ($nostdtext) {
8051: $noshowstd = ' checked="checked"';
8052: } else {
8053: $showstd = ' checked="checked"';
8054: }
8055: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8056: '<td class="LC_left_item"><span class="LC_nobreak">'.
8057: &mt('Retain standard text:').
8058: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8059: &mt('Yes').'</label>'.' '.
8060: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8061: &mt('No').'</label></span><br />'.
8062: '<span class="LC_fontsize_small">'.
8063: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8064: &mt('Include custom text:');
8065: if ($customurl) {
1.369 raeburn 8066: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8067: undef,undef,undef,undef,'background-color:#ffffff');
8068: $datatable .= '<span class="LC_nobreak"> '.$link.
8069: '<label><input type="checkbox" name="passwords_custom_del"'.
8070: ' value="1" />'.&mt('Delete?').'</label></span>'.
8071: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8072: }
8073: if ($switchserver) {
8074: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8075: } else {
8076: $datatable .='<span class="LC_nobreak"> '.
8077: '<input type="file" name="passwords_customfile" /></span>';
8078: }
8079: $datatable .= '</td></tr>';
8080: } elsif ($position eq 'middle') {
8081: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8082: my @items = ('intauth_cost','intauth_check','intauth_switch');
8083: my %defaults;
8084: if (ref($domconf{'defaults'}) eq 'HASH') {
8085: %defaults = %{$domconf{'defaults'}};
8086: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8087: $defaults{'intauth_cost'} = 10;
8088: }
8089: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8090: $defaults{'intauth_check'} = 0;
8091: }
8092: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8093: $defaults{'intauth_switch'} = 0;
8094: }
8095: } else {
8096: %defaults = (
8097: 'intauth_cost' => 10,
8098: 'intauth_check' => 0,
8099: 'intauth_switch' => 0,
8100: );
8101: }
8102: foreach my $item (@items) {
8103: if ($itemcount%2) {
8104: $css_class = '';
8105: } else {
8106: $css_class = ' class="LC_odd_row" ';
8107: }
8108: $datatable .= '<tr'.$css_class.'>'.
8109: '<td><span class="LC_nobreak">'.$titles{$item}.
8110: '</span></td><td class="LC_left_item" colspan="3">';
8111: if ($item eq 'intauth_switch') {
8112: my @options = (0,1,2);
8113: my %optiondesc = &Apache::lonlocal::texthash (
8114: 0 => 'No',
8115: 1 => 'Yes',
8116: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8117: );
8118: $datatable .= '<table width="100%">';
8119: foreach my $option (@options) {
8120: my $checked = ' ';
8121: if ($defaults{$item} eq $option) {
8122: $checked = ' checked="checked"';
8123: }
8124: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8125: '<label><input type="radio" name="'.$item.
8126: '" value="'.$option.'"'.$checked.' />'.
8127: $optiondesc{$option}.'</label></span></td></tr>';
8128: }
8129: $datatable .= '</table>';
8130: } elsif ($item eq 'intauth_check') {
8131: my @options = (0,1,2);
8132: my %optiondesc = &Apache::lonlocal::texthash (
8133: 0 => 'No',
8134: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8135: 2 => 'Yes, disallow login if stored cost is less than domain default',
8136: );
8137: $datatable .= '<table width="100%">';
8138: foreach my $option (@options) {
8139: my $checked = ' ';
8140: my $onclick;
8141: if ($defaults{$item} eq $option) {
8142: $checked = ' checked="checked"';
8143: }
8144: if ($option == 2) {
8145: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8146: }
8147: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8148: '<label><input type="radio" name="'.$item.
8149: '" value="'.$option.'"'.$checked.$onclick.' />'.
8150: $optiondesc{$option}.'</label></span></td></tr>';
8151: }
8152: $datatable .= '</table>';
8153: } else {
8154: $datatable .= '<input type="text" name="'.$item.'" value="'.
8155: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8156: }
8157: $datatable .= '</td></tr>';
8158: $itemcount ++;
8159: }
8160: } elsif ($position eq 'lower') {
1.405 raeburn 8161: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8162: } else {
1.359 raeburn 8163: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8164: my %ownerchg = (
8165: by => {},
8166: for => {},
8167: );
8168: my %ownertitles = &Apache::lonlocal::texthash (
8169: by => 'Course owner status(es) allowed',
8170: for => 'Student status(es) allowed',
8171: );
1.354 raeburn 8172: if (ref($settings) eq 'HASH') {
1.359 raeburn 8173: if (ref($settings->{crsownerchg}) eq 'HASH') {
8174: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8175: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8176: }
8177: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8178: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8179: }
1.354 raeburn 8180: }
8181: }
8182: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8183: $datatable .= '<tr '.$css_class.'>'.
8184: '<td>'.
8185: &mt('Requirements').'<ul>'.
1.359 raeburn 8186: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8187: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8188: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8189: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8190: '</ul>'.
8191: '</td>'.
1.359 raeburn 8192: '<td class="LC_left_item">';
8193: foreach my $item ('by','for') {
8194: $datatable .= '<fieldset style="display: inline-block;">'.
8195: '<legend>'.$ownertitles{$item}.'</legend>';
8196: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8197: foreach my $type (@{$types}) {
8198: my $checked;
8199: if ($ownerchg{$item}{$type}) {
8200: $checked = ' checked="checked"';
8201: }
8202: $datatable .= '<span class="LC_nobreak"><label>'.
8203: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8204: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8205: '</span> ';
1.359 raeburn 8206: }
8207: }
8208: my $checked;
8209: if ($ownerchg{$item}{'default'}) {
8210: $checked = ' checked="checked"';
8211: }
8212: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8213: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8214: $othertitle.'</label></span></fieldset>';
8215: }
8216: $datatable .= '</td></tr>';
1.354 raeburn 8217: }
8218: return $datatable;
8219: }
8220:
1.405 raeburn 8221: sub password_rules {
8222: my ($prefix,$itemcountref,$settings) = @_;
8223: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8224: my %titles;
8225: if ($prefix eq 'passwords') {
8226: %titles = &Apache::lonlocal::texthash (
8227: min => 'Minimum password length',
8228: max => 'Maximum password length',
8229: chars => 'Required characters',
8230: );
8231: } elsif ($prefix eq 'secrets') {
8232: %titles = &Apache::lonlocal::texthash (
8233: min => 'Minimum secret length',
8234: max => 'Maximum secret length',
8235: chars => 'Required characters',
8236: );
8237: }
8238: $min = $Apache::lonnet::passwdmin;
8239: my $datatable;
8240: my $itemcount;
8241: if (ref($itemcountref)) {
8242: $itemcount = $$itemcountref;
8243: }
8244: if (ref($settings) eq 'HASH') {
8245: if ($settings->{min}) {
8246: $min = $settings->{min};
8247: }
8248: if ($settings->{max}) {
8249: $max = $settings->{max};
8250: }
8251: if (ref($settings->{chars}) eq 'ARRAY') {
8252: map { $chars{$_} = 1; } (@{$settings->{chars}});
8253: }
8254: if ($prefix eq 'passwords') {
8255: if ($settings->{expire}) {
8256: $expire = $settings->{expire};
8257: }
8258: if ($settings->{numsaved}) {
8259: $numsaved = $settings->{numsaved};
8260: }
8261: }
8262: }
8263: my %rulenames = &Apache::lonlocal::texthash(
8264: uc => 'At least one upper case letter',
8265: lc => 'At least one lower case letter',
8266: num => 'At least one number',
8267: spec => 'At least one non-alphanumeric',
8268: );
8269: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8270: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8271: '<td class="LC_left_item"><span class="LC_nobreak">'.
8272: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8273: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8274: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8275: '</span></td></tr>';
8276: $itemcount ++;
8277: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8278: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8279: '<td class="LC_left_item"><span class="LC_nobreak">'.
8280: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8281: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8282: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8283: '</span></td></tr>';
8284: $itemcount ++;
8285: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8286: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8287: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8288: '</span></td>';
8289: my $numinrow = 2;
8290: my @possrules = ('uc','lc','num','spec');
8291: $datatable .= '<td class="LC_left_item"><table>';
8292: for (my $i=0; $i<@possrules; $i++) {
8293: my ($rem,$checked);
8294: if ($chars{$possrules[$i]}) {
8295: $checked = ' checked="checked"';
8296: }
8297: $rem = $i%($numinrow);
8298: if ($rem == 0) {
8299: if ($i > 0) {
8300: $datatable .= '</tr>';
8301: }
8302: $datatable .= '<tr>';
8303: }
8304: $datatable .= '<td><span class="LC_nobreak"><label>'.
8305: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8306: $rulenames{$possrules[$i]}.'</label></span></td>';
8307: }
8308: my $rem = @possrules%($numinrow);
8309: my $colsleft = $numinrow - $rem;
8310: if ($colsleft > 1 ) {
8311: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8312: ' </td>';
8313: } elsif ($colsleft == 1) {
8314: $datatable .= '<td class="LC_left_item"> </td>';
8315: }
8316: $datatable .='</table></td></tr>';
8317: $itemcount ++;
8318: if ($prefix eq 'passwords') {
8319: $titles{'expire'} = &mt('Password expiration (days)');
8320: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8321: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8322: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8323: '<td class="LC_left_item"><span class="LC_nobreak">'.
8324: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8325: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8326: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8327: '</span></td></tr>';
8328: $itemcount ++;
8329: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8330: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8331: '<td class="LC_left_item"><span class="LC_nobreak">'.
8332: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8333: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8334: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8335: '</span></td></tr>';
8336: $itemcount ++;
8337: }
8338: if (ref($itemcountref)) {
8339: $$itemcountref += $itemcount;
8340: }
8341: return $datatable;
8342: }
8343:
1.373 raeburn 8344: sub print_wafproxy {
8345: my ($position,$dom,$settings,$rowtotal) = @_;
8346: my $css_class;
8347: my $itemcount = 0;
8348: my $datatable;
8349: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8350: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8351: my %lt = &wafproxy_titles();
1.373 raeburn 8352: foreach my $server (sort(keys(%servers))) {
8353: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8354: next if ($serverhome eq '');
1.373 raeburn 8355: my $serverdom;
8356: if ($serverhome ne $server) {
8357: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8358: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8359: $othercontrol{$server} = $serverdom;
8360: }
1.373 raeburn 8361: } else {
8362: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8363: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8364: if ($serverdom ne $dom) {
8365: $othercontrol{$server} = $serverdom;
8366: } else {
8367: $setdom = 1;
8368: if (ref($settings) eq 'HASH') {
8369: if (ref($settings->{'alias'}) eq 'HASH') {
8370: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8371: if ($aliases{$dom} ne '') {
8372: $showdom = 1;
8373: }
1.373 raeburn 8374: }
1.388 raeburn 8375: if (ref($settings->{'saml'}) eq 'HASH') {
8376: $saml{$dom} = $settings->{'saml'};
8377: }
1.373 raeburn 8378: }
8379: }
8380: }
8381: }
1.381 raeburn 8382: if ($setdom) {
8383: %{$values{$dom}} = ();
8384: if (ref($settings) eq 'HASH') {
8385: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8386: $values{$dom}{$item} = $settings->{$item};
8387: }
8388: }
8389: }
1.373 raeburn 8390: if (keys(%othercontrol)) {
8391: %otherdoms = reverse(%othercontrol);
8392: foreach my $domain (keys(%otherdoms)) {
8393: %{$values{$domain}} = ();
8394: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8395: if (ref($config{'wafproxy'}) eq 'HASH') {
8396: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 8397: if (exists($config{'wafproxy'}{'saml'})) {
8398: $saml{$domain} = $config{'wafproxy'}{'saml'};
8399: }
1.383 raeburn 8400: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8401: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8402: }
8403: }
8404: }
8405: }
8406: if ($position eq 'top') {
8407: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8408: my %aliasinfo;
1.373 raeburn 8409: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8410: $itemcount ++;
8411: my $dom_in_effect;
8412: my $aliasrows = '<tr>'.
1.383 raeburn 8413: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8414: &mt('Hostname').': '.
8415: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8416: if ($othercontrol{$server}) {
1.381 raeburn 8417: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8418: my ($current,$forsaml);
1.383 raeburn 8419: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8420: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8421: }
1.388 raeburn 8422: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8423: if ($saml{$dom_in_effect}{$server}) {
8424: $forsaml = 1;
8425: }
8426: }
1.383 raeburn 8427: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8428: &mt('Alias').': ';
1.373 raeburn 8429: if ($current) {
1.381 raeburn 8430: $aliasrows .= $current;
1.388 raeburn 8431: if ($forsaml) {
1.396 raeburn 8432: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8433: }
1.373 raeburn 8434: } else {
1.383 raeburn 8435: $aliasrows .= &mt('None');
1.373 raeburn 8436: }
1.383 raeburn 8437: $aliasrows .= ' <span class="LC_small">('.
8438: &mt('controlled by domain: [_1]',
8439: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8440: } else {
1.381 raeburn 8441: $dom_in_effect = $dom;
1.388 raeburn 8442: my ($current,$samlon,$samloff);
8443: $samloff = ' checked="checked"';
1.373 raeburn 8444: if (ref($aliases{$dom}) eq 'HASH') {
8445: if ($aliases{$dom}{$server}) {
8446: $current = $aliases{$dom}{$server};
8447: }
8448: }
1.388 raeburn 8449: if (ref($saml{$dom}) eq 'HASH') {
8450: if ($saml{$dom}{$server}) {
8451: $samlon = $samloff;
8452: undef($samloff);
8453: }
8454: }
1.383 raeburn 8455: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8456: &mt('Alias').': '.
1.381 raeburn 8457: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8458: 'value="'.$current.'" size="30" />'.
8459: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8460: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8461: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
8462: &mt('No').'</label> <label>'.
8463: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8464: &mt('Yes').'</label></span>'.
8465: '</td>';
1.381 raeburn 8466: }
8467: $aliasrows .= '</tr>';
8468: $aliasinfo{$dom_in_effect} .= $aliasrows;
8469: }
8470: if ($aliasinfo{$dom}) {
8471: my ($onclick,$wafon,$wafoff,$showtable);
8472: $onclick = ' onclick="javascript:toggleWAF();"';
8473: $wafoff = ' checked="checked"';
8474: $showtable = ' style="display:none";';
8475: if ($showdom) {
8476: $wafon = $wafoff;
8477: $wafoff = '';
8478: $showtable = ' style="display:inline;"';
8479: }
8480: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8481: $datatable = '<tr'.$css_class.'>'.
8482: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8483: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8484: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8485: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8486: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8487: &mt('No').'</label></span></td>'.
8488: '<td class="LC_left_item">'.
8489: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8490: '</table></td></tr>';
8491: $itemcount++;
8492: }
1.383 raeburn 8493: if (keys(%otherdoms)) {
8494: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8495: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8496: $datatable .= '<tr'.$css_class.'>'.
8497: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8498: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8499: '</table></td></tr>';
1.381 raeburn 8500: $itemcount++;
1.373 raeburn 8501: }
8502: }
8503: } else {
1.383 raeburn 8504: my %ip_methods = &remoteip_methods();
1.373 raeburn 8505: if ($setdom) {
8506: $itemcount ++;
8507: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8508: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8509: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8510: $wafstyle = ' style="display:none;"';
8511: $nowafstyle = ' style="display:table-row;"';
8512: $currwafdisplay = ' style="display: none"';
8513: $wafrangestyle = ' style="display: none"';
8514: $curr_remotip = 'n';
1.382 raeburn 8515: $ssltossl = ' checked="checked"';
1.381 raeburn 8516: if ($showdom) {
8517: $wafstyle = ' style="display:table-row;"';
8518: $nowafstyle = ' style="display:none;"';
8519: if (keys(%{$values{$dom}})) {
8520: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8521: $curr_remotip = $values{$dom}{remoteip};
8522: }
8523: if ($curr_remotip eq 'h') {
8524: $currwafdisplay = ' style="display:table-row"';
8525: $wafrangestyle = ' style="display:inline-block;"';
8526: }
1.382 raeburn 8527: if ($values{$dom}{'sslopt'}) {
8528: $alltossl = ' checked="checked"';
8529: $ssltossl = '';
8530: }
1.381 raeburn 8531: }
8532: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8533: $vpndircheck = ' checked="checked"';
8534: $currwafvpn = ' style="display:table-row;"';
8535: $wafrangestyle = ' style="display:inline-block;"';
8536: } else {
8537: $vpnaliascheck = ' checked="checked"';
8538: $currwafvpn = ' style="display:none;"';
8539: }
8540: }
8541: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8542: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8543: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8544: '</tr>'.
8545: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8546: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8547: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8548: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8549: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8550: '<td class="LC_left_item"><table>'.
8551: '<tr>'.
8552: '<td valign="top">'.$lt{'remoteip'}.': '.
8553: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8554: foreach my $option ('m','h','n') {
8555: my $sel;
8556: if ($option eq $curr_remotip) {
8557: $sel = ' selected="selected"';
8558: }
8559: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8560: $ip_methods{$option}.'</option>';
8561: }
8562: $datatable .= '</select></td></tr>'."\n".
8563: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8564: $lt{'ipheader'}.': '.
8565: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8566: 'name="wafproxy_ipheader" />'.
8567: '</td></tr>'."\n".
8568: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8569: $lt{'trusted'}.':<br />'.
1.381 raeburn 8570: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8571: $values{$dom}{'trusted'}.'</textarea>'.
8572: '</td></tr>'."\n".
8573: '<tr><td><hr /></td></tr>'."\n".
8574: '<tr>'.
8575: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8576: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8577: $lt{'vpndirect'}.'</label>'.(' 'x2).
8578: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8579: $lt{'vpnaliased'}.'</label></span></td></tr>';
8580: foreach my $item ('vpnint','vpnext') {
8581: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8582: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8583: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8584: $values{$dom}{$item}.'</textarea>'.
8585: '</td></tr>'."\n";
1.373 raeburn 8586: }
1.382 raeburn 8587: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8588: '<tr>'.
8589: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8590: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8591: $lt{'alltossl'}.'</label>'.(' 'x2).
8592: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8593: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8594: '</table></td></tr>';
1.373 raeburn 8595: }
8596: if (keys(%otherdoms)) {
8597: foreach my $domain (sort(keys(%otherdoms))) {
8598: $itemcount ++;
8599: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8600: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8601: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8602: '<td class="LC_left_item"><table>';
1.382 raeburn 8603: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8604: my $showval = &mt('None');
1.382 raeburn 8605: if ($item eq 'ssl') {
8606: $showval = $lt{'ssltossl'};
8607: }
1.373 raeburn 8608: if ($values{$domain}{$item}) {
1.381 raeburn 8609: $showval = $values{$domain}{$item};
1.382 raeburn 8610: if ($item eq 'ssl') {
8611: $showval = $lt{'alltossl'};
1.383 raeburn 8612: } elsif ($item eq 'remoteip') {
8613: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8614: }
1.373 raeburn 8615: }
8616: $datatable .= '<tr>'.
8617: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8618: }
1.381 raeburn 8619: $datatable .= '</table></td></tr>';
1.373 raeburn 8620: }
8621: }
8622: }
8623: $$rowtotal += $itemcount;
8624: return $datatable;
8625: }
8626:
8627: sub wafproxy_titles {
8628: return &Apache::lonlocal::texthash(
1.381 raeburn 8629: remoteip => "Method for determining user's IP",
8630: ipheader => 'Request header containing remote IP',
8631: trusted => 'Trusted IP range(s)',
8632: vpnaccess => 'Access from institutional VPN',
8633: vpndirect => 'via regular hostname (no WAF)',
8634: vpnaliased => 'via aliased hostname (WAF)',
8635: vpnint => 'Internal IP Range(s) for VPN sessions',
8636: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8637: sslopt => 'Forwarding http/https',
1.381 raeburn 8638: alltossl => 'WAF forwards both http and https requests to https',
8639: ssltossl => 'WAF forwards http requests to http and https to https',
8640: );
8641: }
8642:
8643: sub remoteip_methods {
8644: return &Apache::lonlocal::texthash(
8645: m => 'Use Apache mod_remoteip',
8646: h => 'Use headers parsed by LON-CAPA',
8647: n => 'Not in use',
1.373 raeburn 8648: );
8649: }
8650:
1.137 raeburn 8651: sub print_usersessions {
8652: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8653: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8654: my (%by_ip,%by_location,@intdoms,@instdoms);
8655: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8656:
8657: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8658: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8659: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8660: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8661: if ($position eq 'top') {
1.152 raeburn 8662: if (keys(%serverhomes) > 1) {
1.145 raeburn 8663: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8664: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8665: if (ref($settings) eq 'HASH') {
8666: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8667: $curroffloadnow = $settings->{'offloadnow'};
8668: }
1.371 raeburn 8669: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8670: $curroffloadoth = $settings->{'offloadoth'};
8671: }
1.261 raeburn 8672: }
1.371 raeburn 8673: my $other_insts = scalar(keys(%by_location));
8674: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8675: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8676: } else {
1.140 raeburn 8677: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8678: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8679: '</td></tr>';
1.140 raeburn 8680: }
1.137 raeburn 8681: } else {
1.279 raeburn 8682: my %titles = &usersession_titles();
8683: my ($prefix,@types);
8684: if ($position eq 'bottom') {
8685: $prefix = 'remote';
8686: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8687: } else {
1.279 raeburn 8688: $prefix = 'hosted';
8689: @types = ('excludedomain','includedomain');
8690: }
8691: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8692: }
8693: $$rowtotal += $itemcount;
8694: return $datatable;
8695: }
8696:
8697: sub rules_by_location {
8698: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8699: my ($datatable,$itemcount,$css_class);
8700: if (keys(%{$by_location}) == 0) {
8701: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8702: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8703: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8704: '</td></tr>';
8705: $itemcount = 1;
8706: } else {
8707: $itemcount = 0;
8708: my $numinrow = 5;
8709: my (%current,%checkedon,%checkedoff);
8710: my @locations = sort(keys(%{$by_location}));
8711: foreach my $type (@{$types}) {
8712: $checkedon{$type} = '';
8713: $checkedoff{$type} = ' checked="checked"';
8714: }
8715: if (ref($settings) eq 'HASH') {
8716: if (ref($settings->{$prefix}) eq 'HASH') {
8717: foreach my $key (keys(%{$settings->{$prefix}})) {
8718: $current{$key} = $settings->{$prefix}{$key};
8719: if ($key eq 'version') {
8720: if ($current{$key} ne '') {
1.145 raeburn 8721: $checkedon{$key} = ' checked="checked"';
8722: $checkedoff{$key} = '';
8723: }
1.279 raeburn 8724: } elsif (ref($current{$key}) eq 'ARRAY') {
8725: $checkedon{$key} = ' checked="checked"';
8726: $checkedoff{$key} = '';
1.137 raeburn 8727: }
8728: }
8729: }
1.279 raeburn 8730: }
8731: foreach my $type (@{$types}) {
8732: next if ($type ne 'version' && !@locations);
8733: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8734: $datatable .= '<tr'.$css_class.'>
8735: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8736: <span class="LC_nobreak">
8737: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8738: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8739: if ($type eq 'version') {
8740: my @lcversions = &Apache::lonnet::all_loncaparevs();
8741: my $selector = '<select name="'.$prefix.'_version">';
8742: foreach my $version (@lcversions) {
8743: my $selected = '';
8744: if ($current{'version'} eq $version) {
8745: $selected = ' selected="selected"';
1.145 raeburn 8746: }
1.279 raeburn 8747: $selector .= ' <option value="'.$version.'"'.
8748: $selected.'>'.$version.'</option>';
8749: }
8750: $selector .= '</select> ';
8751: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8752: } else {
8753: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8754: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8755: ' />'.(' 'x2).
8756: '<input type="button" value="'.&mt('uncheck all').'" '.
8757: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8758: "\n".
8759: '</div><div><table>';
8760: my $rem;
8761: for (my $i=0; $i<@locations; $i++) {
8762: my ($showloc,$value,$checkedtype);
8763: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8764: my $ip = $by_location->{$locations[$i]}->[0];
8765: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8766: $value = join(':',@{$by_ip->{$ip}});
8767: $showloc = join(', ',@{$by_ip->{$ip}});
8768: if (ref($current{$type}) eq 'ARRAY') {
8769: foreach my $loc (@{$by_ip->{$ip}}) {
8770: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8771: $checkedtype = ' checked="checked"';
8772: last;
1.145 raeburn 8773: }
1.138 raeburn 8774: }
8775: }
8776: }
1.137 raeburn 8777: }
1.279 raeburn 8778: $rem = $i%($numinrow);
8779: if ($rem == 0) {
8780: if ($i > 0) {
8781: $datatable .= '</tr>';
8782: }
8783: $datatable .= '<tr>';
8784: }
8785: $datatable .= '<td class="LC_left_item">'.
8786: '<span class="LC_nobreak"><label>'.
8787: '<input type="checkbox" name="'.$prefix.'_'.$type.
8788: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8789: '</label></span></td>';
8790: }
8791: $rem = @locations%($numinrow);
8792: my $colsleft = $numinrow - $rem;
8793: if ($colsleft > 1 ) {
8794: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8795: ' </td>';
8796: } elsif ($colsleft == 1) {
8797: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8798: }
1.279 raeburn 8799: $datatable .= '</tr></table>';
1.137 raeburn 8800: }
1.279 raeburn 8801: $datatable .= '</td></tr>';
8802: $itemcount ++;
1.137 raeburn 8803: }
8804: }
1.279 raeburn 8805: return ($datatable,$itemcount);
1.137 raeburn 8806: }
8807:
1.275 raeburn 8808: sub print_ssl {
8809: my ($position,$dom,$settings,$rowtotal) = @_;
8810: my ($css_class,$datatable);
8811: my $itemcount = 1;
8812: if ($position eq 'top') {
1.281 raeburn 8813: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8814: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8815: my $same_institution;
8816: if ($intdom ne '') {
8817: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8818: if (ref($internet_names) eq 'ARRAY') {
8819: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8820: $same_institution = 1;
8821: }
8822: }
8823: }
1.275 raeburn 8824: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8825: $datatable = '<tr'.$css_class.'><td colspan="2">';
8826: if ($same_institution) {
8827: my %domservers = &Apache::lonnet::get_servers($dom);
8828: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8829: } else {
8830: $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.");
8831: }
8832: $datatable .= '</td></tr>';
1.275 raeburn 8833: $itemcount ++;
8834: } else {
8835: my %titles = &ssl_titles();
8836: my (%by_ip,%by_location,@intdoms,@instdoms);
8837: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8838: my @alldoms = &Apache::lonnet::all_domains();
8839: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8840: my @domservers = &Apache::lonnet::get_servers($dom);
8841: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8842: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8843: if (($position eq 'connto') || ($position eq 'connfrom')) {
8844: my $legacy;
8845: unless (ref($settings) eq 'HASH') {
8846: my $name;
8847: if ($position eq 'connto') {
8848: $name = 'loncAllowInsecure';
8849: } else {
8850: $name = 'londAllowInsecure';
8851: }
8852: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8853: my @ids=&Apache::lonnet::current_machine_ids();
8854: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8855: my %what = (
8856: $name => 1,
8857: );
8858: my ($result,$returnhash) =
8859: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8860: if ($result eq 'ok') {
8861: if (ref($returnhash) eq 'HASH') {
8862: $legacy = $returnhash->{$name};
8863: }
8864: }
8865: } else {
8866: $legacy = $Apache::lonnet::perlvar{$name};
8867: }
8868: }
1.275 raeburn 8869: foreach my $type ('dom','intdom','other') {
8870: my %checked;
8871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8872: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8873: '<td class="LC_right_item">';
8874: my $skip;
8875: if ($type eq 'dom') {
8876: unless (keys(%servers) > 1) {
8877: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8878: $skip = 1;
8879: }
8880: }
8881: if ($type eq 'intdom') {
8882: unless (@instdoms > 1) {
8883: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8884: $skip = 1;
8885: }
8886: } elsif ($type eq 'other') {
8887: if (keys(%by_location) == 0) {
8888: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8889: $skip = 1;
8890: }
8891: }
8892: unless ($skip) {
8893: $checked{'yes'} = ' checked="checked"';
8894: if (ref($settings) eq 'HASH') {
1.293 raeburn 8895: if (ref($settings->{$position}) eq 'HASH') {
8896: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8897: $checked{$1} = $checked{'yes'};
8898: delete($checked{'yes'});
8899: }
8900: }
1.293 raeburn 8901: } else {
8902: if ($legacy == 0) {
8903: $checked{'req'} = $checked{'yes'};
8904: delete($checked{'yes'});
8905: }
1.275 raeburn 8906: }
8907: foreach my $option ('no','yes','req') {
8908: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8909: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8910: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8911: '</label></span>'.(' 'x2);
8912: }
8913: }
8914: $datatable .= '</td></tr>';
8915: $itemcount ++;
8916: }
8917: } else {
8918: my $prefix = 'replication';
8919: my @types = ('certreq','nocertreq');
1.279 raeburn 8920: if (keys(%by_location) == 0) {
8921: $datatable .= '<tr'.$css_class.'><td>'.
8922: &mt('Nothing to set here, as there are no other institutions').
8923: '</td></tr>';
8924: $itemcount ++;
1.275 raeburn 8925: } else {
1.279 raeburn 8926: ($datatable,$itemcount) =
8927: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8928: }
8929: }
8930: }
8931: $$rowtotal += $itemcount;
8932: return $datatable;
8933: }
8934:
8935: sub ssl_titles {
8936: return &Apache::lonlocal::texthash (
8937: dom => 'LON-CAPA servers/VMs from same domain',
8938: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8939: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8940: connto => 'Connections to other servers',
8941: connfrom => 'Connections from other servers',
1.275 raeburn 8942: replication => 'Replicating content to other institutions',
8943: certreq => 'Client certificate required, but specific domains exempt',
8944: nocertreq => 'No client certificate required, except for specific domains',
8945: no => 'SSL not used',
8946: yes => 'SSL Optional (used if available)',
8947: req => 'SSL Required',
8948: );
1.279 raeburn 8949: }
8950:
8951: sub print_trust {
8952: my ($prefix,$dom,$settings,$rowtotal) = @_;
8953: my ($css_class,$datatable,%checked,%choices);
8954: my (%by_ip,%by_location,@intdoms,@instdoms);
8955: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8956: my $itemcount = 1;
8957: my %titles = &trust_titles();
8958: my @types = ('exc','inc');
8959: if ($prefix eq 'top') {
8960: $prefix = 'content';
8961: } elsif ($prefix eq 'bottom') {
8962: $prefix = 'msg';
8963: }
8964: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8965: $$rowtotal += $itemcount;
8966: return $datatable;
8967: }
8968:
8969: sub trust_titles {
8970: return &Apache::lonlocal::texthash(
8971: content => "Access to this domain's content by others",
8972: shared => "Access to other domain's content by this domain",
8973: enroll => "Enrollment in this domain's courses by others",
8974: othcoau => "Co-author roles in this domain for others",
8975: coaurem => "Co-author roles for this domain's users elsewhere",
8976: domroles => "Domain roles in this domain assignable to others",
8977: catalog => "Course Catalog for this domain displayed elsewhere",
8978: reqcrs => "Requests for creation of courses in this domain by others",
8979: msg => "Users in other domains can send messages to this domain",
8980: exc => "Allow all, but exclude specific domains",
8981: inc => "Deny all, but include specific domains",
8982: );
1.275 raeburn 8983: }
8984:
1.138 raeburn 8985: sub build_location_hashes {
1.275 raeburn 8986: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8987: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8988: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8989: my %iphost = &Apache::lonnet::get_iphost();
8990: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8991: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8992: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8993: foreach my $id (@{$iphost{$primary_ip}}) {
8994: my $intdom = &Apache::lonnet::internet_dom($id);
8995: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8996: push(@{$intdoms},$intdom);
8997: }
8998: }
8999: }
9000: foreach my $ip (keys(%iphost)) {
9001: if (ref($iphost{$ip}) eq 'ARRAY') {
9002: foreach my $id (@{$iphost{$ip}}) {
9003: my $location = &Apache::lonnet::internet_dom($id);
9004: if ($location) {
1.275 raeburn 9005: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9006: my $dom = &Apache::lonnet::host_domain($id);
9007: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9008: push(@{$instdoms},$dom);
9009: }
9010: next;
9011: }
1.138 raeburn 9012: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9013: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9014: push(@{$by_ip->{$ip}},$location);
9015: }
9016: } else {
9017: $by_ip->{$ip} = [$location];
9018: }
9019: }
9020: }
9021: }
9022: }
9023: foreach my $ip (sort(keys(%{$by_ip}))) {
9024: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9025: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9026: my $first = $by_ip->{$ip}->[0];
9027: if (ref($by_location->{$first}) eq 'ARRAY') {
9028: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9029: push(@{$by_location->{$first}},$ip);
9030: }
9031: } else {
9032: $by_location->{$first} = [$ip];
9033: }
9034: }
9035: }
9036: return;
9037: }
9038:
1.145 raeburn 9039: sub current_offloads_to {
9040: my ($dom,$settings,$servers) = @_;
9041: my (%spareid,%otherdomconfigs);
1.152 raeburn 9042: if (ref($servers) eq 'HASH') {
1.145 raeburn 9043: foreach my $lonhost (sort(keys(%{$servers}))) {
9044: my $gotspares;
1.152 raeburn 9045: if (ref($settings) eq 'HASH') {
9046: if (ref($settings->{'spares'}) eq 'HASH') {
9047: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9048: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9049: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9050: $gotspares = 1;
9051: }
1.145 raeburn 9052: }
9053: }
9054: unless ($gotspares) {
9055: my $gotspares;
9056: my $serverhomeID =
9057: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9058: my $serverhomedom =
9059: &Apache::lonnet::host_domain($serverhomeID);
9060: if ($serverhomedom ne $dom) {
9061: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9062: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9063: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9064: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9065: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9066: $gotspares = 1;
9067: }
9068: }
9069: } else {
9070: $otherdomconfigs{$serverhomedom} =
9071: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9072: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9073: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9074: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9075: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9076: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9077: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9078: $gotspares = 1;
9079: }
9080: }
9081: }
9082: }
9083: }
9084: }
9085: }
9086: unless ($gotspares) {
9087: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9088: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9089: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9090: } else {
9091: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9092: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9093: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9094: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9095: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9096: } else {
1.150 raeburn 9097: my %what = (
9098: spareid => 1,
9099: );
9100: my ($result,$returnhash) =
9101: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9102: if ($result eq 'ok') {
9103: if (ref($returnhash) eq 'HASH') {
9104: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9105: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9106: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9107: }
9108: }
1.145 raeburn 9109: }
9110: }
9111: }
9112: }
9113: }
9114: }
9115: return %spareid;
9116: }
9117:
9118: sub spares_row {
1.371 raeburn 9119: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9120: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9121: my $css_class;
9122: my $numinrow = 4;
9123: my $itemcount = 1;
9124: my $datatable;
1.152 raeburn 9125: my %typetitles = &sparestype_titles();
9126: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9127: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9128: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9129: my ($othercontrol,$serverdom);
9130: if ($serverhome ne $server) {
9131: $serverdom = &Apache::lonnet::host_domain($serverhome);
9132: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9133: } else {
9134: $serverdom = &Apache::lonnet::host_domain($server);
9135: if ($serverdom ne $dom) {
9136: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9137: }
9138: }
9139: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9140: my ($checkednow,$checkedoth);
1.261 raeburn 9141: if (ref($curroffloadnow) eq 'HASH') {
9142: if ($curroffloadnow->{$server}) {
9143: $checkednow = ' checked="checked"';
9144: }
9145: }
1.371 raeburn 9146: if (ref($curroffloadoth) eq 'HASH') {
9147: if ($curroffloadoth->{$server}) {
9148: $checkedoth = ' checked="checked"';
9149: }
9150: }
1.145 raeburn 9151: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9152: $datatable .= '<tr'.$css_class.'>
9153: <td rowspan="2">
1.183 bisitz 9154: <span class="LC_nobreak">'.
9155: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9156: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9157: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9158: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9159: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9160: "\n";
1.371 raeburn 9161: if ($other_insts) {
9162: $datatable .= '<br />'.
9163: '<span class="LC_nobreak">'."\n".
9164: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9165: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9166: "\n";
9167: }
1.145 raeburn 9168: my (%current,%canselect);
1.152 raeburn 9169: my @choices =
9170: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9171: foreach my $type ('primary','default') {
9172: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9173: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9174: my @spares = @{$spareid->{$server}{$type}};
9175: if (@spares > 0) {
1.152 raeburn 9176: if ($othercontrol) {
9177: $current{$type} = join(', ',@spares);
9178: } else {
9179: $current{$type} .= '<table>';
9180: my $numspares = scalar(@spares);
9181: for (my $i=0; $i<@spares; $i++) {
9182: my $rem = $i%($numinrow);
9183: if ($rem == 0) {
9184: if ($i > 0) {
9185: $current{$type} .= '</tr>';
9186: }
9187: $current{$type} .= '<tr>';
1.145 raeburn 9188: }
1.152 raeburn 9189: $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'".');" /> '.
9190: $spareid->{$server}{$type}[$i].
9191: '</label></td>'."\n";
9192: }
9193: my $rem = @spares%($numinrow);
9194: my $colsleft = $numinrow - $rem;
9195: if ($colsleft > 1 ) {
9196: $current{$type} .= '<td colspan="'.$colsleft.
9197: '" class="LC_left_item">'.
9198: ' </td>';
9199: } elsif ($colsleft == 1) {
9200: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9201: }
1.152 raeburn 9202: $current{$type} .= '</tr></table>';
1.150 raeburn 9203: }
1.145 raeburn 9204: }
9205: }
9206: if ($current{$type} eq '') {
9207: $current{$type} = &mt('None specified');
9208: }
1.152 raeburn 9209: if ($othercontrol) {
9210: if ($type eq 'primary') {
9211: $canselect{$type} = $othercontrol;
9212: }
9213: } else {
9214: $canselect{$type} =
9215: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9216: '<select name="newspare_'.$type.'_'.$server.'" '.
9217: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9218: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9219: if (@choices > 0) {
9220: foreach my $lonhost (@choices) {
9221: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9222: }
9223: }
9224: $canselect{$type} .= '</select>'."\n";
9225: }
9226: } else {
9227: $current{$type} = &mt('Could not be determined');
9228: if ($type eq 'primary') {
9229: $canselect{$type} = $othercontrol;
9230: }
1.145 raeburn 9231: }
1.152 raeburn 9232: if ($type eq 'default') {
9233: $datatable .= '<tr'.$css_class.'>';
9234: }
9235: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9236: '<td>'.$current{$type}.'</td>'."\n".
9237: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9238: }
9239: $itemcount ++;
9240: }
9241: }
9242: $$rowtotal += $itemcount;
9243: return $datatable;
9244: }
9245:
1.152 raeburn 9246: sub possible_newspares {
9247: my ($server,$currspares,$serverhomes,$altids) = @_;
9248: my $serverhostname = &Apache::lonnet::hostname($server);
9249: my %excluded;
9250: if ($serverhostname ne '') {
9251: %excluded = (
9252: $serverhostname => 1,
9253: );
9254: }
9255: if (ref($currspares) eq 'HASH') {
9256: foreach my $type (keys(%{$currspares})) {
9257: if (ref($currspares->{$type}) eq 'ARRAY') {
9258: if (@{$currspares->{$type}} > 0) {
9259: foreach my $curr (@{$currspares->{$type}}) {
9260: my $hostname = &Apache::lonnet::hostname($curr);
9261: $excluded{$hostname} = 1;
9262: }
9263: }
9264: }
9265: }
9266: }
9267: my @choices;
9268: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9269: if (keys(%{$serverhomes}) > 1) {
9270: foreach my $name (sort(keys(%{$serverhomes}))) {
9271: unless ($excluded{$name}) {
9272: if (exists($altids->{$serverhomes->{$name}})) {
9273: push(@choices,$altids->{$serverhomes->{$name}});
9274: } else {
9275: push(@choices,$serverhomes->{$name});
1.145 raeburn 9276: }
9277: }
9278: }
9279: }
9280: }
1.152 raeburn 9281: return sort(@choices);
1.145 raeburn 9282: }
9283:
1.150 raeburn 9284: sub print_loadbalancing {
9285: my ($dom,$settings,$rowtotal) = @_;
9286: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9287: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9288: my $numinrow = 1;
9289: my $datatable;
9290: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9291: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9292: if (ref($settings) eq 'HASH') {
9293: %existing = %{$settings};
9294: }
9295: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9296: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9297: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9298: } else {
9299: return;
9300: }
9301: my ($othertitle,$usertypes,$types) =
9302: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9303: my $rownum = 8;
1.150 raeburn 9304: if (ref($types) eq 'ARRAY') {
9305: $rownum += scalar(@{$types});
9306: }
1.171 raeburn 9307: my @css_class = ('LC_odd_row','LC_even_row');
9308: my $balnum = 0;
9309: my $islast;
9310: my (@toshow,$disabledtext);
9311: if (keys(%currbalancer) > 0) {
9312: @toshow = sort(keys(%currbalancer));
9313: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9314: push(@toshow,'');
9315: }
9316: } else {
9317: @toshow = ('');
9318: $disabledtext = &mt('No existing load balancer');
9319: }
9320: foreach my $lonhost (@toshow) {
9321: if ($balnum == scalar(@toshow)-1) {
9322: $islast = 1;
9323: } else {
9324: $islast = 0;
9325: }
9326: my $cssidx = $balnum%2;
9327: my $targets_div_style = 'display: none';
9328: my $disabled_div_style = 'display: block';
9329: my $homedom_div_style = 'display: none';
9330: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9331: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9332: '<p>';
9333: if ($lonhost eq '') {
1.210 raeburn 9334: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9335: if (keys(%currbalancer) > 0) {
9336: $datatable .= &mt('Add balancer:');
9337: } else {
9338: $datatable .= &mt('Enable balancer:');
9339: }
9340: $datatable .= ' '.
9341: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9342: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9343: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9344: '<option value="" selected="selected">'.&mt('None').
9345: '</option>'."\n";
9346: foreach my $server (sort(keys(%servers))) {
9347: next if ($currbalancer{$server});
9348: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9349: }
1.210 raeburn 9350: $datatable .=
1.171 raeburn 9351: '</select>'."\n".
9352: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9353: } else {
9354: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9355: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9356: &mt('Stop balancing').'</label>'.
9357: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9358: $targets_div_style = 'display: block';
9359: $disabled_div_style = 'display: none';
9360: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9361: $homedom_div_style = 'display: block';
9362: }
9363: }
1.306 raeburn 9364: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9365: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9366: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9367: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9368: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9369: my @sparestypes = ('primary','default');
9370: my %typetitles = &sparestype_titles();
1.284 raeburn 9371: my %hostherechecked = (
9372: no => ' checked="checked"',
9373: );
1.342 raeburn 9374: my %balcookiechecked = (
9375: no => ' checked="checked"',
9376: );
1.171 raeburn 9377: foreach my $sparetype (@sparestypes) {
9378: my $targettable;
9379: for (my $i=0; $i<$numspares; $i++) {
9380: my $checked;
9381: if (ref($currtargets{$lonhost}) eq 'HASH') {
9382: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9383: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9384: $checked = ' checked="checked"';
9385: }
9386: }
9387: }
9388: my ($chkboxval,$disabled);
9389: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9390: $chkboxval = $spares[$i];
9391: }
9392: if (exists($currbalancer{$spares[$i]})) {
9393: $disabled = ' disabled="disabled"';
9394: }
1.210 raeburn 9395: $targettable .=
1.253 raeburn 9396: '<td><span class="LC_nobreak"><label>'.
9397: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9398: $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 9399: '</span></label></span></td>';
1.171 raeburn 9400: my $rem = $i%($numinrow);
9401: if ($rem == 0) {
9402: if (($i > 0) && ($i < $numspares-1)) {
9403: $targettable .= '</tr>';
9404: }
9405: if ($i < $numspares-1) {
9406: $targettable .= '<tr>';
1.150 raeburn 9407: }
9408: }
9409: }
1.171 raeburn 9410: if ($targettable ne '') {
9411: my $rem = $numspares%($numinrow);
9412: my $colsleft = $numinrow - $rem;
9413: if ($colsleft > 1 ) {
9414: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9415: ' </td>';
9416: } elsif ($colsleft == 1) {
9417: $targettable .= '<td class="LC_left_item"> </td>';
9418: }
9419: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9420: '<table><tr>'.$targettable.'</tr></table><br />';
9421: }
1.284 raeburn 9422: $hostherechecked{$sparetype} = '';
9423: if (ref($currtargets{$lonhost}) eq 'HASH') {
9424: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9425: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9426: $hostherechecked{$sparetype} = ' checked="checked"';
9427: $hostherechecked{'no'} = '';
9428: }
9429: }
9430: }
9431: }
1.342 raeburn 9432: if ($currcookies{$lonhost}) {
9433: %balcookiechecked = (
9434: yes => ' checked="checked"',
9435: );
9436: }
1.284 raeburn 9437: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9438: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9439: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9440: foreach my $sparetype (@sparestypes) {
9441: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9442: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9443: '</i></label><br />';
1.171 raeburn 9444: }
1.342 raeburn 9445: $datatable .= &mt('Use balancer cookie').'<br />'.
9446: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9447: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9448: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9449: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9450: '</div></td></tr>'.
1.171 raeburn 9451: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9452: $othertitle,$usertypes,$types,\%servers,
9453: \%currbalancer,$lonhost,
9454: $targets_div_style,$homedom_div_style,
9455: $css_class[$cssidx],$balnum,$islast);
9456: $$rowtotal += $rownum;
9457: $balnum ++;
9458: }
9459: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9460: return $datatable;
9461: }
9462:
9463: sub get_loadbalancers_config {
1.342 raeburn 9464: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9465: return unless ((ref($servers) eq 'HASH') &&
9466: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9467: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9468: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9469: if (keys(%{$existing}) > 0) {
9470: my $oldlonhost;
9471: foreach my $key (sort(keys(%{$existing}))) {
9472: if ($key eq 'lonhost') {
9473: $oldlonhost = $existing->{'lonhost'};
9474: $currbalancer->{$oldlonhost} = 1;
9475: } elsif ($key eq 'targets') {
9476: if ($oldlonhost) {
9477: $currtargets->{$oldlonhost} = $existing->{'targets'};
9478: }
9479: } elsif ($key eq 'rules') {
9480: if ($oldlonhost) {
9481: $currrules->{$oldlonhost} = $existing->{'rules'};
9482: }
9483: } elsif (ref($existing->{$key}) eq 'HASH') {
9484: $currbalancer->{$key} = 1;
9485: $currtargets->{$key} = $existing->{$key}{'targets'};
9486: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9487: if ($existing->{$key}{'cookie'}) {
9488: $currcookies->{$key} = 1;
9489: }
1.150 raeburn 9490: }
9491: }
1.171 raeburn 9492: } else {
9493: my ($balancerref,$targetsref) =
9494: &Apache::lonnet::get_lonbalancer_config($servers);
9495: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9496: foreach my $server (sort(keys(%{$balancerref}))) {
9497: $currbalancer->{$server} = 1;
9498: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9499: }
9500: }
9501: }
1.171 raeburn 9502: return;
1.150 raeburn 9503: }
9504:
9505: sub loadbalancing_rules {
9506: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9507: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9508: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9509: my $output;
1.171 raeburn 9510: my $num = 0;
1.210 raeburn 9511: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9512: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9513: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9514: foreach my $type (@{$alltypes}) {
1.171 raeburn 9515: $num ++;
1.150 raeburn 9516: my $current;
9517: if (ref($currrules) eq 'HASH') {
9518: $current = $currrules->{$type};
9519: }
1.253 raeburn 9520: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9521: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9522: $current = '';
9523: }
9524: }
9525: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9526: $servers,$currbalancer,$lonhost,$dom,
9527: $targets_div_style,$homedom_div_style,
9528: $css_class,$balnum,$num,$islast);
1.150 raeburn 9529: }
9530: }
9531: return $output;
9532: }
9533:
9534: sub loadbalancing_titles {
9535: my ($dom,$intdom,$usertypes,$types) = @_;
9536: my %othertypes = (
9537: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9538: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9539: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9540: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9541: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9542: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9543: );
1.209 raeburn 9544: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9545: my @available;
1.150 raeburn 9546: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9547: @available = @{$types};
1.150 raeburn 9548: }
1.302 raeburn 9549: unless (grep(/^default$/,@available)) {
9550: push(@available,'default');
9551: }
9552: unshift(@alltypes,@available);
1.150 raeburn 9553: my %titles;
9554: foreach my $type (@alltypes) {
9555: if ($type =~ /^_LC_/) {
9556: $titles{$type} = $othertypes{$type};
9557: } elsif ($type eq 'default') {
9558: $titles{$type} = &mt('All users from [_1]',$dom);
9559: if (ref($types) eq 'ARRAY') {
9560: if (@{$types} > 0) {
9561: $titles{$type} = &mt('Other users from [_1]',$dom);
9562: }
9563: }
9564: } elsif (ref($usertypes) eq 'HASH') {
9565: $titles{$type} = $usertypes->{$type};
9566: }
9567: }
9568: return (\@alltypes,\%othertypes,\%titles);
9569: }
9570:
9571: sub loadbalance_rule_row {
1.171 raeburn 9572: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9573: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9574: my @rulenames;
1.150 raeburn 9575: my %ruletitles = &offloadtype_text();
1.209 raeburn 9576: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9577: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9578: } else {
1.209 raeburn 9579: @rulenames = ('default','homeserver');
9580: if ($type eq '_LC_external') {
9581: push(@rulenames,'externalbalancer');
9582: } else {
9583: push(@rulenames,'specific');
9584: }
9585: push(@rulenames,'none');
1.150 raeburn 9586: }
9587: my $style = $targets_div_style;
1.253 raeburn 9588: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9589: $style = $homedom_div_style;
9590: }
1.171 raeburn 9591: my $space;
9592: if ($islast && $num == 1) {
1.317 raeburn 9593: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9594: }
1.210 raeburn 9595: my $output =
1.306 raeburn 9596: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9597: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9598: '<td valaign="top">'.$space.
9599: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9600: for (my $i=0; $i<@rulenames; $i++) {
9601: my $rule = $rulenames[$i];
9602: my ($checked,$extra);
9603: if ($rulenames[$i] eq 'default') {
9604: $rule = '';
9605: }
9606: if ($rulenames[$i] eq 'specific') {
9607: if (ref($servers) eq 'HASH') {
9608: my $default;
9609: if (($current ne '') && (exists($servers->{$current}))) {
9610: $checked = ' checked="checked"';
9611: }
9612: unless ($checked) {
9613: $default = ' selected="selected"';
9614: }
1.210 raeburn 9615: $extra =
1.171 raeburn 9616: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9617: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9618: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9619: '<option value=""'.$default.'></option>'."\n";
9620: foreach my $server (sort(keys(%{$servers}))) {
9621: if (ref($currbalancer) eq 'HASH') {
9622: next if (exists($currbalancer->{$server}));
9623: }
1.150 raeburn 9624: my $selected;
1.171 raeburn 9625: if ($server eq $current) {
1.150 raeburn 9626: $selected = ' selected="selected"';
9627: }
1.171 raeburn 9628: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9629: }
9630: $extra .= '</select>';
9631: }
9632: } elsif ($rule eq $current) {
9633: $checked = ' checked="checked"';
9634: }
9635: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9636: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9637: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9638: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9639: ')"'.$checked.' /> ';
9640: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9641: $output .= $ruletitles{'particular'};
9642: } else {
9643: $output .= $ruletitles{$rulenames[$i]};
9644: }
9645: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9646: }
9647: $output .= '</div></td></tr>'."\n";
9648: return $output;
9649: }
9650:
9651: sub offloadtype_text {
9652: my %ruletitles = &Apache::lonlocal::texthash (
9653: 'default' => 'Offloads to default destinations',
9654: 'homeserver' => "Offloads to user's home server",
9655: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9656: 'specific' => 'Offloads to specific server',
1.161 raeburn 9657: 'none' => 'No offload',
1.209 raeburn 9658: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9659: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9660: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9661: );
9662: return %ruletitles;
9663: }
9664:
9665: sub sparestype_titles {
9666: my %typestitles = &Apache::lonlocal::texthash (
9667: 'primary' => 'primary',
9668: 'default' => 'default',
9669: );
9670: return %typestitles;
9671: }
9672:
1.28 raeburn 9673: sub contact_titles {
9674: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9675: 'supportemail' => 'Support E-mail address',
9676: 'adminemail' => 'Default Server Admin E-mail address',
9677: 'errormail' => 'Error reports to be e-mailed to',
9678: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9679: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9680: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9681: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9682: 'requestsmail' => 'E-mail from course requests requiring approval',
9683: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9684: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9685: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9686: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9687: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9688: 'errorweights' => 'Weights used to compute error count',
9689: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9690: );
9691: my %short_titles = &Apache::lonlocal::texthash (
9692: adminemail => 'Admin E-mail address',
9693: supportemail => 'Support E-mail',
9694: );
9695: return (\%titles,\%short_titles);
9696: }
9697:
1.286 raeburn 9698: sub helpform_fields {
9699: my %titles = &Apache::lonlocal::texthash (
9700: 'username' => 'Name',
9701: 'user' => 'Username/domain',
9702: 'phone' => 'Phone',
9703: 'cc' => 'Cc e-mail',
9704: 'course' => 'Course Details',
9705: 'section' => 'Sections',
1.289 raeburn 9706: 'screenshot' => 'File upload',
1.286 raeburn 9707: );
9708: my @fields = ('username','phone','user','course','section','cc','screenshot');
9709: my %possoptions = (
9710: username => ['yes','no','req'],
1.289 raeburn 9711: phone => ['yes','no','req'],
1.286 raeburn 9712: user => ['yes','no'],
1.289 raeburn 9713: cc => ['yes','no'],
1.286 raeburn 9714: course => ['yes','no'],
9715: section => ['yes','no'],
9716: screenshot => ['yes','no'],
9717: );
9718: my %fieldoptions = &Apache::lonlocal::texthash (
9719: 'yes' => 'Optional',
9720: 'req' => 'Required',
9721: 'no' => "Not shown",
9722: );
9723: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9724: }
9725:
1.72 raeburn 9726: sub tool_titles {
9727: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9728: aboutme => 'Personal web page',
1.86 raeburn 9729: blog => 'Blog',
1.162 raeburn 9730: webdav => 'WebDAV',
1.86 raeburn 9731: portfolio => 'Portfolio',
1.413 raeburn 9732: timezone => 'Can set time zone',
1.88 bisitz 9733: official => 'Official courses (with institutional codes)',
9734: unofficial => 'Unofficial courses',
1.98 raeburn 9735: community => 'Communities',
1.216 raeburn 9736: textbook => 'Textbook courses',
1.271 raeburn 9737: placement => 'Placement tests',
1.86 raeburn 9738: );
1.72 raeburn 9739: return %titles;
9740: }
9741:
1.101 raeburn 9742: sub courserequest_titles {
9743: my %titles = &Apache::lonlocal::texthash (
9744: official => 'Official',
9745: unofficial => 'Unofficial',
9746: community => 'Communities',
1.216 raeburn 9747: textbook => 'Textbook',
1.271 raeburn 9748: placement => 'Placement tests',
1.325 raeburn 9749: lti => 'LTI Provider',
1.101 raeburn 9750: norequest => 'Not allowed',
1.325 raeburn 9751: approval => 'Approval by DC',
1.101 raeburn 9752: validate => 'With validation',
9753: autolimit => 'Numerical limit',
1.103 raeburn 9754: unlimited => '(blank for unlimited)',
1.101 raeburn 9755: );
9756: return %titles;
9757: }
9758:
1.163 raeburn 9759: sub authorrequest_titles {
9760: my %titles = &Apache::lonlocal::texthash (
9761: norequest => 'Not allowed',
9762: approval => 'Approval by Dom. Coord.',
9763: automatic => 'Automatic approval',
9764: );
9765: return %titles;
1.210 raeburn 9766: }
1.163 raeburn 9767:
1.101 raeburn 9768: sub courserequest_conditions {
9769: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9770: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9771: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9772: );
9773: return %conditions;
9774: }
9775:
9776:
1.27 raeburn 9777: sub print_usercreation {
1.30 raeburn 9778: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9779: my $numinrow = 4;
1.28 raeburn 9780: my $datatable;
9781: if ($position eq 'top') {
1.30 raeburn 9782: $$rowtotal ++;
1.34 raeburn 9783: my $rowcount = 0;
1.32 raeburn 9784: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9785: if (ref($rules) eq 'HASH') {
9786: if (keys(%{$rules}) > 0) {
1.32 raeburn 9787: $datatable .= &user_formats_row('username',$settings,$rules,
9788: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9789: $$rowtotal ++;
1.32 raeburn 9790: $rowcount ++;
9791: }
9792: }
9793: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9794: if (ref($idrules) eq 'HASH') {
9795: if (keys(%{$idrules}) > 0) {
9796: $datatable .= &user_formats_row('id',$settings,$idrules,
9797: $idruleorder,$numinrow,$rowcount);
9798: $$rowtotal ++;
9799: $rowcount ++;
1.28 raeburn 9800: }
9801: }
1.39 raeburn 9802: if ($rowcount == 0) {
9803: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9804: $$rowtotal ++;
9805: $rowcount ++;
9806: }
1.34 raeburn 9807: } elsif ($position eq 'middle') {
1.224 raeburn 9808: my @creators = ('author','course','requestcrs');
1.37 raeburn 9809: my ($rules,$ruleorder) =
9810: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9811: my %lt = &usercreation_types();
9812: my %checked;
9813: if (ref($settings) eq 'HASH') {
9814: if (ref($settings->{'cancreate'}) eq 'HASH') {
9815: foreach my $item (@creators) {
9816: $checked{$item} = $settings->{'cancreate'}{$item};
9817: }
9818: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9819: foreach my $item (@creators) {
9820: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9821: $checked{$item} = 'none';
9822: }
9823: }
9824: }
9825: }
9826: my $rownum = 0;
9827: foreach my $item (@creators) {
9828: $rownum ++;
1.224 raeburn 9829: if ($checked{$item} eq '') {
9830: $checked{$item} = 'any';
1.34 raeburn 9831: }
9832: my $css_class;
9833: if ($rownum%2) {
9834: $css_class = '';
9835: } else {
9836: $css_class = ' class="LC_odd_row" ';
9837: }
9838: $datatable .= '<tr'.$css_class.'>'.
9839: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9840: '</span></td><td style="text-align: right">';
1.224 raeburn 9841: my @options = ('any');
9842: if (ref($rules) eq 'HASH') {
9843: if (keys(%{$rules}) > 0) {
9844: push(@options,('official','unofficial'));
1.37 raeburn 9845: }
9846: }
1.224 raeburn 9847: push(@options,'none');
1.37 raeburn 9848: foreach my $option (@options) {
1.50 raeburn 9849: my $type = 'radio';
1.34 raeburn 9850: my $check = ' ';
1.224 raeburn 9851: if ($checked{$item} eq $option) {
9852: $check = ' checked="checked" ';
1.34 raeburn 9853: }
9854: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9855: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9856: $item.'" value="'.$option.'"'.$check.'/> '.
9857: $lt{$option}.'</label> </span>';
9858: }
9859: $datatable .= '</td></tr>';
9860: }
1.28 raeburn 9861: } else {
9862: my @contexts = ('author','course','domain');
1.325 raeburn 9863: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9864: my %checked;
9865: if (ref($settings) eq 'HASH') {
9866: if (ref($settings->{'authtypes'}) eq 'HASH') {
9867: foreach my $item (@contexts) {
9868: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9869: foreach my $auth (@authtypes) {
9870: if ($settings->{'authtypes'}{$item}{$auth}) {
9871: $checked{$item}{$auth} = ' checked="checked" ';
9872: }
9873: }
9874: }
9875: }
1.27 raeburn 9876: }
1.35 raeburn 9877: } else {
9878: foreach my $item (@contexts) {
1.36 raeburn 9879: foreach my $auth (@authtypes) {
1.35 raeburn 9880: $checked{$item}{$auth} = ' checked="checked" ';
9881: }
9882: }
1.27 raeburn 9883: }
1.28 raeburn 9884: my %title = &context_names();
9885: my %authname = &authtype_names();
9886: my $rownum = 0;
9887: my $css_class;
9888: foreach my $item (@contexts) {
9889: if ($rownum%2) {
9890: $css_class = '';
9891: } else {
9892: $css_class = ' class="LC_odd_row" ';
9893: }
1.30 raeburn 9894: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9895: '<td>'.$title{$item}.
9896: '</td><td class="LC_left_item">'.
9897: '<span class="LC_nobreak">';
9898: foreach my $auth (@authtypes) {
9899: $datatable .= '<label>'.
9900: '<input type="checkbox" name="'.$item.'_auth" '.
9901: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9902: $authname{$auth}.'</label> ';
9903: }
9904: $datatable .= '</span></td></tr>';
9905: $rownum ++;
1.27 raeburn 9906: }
1.30 raeburn 9907: $$rowtotal += $rownum;
1.27 raeburn 9908: }
9909: return $datatable;
9910: }
9911:
1.224 raeburn 9912: sub print_selfcreation {
9913: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9914: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9915: $emaildomain,$datatable);
1.224 raeburn 9916: if (ref($settings) eq 'HASH') {
9917: if (ref($settings->{'cancreate'}) eq 'HASH') {
9918: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9919: if (ref($createsettings) eq 'HASH') {
9920: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9921: @selfcreate = @{$createsettings->{'selfcreate'}};
9922: } elsif ($createsettings->{'selfcreate'} ne '') {
9923: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9924: @selfcreate = ('email','login','sso');
9925: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9926: @selfcreate = ($createsettings->{'selfcreate'});
9927: }
9928: }
9929: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9930: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9931: }
1.305 raeburn 9932: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9933: $emailoptions = $createsettings->{'emailoptions'};
9934: }
1.303 raeburn 9935: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9936: $emailverified = $createsettings->{'emailverified'};
9937: }
9938: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9939: $emaildomain = $createsettings->{'emaildomain'};
9940: }
1.224 raeburn 9941: }
9942: }
9943: }
9944: my %radiohash;
9945: my $numinrow = 4;
9946: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9947: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9948: if ($position eq 'top') {
9949: my %choices = &Apache::lonlocal::texthash (
9950: cancreate_login => 'Institutional Login',
9951: cancreate_sso => 'Institutional Single Sign On',
9952: );
9953: my @toggles = sort(keys(%choices));
9954: my %defaultchecked = (
9955: 'cancreate_login' => 'off',
9956: 'cancreate_sso' => 'off',
9957: );
1.228 raeburn 9958: my ($onclick,$itemcount);
1.224 raeburn 9959: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9960: \%choices,$itemcount,$onclick);
1.228 raeburn 9961: $$rowtotal += $itemcount;
9962:
1.224 raeburn 9963: if (ref($usertypes) eq 'HASH') {
9964: if (keys(%{$usertypes}) > 0) {
9965: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9966: $dom,$numinrow,$othertitle,
1.305 raeburn 9967: 'statustocreate',$rowtotal);
1.224 raeburn 9968: $$rowtotal ++;
9969: }
9970: }
1.240 raeburn 9971: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9972: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9973: $fieldtitles{'inststatus'} = &mt('Institutional status');
9974: my $rem;
9975: my $numperrow = 2;
9976: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9977: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9978: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9979: '<td class="LC_left_item">'."\n".
1.334 raeburn 9980: '<table>'."\n";
1.240 raeburn 9981: for (my $i=0; $i<@fields; $i++) {
9982: $rem = $i%($numperrow);
9983: if ($rem == 0) {
9984: if ($i > 0) {
9985: $datatable .= '</tr>';
9986: }
9987: $datatable .= '<tr>';
9988: }
9989: my $currval;
1.248 raeburn 9990: if (ref($createsettings) eq 'HASH') {
9991: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9992: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9993: }
1.240 raeburn 9994: }
9995: $datatable .= '<td class="LC_left_item">'.
9996: '<span class="LC_nobreak">'.
9997: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9998: 'value="'.$currval.'" size="10" /> '.
9999: $fieldtitles{$fields[$i]}.'</span></td>';
10000: }
10001: my $colsleft = $numperrow - $rem;
10002: if ($colsleft > 1 ) {
10003: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10004: ' </td>';
10005: } elsif ($colsleft == 1) {
10006: $datatable .= '<td class="LC_left_item"> </td>';
10007: }
10008: $datatable .= '</tr></table></td></tr>';
10009: $$rowtotal ++;
1.224 raeburn 10010: } elsif ($position eq 'middle') {
10011: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10012: my @posstypes;
1.224 raeburn 10013: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10014: @posstypes = @{$types};
10015: }
10016: unless (grep(/^default$/,@posstypes)) {
10017: push(@posstypes,'default');
10018: }
10019: my %usertypeshash;
10020: if (ref($usertypes) eq 'HASH') {
10021: %usertypeshash = %{$usertypes};
10022: }
10023: $usertypeshash{'default'} = $othertitle;
10024: foreach my $status (@posstypes) {
10025: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10026: $numinrow,$$rowtotal,\%usertypeshash);
10027: $$rowtotal ++;
1.224 raeburn 10028: }
10029: } else {
1.236 raeburn 10030: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10031: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10032: );
10033: my @toggles = sort(keys(%choices));
10034: my %defaultchecked = (
10035: 'cancreate_email' => 'off',
10036: );
1.305 raeburn 10037: my $customclass = 'LC_selfcreate_email';
10038: my $classprefix = 'LC_canmodify_emailusername_';
10039: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10040: my $display = 'none';
1.305 raeburn 10041: my $rowstyle = 'display:none';
1.236 raeburn 10042: if (grep(/^\Qemail\E$/,@selfcreate)) {
10043: $display = 'block';
1.305 raeburn 10044: $rowstyle = 'display:table-row';
1.236 raeburn 10045: }
1.305 raeburn 10046: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10047: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10048: \%choices,$$rowtotal,$onclick);
10049: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10050: $rowstyle);
10051: $$rowtotal ++;
10052: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10053: $rowstyle);
10054: $$rowtotal ++;
10055: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10056: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10057: my ($emailrules,$emailruleorder) =
10058: &Apache::lonnet::inst_userrules($dom,'email');
10059: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10060: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10061: if (ref($types) eq 'ARRAY') {
10062: @posstypes = @{$types};
10063: }
10064: if (@posstypes) {
10065: unless (grep(/^default$/,@posstypes)) {
10066: push(@posstypes,'default');
1.302 raeburn 10067: }
10068: if (ref($usertypes) eq 'HASH') {
10069: %usertypeshash = %{$usertypes};
10070: }
1.305 raeburn 10071: my $currassign;
10072: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10073: $currassign = {
10074: selfassign => $domdefaults{'inststatusguest'},
10075: };
10076: @ordered = @{$domdefaults{'inststatusguest'}};
10077: } else {
10078: $currassign = { selfassign => [] };
10079: }
10080: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10081: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10082: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10083: $numinrow,$othertitle,'selfassign',
10084: $rowtotal,$onclicktypes,$customclass,
10085: $rowstyle);
10086: $$rowtotal ++;
1.302 raeburn 10087: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10088: foreach my $status (@posstypes) {
10089: my $css_class;
10090: if ($$rowtotal%2) {
10091: $css_class = 'LC_odd_row ';
10092: }
10093: $css_class .= $customclass;
10094: my $rowid = $optionsprefix.$status;
10095: my $hidden = 1;
10096: my $currstyle = 'display:none';
10097: if (grep(/^\Q$status\E$/,@ordered)) {
10098: $currstyle = $rowstyle;
10099: $hidden = 0;
10100: }
10101: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10102: $emailrules,$emailruleorder,$settings,$status,$rowid,
10103: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10104: unless ($hidden) {
10105: $$rowtotal ++;
10106: }
1.224 raeburn 10107: }
1.302 raeburn 10108: } else {
1.305 raeburn 10109: my $css_class;
10110: if ($$rowtotal%2) {
10111: $css_class = 'LC_odd_row ';
10112: }
10113: $css_class .= $customclass;
1.302 raeburn 10114: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10115: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10116: $emailrules,$emailruleorder,$settings,'default','',
10117: $othertitle,$css_class,$rowstyle,$intdom);
10118: $$rowtotal ++;
1.224 raeburn 10119: }
10120: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10121: $numinrow = 1;
1.305 raeburn 10122: if (@posstypes) {
10123: foreach my $status (@posstypes) {
10124: my $rowid = $classprefix.$status;
10125: my $datarowstyle = 'display:none';
10126: if (grep(/^\Q$status\E$/,@ordered)) {
10127: $datarowstyle = $rowstyle;
10128: }
10129: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10130: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10131: $infotitles,$rowid,$customclass,$datarowstyle);
10132: unless ($datarowstyle eq 'display:none') {
10133: $$rowtotal ++;
10134: }
1.224 raeburn 10135: }
1.305 raeburn 10136: } else {
10137: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10138: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10139: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10140: }
10141: }
10142: return $datatable;
10143: }
10144:
1.305 raeburn 10145: sub selfcreate_javascript {
10146: return <<"ENDSCRIPT";
10147:
10148: <script type="text/javascript">
10149: // <![CDATA[
10150:
10151: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10152: var x = document.getElementsByClassName(target);
10153: var insttypes = 0;
10154: var insttypeRegExp = new RegExp(prefix);
10155: if ((x.length != undefined) && (x.length > 0)) {
10156: if (form.elements[radio].length != undefined) {
10157: for (var i=0; i<form.elements[radio].length; i++) {
10158: if (form.elements[radio][i].checked) {
10159: if (form.elements[radio][i].value == 1) {
10160: for (var j=0; j<x.length; j++) {
10161: if (x[j].id == 'undefined') {
10162: x[j].style.display = 'table-row';
10163: } else if (insttypeRegExp.test(x[j].id)) {
10164: insttypes ++;
10165: } else {
10166: x[j].style.display = 'table-row';
10167: }
10168: }
10169: } else {
10170: for (var j=0; j<x.length; j++) {
10171: x[j].style.display = 'none';
10172: }
1.236 raeburn 10173: }
1.305 raeburn 10174: break;
10175: }
10176: }
10177: if (insttypes > 0) {
10178: toggleDataRow(form,checkbox,target,altprefix);
10179: toggleDataRow(form,checkbox,target,prefix,1);
10180: }
10181: }
10182: }
10183: return;
10184: }
10185:
10186: function toggleDataRow(form,checkbox,target,prefix,docount) {
10187: if (form.elements[checkbox].length != undefined) {
10188: var count = 0;
10189: if (docount) {
10190: for (var i=0; i<form.elements[checkbox].length; i++) {
10191: if (form.elements[checkbox][i].checked) {
10192: count ++;
1.236 raeburn 10193: }
1.305 raeburn 10194: }
10195: }
10196: for (var i=0; i<form.elements[checkbox].length; i++) {
10197: var type = form.elements[checkbox][i].value;
10198: if (document.getElementById(prefix+type)) {
10199: if (form.elements[checkbox][i].checked) {
10200: document.getElementById(prefix+type).style.display = 'table-row';
10201: if (count % 2 == 1) {
10202: document.getElementById(prefix+type).className = target+' LC_odd_row';
10203: } else {
10204: document.getElementById(prefix+type).className = target;
1.236 raeburn 10205: }
1.305 raeburn 10206: count ++;
1.236 raeburn 10207: } else {
1.305 raeburn 10208: document.getElementById(prefix+type).style.display = 'none';
10209: }
10210: }
10211: }
10212: }
10213: return;
10214: }
10215:
10216: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10217: var caller = radio+'_'+status;
10218: if (form.elements[caller].length != undefined) {
10219: for (var i=0; i<form.elements[caller].length; i++) {
10220: if (form.elements[caller][i].checked) {
10221: if (document.getElementById(altprefix+'_inst_'+status)) {
10222: var curr = form.elements[caller][i].value;
10223: if (prefix) {
10224: document.getElementById(prefix+'_'+status).style.display = 'none';
10225: }
10226: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10227: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10228: if (curr == 'custom') {
10229: if (prefix) {
10230: document.getElementById(prefix+'_'+status).style.display = 'inline';
10231: }
10232: } else if (curr == 'inst') {
10233: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10234: } else if (curr == 'noninst') {
10235: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10236: }
1.305 raeburn 10237: break;
1.236 raeburn 10238: }
10239: }
10240: }
10241: }
10242: }
10243:
1.305 raeburn 10244: // ]]>
10245: </script>
10246:
10247: ENDSCRIPT
10248: }
10249:
10250: sub noninst_users {
10251: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
10252: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
10253: my $class = 'LC_left_item';
10254: if ($css_class) {
10255: $css_class = ' class="'.$css_class.'"';
10256: }
10257: if ($rowid) {
10258: $rowid = ' id="'.$rowid.'"';
10259: }
10260: if ($rowstyle) {
10261: $rowstyle = ' style="'.$rowstyle.'"';
10262: }
10263: my ($output,$description);
10264: if ($type eq 'default') {
10265: $description = &mt('Requests for: [_1]',$typetitle);
10266: } else {
10267: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10268: }
10269: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
10270: "<td>$description</td>\n".
10271: '<td class="'.$class.'" colspan="2">'.
10272: '<table><tr>';
10273: my %headers = &Apache::lonlocal::texthash(
10274: approve => 'Processing',
10275: email => 'E-mail',
10276: username => 'Username',
10277: );
10278: foreach my $item ('approve','email','username') {
10279: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10280: }
1.305 raeburn 10281: $output .= '</tr><tr>';
10282: foreach my $item ('approve','email','username') {
1.306 raeburn 10283: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10284: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10285: if ($item eq 'approve') {
10286: %choices = &Apache::lonlocal::texthash (
10287: automatic => 'Automatically approved',
10288: approval => 'Queued for approval',
10289: );
10290: @options = ('automatic','approval');
10291: $hashref = $processing;
10292: $defoption = 'automatic';
10293: $name = 'cancreate_emailprocess_'.$type;
10294: } elsif ($item eq 'email') {
10295: %choices = &Apache::lonlocal::texthash (
10296: any => 'Any e-mail',
10297: inst => 'Institutional only',
10298: noninst => 'Non-institutional only',
10299: custom => 'Custom restrictions',
10300: );
10301: @options = ('any','inst','noninst');
10302: my $showcustom;
10303: if (ref($emailrules) eq 'HASH') {
10304: if (keys(%{$emailrules}) > 0) {
10305: push(@options,'custom');
10306: $showcustom = 'cancreate_emailrule';
10307: if (ref($settings) eq 'HASH') {
10308: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10309: foreach my $rule (@{$settings->{'email_rule'}}) {
10310: if (exists($emailrules->{$rule})) {
10311: $hascustom ++;
10312: }
10313: }
10314: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10315: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10316: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10317: if (exists($emailrules->{$rule})) {
10318: $hascustom ++;
10319: }
10320: }
10321: }
10322: }
10323: }
10324: }
10325: }
10326: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10327: "'cancreate_emaildomain','$type'".');"';
10328: $hashref = $emailoptions;
10329: $defoption = 'any';
10330: $name = 'cancreate_emailoptions_'.$type;
10331: } elsif ($item eq 'username') {
10332: %choices = &Apache::lonlocal::texthash (
10333: all => 'Same as e-mail',
10334: first => 'Omit @domain',
10335: free => 'Free to choose',
10336: );
10337: @options = ('all','first','free');
10338: $hashref = $emailverified;
10339: $defoption = 'all';
10340: $name = 'cancreate_usernameoptions_'.$type;
10341: }
10342: foreach my $option (@options) {
10343: my $checked;
10344: if (ref($hashref) eq 'HASH') {
10345: if ($type eq '') {
10346: if (!exists($hashref->{'default'})) {
10347: if ($option eq $defoption) {
10348: $checked = ' checked="checked"';
10349: }
10350: } else {
10351: if ($hashref->{'default'} eq $option) {
10352: $checked = ' checked="checked"';
10353: }
1.303 raeburn 10354: }
10355: } else {
1.305 raeburn 10356: if (!exists($hashref->{$type})) {
10357: if ($option eq $defoption) {
10358: $checked = ' checked="checked"';
10359: }
10360: } else {
10361: if ($hashref->{$type} eq $option) {
10362: $checked = ' checked="checked"';
10363: }
1.303 raeburn 10364: }
10365: }
1.305 raeburn 10366: } elsif (($item eq 'email') && ($hascustom)) {
10367: if ($option eq 'custom') {
10368: $checked = ' checked="checked"';
10369: }
10370: } elsif ($option eq $defoption) {
10371: $checked = ' checked="checked"';
10372: }
10373: $output .= '<span class="LC_nobreak"><label>'.
10374: '<input type="radio" name="'.$name.'"'.
10375: $checked.' value="'.$option.'"'.$onclick.' />'.
10376: $choices{$option}.'</label></span><br />';
10377: if ($item eq 'email') {
10378: if ($option eq 'custom') {
10379: my $id = 'cancreate_emailrule_'.$type;
10380: my $display = 'none';
10381: if ($checked) {
10382: $display = 'inline';
1.303 raeburn 10383: }
1.305 raeburn 10384: my $numinrow = 2;
10385: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10386: '<legend>'.&mt('Disallow').'</legend><table>'.
10387: &user_formats_row('email',$settings,$emailrules,
10388: $emailruleorder,$numinrow,'',$type);
10389: '</table></fieldset>';
10390: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10391: my %text = &Apache::lonlocal::texthash (
10392: inst => 'must end:',
10393: noninst => 'cannot end:',
10394: );
10395: my $value;
10396: if (ref($emaildomain) eq 'HASH') {
10397: if (ref($emaildomain->{$type}) eq 'HASH') {
10398: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10399: }
10400: }
1.305 raeburn 10401: if ($value eq '') {
10402: $value = '@'.$intdom;
10403: }
10404: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10405: my $display = 'none';
10406: if ($checked) {
10407: $display = 'inline';
10408: }
10409: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10410: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10411: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10412: '</div>';
1.303 raeburn 10413: }
10414: }
10415: }
1.305 raeburn 10416: $output .= '</td>'."\n";
1.303 raeburn 10417: }
1.305 raeburn 10418: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10419: return $output;
10420: }
10421:
1.165 raeburn 10422: sub captcha_choice {
1.305 raeburn 10423: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10424: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10425: $vertext,$currver);
1.165 raeburn 10426: my %lt = &captcha_phrases();
10427: $keyentry = 'hidden';
1.354 raeburn 10428: my $colspan=2;
1.165 raeburn 10429: if ($context eq 'cancreate') {
1.224 raeburn 10430: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10431: } elsif ($context eq 'login') {
10432: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10433: } elsif ($context eq 'passwords') {
10434: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10435: $colspan=1;
1.165 raeburn 10436: }
10437: if (ref($settings) eq 'HASH') {
10438: if ($settings->{'captcha'}) {
10439: $checked{$settings->{'captcha'}} = ' checked="checked"';
10440: } else {
10441: $checked{'original'} = ' checked="checked"';
10442: }
10443: if ($settings->{'captcha'} eq 'recaptcha') {
10444: $pubtext = $lt{'pub'};
10445: $privtext = $lt{'priv'};
10446: $keyentry = 'text';
1.269 raeburn 10447: $vertext = $lt{'ver'};
10448: $currver = $settings->{'recaptchaversion'};
10449: if ($currver ne '2') {
10450: $currver = 1;
10451: }
1.165 raeburn 10452: }
10453: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10454: $currpub = $settings->{'recaptchakeys'}{'public'};
10455: $currpriv = $settings->{'recaptchakeys'}{'private'};
10456: }
10457: } else {
10458: $checked{'original'} = ' checked="checked"';
10459: }
1.305 raeburn 10460: my $css_class;
10461: if ($itemcount%2) {
10462: $css_class = 'LC_odd_row';
10463: }
10464: if ($customcss) {
10465: $css_class .= " $customcss";
10466: }
10467: $css_class =~ s/^\s+//;
10468: if ($css_class) {
10469: $css_class = ' class="'.$css_class.'"';
10470: }
10471: if ($rowstyle) {
10472: $css_class .= ' style="'.$rowstyle.'"';
10473: }
1.169 raeburn 10474: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10475: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10476: '<table><tr><td>'."\n";
10477: foreach my $option ('original','recaptcha','notused') {
10478: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10479: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10480: $lt{$option}.'</label></span>';
10481: unless ($option eq 'notused') {
10482: $output .= (' 'x2)."\n";
10483: }
10484: }
10485: #
10486: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10487: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10488: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10489: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10490: #
1.165 raeburn 10491: $output .= '</td></tr>'."\n".
1.305 raeburn 10492: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10493: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10494: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10495: $currpub.'" size="40" /></span><br />'."\n".
10496: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10497: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10498: $currpriv.'" size="40" /></span><br />'.
10499: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10500: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10501: $currver.'" size="3" /></span><br />'.
10502: '</td></tr></table>'."\n".
1.165 raeburn 10503: '</td></tr>';
10504: return $output;
10505: }
10506:
1.32 raeburn 10507: sub user_formats_row {
1.305 raeburn 10508: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10509: my $output;
10510: my %text = (
10511: 'username' => 'new usernames',
10512: 'id' => 'IDs',
10513: );
1.409 raeburn 10514: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10515: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10516: $output = '<tr '.$css_class.'>'.
10517: '<td><span class="LC_nobreak">'.
10518: &mt("Format rules to check for $text{$type}: ").
10519: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10520: }
1.27 raeburn 10521: my $rem;
10522: if (ref($ruleorder) eq 'ARRAY') {
10523: for (my $i=0; $i<@{$ruleorder}; $i++) {
10524: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10525: my $rem = $i%($numinrow);
10526: if ($rem == 0) {
10527: if ($i > 0) {
10528: $output .= '</tr>';
10529: }
10530: $output .= '<tr>';
10531: }
10532: my $check = ' ';
1.39 raeburn 10533: if (ref($settings) eq 'HASH') {
10534: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10535: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10536: $check = ' checked="checked" ';
10537: }
1.305 raeburn 10538: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10539: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10540: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10541: $check = ' checked="checked" ';
10542: }
10543: }
1.27 raeburn 10544: }
10545: }
1.305 raeburn 10546: my $name = $type.'_rule';
10547: if ($type eq 'email') {
10548: $name .= '_'.$status;
10549: }
1.27 raeburn 10550: $output .= '<td class="LC_left_item">'.
10551: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10552: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10553: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10554: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10555: }
10556: }
10557: $rem = @{$ruleorder}%($numinrow);
10558: }
1.305 raeburn 10559: my $colsleft;
10560: if ($rem) {
10561: $colsleft = $numinrow - $rem;
10562: }
1.27 raeburn 10563: if ($colsleft > 1 ) {
10564: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10565: ' </td>';
10566: } elsif ($colsleft == 1) {
10567: $output .= '<td class="LC_left_item"> </td>';
10568: }
1.409 raeburn 10569: $output .= '</tr>';
10570: unless (($type eq 'email') || ($type eq 'unamemap')) {
10571: $output .= '</table></td></tr>';
1.305 raeburn 10572: }
1.27 raeburn 10573: return $output;
10574: }
10575:
1.34 raeburn 10576: sub usercreation_types {
10577: my %lt = &Apache::lonlocal::texthash (
10578: author => 'When adding a co-author',
10579: course => 'When adding a user to a course',
1.100 raeburn 10580: requestcrs => 'When requesting a course',
1.34 raeburn 10581: any => 'Any',
10582: official => 'Institutional only ',
10583: unofficial => 'Non-institutional only',
10584: none => 'None',
10585: );
10586: return %lt;
1.48 raeburn 10587: }
1.34 raeburn 10588:
1.224 raeburn 10589: sub selfcreation_types {
10590: my %lt = &Apache::lonlocal::texthash (
10591: selfcreate => 'User creates own account',
10592: any => 'Any',
10593: official => 'Institutional only ',
10594: unofficial => 'Non-institutional only',
10595: email => 'E-mail address',
10596: login => 'Institutional Login',
10597: sso => 'SSO',
10598: );
10599: }
10600:
1.28 raeburn 10601: sub authtype_names {
10602: my %lt = &Apache::lonlocal::texthash(
10603: int => 'Internal',
10604: krb4 => 'Kerberos 4',
10605: krb5 => 'Kerberos 5',
10606: loc => 'Local',
1.325 raeburn 10607: lti => 'LTI',
1.28 raeburn 10608: );
10609: return %lt;
10610: }
10611:
10612: sub context_names {
10613: my %context_title = &Apache::lonlocal::texthash(
10614: author => 'Creating users when an Author',
10615: course => 'Creating users when in a course',
10616: domain => 'Creating users when a Domain Coordinator',
10617: );
10618: return %context_title;
10619: }
10620:
1.33 raeburn 10621: sub print_usermodification {
10622: my ($position,$dom,$settings,$rowtotal) = @_;
10623: my $numinrow = 4;
10624: my ($context,$datatable,$rowcount);
10625: if ($position eq 'top') {
10626: $rowcount = 0;
10627: $context = 'author';
10628: foreach my $role ('ca','aa') {
10629: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10630: $numinrow,$rowcount);
10631: $$rowtotal ++;
10632: $rowcount ++;
10633: }
1.230 raeburn 10634: } elsif ($position eq 'bottom') {
1.33 raeburn 10635: $context = 'course';
10636: $rowcount = 0;
10637: foreach my $role ('st','ep','ta','in','cr') {
10638: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10639: $numinrow,$rowcount);
10640: $$rowtotal ++;
10641: $rowcount ++;
10642: }
10643: }
10644: return $datatable;
10645: }
10646:
1.43 raeburn 10647: sub print_defaults {
1.236 raeburn 10648: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10649: my $rownum = 0;
1.294 raeburn 10650: my ($datatable,$css_class,$titles);
10651: unless ($position eq 'bottom') {
10652: $titles = &defaults_titles($dom);
10653: }
1.236 raeburn 10654: if ($position eq 'top') {
10655: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10656: 'datelocale_def','portal_def');
10657: my %defaults;
10658: if (ref($settings) eq 'HASH') {
10659: %defaults = %{$settings};
1.43 raeburn 10660: } else {
1.236 raeburn 10661: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10662: foreach my $item (@items) {
10663: $defaults{$item} = $domdefaults{$item};
10664: }
1.43 raeburn 10665: }
1.236 raeburn 10666: foreach my $item (@items) {
10667: if ($rownum%2) {
10668: $css_class = '';
10669: } else {
10670: $css_class = ' class="LC_odd_row" ';
10671: }
10672: $datatable .= '<tr'.$css_class.'>'.
10673: '<td><span class="LC_nobreak">'.$titles->{$item}.
10674: '</span></td><td class="LC_right_item" colspan="3">';
10675: if ($item eq 'auth_def') {
1.325 raeburn 10676: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10677: my %shortauth = (
10678: internal => 'int',
10679: krb4 => 'krb4',
10680: krb5 => 'krb5',
1.325 raeburn 10681: localauth => 'loc',
10682: lti => 'lti',
1.236 raeburn 10683: );
10684: my %authnames = &authtype_names();
10685: foreach my $auth (@authtypes) {
10686: my $checked = ' ';
10687: if ($defaults{$item} eq $auth) {
10688: $checked = ' checked="checked" ';
10689: }
10690: $datatable .= '<label><input type="radio" name="'.$item.
10691: '" value="'.$auth.'"'.$checked.'/>'.
10692: $authnames{$shortauth{$auth}}.'</label> ';
10693: }
10694: } elsif ($item eq 'timezone_def') {
10695: my $includeempty = 1;
10696: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10697: } elsif ($item eq 'datelocale_def') {
10698: my $includeempty = 1;
10699: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10700: } elsif ($item eq 'lang_def') {
1.263 raeburn 10701: my $includeempty = 1;
10702: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10703: } elsif ($item eq 'portal_def') {
10704: $datatable .= '<input type="text" name="'.$item.'" value="'.
10705: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10706: my $portalsty = 'none';
10707: if ($defaults{$item}) {
10708: $portalsty = 'block';
10709: }
10710: foreach my $field ('email','web') {
10711: my $checkedoff = ' checked="checked"';
10712: my $checkedon;
10713: if ($defaults{$item.'_'.$field}) {
10714: $checkedon = $checkedoff;
10715: $checkedoff = '';
10716: }
10717: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10718: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10719: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10720: (' 'x2).
10721: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10722: '</div>';
10723: }
1.236 raeburn 10724: } else {
1.414 raeburn 10725: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10726: }
1.236 raeburn 10727: $datatable .= '</td></tr>';
10728: $rownum ++;
10729: }
1.409 raeburn 10730: } elsif ($position eq 'middle') {
1.294 raeburn 10731: my %defaults;
10732: if (ref($settings) eq 'HASH') {
1.354 raeburn 10733: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10734: my $maxnum = @{$settings->{'inststatusorder'}};
10735: for (my $i=0; $i<$maxnum; $i++) {
10736: $css_class = $rownum%2?' class="LC_odd_row"':'';
10737: my $item = $settings->{'inststatusorder'}->[$i];
10738: my $title = $settings->{'inststatustypes'}->{$item};
10739: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10740: $datatable .= '<tr'.$css_class.'>'.
10741: '<td><span class="LC_nobreak">'.
10742: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10743: for (my $k=0; $k<=$maxnum; $k++) {
10744: my $vpos = $k+1;
10745: my $selstr;
10746: if ($k == $i) {
10747: $selstr = ' selected="selected" ';
10748: }
10749: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10750: }
10751: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10752: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10753: &mt('delete').'</span></td>'.
1.380 raeburn 10754: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10755: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10756: '</span></td></tr>';
10757: }
10758: $css_class = $rownum%2?' class="LC_odd_row"':'';
10759: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10760: $datatable .= '<tr '.$css_class.'>'.
10761: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10762: for (my $k=0; $k<=$maxnum; $k++) {
10763: my $vpos = $k+1;
10764: my $selstr;
10765: if ($k == $maxnum) {
10766: $selstr = ' selected="selected" ';
10767: }
10768: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10769: }
10770: $datatable .= '</select> '.&mt('Internal ID:').
10771: '<input type="text" size="10" name="addinststatus" value="" />'.
10772: ' '.&mt('(new)').
10773: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10774: &mt('Name displayed').':'.
1.354 raeburn 10775: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10776: '</tr>'."\n";
10777: $rownum ++;
1.294 raeburn 10778: }
1.354 raeburn 10779: }
1.409 raeburn 10780: } else {
10781: my ($unamemaprules,$ruleorder) =
10782: &Apache::lonnet::inst_userrules($dom,'unamemap');
10783: $css_class = $rownum%2?' class="LC_odd_row"':'';
10784: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10785: my $numinrow = 2;
10786: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10787: &user_formats_row('unamemap',$settings,$unamemaprules,
10788: $ruleorder,$numinrow).
10789: '</table></td></tr>';
10790: }
10791: if ($datatable eq '') {
10792: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10793: &mt('No rules set for domain in customized localenroll.pm').
10794: '</td></tr>';
10795: }
1.354 raeburn 10796: }
10797: $$rowtotal += $rownum;
1.43 raeburn 10798: return $datatable;
10799: }
10800:
1.168 raeburn 10801: sub get_languages_hash {
10802: my %langchoices;
10803: foreach my $id (&Apache::loncommon::languageids()) {
10804: my $code = &Apache::loncommon::supportedlanguagecode($id);
10805: if ($code ne '') {
10806: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10807: }
10808: }
10809: return %langchoices;
10810: }
10811:
1.43 raeburn 10812: sub defaults_titles {
1.141 raeburn 10813: my ($dom) = @_;
1.43 raeburn 10814: my %titles = &Apache::lonlocal::texthash (
10815: 'auth_def' => 'Default authentication type',
10816: 'auth_arg_def' => 'Default authentication argument',
10817: 'lang_def' => 'Default language',
1.54 raeburn 10818: 'timezone_def' => 'Default timezone',
1.68 raeburn 10819: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10820: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10821: 'email' => 'Email links use portal URL',
10822: 'web' => 'Public web links use portal URL',
1.294 raeburn 10823: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10824: 'intauth_check' => 'Check bcrypt cost if authenticated',
10825: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10826: );
1.141 raeburn 10827: if ($dom) {
10828: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10829: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10830: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10831: $protocol = 'http' if ($protocol ne 'https');
10832: if ($uint_dom) {
10833: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10834: $uint_dom);
10835: }
10836: }
1.43 raeburn 10837: return (\%titles);
10838: }
10839:
1.346 raeburn 10840: sub print_scantron {
10841: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10842: if ($position eq 'top') {
10843: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10844: } else {
10845: return &print_scantronconfig($dom,$settings,\$rowtotal);
10846: }
10847: }
10848:
10849: sub scantron_javascript {
10850: return <<"ENDSCRIPT";
10851:
10852: <script type="text/javascript">
10853: // <![CDATA[
10854:
10855: function toggleScantron(form) {
1.347 raeburn 10856: var csvfieldset = new Array();
1.346 raeburn 10857: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10858: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10859: }
10860: if (document.getElementById('scantroncsv_options')) {
10861: csvfieldset.push(document.getElementById('scantroncsv_options'));
10862: }
10863: if (csvfieldset.length) {
1.346 raeburn 10864: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10865: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10866: if (scantroncsv.checked) {
1.347 raeburn 10867: for (var i=0; i<csvfieldset.length; i++) {
10868: csvfieldset[i].style.display = 'block';
10869: }
1.346 raeburn 10870: } else {
1.347 raeburn 10871: for (var i=0; i<csvfieldset.length; i++) {
10872: csvfieldset[i].style.display = 'none';
10873: }
1.346 raeburn 10874: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10875: if (csvselects.length) {
10876: for (var j=0; j<csvselects.length; j++) {
10877: csvselects[j].selectedIndex = 0;
10878: }
10879: }
10880: }
10881: }
10882: }
10883: return;
10884: }
10885: // ]]>
10886: </script>
10887:
10888: ENDSCRIPT
10889:
10890: }
10891:
1.46 raeburn 10892: sub print_scantronformat {
10893: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10894: my $itemcount = 1;
1.60 raeburn 10895: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10896: %confhash);
1.46 raeburn 10897: my $switchserver = &check_switchserver($dom,$confname);
10898: my %lt = &Apache::lonlocal::texthash (
1.95 www 10899: default => 'Default bubblesheet format file error',
10900: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10901: );
10902: my %scantronfiles = (
10903: default => 'default.tab',
10904: custom => 'custom.tab',
10905: );
10906: foreach my $key (keys(%scantronfiles)) {
10907: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10908: .$scantronfiles{$key};
10909: }
10910: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10911: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10912: if (!$switchserver) {
10913: my $servadm = $r->dir_config('lonAdmEMail');
10914: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10915: if ($configuserok eq 'ok') {
10916: if ($author_ok eq 'ok') {
10917: my %legacyfile = (
1.346 raeburn 10918: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10919: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10920: );
10921: my %md5chk;
10922: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10923: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10924: chomp($md5chk{$type});
1.46 raeburn 10925: }
10926: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10927: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10928: ($scantronurls{$type},my $error) =
1.46 raeburn 10929: &legacy_scantronformat($r,$dom,$confname,
10930: $type,$legacyfile{$type},
10931: $scantronurls{$type},
10932: $scantronfiles{$type});
1.60 raeburn 10933: if ($error ne '') {
10934: $error{$type} = $error;
10935: }
10936: }
10937: if (keys(%error) == 0) {
10938: $is_custom = 1;
1.346 raeburn 10939: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10940: $scantronurls{'custom'};
1.346 raeburn 10941: my $putresult =
1.60 raeburn 10942: &Apache::lonnet::put_dom('configuration',
10943: \%confhash,$dom);
10944: if ($putresult ne 'ok') {
1.346 raeburn 10945: $error{'custom'} =
1.60 raeburn 10946: '<span class="LC_error">'.
10947: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10948: }
1.46 raeburn 10949: }
10950: } else {
1.60 raeburn 10951: ($scantronurls{'default'},my $error) =
1.46 raeburn 10952: &legacy_scantronformat($r,$dom,$confname,
10953: 'default',$legacyfile{'default'},
10954: $scantronurls{'default'},
10955: $scantronfiles{'default'});
1.60 raeburn 10956: if ($error eq '') {
10957: $confhash{'scantron'}{'scantronformat'} = '';
10958: my $putresult =
10959: &Apache::lonnet::put_dom('configuration',
10960: \%confhash,$dom);
10961: if ($putresult ne 'ok') {
10962: $error{'default'} =
10963: '<span class="LC_error">'.
10964: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10965: }
10966: } else {
10967: $error{'default'} = $error;
10968: }
1.46 raeburn 10969: }
10970: }
10971: }
10972: } else {
1.95 www 10973: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10974: }
10975: }
10976: if (ref($settings) eq 'HASH') {
10977: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10978: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10979: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10980: $scantronurl = '';
10981: } else {
10982: $scantronurl = $settings->{'scantronformat'};
10983: }
10984: $is_custom = 1;
10985: } else {
10986: $scantronurl = $scantronurls{'default'};
10987: }
10988: } else {
1.60 raeburn 10989: if ($is_custom) {
10990: $scantronurl = $scantronurls{'custom'};
10991: } else {
10992: $scantronurl = $scantronurls{'default'};
10993: }
1.46 raeburn 10994: }
10995: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10996: $datatable .= '<tr'.$css_class.'>';
10997: if (!$is_custom) {
1.65 raeburn 10998: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10999: '<span class="LC_nobreak">';
1.46 raeburn 11000: if ($scantronurl) {
1.199 raeburn 11001: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11002: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11003: } else {
11004: $datatable = &mt('File unavailable for display');
11005: }
1.65 raeburn 11006: $datatable .= '</span></td>';
1.60 raeburn 11007: if (keys(%error) == 0) {
1.306 raeburn 11008: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11009: if (!$switchserver) {
11010: $datatable .= &mt('Upload:').'<br />';
11011: }
11012: } else {
11013: my $errorstr;
11014: foreach my $key (sort(keys(%error))) {
11015: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11016: }
11017: $datatable .= '<td>'.$errorstr;
11018: }
1.46 raeburn 11019: } else {
11020: if (keys(%error) > 0) {
11021: my $errorstr;
11022: foreach my $key (sort(keys(%error))) {
11023: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11024: }
1.60 raeburn 11025: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11026: } elsif ($scantronurl) {
1.199 raeburn 11027: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11028: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11029: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11030: $link.
11031: '<label><input type="checkbox" name="scantronformat_del"'.
11032: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11033: '<td><span class="LC_nobreak"> '.
11034: &mt('Replace:').'</span><br />';
1.46 raeburn 11035: }
11036: }
11037: if (keys(%error) == 0) {
11038: if ($switchserver) {
11039: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11040: } else {
1.65 raeburn 11041: $datatable .='<span class="LC_nobreak"> '.
11042: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11043: }
11044: }
11045: $datatable .= '</td></tr>';
11046: $$rowtotal ++;
11047: return $datatable;
11048: }
11049:
11050: sub legacy_scantronformat {
11051: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11052: my ($url,$error);
11053: my @statinfo = &Apache::lonnet::stat_file($newurl);
11054: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
11055: (my $result,$url) =
11056: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
11057: '','',$newfile);
11058: if ($result ne 'ok') {
1.130 raeburn 11059: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11060: }
11061: }
11062: return ($url,$error);
11063: }
1.43 raeburn 11064:
1.346 raeburn 11065: sub print_scantronconfig {
11066: my ($dom,$settings,$rowtotal) = @_;
11067: my $itemcount = 2;
11068: my $is_checked = ' checked="checked"';
1.347 raeburn 11069: my %optionson = (
11070: hdr => ' checked="checked"',
11071: pad => ' checked="checked"',
11072: rem => ' checked="checked"',
11073: );
11074: my %optionsoff = (
11075: hdr => '',
11076: pad => '',
11077: rem => '',
11078: );
1.346 raeburn 11079: my $currcsvsty = 'none';
1.347 raeburn 11080: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11081: my @fields = &scantroncsv_fields();
11082: my %titles = &scantronconfig_titles();
11083: if (ref($settings) eq 'HASH') {
11084: if (ref($settings->{config}) eq 'HASH') {
11085: if ($settings->{config}->{dat}) {
11086: $checked{'dat'} = $is_checked;
11087: }
11088: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11089: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11090: %csvfields = %{$settings->{config}->{csv}->{fields}};
11091: if (keys(%csvfields) > 0) {
11092: $checked{'csv'} = $is_checked;
11093: $currcsvsty = 'block';
11094: }
11095: }
11096: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11097: %csvoptions = %{$settings->{config}->{csv}->{options}};
11098: foreach my $option (keys(%optionson)) {
11099: unless ($csvoptions{$option}) {
11100: $optionsoff{$option} = $optionson{$option};
11101: $optionson{$option} = '';
11102: }
11103: }
1.346 raeburn 11104: }
11105: }
11106: } else {
11107: $checked{'dat'} = $is_checked;
11108: }
11109: } else {
11110: $checked{'dat'} = $is_checked;
11111: }
11112: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11113: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11114: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11115: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11116: foreach my $item ('dat','csv') {
11117: my $id;
11118: if ($item eq 'csv') {
11119: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11120: }
1.346 raeburn 11121: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11122: $titles{$item}.'</label>'.(' 'x3);
11123: if ($item eq 'csv') {
11124: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11125: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11126: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11127: foreach my $col (@fields) {
11128: my $selnone;
11129: if ($csvfields{$col} eq '') {
11130: $selnone = ' selected="selected"';
11131: }
11132: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11133: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11134: '<option value=""'.$selnone.'></option>';
11135: for (my $i=0; $i<20; $i++) {
11136: my $shown = $i+1;
11137: my $sel;
11138: unless ($selnone) {
11139: if (exists($csvfields{$col})) {
11140: if ($csvfields{$col} == $i) {
11141: $sel = ' selected="selected"';
11142: }
11143: }
11144: }
11145: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11146: }
11147: $datatable .= '</select></td></tr>';
11148: }
1.347 raeburn 11149: $datatable .= '</table></fieldset>'.
11150: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11151: '<legend>'.&mt('CSV Options').'</legend>';
11152: foreach my $option ('hdr','pad','rem') {
11153: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11154: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11155: &mt('Yes').'</label>'.(' 'x2)."\n".
11156: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11157: }
11158: $datatable .= '</fieldset>';
1.346 raeburn 11159: $itemcount ++;
11160: }
11161: }
11162: $datatable .= '</td></tr>';
11163: $$rowtotal ++;
11164: return $datatable;
11165: }
11166:
11167: sub scantronconfig_titles {
11168: return &Apache::lonlocal::texthash(
11169: dat => 'Standard format (.dat)',
11170: csv => 'Comma separated values (.csv)',
1.347 raeburn 11171: hdr => 'Remove first line in file (contains column titles)',
11172: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11173: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11174: CODE => 'CODE',
11175: ID => 'Student ID',
11176: PaperID => 'Paper ID',
11177: FirstName => 'First Name',
11178: LastName => 'Last Name',
11179: FirstQuestion => 'First Question Response',
11180: Section => 'Section',
11181: );
11182: }
11183:
11184: sub scantroncsv_fields {
11185: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11186: }
11187:
1.49 raeburn 11188: sub print_coursecategories {
1.57 raeburn 11189: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11190: my $datatable;
11191: if ($position eq 'top') {
1.238 raeburn 11192: my (%checked);
11193: my @catitems = ('unauth','auth');
11194: my @cattypes = ('std','domonly','codesrch','none');
11195: $checked{'unauth'} = 'std';
11196: $checked{'auth'} = 'std';
11197: if (ref($settings) eq 'HASH') {
11198: foreach my $type (@cattypes) {
11199: if ($type eq $settings->{'unauth'}) {
11200: $checked{'unauth'} = $type;
11201: }
11202: if ($type eq $settings->{'auth'}) {
11203: $checked{'auth'} = $type;
11204: }
11205: }
11206: }
11207: my %lt = &Apache::lonlocal::texthash (
11208: unauth => 'Catalog type for unauthenticated users',
11209: auth => 'Catalog type for authenticated users',
11210: none => 'No catalog',
11211: std => 'Standard catalog',
11212: domonly => 'Domain-only catalog',
11213: codesrch => "Code search form",
11214: );
11215: my $itemcount = 0;
11216: foreach my $item (@catitems) {
11217: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11218: $datatable .= '<tr '.$css_class.'>'.
11219: '<td>'.$lt{$item}.'</td>'.
11220: '<td class="LC_right_item"><span class="LC_nobreak">';
11221: foreach my $type (@cattypes) {
11222: my $ischecked;
11223: if ($checked{$item} eq $type) {
11224: $ischecked=' checked="checked"';
11225: }
11226: $datatable .= '<label>'.
11227: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11228: ' />'.$lt{$type}.'</label> ';
11229: }
1.327 raeburn 11230: $datatable .= '</span></td></tr>';
1.238 raeburn 11231: $itemcount ++;
11232: }
11233: $$rowtotal += $itemcount;
11234: } elsif ($position eq 'middle') {
1.57 raeburn 11235: my $toggle_cats_crs = ' ';
11236: my $toggle_cats_dom = ' checked="checked" ';
11237: my $can_cat_crs = ' ';
11238: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11239: my $toggle_catscomm_comm = ' ';
11240: my $toggle_catscomm_dom = ' checked="checked" ';
11241: my $can_catcomm_comm = ' ';
11242: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11243: my $toggle_catsplace_place = ' ';
11244: my $toggle_catsplace_dom = ' checked="checked" ';
11245: my $can_catplace_place = ' ';
11246: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11247:
1.57 raeburn 11248: if (ref($settings) eq 'HASH') {
11249: if ($settings->{'togglecats'} eq 'crs') {
11250: $toggle_cats_crs = $toggle_cats_dom;
11251: $toggle_cats_dom = ' ';
11252: }
11253: if ($settings->{'categorize'} eq 'crs') {
11254: $can_cat_crs = $can_cat_dom;
11255: $can_cat_dom = ' ';
11256: }
1.120 raeburn 11257: if ($settings->{'togglecatscomm'} eq 'comm') {
11258: $toggle_catscomm_comm = $toggle_catscomm_dom;
11259: $toggle_catscomm_dom = ' ';
11260: }
11261: if ($settings->{'categorizecomm'} eq 'comm') {
11262: $can_catcomm_comm = $can_catcomm_dom;
11263: $can_catcomm_dom = ' ';
11264: }
1.272 raeburn 11265: if ($settings->{'togglecatsplace'} eq 'place') {
11266: $toggle_catsplace_place = $toggle_catsplace_dom;
11267: $toggle_catsplace_dom = ' ';
11268: }
11269: if ($settings->{'categorizeplace'} eq 'place') {
11270: $can_catplace_place = $can_catplace_dom;
11271: $can_catplace_dom = ' ';
11272: }
1.57 raeburn 11273: }
11274: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11275: togglecats => 'Show/Hide a course in catalog',
11276: togglecatscomm => 'Show/Hide a community in catalog',
11277: togglecatsplace => 'Show/Hide a placement test in catalog',
11278: categorize => 'Assign a category to a course',
11279: categorizecomm => 'Assign a category to a community',
11280: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11281: );
11282: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11283: dom => 'Set in Domain',
11284: crs => 'Set in Course',
11285: comm => 'Set in Community',
11286: place => 'Set in Placement Test',
1.57 raeburn 11287: );
11288: $datatable = '<tr class="LC_odd_row">'.
11289: '<td>'.$title{'togglecats'}.'</td>'.
11290: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11291: '<input type="radio" name="togglecats"'.
11292: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11293: '<label><input type="radio" name="togglecats"'.
11294: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11295: '</tr><tr>'.
11296: '<td>'.$title{'categorize'}.'</td>'.
11297: '<td class="LC_right_item"><span class="LC_nobreak">'.
11298: '<label><input type="radio" name="categorize"'.
11299: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11300: '<label><input type="radio" name="categorize"'.
11301: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11302: '</tr><tr class="LC_odd_row">'.
11303: '<td>'.$title{'togglecatscomm'}.'</td>'.
11304: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11305: '<input type="radio" name="togglecatscomm"'.
11306: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11307: '<label><input type="radio" name="togglecatscomm"'.
11308: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11309: '</tr><tr>'.
11310: '<td>'.$title{'categorizecomm'}.'</td>'.
11311: '<td class="LC_right_item"><span class="LC_nobreak">'.
11312: '<label><input type="radio" name="categorizecomm"'.
11313: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11314: '<label><input type="radio" name="categorizecomm"'.
11315: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11316: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11317: '<td>'.$title{'togglecatsplace'}.'</td>'.
11318: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11319: '<input type="radio" name="togglecatsplace"'.
11320: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11321: '<label><input type="radio" name="togglecatscomm"'.
11322: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11323: '</tr><tr>'.
11324: '<td>'.$title{'categorizeplace'}.'</td>'.
11325: '<td class="LC_right_item"><span class="LC_nobreak">'.
11326: '<label><input type="radio" name="categorizeplace"'.
11327: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11328: '<label><input type="radio" name="categorizeplace"'.
11329: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11330: '</tr>';
1.272 raeburn 11331: $$rowtotal += 6;
1.57 raeburn 11332: } else {
11333: my $css_class;
11334: my $itemcount = 1;
11335: my $cathash;
11336: if (ref($settings) eq 'HASH') {
11337: $cathash = $settings->{'cats'};
11338: }
11339: if (ref($cathash) eq 'HASH') {
11340: my (@cats,@trails,%allitems,%idx,@jsarray);
11341: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11342: \%allitems,\%idx,\@jsarray);
11343: my $maxdepth = scalar(@cats);
11344: my $colattrib = '';
11345: if ($maxdepth > 2) {
11346: $colattrib = ' colspan="2" ';
11347: }
11348: my @path;
11349: if (@cats > 0) {
11350: if (ref($cats[0]) eq 'ARRAY') {
11351: my $numtop = @{$cats[0]};
11352: my $maxnum = $numtop;
1.120 raeburn 11353: my %default_names = (
11354: instcode => &mt('Official courses'),
11355: communities => &mt('Communities'),
1.272 raeburn 11356: placement => &mt('Placement Tests'),
1.120 raeburn 11357: );
11358:
11359: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11360: ($cathash->{'instcode::0'} eq '') ||
11361: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11362: ($cathash->{'communities::0'} eq '') ||
11363: (!grep(/^placement$/,@{$cats[0]})) ||
11364: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11365: $maxnum ++;
11366: }
11367: my $lastidx;
11368: for (my $i=0; $i<$numtop; $i++) {
11369: my $parent = $cats[0][$i];
11370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11371: my $item = &escape($parent).'::0';
11372: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11373: $lastidx = $idx{$item};
11374: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11375: .'<select name="'.$item.'"'.$chgstr.'>';
11376: for (my $k=0; $k<=$maxnum; $k++) {
11377: my $vpos = $k+1;
11378: my $selstr;
11379: if ($k == $i) {
11380: $selstr = ' selected="selected" ';
11381: }
11382: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11383: }
1.214 raeburn 11384: $datatable .= '</select></span></td><td>';
1.272 raeburn 11385: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11386: $datatable .= '<span class="LC_nobreak">'
11387: .$default_names{$parent}.'</span>';
11388: if ($parent eq 'instcode') {
11389: $datatable .= '<br /><span class="LC_nobreak">('
11390: .&mt('with institutional codes')
11391: .')</span></td><td'.$colattrib.'>';
11392: } else {
11393: $datatable .= '<table><tr><td>';
11394: }
11395: $datatable .= '<span class="LC_nobreak">'
11396: .'<label><input type="radio" name="'
11397: .$parent.'" value="1" checked="checked" />'
11398: .&mt('Display').'</label>';
11399: if ($parent eq 'instcode') {
11400: $datatable .= ' ';
11401: } else {
11402: $datatable .= '</span></td></tr><tr><td>'
11403: .'<span class="LC_nobreak">';
11404: }
11405: $datatable .= '<label><input type="radio" name="'
11406: .$parent.'" value="0" />'
11407: .&mt('Do not display').'</label></span>';
1.272 raeburn 11408: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11409: $datatable .= '</td></tr></table>';
11410: }
11411: $datatable .= '</td>';
1.57 raeburn 11412: } else {
11413: $datatable .= $parent
1.214 raeburn 11414: .' <span class="LC_nobreak"><label>'
11415: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11416: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11417: }
11418: my $depth = 1;
11419: push(@path,$parent);
11420: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11421: pop(@path);
11422: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11423: $itemcount ++;
11424: }
1.48 raeburn 11425: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11426: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11427: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11428: for (my $k=0; $k<=$maxnum; $k++) {
11429: my $vpos = $k+1;
11430: my $selstr;
1.57 raeburn 11431: if ($k == $numtop) {
1.48 raeburn 11432: $selstr = ' selected="selected" ';
11433: }
11434: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11435: }
1.59 bisitz 11436: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11437: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11438: .'</tr>'."\n";
1.48 raeburn 11439: $itemcount ++;
1.272 raeburn 11440: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11441: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11442: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11443: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11444: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11445: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11446: for (my $k=0; $k<=$maxnum; $k++) {
11447: my $vpos = $k+1;
11448: my $selstr;
11449: if ($k == $maxnum) {
11450: $selstr = ' selected="selected" ';
11451: }
11452: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11453: }
1.120 raeburn 11454: $datatable .= '</select></span></td>'.
11455: '<td><span class="LC_nobreak">'.
11456: $default_names{$default}.'</span>';
11457: if ($default eq 'instcode') {
11458: $datatable .= '<br /><span class="LC_nobreak">('
11459: .&mt('with institutional codes').')</span>';
11460: }
11461: $datatable .= '</td>'
11462: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11463: .&mt('Display').'</label> '
11464: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11465: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11466: }
11467: }
11468: }
1.57 raeburn 11469: } else {
11470: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11471: }
11472: } else {
1.327 raeburn 11473: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11474: .&initialize_categories($itemcount);
1.48 raeburn 11475: }
1.57 raeburn 11476: $$rowtotal += $itemcount;
1.48 raeburn 11477: }
11478: return $datatable;
11479: }
11480:
1.69 raeburn 11481: sub print_serverstatuses {
11482: my ($dom,$settings,$rowtotal) = @_;
11483: my $datatable;
11484: my @pages = &serverstatus_pages();
11485: my (%namedaccess,%machineaccess);
11486: foreach my $type (@pages) {
11487: $namedaccess{$type} = '';
11488: $machineaccess{$type}= '';
11489: }
11490: if (ref($settings) eq 'HASH') {
11491: foreach my $type (@pages) {
11492: if (exists($settings->{$type})) {
11493: if (ref($settings->{$type}) eq 'HASH') {
11494: foreach my $key (keys(%{$settings->{$type}})) {
11495: if ($key eq 'namedusers') {
11496: $namedaccess{$type} = $settings->{$type}->{$key};
11497: } elsif ($key eq 'machines') {
11498: $machineaccess{$type} = $settings->{$type}->{$key};
11499: }
11500: }
11501: }
11502: }
11503: }
11504: }
1.81 raeburn 11505: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11506: my $rownum = 0;
11507: my $css_class;
11508: foreach my $type (@pages) {
11509: $rownum ++;
11510: $css_class = $rownum%2?' class="LC_odd_row"':'';
11511: $datatable .= '<tr'.$css_class.'>'.
11512: '<td><span class="LC_nobreak">'.
11513: $titles->{$type}.'</span></td>'.
11514: '<td class="LC_left_item">'.
11515: '<input type="text" name="'.$type.'_namedusers" '.
11516: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11517: '<td class="LC_right_item">'.
11518: '<span class="LC_nobreak">'.
11519: '<input type="text" name="'.$type.'_machines" '.
11520: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11521: '</span></td></tr>'."\n";
1.69 raeburn 11522: }
11523: $$rowtotal += $rownum;
11524: return $datatable;
11525: }
11526:
11527: sub serverstatus_pages {
11528: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11529: 'checksums','clusterstatus','certstatus','metadata_keywords',
11530: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11531: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11532: }
11533:
1.236 raeburn 11534: sub defaults_javascript {
11535: my ($settings) = @_;
1.354 raeburn 11536: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11537: my $portal_js = <<"ENDPORTAL";
11538:
11539: function portalExtras(caller) {
11540: var x = caller.value;
11541: var y = new Array('email','web');
11542: for (var i=0; i<y.length; i++) {
11543: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11544: var z = document.getElementById('portal_def_'+y[i]+'_div');
11545: if (x.length > 0) {
11546: z.style.display = 'block';
11547: } else {
11548: z.style.display = 'none';
11549: }
11550: }
11551: }
11552: }
11553: ENDPORTAL
1.236 raeburn 11554: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11555: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11556: if ($maxnum eq '') {
11557: $maxnum = 0;
11558: }
11559: $maxnum ++;
1.249 raeburn 11560: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11561: return <<"ENDSCRIPT";
11562: <script type="text/javascript">
11563: // <![CDATA[
11564: function reorderTypes(form,caller) {
11565: var changedVal;
11566: $jstext
11567: var newpos = 'addinststatus_pos';
11568: var current = new Array;
11569: var maxh = $maxnum;
11570: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11571: var oldVal;
11572: if (caller == newpos) {
11573: changedVal = newitemVal;
11574: } else {
11575: var curritem = 'inststatus_pos_'+caller;
11576: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11577: current[newitemVal] = newpos;
11578: }
11579: for (var i=0; i<inststatuses.length; i++) {
11580: if (inststatuses[i] != caller) {
11581: var elementName = 'inststatus_pos_'+inststatuses[i];
11582: if (form.elements[elementName]) {
11583: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11584: current[currVal] = elementName;
11585: }
11586: }
11587: }
11588: for (var j=0; j<maxh; j++) {
11589: if (current[j] == undefined) {
11590: oldVal = j;
11591: }
11592: }
11593: if (oldVal < changedVal) {
11594: for (var k=oldVal+1; k<=changedVal ; k++) {
11595: var elementName = current[k];
11596: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11597: }
11598: } else {
11599: for (var k=changedVal; k<oldVal; k++) {
11600: var elementName = current[k];
11601: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11602: }
11603: }
11604: return;
11605: }
11606:
1.414 raeburn 11607: $portal_js
11608:
11609: // ]]>
11610: </script>
11611:
11612: ENDSCRIPT
11613: } else {
11614: return <<"ENDSCRIPT";
11615: <script type="text/javascript">
11616: // <![CDATA[
11617: $portal_js
1.236 raeburn 11618: // ]]>
11619: </script>
11620:
11621: ENDSCRIPT
11622: }
1.354 raeburn 11623: return;
11624: }
11625:
11626: sub passwords_javascript {
1.405 raeburn 11627: my ($prefix) = @_;
11628: my %intalert;
11629: if ($prefix eq 'passwords') {
11630: %intalert = &Apache::lonlocal::texthash (
11631: 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.',
11632: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11633: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11634: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11635: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11636: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11637: );
11638: } elsif ($prefix eq 'secrets') {
11639: %intalert = &Apache::lonlocal::texthash (
11640: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11641: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11642: );
11643: }
1.365 raeburn 11644: &js_escape(\%intalert);
11645: my $defmin = $Apache::lonnet::passwdmin;
1.405 raeburn 11646: my $intauthjs;
11647: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11648:
11649: function warnIntAuth(field) {
11650: if (field.name == 'intauth_check') {
11651: if (field.value == '2') {
1.365 raeburn 11652: alert('$intalert{authcheck}');
1.354 raeburn 11653: }
11654: }
11655: if (field.name == 'intauth_cost') {
11656: field.value.replace(/\s/g,'');
11657: if (field.value != '') {
11658: var regexdigit=/^\\d+\$/;
11659: if (!regexdigit.test(field.value)) {
1.365 raeburn 11660: alert('$intalert{authcost}');
11661: }
11662: }
11663: }
11664: return;
11665: }
11666:
1.405 raeburn 11667: ENDSCRIPT
11668:
11669: }
11670:
11671: $intauthjs .= <<"ENDSCRIPT";
11672:
11673: function warnInt$prefix(field) {
1.365 raeburn 11674: field.value.replace(/^\s+/,'');
11675: field.value.replace(/\s+\$/,'');
11676: var regexdigit=/^\\d+\$/;
1.408 raeburn 11677: if (field.name == '${prefix}_min') {
1.365 raeburn 11678: if (field.value == '') {
11679: alert('$intalert{passmin}');
11680: field.value = '$defmin';
11681: } else {
11682: if (!regexdigit.test(field.value)) {
11683: alert('$intalert{passmin}');
11684: field.value = '$defmin';
11685: }
1.366 raeburn 11686: var minval = parseInt(field.value,10);
1.365 raeburn 11687: if (minval < $defmin) {
11688: alert('$intalert{passmin}');
11689: field.value = '$defmin';
11690: }
11691: }
11692: } else {
11693: if (field.value == '0') {
11694: field.value = '';
11695: }
11696: if (field.value != '') {
1.408 raeburn 11697: if (field.name == '${prefix}_expire') {
1.365 raeburn 11698: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11699: if (!regexpposnum.test(field.value)) {
11700: alert('$intalert{passexp}');
11701: field.value = '';
11702: } else {
11703: var expval = parseFloat(field.value);
11704: if (expval == 0) {
11705: alert('$intalert{passexp}');
11706: field.value = '';
11707: }
11708: }
11709: } else {
11710: if (!regexdigit.test(field.value)) {
1.408 raeburn 11711: if (field.name == '${prefix}_max') {
1.365 raeburn 11712: alert('$intalert{passmax}');
11713: } else {
1.408 raeburn 11714: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11715: alert('$intalert{passnum}');
11716: }
11717: }
1.370 raeburn 11718: field.value = '';
1.365 raeburn 11719: }
1.354 raeburn 11720: }
11721: }
11722: }
11723: return;
11724: }
11725:
11726: ENDSCRIPT
11727: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11728: }
11729:
1.49 raeburn 11730: sub coursecategories_javascript {
11731: my ($settings) = @_;
1.57 raeburn 11732: my ($output,$jstext,$cathash);
1.49 raeburn 11733: if (ref($settings) eq 'HASH') {
1.57 raeburn 11734: $cathash = $settings->{'cats'};
11735: }
11736: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11737: my (@cats,@jsarray,%idx);
1.57 raeburn 11738: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11739: if (@jsarray > 0) {
11740: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11741: for (my $i=0; $i<@jsarray; $i++) {
11742: if (ref($jsarray[$i]) eq 'ARRAY') {
11743: my $catstr = join('","',@{$jsarray[$i]});
11744: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11745: }
11746: }
11747: }
11748: } else {
11749: $jstext = ' var categories = Array(1);'."\n".
11750: ' categories[0] = Array("instcode_pos");'."\n";
11751: }
1.237 bisitz 11752: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11753: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11754: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11755: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11756: &js_escape(\$instcode_reserved);
11757: &js_escape(\$communities_reserved);
1.272 raeburn 11758: &js_escape(\$placement_reserved);
1.265 damieng 11759: &js_escape(\$choose_again);
1.49 raeburn 11760: $output = <<"ENDSCRIPT";
11761: <script type="text/javascript">
1.109 raeburn 11762: // <![CDATA[
1.49 raeburn 11763: function reorderCats(form,parent,item,idx) {
11764: var changedVal;
11765: $jstext
11766: var newpos = 'addcategory_pos';
11767: if (parent == '') {
11768: var has_instcode = 0;
11769: var maxtop = categories[idx].length;
11770: for (var j=0; j<maxtop; j++) {
11771: if (categories[idx][j] == 'instcode::0') {
11772: has_instcode == 1;
11773: }
11774: }
11775: if (has_instcode == 0) {
11776: categories[idx][maxtop] = 'instcode_pos';
11777: }
11778: } else {
11779: newpos += '_'+parent;
11780: }
11781: var maxh = 1 + categories[idx].length;
11782: var current = new Array;
11783: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11784: if (item == newpos) {
11785: changedVal = newitemVal;
11786: } else {
11787: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11788: current[newitemVal] = newpos;
11789: }
11790: for (var i=0; i<categories[idx].length; i++) {
11791: var elementName = categories[idx][i];
11792: if (elementName != item) {
11793: if (form.elements[elementName]) {
11794: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11795: current[currVal] = elementName;
11796: }
11797: }
11798: }
11799: var oldVal;
11800: for (var j=0; j<maxh; j++) {
11801: if (current[j] == undefined) {
11802: oldVal = j;
11803: }
11804: }
11805: if (oldVal < changedVal) {
11806: for (var k=oldVal+1; k<=changedVal ; k++) {
11807: var elementName = current[k];
11808: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11809: }
11810: } else {
11811: for (var k=changedVal; k<oldVal; k++) {
11812: var elementName = current[k];
11813: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11814: }
11815: }
11816: return;
11817: }
1.120 raeburn 11818:
11819: function categoryCheck(form) {
11820: if (form.elements['addcategory_name'].value == 'instcode') {
11821: alert('$instcode_reserved\\n$choose_again');
11822: return false;
11823: }
11824: if (form.elements['addcategory_name'].value == 'communities') {
11825: alert('$communities_reserved\\n$choose_again');
11826: return false;
11827: }
1.272 raeburn 11828: if (form.elements['addcategory_name'].value == 'placement') {
11829: alert('$placement_reserved\\n$choose_again');
11830: return false;
11831: }
1.120 raeburn 11832: return true;
11833: }
11834:
1.109 raeburn 11835: // ]]>
1.49 raeburn 11836: </script>
11837:
11838: ENDSCRIPT
11839: return $output;
11840: }
11841:
1.48 raeburn 11842: sub initialize_categories {
11843: my ($itemcount) = @_;
1.120 raeburn 11844: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11845: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11846: instcode => 'Official courses (with institutional codes)',
11847: communities => 'Communities',
1.272 raeburn 11848: placement => 'Placement Tests',
1.120 raeburn 11849: );
1.328 raeburn 11850: my %selnum = (
11851: instcode => '0',
11852: communities => '1',
11853: placement => '2',
11854: );
11855: my %selected;
1.272 raeburn 11856: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11858: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11859: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11860: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11861: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11862: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11863: .'<option value="0"'.$selected{'0'}.'>1</option>'
11864: .'<option value="1"'.$selected{'1'}.'>2</option>'
11865: .'<option value="2"'.$selected{'2'}.'>3</option>'
11866: .'<option value="3">4</option></select> '
1.120 raeburn 11867: .$default_names{$default}
11868: .'</span></td><td><span class="LC_nobreak">'
11869: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11870: .&mt('Display').'</label> <label>'
11871: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11872: .'</label></span></td></tr>';
1.120 raeburn 11873: $itemcount ++;
11874: }
1.48 raeburn 11875: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11876: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11877: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11878: .'<select name="addcategory_pos"'.$chgstr.'>'
11879: .'<option value="0">1</option>'
11880: .'<option value="1">2</option>'
1.328 raeburn 11881: .'<option value="2">3</option>'
11882: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11883: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11884: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11885: .'</td></tr>';
1.48 raeburn 11886: return $datatable;
11887: }
11888:
11889: sub build_category_rows {
1.49 raeburn 11890: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11891: my ($text,$name,$item,$chgstr);
1.48 raeburn 11892: if (ref($cats) eq 'ARRAY') {
11893: my $maxdepth = scalar(@{$cats});
11894: if (ref($cats->[$depth]) eq 'HASH') {
11895: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11896: my $numchildren = @{$cats->[$depth]{$parent}};
11897: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11898: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11899: my ($idxnum,$parent_name,$parent_item);
11900: my $higher = $depth - 1;
11901: if ($higher == 0) {
11902: $parent_name = &escape($parent).'::'.$higher;
11903: } else {
11904: if (ref($path) eq 'ARRAY') {
11905: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11906: }
11907: }
11908: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11909: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11910: if ($j < $numchildren) {
1.48 raeburn 11911: $name = $cats->[$depth]{$parent}[$j];
11912: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11913: $idxnum = $idx->{$item};
11914: } else {
11915: $name = $parent_name;
11916: $item = $parent_item;
1.48 raeburn 11917: }
1.49 raeburn 11918: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11919: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11920: for (my $i=0; $i<=$numchildren; $i++) {
11921: my $vpos = $i+1;
11922: my $selstr;
11923: if ($j == $i) {
11924: $selstr = ' selected="selected" ';
11925: }
11926: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11927: }
11928: $text .= '</select> ';
11929: if ($j < $numchildren) {
11930: my $deeper = $depth+1;
11931: $text .= $name.' '
11932: .'<label><input type="checkbox" name="deletecategory" value="'
11933: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11934: if(ref($path) eq 'ARRAY') {
11935: push(@{$path},$name);
1.49 raeburn 11936: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11937: pop(@{$path});
11938: }
11939: } else {
1.330 raeburn 11940: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11941: if ($j == $numchildren) {
11942: $text .= $name;
11943: } else {
11944: $text .= $item;
11945: }
11946: $text .= '" value="" />';
11947: }
11948: $text .= '</td></tr>';
11949: }
11950: $text .= '</table></td>';
11951: } else {
11952: my $higher = $depth-1;
11953: if ($higher == 0) {
11954: $name = &escape($parent).'::'.$higher;
11955: } else {
11956: if (ref($path) eq 'ARRAY') {
11957: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11958: }
11959: }
11960: my $colspan;
11961: if ($parent ne 'instcode') {
11962: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11963: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11964: }
11965: }
11966: }
11967: }
11968: return $text;
11969: }
11970:
1.33 raeburn 11971: sub modifiable_userdata_row {
1.305 raeburn 11972: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11973: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11974: my ($role,$rolename,$statustype);
11975: $role = $item;
1.224 raeburn 11976: if ($context eq 'cancreate') {
1.305 raeburn 11977: if ($item =~ /^(emailusername)_(.+)$/) {
11978: $role = $1;
11979: $statustype = $2;
1.228 raeburn 11980: if (ref($usertypes) eq 'HASH') {
11981: if ($usertypes->{$statustype}) {
11982: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11983: } else {
11984: $rolename = &mt('Data provided by user');
11985: }
11986: }
1.224 raeburn 11987: }
11988: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11989: if (ref($usertypes) eq 'HASH') {
11990: $rolename = $usertypes->{$role};
11991: } else {
11992: $rolename = $role;
11993: }
1.325 raeburn 11994: } elsif ($context eq 'lti') {
11995: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11996: } elsif ($context eq 'privacy') {
11997: $rolename = $itemdesc;
1.33 raeburn 11998: } else {
1.63 raeburn 11999: if ($role eq 'cr') {
12000: $rolename = &mt('Custom role');
12001: } else {
12002: $rolename = &Apache::lonnet::plaintext($role);
12003: }
1.33 raeburn 12004: }
1.224 raeburn 12005: my (@fields,%fieldtitles);
12006: if (ref($fieldsref) eq 'ARRAY') {
12007: @fields = @{$fieldsref};
12008: } else {
12009: @fields = ('lastname','firstname','middlename','generation',
12010: 'permanentemail','id');
12011: }
12012: if ((ref($titlesref) eq 'HASH')) {
12013: %fieldtitles = %{$titlesref};
12014: } else {
12015: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12016: }
1.33 raeburn 12017: my $output;
1.305 raeburn 12018: my $css_class;
12019: if ($rowcount%2) {
12020: $css_class = 'LC_odd_row';
12021: }
12022: if ($customcss) {
12023: $css_class .= " $customcss";
12024: }
12025: $css_class =~ s/^\s+//;
12026: if ($css_class) {
12027: $css_class = ' class="'.$css_class.'"';
12028: }
12029: if ($rowstyle) {
12030: $css_class .= ' style="'.$rowstyle.'"';
12031: }
12032: if ($rowid) {
12033: $rowid = ' id="'.$rowid.'"';
12034: }
12035: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12036: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12037: '<td class="LC_left_item" colspan="2"><table>';
12038: my $rem;
12039: my %checks;
1.325 raeburn 12040: my %current;
1.33 raeburn 12041: if (ref($settings) eq 'HASH') {
1.325 raeburn 12042: my $hashref;
12043: if ($context eq 'lti') {
12044: if (ref($settings) eq 'HASH') {
12045: $hashref = $settings->{'instdata'};
12046: }
1.357 raeburn 12047: } elsif ($context eq 'privacy') {
12048: my ($key,$inner) = split(/_/,$role);
12049: if (ref($settings) eq 'HASH') {
12050: if (ref($settings->{$key}) eq 'HASH') {
12051: $hashref = $settings->{$key}->{$inner};
12052: }
12053: }
1.325 raeburn 12054: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12055: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12056: $hashref = $settings->{'lti_instdata'};
12057: }
12058: if ($role eq 'emailusername') {
12059: if ($statustype) {
12060: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12061: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12062: }
1.325 raeburn 12063: }
12064: }
12065: }
12066: if (ref($hashref) eq 'HASH') {
12067: foreach my $field (@fields) {
12068: if ($hashref->{$field}) {
12069: if ($role eq 'emailusername') {
12070: $checks{$field} = $hashref->{$field};
12071: } else {
12072: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12073: }
12074: }
12075: }
12076: }
12077: }
1.305 raeburn 12078:
12079: my $total = scalar(@fields);
12080: for (my $i=0; $i<$total; $i++) {
12081: $rem = $i%($numinrow);
1.33 raeburn 12082: if ($rem == 0) {
12083: if ($i > 0) {
12084: $output .= '</tr>';
12085: }
12086: $output .= '<tr>';
12087: }
12088: my $check = ' ';
1.228 raeburn 12089: unless ($role eq 'emailusername') {
12090: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12091: $check = $checks{$fields[$i]};
1.357 raeburn 12092: } elsif ($context eq 'privacy') {
12093: if ($role =~ /^priv_(domain|course)$/) {
12094: if (ref($settings) ne 'HASH') {
12095: $check = ' checked="checked" ';
12096: }
12097: } elsif ($role =~ /^priv_(author|community)$/) {
12098: if (ref($settings) ne 'HASH') {
12099: unless ($fields[$i] eq 'id') {
12100: $check = ' checked="checked" ';
12101: }
12102: }
12103: } elsif ($role =~ /^(unpriv|othdom)_/) {
12104: if (ref($settings) ne 'HASH') {
12105: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12106: $check = ' checked="checked" ';
12107: }
12108: }
12109: }
1.325 raeburn 12110: } elsif ($context ne 'lti') {
1.228 raeburn 12111: if ($role eq 'st') {
12112: if (ref($settings) ne 'HASH') {
12113: $check = ' checked="checked" ';
12114: }
1.33 raeburn 12115: }
12116: }
12117: }
12118: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12119: '<span class="LC_nobreak">';
1.325 raeburn 12120: my $prefix = 'canmodify';
1.228 raeburn 12121: if ($role eq 'emailusername') {
12122: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12123: $checks{$fields[$i]} = 'omit';
12124: }
12125: foreach my $option ('required','optional','omit') {
12126: my $checked='';
12127: if ($checks{$fields[$i]} eq $option) {
12128: $checked='checked="checked" ';
12129: }
12130: $output .= '<label>'.
1.325 raeburn 12131: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12132: &mt($option).'</label>'.(' ' x2);
12133: }
12134: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12135: } else {
1.325 raeburn 12136: if ($context eq 'lti') {
12137: $prefix = 'lti';
1.357 raeburn 12138: } elsif ($context eq 'privacy') {
12139: $prefix = 'privacy';
1.325 raeburn 12140: }
1.228 raeburn 12141: $output .= '<label>'.
1.325 raeburn 12142: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12143: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12144: '</label>';
12145: }
12146: $output .= '</span></td>';
1.33 raeburn 12147: }
1.305 raeburn 12148: $rem = $total%$numinrow;
12149: my $colsleft;
12150: if ($rem) {
12151: $colsleft = $numinrow - $rem;
12152: }
12153: if ($colsleft > 1) {
1.33 raeburn 12154: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12155: ' </td>';
12156: } elsif ($colsleft == 1) {
12157: $output .= '<td class="LC_left_item"> </td>';
12158: }
12159: $output .= '</tr></table></td></tr>';
12160: return $output;
12161: }
1.28 raeburn 12162:
1.93 raeburn 12163: sub insttypes_row {
1.305 raeburn 12164: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12165: $customcss,$rowstyle) = @_;
1.93 raeburn 12166: my %lt = &Apache::lonlocal::texthash (
12167: cansearch => 'Users allowed to search',
12168: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 12169: lockablenames => 'User preference to lock name',
1.305 raeburn 12170: selfassign => 'Self-reportable affiliations',
1.315 raeburn 12171: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 12172: );
12173: my $showdom;
12174: if ($context eq 'cansearch') {
12175: $showdom = ' ('.$dom.')';
12176: }
1.165 raeburn 12177: my $class = 'LC_left_item';
12178: if ($context eq 'statustocreate') {
12179: $class = 'LC_right_item';
12180: }
1.305 raeburn 12181: my $css_class;
12182: if ($$rowtotal%2) {
12183: $css_class = 'LC_odd_row';
12184: }
12185: if ($customcss) {
12186: $css_class .= ' '.$customcss;
12187: }
12188: $css_class =~ s/^\s+//;
12189: if ($css_class) {
12190: $css_class = ' class="'.$css_class.'"';
12191: }
12192: if ($rowstyle) {
12193: $css_class .= ' style="'.$rowstyle.'"';
12194: }
12195: if ($onclick) {
12196: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12197: }
12198: my $output = '<tr'.$css_class.'>'.
12199: '<td>'.$lt{$context}.$showdom.
12200: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12201: my $rem;
12202: if (ref($types) eq 'ARRAY') {
12203: for (my $i=0; $i<@{$types}; $i++) {
12204: if (defined($usertypes->{$types->[$i]})) {
12205: my $rem = $i%($numinrow);
12206: if ($rem == 0) {
12207: if ($i > 0) {
12208: $output .= '</tr>';
12209: }
12210: $output .= '<tr>';
1.23 raeburn 12211: }
1.26 raeburn 12212: my $check = ' ';
1.99 raeburn 12213: if (ref($settings) eq 'HASH') {
12214: if (ref($settings->{$context}) eq 'ARRAY') {
12215: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12216: $check = ' checked="checked" ';
12217: }
1.315 raeburn 12218: } elsif (ref($settings->{$context}) eq 'HASH') {
12219: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12220: $check = ' checked="checked" ';
12221: }
1.99 raeburn 12222: } elsif ($context eq 'statustocreate') {
1.26 raeburn 12223: $check = ' checked="checked" ';
12224: }
1.23 raeburn 12225: }
1.26 raeburn 12226: $output .= '<td class="LC_left_item">'.
12227: '<span class="LC_nobreak"><label>'.
1.93 raeburn 12228: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 12229: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 12230: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12231: }
12232: }
1.26 raeburn 12233: $rem = @{$types}%($numinrow);
1.23 raeburn 12234: }
12235: my $colsleft = $numinrow - $rem;
1.315 raeburn 12236: if ($context eq 'overrides') {
12237: if ($colsleft > 1) {
12238: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12239: } else {
12240: $output .= '<td class="LC_left_item">';
12241: }
12242: $output .= ' ';
1.23 raeburn 12243: } else {
1.334 raeburn 12244: if ($rem == 0) {
1.315 raeburn 12245: $output .= '<tr>';
12246: }
12247: if ($colsleft > 1) {
12248: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12249: } else {
12250: $output .= '<td class="LC_left_item">';
12251: }
12252: my $defcheck = ' ';
12253: if (ref($settings) eq 'HASH') {
12254: if (ref($settings->{$context}) eq 'ARRAY') {
12255: if (grep(/^default$/,@{$settings->{$context}})) {
12256: $defcheck = ' checked="checked" ';
12257: }
12258: } elsif ($context eq 'statustocreate') {
1.99 raeburn 12259: $defcheck = ' checked="checked" ';
12260: }
1.26 raeburn 12261: }
1.315 raeburn 12262: $output .= '<span class="LC_nobreak"><label>'.
12263: '<input type="checkbox" name="'.$context.'" '.
12264: 'value="default"'.$defcheck.$onclick.' />'.
12265: $othertitle.'</label></span>';
1.23 raeburn 12266: }
1.315 raeburn 12267: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12268: return $output;
1.23 raeburn 12269: }
12270:
12271: sub sorted_searchtitles {
12272: my %searchtitles = &Apache::lonlocal::texthash(
12273: 'uname' => 'username',
12274: 'lastname' => 'last name',
12275: 'lastfirst' => 'last name, first name',
12276: );
12277: my @titleorder = ('uname','lastname','lastfirst');
12278: return (\%searchtitles,\@titleorder);
12279: }
12280:
1.25 raeburn 12281: sub sorted_searchtypes {
12282: my %srchtypes_desc = (
12283: exact => 'is exact match',
12284: contains => 'contains ..',
12285: begins => 'begins with ..',
12286: );
12287: my @srchtypeorder = ('exact','begins','contains');
12288: return (\%srchtypes_desc,\@srchtypeorder);
12289: }
12290:
1.3 raeburn 12291: sub usertype_update_row {
12292: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12293: my $datatable;
12294: my $numinrow = 4;
12295: foreach my $type (@{$types}) {
12296: if (defined($usertypes->{$type})) {
12297: $$rownums ++;
12298: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12299: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12300: '</td><td class="LC_left_item"><table>';
12301: for (my $i=0; $i<@{$fields}; $i++) {
12302: my $rem = $i%($numinrow);
12303: if ($rem == 0) {
12304: if ($i > 0) {
12305: $datatable .= '</tr>';
12306: }
12307: $datatable .= '<tr>';
12308: }
12309: my $check = ' ';
1.39 raeburn 12310: if (ref($settings) eq 'HASH') {
12311: if (ref($settings->{'fields'}) eq 'HASH') {
12312: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12313: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12314: $check = ' checked="checked" ';
12315: }
1.3 raeburn 12316: }
12317: }
12318: }
12319:
12320: if ($i == @{$fields}-1) {
12321: my $colsleft = $numinrow - $rem;
12322: if ($colsleft > 1) {
12323: $datatable .= '<td colspan="'.$colsleft.'">';
12324: } else {
12325: $datatable .= '<td>';
12326: }
12327: } else {
12328: $datatable .= '<td>';
12329: }
1.8 raeburn 12330: $datatable .= '<span class="LC_nobreak"><label>'.
12331: '<input type="checkbox" name="updateable_'.$type.
12332: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12333: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12334: }
12335: $datatable .= '</tr></table></td></tr>';
12336: }
12337: }
12338: return $datatable;
1.1 raeburn 12339: }
12340:
12341: sub modify_login {
1.205 raeburn 12342: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12343: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12344: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12345: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12346: %title = ( coursecatalog => 'Display course catalog',
12347: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12348: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12349: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12350: loginheader => 'Log-in box header',
12351: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12352: @offon = ('off','on');
1.112 raeburn 12353: if (ref($domconfig{login}) eq 'HASH') {
12354: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12355: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12356: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12357: }
12358: }
1.386 raeburn 12359: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12360: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12361: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12362: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12363: $saml{$lonhost} = 1;
12364: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12365: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12366: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12367: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12368: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12369: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12370: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12371: }
12372: }
12373: }
1.112 raeburn 12374: }
1.9 raeburn 12375: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12376: \%domconfig,\%loginhash);
1.188 raeburn 12377: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12378: foreach my $item (@toggles) {
12379: $loginhash{login}{$item} = $env{'form.'.$item};
12380: }
1.41 raeburn 12381: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12382: if (ref($colchanges{'login'}) eq 'HASH') {
12383: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12384: \%loginhash);
12385: }
1.110 raeburn 12386:
1.149 raeburn 12387: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12388: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12389: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12390: if (keys(%servers) > 1) {
12391: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12392: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12393: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12394: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12395: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12396: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12397: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12398: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12399: $changes{'loginvia'}{$lonhost} = 1;
12400: } else {
12401: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12402: $changes{'loginvia'}{$lonhost} = 1;
12403: }
12404: } else {
12405: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12406: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12407: $changes{'loginvia'}{$lonhost} = 1;
12408: }
12409: }
12410: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12411: foreach my $item (@loginvia_attribs) {
12412: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12413: }
12414: } else {
12415: foreach my $item (@loginvia_attribs) {
12416: my $new = $env{'form.'.$lonhost.'_'.$item};
12417: if (($item eq 'serverpath') && ($new eq 'custom')) {
12418: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12419: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12420: $new = '/';
12421: }
12422: }
12423: if (($item eq 'custompath') &&
12424: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12425: $new = '';
12426: }
12427: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12428: $changes{'loginvia'}{$lonhost} = 1;
12429: }
12430: if ($item eq 'exempt') {
1.256 raeburn 12431: $new = &check_exempt_addresses($new);
1.128 raeburn 12432: }
12433: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12434: }
12435: }
1.112 raeburn 12436: } else {
1.128 raeburn 12437: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12438: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12439: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12440: foreach my $item (@loginvia_attribs) {
12441: my $new = $env{'form.'.$lonhost.'_'.$item};
12442: if (($item eq 'serverpath') && ($new eq 'custom')) {
12443: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12444: $new = '/';
12445: }
12446: }
12447: if (($item eq 'custompath') &&
12448: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12449: $new = '';
12450: }
12451: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12452: }
1.110 raeburn 12453: }
12454: }
12455: }
12456: }
1.119 raeburn 12457:
1.168 raeburn 12458: my $servadm = $r->dir_config('lonAdmEMail');
12459: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12460: if (ref($domconfig{'login'}) eq 'HASH') {
12461: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12462: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12463: if ($lang eq 'nolang') {
12464: push(@currlangs,$lang);
12465: } elsif (defined($langchoices{$lang})) {
12466: push(@currlangs,$lang);
12467: } else {
12468: next;
12469: }
12470: }
12471: }
12472: }
12473: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12474: if (@currlangs > 0) {
12475: foreach my $lang (@currlangs) {
12476: if (grep(/^\Q$lang\E$/,@delurls)) {
12477: $changes{'helpurl'}{$lang} = 1;
12478: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12479: $changes{'helpurl'}{$lang} = 1;
12480: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12481: push(@newlangs,$lang);
12482: } else {
12483: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12484: }
12485: }
12486: }
12487: unless (grep(/^nolang$/,@currlangs)) {
12488: if ($env{'form.loginhelpurl_nolang.filename'}) {
12489: $changes{'helpurl'}{'nolang'} = 1;
12490: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12491: push(@newlangs,'nolang');
12492: }
12493: }
12494: if ($env{'form.loginhelpurl_add_lang'}) {
12495: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12496: ($env{'form.loginhelpurl_add_file.filename'})) {
12497: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12498: $addedfile = $env{'form.loginhelpurl_add_lang'};
12499: }
12500: }
12501: if ((@newlangs > 0) || ($addedfile)) {
12502: my $error;
12503: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12504: if ($configuserok eq 'ok') {
12505: if ($switchserver) {
12506: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12507: } elsif ($author_ok eq 'ok') {
12508: my @allnew = @newlangs;
12509: if ($addedfile ne '') {
12510: push(@allnew,$addedfile);
12511: }
12512: foreach my $lang (@allnew) {
12513: my $formelem = 'loginhelpurl_'.$lang;
12514: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12515: $formelem = 'loginhelpurl_add_file';
12516: }
12517: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12518: "help/$lang",'','',$newfile{$lang});
12519: if ($result eq 'ok') {
12520: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12521: $changes{'helpurl'}{$lang} = 1;
12522: } else {
12523: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12524: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12525: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12526: (!grep(/^\Q$lang\E$/,@delurls))) {
12527: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12528: }
12529: }
12530: }
12531: } else {
12532: $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);
12533: }
12534: } else {
12535: $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);
12536: }
12537: if ($error) {
12538: &Apache::lonnet::logthis($error);
12539: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12540: }
12541: }
1.256 raeburn 12542:
12543: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12544: if (ref($domconfig{'login'}) eq 'HASH') {
12545: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12546: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12547: if ($domservers{$lonhost}) {
12548: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12549: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12550: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12551: }
12552: }
12553: }
12554: }
12555: }
12556: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12557: foreach my $lonhost (sort(keys(%domservers))) {
12558: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12559: $changes{'headtag'}{$lonhost} = 1;
12560: } else {
12561: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12562: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12563: }
12564: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12565: push(@newhosts,$lonhost);
12566: } elsif ($currheadtagurls{$lonhost}) {
12567: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12568: if ($currexempt{$lonhost}) {
1.289 raeburn 12569: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12570: $changes{'headtag'}{$lonhost} = 1;
12571: }
12572: } elsif ($possexempt{$lonhost}) {
12573: $changes{'headtag'}{$lonhost} = 1;
12574: }
12575: if ($possexempt{$lonhost}) {
12576: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12577: }
12578: }
12579: }
12580: }
12581: if (@newhosts) {
12582: my $error;
12583: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12584: if ($configuserok eq 'ok') {
12585: if ($switchserver) {
12586: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12587: } elsif ($author_ok eq 'ok') {
12588: foreach my $lonhost (@newhosts) {
12589: my $formelem = 'loginheadtag_'.$lonhost;
12590: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12591: "login/headtag/$lonhost",'','',
12592: $env{'form.loginheadtag_'.$lonhost.'.filename'});
12593: if ($result eq 'ok') {
12594: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12595: $changes{'headtag'}{$lonhost} = 1;
12596: if ($possexempt{$lonhost}) {
12597: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12598: }
12599: } else {
12600: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12601: $newheadtagurls{$lonhost},$result);
12602: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12603: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12604: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12605: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12606: }
12607: }
12608: }
12609: } else {
12610: $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);
12611: }
12612: } else {
12613: $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);
12614: }
12615: if ($error) {
12616: &Apache::lonnet::logthis($error);
12617: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12618: }
12619: }
1.386 raeburn 12620: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12621: my @newsamlimgs;
12622: foreach my $lonhost (keys(%domservers)) {
12623: if ($env{'form.saml_'.$lonhost}) {
12624: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12625: push(@newsamlimgs,$lonhost);
12626: }
1.412 raeburn 12627: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12628: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12629: }
12630: if ($saml{$lonhost}) {
1.412 raeburn 12631: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12632: $env{'form.saml_window_'.$lonhost} = '';
12633: }
1.386 raeburn 12634: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12635: #FIXME Need to obsolete published image
12636: delete($currsaml{$lonhost}{'img'});
12637: $changes{'saml'}{$lonhost} = 1;
12638: }
12639: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12640: $changes{'saml'}{$lonhost} = 1;
12641: }
12642: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12643: $changes{'saml'}{$lonhost} = 1;
12644: }
12645: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12646: $changes{'saml'}{$lonhost} = 1;
12647: }
12648: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12649: $changes{'saml'}{$lonhost} = 1;
12650: }
1.412 raeburn 12651: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12652: $changes{'saml'}{$lonhost} = 1;
12653: }
1.386 raeburn 12654: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12655: $changes{'saml'}{$lonhost} = 1;
12656: }
12657: } else {
12658: $changes{'saml'}{$lonhost} = 1;
12659: }
1.412 raeburn 12660: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12661: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12662: }
12663: } else {
1.389 raeburn 12664: if ($saml{$lonhost}) {
12665: $changes{'saml'}{$lonhost} = 1;
12666: delete($currsaml{$lonhost});
12667: }
1.386 raeburn 12668: }
12669: }
12670: foreach my $posshost (keys(%currsaml)) {
12671: unless (exists($domservers{$posshost})) {
12672: delete($currsaml{$posshost});
12673: }
12674: }
12675: %{$loginhash{'login'}{'saml'}} = %currsaml;
12676: if (@newsamlimgs) {
12677: my $error;
12678: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12679: if ($configuserok eq 'ok') {
12680: if ($switchserver) {
12681: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12682: } elsif ($author_ok eq 'ok') {
12683: foreach my $lonhost (@newsamlimgs) {
12684: my $formelem = 'saml_img_'.$lonhost;
12685: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12686: "login/saml/$lonhost",'','',
12687: $env{'form.saml_img_'.$lonhost.'.filename'});
12688: if ($result eq 'ok') {
12689: $currsaml{$lonhost}{'img'} = $imgurl;
12690: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12691: $changes{'saml'}{$lonhost} = 1;
12692: } else {
12693: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12694: $lonhost,$result);
12695: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12696: }
12697: }
12698: } else {
12699: $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);
12700: }
12701: } else {
12702: $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);
12703: }
12704: if ($error) {
12705: &Apache::lonnet::logthis($error);
12706: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12707: }
12708: }
1.169 raeburn 12709: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12710:
12711: my $defaulthelpfile = '/adm/loginproblems.html';
12712: my $defaulttext = &mt('Default in use');
12713:
1.1 raeburn 12714: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12715: $dom);
12716: if ($putresult eq 'ok') {
1.188 raeburn 12717: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12718: my %defaultchecked = (
12719: 'coursecatalog' => 'on',
1.188 raeburn 12720: 'helpdesk' => 'on',
1.42 raeburn 12721: 'adminmail' => 'off',
1.43 raeburn 12722: 'newuser' => 'off',
1.42 raeburn 12723: );
1.55 raeburn 12724: if (ref($domconfig{'login'}) eq 'HASH') {
12725: foreach my $item (@toggles) {
12726: if ($defaultchecked{$item} eq 'on') {
12727: if (($domconfig{'login'}{$item} eq '0') &&
12728: ($env{'form.'.$item} eq '1')) {
12729: $changes{$item} = 1;
12730: } elsif (($domconfig{'login'}{$item} eq '' ||
12731: $domconfig{'login'}{$item} eq '1') &&
12732: ($env{'form.'.$item} eq '0')) {
12733: $changes{$item} = 1;
12734: }
12735: } elsif ($defaultchecked{$item} eq 'off') {
12736: if (($domconfig{'login'}{$item} eq '1') &&
12737: ($env{'form.'.$item} eq '0')) {
12738: $changes{$item} = 1;
12739: } elsif (($domconfig{'login'}{$item} eq '' ||
12740: $domconfig{'login'}{$item} eq '0') &&
12741: ($env{'form.'.$item} eq '1')) {
12742: $changes{$item} = 1;
12743: }
1.42 raeburn 12744: }
12745: }
1.41 raeburn 12746: }
1.6 raeburn 12747: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12748: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12749: if (exists($changes{'saml'})) {
12750: my $hostid_in_use;
12751: my @hosts = &Apache::lonnet::current_machine_ids();
12752: if (@hosts > 1) {
12753: foreach my $hostid (@hosts) {
12754: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12755: $hostid_in_use = $hostid;
12756: last;
12757: }
12758: }
12759: } else {
12760: $hostid_in_use = $r->dir_config('lonHostID');
12761: }
12762: if (($hostid_in_use) &&
12763: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12764: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12765: }
12766: if (ref($lastactref) eq 'HASH') {
12767: if (ref($changes{'saml'}) eq 'HASH') {
12768: my %updates;
12769: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12770: $lastactref->{'samllanding'} = \%updates;
12771: }
12772: }
12773: }
1.212 raeburn 12774: if (ref($lastactref) eq 'HASH') {
12775: $lastactref->{'domainconfig'} = 1;
12776: }
1.1 raeburn 12777: $resulttext = &mt('Changes made:').'<ul>';
12778: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12779: if ($item eq 'loginvia') {
1.112 raeburn 12780: if (ref($changes{$item}) eq 'HASH') {
12781: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12782: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12783: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12784: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12785: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12786: $protocol = 'http' if ($protocol ne 'https');
12787: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12788:
12789: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12790: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12791: } else {
12792: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12793: }
12794: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12795: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12796: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12797: }
12798: $resulttext .= '</li>';
12799: } else {
12800: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12801: }
1.112 raeburn 12802: } else {
1.128 raeburn 12803: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12804: }
12805: }
1.128 raeburn 12806: $resulttext .= '</ul></li>';
1.112 raeburn 12807: }
1.168 raeburn 12808: } elsif ($item eq 'helpurl') {
12809: if (ref($changes{$item}) eq 'HASH') {
12810: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12811: if (grep(/^\Q$lang\E$/,@delurls)) {
12812: my ($chg,$link);
12813: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12814: if ($lang eq 'nolang') {
12815: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12816: } else {
12817: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12818: }
12819: $resulttext .= '<li>'.$chg.'</li>';
12820: } else {
12821: my $chg;
12822: if ($lang eq 'nolang') {
12823: $chg = &mt('custom log-in help file for no preferred language');
12824: } else {
12825: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12826: }
12827: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12828: $loginhash{'login'}{'helpurl'}{$lang}.
12829: '?inhibitmenu=yes',$chg,600,500).
12830: '</li>';
12831: }
12832: }
12833: }
1.256 raeburn 12834: } elsif ($item eq 'headtag') {
12835: if (ref($changes{$item}) eq 'HASH') {
12836: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12837: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12838: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12839: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12840: $resulttext .= '<li><a href="'.
12841: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12842: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12843: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12844: if ($possexempt{$lonhost}) {
12845: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12846: } else {
12847: $resulttext .= &mt('included for any client IP');
12848: }
12849: $resulttext .= '</li>';
12850: }
12851: }
12852: }
1.386 raeburn 12853: } elsif ($item eq 'saml') {
12854: if (ref($changes{$item}) eq 'HASH') {
12855: my %notlt = (
12856: text => 'Text for log-in by SSO',
12857: img => 'SSO button image',
12858: alt => 'Alt text for button image',
12859: url => 'SSO URL',
12860: title => 'Tooltip for SSO link',
1.412 raeburn 12861: window => 'Pop-up window if iframe',
1.386 raeburn 12862: notsso => 'Text for non-SSO log-in',
12863: );
12864: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12865: if (ref($currsaml{$lonhost}) eq 'HASH') {
12866: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12867: '<ul>';
1.412 raeburn 12868: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12869: if ($currsaml{$lonhost}{$key} eq '') {
12870: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12871: } else {
12872: my $value = "'$currsaml{$lonhost}{$key}'";
12873: if ($key eq 'img') {
12874: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12875: } elsif ($key eq 'window') {
12876: $value = 'On';
1.386 raeburn 12877: }
12878: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12879: $value).'</li>';
12880: }
12881: }
12882: $resulttext .= '</ul></li>';
12883: } else {
12884: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12885: }
12886: }
12887: }
1.169 raeburn 12888: } elsif ($item eq 'captcha') {
12889: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12890: my $chgtxt;
1.169 raeburn 12891: if ($loginhash{'login'}{$item} eq 'notused') {
12892: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12893: } else {
12894: my %captchas = &captcha_phrases();
12895: if ($captchas{$loginhash{'login'}{$item}}) {
12896: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12897: } else {
12898: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12899: }
12900: }
12901: $resulttext .= '<li>'.$chgtxt.'</li>';
12902: }
12903: } elsif ($item eq 'recaptchakeys') {
12904: if (ref($loginhash{'login'}) eq 'HASH') {
12905: my ($privkey,$pubkey);
12906: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12907: $pubkey = $loginhash{'login'}{$item}{'public'};
12908: $privkey = $loginhash{'login'}{$item}{'private'};
12909: }
12910: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12911: if (!$pubkey) {
12912: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12913: } else {
12914: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12915: }
12916: if (!$privkey) {
12917: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12918: } else {
1.251 raeburn 12919: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12920: }
12921: $chgtxt .= '</ul>';
12922: $resulttext .= '<li>'.$chgtxt.'</li>';
12923: }
1.269 raeburn 12924: } elsif ($item eq 'recaptchaversion') {
12925: if (ref($loginhash{'login'}) eq 'HASH') {
12926: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12927: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12928: '</li>';
12929: }
12930: }
1.41 raeburn 12931: } else {
12932: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12933: }
1.1 raeburn 12934: }
1.6 raeburn 12935: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12936: } else {
12937: $resulttext = &mt('No changes made to log-in page settings');
12938: }
12939: } else {
1.11 albertel 12940: $resulttext = '<span class="LC_error">'.
12941: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12942: }
1.6 raeburn 12943: if ($errors) {
1.9 raeburn 12944: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12945: $errors.'</ul>';
12946: }
12947: return $resulttext;
12948: }
12949:
1.256 raeburn 12950: sub check_exempt_addresses {
12951: my ($iplist) = @_;
12952: $iplist =~ s/^\s+//;
12953: $iplist =~ s/\s+$//;
12954: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12955: my (@okips,$new);
12956: foreach my $ip (@poss_ips) {
12957: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12958: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12959: push(@okips,$ip);
12960: }
12961: }
12962: }
12963: if (@okips > 0) {
12964: $new = join(',',@okips);
12965: } else {
12966: $new = '';
12967: }
12968: return $new;
12969: }
12970:
1.6 raeburn 12971: sub color_font_choices {
12972: my %choices =
12973: &Apache::lonlocal::texthash (
12974: img => "Header",
12975: bgs => "Background colors",
12976: links => "Link colors",
1.55 raeburn 12977: images => "Images",
1.6 raeburn 12978: font => "Font color",
1.201 raeburn 12979: fontmenu => "Font menu",
1.76 raeburn 12980: pgbg => "Page",
1.6 raeburn 12981: tabbg => "Header",
12982: sidebg => "Border",
12983: link => "Link",
12984: alink => "Active link",
12985: vlink => "Visited link",
12986: );
12987: return %choices;
12988: }
12989:
1.394 raeburn 12990: sub modify_ipaccess {
12991: my ($dom,$lastactref,%domconfig) = @_;
12992: my (@allpos,%changes,%confhash,$errors,$resulttext);
12993: my (@items,%deletions,%itemids,@warnings);
12994: my ($typeorder,$types) = &commblocktype_text();
12995: if ($env{'form.ipaccess_add'}) {
12996: my $name = $env{'form.ipaccess_name_add'};
12997: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12998: if ($newid) {
12999: $itemids{'add'} = $newid;
13000: push(@items,'add');
13001: $changes{$newid} = 1;
13002: } else {
13003: $error = &mt('Failed to acquire unique ID for new IP access control item');
13004: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13005: }
13006: }
13007: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13008: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13009: if (@todelete) {
13010: map { $deletions{$_} = 1; } @todelete;
13011: }
13012: my $maxnum = $env{'form.ipaccess_maxnum'};
13013: for (my $i=0; $i<$maxnum; $i++) {
13014: my $itemid = $env{'form.ipaccess_id_'.$i};
13015: $itemid =~ s/\D+//g;
13016: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13017: if ($deletions{$itemid}) {
13018: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13019: } else {
13020: push(@items,$i);
13021: $itemids{$i} = $itemid;
13022: }
13023: }
13024: }
13025: }
13026: foreach my $idx (@items) {
13027: my $itemid = $itemids{$idx};
13028: next unless ($itemid);
13029: my %current;
13030: unless ($idx eq 'add') {
13031: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13032: %current = %{$domconfig{'ipaccess'}{$itemid}};
13033: }
13034: }
13035: my $position = $env{'form.ipaccess_pos_'.$itemid};
13036: $position =~ s/\D+//g;
13037: if ($position ne '') {
13038: $allpos[$position] = $itemid;
13039: }
13040: my $name = $env{'form.ipaccess_name_'.$idx};
13041: $name =~ s/^\s+|\s+$//g;
13042: $confhash{$itemid}{'name'} = $name;
13043: my $possrange = $env{'form.ipaccess_range_'.$idx};
13044: $possrange =~ s/^\s+|\s+$//g;
13045: unless ($possrange eq '') {
13046: $possrange =~ s/[\r\n]+/\s/g;
13047: $possrange =~ s/\s*-\s*/-/g;
13048: $possrange =~ s/\s+/,/g;
13049: $possrange =~ s/,+/,/g;
13050: if ($possrange ne '') {
13051: my (@ok,$count);
13052: $count = 0;
13053: foreach my $poss (split(/\,/,$possrange)) {
13054: $count ++;
13055: $poss = &validate_ip_pattern($poss);
13056: if ($poss ne '') {
13057: push(@ok,$poss);
13058: }
13059: }
13060: my $diff = $count - scalar(@ok);
13061: if ($diff) {
13062: $errors .= '<li><span class="LC_error">'.
13063: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13064: $diff,$name).
13065: '</span></li>';
13066: }
13067: if (@ok) {
13068: my @cidr_list;
13069: foreach my $item (@ok) {
13070: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13071: }
13072: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13073: }
13074: }
13075: }
13076: foreach my $field ('name','ip') {
13077: unless (($idx eq 'add') || ($changes{$itemid})) {
13078: if ($current{$field} ne $confhash{$itemid}{$field}) {
13079: $changes{$itemid} = 1;
13080: last;
13081: }
13082: }
13083: }
13084: $confhash{$itemid}{'commblocks'} = {};
13085:
13086: my %commblocks;
13087: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
13088: foreach my $type (@{$typeorder}) {
13089: if ($commblocks{$type}) {
13090: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13091: }
13092: unless (($idx eq 'add') || ($changes{$itemid})) {
13093: if (ref($current{'commblocks'}) eq 'HASH') {
13094: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13095: $changes{$itemid} = 1;
13096: }
13097: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13098: $changes{$itemid} = 1;
13099: }
13100: }
13101: }
13102: $confhash{$itemid}{'courses'} = {};
13103: my %crsdeletions;
13104: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13105: if (@delcrs) {
13106: map { $crsdeletions{$_} = 1; } @delcrs;
13107: }
13108: if (ref($current{'courses'}) eq 'HASH') {
13109: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13110: if ($crsdeletions{$cid}) {
13111: $changes{$itemid} = 1;
13112: } else {
13113: $confhash{$itemid}{'courses'}{$cid} = 1;
13114: }
13115: }
13116: }
13117: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13118: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
13119: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
13120: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13121: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13122: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13123: $errors .= '<li><span class="LC_error">'.
13124: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13125: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13126: '</span></li>';
13127: } else {
13128: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13129: $changes{$itemid} = 1;
13130: }
13131: }
13132: }
13133: if (@allpos > 0) {
13134: my $idx = 0;
13135: foreach my $itemid (@allpos) {
13136: if ($itemid ne '') {
13137: $confhash{$itemid}{'order'} = $idx;
13138: unless ($changes{$itemid}) {
13139: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13140: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13141: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13142: $changes{$itemid} = 1;
13143: }
13144: }
13145: }
13146: }
13147: $idx ++;
13148: }
13149: }
13150: }
13151: if (keys(%changes)) {
13152: my %defaultshash = (
13153: ipaccess => \%confhash,
13154: );
13155: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13156: $dom);
13157: if ($putresult eq 'ok') {
13158: my $cachetime = 1800;
13159: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13160: if (ref($lastactref) eq 'HASH') {
13161: $lastactref->{'ipaccess'} = 1;
13162: }
13163: $resulttext = &mt('Changes made:').'<ul>';
13164: my %bynum;
13165: foreach my $itemid (sort(keys(%changes))) {
13166: if (ref($confhash{$itemid}) eq 'HASH') {
13167: my $position = $confhash{$itemid}{'order'};
13168: if ($position =~ /^\d+$/) {
13169: $bynum{$position} = $itemid;
13170: }
13171: }
13172: }
13173: if (keys(%deletions)) {
13174: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13175: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13176: }
13177: }
13178: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13179: my $itemid = $bynum{$pos};
13180: if (ref($confhash{$itemid}) eq 'HASH') {
13181: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13182: my $position = $pos + 1;
13183: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13184: if ($confhash{$itemid}{'ip'} eq '') {
13185: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13186: } else {
13187: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13188: }
13189: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13190: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13191: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13192: '</li>';
13193: } else {
13194: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13195: }
13196: if (keys(%{$confhash{$itemid}{'courses'}})) {
13197: my @courses;
13198: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
13199: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
13200: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13201: }
13202: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13203: join('</li><li>',@courses).'</li></ul>';
13204: } else {
13205: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13206: }
1.395 raeburn 13207: $resulttext .= '</ul></li>';
1.394 raeburn 13208: }
13209: }
1.395 raeburn 13210: $resulttext .= '</ul>';
1.394 raeburn 13211: } else {
13212: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13213: }
13214: } else {
13215: $resulttext = &mt('No changes made');
13216: }
13217: if ($errors) {
13218: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13219: $errors.'</ul></p>';
13220: }
13221: return $resulttext;
13222: }
13223:
13224: sub get_ipaccess_id {
13225: my ($domain,$location) = @_;
13226: # get lock on ipaccess db
13227: my $lockhash = {
13228: lock => $env{'user.name'}.
13229: ':'.$env{'user.domain'},
13230: };
13231: my $tries = 0;
13232: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13233: my ($id,$error);
13234:
13235: while (($gotlock ne 'ok') && ($tries<10)) {
13236: $tries ++;
13237: sleep (0.1);
13238: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13239: }
13240: if ($gotlock eq 'ok') {
13241: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13242: if ($currids{'lock'}) {
13243: delete($currids{'lock'});
13244: if (keys(%currids)) {
13245: my @curr = sort { $a <=> $b } keys(%currids);
13246: if ($curr[-1] =~ /^\d+$/) {
13247: $id = 1 + $curr[-1];
13248: }
13249: } else {
13250: $id = 1;
13251: }
13252: if ($id) {
13253: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13254: $error = 'nostore';
13255: }
13256: } else {
13257: $error = 'nonumber';
13258: }
13259: }
13260: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13261: } else {
13262: $error = 'nolock';
13263: }
13264: return ($id,$error);
13265: }
13266:
1.6 raeburn 13267: sub modify_rolecolors {
1.205 raeburn 13268: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13269: my ($resulttext,%rolehash);
13270: $rolehash{'rolecolors'} = {};
1.55 raeburn 13271: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13272: if ($domconfig{'rolecolors'} eq '') {
13273: $domconfig{'rolecolors'} = {};
13274: }
13275: }
1.9 raeburn 13276: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13277: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13278: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13279: $dom);
13280: if ($putresult eq 'ok') {
13281: if (keys(%changes) > 0) {
1.41 raeburn 13282: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13283: if (ref($lastactref) eq 'HASH') {
13284: $lastactref->{'domainconfig'} = 1;
13285: }
1.6 raeburn 13286: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13287: $rolehash{'rolecolors'});
13288: } else {
13289: $resulttext = &mt('No changes made to default color schemes');
13290: }
13291: } else {
1.11 albertel 13292: $resulttext = '<span class="LC_error">'.
13293: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13294: }
13295: if ($errors) {
13296: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13297: $errors.'</ul>';
13298: }
13299: return $resulttext;
13300: }
13301:
13302: sub modify_colors {
1.9 raeburn 13303: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13304: my (%changes,%choices);
1.51 raeburn 13305: my @bgs;
1.6 raeburn 13306: my @links = ('link','alink','vlink');
1.41 raeburn 13307: my @logintext;
1.6 raeburn 13308: my @images;
13309: my $servadm = $r->dir_config('lonAdmEMail');
13310: my $errors;
1.200 raeburn 13311: my %defaults;
1.6 raeburn 13312: foreach my $role (@{$roles}) {
13313: if ($role eq 'login') {
1.12 raeburn 13314: %choices = &login_choices();
1.41 raeburn 13315: @logintext = ('textcol','bgcol');
1.12 raeburn 13316: } else {
13317: %choices = &color_font_choices();
13318: }
13319: if ($role eq 'login') {
1.41 raeburn 13320: @images = ('img','logo','domlogo','login');
1.51 raeburn 13321: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13322: } else {
13323: @images = ('img');
1.200 raeburn 13324: @bgs = ('pgbg','tabbg','sidebg');
13325: }
13326: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13327: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13328: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13329: }
13330: if ($role eq 'login') {
13331: foreach my $item (@logintext) {
1.234 raeburn 13332: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13333: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13334: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13335: }
13336: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13337: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13338: }
13339: }
13340: } else {
1.234 raeburn 13341: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13342: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13343: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13344: }
13345: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13346: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13347: }
1.6 raeburn 13348: }
1.200 raeburn 13349: foreach my $item (@bgs) {
1.234 raeburn 13350: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13351: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13352: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13353: }
13354: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13355: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13356: }
13357: }
13358: foreach my $item (@links) {
1.234 raeburn 13359: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13360: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13361: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13362: }
13363: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13364: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13365: }
1.6 raeburn 13366: }
1.46 raeburn 13367: my ($configuserok,$author_ok,$switchserver) =
13368: &config_check($dom,$confname,$servadm);
1.9 raeburn 13369: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13370: if (ref($domconfig->{$role}) ne 'HASH') {
13371: $domconfig->{$role} = {};
13372: }
1.8 raeburn 13373: foreach my $img (@images) {
1.402 raeburn 13374: if ($role eq 'login') {
13375: if (($img eq 'img') || ($img eq 'logo')) {
13376: if (defined($env{'form.login_showlogo_'.$img})) {
13377: $confhash->{$role}{'showlogo'}{$img} = 1;
13378: } else {
13379: $confhash->{$role}{'showlogo'}{$img} = 0;
13380: }
13381: }
13382: if ($env{'form.login_alt_'.$img} ne '') {
13383: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13384: }
1.402 raeburn 13385: }
1.18 albertel 13386: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13387: && !defined($domconfig->{$role}{$img})
13388: && !$env{'form.'.$role.'_del_'.$img}
13389: && $env{'form.'.$role.'_import_'.$img}) {
13390: # import the old configured image from the .tab setting
13391: # if they haven't provided a new one
13392: $domconfig->{$role}{$img} =
13393: $env{'form.'.$role.'_import_'.$img};
13394: }
1.6 raeburn 13395: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13396: my $error;
1.6 raeburn 13397: if ($configuserok eq 'ok') {
1.9 raeburn 13398: if ($switchserver) {
1.12 raeburn 13399: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13400: } else {
13401: if ($author_ok eq 'ok') {
13402: my ($result,$logourl) =
13403: &publishlogo($r,'upload',$role.'_'.$img,
13404: $dom,$confname,$img,$width,$height);
13405: if ($result eq 'ok') {
13406: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13407: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 13408: } else {
1.12 raeburn 13409: $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 13410: }
13411: } else {
1.46 raeburn 13412: $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 13413: }
13414: }
13415: } else {
1.46 raeburn 13416: $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 13417: }
13418: if ($error) {
1.8 raeburn 13419: &Apache::lonnet::logthis($error);
1.11 albertel 13420: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13421: }
13422: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13423: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13424: my $error;
13425: if ($configuserok eq 'ok') {
13426: # is confname an author?
13427: if ($switchserver eq '') {
13428: if ($author_ok eq 'ok') {
13429: my ($result,$logourl) =
13430: &publishlogo($r,'copy',$domconfig->{$role}{$img},
13431: $dom,$confname,$img,$width,$height);
13432: if ($result eq 'ok') {
13433: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13434: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 13435: }
13436: }
13437: }
13438: }
1.6 raeburn 13439: }
13440: }
13441: }
13442: if (ref($domconfig) eq 'HASH') {
13443: if (ref($domconfig->{$role}) eq 'HASH') {
13444: foreach my $img (@images) {
13445: if ($domconfig->{$role}{$img} ne '') {
13446: if ($env{'form.'.$role.'_del_'.$img}) {
13447: $confhash->{$role}{$img} = '';
1.12 raeburn 13448: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13449: } else {
1.9 raeburn 13450: if ($confhash->{$role}{$img} eq '') {
13451: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13452: }
1.6 raeburn 13453: }
13454: } else {
13455: if ($env{'form.'.$role.'_del_'.$img}) {
13456: $confhash->{$role}{$img} = '';
1.12 raeburn 13457: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13458: }
13459: }
1.402 raeburn 13460: if ($role eq 'login') {
13461: if (($img eq 'logo') || ($img eq 'img')) {
13462: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13463: if ($confhash->{$role}{'showlogo'}{$img} ne
13464: $domconfig->{$role}{'showlogo'}{$img}) {
13465: $changes{$role}{'showlogo'}{$img} = 1;
13466: }
13467: } else {
13468: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13469: $changes{$role}{'showlogo'}{$img} = 1;
13470: }
1.70 raeburn 13471: }
1.402 raeburn 13472: }
13473: if ($img ne 'login') {
13474: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13475: if ($confhash->{$role}{'alttext'}{$img} ne
13476: $domconfig->{$role}{'alttext'}{$img}) {
13477: $changes{$role}{'alttext'}{$img} = 1;
13478: }
13479: } else {
13480: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13481: $changes{$role}{'alttext'}{$img} = 1;
13482: }
1.70 raeburn 13483: }
13484: }
13485: }
13486: }
1.6 raeburn 13487: if ($domconfig->{$role}{'font'} ne '') {
13488: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13489: $changes{$role}{'font'} = 1;
13490: }
13491: } else {
13492: if ($confhash->{$role}{'font'}) {
13493: $changes{$role}{'font'} = 1;
13494: }
13495: }
1.107 raeburn 13496: if ($role ne 'login') {
13497: if ($domconfig->{$role}{'fontmenu'} ne '') {
13498: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13499: $changes{$role}{'fontmenu'} = 1;
13500: }
13501: } else {
13502: if ($confhash->{$role}{'fontmenu'}) {
13503: $changes{$role}{'fontmenu'} = 1;
13504: }
1.97 tempelho 13505: }
13506: }
1.6 raeburn 13507: foreach my $item (@bgs) {
13508: if ($domconfig->{$role}{$item} ne '') {
13509: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13510: $changes{$role}{'bgs'}{$item} = 1;
13511: }
13512: } else {
13513: if ($confhash->{$role}{$item}) {
13514: $changes{$role}{'bgs'}{$item} = 1;
13515: }
13516: }
13517: }
13518: foreach my $item (@links) {
13519: if ($domconfig->{$role}{$item} ne '') {
13520: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13521: $changes{$role}{'links'}{$item} = 1;
13522: }
13523: } else {
13524: if ($confhash->{$role}{$item}) {
13525: $changes{$role}{'links'}{$item} = 1;
13526: }
13527: }
13528: }
1.41 raeburn 13529: foreach my $item (@logintext) {
13530: if ($domconfig->{$role}{$item} ne '') {
13531: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13532: $changes{$role}{'logintext'}{$item} = 1;
13533: }
13534: } else {
13535: if ($confhash->{$role}{$item}) {
13536: $changes{$role}{'logintext'}{$item} = 1;
13537: }
13538: }
13539: }
1.6 raeburn 13540: } else {
13541: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13542: \@logintext,$confhash,\%changes);
1.6 raeburn 13543: }
13544: } else {
13545: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13546: \@logintext,$confhash,\%changes);
1.6 raeburn 13547: }
13548: }
13549: return ($errors,%changes);
13550: }
13551:
1.46 raeburn 13552: sub config_check {
13553: my ($dom,$confname,$servadm) = @_;
13554: my ($configuserok,$author_ok,$switchserver,%currroles);
13555: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13556: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13557: $confname,$servadm);
13558: if ($configuserok eq 'ok') {
13559: $switchserver = &check_switchserver($dom,$confname);
13560: if ($switchserver eq '') {
13561: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13562: }
13563: }
13564: return ($configuserok,$author_ok,$switchserver);
13565: }
13566:
1.6 raeburn 13567: sub default_change_checker {
1.41 raeburn 13568: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13569: foreach my $item (@{$links}) {
13570: if ($confhash->{$role}{$item}) {
13571: $changes->{$role}{'links'}{$item} = 1;
13572: }
13573: }
13574: foreach my $item (@{$bgs}) {
13575: if ($confhash->{$role}{$item}) {
13576: $changes->{$role}{'bgs'}{$item} = 1;
13577: }
13578: }
1.41 raeburn 13579: foreach my $item (@{$logintext}) {
13580: if ($confhash->{$role}{$item}) {
13581: $changes->{$role}{'logintext'}{$item} = 1;
13582: }
13583: }
1.6 raeburn 13584: foreach my $img (@{$images}) {
13585: if ($env{'form.'.$role.'_del_'.$img}) {
13586: $confhash->{$role}{$img} = '';
1.12 raeburn 13587: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13588: }
1.70 raeburn 13589: if ($role eq 'login') {
13590: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13591: $changes->{$role}{'showlogo'}{$img} = 1;
13592: }
1.402 raeburn 13593: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13594: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13595: $changes->{$role}{'alttext'}{$img} = 1;
13596: }
13597: }
1.70 raeburn 13598: }
1.6 raeburn 13599: }
13600: if ($confhash->{$role}{'font'}) {
13601: $changes->{$role}{'font'} = 1;
13602: }
1.48 raeburn 13603: }
1.6 raeburn 13604:
13605: sub display_colorchgs {
13606: my ($dom,$changes,$roles,$confhash) = @_;
13607: my (%choices,$resulttext);
13608: if (!grep(/^login$/,@{$roles})) {
13609: $resulttext = &mt('Changes made:').'<br />';
13610: }
13611: foreach my $role (@{$roles}) {
13612: if ($role eq 'login') {
13613: %choices = &login_choices();
13614: } else {
13615: %choices = &color_font_choices();
13616: }
13617: if (ref($changes->{$role}) eq 'HASH') {
13618: if ($role ne 'login') {
13619: $resulttext .= '<h4>'.&mt($role).'</h4>';
13620: }
13621: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13622: if ($role ne 'login') {
13623: $resulttext .= '<ul>';
13624: }
13625: if (ref($changes->{$role}{$key}) eq 'HASH') {
13626: if ($role ne 'login') {
13627: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13628: }
13629: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13630: if (($role eq 'login') && ($key eq 'showlogo')) {
13631: if ($confhash->{$role}{$key}{$item}) {
13632: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13633: } else {
13634: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13635: }
1.402 raeburn 13636: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13637: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13638: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13639: $confhash->{$role}{$key}{$item}).'</li>';
13640: } else {
13641: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13642: }
1.70 raeburn 13643: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13644: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13645: } else {
1.12 raeburn 13646: my $newitem = $confhash->{$role}{$item};
13647: if ($key eq 'images') {
1.306 raeburn 13648: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13649: }
13650: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13651: }
13652: }
13653: if ($role ne 'login') {
13654: $resulttext .= '</ul></li>';
13655: }
13656: } else {
13657: if ($confhash->{$role}{$key} eq '') {
13658: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13659: } else {
13660: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13661: }
13662: }
13663: if ($role ne 'login') {
13664: $resulttext .= '</ul>';
13665: }
13666: }
13667: }
13668: }
1.3 raeburn 13669: return $resulttext;
1.1 raeburn 13670: }
13671:
1.9 raeburn 13672: sub thumb_dimensions {
13673: return ('200','50');
13674: }
13675:
1.16 raeburn 13676: sub check_dimensions {
13677: my ($inputfile) = @_;
13678: my ($fullwidth,$fullheight);
13679: if ($inputfile =~ m|^[/\w.\-]+$|) {
13680: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13681: my $imageinfo = <PIPE>;
13682: if (!close(PIPE)) {
13683: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13684: }
13685: chomp($imageinfo);
13686: my ($fullsize) =
1.21 raeburn 13687: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13688: if ($fullsize) {
13689: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13690: }
13691: }
13692: }
13693: return ($fullwidth,$fullheight);
13694: }
13695:
1.9 raeburn 13696: sub check_configuser {
13697: my ($uhome,$dom,$confname,$servadm) = @_;
13698: my ($configuserok,%currroles);
13699: if ($uhome eq 'no_host') {
13700: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13701: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13702: $configuserok =
13703: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13704: $configpass,'','','','','',undef,$servadm);
13705: } else {
13706: $configuserok = 'ok';
13707: %currroles =
13708: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13709: }
13710: return ($configuserok,%currroles);
13711: }
13712:
13713: sub check_authorstatus {
13714: my ($dom,$confname,%currroles) = @_;
13715: my $author_ok;
1.40 raeburn 13716: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13717: my $start = time;
13718: my $end = 0;
13719: $author_ok =
13720: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13721: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13722: } else {
13723: $author_ok = 'ok';
13724: }
13725: return $author_ok;
13726: }
13727:
13728: sub publishlogo {
1.46 raeburn 13729: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 13730: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 13731: if ($action eq 'upload') {
13732: $fname=$env{'form.'.$formname.'.filename'};
13733: chop($env{'form.'.$formname});
13734: } else {
13735: ($fname) = ($formname =~ /([^\/]+)$/);
13736: }
1.46 raeburn 13737: if ($savefileas ne '') {
13738: $fname = $savefileas;
13739: }
1.9 raeburn 13740: $fname=&Apache::lonnet::clean_filename($fname);
13741: # See if there is anything left
13742: unless ($fname) { return ('error: no uploaded file'); }
13743: $fname="$subdir/$fname";
1.210 raeburn 13744: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 13745: my $filepath="$docroot/priv";
13746: my $relpath = "$dom/$confname";
1.9 raeburn 13747: my ($fnamepath,$file,$fetchthumb);
13748: $file=$fname;
13749: if ($fname=~m|/|) {
13750: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
13751: }
1.164 raeburn 13752: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 13753: my $count;
1.164 raeburn 13754: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 13755: $filepath.="/$parts[$count]";
13756: if ((-e $filepath)!=1) {
13757: mkdir($filepath,02770);
13758: }
13759: }
13760: # Check for bad extension and disallow upload
13761: if ($file=~/\.(\w+)$/ &&
13762: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
13763: $output =
1.207 bisitz 13764: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 13765: } elsif ($file=~/\.(\w+)$/ &&
13766: !defined(&Apache::loncommon::fileembstyle($1))) {
13767: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
13768: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 13769: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 13770: } elsif (-d "$filepath/$file") {
1.195 bisitz 13771: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 13772: } else {
13773: my $source = $filepath.'/'.$file;
13774: my $logfile;
1.316 raeburn 13775: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 13776: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 13777: }
13778: print $logfile
13779: "\n================= Publish ".localtime()." ================\n".
13780: $env{'user.name'}.':'.$env{'user.domain'}."\n";
13781: # Save the file
1.316 raeburn 13782: if (!open(FH,">",$source)) {
1.9 raeburn 13783: &Apache::lonnet::logthis('Failed to create '.$source);
13784: return (&mt('Failed to create file'));
13785: }
13786: if ($action eq 'upload') {
13787: if (!print FH ($env{'form.'.$formname})) {
13788: &Apache::lonnet::logthis('Failed to write to '.$source);
13789: return (&mt('Failed to write file'));
13790: }
13791: } else {
13792: my $original = &Apache::lonnet::filelocation('',$formname);
13793: if(!copy($original,$source)) {
13794: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
13795: return (&mt('Failed to write file'));
13796: }
13797: }
13798: close(FH);
13799: chmod(0660, $source); # Permissions to rw-rw---.
13800:
13801: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
13802: my $copyfile=$targetdir.'/'.$file;
13803:
13804: my @parts=split(/\//,$targetdir);
13805: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
13806: for (my $count=5;$count<=$#parts;$count++) {
13807: $path.="/$parts[$count]";
13808: if (!-e $path) {
13809: print $logfile "\nCreating directory ".$path;
13810: mkdir($path,02770);
13811: }
13812: }
13813: my $versionresult;
13814: if (-e $copyfile) {
13815: $versionresult = &logo_versioning($targetdir,$file,$logfile);
13816: } else {
13817: $versionresult = 'ok';
13818: }
13819: if ($versionresult eq 'ok') {
13820: if (copy($source,$copyfile)) {
13821: print $logfile "\nCopied original source to ".$copyfile."\n";
13822: $output = 'ok';
13823: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 13824: push(@{$modified_urls},[$copyfile,$source]);
13825: my $metaoutput =
13826: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
13827: unless ($registered_cleanup) {
13828: my $handlers = $r->get_handlers('PerlCleanupHandler');
13829: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13830: $registered_cleanup=1;
13831: }
1.9 raeburn 13832: } else {
13833: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
13834: $output = &mt('Failed to copy file to RES space').", $!";
13835: }
13836: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
13837: my $inputfile = $filepath.'/'.$file;
13838: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 13839: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
13840: if ($fullwidth ne '' && $fullheight ne '') {
13841: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
13842: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 13843: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
13844: system({$args[0]} @args);
1.16 raeburn 13845: chmod(0660, $filepath.'/tn-'.$file);
13846: if (-e $outfile) {
13847: my $copyfile=$targetdir.'/tn-'.$file;
13848: if (copy($outfile,$copyfile)) {
13849: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 13850: my $thumb_metaoutput =
13851: &write_metadata($dom,$confname,$formname,
13852: $targetdir,'tn-'.$file,$logfile);
13853: push(@{$modified_urls},[$copyfile,$outfile]);
13854: unless ($registered_cleanup) {
13855: my $handlers = $r->get_handlers('PerlCleanupHandler');
13856: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13857: $registered_cleanup=1;
13858: }
1.267 raeburn 13859: $madethumb = 1;
1.16 raeburn 13860: } else {
13861: print $logfile "\nUnable to write ".$copyfile.
13862: ':'.$!."\n";
13863: }
13864: }
1.9 raeburn 13865: }
13866: }
13867: }
13868: } else {
13869: $output = $versionresult;
13870: }
13871: }
1.267 raeburn 13872: return ($output,$logourl,$madethumb);
1.9 raeburn 13873: }
13874:
13875: sub logo_versioning {
13876: my ($targetdir,$file,$logfile) = @_;
13877: my $target = $targetdir.'/'.$file;
13878: my ($maxversion,$fn,$extn,$output);
13879: $maxversion = 0;
13880: if ($file =~ /^(.+)\.(\w+)$/) {
13881: $fn=$1;
13882: $extn=$2;
13883: }
13884: opendir(DIR,$targetdir);
13885: while (my $filename=readdir(DIR)) {
13886: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
13887: $maxversion=($1>$maxversion)?$1:$maxversion;
13888: }
13889: }
13890: $maxversion++;
13891: print $logfile "\nCreating old version ".$maxversion."\n";
13892: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
13893: if (copy($target,$copyfile)) {
13894: print $logfile "Copied old target to ".$copyfile."\n";
13895: $copyfile=$copyfile.'.meta';
13896: if (copy($target.'.meta',$copyfile)) {
13897: print $logfile "Copied old target metadata to ".$copyfile."\n";
13898: $output = 'ok';
13899: } else {
13900: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
13901: $output = &mt('Failed to copy old meta').", $!, ";
13902: }
13903: } else {
13904: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
13905: $output = &mt('Failed to copy old target').", $!, ";
13906: }
13907: return $output;
13908: }
13909:
13910: sub write_metadata {
13911: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
13912: my (%metadatafields,%metadatakeys,$output);
13913: $metadatafields{'title'}=$formname;
13914: $metadatafields{'creationdate'}=time;
13915: $metadatafields{'lastrevisiondate'}=time;
13916: $metadatafields{'copyright'}='public';
13917: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
13918: $env{'user.domain'};
13919: $metadatafields{'authorspace'}=$confname.':'.$dom;
13920: $metadatafields{'domain'}=$dom;
13921: {
13922: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
13923: my $mfh;
1.316 raeburn 13924: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 13925: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 13926: unless ($_=~/\./) {
13927: my $unikey=$_;
13928: $unikey=~/^([A-Za-z]+)/;
13929: my $tag=$1;
13930: $tag=~tr/A-Z/a-z/;
13931: print $mfh "\n\<$tag";
13932: foreach (split(/\,/,$metadatakeys{$unikey})) {
13933: my $value=$metadatafields{$unikey.'.'.$_};
13934: $value=~s/\"/\'\'/g;
13935: print $mfh ' '.$_.'="'.$value.'"';
13936: }
13937: print $mfh '>'.
13938: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
13939: .'</'.$tag.'>';
13940: }
13941: }
13942: $output = 'ok';
13943: print $logfile "\nWrote metadata";
13944: close($mfh);
13945: } else {
13946: print $logfile "\nFailed to open metadata file";
1.9 raeburn 13947: $output = &mt('Could not write metadata');
13948: }
13949: }
1.155 raeburn 13950: return $output;
13951: }
13952:
13953: sub notifysubscribed {
13954: foreach my $targetsource (@{$modified_urls}){
13955: next unless (ref($targetsource) eq 'ARRAY');
13956: my ($target,$source)=@{$targetsource};
13957: if ($source ne '') {
1.316 raeburn 13958: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13959: print $logfh "\nCleanup phase: Notifications\n";
13960: my @subscribed=&subscribed_hosts($target);
13961: foreach my $subhost (@subscribed) {
13962: print $logfh "\nNotifying host ".$subhost.':';
13963: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13964: print $logfh $reply;
13965: }
13966: my @subscribedmeta=&subscribed_hosts("$target.meta");
13967: foreach my $subhost (@subscribedmeta) {
13968: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13969: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13970: $subhost);
13971: print $logfh $reply;
13972: }
13973: print $logfh "\n============ Done ============\n";
1.160 raeburn 13974: close($logfh);
1.155 raeburn 13975: }
13976: }
13977: }
13978: return OK;
13979: }
13980:
13981: sub subscribed_hosts {
13982: my ($target) = @_;
13983: my @subscribed;
1.316 raeburn 13984: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13985: while (my $subline=<$fh>) {
13986: if ($subline =~ /^($match_lonid):/) {
13987: my $host = $1;
13988: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13989: unless (grep(/^\Q$host\E$/,@subscribed)) {
13990: push(@subscribed,$host);
13991: }
13992: }
13993: }
13994: }
13995: }
13996: return @subscribed;
1.9 raeburn 13997: }
13998:
13999: sub check_switchserver {
14000: my ($dom,$confname) = @_;
14001: my ($allowed,$switchserver);
14002: my $home = &Apache::lonnet::homeserver($confname,$dom);
14003: if ($home eq 'no_host') {
14004: $home = &Apache::lonnet::domain($dom,'primary');
14005: }
14006: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14007: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14008: if (!$allowed) {
1.180 raeburn 14009: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14010: }
14011: return $switchserver;
14012: }
14013:
1.1 raeburn 14014: sub modify_quotas {
1.216 raeburn 14015: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14016: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14017: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14018: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14019: $validationfieldsref);
1.86 raeburn 14020: if ($action eq 'quotas') {
14021: $context = 'tools';
1.163 raeburn 14022: } else {
1.86 raeburn 14023: $context = $action;
14024: }
14025: if ($context eq 'requestcourses') {
1.325 raeburn 14026: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14027: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14028: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14029: %titles = &courserequest_titles();
14030: $toolregexp = join('|',@usertools);
14031: %conditions = &courserequest_conditions();
1.216 raeburn 14032: $confname = $dom.'-domainconfig';
14033: my $servadm = $r->dir_config('lonAdmEMail');
14034: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14035: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14036: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14037: } elsif ($context eq 'requestauthor') {
14038: @usertools = ('author');
14039: %titles = &authorrequest_titles();
1.86 raeburn 14040: } else {
1.413 raeburn 14041: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 14042: %titles = &tool_titles();
1.86 raeburn 14043: }
1.212 raeburn 14044: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14045: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14046: foreach my $key (keys(%env)) {
1.101 raeburn 14047: if ($context eq 'requestcourses') {
14048: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14049: my $item = $1;
14050: my $type = $2;
14051: if ($type =~ /^limit_(.+)/) {
14052: $limithash{$item}{$1} = $env{$key};
14053: } else {
14054: $confhash{$item}{$type} = $env{$key};
14055: }
14056: }
1.163 raeburn 14057: } elsif ($context eq 'requestauthor') {
14058: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14059: $confhash{$1} = $env{$key};
14060: }
1.101 raeburn 14061: } else {
1.86 raeburn 14062: if ($key =~ /^form\.quota_(.+)$/) {
14063: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14064: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
14065: $confhash{'authorquota'}{$1} = $env{$key};
14066: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14067: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14068: }
1.72 raeburn 14069: }
14070: }
1.163 raeburn 14071: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14072: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14073: @approvalnotify = sort(@approvalnotify);
14074: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14075: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14076: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14077: foreach my $type (@hasuniquecode) {
14078: if (grep(/^\Q$type\E$/,@crstypes)) {
14079: $confhash{'uniquecode'}{$type} = 1;
14080: }
1.216 raeburn 14081: }
1.242 raeburn 14082: my (%newbook,%allpos);
1.216 raeburn 14083: if ($context eq 'requestcourses') {
1.242 raeburn 14084: foreach my $type ('textbooks','templates') {
14085: @{$allpos{$type}} = ();
14086: my $invalid;
14087: if ($type eq 'textbooks') {
14088: $invalid = &mt('Invalid LON-CAPA course for textbook');
14089: } else {
14090: $invalid = &mt('Invalid LON-CAPA course for template');
14091: }
14092: if ($env{'form.'.$type.'_addbook'}) {
14093: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14094: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14095: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14096: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14097: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14098: } else {
14099: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14100: my $position = $env{'form.'.$type.'_addbook_pos'};
14101: $position =~ s/\D+//g;
14102: if ($position ne '') {
14103: $allpos{$type}[$position] = $newbook{$type};
14104: }
1.216 raeburn 14105: }
1.242 raeburn 14106: } else {
14107: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14108: }
14109: }
1.242 raeburn 14110: }
1.216 raeburn 14111: }
1.102 raeburn 14112: if (ref($domconfig{$action}) eq 'HASH') {
14113: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14114: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14115: $changes{'notify'}{'approval'} = 1;
14116: }
14117: } else {
1.144 raeburn 14118: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14119: $changes{'notify'}{'approval'} = 1;
14120: }
14121: }
1.218 raeburn 14122: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14123: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14124: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14125: unless ($confhash{'uniquecode'}{$crstype}) {
14126: $changes{'uniquecode'} = 1;
14127: }
14128: }
14129: unless ($changes{'uniquecode'}) {
14130: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14131: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14132: $changes{'uniquecode'} = 1;
14133: }
14134: }
14135: }
14136: } else {
14137: $changes{'uniquecode'} = 1;
14138: }
14139: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14140: $changes{'uniquecode'} = 1;
1.216 raeburn 14141: }
14142: if ($context eq 'requestcourses') {
1.242 raeburn 14143: foreach my $type ('textbooks','templates') {
14144: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14145: my %deletions;
14146: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14147: if (@todelete) {
14148: map { $deletions{$_} = 1; } @todelete;
14149: }
14150: my %imgdeletions;
14151: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14152: if (@todeleteimages) {
14153: map { $imgdeletions{$_} = 1; } @todeleteimages;
14154: }
14155: my $maxnum = $env{'form.'.$type.'_maxnum'};
14156: for (my $i=0; $i<=$maxnum; $i++) {
14157: my $itemid = $env{'form.'.$type.'_id_'.$i};
14158: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14159: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14160: if ($deletions{$key}) {
14161: if ($domconfig{$action}{$type}{$key}{'image'}) {
14162: #FIXME need to obsolete item in RES space
14163: }
14164: next;
14165: } else {
14166: my $newpos = $env{'form.'.$itemid};
14167: $newpos =~ s/\D+//g;
1.243 raeburn 14168: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14169: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14170: ($type eq 'templates'));
1.242 raeburn 14171: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14172: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14173: $changes{$type}{$key} = 1;
14174: }
14175: }
14176: $allpos{$type}[$newpos] = $key;
14177: }
14178: if ($imgdeletions{$key}) {
14179: $changes{$type}{$key} = 1;
1.216 raeburn 14180: #FIXME need to obsolete item in RES space
1.242 raeburn 14181: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14182: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14183: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14184: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14185: } else {
14186: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14187: $cdom,$cnum,$type,$configuserok,
14188: $switchserver,$author_ok);
14189: if ($imgurl) {
14190: $confhash{$type}{$key}{'image'} = $imgurl;
14191: $changes{$type}{$key} = 1;
14192: }
14193: if ($error) {
14194: &Apache::lonnet::logthis($error);
14195: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14196: }
14197: }
1.242 raeburn 14198: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14199: $confhash{$type}{$key}{'image'} =
14200: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14201: }
14202: }
14203: }
14204: }
14205: }
14206: }
1.102 raeburn 14207: } else {
1.144 raeburn 14208: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14209: $changes{'notify'}{'approval'} = 1;
14210: }
1.218 raeburn 14211: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14212: $changes{'uniquecode'} = 1;
14213: }
14214: }
14215: if ($context eq 'requestcourses') {
1.242 raeburn 14216: foreach my $type ('textbooks','templates') {
14217: if ($newbook{$type}) {
14218: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14219: foreach my $item ('subject','title','publisher','author') {
14220: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14221: ($type eq 'template'));
1.242 raeburn 14222: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14223: if ($env{'form.'.$type.'_addbook_'.$item}) {
14224: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14225: }
14226: }
14227: if ($type eq 'textbooks') {
14228: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14229: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14230: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14231: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14232: } else {
14233: my ($imageurl,$error) =
14234: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14235: $configuserok,$switchserver,$author_ok);
14236: if ($imageurl) {
14237: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14238: }
14239: if ($error) {
14240: &Apache::lonnet::logthis($error);
14241: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14242: }
1.242 raeburn 14243: }
14244: }
1.216 raeburn 14245: }
14246: }
1.242 raeburn 14247: if (@{$allpos{$type}} > 0) {
14248: my $idx = 0;
14249: foreach my $item (@{$allpos{$type}}) {
14250: if ($item ne '') {
14251: $confhash{$type}{$item}{'order'} = $idx;
14252: if (ref($domconfig{$action}) eq 'HASH') {
14253: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14254: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14255: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14256: $changes{$type}{$item} = 1;
14257: }
1.216 raeburn 14258: }
14259: }
14260: }
1.242 raeburn 14261: $idx ++;
1.216 raeburn 14262: }
14263: }
14264: }
14265: }
1.235 raeburn 14266: if (ref($validationitemsref) eq 'ARRAY') {
14267: foreach my $item (@{$validationitemsref}) {
14268: if ($item eq 'fields') {
14269: my @changed;
14270: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14271: if (@{$confhash{'validation'}{$item}} > 0) {
14272: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14273: }
1.266 raeburn 14274: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14275: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14276: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14277: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14278: $domconfig{'requestcourses'}{'validation'}{$item});
14279: } else {
14280: @changed = @{$confhash{'validation'}{$item}};
14281: }
1.235 raeburn 14282: } else {
14283: @changed = @{$confhash{'validation'}{$item}};
14284: }
14285: } else {
14286: @changed = @{$confhash{'validation'}{$item}};
14287: }
14288: if (@changed) {
14289: if ($confhash{'validation'}{$item}) {
14290: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14291: } else {
14292: $changes{'validation'}{$item} = &mt('None');
14293: }
14294: }
14295: } else {
14296: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14297: if ($item eq 'markup') {
14298: if ($env{'form.requestcourses_validation_'.$item}) {
14299: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14300: }
14301: }
1.266 raeburn 14302: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14303: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14304: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14305: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14306: }
14307: } else {
14308: if ($confhash{'validation'}{$item} ne '') {
14309: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14310: }
1.235 raeburn 14311: }
14312: } else {
14313: if ($confhash{'validation'}{$item} ne '') {
14314: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14315: }
14316: }
14317: }
14318: }
14319: }
14320: if ($env{'form.validationdc'}) {
14321: my $newval = $env{'form.validationdc'};
1.285 raeburn 14322: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14323: if (exists($domcoords{$newval})) {
14324: $confhash{'validation'}{'dc'} = $newval;
14325: }
14326: }
14327: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14328: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14329: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14330: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14331: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14332: if ($confhash{'validation'}{'dc'} eq '') {
14333: $changes{'validation'}{'dc'} = &mt('None');
14334: } else {
14335: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14336: }
1.235 raeburn 14337: }
1.266 raeburn 14338: } elsif ($confhash{'validation'}{'dc'} ne '') {
14339: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14340: }
14341: } elsif ($confhash{'validation'}{'dc'} ne '') {
14342: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14343: }
14344: } elsif ($confhash{'validation'}{'dc'} ne '') {
14345: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14346: }
1.266 raeburn 14347: } else {
14348: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14349: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14350: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14351: $changes{'validation'}{'dc'} = &mt('None');
14352: }
14353: }
1.235 raeburn 14354: }
14355: }
1.102 raeburn 14356: }
14357: } else {
1.86 raeburn 14358: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 14359: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 14360: }
1.72 raeburn 14361: foreach my $item (@usertools) {
14362: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14363: my $unset;
1.101 raeburn 14364: if ($context eq 'requestcourses') {
1.104 raeburn 14365: $unset = '0';
14366: if ($type eq '_LC_adv') {
14367: $unset = '';
14368: }
1.101 raeburn 14369: if ($confhash{$item}{$type} eq 'autolimit') {
14370: $confhash{$item}{$type} .= '=';
14371: unless ($limithash{$item}{$type} =~ /\D/) {
14372: $confhash{$item}{$type} .= $limithash{$item}{$type};
14373: }
14374: }
1.163 raeburn 14375: } elsif ($context eq 'requestauthor') {
14376: $unset = '0';
14377: if ($type eq '_LC_adv') {
14378: $unset = '';
14379: }
1.72 raeburn 14380: } else {
1.101 raeburn 14381: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14382: $confhash{$item}{$type} = 1;
14383: } else {
14384: $confhash{$item}{$type} = 0;
14385: }
1.72 raeburn 14386: }
1.86 raeburn 14387: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14388: if ($action eq 'requestauthor') {
14389: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14390: $changes{$type} = 1;
14391: }
14392: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14393: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14394: $changes{$item}{$type} = 1;
14395: }
14396: } else {
14397: if ($context eq 'requestcourses') {
1.104 raeburn 14398: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14399: $changes{$item}{$type} = 1;
14400: }
14401: } else {
14402: if (!$confhash{$item}{$type}) {
14403: $changes{$item}{$type} = 1;
14404: }
14405: }
14406: }
14407: } else {
14408: if ($context eq 'requestcourses') {
1.104 raeburn 14409: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14410: $changes{$item}{$type} = 1;
14411: }
1.163 raeburn 14412: } elsif ($context eq 'requestauthor') {
14413: if ($confhash{$type} ne $unset) {
14414: $changes{$type} = 1;
14415: }
1.72 raeburn 14416: } else {
14417: if (!$confhash{$item}{$type}) {
14418: $changes{$item}{$type} = 1;
14419: }
14420: }
14421: }
1.1 raeburn 14422: }
14423: }
1.163 raeburn 14424: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14425: if (ref($domconfig{'quotas'}) eq 'HASH') {
14426: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14427: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14428: if (exists($confhash{'defaultquota'}{$key})) {
14429: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14430: $changes{'defaultquota'}{$key} = 1;
14431: }
14432: } else {
14433: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14434: }
14435: }
1.86 raeburn 14436: } else {
14437: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14438: if (exists($confhash{'defaultquota'}{$key})) {
14439: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14440: $changes{'defaultquota'}{$key} = 1;
14441: }
14442: } else {
14443: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14444: }
1.1 raeburn 14445: }
14446: }
1.197 raeburn 14447: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
14448: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
14449: if (exists($confhash{'authorquota'}{$key})) {
14450: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
14451: $changes{'authorquota'}{$key} = 1;
14452: }
14453: } else {
14454: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
14455: }
14456: }
14457: }
1.1 raeburn 14458: }
1.86 raeburn 14459: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14460: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14461: if (ref($domconfig{'quotas'}) eq 'HASH') {
14462: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14463: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14464: $changes{'defaultquota'}{$key} = 1;
14465: }
14466: } else {
14467: if (!exists($domconfig{'quotas'}{$key})) {
14468: $changes{'defaultquota'}{$key} = 1;
14469: }
1.72 raeburn 14470: }
14471: } else {
1.86 raeburn 14472: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14473: }
1.1 raeburn 14474: }
14475: }
1.197 raeburn 14476: if (ref($confhash{'authorquota'}) eq 'HASH') {
14477: foreach my $key (keys(%{$confhash{'authorquota'}})) {
14478: if (ref($domconfig{'quotas'}) eq 'HASH') {
14479: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
14480: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
14481: $changes{'authorquota'}{$key} = 1;
14482: }
14483: } else {
14484: $changes{'authorquota'}{$key} = 1;
14485: }
14486: } else {
14487: $changes{'authorquota'}{$key} = 1;
14488: }
14489: }
14490: }
1.1 raeburn 14491: }
1.72 raeburn 14492:
1.163 raeburn 14493: if ($context eq 'requestauthor') {
14494: $domdefaults{'requestauthor'} = \%confhash;
14495: } else {
14496: foreach my $key (keys(%confhash)) {
1.242 raeburn 14497: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14498: $domdefaults{$key} = $confhash{$key};
14499: }
1.163 raeburn 14500: }
1.72 raeburn 14501: }
1.163 raeburn 14502:
1.1 raeburn 14503: my %quotahash = (
1.86 raeburn 14504: $action => { %confhash }
1.1 raeburn 14505: );
14506: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14507: $dom);
14508: if ($putresult eq 'ok') {
14509: if (keys(%changes) > 0) {
1.72 raeburn 14510: my $cachetime = 24*60*60;
14511: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14512: if (ref($lastactref) eq 'HASH') {
14513: $lastactref->{'domdefaults'} = 1;
14514: }
1.1 raeburn 14515: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14516: unless (($context eq 'requestcourses') ||
1.163 raeburn 14517: ($context eq 'requestauthor')) {
1.86 raeburn 14518: if (ref($changes{'defaultquota'}) eq 'HASH') {
14519: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14520: foreach my $type (@{$types},'default') {
14521: if (defined($changes{'defaultquota'}{$type})) {
14522: my $typetitle = $usertypes->{$type};
14523: if ($type eq 'default') {
14524: $typetitle = $othertitle;
14525: }
1.213 raeburn 14526: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14527: }
14528: }
1.86 raeburn 14529: $resulttext .= '</ul></li>';
1.72 raeburn 14530: }
1.197 raeburn 14531: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 14532: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 14533: foreach my $type (@{$types},'default') {
14534: if (defined($changes{'authorquota'}{$type})) {
14535: my $typetitle = $usertypes->{$type};
14536: if ($type eq 'default') {
14537: $typetitle = $othertitle;
14538: }
1.213 raeburn 14539: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 14540: }
14541: }
14542: $resulttext .= '</ul></li>';
14543: }
1.72 raeburn 14544: }
1.80 raeburn 14545: my %newenv;
1.72 raeburn 14546: foreach my $item (@usertools) {
1.163 raeburn 14547: my (%haschgs,%inconf);
14548: if ($context eq 'requestauthor') {
14549: %haschgs = %changes;
1.210 raeburn 14550: %inconf = %confhash;
1.163 raeburn 14551: } else {
14552: if (ref($changes{$item}) eq 'HASH') {
14553: %haschgs = %{$changes{$item}};
14554: }
14555: if (ref($confhash{$item}) eq 'HASH') {
14556: %inconf = %{$confhash{$item}};
14557: }
14558: }
14559: if (keys(%haschgs) > 0) {
1.80 raeburn 14560: my $newacc =
14561: &Apache::lonnet::usertools_access($env{'user.name'},
14562: $env{'user.domain'},
1.86 raeburn 14563: $item,'reload',$context);
1.210 raeburn 14564: if (($context eq 'requestcourses') ||
1.163 raeburn 14565: ($context eq 'requestauthor')) {
1.108 raeburn 14566: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14567: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14568: }
14569: } else {
14570: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14571: $newenv{'environment.availabletools.'.$item} = $newacc;
14572: }
1.80 raeburn 14573: }
1.163 raeburn 14574: unless ($context eq 'requestauthor') {
14575: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14576: }
1.72 raeburn 14577: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14578: if ($haschgs{$type}) {
1.72 raeburn 14579: my $typetitle = $usertypes->{$type};
14580: if ($type eq 'default') {
14581: $typetitle = $othertitle;
14582: } elsif ($type eq '_LC_adv') {
14583: $typetitle = 'LON-CAPA Advanced Users';
14584: }
1.163 raeburn 14585: if ($inconf{$type}) {
1.101 raeburn 14586: if ($context eq 'requestcourses') {
14587: my $cond;
1.163 raeburn 14588: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14589: if ($1 eq '') {
14590: $cond = &mt('(Automatic processing of any request).');
14591: } else {
14592: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14593: }
14594: } else {
1.163 raeburn 14595: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14596: }
14597: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14598: } elsif ($context eq 'requestauthor') {
14599: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14600: $titles{$inconf{$type}},$typetitle);
14601:
1.101 raeburn 14602: } else {
14603: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14604: }
1.72 raeburn 14605: } else {
1.104 raeburn 14606: if ($type eq '_LC_adv') {
1.163 raeburn 14607: if ($inconf{$type} eq '0') {
1.104 raeburn 14608: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14609: } else {
14610: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14611: }
14612: } else {
14613: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14614: }
1.72 raeburn 14615: }
14616: }
1.26 raeburn 14617: }
1.163 raeburn 14618: unless ($context eq 'requestauthor') {
14619: $resulttext .= '</ul></li>';
14620: }
1.26 raeburn 14621: }
1.1 raeburn 14622: }
1.163 raeburn 14623: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14624: if (ref($changes{'notify'}) eq 'HASH') {
14625: if ($changes{'notify'}{'approval'}) {
14626: if (ref($confhash{'notify'}) eq 'HASH') {
14627: if ($confhash{'notify'}{'approval'}) {
14628: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14629: } else {
1.163 raeburn 14630: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14631: }
14632: }
14633: }
14634: }
14635: }
1.216 raeburn 14636: if ($action eq 'requestcourses') {
14637: my @offon = ('off','on');
14638: if ($changes{'uniquecode'}) {
1.218 raeburn 14639: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14640: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14641: $resulttext .= '<li>'.
14642: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14643: '</li>';
14644: } else {
14645: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14646: '</li>';
14647: }
1.216 raeburn 14648: }
1.242 raeburn 14649: foreach my $type ('textbooks','templates') {
14650: if (ref($changes{$type}) eq 'HASH') {
14651: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14652: foreach my $key (sort(keys(%{$changes{$type}}))) {
14653: my %coursehash = &Apache::lonnet::coursedescription($key);
14654: my $coursetitle = $coursehash{'description'};
14655: my $position = $confhash{$type}{$key}{'order'} + 1;
14656: $resulttext .= '<li>';
1.243 raeburn 14657: foreach my $item ('subject','title','publisher','author') {
14658: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14659: ($type eq 'templates'));
1.242 raeburn 14660: my $name = $item.':';
14661: $name =~ s/^(\w)/\U$1/;
14662: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14663: }
14664: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14665: if ($type eq 'textbooks') {
14666: if ($confhash{$type}{$key}{'image'}) {
14667: $resulttext .= ' '.&mt('Image: [_1]',
14668: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14669: ' alt="Textbook cover" />').'<br />';
14670: }
14671: }
14672: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14673: }
1.242 raeburn 14674: $resulttext .= '</ul></li>';
1.216 raeburn 14675: }
14676: }
1.235 raeburn 14677: if (ref($changes{'validation'}) eq 'HASH') {
14678: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14679: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14680: foreach my $item (@{$validationitemsref}) {
14681: if (exists($changes{'validation'}{$item})) {
14682: if ($item eq 'markup') {
14683: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14684: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14685: } else {
14686: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14687: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14688: }
14689: }
14690: }
14691: if (exists($changes{'validation'}{'dc'})) {
14692: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14693: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14694: }
14695: }
14696: }
1.216 raeburn 14697: }
1.1 raeburn 14698: $resulttext .= '</ul>';
1.80 raeburn 14699: if (keys(%newenv)) {
14700: &Apache::lonnet::appenv(\%newenv);
14701: }
1.1 raeburn 14702: } else {
1.86 raeburn 14703: if ($context eq 'requestcourses') {
14704: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14705: } elsif ($context eq 'requestauthor') {
14706: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14707: } else {
1.90 weissno 14708: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14709: }
1.1 raeburn 14710: }
14711: } else {
1.11 albertel 14712: $resulttext = '<span class="LC_error">'.
14713: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14714: }
1.216 raeburn 14715: if ($errors) {
14716: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14717: '<ul>'.$errors.'</ul></p>';
14718: }
1.3 raeburn 14719: return $resulttext;
1.1 raeburn 14720: }
14721:
1.216 raeburn 14722: sub process_textbook_image {
1.242 raeburn 14723: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14724: my $filename = $env{'form.'.$caller.'.filename'};
14725: my ($error,$url);
14726: my ($width,$height) = (50,50);
14727: if ($configuserok eq 'ok') {
14728: if ($switchserver) {
14729: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14730: $switchserver);
14731: } elsif ($author_ok eq 'ok') {
14732: my ($result,$imageurl) =
14733: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 14734: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 14735: if ($result eq 'ok') {
14736: $url = $imageurl;
14737: } else {
14738: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14739: }
14740: } else {
14741: $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);
14742: }
14743: } else {
14744: $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);
14745: }
14746: return ($url,$error);
14747: }
14748:
1.267 raeburn 14749: sub modify_ltitools {
14750: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14751: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 14752: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 14753: my $confname = $dom.'-domainconfig';
14754: my $servadm = $r->dir_config('lonAdmEMail');
14755: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14756: my (%posslti,%possfield);
14757: my @courseroles = ('cc','in','ta','ep','st');
14758: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
14759: map { $posslti{$_} = 1; } @ltiroles;
14760: my @allfields = ('fullname','firstname','lastname','email','user','roles');
14761: map { $possfield{$_} = 1; } @allfields;
14762: my %lt = <itools_names();
14763: if ($env{'form.ltitools_add'}) {
14764: my $title = $env{'form.ltitools_add_title'};
14765: $title =~ s/(`)/'/g;
14766: ($newid,my $error) = &get_ltitools_id($dom,$title);
14767: if ($newid) {
14768: my $position = $env{'form.ltitools_add_pos'};
14769: $position =~ s/\D+//g;
14770: if ($position ne '') {
14771: $allpos[$position] = $newid;
14772: }
14773: $changes{$newid} = 1;
1.322 raeburn 14774: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 14775: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 14776: if ($item eq 'lifetime') {
14777: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
14778: }
1.267 raeburn 14779: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 14780: if (($item eq 'key') || ($item eq 'secret')) {
14781: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14782: } else {
14783: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14784: }
1.267 raeburn 14785: }
14786: }
14787: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
14788: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
14789: }
14790: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
14791: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
14792: }
1.323 raeburn 14793: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
14794: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
14795: } else {
14796: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
14797: }
1.296 raeburn 14798: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 14799: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
14800: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 14801: if (($item eq 'width') || ($item eq 'height')) {
14802: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
14803: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14804: }
14805: } else {
14806: if ($env{'form.ltitools_add_'.$item} ne '') {
14807: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14808: }
1.267 raeburn 14809: }
14810: }
14811: if ($env{'form.ltitools_add_target'} eq 'window') {
14812: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 14813: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
14814: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 14815: } else {
14816: $confhash{$newid}{'display'}{'target'} = 'iframe';
14817: }
14818: foreach my $item ('passback','roster') {
1.319 raeburn 14819: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 14820: $confhash{$newid}{$item} = 1;
1.319 raeburn 14821: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
14822: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
14823: $lifetime =~ s/^\s+|\s+$//g;
14824: if ($lifetime =~ /^\d+\.?\d*$/) {
14825: $confhash{$newid}{$item.'valid'} = $lifetime;
14826: }
14827: }
1.267 raeburn 14828: }
14829: }
14830: if ($env{'form.ltitools_add_image.filename'} ne '') {
14831: my ($imageurl,$error) =
1.307 raeburn 14832: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 14833: $configuserok,$switchserver,$author_ok);
14834: if ($imageurl) {
14835: $confhash{$newid}{'image'} = $imageurl;
14836: }
14837: if ($error) {
14838: &Apache::lonnet::logthis($error);
14839: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14840: }
14841: }
14842: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
14843: foreach my $field (@fields) {
14844: if ($possfield{$field}) {
14845: if ($field eq 'roles') {
14846: foreach my $role (@courseroles) {
14847: my $choice = $env{'form.ltitools_add_roles_'.$role};
14848: if (($choice ne '') && ($posslti{$choice})) {
14849: $confhash{$newid}{'roles'}{$role} = $choice;
14850: if ($role eq 'cc') {
14851: $confhash{$newid}{'roles'}{'co'} = $choice;
14852: }
14853: }
14854: }
14855: } else {
14856: $confhash{$newid}{'fields'}{$field} = 1;
14857: }
14858: }
14859: }
1.324 raeburn 14860: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
14861: if ($confhash{$newid}{'fields'}{'user'}) {
14862: if ($env{'form.ltitools_userincdom_add'}) {
14863: $confhash{$newid}{'incdom'} = 1;
14864: }
14865: }
14866: }
1.273 raeburn 14867: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
14868: foreach my $item (@courseconfig) {
14869: $confhash{$newid}{'crsconf'}{$item} = 1;
14870: }
1.267 raeburn 14871: if ($env{'form.ltitools_add_custom'}) {
14872: my $name = $env{'form.ltitools_add_custom_name'};
14873: my $value = $env{'form.ltitools_add_custom_value'};
14874: $value =~ s/(`)/'/g;
14875: $name =~ s/(`)/'/g;
14876: $confhash{$newid}{'custom'}{$name} = $value;
14877: }
14878: } else {
14879: my $error = &mt('Failed to acquire unique ID for new external tool');
14880: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14881: }
14882: }
14883: if (ref($domconfig{$action}) eq 'HASH') {
14884: my %deletions;
14885: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
14886: if (@todelete) {
14887: map { $deletions{$_} = 1; } @todelete;
14888: }
14889: my %customadds;
14890: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
14891: if (@newcustom) {
14892: map { $customadds{$_} = 1; } @newcustom;
14893: }
14894: my %imgdeletions;
14895: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
14896: if (@todeleteimages) {
14897: map { $imgdeletions{$_} = 1; } @todeleteimages;
14898: }
14899: my $maxnum = $env{'form.ltitools_maxnum'};
14900: for (my $i=0; $i<=$maxnum; $i++) {
14901: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 14902: $itemid =~ s/\D+//g;
1.267 raeburn 14903: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14904: if ($deletions{$itemid}) {
14905: if ($domconfig{$action}{$itemid}{'image'}) {
14906: #FIXME need to obsolete item in RES space
14907: }
14908: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
14909: next;
14910: } else {
14911: my $newpos = $env{'form.ltitools_'.$itemid};
14912: $newpos =~ s/\D+//g;
1.322 raeburn 14913: foreach my $item ('title','url','lifetime') {
1.267 raeburn 14914: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14915: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14916: $changes{$itemid} = 1;
14917: }
14918: }
1.297 raeburn 14919: foreach my $item ('key','secret') {
14920: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14921: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
14922: $changes{$itemid} = 1;
14923: }
14924: }
1.267 raeburn 14925: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
14926: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
14927: }
14928: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
14929: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
14930: }
1.323 raeburn 14931: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
14932: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
14933: } else {
14934: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
14935: }
14936: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
14937: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
14938: $changes{$itemid} = 1;
14939: }
14940: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
14941: $changes{$itemid} = 1;
14942: }
1.267 raeburn 14943: foreach my $size ('width','height') {
14944: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
14945: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
14946: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
14947: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
14948: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14949: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
14950: $changes{$itemid} = 1;
14951: }
14952: } else {
14953: $changes{$itemid} = 1;
14954: }
1.296 raeburn 14955: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14956: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
14957: $changes{$itemid} = 1;
14958: }
14959: }
14960: }
14961: foreach my $item ('linktext','explanation') {
14962: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
14963: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
14964: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
14965: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14966: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14967: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
14968: $changes{$itemid} = 1;
14969: }
14970: } else {
14971: $changes{$itemid} = 1;
14972: }
14973: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14974: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
14975: $changes{$itemid} = 1;
14976: }
1.267 raeburn 14977: }
14978: }
14979: if ($env{'form.ltitools_target_'.$i} eq 'window') {
14980: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 14981: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
14982: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 14983: } else {
14984: $confhash{$itemid}{'display'}{'target'} = 'iframe';
14985: }
14986: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14987: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
14988: $changes{$itemid} = 1;
14989: }
14990: } else {
14991: $changes{$itemid} = 1;
14992: }
14993: foreach my $extra ('passback','roster') {
14994: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
14995: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 14996: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 14997: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 14998: $lifetime =~ s/^\s+|\s+$//g;
14999: if ($lifetime =~ /^\d+\.?\d*$/) {
15000: $confhash{$itemid}{$extra.'valid'} = $lifetime;
15001: }
15002: }
1.267 raeburn 15003: }
15004: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
15005: $changes{$itemid} = 1;
15006: }
1.319 raeburn 15007: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
15008: $changes{$itemid} = 1;
15009: }
1.267 raeburn 15010: }
1.273 raeburn 15011: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 15012: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 15013: if (grep(/^\Q$item\E$/,@courseconfig)) {
15014: $confhash{$itemid}{'crsconf'}{$item} = 1;
15015: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
15016: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
15017: $changes{$itemid} = 1;
15018: }
15019: } else {
15020: $changes{$itemid} = 1;
15021: }
15022: }
15023: }
1.267 raeburn 15024: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
15025: foreach my $field (@fields) {
15026: if ($possfield{$field}) {
15027: if ($field eq 'roles') {
15028: foreach my $role (@courseroles) {
15029: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
15030: if (($choice ne '') && ($posslti{$choice})) {
15031: $confhash{$itemid}{'roles'}{$role} = $choice;
15032: if ($role eq 'cc') {
15033: $confhash{$itemid}{'roles'}{'co'} = $choice;
15034: }
15035: }
15036: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
15037: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
15038: $changes{$itemid} = 1;
15039: }
15040: } elsif ($confhash{$itemid}{'roles'}{$role}) {
15041: $changes{$itemid} = 1;
15042: }
15043: }
15044: } else {
15045: $confhash{$itemid}{'fields'}{$field} = 1;
15046: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
15047: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
15048: $changes{$itemid} = 1;
15049: }
15050: } else {
15051: $changes{$itemid} = 1;
15052: }
15053: }
15054: }
15055: }
1.324 raeburn 15056: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
15057: if ($confhash{$itemid}{'fields'}{'user'}) {
15058: if ($env{'form.ltitools_userincdom_'.$i}) {
15059: $confhash{$itemid}{'incdom'} = 1;
15060: }
15061: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
15062: $changes{$itemid} = 1;
15063: }
15064: }
15065: }
1.267 raeburn 15066: $allpos[$newpos] = $itemid;
15067: }
15068: if ($imgdeletions{$itemid}) {
15069: $changes{$itemid} = 1;
15070: #FIXME need to obsolete item in RES space
15071: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
15072: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
15073: $itemid,$configuserok,$switchserver,
15074: $author_ok);
15075: if ($imgurl) {
15076: $confhash{$itemid}{'image'} = $imgurl;
15077: $changes{$itemid} = 1;
15078: }
15079: if ($error) {
15080: &Apache::lonnet::logthis($error);
15081: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15082: }
15083: } elsif ($domconfig{$action}{$itemid}{'image'}) {
15084: $confhash{$itemid}{'image'} =
15085: $domconfig{$action}{$itemid}{'image'};
15086: }
15087: if ($customadds{$i}) {
15088: my $name = $env{'form.ltitools_custom_name_'.$i};
15089: $name =~ s/(`)/'/g;
15090: $name =~ s/^\s+//;
15091: $name =~ s/\s+$//;
15092: my $value = $env{'form.ltitools_custom_value_'.$i};
15093: $value =~ s/(`)/'/g;
15094: $value =~ s/^\s+//;
15095: $value =~ s/\s+$//;
15096: if ($name ne '') {
15097: $confhash{$itemid}{'custom'}{$name} = $value;
15098: $changes{$itemid} = 1;
15099: }
15100: }
15101: my %customdels;
15102: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
15103: if (@customdeletions) {
15104: $changes{$itemid} = 1;
15105: }
15106: map { $customdels{$_} = 1; } @customdeletions;
15107: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
15108: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
15109: unless ($customdels{$key}) {
15110: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
15111: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
15112: }
15113: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
15114: $changes{$itemid} = 1;
15115: }
15116: }
15117: }
15118: }
15119: unless ($changes{$itemid}) {
15120: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
15121: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
15122: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
15123: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
15124: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
15125: $changes{$itemid} = 1;
15126: last;
15127: }
15128: }
15129: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
15130: $changes{$itemid} = 1;
15131: }
15132: }
15133: last if ($changes{$itemid});
15134: }
15135: }
15136: }
15137: }
15138: }
15139: if (@allpos > 0) {
15140: my $idx = 0;
15141: foreach my $itemid (@allpos) {
15142: if ($itemid ne '') {
15143: $confhash{$itemid}{'order'} = $idx;
15144: if (ref($domconfig{$action}) eq 'HASH') {
15145: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15146: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15147: $changes{$itemid} = 1;
15148: }
15149: }
15150: }
15151: $idx ++;
15152: }
15153: }
15154: }
15155: my %ltitoolshash = (
15156: $action => { %confhash }
15157: );
15158: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
15159: $dom);
15160: if ($putresult eq 'ok') {
1.297 raeburn 15161: my %ltienchash = (
15162: $action => { %encconfig }
15163: );
1.384 raeburn 15164: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 15165: if (keys(%changes) > 0) {
15166: my $cachetime = 24*60*60;
1.297 raeburn 15167: my %ltiall = %confhash;
15168: foreach my $id (keys(%ltiall)) {
15169: if (ref($encconfig{$id}) eq 'HASH') {
15170: foreach my $item ('key','secret') {
15171: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15172: }
15173: }
15174: }
15175: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 15176: if (ref($lastactref) eq 'HASH') {
15177: $lastactref->{'ltitools'} = 1;
15178: }
15179: $resulttext = &mt('Changes made:').'<ul>';
15180: my %bynum;
15181: foreach my $itemid (sort(keys(%changes))) {
15182: my $position = $confhash{$itemid}{'order'};
15183: $bynum{$position} = $itemid;
15184: }
15185: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15186: my $itemid = $bynum{$pos};
15187: if (ref($confhash{$itemid}) ne 'HASH') {
15188: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15189: } else {
15190: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
15191: if ($confhash{$itemid}{'image'}) {
15192: $resulttext .= ' '.
15193: '<img src="'.$confhash{$itemid}{'image'}.'"'.
15194: ' alt="'.&mt('Tool Provider icon').'" />';
15195: }
15196: $resulttext .= '</li><ul>';
15197: my $position = $pos + 1;
15198: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 15199: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 15200: if ($confhash{$itemid}{$item} ne '') {
15201: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15202: }
15203: }
1.297 raeburn 15204: if ($encconfig{$itemid}{'key'} ne '') {
15205: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15206: }
15207: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 15208: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 15209: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 15210: $resulttext .= ('*'x$num).'</li>';
15211: }
1.273 raeburn 15212: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 15213: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 15214: my $numconfig = 0;
15215: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
15216: foreach my $item (@possconfig) {
15217: if ($confhash{$itemid}{'crsconf'}{$item}) {
15218: $numconfig ++;
1.296 raeburn 15219: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 15220: }
15221: }
15222: }
15223: if (!$numconfig) {
1.372 raeburn 15224: $resulttext .= ' '.&mt('None');
1.273 raeburn 15225: }
15226: $resulttext .= '</li>';
1.267 raeburn 15227: foreach my $item ('passback','roster') {
15228: $resulttext .= '<li>'.$lt{$item}.' ';
15229: if ($confhash{$itemid}{$item}) {
15230: $resulttext .= &mt('Yes');
1.319 raeburn 15231: if ($confhash{$itemid}{$item.'valid'}) {
15232: if ($item eq 'passback') {
15233: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
15234: $confhash{$itemid}{$item.'valid'});
15235: } else {
15236: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
15237: $confhash{$itemid}{$item.'valid'});
15238: }
15239: }
1.267 raeburn 15240: } else {
15241: $resulttext .= &mt('No');
15242: }
15243: $resulttext .= '</li>';
15244: }
15245: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
15246: my $displaylist;
15247: if ($confhash{$itemid}{'display'}{'target'}) {
15248: $displaylist = &mt('Display target').': '.
15249: $confhash{$itemid}{'display'}{'target'}.',';
15250: }
15251: foreach my $size ('width','height') {
15252: if ($confhash{$itemid}{'display'}{$size}) {
15253: $displaylist .= (' 'x2).$lt{$size}.': '.
15254: $confhash{$itemid}{'display'}{$size}.',';
15255: }
15256: }
15257: if ($displaylist) {
15258: $displaylist =~ s/,$//;
15259: $resulttext .= '<li>'.$displaylist.'</li>';
15260: }
1.296 raeburn 15261: foreach my $item ('linktext','explanation') {
15262: if ($confhash{$itemid}{'display'}{$item}) {
15263: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
15264: }
15265: }
15266: }
1.267 raeburn 15267: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
15268: my $fieldlist;
15269: foreach my $field (@allfields) {
15270: if ($confhash{$itemid}{'fields'}{$field}) {
15271: $fieldlist .= (' 'x2).$lt{$field}.',';
15272: }
15273: }
15274: if ($fieldlist) {
15275: $fieldlist =~ s/,$//;
1.324 raeburn 15276: if ($confhash{$itemid}{'fields'}{'user'}) {
15277: if ($confhash{$itemid}{'incdom'}) {
15278: $fieldlist .= ' ('.&mt('username:domain').')';
15279: } else {
15280: $fieldlist .= ' ('.&mt('username').')';
15281: }
15282: }
1.267 raeburn 15283: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
15284: }
15285: }
15286: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
15287: my $rolemaps;
15288: foreach my $role (@courseroles) {
15289: if ($confhash{$itemid}{'roles'}{$role}) {
15290: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15291: $confhash{$itemid}{'roles'}{$role}.',';
15292: }
15293: }
15294: if ($rolemaps) {
15295: $rolemaps =~ s/,$//;
15296: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15297: }
15298: }
15299: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
15300: my $customlist;
15301: if (keys(%{$confhash{$itemid}{'custom'}})) {
15302: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
15303: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
15304: }
15305: }
15306: if ($customlist) {
1.317 raeburn 15307: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 15308: }
15309: }
15310: $resulttext .= '</ul></li>';
15311: }
15312: }
15313: $resulttext .= '</ul>';
15314: } else {
15315: $resulttext = &mt('No changes made.');
15316: }
15317: } else {
15318: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15319: }
15320: if ($errors) {
15321: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15322: $errors.'</ul>';
15323: }
15324: return $resulttext;
15325: }
15326:
15327: sub process_ltitools_image {
15328: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
15329: my $filename = $env{'form.'.$caller.'.filename'};
15330: my ($error,$url);
15331: my ($width,$height) = (21,21);
15332: if ($configuserok eq 'ok') {
15333: if ($switchserver) {
15334: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
15335: $switchserver);
15336: } elsif ($author_ok eq 'ok') {
15337: my ($result,$imageurl,$madethumb) =
15338: &publishlogo($r,'upload',$caller,$dom,$confname,
15339: "ltitools/$itemid/icon",$width,$height);
15340: if ($result eq 'ok') {
15341: if ($madethumb) {
15342: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15343: my $imagethumb = "$path/tn-".$imagefile;
15344: $url = $imagethumb;
15345: } else {
15346: $url = $imageurl;
15347: }
15348: } else {
15349: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15350: }
15351: } else {
15352: $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);
15353: }
15354: } else {
15355: $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);
15356: }
15357: return ($url,$error);
15358: }
15359:
15360: sub get_ltitools_id {
15361: my ($cdom,$title) = @_;
15362: # get lock on ltitools db
15363: my $lockhash = {
15364: lock => $env{'user.name'}.
15365: ':'.$env{'user.domain'},
15366: };
15367: my $tries = 0;
15368: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
15369: my ($id,$error);
15370:
15371: while (($gotlock ne 'ok') && ($tries<10)) {
15372: $tries ++;
15373: sleep (0.1);
15374: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
15375: }
15376: if ($gotlock eq 'ok') {
15377: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
15378: if ($currids{'lock'}) {
15379: delete($currids{'lock'});
15380: if (keys(%currids)) {
15381: my @curr = sort { $a <=> $b } keys(%currids);
15382: if ($curr[-1] =~ /^\d+$/) {
15383: $id = 1 + $curr[-1];
15384: }
15385: } else {
15386: $id = 1;
15387: }
15388: if ($id) {
15389: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
15390: $error = 'nostore';
15391: }
15392: } else {
15393: $error = 'nonumber';
15394: }
15395: }
15396: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
15397: } else {
15398: $error = 'nolock';
15399: }
15400: return ($id,$error);
15401: }
15402:
1.372 raeburn 15403: sub modify_proctoring {
15404: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15405: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15406: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15407: my $confname = $dom.'-domainconfig';
15408: my $servadm = $r->dir_config('lonAdmEMail');
15409: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15410: my %providernames = &proctoring_providernames();
15411: my $maxnum = scalar(keys(%providernames));
15412:
15413: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15414: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15415: if (ref($requref) eq 'HASH') {
15416: %requserfields = %{$requref};
15417: }
15418: if (ref($opturef) eq 'HASH') {
15419: %optuserfields = %{$opturef};
15420: }
15421: if (ref($defref) eq 'HASH') {
15422: %defaults = %{$defref};
15423: }
15424: if (ref($extref) eq 'HASH') {
15425: %extended = %{$extref};
15426: }
15427: if (ref($crsref) eq 'HASH') {
15428: %crsconf = %{$crsref};
15429: }
15430: if (ref($rolesref) eq 'ARRAY') {
15431: @courseroles = @{$rolesref};
15432: }
15433: if (ref($ltiref) eq 'ARRAY') {
15434: @ltiroles = @{$ltiref};
15435: }
15436:
15437: if (ref($domconfig{$action}) eq 'HASH') {
15438: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15439: if (@todeleteimages) {
15440: map { $imgdeletions{$_} = 1; } @todeleteimages;
15441: }
15442: }
15443: my %customadds;
15444: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15445: if (@newcustom) {
15446: map { $customadds{$_} = 1; } @newcustom;
15447: }
15448: foreach my $provider (sort(keys(%providernames))) {
15449: $confhash{$provider} = {};
15450: my $pos = $env{'form.proctoring_pos_'.$provider};
15451: $pos =~ s/\D+//g;
15452: $allpos[$pos] = $provider;
15453: my (%current,%currentenc);
15454: my $showroles = 0;
15455: if (ref($domconfig{$action}) eq 'HASH') {
15456: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15457: %current = %{$domconfig{$action}{$provider}};
15458: foreach my $item ('key','secret') {
15459: $currentenc{$item} = $current{$item};
15460: delete($current{$item});
15461: }
15462: }
15463: }
15464: if ($env{'form.proctoring_available_'.$provider}) {
15465: $confhash{$provider}{'available'} = 1;
15466: unless ($current{'available'}) {
15467: $changes{$provider} = 1;
15468: }
15469: } else {
15470: %{$confhash{$provider}} = %current;
15471: %{$encconfhash{$provider}} = %currentenc;
15472: $confhash{$provider}{'available'} = 0;
15473: if ($current{'available'}) {
15474: $changes{$provider} = 1;
15475: }
15476: }
15477: if ($confhash{$provider}{'available'}) {
15478: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15479: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15480: if ($field eq 'lifetime') {
15481: if ($possval =~ /^\d+$/) {
15482: $confhash{$provider}{$field} = $possval;
15483: }
15484: } elsif ($field eq 'version') {
15485: if ($possval =~ /^\d+\.\d+$/) {
15486: $confhash{$provider}{$field} = $possval;
15487: }
15488: } elsif ($field eq 'sigmethod') {
15489: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15490: $confhash{$provider}{$field} = $possval;
15491: }
15492: } elsif ($field eq 'url') {
15493: $confhash{$provider}{$field} = $possval;
15494: } elsif (($field eq 'key') || ($field eq 'secret')) {
15495: $encconfhash{$provider}{$field} = $possval;
15496: unless ($currentenc{$field} eq $possval) {
15497: $changes{$provider} = 1;
15498: }
15499: }
15500: unless (($field eq 'key') || ($field eq 'secret')) {
15501: unless ($current{$field} eq $confhash{$provider}{$field}) {
15502: $changes{$provider} = 1;
15503: }
15504: }
15505: }
15506: if ($imgdeletions{$provider}) {
15507: $changes{$provider} = 1;
15508: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15509: my ($imageurl,$error) =
15510: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15511: $configuserok,$switchserver,$author_ok);
15512: if ($imageurl) {
15513: $confhash{$provider}{'image'} = $imageurl;
15514: $changes{$provider} = 1;
15515: }
15516: if ($error) {
15517: &Apache::lonnet::logthis($error);
15518: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15519: }
15520: } elsif (exists($current{'image'})) {
15521: $confhash{$provider}{'image'} = $current{'image'};
15522: }
15523: if (ref($requserfields{$provider}) eq 'ARRAY') {
15524: if (@{$requserfields{$provider}} > 0) {
15525: if (grep(/^user$/,@{$requserfields{$provider}})) {
15526: if ($env{'form.proctoring_userincdom_'.$provider}) {
15527: $confhash{$provider}{'incdom'} = 1;
15528: }
15529: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15530: $changes{$provider} = 1;
15531: }
15532: }
15533: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15534: $showroles = 1;
15535: }
15536: }
15537: }
15538: $confhash{$provider}{'fields'} = [];
15539: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15540: if (@{$optuserfields{$provider}} > 0) {
15541: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15542: foreach my $field (@{$optuserfields{$provider}}) {
15543: if (grep(/^\Q$field\E$/,@optfields)) {
15544: push(@{$confhash{$provider}{'fields'}},$field);
15545: }
15546: }
15547: }
15548: if (ref($current{'fields'}) eq 'ARRAY') {
15549: unless ($changes{$provider}) {
15550: my @new = sort(@{$confhash{$provider}{'fields'}});
15551: my @old = sort(@{$current{'fields'}});
15552: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15553: if (@diffs) {
15554: $changes{$provider} = 1;
15555: }
15556: }
15557: } elsif (@{$confhash{$provider}{'fields'}}) {
15558: $changes{$provider} = 1;
15559: }
15560: }
15561: if (ref($defaults{$provider}) eq 'ARRAY') {
15562: if (@{$defaults{$provider}} > 0) {
15563: my %options;
15564: if (ref($extended{$provider}) eq 'HASH') {
15565: %options = %{$extended{$provider}};
15566: }
15567: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15568: foreach my $field (@{$defaults{$provider}}) {
15569: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15570: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15571: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15572: push(@{$confhash{$provider}{'defaults'}},$poss);
15573: }
15574: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15575: foreach my $inner (keys(%{$options{$field}})) {
15576: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15577: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15578: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15579: $confhash{$provider}{'defaults'}{$inner} = $poss;
15580: }
15581: } else {
15582: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15583: }
15584: }
15585: } else {
15586: if (grep(/^\Q$field\E$/,@checked)) {
15587: push(@{$confhash{$provider}{'defaults'}},$field);
15588: }
15589: }
15590: }
15591: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15592: if (ref($current{'defaults'}) eq 'ARRAY') {
15593: unless ($changes{$provider}) {
15594: my @new = sort(@{$confhash{$provider}{'defaults'}});
15595: my @old = sort(@{$current{'defaults'}});
15596: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15597: if (@diffs) {
15598: $changes{$provider} = 1;
15599: }
15600: }
15601: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15602: if (@{$current{'defaults'}}) {
15603: $changes{$provider} = 1;
15604: }
15605: }
15606: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15607: if (ref($current{'defaults'}) eq 'HASH') {
15608: unless ($changes{$provider}) {
15609: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15610: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15611: $changes{$provider} = 1;
15612: last;
15613: }
15614: }
15615: }
15616: unless ($changes{$provider}) {
15617: foreach my $key (keys(%{$current{'defaults'}})) {
15618: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15619: $changes{$provider} = 1;
15620: last;
15621: }
15622: }
15623: }
15624: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15625: $changes{$provider} = 1;
15626: }
15627: }
15628: }
15629: }
15630: if (ref($crsconf{$provider}) eq 'ARRAY') {
15631: if (@{$crsconf{$provider}} > 0) {
15632: $confhash{$provider}{'crsconf'} = [];
15633: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15634: foreach my $crsfield (@{$crsconf{$provider}}) {
15635: if (grep(/^\Q$crsfield\E$/,@checked)) {
15636: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15637: }
15638: }
15639: if (ref($current{'crsconf'}) eq 'ARRAY') {
15640: unless ($changes{$provider}) {
15641: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15642: my @old = sort(@{$current{'crsconf'}});
15643: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15644: if (@diffs) {
15645: $changes{$provider} = 1;
15646: }
15647: }
15648: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15649: $changes{$provider} = 1;
15650: }
15651: }
15652: }
15653: if ($showroles) {
15654: $confhash{$provider}{'roles'} = {};
15655: foreach my $role (@courseroles) {
15656: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15657: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15658: $confhash{$provider}{'roles'}{$role} = $poss;
15659: }
15660: }
15661: unless ($changes{$provider}) {
15662: if (ref($current{'roles'}) eq 'HASH') {
15663: foreach my $role (keys(%{$current{'roles'}})) {
15664: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15665: $changes{$provider} = 1;
15666: last
15667: }
15668: }
15669: unless ($changes{$provider}) {
15670: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15671: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15672: $changes{$provider} = 1;
15673: last;
15674: }
15675: }
15676: }
15677: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15678: $changes{$provider} = 1;
15679: }
15680: }
15681: }
15682: if (ref($current{'custom'}) eq 'HASH') {
15683: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15684: foreach my $key (keys(%{$current{'custom'}})) {
15685: if (grep(/^\Q$key\E$/,@customdels)) {
15686: $changes{$provider} = 1;
15687: } else {
15688: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15689: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15690: $changes{$provider} = 1;
15691: }
15692: }
15693: }
15694: }
15695: if ($customadds{$provider}) {
15696: my $name = $env{'form.proctoring_custom_name_'.$provider};
15697: $name =~ s/(`)/'/g;
15698: $name =~ s/^\s+//;
15699: $name =~ s/\s+$//;
15700: my $value = $env{'form.proctoring_custom_value_'.$provider};
15701: $value =~ s/(`)/'/g;
15702: $value =~ s/^\s+//;
15703: $value =~ s/\s+$//;
15704: if ($name ne '') {
15705: $confhash{$provider}{'custom'}{$name} = $value;
15706: $changes{$provider} = 1;
15707: }
15708: }
15709: }
15710: }
15711: if (@allpos > 0) {
15712: my $idx = 0;
15713: foreach my $provider (@allpos) {
15714: if ($provider ne '') {
15715: $confhash{$provider}{'order'} = $idx;
15716: unless ($changes{$provider}) {
15717: if (ref($domconfig{$action}) eq 'HASH') {
15718: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15719: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15720: $changes{$provider} = 1;
15721: }
15722: }
15723: }
15724: }
15725: $idx ++;
15726: }
15727: }
15728: }
15729: my %proc_hash = (
15730: $action => { %confhash }
15731: );
15732: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15733: $dom);
15734: if ($putresult eq 'ok') {
15735: my %proc_enchash = (
15736: $action => { %encconfhash }
15737: );
1.384 raeburn 15738: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15739: if (keys(%changes) > 0) {
15740: my $cachetime = 24*60*60;
15741: my %procall = %confhash;
15742: foreach my $provider (keys(%procall)) {
15743: if (ref($encconfhash{$provider}) eq 'HASH') {
15744: foreach my $key ('key','secret') {
15745: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15746: }
15747: }
15748: }
15749: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15750: if (ref($lastactref) eq 'HASH') {
15751: $lastactref->{'proctoring'} = 1;
15752: }
15753: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15754: my %bynum;
15755: foreach my $provider (sort(keys(%changes))) {
15756: my $position = $confhash{$provider}{'order'};
15757: $bynum{$position} = $provider;
15758: }
15759: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15760: my $provider = $bynum{$pos};
15761: my %lt = &proctoring_titles($provider);
15762: my %fieldtitles = &proctoring_fieldtitles($provider);
15763: if (!$confhash{$provider}{'available'}) {
15764: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15765: } else {
15766: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15767: if ($confhash{$provider}{'image'}) {
15768: $resulttext .= ' '.
15769: '<img src="'.$confhash{$provider}{'image'}.'"'.
15770: ' alt="'.&mt('Proctoring icon').'" />';
15771: }
15772: $resulttext .= '<ul>';
15773: my $position = $pos + 1;
15774: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15775: foreach my $key ('version','sigmethod','url','lifetime') {
15776: if ($confhash{$provider}{$key} ne '') {
15777: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15778: }
15779: }
15780: if ($encconfhash{$provider}{'key'} ne '') {
15781: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15782: }
15783: if ($encconfhash{$provider}{'secret'} ne '') {
15784: $resulttext .= '<li>'.$lt{'secret'}.': ';
15785: my $num = length($encconfhash{$provider}{'secret'});
15786: $resulttext .= ('*'x$num).'</li>';
15787: }
15788: my (@fields,$showroles);
15789: if (ref($requserfields{$provider}) eq 'ARRAY') {
15790: push(@fields,@{$requserfields{$provider}});
15791: }
15792: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15793: push(@fields,@{$confhash{$provider}{'fields'}});
15794: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15795: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15796: }
15797: if (@fields) {
15798: if (grep(/^roles$/,@fields)) {
15799: $showroles = 1;
15800: }
15801: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15802: join('", "', map { $lt{$_}; } @fields).'"</li>';
15803: }
15804: if (ref($requserfields{$provider}) eq 'ARRAY') {
15805: if (grep(/^user$/,@{$requserfields{$provider}})) {
15806: if ($confhash{$provider}{'incdom'}) {
15807: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15808: } else {
15809: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15810: }
15811: }
15812: }
15813: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15814: if (@{$confhash{$provider}{'defaults'}} > 0) {
15815: $resulttext .= '<li>'.$lt{'defa'};
15816: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15817: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15818: }
15819: $resulttext =~ s/,$//;
15820: $resulttext .= '</li>';
15821: }
15822: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15823: if (keys(%{$confhash{$provider}{'defaults'}})) {
15824: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15825: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15826: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15827: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15828: }
15829: }
15830: $resulttext .= '</ul></li>';
15831: }
15832: }
15833: if (ref($crsconf{$provider}) eq 'ARRAY') {
15834: if (@{$crsconf{$provider}} > 0) {
15835: $resulttext .= '<li>'.&mt('Configurable in course:');
15836: my $numconfig = 0;
15837: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15838: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15839: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15840: $numconfig ++;
15841: if ($provider eq 'examity') {
15842: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15843: } else {
15844: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15845: }
15846: }
15847: $resulttext =~ s/,$//;
15848: }
15849: }
15850: if (!$numconfig) {
15851: $resulttext .= ' '.&mt('None');
15852: }
15853: $resulttext .= '</li>';
15854: }
15855: }
15856: if ($showroles) {
15857: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15858: my $rolemaps;
15859: foreach my $role (@courseroles) {
15860: if ($confhash{$provider}{'roles'}{$role}) {
15861: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15862: $confhash{$provider}{'roles'}{$role}.',';
15863: }
15864: }
15865: if ($rolemaps) {
15866: $rolemaps =~ s/,$//;
15867: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15868: }
15869: }
15870: }
15871: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15872: my $customlist;
15873: if (keys(%{$confhash{$provider}{'custom'}})) {
15874: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15875: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15876: }
15877: $customlist =~ s/,$//;
15878: }
15879: if ($customlist) {
15880: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15881: }
15882: }
15883: $resulttext .= '</ul></li>';
15884: }
15885: }
15886: $resulttext .= '</ul>';
15887: } else {
15888: $resulttext = &mt('No changes made.');
15889: }
15890: } else {
15891: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15892: }
15893: if ($errors) {
15894: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15895: $errors.'</ul>';
15896: }
15897: return $resulttext;
15898: }
15899:
15900: sub process_proctoring_image {
15901: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15902: my $filename = $env{'form.'.$caller.'.filename'};
15903: my ($error,$url);
15904: my ($width,$height) = (21,21);
15905: if ($configuserok eq 'ok') {
15906: if ($switchserver) {
15907: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15908: $switchserver);
15909: } elsif ($author_ok eq 'ok') {
15910: my ($result,$imageurl,$madethumb) =
15911: &publishlogo($r,'upload',$caller,$dom,$confname,
15912: "proctoring/$provider/icon",$width,$height);
15913: if ($result eq 'ok') {
15914: if ($madethumb) {
15915: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15916: my $imagethumb = "$path/tn-".$imagefile;
15917: $url = $imagethumb;
15918: } else {
15919: $url = $imageurl;
15920: }
15921: } else {
15922: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15923: }
15924: } else {
15925: $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);
15926: }
15927: } else {
15928: $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);
15929: }
15930: return ($url,$error);
15931: }
15932:
1.320 raeburn 15933: sub modify_lti {
15934: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15935: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15936: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
15937: my (%posslti,%posslticrs,%posscrstype);
15938: my @courseroles = ('cc','in','ta','ep','st');
15939: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15940: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15941: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15942: my %coursetypetitles = &Apache::lonlocal::texthash (
15943: official => 'Official',
15944: unofficial => 'Unofficial',
15945: community => 'Community',
15946: textbook => 'Textbook',
15947: placement => 'Placement Test',
1.392 raeburn 15948: lti => 'LTI Provider',
1.320 raeburn 15949: );
1.325 raeburn 15950: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15951: my %lt = <i_names();
15952: map { $posslti{$_} = 1; } @ltiroles;
15953: map { $posslticrs{$_} = 1; } @lticourseroles;
15954: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15955:
1.326 raeburn 15956: my %menutitles = <imenu_titles();
15957:
1.406 raeburn 15958: my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
1.405 raeburn 15959: $newltisec{'private'}{'keys'} = [];
15960: $newltisec{'encrypt'} = {};
15961: $newltisec{'rules'} = {};
1.406 raeburn 15962: $newltisec{'linkprot'} = {};
1.405 raeburn 15963: if (ref($domconfig{'ltisec'}) eq 'HASH') {
15964: %currltisec = %{$domconfig{'ltisec'}};
1.406 raeburn 15965: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15966: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
15967: unless ($id =~ /^\d+$/) {
15968: delete($currltisec{'linkprot'}{$id});
15969: }
15970: }
15971: }
1.405 raeburn 15972: if (ref($currltisec{'private'}) eq 'HASH') {
15973: if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
15974: $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
15975: map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
15976: }
15977: }
15978: }
15979: foreach my $item ('crs','dom','consumers') {
15980: my $formelement;
15981: if ($item eq 'consumers') {
15982: $formelement = 'form.ltisec_'.$item;
15983: } else {
15984: $formelement = 'form.ltisec_'.$item.'linkprot';
15985: }
15986: if ($env{$formelement}) {
15987: $newltisec{'encrypt'}{$item} = 1;
15988: if (ref($currltisec{'encrypt'}) eq 'HASH') {
15989: unless ($currltisec{'encrypt'}{$item}) {
15990: $secchanges{'encrypt'} = 1;
15991: }
15992: } else {
15993: $secchanges{'encrypt'} = 1;
15994: }
15995: } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
15996: if ($currltisec{'encrypt'}{$item}) {
15997: $secchanges{'encrypt'} = 1;
15998: }
15999: }
16000: }
16001: unless (exists($currltisec{'rules'})) {
16002: $currltisec{'rules'} = {};
16003: }
16004: &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
16005:
16006: my @ids=&Apache::lonnet::current_machine_ids();
16007: my %servers = &Apache::lonnet::get_servers($dom,'library');
16008:
16009: foreach my $hostid (keys(%servers)) {
16010: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
16011: my $newkey;
16012: my $keyitem = 'form.ltisec_privkey_'.$hostid;
16013: if (exists($env{$keyitem})) {
16014: $env{$keyitem} =~ s/(`)/'/g;
16015: if ($keyset{$hostid}) {
16016: if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
16017: if ($env{$keyitem} ne '') {
16018: $secchanges{'private'} = 1;
16019: $newkeyset{$hostid} = $env{$keyitem};
16020: }
16021: }
16022: } elsif ($env{$keyitem} ne '') {
16023: unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
16024: push(@{$newltisec{'private'}{'keys'}},$hostid);
16025: }
16026: $secchanges{'private'} = 1;
16027: $newkeyset{$hostid} = $env{$keyitem};
16028: }
16029: }
16030: }
16031: }
16032:
1.406 raeburn 16033: my (%linkprotchg,$linkprotoutput,$is_home);
16034: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
16035: \%linkprotchg,'domain');
16036: my $home = &Apache::lonnet::domain($dom,'primary');
16037: unless (($home eq 'no_host') || ($home eq '')) {
16038: my @ids=&Apache::lonnet::current_machine_ids();
16039: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
16040: }
16041:
16042: if (keys(%linkprotchg)) {
16043: $secchanges{'linkprot'} = 1;
16044: my %oldlinkprot;
16045: if (ref($currltisec{'linkprot'}) eq 'HASH') {
16046: %oldlinkprot = %{$currltisec{'linkprot'}};
16047: }
16048: foreach my $id (keys(%linkprotchg)) {
16049: if (ref($linkprotchg{$id}) eq 'HASH') {
16050: foreach my $inner (keys(%{$linkprotchg{$id}})) {
16051: if (($inner eq 'secret') || ($inner eq 'key')) {
16052: if ($is_home) {
16053: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
16054: }
16055: }
16056: }
16057: } else {
16058: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
16059: }
16060: }
16061: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
16062: if (keys(%linkprotchg)) {
16063: %{$newltisec{'linkprot'}} = %linkprotchg;
16064: }
16065: }
16066: if (ref($currltisec{'linkprot'}) eq 'HASH') {
16067: foreach my $id (%{$currltisec{'linkprot'}}) {
16068: next if ($id !~ /^\d+$/);
16069: unless (exists($linkprotchg{$id})) {
16070: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
16071: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
16072: if (($inner eq 'secret') || ($inner eq 'key')) {
16073: if ($is_home) {
16074: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
16075: }
16076: } else {
16077: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
16078: }
16079: }
16080: } else {
16081: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
16082: }
16083: }
16084: }
16085: }
16086: if ($proterror) {
16087: $errors .= '<li>'.$proterror.'</li>';
16088: }
1.320 raeburn 16089: my (@items,%deletions,%itemids);
16090: if ($env{'form.lti_add'}) {
16091: my $consumer = $env{'form.lti_consumer_add'};
16092: $consumer =~ s/(`)/'/g;
16093: ($newid,my $error) = &get_lti_id($dom,$consumer);
16094: if ($newid) {
16095: $itemids{'add'} = $newid;
16096: push(@items,'add');
16097: $changes{$newid} = 1;
16098: } else {
16099: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
16100: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16101: }
16102: }
16103: if (ref($domconfig{$action}) eq 'HASH') {
16104: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
16105: if (@todelete) {
16106: map { $deletions{$_} = 1; } @todelete;
16107: }
16108: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 16109: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 16110: my $itemid = $env{'form.lti_id_'.$i};
16111: $itemid =~ s/\D+//g;
16112: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16113: if ($deletions{$itemid}) {
16114: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16115: } else {
1.390 raeburn 16116: push(@items,$i);
16117: $itemids{$i} = $itemid;
1.320 raeburn 16118: }
16119: }
16120: }
16121: }
16122: foreach my $idx (@items) {
16123: my $itemid = $itemids{$idx};
16124: next unless ($itemid);
1.390 raeburn 16125: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16126: $position =~ s/\D+//g;
16127: if ($position ne '') {
16128: $allpos[$position] = $itemid;
16129: }
1.391 raeburn 16130: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 16131: my $formitem = 'form.lti_'.$item.'_'.$idx;
16132: $env{$formitem} =~ s/(`)/'/g;
16133: if ($item eq 'lifetime') {
16134: $env{$formitem} =~ s/[^\d.]//g;
16135: }
16136: if ($env{$formitem} ne '') {
16137: if (($item eq 'key') || ($item eq 'secret')) {
16138: $encconfig{$itemid}{$item} = $env{$formitem};
16139: } else {
16140: $confhash{$itemid}{$item} = $env{$formitem};
16141: unless (($idx eq 'add') || ($changes{$itemid})) {
16142: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
16143: $changes{$itemid} = 1;
16144: }
16145: }
16146: }
16147: }
16148: }
16149: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16150: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16151: }
1.345 raeburn 16152: if ($confhash{$itemid}{'requser'}) {
16153: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16154: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16155: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16156: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16157: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16158: my $mapuser = $env{'form.lti_customuser_'.$idx};
16159: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16160: $mapuser =~ s/^\s+|\s+$//g;
16161: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16162: }
16163: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16164: my @makeuser;
16165: foreach my $ltirole (sort(@possmakeuser)) {
16166: if ($posslti{$ltirole}) {
16167: push(@makeuser,$ltirole);
16168: }
16169: }
16170: $confhash{$itemid}{'makeuser'} = \@makeuser;
16171: if (@makeuser) {
16172: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16173: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16174: $confhash{$itemid}{'lcauth'} = $lcauth;
16175: if ($lcauth ne 'internal') {
16176: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16177: $lcauthparm =~ s/^(\s+|\s+)$//g;
16178: $lcauthparm =~ s/`//g;
16179: if ($lcauthparm ne '') {
16180: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16181: }
16182: }
16183: } else {
16184: $confhash{$itemid}{'lcauth'} = 'lti';
16185: }
1.320 raeburn 16186: }
1.345 raeburn 16187: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16188: if (@possinstdata) {
16189: foreach my $field (@possinstdata) {
16190: if (exists($fieldtitles{$field})) {
16191: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16192: }
16193: }
16194: }
1.363 raeburn 16195: if ($env{'form.lti_callback_'.$idx}) {
16196: if ($env{'form.lti_callbackparam_'.$idx}) {
16197: my $callback = $env{'form.lti_callbackparam_'.$idx};
16198: $callback =~ s/^\s+|\s+$//g;
16199: $confhash{$itemid}{'callback'} = $callback;
16200: }
16201: }
1.391 raeburn 16202: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16203: if ($env{'form.lti_'.$field.'_'.$idx}) {
16204: $confhash{$itemid}{$field} = 1;
16205: }
1.320 raeburn 16206: }
1.345 raeburn 16207: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16208: $confhash{$itemid}{lcmenu} = [];
16209: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16210: foreach my $field (@possmenu) {
16211: if (exists($menutitles{$field})) {
16212: if ($field eq 'grades') {
16213: next unless ($env{'form.lti_inlinemenu_'.$idx});
16214: }
16215: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16216: }
16217: }
16218: }
1.391 raeburn 16219: if ($confhash{$itemid}{'crsinc'}) {
16220: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16221: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16222: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16223: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16224: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16225: $mapcrs =~ s/(`)/'/g;
16226: $mapcrs =~ s/^\s+|\s+$//g;
16227: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16228: }
16229: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16230: my @crstypes;
16231: foreach my $type (sort(@posstypes)) {
16232: if ($posscrstype{$type}) {
16233: push(@crstypes,$type);
16234: }
16235: }
16236: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16237: if ($env{'form.lti_storecrs_'.$idx}) {
16238: $confhash{$itemid}{'storecrs'} = 1;
16239: }
1.391 raeburn 16240: if ($env{'form.lti_makecrs_'.$idx}) {
16241: $confhash{$itemid}{'makecrs'} = 1;
16242: }
16243: foreach my $ltirole (@lticourseroles) {
16244: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16245: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16246: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16247: }
16248: }
16249: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16250: my @selfenroll;
16251: foreach my $type (sort(@possenroll)) {
16252: if ($posslticrs{$type}) {
16253: push(@selfenroll,$type);
16254: }
16255: }
16256: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16257: if ($env{'form.lti_crssec_'.$idx}) {
16258: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16259: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16260: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16261: my $section = $env{'form.lti_customsection_'.$idx};
16262: $section =~ s/(`)/'/g;
16263: $section =~ s/^\s+|\s+$//g;
16264: if ($section ne '') {
16265: $confhash{$itemid}{'section'} = $section;
16266: }
16267: }
16268: }
16269: foreach my $field ('passback','roster') {
16270: if ($env{'form.lti_'.$field.'_'.$idx}) {
16271: $confhash{$itemid}{$field} = 1;
16272: }
16273: }
16274: if ($env{'form.lti_passback_'.$idx}) {
16275: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16276: $confhash{$itemid}{'passbackformat'} = '1.0';
16277: } else {
16278: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16279: }
16280: }
1.391 raeburn 16281: }
16282: unless (($idx eq 'add') || ($changes{$itemid})) {
16283: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16284: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 16285: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16286: $changes{$itemid} = 1;
16287: }
1.345 raeburn 16288: }
16289: unless ($changes{$itemid}) {
1.391 raeburn 16290: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
16291: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16292: $changes{$itemid} = 1;
16293: }
16294: }
1.345 raeburn 16295: }
1.391 raeburn 16296: foreach my $field ('mapcrstype','selfenroll') {
16297: unless ($changes{$itemid}) {
16298: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
16299: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16300: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
16301: $confhash{$itemid}{$field});
16302: if (@diffs) {
16303: $changes{$itemid} = 1;
16304: }
16305: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
16306: $changes{$itemid} = 1;
16307: }
16308: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16309: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16310: $changes{$itemid} = 1;
16311: }
16312: }
1.391 raeburn 16313: }
16314: }
16315: unless ($changes{$itemid}) {
16316: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
16317: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16318: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
16319: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
16320: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16321: $changes{$itemid} = 1;
16322: last;
16323: }
16324: }
1.391 raeburn 16325: unless ($changes{$itemid}) {
16326: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16327: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
16328: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
16329: $changes{$itemid} = 1;
16330: last;
16331: }
16332: }
16333: }
16334: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
16335: $changes{$itemid} = 1;
1.345 raeburn 16336: }
1.391 raeburn 16337: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16338: unless ($changes{$itemid}) {
16339: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16340: $changes{$itemid} = 1;
16341: }
16342: }
16343: }
16344: }
16345: }
16346: unless ($changes{$itemid}) {
16347: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
16348: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16349: $changes{$itemid} = 1;
1.320 raeburn 16350: }
1.391 raeburn 16351: }
16352: unless ($changes{$itemid}) {
16353: foreach my $field ('makeuser','lcmenu') {
16354: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
16355: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16356: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
16357: $confhash{$itemid}{$field});
16358: if (@diffs) {
16359: $changes{$itemid} = 1;
16360: }
16361: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
16362: $changes{$itemid} = 1;
16363: }
16364: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16365: if (@{$confhash{$itemid}{$field}} > 0) {
16366: $changes{$itemid} = 1;
16367: }
1.345 raeburn 16368: }
1.320 raeburn 16369: }
16370: }
16371: }
16372: }
16373: }
16374: }
16375: if (@allpos > 0) {
16376: my $idx = 0;
16377: foreach my $itemid (@allpos) {
16378: if ($itemid ne '') {
16379: $confhash{$itemid}{'order'} = $idx;
16380: if (ref($domconfig{$action}) eq 'HASH') {
16381: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16382: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16383: $changes{$itemid} = 1;
16384: }
16385: }
16386: }
16387: $idx ++;
16388: }
16389: }
16390: }
16391: my %ltihash = (
1.405 raeburn 16392: $action => { %confhash }
16393: );
1.406 raeburn 16394: my %ltienchash = (
16395: $action => { %encconfig }
16396: );
1.405 raeburn 16397: if (keys(%secchanges)) {
16398: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16399: if ($secchanges{'linkprot'}) {
16400: if ($is_home) {
16401: $ltienchash{'linkprot'} = \%newltienc;
16402: }
16403: }
1.405 raeburn 16404: }
16405: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16406: if ($putresult eq 'ok') {
1.405 raeburn 16407: my %keystore;
16408: if (keys(%secchanges)) {
16409: if ($secchanges{'private'}) {
16410: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
16411: foreach my $hostid (keys(%newkeyset)) {
16412: my $storehash = {
16413: key => $newkeyset{$hostid},
16414: who => $env{'user.name'}.':'.$env{'user.domain'},
16415: };
16416: $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
16417: $dom,$hostid);
16418: }
16419: }
1.407 raeburn 16420: if (ref($lastactref) eq 'HASH') {
16421: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
16422: $lastactref->{'domdefaults'} = 1;
16423: }
16424: }
1.405 raeburn 16425: }
1.384 raeburn 16426: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16427: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16428: return &mt('No changes made.');
16429: }
16430: $resulttext = &mt('Changes made:').'<ul>';
16431: if (keys(%secchanges) > 0) {
16432: foreach my $item (keys(%secchanges)) {
16433: if ($item eq 'encrypt') {
16434: my %encrypted = (
16435: crs => {
16436: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
16437: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
16438: },
16439: dom => {
16440: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
16441: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
16442: },
16443: consumers => {
16444: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
16445: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
16446: },
16447: );
16448: foreach my $type ('crs','dom','consumers') {
16449: my $shown = $encrypted{$type}{'off'};
16450: if (ref($newltisec{$item}) eq 'HASH') {
16451: if ($newltisec{$item}{$type}) {
16452: $shown = $encrypted{$type}{'on'};
16453: }
16454: }
16455: $resulttext .= '<li>'.$shown.'</li>';
16456: }
16457: } elsif ($item eq 'rules') {
16458: my %titles = &Apache::lonlocal::texthash(
16459: min => 'Minimum password length',
16460: max => 'Maximum password length',
16461: chars => 'Required characters',
16462: );
16463: foreach my $rule ('min','max') {
16464: if ($newltisec{rules}{$rule} eq '') {
16465: if ($rule eq 'min') {
16466: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
16467: ' '.&mt('Default of [_1] will be used',
16468: $Apache::lonnet::passwdmin).'</li>';
16469: } else {
16470: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
16471: }
16472: } else {
16473: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
16474: }
16475: }
16476: if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
16477: if (@{$newltisec{'rules'}{'chars'}} > 0) {
16478: my %rulenames = &Apache::lonlocal::texthash(
16479: uc => 'At least one upper case letter',
16480: lc => 'At least one lower case letter',
16481: num => 'At least one number',
16482: spec => 'At least one non-alphanumeric',
16483: );
16484: my $needed = '<ul><li>'.
16485: join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
16486: '</li></ul>';
16487: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16488: } else {
16489: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16490: }
16491: } else {
16492: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16493: }
16494: } elsif ($item eq 'private') {
16495: if (keys(%newkeyset)) {
16496: foreach my $hostid (sort(keys(%newkeyset))) {
16497: if ($keystore{$hostid} eq 'ok') {
16498: $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
16499: }
16500: }
16501: }
1.406 raeburn 16502: } elsif ($item eq 'linkprot') {
16503: $resulttext .= $linkprotoutput;
1.405 raeburn 16504: }
16505: }
16506: }
1.320 raeburn 16507: if (keys(%changes) > 0) {
16508: my $cachetime = 24*60*60;
16509: my %ltiall = %confhash;
16510: foreach my $id (keys(%ltiall)) {
16511: if (ref($encconfig{$id}) eq 'HASH') {
16512: foreach my $item ('key','secret') {
16513: $ltiall{$id}{$item} = $encconfig{$id}{$item};
16514: }
16515: }
16516: }
16517: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
16518: if (ref($lastactref) eq 'HASH') {
16519: $lastactref->{'lti'} = 1;
16520: }
16521: my %bynum;
16522: foreach my $itemid (sort(keys(%changes))) {
16523: my $position = $confhash{$itemid}{'order'};
16524: $bynum{$position} = $itemid;
16525: }
16526: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16527: my $itemid = $bynum{$pos};
16528: if (ref($confhash{$itemid}) ne 'HASH') {
16529: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16530: } else {
1.390 raeburn 16531: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16532: my $position = $pos + 1;
16533: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16534: foreach my $item ('version','lifetime') {
16535: if ($confhash{$itemid}{$item} ne '') {
16536: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16537: }
16538: }
16539: if ($encconfig{$itemid}{'key'} ne '') {
16540: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
16541: }
16542: if ($encconfig{$itemid}{'secret'} ne '') {
16543: $resulttext .= '<li>'.$lt{'secret'}.': ';
16544: my $num = length($encconfig{$itemid}{'secret'});
16545: $resulttext .= ('*'x$num).'</li>';
16546: }
1.345 raeburn 16547: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16548: if ($confhash{$itemid}{'callback'}) {
16549: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16550: } else {
1.392 raeburn 16551: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16552: }
1.345 raeburn 16553: if ($confhash{$itemid}{'mapuser'}) {
16554: my $shownmapuser;
16555: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16556: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16557: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16558: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16559: } else {
16560: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16561: }
1.345 raeburn 16562: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16563: }
1.345 raeburn 16564: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16565: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16566: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16567: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16568: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16569: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16570: } else {
16571: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16572: $confhash{$itemid}{'lcauth'});
16573: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16574: $resulttext .= '; '.&mt('a randomly generated password will be created');
16575: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16576: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16577: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16578: }
16579: } else {
16580: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16581: }
16582: }
16583: $resulttext .= '</li>';
16584: } else {
16585: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16586: }
1.320 raeburn 16587: }
1.345 raeburn 16588: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16589: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16590: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16591: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16592: } else {
1.345 raeburn 16593: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16594: }
1.320 raeburn 16595: }
1.391 raeburn 16596: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16597: $resulttext .= '<li>'.$lt{$item}.': ';
16598: if ($confhash{$itemid}{$item}) {
16599: $resulttext .= &mt('Yes');
16600: } else {
16601: $resulttext .= &mt('No');
1.337 raeburn 16602: }
1.345 raeburn 16603: $resulttext .= '</li>';
1.320 raeburn 16604: }
1.345 raeburn 16605: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16606: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16607: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16608: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16609: } else {
16610: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16611: }
16612: }
16613: if ($confhash{$itemid}{'crsinc'}) {
16614: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16615: my $rolemaps;
16616: foreach my $role (@ltiroles) {
16617: if ($confhash{$itemid}{'maproles'}{$role}) {
16618: $rolemaps .= (' 'x2).$role.'='.
16619: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16620: 'Course').',';
16621: }
16622: }
16623: if ($rolemaps) {
16624: $rolemaps =~ s/,$//;
16625: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16626: }
16627: }
16628: if ($confhash{$itemid}{'mapcrs'}) {
16629: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16630: }
16631: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16632: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16633: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16634: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16635: '</li>';
16636: } else {
16637: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16638: }
16639: }
1.392 raeburn 16640: if ($confhash{$itemid}{'storecrs'}) {
16641: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16642: }
1.391 raeburn 16643: if ($confhash{$itemid}{'makecrs'}) {
16644: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16645: } else {
16646: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16647: }
16648: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16649: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16650: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16651: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16652: '</li>';
16653: } else {
16654: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16655: }
16656: }
16657: if ($confhash{$itemid}{'section'}) {
16658: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16659: $resulttext .= '<li>'.&mt('User section from standard field:').
16660: ' (course_section_sourcedid)'.'</li>';
16661: } else {
16662: $resulttext .= '<li>'.&mt('User section from:').' '.
16663: $confhash{$itemid}{'section'}.'</li>';
16664: }
1.345 raeburn 16665: } else {
1.391 raeburn 16666: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16667: }
16668: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16669: $resulttext .= '<li>'.$lt{$item}.': ';
16670: if ($confhash{$itemid}{$item}) {
16671: $resulttext .= &mt('Yes');
16672: if ($item eq 'passback') {
16673: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16674: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16675: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16676: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16677: }
16678: }
16679: } else {
16680: $resulttext .= &mt('No');
16681: }
16682: $resulttext .= '</li>';
16683: }
16684: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16685: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16686: $resulttext .= '<li>'.&mt('Menu items:').' '.
16687: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16688: } else {
16689: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16690: }
1.345 raeburn 16691: }
1.326 raeburn 16692: }
16693: }
1.320 raeburn 16694: $resulttext .= '</ul></li>';
16695: }
16696: }
16697: }
1.405 raeburn 16698: $resulttext .= '</ul>';
1.320 raeburn 16699: } else {
16700: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16701: }
16702: if ($errors) {
16703: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16704: $errors.'</ul>';
16705: }
16706: return $resulttext;
16707: }
16708:
16709: sub get_lti_id {
16710: my ($domain,$consumer) = @_;
16711: # get lock on lti db
16712: my $lockhash = {
16713: lock => $env{'user.name'}.
16714: ':'.$env{'user.domain'},
16715: };
16716: my $tries = 0;
16717: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16718: my ($id,$error);
16719:
16720: while (($gotlock ne 'ok') && ($tries<10)) {
16721: $tries ++;
16722: sleep (0.1);
16723: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16724: }
16725: if ($gotlock eq 'ok') {
16726: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16727: if ($currids{'lock'}) {
16728: delete($currids{'lock'});
16729: if (keys(%currids)) {
16730: my @curr = sort { $a <=> $b } keys(%currids);
16731: if ($curr[-1] =~ /^\d+$/) {
16732: $id = 1 + $curr[-1];
16733: }
16734: } else {
16735: $id = 1;
16736: }
16737: if ($id) {
16738: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16739: $error = 'nostore';
16740: }
16741: } else {
16742: $error = 'nonumber';
16743: }
16744: }
16745: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16746: } else {
16747: $error = 'nolock';
16748: }
16749: return ($id,$error);
16750: }
16751:
1.3 raeburn 16752: sub modify_autoenroll {
1.205 raeburn 16753: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16754: my ($resulttext,%changes);
16755: my %currautoenroll;
16756: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16757: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16758: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16759: }
16760: }
16761: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16762: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16763: sender => 'Sender for notification messages',
1.274 raeburn 16764: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16765: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16766: my @offon = ('off','on');
1.17 raeburn 16767: my $sender_uname = $env{'form.sender_uname'};
16768: my $sender_domain = $env{'form.sender_domain'};
16769: if ($sender_domain eq '') {
16770: $sender_uname = '';
16771: } elsif ($sender_uname eq '') {
16772: $sender_domain = '';
16773: }
1.129 raeburn 16774: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16775: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16776: $autofailsafe =~ s{^\s+|\s+$}{}g;
16777: if ($autofailsafe =~ /\D/) {
16778: undef($autofailsafe);
16779: }
1.274 raeburn 16780: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16781: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16782: $failsafe = 'off';
1.400 raeburn 16783: undef($autofailsafe);
1.274 raeburn 16784: }
1.1 raeburn 16785: my %autoenrollhash = (
1.129 raeburn 16786: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16787: 'sender_uname' => $sender_uname,
16788: 'sender_domain' => $sender_domain,
16789: 'co-owners' => $coowners,
1.399 raeburn 16790: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16791: 'failsafe' => $failsafe,
1.1 raeburn 16792: }
16793: );
1.4 raeburn 16794: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16795: $dom);
1.1 raeburn 16796: if ($putresult eq 'ok') {
16797: if (exists($currautoenroll{'run'})) {
16798: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16799: $changes{'run'} = 1;
16800: }
16801: } elsif ($autorun) {
16802: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16803: $changes{'run'} = 1;
1.1 raeburn 16804: }
16805: }
1.17 raeburn 16806: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16807: $changes{'sender'} = 1;
16808: }
1.17 raeburn 16809: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16810: $changes{'sender'} = 1;
16811: }
1.129 raeburn 16812: if ($currautoenroll{'co-owners'} ne '') {
16813: if ($currautoenroll{'co-owners'} ne $coowners) {
16814: $changes{'coowners'} = 1;
16815: }
16816: } elsif ($coowners) {
16817: $changes{'coowners'} = 1;
1.274 raeburn 16818: }
1.399 raeburn 16819: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16820: $changes{'autofailsafe'} = 1;
16821: }
1.399 raeburn 16822: if ($currautoenroll{'failsafe'} ne $failsafe) {
16823: $changes{'failsafe'} = 1;
16824: }
1.1 raeburn 16825: if (keys(%changes) > 0) {
16826: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16827: if ($changes{'run'}) {
1.1 raeburn 16828: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16829: }
16830: if ($changes{'sender'}) {
1.17 raeburn 16831: if ($sender_uname eq '' || $sender_domain eq '') {
16832: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16833: } else {
16834: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16835: }
1.1 raeburn 16836: }
1.129 raeburn 16837: if ($changes{'coowners'}) {
16838: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16839: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16840: if (ref($lastactref) eq 'HASH') {
16841: $lastactref->{'domainconfig'} = 1;
16842: }
1.129 raeburn 16843: }
1.274 raeburn 16844: if ($changes{'autofailsafe'}) {
1.399 raeburn 16845: if ($autofailsafe ne '') {
16846: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16847: } else {
1.399 raeburn 16848: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16849: }
1.399 raeburn 16850: }
16851: if ($changes{'failsafe'}) {
16852: if ($failsafe eq 'off') {
16853: unless ($changes{'autofailsafe'}) {
16854: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16855: }
16856: } elsif ($failsafe eq 'zero') {
16857: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16858: } else {
16859: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16860: }
16861: }
16862: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16863: &Apache::lonnet::get_domain_defaults($dom,1);
16864: if (ref($lastactref) eq 'HASH') {
16865: $lastactref->{'domdefaults'} = 1;
16866: }
16867: }
1.1 raeburn 16868: $resulttext .= '</ul>';
16869: } else {
16870: $resulttext = &mt('No changes made to auto-enrollment settings');
16871: }
16872: } else {
1.11 albertel 16873: $resulttext = '<span class="LC_error">'.
16874: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16875: }
1.3 raeburn 16876: return $resulttext;
1.1 raeburn 16877: }
16878:
16879: sub modify_autoupdate {
1.3 raeburn 16880: my ($dom,%domconfig) = @_;
1.1 raeburn 16881: my ($resulttext,%currautoupdate,%fields,%changes);
16882: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16883: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16884: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16885: }
16886: }
16887: my @offon = ('off','on');
16888: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16889: run => 'Auto-update:',
16890: classlists => 'Updates to user information in classlists?',
16891: unexpired => 'Skip updates for users without active or future roles?',
16892: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16893: );
1.44 raeburn 16894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16895: my %fieldtitles = &Apache::lonlocal::texthash (
16896: id => 'Student/Employee ID',
1.20 raeburn 16897: permanentemail => 'E-mail address',
1.1 raeburn 16898: lastname => 'Last Name',
16899: firstname => 'First Name',
16900: middlename => 'Middle Name',
1.132 raeburn 16901: generation => 'Generation',
1.1 raeburn 16902: );
1.142 raeburn 16903: $othertitle = &mt('All users');
1.1 raeburn 16904: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16905: $othertitle = &mt('Other users');
1.1 raeburn 16906: }
16907: foreach my $key (keys(%env)) {
16908: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16909: my ($usertype,$item) = ($1,$2);
16910: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16911: if ($usertype eq 'default') {
16912: push(@{$fields{$1}},$2);
16913: } elsif (ref($types) eq 'ARRAY') {
16914: if (grep(/^\Q$usertype\E$/,@{$types})) {
16915: push(@{$fields{$1}},$2);
16916: }
16917: }
16918: }
1.1 raeburn 16919: }
16920: }
1.131 raeburn 16921: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16922: @lockablenames = sort(@lockablenames);
16923: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16924: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16925: if (@changed) {
16926: $changes{'lockablenames'} = 1;
16927: }
16928: } else {
16929: if (@lockablenames) {
16930: $changes{'lockablenames'} = 1;
16931: }
16932: }
1.1 raeburn 16933: my %updatehash = (
16934: autoupdate => { run => $env{'form.autoupdate_run'},
16935: classlists => $env{'form.classlists'},
1.385 raeburn 16936: unexpired => $env{'form.unexpired'},
1.1 raeburn 16937: fields => {%fields},
1.131 raeburn 16938: lockablenames => \@lockablenames,
1.1 raeburn 16939: }
16940: );
1.385 raeburn 16941: my $lastactivedays;
16942: if ($env{'form.lastactive'}) {
16943: $lastactivedays = $env{'form.lastactivedays'};
16944: $lastactivedays =~ s/^\s+|\s+$//g;
16945: unless ($lastactivedays =~ /^\d+$/) {
16946: undef($lastactivedays);
16947: $env{'form.lastactive'} = 0;
16948: }
16949: }
16950: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16951: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16952: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16953: if (exists($updatehash{autoupdate}{$key})) {
16954: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16955: $changes{$key} = 1;
16956: }
16957: }
16958: } elsif ($key eq 'fields') {
16959: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16960: foreach my $item (@{$types},'default') {
1.1 raeburn 16961: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16962: my $change = 0;
16963: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16964: if (!exists($fields{$item})) {
16965: $change = 1;
1.132 raeburn 16966: last;
1.1 raeburn 16967: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16968: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16969: $change = 1;
1.132 raeburn 16970: last;
1.1 raeburn 16971: }
16972: }
16973: }
16974: if ($change) {
16975: push(@{$changes{$key}},$item);
16976: }
1.26 raeburn 16977: }
1.1 raeburn 16978: }
16979: }
1.131 raeburn 16980: } elsif ($key eq 'lockablenames') {
16981: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16982: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16983: if (@changed) {
16984: $changes{'lockablenames'} = 1;
16985: }
16986: } else {
16987: if (@lockablenames) {
16988: $changes{'lockablenames'} = 1;
16989: }
16990: }
16991: }
16992: }
16993: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16994: if (@lockablenames) {
16995: $changes{'lockablenames'} = 1;
1.1 raeburn 16996: }
16997: }
1.385 raeburn 16998: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16999: if ($updatehash{'autoupdate'}{'unexpired'}) {
17000: $changes{'unexpired'} = 1;
17001: }
17002: }
17003: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
17004: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
17005: $changes{'lastactive'} = 1;
17006: }
17007: }
1.26 raeburn 17008: foreach my $item (@{$types},'default') {
17009: if (defined($fields{$item})) {
17010: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 17011: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
17012: my $change = 0;
17013: if (ref($fields{$item}) eq 'ARRAY') {
17014: foreach my $type (@{$fields{$item}}) {
17015: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
17016: $change = 1;
17017: last;
17018: }
17019: }
17020: }
17021: if ($change) {
17022: push(@{$changes{'fields'}},$item);
17023: }
17024: } else {
1.26 raeburn 17025: push(@{$changes{'fields'}},$item);
17026: }
17027: } else {
17028: push(@{$changes{'fields'}},$item);
1.1 raeburn 17029: }
17030: }
17031: }
17032: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
17033: $dom);
17034: if ($putresult eq 'ok') {
17035: if (keys(%changes) > 0) {
17036: $resulttext = &mt('Changes made:').'<ul>';
17037: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 17038: if ($key eq 'lockablenames') {
17039: $resulttext .= '<li>';
17040: if (@lockablenames) {
17041: $usertypes->{'default'} = $othertitle;
17042: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
17043: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
17044: } else {
17045: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
17046: }
17047: $resulttext .= '</li>';
17048: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 17049: foreach my $item (@{$changes{$key}}) {
17050: my @newvalues;
17051: foreach my $type (@{$fields{$item}}) {
17052: push(@newvalues,$fieldtitles{$type});
17053: }
1.3 raeburn 17054: my $newvaluestr;
17055: if (@newvalues > 0) {
17056: $newvaluestr = join(', ',@newvalues);
17057: } else {
17058: $newvaluestr = &mt('none');
1.6 raeburn 17059: }
1.1 raeburn 17060: if ($item eq 'default') {
1.26 raeburn 17061: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 17062: } else {
1.26 raeburn 17063: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 17064: }
17065: }
17066: } else {
17067: my $newvalue;
17068: if ($key eq 'run') {
17069: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 17070: } elsif ($key eq 'lastactive') {
17071: $newvalue = $offon[$env{'form.lastactive'}];
17072: unless ($lastactivedays eq '') {
17073: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
17074: }
1.1 raeburn 17075: } else {
17076: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 17077: }
1.1 raeburn 17078: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
17079: }
17080: }
17081: $resulttext .= '</ul>';
17082: } else {
1.3 raeburn 17083: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 17084: }
17085: } else {
1.11 albertel 17086: $resulttext = '<span class="LC_error">'.
17087: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17088: }
1.3 raeburn 17089: return $resulttext;
1.1 raeburn 17090: }
17091:
1.125 raeburn 17092: sub modify_autocreate {
17093: my ($dom,%domconfig) = @_;
17094: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17095: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17096: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17097: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17098: }
17099: }
17100: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17101: req => 'Auto-creation of validated requests for official courses',
17102: xmldc => 'Identity of course creator of courses from XML files',
17103: );
17104: my @types = ('xml','req');
17105: foreach my $item (@types) {
17106: $newvals{$item} = $env{'form.autocreate_'.$item};
17107: $newvals{$item} =~ s/\D//g;
17108: $newvals{$item} = 0 if ($newvals{$item} eq '');
17109: }
17110: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17111: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17112: unless (exists($domcoords{$newvals{'xmldc'}})) {
17113: $newvals{'xmldc'} = '';
17114: }
17115: %autocreatehash = (
17116: autocreate => { xml => $newvals{'xml'},
17117: req => $newvals{'req'},
17118: }
17119: );
17120: if ($newvals{'xmldc'} ne '') {
17121: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17122: }
17123: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17124: $dom);
17125: if ($putresult eq 'ok') {
17126: my @items = @types;
17127: if ($newvals{'xml'}) {
17128: push(@items,'xmldc');
17129: }
17130: foreach my $item (@items) {
17131: if (exists($currautocreate{$item})) {
17132: if ($currautocreate{$item} ne $newvals{$item}) {
17133: $changes{$item} = 1;
17134: }
17135: } elsif ($newvals{$item}) {
17136: $changes{$item} = 1;
17137: }
17138: }
17139: if (keys(%changes) > 0) {
17140: my @offon = ('off','on');
17141: $resulttext = &mt('Changes made:').'<ul>';
17142: foreach my $item (@types) {
17143: if ($changes{$item}) {
17144: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17145: $resulttext .= '<li>'.
17146: &mt("$title{$item} set to [_1]$newtxt [_2]",
17147: '<b>','</b>').
17148: '</li>';
1.125 raeburn 17149: }
17150: }
17151: if ($changes{'xmldc'}) {
17152: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17153: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17154: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17155: }
17156: $resulttext .= '</ul>';
17157: } else {
17158: $resulttext = &mt('No changes made to auto-creation settings');
17159: }
17160: } else {
17161: $resulttext = '<span class="LC_error">'.
17162: &mt('An error occurred: [_1]',$putresult).'</span>';
17163: }
17164: return $resulttext;
17165: }
17166:
1.23 raeburn 17167: sub modify_directorysrch {
1.295 raeburn 17168: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17169: my ($resulttext,%changes);
17170: my %currdirsrch;
17171: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17172: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17173: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17174: }
17175: }
1.277 raeburn 17176: my %title = ( available => 'Institutional directory search available',
17177: localonly => 'Other domains can search institution',
17178: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17179: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17180: searchby => 'Search types',
17181: searchtypes => 'Search latitude');
17182: my @offon = ('off','on');
1.24 raeburn 17183: my @otherdoms = ('Yes','No');
1.23 raeburn 17184:
1.25 raeburn 17185: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17186: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17187: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17188:
1.44 raeburn 17189: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17190: if (keys(%{$usertypes}) == 0) {
17191: @cansearch = ('default');
17192: } else {
17193: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17194: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17195: if (!grep(/^\Q$type\E$/,@cansearch)) {
17196: push(@{$changes{'cansearch'}},$type);
17197: }
1.23 raeburn 17198: }
1.26 raeburn 17199: foreach my $type (@cansearch) {
17200: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17201: push(@{$changes{'cansearch'}},$type);
17202: }
1.23 raeburn 17203: }
1.26 raeburn 17204: } else {
17205: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17206: }
17207: }
17208:
17209: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17210: foreach my $by (@{$currdirsrch{'searchby'}}) {
17211: if (!grep(/^\Q$by\E$/,@searchby)) {
17212: push(@{$changes{'searchby'}},$by);
17213: }
17214: }
17215: foreach my $by (@searchby) {
17216: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17217: push(@{$changes{'searchby'}},$by);
17218: }
17219: }
17220: } else {
17221: push(@{$changes{'searchby'}},@searchby);
17222: }
1.25 raeburn 17223:
17224: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17225: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17226: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17227: push(@{$changes{'searchtypes'}},$type);
17228: }
17229: }
17230: foreach my $type (@searchtypes) {
17231: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17232: push(@{$changes{'searchtypes'}},$type);
17233: }
17234: }
17235: } else {
17236: if (exists($currdirsrch{'searchtypes'})) {
17237: foreach my $type (@searchtypes) {
17238: if ($type ne $currdirsrch{'searchtypes'}) {
17239: push(@{$changes{'searchtypes'}},$type);
17240: }
17241: }
17242: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17243: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17244: }
17245: } else {
17246: push(@{$changes{'searchtypes'}},@searchtypes);
17247: }
17248: }
17249:
1.23 raeburn 17250: my %dirsrch_hash = (
17251: directorysrch => { available => $env{'form.dirsrch_available'},
17252: cansearch => \@cansearch,
1.277 raeburn 17253: localonly => $env{'form.dirsrch_instlocalonly'},
17254: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17255: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17256: searchby => \@searchby,
1.25 raeburn 17257: searchtypes => \@searchtypes,
1.23 raeburn 17258: }
17259: );
17260: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17261: $dom);
17262: if ($putresult eq 'ok') {
17263: if (exists($currdirsrch{'available'})) {
17264: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17265: $changes{'available'} = 1;
17266: }
17267: } else {
17268: if ($env{'form.dirsrch_available'} eq '1') {
17269: $changes{'available'} = 1;
17270: }
17271: }
1.277 raeburn 17272: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17273: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17274: $changes{'lcavailable'} = 1;
17275: }
1.277 raeburn 17276: } else {
17277: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17278: $changes{'lcavailable'} = 1;
17279: }
17280: }
1.24 raeburn 17281: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17282: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17283: $changes{'localonly'} = 1;
17284: }
1.24 raeburn 17285: } else {
1.277 raeburn 17286: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17287: $changes{'localonly'} = 1;
17288: }
17289: }
1.277 raeburn 17290: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17291: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17292: $changes{'lclocalonly'} = 1;
17293: }
1.277 raeburn 17294: } else {
17295: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17296: $changes{'lclocalonly'} = 1;
17297: }
17298: }
1.23 raeburn 17299: if (keys(%changes) > 0) {
17300: $resulttext = &mt('Changes made:').'<ul>';
17301: if ($changes{'available'}) {
17302: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17303: }
1.277 raeburn 17304: if ($changes{'lcavailable'}) {
17305: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17306: }
1.24 raeburn 17307: if ($changes{'localonly'}) {
1.277 raeburn 17308: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17309: }
1.277 raeburn 17310: if ($changes{'lclocalonly'}) {
17311: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17312: }
1.23 raeburn 17313: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17314: my $chgtext;
1.26 raeburn 17315: if (ref($usertypes) eq 'HASH') {
17316: if (keys(%{$usertypes}) > 0) {
17317: foreach my $type (@{$types}) {
17318: if (grep(/^\Q$type\E$/,@cansearch)) {
17319: $chgtext .= $usertypes->{$type}.'; ';
17320: }
17321: }
17322: if (grep(/^default$/,@cansearch)) {
17323: $chgtext .= $othertitle;
17324: } else {
17325: $chgtext =~ s/\; $//;
17326: }
1.210 raeburn 17327: $resulttext .=
1.178 raeburn 17328: '<li>'.
17329: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17330: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17331: '</li>';
1.23 raeburn 17332: }
17333: }
17334: }
17335: if (ref($changes{'searchby'}) eq 'ARRAY') {
17336: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17337: my $chgtext;
17338: foreach my $type (@{$titleorder}) {
17339: if (grep(/^\Q$type\E$/,@searchby)) {
17340: if (defined($searchtitles->{$type})) {
17341: $chgtext .= $searchtitles->{$type}.'; ';
17342: }
17343: }
17344: }
17345: $chgtext =~ s/\; $//;
17346: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17347: }
1.25 raeburn 17348: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17349: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17350: my $chgtext;
17351: foreach my $type (@{$srchtypeorder}) {
17352: if (grep(/^\Q$type\E$/,@searchtypes)) {
17353: if (defined($srchtypes_desc->{$type})) {
17354: $chgtext .= $srchtypes_desc->{$type}.'; ';
17355: }
17356: }
17357: }
17358: $chgtext =~ s/\; $//;
1.178 raeburn 17359: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17360: }
17361: $resulttext .= '</ul>';
1.295 raeburn 17362: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17363: if (ref($lastactref) eq 'HASH') {
17364: $lastactref->{'directorysrch'} = 1;
17365: }
1.23 raeburn 17366: } else {
1.277 raeburn 17367: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17368: }
17369: } else {
17370: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17371: &mt('An error occurred: [_1]',$putresult).'</span>';
17372: }
17373: return $resulttext;
17374: }
17375:
1.28 raeburn 17376: sub modify_contacts {
1.205 raeburn 17377: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17378: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17379: if (ref($domconfig{'contacts'}) eq 'HASH') {
17380: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17381: $currsetting{$key} = $domconfig{'contacts'}{$key};
17382: }
17383: }
1.286 raeburn 17384: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17385: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17386: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17387: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17388: my @toggles = ('reporterrors','reportupdates','reportstatus');
17389: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17390: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17391: foreach my $type (@mailings) {
17392: @{$newsetting{$type}} =
17393: &Apache::loncommon::get_env_multiple('form.'.$type);
17394: foreach my $item (@contacts) {
17395: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17396: $contacts_hash{contacts}{$type}{$item} = 1;
17397: } else {
17398: $contacts_hash{contacts}{$type}{$item} = 0;
17399: }
1.289 raeburn 17400: }
1.28 raeburn 17401: $others{$type} = $env{'form.'.$type.'_others'};
17402: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17403: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17404: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17405: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17406: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17407: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17408: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17409: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17410: }
1.134 raeburn 17411: }
1.28 raeburn 17412: }
17413: foreach my $item (@contacts) {
17414: $to{$item} = $env{'form.'.$item};
17415: $contacts_hash{'contacts'}{$item} = $to{$item};
17416: }
1.203 raeburn 17417: foreach my $item (@toggles) {
17418: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17419: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17420: }
17421: }
1.340 raeburn 17422: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17423: foreach my $item (@lonstatus) {
17424: if ($item eq 'excluded') {
17425: my (%serverhomes,@excluded);
17426: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17427: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17428: if (@possexcluded) {
17429: foreach my $id (sort(@possexcluded)) {
17430: if ($serverhomes{$id}) {
17431: push(@excluded,$id);
17432: }
17433: }
17434: }
17435: if (@excluded) {
17436: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17437: }
17438: } elsif ($item eq 'weights') {
1.377 raeburn 17439: foreach my $type ('E','W','N','U') {
1.340 raeburn 17440: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17441: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17442: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17443: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17444: $env{'form.error'.$item.'_'.$type};
17445: }
17446: }
17447: }
17448: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17449: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17450: if ($env{'form.error'.$item} =~ /^\d+$/) {
17451: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17452: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17453: }
17454: }
17455: }
17456: }
1.286 raeburn 17457: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17458: foreach my $field (@{$fields}) {
17459: if (ref($possoptions->{$field}) eq 'ARRAY') {
17460: my $value = $env{'form.helpform_'.$field};
17461: $value =~ s/^\s+|\s+$//g;
17462: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17463: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17464: if ($field eq 'screenshot') {
17465: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17466: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17467: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17468: }
17469: }
17470: }
17471: }
17472: }
17473: }
1.315 raeburn 17474: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17475: my (@statuses,%usertypeshash,@overrides);
17476: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17477: @statuses = @{$types};
17478: if (ref($usertypes) eq 'HASH') {
17479: %usertypeshash = %{$usertypes};
17480: }
17481: }
17482: if (@statuses) {
17483: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17484: foreach my $type (@possoverrides) {
17485: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17486: push(@overrides,$type);
17487: }
17488: }
17489: if (@overrides) {
17490: foreach my $type (@overrides) {
17491: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17492: foreach my $item (@contacts) {
17493: if (grep(/^\Q$item\E$/,@standard)) {
17494: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17495: $newsetting{'override_'.$type}{$item} = 1;
17496: } else {
17497: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17498: $newsetting{'override_'.$type}{$item} = 0;
17499: }
17500: }
17501: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17502: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17503: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17504: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17505: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17506: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17507: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17508: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17509: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17510: }
17511: }
17512: }
17513: }
1.28 raeburn 17514: if (keys(%currsetting) > 0) {
17515: foreach my $item (@contacts) {
17516: if ($to{$item} ne $currsetting{$item}) {
17517: $changes{$item} = 1;
17518: }
17519: }
17520: foreach my $type (@mailings) {
17521: foreach my $item (@contacts) {
17522: if (ref($currsetting{$type}) eq 'HASH') {
17523: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17524: push(@{$changes{$type}},$item);
17525: }
17526: } else {
17527: push(@{$changes{$type}},@{$newsetting{$type}});
17528: }
17529: }
17530: if ($others{$type} ne $currsetting{$type}{'others'}) {
17531: push(@{$changes{$type}},'others');
17532: }
1.289 raeburn 17533: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17534: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17535: push(@{$changes{$type}},'bcc');
17536: }
1.286 raeburn 17537: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17538: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17539: push(@{$changes{$type}},'include');
17540: }
17541: }
17542: }
17543: if (ref($fields) eq 'ARRAY') {
17544: if (ref($currsetting{'helpform'}) eq 'HASH') {
17545: foreach my $field (@{$fields}) {
17546: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17547: push(@{$changes{'helpform'}},$field);
17548: }
17549: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17550: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17551: push(@{$changes{'helpform'}},'maxsize');
17552: }
17553: }
17554: }
17555: } else {
17556: foreach my $field (@{$fields}) {
17557: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17558: push(@{$changes{'helpform'}},$field);
17559: }
17560: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17561: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17562: push(@{$changes{'helpform'}},'maxsize');
17563: }
17564: }
17565: }
1.134 raeburn 17566: }
1.28 raeburn 17567: }
1.315 raeburn 17568: if (@statuses) {
17569: if (ref($currsetting{'overrides'}) eq 'HASH') {
17570: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17571: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17572: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17573: foreach my $item (@contacts,'bcc','others','include') {
17574: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
17575: push(@{$changes{'overrides'}},$key);
17576: last;
17577: }
17578: }
17579: } else {
17580: push(@{$changes{'overrides'}},$key);
17581: }
17582: }
17583: }
17584: foreach my $key (@overrides) {
17585: unless (exists($currsetting{'overrides'}{$key})) {
17586: push(@{$changes{'overrides'}},$key);
17587: }
17588: }
17589: } else {
17590: foreach my $key (@overrides) {
17591: push(@{$changes{'overrides'}},$key);
17592: }
17593: }
17594: }
1.340 raeburn 17595: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17596: foreach my $key ('excluded','weights','threshold','sysmail') {
17597: if ($key eq 'excluded') {
17598: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17599: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17600: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17601: (@{$currsetting{'lonstatus'}{$key}})) {
17602: my @diffs =
17603: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17604: $currsetting{'lonstatus'}{$key});
17605: if (@diffs) {
17606: push(@{$changes{'lonstatus'}},$key);
17607: }
17608: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17609: push(@{$changes{'lonstatus'}},$key);
17610: }
17611: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17612: (@{$currsetting{'lonstatus'}{$key}})) {
17613: push(@{$changes{'lonstatus'}},$key);
17614: }
17615: } elsif ($key eq 'weights') {
17616: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17617: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17618: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17619: foreach my $type ('E','W','N','U') {
1.340 raeburn 17620: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17621: $currsetting{'lonstatus'}{$key}{$type}) {
17622: push(@{$changes{'lonstatus'}},$key);
17623: last;
17624: }
17625: }
17626: } else {
1.341 raeburn 17627: foreach my $type ('E','W','N','U') {
1.340 raeburn 17628: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17629: push(@{$changes{'lonstatus'}},$key);
17630: last;
17631: }
17632: }
17633: }
17634: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17635: foreach my $type ('E','W','N','U') {
1.340 raeburn 17636: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17637: push(@{$changes{'lonstatus'}},$key);
17638: last;
17639: }
17640: }
17641: }
17642: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17643: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17644: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17645: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17646: push(@{$changes{'lonstatus'}},$key);
17647: }
17648: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17649: push(@{$changes{'lonstatus'}},$key);
17650: }
17651: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17652: push(@{$changes{'lonstatus'}},$key);
17653: }
17654: }
17655: }
17656: } else {
17657: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17658: foreach my $key ('excluded','weights','threshold','sysmail') {
17659: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17660: push(@{$changes{'lonstatus'}},$key);
17661: }
17662: }
17663: }
17664: }
1.28 raeburn 17665: } else {
17666: my %default;
17667: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17668: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17669: $default{'errormail'} = 'adminemail';
17670: $default{'packagesmail'} = 'adminemail';
17671: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17672: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17673: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17674: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17675: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17676: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17677: foreach my $item (@contacts) {
17678: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17679: $changes{$item} = 1;
1.203 raeburn 17680: }
1.28 raeburn 17681: }
17682: foreach my $type (@mailings) {
17683: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17684: push(@{$changes{$type}},@{$newsetting{$type}});
17685: }
17686: if ($others{$type} ne '') {
17687: push(@{$changes{$type}},'others');
1.134 raeburn 17688: }
1.286 raeburn 17689: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17690: if ($bcc{$type} ne '') {
17691: push(@{$changes{$type}},'bcc');
17692: }
1.286 raeburn 17693: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17694: push(@{$changes{$type}},'include');
17695: }
1.134 raeburn 17696: }
1.28 raeburn 17697: }
1.286 raeburn 17698: if (ref($fields) eq 'ARRAY') {
17699: foreach my $field (@{$fields}) {
17700: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17701: push(@{$changes{'helpform'}},$field);
17702: }
17703: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17704: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17705: push(@{$changes{'helpform'}},'maxsize');
17706: }
17707: }
17708: }
1.289 raeburn 17709: }
1.340 raeburn 17710: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17711: foreach my $key ('excluded','weights','threshold','sysmail') {
17712: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17713: push(@{$changes{'lonstatus'}},$key);
17714: }
17715: }
17716: }
1.28 raeburn 17717: }
1.203 raeburn 17718: foreach my $item (@toggles) {
17719: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17720: $changes{$item} = 1;
17721: } elsif ((!$env{'form.'.$item}) &&
17722: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17723: $changes{$item} = 1;
17724: }
17725: }
1.28 raeburn 17726: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17727: $dom);
17728: if ($putresult eq 'ok') {
17729: if (keys(%changes) > 0) {
1.205 raeburn 17730: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17731: if (ref($lastactref) eq 'HASH') {
17732: $lastactref->{'domainconfig'} = 1;
17733: }
1.28 raeburn 17734: my ($titles,$short_titles) = &contact_titles();
17735: $resulttext = &mt('Changes made:').'<ul>';
17736: foreach my $item (@contacts) {
17737: if ($changes{$item}) {
17738: $resulttext .= '<li>'.$titles->{$item}.
17739: &mt(' set to: ').
17740: '<span class="LC_cusr_emph">'.
17741: $to{$item}.'</span></li>';
17742: }
17743: }
17744: foreach my $type (@mailings) {
17745: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17746: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17747: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17748: } else {
17749: $resulttext .= '<li>'.$titles->{$type}.': ';
17750: }
1.28 raeburn 17751: my @text;
17752: foreach my $item (@{$newsetting{$type}}) {
17753: push(@text,$short_titles->{$item});
17754: }
17755: if ($others{$type} ne '') {
17756: push(@text,$others{$type});
17757: }
1.286 raeburn 17758: if (@text) {
17759: $resulttext .= '<span class="LC_cusr_emph">'.
17760: join(', ',@text).'</span>';
17761: }
17762: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17763: if ($bcc{$type} ne '') {
1.286 raeburn 17764: my $bcctext;
17765: if (@text) {
1.289 raeburn 17766: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17767: } else {
17768: $bcctext = '(Bcc)';
17769: }
17770: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17771: } elsif (!@text) {
17772: $resulttext .= &mt('No one');
17773: }
1.289 raeburn 17774: if ($includestr{$type} ne '') {
1.286 raeburn 17775: if ($includeloc{$type} eq 'b') {
17776: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17777: } elsif ($includeloc{$type} eq 's') {
17778: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17779: }
1.134 raeburn 17780: }
1.286 raeburn 17781: } elsif (!@text) {
17782: $resulttext .= &mt('No recipients');
1.134 raeburn 17783: }
17784: $resulttext .= '</li>';
1.28 raeburn 17785: }
17786: }
1.315 raeburn 17787: if (ref($changes{'overrides'}) eq 'ARRAY') {
17788: my @deletions;
17789: foreach my $type (@{$changes{'overrides'}}) {
17790: if ($usertypeshash{$type}) {
17791: if (grep(/^\Q$type\E/,@overrides)) {
17792: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17793: $usertypeshash{$type}).'<ul><li>';
17794: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17795: my @text;
17796: foreach my $item (@contacts) {
17797: if ($newsetting{'override_'.$type}{$item}) {
17798: push(@text,$short_titles->{$item});
17799: }
17800: }
17801: if ($newsetting{'override_'.$type}{'others'} ne '') {
17802: push(@text,$newsetting{'override_'.$type}{'others'});
17803: }
17804:
17805: if (@text) {
17806: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17807: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17808: }
17809: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17810: my $bcctext;
17811: if (@text) {
17812: $bcctext = ' '.&mt('with Bcc to');
17813: } else {
17814: $bcctext = '(Bcc)';
17815: }
17816: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17817: } elsif (!@text) {
17818: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17819: }
17820: $resulttext .= '</li>';
17821: if ($newsetting{'override_'.$type}{'include'} ne '') {
17822: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17823: if ($loc eq 'b') {
17824: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17825: } elsif ($loc eq 's') {
17826: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17827: }
17828: }
17829: }
17830: $resulttext .= '</li></ul></li>';
17831: } else {
17832: push(@deletions,$usertypeshash{$type});
17833: }
17834: }
17835: }
17836: if (@deletions) {
17837: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17838: join(', ',@deletions)).'</li>';
17839: }
17840: }
1.203 raeburn 17841: my @offon = ('off','on');
1.340 raeburn 17842: my $corelink = &core_link_msu();
1.203 raeburn 17843: if ($changes{'reporterrors'}) {
17844: $resulttext .= '<li>'.
17845: &mt('E-mail error reports to [_1] set to "'.
17846: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17847: $corelink).
1.203 raeburn 17848: '</li>';
17849: }
17850: if ($changes{'reportupdates'}) {
17851: $resulttext .= '<li>'.
17852: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17853: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17854: $corelink).
1.203 raeburn 17855: '</li>';
17856: }
1.340 raeburn 17857: if ($changes{'reportstatus'}) {
17858: $resulttext .= '<li>'.
17859: &mt('E-mail status if errors above threshold to [_1] set to "'.
17860: $offon[$env{'form.reportstatus'}].'".',
17861: $corelink).
17862: '</li>';
17863: }
17864: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17865: $resulttext .= '<li>'.
17866: &mt('Nightly status check e-mail settings').':<ul>';
17867: my (%defval,%use_def,%shown);
17868: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17869: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17870: $defval{'weights'} =
1.341 raeburn 17871: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17872: $defval{'excluded'} = &mt('None');
17873: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17874: foreach my $item ('threshold','sysmail','weights','excluded') {
17875: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17876: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17877: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17878: } elsif ($item eq 'weights') {
17879: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17880: foreach my $type ('E','W','N','U') {
1.340 raeburn 17881: $shown{$item} .= $lonstatus_names->{$type}.'=';
17882: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17883: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17884: } else {
17885: $shown{$item} .= $lonstatus_defs->{$type};
17886: }
17887: $shown{$item} .= ', ';
17888: }
17889: $shown{$item} =~ s/, $//;
17890: } else {
17891: $shown{$item} = $defval{$item};
17892: }
17893: } elsif ($item eq 'excluded') {
17894: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17895: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17896: } else {
17897: $shown{$item} = $defval{$item};
17898: }
17899: }
17900: } else {
17901: $shown{$item} = $defval{$item};
17902: }
17903: }
17904: } else {
17905: foreach my $item ('threshold','weights','excluded','sysmail') {
17906: $shown{$item} = $defval{$item};
17907: }
17908: }
17909: foreach my $item ('threshold','weights','excluded','sysmail') {
17910: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17911: $shown{$item}).'</li>';
17912: }
17913: $resulttext .= '</ul></li>';
17914: }
1.286 raeburn 17915: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17916: my (@optional,@required,@unused,$maxsizechg);
17917: foreach my $field (@{$changes{'helpform'}}) {
17918: if ($field eq 'maxsize') {
17919: $maxsizechg = 1;
17920: next;
17921: }
17922: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17923: push(@optional,$field);
1.286 raeburn 17924: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17925: push(@unused,$field);
17926: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17927: push(@required,$field);
1.286 raeburn 17928: }
17929: }
17930: if (@optional) {
17931: $resulttext .= '<li>'.
17932: &mt('Help form fields changed to "Optional": [_1].',
17933: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17934: '</li>';
17935: }
17936: if (@required) {
17937: $resulttext .= '<li>'.
17938: &mt('Help form fields changed to "Required": [_1].',
17939: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17940: '</li>';
17941: }
17942: if (@unused) {
17943: $resulttext .= '<li>'.
17944: &mt('Help form fields changed to "Not shown": [_1].',
17945: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17946: '</li>';
17947: }
17948: if ($maxsizechg) {
17949: $resulttext .= '<li>'.
17950: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17951: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17952: '</li>';
17953: }
17954: }
1.28 raeburn 17955: $resulttext .= '</ul>';
17956: } else {
1.288 raeburn 17957: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17958: }
17959: } else {
17960: $resulttext = '<span class="LC_error">'.
17961: &mt('An error occurred: [_1].',$putresult).'</span>';
17962: }
17963: return $resulttext;
17964: }
17965:
1.357 raeburn 17966: sub modify_privacy {
17967: my ($dom,%domconfig) = @_;
17968: my ($resulttext,%current,%changes);
17969: if (ref($domconfig{'privacy'}) eq 'HASH') {
17970: %current = %{$domconfig{'privacy'}};
17971: }
17972: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17973: my @items = ('domain','author','course','community');
17974: my %names = &Apache::lonlocal::texthash (
17975: domain => 'Assigned domain role(s)',
17976: author => 'Assigned co-author role(s)',
17977: course => 'Assigned course role(s)',
1.416 raeburn 17978: community => 'Assigned community role(s)',
1.357 raeburn 17979: );
17980: my %roles = &Apache::lonlocal::texthash (
17981: domain => 'Domain role',
17982: author => 'Co-author role',
17983: course => 'Course role',
17984: community => 'Community role',
17985: );
17986: my %titles = &Apache::lonlocal::texthash (
17987: approval => 'Approval for role in different domain',
17988: othdom => 'User information available in other domain',
17989: priv => 'Information viewable by privileged user in same domain',
17990: unpriv => 'Information viewable by unprivileged user in same domain',
17991: instdom => 'Other domain shares institution/provider',
17992: extdom => 'Other domain has different institution/provider',
17993: none => 'Not allowed',
17994: user => 'User authorizes',
17995: domain => 'Domain Coordinator authorizes',
17996: auto => 'Unrestricted',
1.417 ! raeburn 17997: notify => 'Receive notification of role requests requiring DC authorization',
1.357 raeburn 17998: );
17999: my %fieldnames = &Apache::lonlocal::texthash (
18000: id => 'Student/Employee ID',
18001: permanentemail => 'E-mail address',
18002: lastname => 'Last Name',
18003: firstname => 'First Name',
18004: middlename => 'Middle Name',
18005: generation => 'Generation',
18006: );
18007: my ($othertitle,$usertypes,$types) =
18008: &Apache::loncommon::sorted_inst_types($dom);
18009: my (%by_ip,%by_location,@intdoms,@instdoms);
18010: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18011:
18012: my %privacyhash = (
18013: 'approval' => {
18014: instdom => {},
18015: extdom => {},
18016: },
18017: 'othdom' => {},
18018: 'priv' => {},
18019: 'unpriv' => {},
18020: );
18021: foreach my $item (@items) {
18022: if (@instdoms > 1) {
1.416 raeburn 18023: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 18024: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
18025: }
18026: if (ref($current{'approval'}) eq 'HASH') {
18027: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
18028: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
18029: $changes{'approval'} = 1;
18030: }
18031: }
18032: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
18033: $changes{'approval'} = 1;
18034: }
18035: }
18036: if (keys(%by_location) > 0) {
18037: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
18038: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
18039: }
18040: if (ref($current{'approval'}) eq 'HASH') {
18041: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
18042: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
18043: $changes{'approval'} = 1;
18044: }
18045: }
18046: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
18047: $changes{'approval'} = 1;
18048: }
18049: }
18050: foreach my $status ('priv','unpriv') {
18051: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
18052: my @newvalues;
18053: foreach my $field (@possibles) {
18054: if (grep(/^\Q$field\E$/,@fields)) {
18055: $privacyhash{$status}{$item}{$field} = 1;
18056: push(@newvalues,$field);
18057: }
18058: }
18059: @newvalues = sort(@newvalues);
18060: if (ref($current{$status}) eq 'HASH') {
18061: if (ref($current{$status}{$item}) eq 'HASH') {
18062: my @currvalues = sort(keys(%{$current{$status}{$item}}));
18063: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18064: if (@diffs > 0) {
18065: $changes{$status} = 1;
18066: }
18067: }
18068: } else {
18069: my @stdfields;
18070: foreach my $field (@fields) {
18071: if ($field eq 'id') {
18072: next if ($status eq 'unpriv');
18073: next if (($status eq 'priv') && ($item eq 'community'));
18074: }
18075: push(@stdfields,$field);
18076: }
18077: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18078: if (@diffs > 0) {
18079: $changes{$status} = 1;
18080: }
18081: }
18082: }
18083: }
18084: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
18085: my @statuses;
18086: if (ref($types) eq 'ARRAY') {
18087: @statuses = @{$types};
18088: }
18089: foreach my $type (@statuses,'default') {
18090: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18091: my @newvalues;
18092: foreach my $field (sort(@possfields)) {
18093: if (grep(/^\Q$field\E$/,@fields)) {
18094: $privacyhash{'othdom'}{$type}{$field} = 1;
18095: push(@newvalues,$field);
18096: }
18097: }
18098: @newvalues = sort(@newvalues);
18099: if (ref($current{'othdom'}) eq 'HASH') {
18100: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18101: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18102: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18103: if (@diffs > 0) {
18104: $changes{'othdom'} = 1;
18105: }
18106: }
18107: } else {
18108: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18109: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18110: if (@diffs > 0) {
18111: $changes{'othdom'} = 1;
18112: }
18113: }
18114: }
1.417 ! raeburn 18115: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
! 18116: my %notify;
! 18117: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
! 18118: if (exists($domcoords{$possdc})) {
! 18119: $notify{$possdc} = 1;
! 18120: }
! 18121: }
! 18122: my $notify = join(',',sort(keys(%notify)));
! 18123: if ($current{'notify'} ne $notify) {
! 18124: $changes{'notify'} = 1;
! 18125: }
! 18126: $privacyhash{'notify'} = $notify;
1.357 raeburn 18127: }
18128: my %confighash = (
18129: privacy => \%privacyhash,
18130: );
18131: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18132: if ($putresult eq 'ok') {
18133: if (keys(%changes) > 0) {
18134: $resulttext = &mt('Changes made: ').'<ul>';
1.417 ! raeburn 18135: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18136: if ($changes{$key}) {
18137: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18138: if ($key eq 'approval') {
18139: if (keys(%{$privacyhash{$key}{instdom}})) {
18140: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18141: foreach my $item (@items) {
18142: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18143: }
18144: $resulttext .= '</ul></li>';
18145: }
18146: if (keys(%{$privacyhash{$key}{extdom}})) {
18147: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18148: foreach my $item (@items) {
18149: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18150: }
18151: $resulttext .= '</ul></li>';
18152: }
1.417 ! raeburn 18153: } elsif ($key eq 'notify') {
! 18154: if ($privacyhash{$key}) {
! 18155: foreach my $dc (split(/,/,$privacyhash{$key})) {
! 18156: my ($dcname,$dcdom) = split(/:/,$dc);
! 18157: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
! 18158: }
! 18159: } else {
! 18160: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
! 18161: }
1.357 raeburn 18162: } elsif ($key eq 'othdom') {
18163: my @statuses;
18164: if (ref($types) eq 'ARRAY') {
18165: @statuses = @{$types};
18166: }
18167: if (ref($privacyhash{$key}) eq 'HASH') {
18168: foreach my $status (@statuses,'default') {
18169: if ($status eq 'default') {
18170: $resulttext .= '<li>'.$othertitle.': ';
18171: } elsif (ref($usertypes) eq 'HASH') {
18172: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18173: } else {
18174: next;
18175: }
18176: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18177: if (keys(%{$privacyhash{$key}{$status}})) {
18178: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18179: } else {
18180: $resulttext .= &mt('none');
18181: }
18182: }
18183: $resulttext .= '</li>';
18184: }
18185: }
18186: } else {
18187: foreach my $item (@items) {
18188: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18189: $resulttext .= '<li>'.$names{$item}.': ';
18190: if (keys(%{$privacyhash{$key}{$item}})) {
18191: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18192: } else {
18193: $resulttext .= &mt('none');
18194: }
18195: $resulttext .= '</li>';
18196: }
18197: }
18198: }
18199: $resulttext .= '</ul></li>';
18200: }
18201: }
18202: } else {
18203: $resulttext = &mt('No changes made to user information settings');
18204: }
18205: } else {
18206: $resulttext = '<span class="LC_error">'.
18207: &mt('An error occurred: [_1]',$putresult).'</span>';
18208: }
18209: return $resulttext;
18210: }
18211:
1.354 raeburn 18212: sub modify_passwords {
18213: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18214: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18215: $updatedefaults,$updateconf);
1.354 raeburn 18216: my $customfn = 'resetpw.html';
18217: if (ref($domconfig{'passwords'}) eq 'HASH') {
18218: %current = %{$domconfig{'passwords'}};
18219: }
18220: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18221: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18222: if (ref($types) eq 'ARRAY') {
18223: @oktypes = @{$types};
18224: }
18225: push(@oktypes,'default');
18226:
18227: my %titles = &Apache::lonlocal::texthash (
18228: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18229: intauth_check => 'Check bcrypt cost if authenticated',
18230: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18231: permanent => 'Permanent e-mail address',
18232: critical => 'Critical notification address',
18233: notify => 'Notification address',
18234: min => 'Minimum password length',
18235: max => 'Maximum password length',
18236: chars => 'Required characters',
18237: expire => 'Password expiration (days)',
1.356 raeburn 18238: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18239: reset => 'Resetting Forgotten Password',
18240: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18241: rules => 'Rules for LON-CAPA Passwords',
18242: crsownerchg => 'Course Owner Changing Student Passwords',
18243: username => 'Username',
18244: email => 'E-mail address',
18245: );
18246:
18247: #
18248: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18249: #
18250: my (%curr_defaults,%save_defaults);
18251: if (ref($domconfig{'defaults'}) eq 'HASH') {
18252: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18253: if ($key =~ /^intauth_(cost|check|switch)$/) {
18254: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18255: } else {
18256: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18257: }
18258: }
18259: }
18260: my %staticdefaults = (
18261: 'resetlink' => 2,
18262: 'resetcase' => \@oktypes,
18263: 'resetprelink' => 'both',
18264: 'resetemail' => ['critical','notify','permanent'],
18265: 'intauth_cost' => 10,
18266: 'intauth_check' => 0,
18267: 'intauth_switch' => 0,
18268: );
1.365 raeburn 18269: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18270: foreach my $type (@oktypes) {
18271: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18272: }
18273: my $linklife = $env{'form.passwords_link'};
18274: $linklife =~ s/^\s+|\s+$//g;
18275: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18276: $newvalues{'resetlink'} = $linklife;
18277: if ($current{'resetlink'}) {
18278: if ($current{'resetlink'} ne $linklife) {
18279: $changes{'reset'} = 1;
18280: }
1.368 raeburn 18281: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18282: if ($staticdefaults{'resetlink'} ne $linklife) {
18283: $changes{'reset'} = 1;
18284: }
18285: }
18286: } elsif ($current{'resetlink'}) {
18287: $changes{'reset'} = 1;
18288: }
18289: my @casesens;
18290: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18291: foreach my $case (sort(@posscase)) {
18292: if (grep(/^\Q$case\E$/,@oktypes)) {
18293: push(@casesens,$case);
18294: }
18295: }
18296: $newvalues{'resetcase'} = \@casesens;
18297: if (ref($current{'resetcase'}) eq 'ARRAY') {
18298: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18299: if (@diffs > 0) {
18300: $changes{'reset'} = 1;
18301: }
1.368 raeburn 18302: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18303: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18304: if (@diffs > 0) {
18305: $changes{'reset'} = 1;
18306: }
18307: }
18308: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18309: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18310: if (exists($current{'resetprelink'})) {
18311: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18312: $changes{'reset'} = 1;
18313: }
1.368 raeburn 18314: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18315: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18316: $changes{'reset'} = 1;
18317: }
18318: }
18319: } elsif ($current{'resetprelink'}) {
18320: $changes{'reset'} = 1;
18321: }
18322: foreach my $type (@oktypes) {
18323: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18324: my @postlink;
18325: foreach my $item (sort(@possplink)) {
18326: if ($item =~ /^(email|username)$/) {
18327: push(@postlink,$item);
18328: }
18329: }
18330: $newvalues{'resetpostlink'}{$type} = \@postlink;
18331: unless ($changes{'reset'}) {
18332: if (ref($current{'resetpostlink'}) eq 'HASH') {
18333: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18334: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18335: if (@diffs > 0) {
18336: $changes{'reset'} = 1;
18337: }
18338: } else {
18339: $changes{'reset'} = 1;
18340: }
1.368 raeburn 18341: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18342: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18343: if (@diffs > 0) {
18344: $changes{'reset'} = 1;
18345: }
18346: }
18347: }
18348: }
18349: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18350: my @resetemail;
18351: foreach my $item (sort(@possemailsrc)) {
18352: if ($item =~ /^(permanent|critical|notify)$/) {
18353: push(@resetemail,$item);
18354: }
18355: }
18356: $newvalues{'resetemail'} = \@resetemail;
18357: unless ($changes{'reset'}) {
18358: if (ref($current{'resetemail'}) eq 'ARRAY') {
18359: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18360: if (@diffs > 0) {
18361: $changes{'reset'} = 1;
18362: }
1.368 raeburn 18363: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18364: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18365: if (@diffs > 0) {
18366: $changes{'reset'} = 1;
18367: }
18368: }
18369: }
18370: if ($env{'form.passwords_stdtext'} == 0) {
18371: $newvalues{'resetremove'} = 1;
18372: unless ($current{'resetremove'}) {
18373: $changes{'reset'} = 1;
18374: }
18375: } elsif ($current{'resetremove'}) {
18376: $changes{'reset'} = 1;
18377: }
18378: if ($env{'form.passwords_customfile.filename'} ne '') {
18379: my $servadm = $r->dir_config('lonAdmEMail');
18380: my ($configuserok,$author_ok,$switchserver) =
18381: &config_check($dom,$confname,$servadm);
18382: my $error;
18383: if ($configuserok eq 'ok') {
18384: if ($switchserver) {
18385: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18386: } else {
18387: if ($author_ok eq 'ok') {
18388: my ($result,$customurl) =
18389: &publishlogo($r,'upload','passwords_customfile',$dom,
18390: $confname,'customtext/resetpw','','',$customfn);
18391: if ($result eq 'ok') {
18392: $newvalues{'resetcustom'} = $customurl;
18393: $changes{'reset'} = 1;
18394: } else {
18395: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18396: }
18397: } else {
18398: $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);
18399: }
18400: }
18401: } else {
18402: $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);
18403: }
18404: if ($error) {
18405: &Apache::lonnet::logthis($error);
18406: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18407: }
18408: } elsif ($current{'resetcustom'}) {
18409: if ($env{'form.passwords_custom_del'}) {
18410: $changes{'reset'} = 1;
18411: } else {
18412: $newvalues{'resetcustom'} = $current{'resetcustom'};
18413: }
18414: }
18415: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18416: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18417: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18418: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18419: $changes{'intauth'} = 1;
18420: }
18421: } else {
18422: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18423: }
18424: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18425: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18426: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18427: $changes{'intauth'} = 1;
18428: }
18429: } else {
18430: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18431: }
18432: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18433: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18434: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18435: $changes{'intauth'} = 1;
18436: }
18437: } else {
18438: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18439: }
18440: foreach my $item ('cost','check','switch') {
18441: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18442: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18443: $updatedefaults = 1;
18444: }
18445: }
1.405 raeburn 18446: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18447: my %crsownerchg = (
18448: by => [],
18449: for => [],
18450: );
18451: foreach my $item ('by','for') {
18452: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18453: foreach my $type (sort(@posstypes)) {
18454: if (grep(/^\Q$type\E$/,@oktypes)) {
18455: push(@{$crsownerchg{$item}},$type);
18456: }
18457: }
18458: }
18459: $newvalues{'crsownerchg'} = \%crsownerchg;
18460: if (ref($current{'crsownerchg'}) eq 'HASH') {
18461: foreach my $item ('by','for') {
18462: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18463: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18464: if (@diffs > 0) {
18465: $changes{'crsownerchg'} = 1;
18466: last;
18467: }
18468: }
18469: }
1.368 raeburn 18470: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18471: foreach my $item ('by','for') {
18472: if (@{$crsownerchg{$item}} > 0) {
18473: $changes{'crsownerchg'} = 1;
18474: last;
18475: }
1.354 raeburn 18476: }
18477: }
18478:
18479: my %confighash = (
18480: defaults => \%save_defaults,
18481: passwords => \%newvalues,
18482: );
18483: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18484:
18485: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18486: if ($putresult eq 'ok') {
18487: if (keys(%changes) > 0) {
18488: $resulttext = &mt('Changes made: ').'<ul>';
18489: foreach my $key ('reset','intauth','rules','crsownerchg') {
18490: if ($changes{$key}) {
1.355 raeburn 18491: unless ($key eq 'intauth') {
18492: $updateconf = 1;
18493: }
1.354 raeburn 18494: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18495: if ($key eq 'reset') {
18496: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18497: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18498: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18499: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18500: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18501: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18502: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18503: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18504: }
1.354 raeburn 18505: } else {
18506: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18507: }
18508: if ($confighash{'passwords'}{'resetlink'}) {
18509: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18510: } else {
18511: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18512: &mt('Will default to 2 hours').'</li>';
18513: }
18514: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18515: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18516: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18517: } else {
18518: my $casesens;
18519: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18520: if ($type eq 'default') {
18521: $casesens .= $othertitle.', ';
18522: } elsif ($usertypes->{$type} ne '') {
18523: $casesens .= $usertypes->{$type}.', ';
18524: }
18525: }
18526: $casesens =~ s/\Q, \E$//;
18527: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18528: }
18529: } else {
18530: $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>';
18531: }
18532: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18533: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18534: } else {
18535: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18536: }
18537: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18538: my $output;
18539: if (ref($types) eq 'ARRAY') {
18540: foreach my $type (@{$types}) {
18541: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18542: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18543: $output .= $usertypes->{$type}.' -- '.&mt('none');
18544: } else {
18545: $output .= $usertypes->{$type}.' -- '.
18546: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18547: }
18548: }
18549: }
18550: }
18551: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18552: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18553: $output .= $othertitle.' -- '.&mt('none');
18554: } else {
18555: $output .= $othertitle.' -- '.
18556: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18557: }
18558: }
18559: if ($output) {
18560: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18561: } else {
18562: $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>';
18563: }
18564: } else {
18565: $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>';
18566: }
18567: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18568: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18569: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18570: } else {
18571: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18572: }
18573: } else {
1.379 raeburn 18574: $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 18575: }
18576: if ($confighash{'passwords'}{'resetremove'}) {
18577: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18578: } else {
18579: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18580: }
18581: if ($confighash{'passwords'}{'resetcustom'}) {
18582: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18583: &mt('custom text'),600,500,undef,undef,
18584: undef,undef,'background-color:#ffffff');
18585: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18586: } else {
18587: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18588: }
18589: } elsif ($key eq 'intauth') {
18590: foreach my $item ('cost','switch','check') {
18591: my $value = $save_defaults{$key.'_'.$item};
18592: if ($item eq 'switch') {
18593: my %optiondesc = &Apache::lonlocal::texthash (
18594: 0 => 'No',
18595: 1 => 'Yes',
18596: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18597: );
18598: if ($value =~ /^(0|1|2)$/) {
18599: $value = $optiondesc{$value};
18600: } else {
18601: $value = &mt('none -- defaults to No');
18602: }
18603: } elsif ($item eq 'check') {
18604: my %optiondesc = &Apache::lonlocal::texthash (
18605: 0 => 'No',
18606: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18607: 2 => 'Yes, disallow login if stored cost is less than domain default',
18608: );
18609: if ($value =~ /^(0|1|2)$/) {
18610: $value = $optiondesc{$value};
18611: } else {
18612: $value = &mt('none -- defaults to No');
18613: }
18614: }
18615: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18616: }
18617: } elsif ($key eq 'rules') {
1.356 raeburn 18618: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18619: if ($confighash{'passwords'}{$rule} eq '') {
18620: if ($rule eq 'min') {
1.356 raeburn 18621: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18622: ' '.&mt('Default of [_1] will be used',
18623: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18624: } else {
18625: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18626: }
18627: } else {
18628: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18629: }
18630: }
1.370 raeburn 18631: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18632: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18633: my %rulenames = &Apache::lonlocal::texthash(
18634: uc => 'At least one upper case letter',
18635: lc => 'At least one lower case letter',
18636: num => 'At least one number',
18637: spec => 'At least one non-alphanumeric',
18638: );
18639: my $needed = '<ul><li>'.
18640: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
18641: '</li></ul>';
18642: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18643: } else {
18644: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18645: }
18646: } else {
18647: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18648: }
1.354 raeburn 18649: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18650: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18651: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18652: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18653: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18654: } else {
18655: my %crsownerstr;
18656: foreach my $item ('by','for') {
18657: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18658: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18659: if ($type eq 'default') {
18660: $crsownerstr{$item} .= $othertitle.', ';
18661: } elsif ($usertypes->{$type} ne '') {
18662: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18663: }
18664: }
18665: $crsownerstr{$item} =~ s/\Q, \E$//;
18666: }
18667: }
18668: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18669: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18670: }
1.354 raeburn 18671: } else {
1.359 raeburn 18672: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18673: }
18674: }
18675: $resulttext .= '</ul></li>';
18676: }
18677: }
18678: $resulttext .= '</ul>';
18679: } else {
18680: $resulttext = &mt('No changes made to password settings');
18681: }
1.355 raeburn 18682: my $cachetime = 24*60*60;
1.354 raeburn 18683: if ($updatedefaults) {
18684: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18685: if (ref($lastactref) eq 'HASH') {
18686: $lastactref->{'domdefaults'} = 1;
18687: }
18688: }
1.355 raeburn 18689: if ($updateconf) {
18690: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18691: if (ref($lastactref) eq 'HASH') {
18692: $lastactref->{'passwdconf'} = 1;
18693: }
18694: }
1.354 raeburn 18695: } else {
18696: $resulttext = '<span class="LC_error">'.
18697: &mt('An error occurred: [_1]',$putresult).'</span>';
18698: }
18699: if ($errors) {
18700: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18701: $errors.'</ul></p>';
18702: }
18703: return $resulttext;
18704: }
18705:
1.405 raeburn 18706: sub password_rule_changes {
18707: my ($prefix,$newvalues,$current,$changes) = @_;
18708: return unless ((ref($newvalues) eq 'HASH') &&
18709: (ref($current) eq 'HASH') &&
18710: (ref($changes) eq 'HASH'));
18711: my (@rules,%staticdefaults);
18712: if ($prefix eq 'passwords') {
18713: @rules = ('min','max','expire','numsaved');
18714: } elsif ($prefix eq 'secrets') {
18715: @rules = ('min','max');
18716: }
18717: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18718: foreach my $rule (@rules) {
18719: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18720: my $ruleok;
18721: if ($rule eq 'expire') {
18722: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18723: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18724: $ruleok = 1;
18725: }
18726: } elsif ($rule eq 'min') {
18727: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18728: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18729: $ruleok = 1;
18730: }
18731: }
18732: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18733: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18734: $ruleok = 1;
18735: }
18736: if ($ruleok) {
18737: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18738: if (exists($current->{$rule})) {
18739: if ($newvalues->{$rule} ne $current->{$rule}) {
18740: $changes->{'rules'} = 1;
18741: }
18742: } elsif ($rule eq 'min') {
18743: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18744: $changes->{'rules'} = 1;
18745: }
18746: } else {
18747: $changes->{'rules'} = 1;
18748: }
18749: } elsif (exists($current->{$rule})) {
18750: $changes->{'rules'} = 1;
18751: }
18752: }
18753: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18754: my @chars;
18755: foreach my $item (sort(@posschars)) {
18756: if ($item =~ /^(uc|lc|num|spec)$/) {
18757: push(@chars,$item);
18758: }
18759: }
18760: $newvalues->{'chars'} = \@chars;
18761: unless ($changes->{'rules'}) {
18762: if (ref($current->{'chars'}) eq 'ARRAY') {
18763: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18764: if (@diffs > 0) {
18765: $changes->{'rules'} = 1;
18766: }
18767: } else {
18768: if (@chars > 0) {
18769: $changes->{'rules'} = 1;
18770: }
18771: }
18772: }
18773: return;
18774: }
18775:
1.28 raeburn 18776: sub modify_usercreation {
1.27 raeburn 18777: my ($dom,%domconfig) = @_;
1.224 raeburn 18778: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18779: my $warningmsg;
1.27 raeburn 18780: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18781: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18782: if ($key eq 'cancreate') {
18783: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18784: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18785: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18786: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18787: } else {
1.224 raeburn 18788: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18789: }
18790: }
18791: }
18792: } elsif ($key eq 'email_rule') {
18793: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18794: } else {
18795: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18796: }
1.27 raeburn 18797: }
18798: }
18799: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18800: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18801: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18802: foreach my $item(@contexts) {
1.224 raeburn 18803: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18804: }
1.34 raeburn 18805: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18806: foreach my $item (@contexts) {
1.224 raeburn 18807: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18808: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18809: }
1.27 raeburn 18810: }
1.34 raeburn 18811: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18812: foreach my $item (@contexts) {
1.43 raeburn 18813: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18814: if ($cancreate{$item} ne 'any') {
18815: push(@{$changes{'cancreate'}},$item);
18816: }
18817: } else {
18818: if ($cancreate{$item} ne 'none') {
18819: push(@{$changes{'cancreate'}},$item);
18820: }
1.27 raeburn 18821: }
18822: }
18823: } else {
1.43 raeburn 18824: foreach my $item (@contexts) {
1.34 raeburn 18825: push(@{$changes{'cancreate'}},$item);
18826: }
1.27 raeburn 18827: }
1.34 raeburn 18828:
1.27 raeburn 18829: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18830: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18831: if (!grep(/^\Q$type\E$/,@username_rule)) {
18832: push(@{$changes{'username_rule'}},$type);
18833: }
18834: }
18835: foreach my $type (@username_rule) {
18836: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18837: push(@{$changes{'username_rule'}},$type);
18838: }
18839: }
18840: } else {
18841: push(@{$changes{'username_rule'}},@username_rule);
18842: }
18843:
1.32 raeburn 18844: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18845: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18846: if (!grep(/^\Q$type\E$/,@id_rule)) {
18847: push(@{$changes{'id_rule'}},$type);
18848: }
18849: }
18850: foreach my $type (@id_rule) {
18851: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18852: push(@{$changes{'id_rule'}},$type);
18853: }
18854: }
18855: } else {
18856: push(@{$changes{'id_rule'}},@id_rule);
18857: }
18858:
1.43 raeburn 18859: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18860: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18861: my %authhash;
1.43 raeburn 18862: foreach my $item (@authen_contexts) {
1.28 raeburn 18863: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18864: foreach my $auth (@authtypes) {
18865: if (grep(/^\Q$auth\E$/,@authallowed)) {
18866: $authhash{$item}{$auth} = 1;
18867: } else {
18868: $authhash{$item}{$auth} = 0;
18869: }
18870: }
18871: }
18872: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18873: foreach my $item (@authen_contexts) {
1.28 raeburn 18874: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18875: foreach my $auth (@authtypes) {
18876: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18877: push(@{$changes{'authtypes'}},$item);
18878: last;
18879: }
18880: }
18881: }
18882: }
18883: } else {
1.43 raeburn 18884: foreach my $item (@authen_contexts) {
1.28 raeburn 18885: push(@{$changes{'authtypes'}},$item);
18886: }
18887: }
18888:
1.224 raeburn 18889: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18890: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18891: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18892: $save_usercreate{'id_rule'} = \@id_rule;
18893: $save_usercreate{'username_rule'} = \@username_rule,
18894: $save_usercreate{'authtypes'} = \%authhash;
18895:
1.27 raeburn 18896: my %usercreation_hash = (
1.224 raeburn 18897: usercreation => \%save_usercreate,
18898: );
1.27 raeburn 18899:
18900: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18901: $dom);
1.50 raeburn 18902:
1.224 raeburn 18903: if ($putresult eq 'ok') {
18904: if (keys(%changes) > 0) {
18905: $resulttext = &mt('Changes made:').'<ul>';
18906: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18907: my %lt = &usercreation_types();
18908: foreach my $type (@{$changes{'cancreate'}}) {
18909: my $chgtext = $lt{$type}.', ';
18910: if ($cancreate{$type} eq 'none') {
18911: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18912: } elsif ($cancreate{$type} eq 'any') {
18913: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18914: } elsif ($cancreate{$type} eq 'official') {
18915: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18916: } elsif ($cancreate{$type} eq 'unofficial') {
18917: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18918: }
18919: $resulttext .= '<li>'.$chgtext.'</li>';
18920: }
18921: }
18922: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18923: my ($rules,$ruleorder) =
18924: &Apache::lonnet::inst_userrules($dom,'username');
18925: my $chgtext = '<ul>';
18926: foreach my $type (@username_rule) {
18927: if (ref($rules->{$type}) eq 'HASH') {
18928: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18929: }
18930: }
18931: $chgtext .= '</ul>';
18932: if (@username_rule > 0) {
18933: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18934: } else {
18935: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18936: }
18937: }
18938: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18939: my ($idrules,$idruleorder) =
18940: &Apache::lonnet::inst_userrules($dom,'id');
18941: my $chgtext = '<ul>';
18942: foreach my $type (@id_rule) {
18943: if (ref($idrules->{$type}) eq 'HASH') {
18944: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18945: }
18946: }
18947: $chgtext .= '</ul>';
18948: if (@id_rule > 0) {
18949: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18950: } else {
18951: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18952: }
18953: }
18954: my %authname = &authtype_names();
18955: my %context_title = &context_names();
18956: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18957: my $chgtext = '<ul>';
18958: foreach my $type (@{$changes{'authtypes'}}) {
18959: my @allowed;
18960: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18961: foreach my $auth (@authtypes) {
18962: if ($authhash{$type}{$auth}) {
18963: push(@allowed,$authname{$auth});
18964: }
18965: }
18966: if (@allowed > 0) {
18967: $chgtext .= join(', ',@allowed).'</li>';
18968: } else {
18969: $chgtext .= &mt('none').'</li>';
18970: }
18971: }
18972: $chgtext .= '</ul>';
18973: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18974: $resulttext .= '</li>';
18975: }
18976: $resulttext .= '</ul>';
18977: } else {
18978: $resulttext = &mt('No changes made to user creation settings');
18979: }
18980: } else {
18981: $resulttext = '<span class="LC_error">'.
18982: &mt('An error occurred: [_1]',$putresult).'</span>';
18983: }
18984: if ($warningmsg ne '') {
18985: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18986: }
18987: return $resulttext;
18988: }
18989:
18990: sub modify_selfcreation {
1.305 raeburn 18991: my ($dom,$lastactref,%domconfig) = @_;
18992: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18993: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18994: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18995: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18996: if (ref($typesref) eq 'ARRAY') {
18997: @types = @{$typesref};
18998: }
18999: if (ref($usertypesref) eq 'HASH') {
19000: %usertypes = %{$usertypesref};
1.228 raeburn 19001: }
1.303 raeburn 19002: $usertypes{'default'} = $othertitle;
1.224 raeburn 19003: #
19004: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
19005: #
19006: if (ref($domconfig{'usercreation'}) eq 'HASH') {
19007: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
19008: if ($key eq 'cancreate') {
19009: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
19010: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
19011: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 19012: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
19013: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
19014: ($item eq 'emailusername') || ($item eq 'shibenv') ||
19015: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 19016: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 19017: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
19018: } else {
19019: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
19020: }
19021: }
19022: }
19023: } elsif ($key eq 'email_rule') {
19024: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
19025: } else {
19026: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
19027: }
19028: }
19029: }
19030: #
19031: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
19032: #
19033: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19034: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
19035: if ($key eq 'selfcreate') {
19036: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
19037: } else {
19038: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
19039: }
19040: }
19041: }
1.305 raeburn 19042: #
19043: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
19044: #
19045: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19046: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
19047: if ($key eq 'inststatusguest') {
19048: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
19049: } else {
19050: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
19051: }
19052: }
19053: }
1.224 raeburn 19054:
19055: my @contexts = ('selfcreate');
19056: @{$cancreate{'selfcreate'}} = ();
19057: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 19058: if (@types) {
19059: @{$cancreate{'statustocreate'}} = ();
19060: }
1.236 raeburn 19061: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 19062: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 19063: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19064: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19065: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19066: my %selfcreatetypes = (
19067: sso => 'users authenticated by institutional single sign on',
19068: login => 'users authenticated by institutional log-in',
1.303 raeburn 19069: email => 'users verified by e-mail',
1.50 raeburn 19070: );
1.224 raeburn 19071: #
19072: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19073: # is permitted.
19074: #
1.305 raeburn 19075: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19076:
1.305 raeburn 19077: my (@statuses,%email_rule);
1.228 raeburn 19078: foreach my $item ('login','sso','email') {
1.224 raeburn 19079: if ($item eq 'email') {
1.236 raeburn 19080: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19081: if (@types) {
19082: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19083: foreach my $status (@poss_statuses) {
19084: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19085: push(@statuses,$status);
19086: }
19087: }
19088: $save_inststatus{'inststatusguest'} = \@statuses;
19089: } else {
19090: push(@statuses,'default');
19091: }
19092: if (@statuses) {
19093: my %curr_rule;
19094: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19095: foreach my $type (@statuses) {
19096: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19097: }
1.305 raeburn 19098: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19099: foreach my $type (@statuses) {
19100: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19101: }
19102: }
19103: push(@{$cancreate{'selfcreate'}},'email');
19104: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19105: my %curremaildom;
19106: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19107: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19108: }
19109: foreach my $type (@statuses) {
19110: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19111: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19112: }
19113: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19114: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19115: }
19116: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19117: #
19118: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19119: #
19120: my $chosen = $1;
19121: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19122: my $emaildom;
19123: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
19124: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
19125: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19126: if (ref($curremaildom{$type}) eq 'HASH') {
19127: if (exists($curremaildom{$type}{$chosen})) {
19128: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19129: push(@{$changes{'cancreate'}},'emaildomain');
19130: }
19131: } elsif ($emaildom ne '') {
19132: push(@{$changes{'cancreate'}},'emaildomain');
19133: }
19134: } elsif ($emaildom ne '') {
19135: push(@{$changes{'cancreate'}},'emaildomain');
19136: }
19137: }
19138: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19139: } elsif ($chosen eq 'custom') {
19140: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19141: $email_rule{$type} = [];
19142: if (ref($emailrules) eq 'HASH') {
19143: foreach my $rule (@possemail_rules) {
19144: if (exists($emailrules->{$rule})) {
19145: push(@{$email_rule{$type}},$rule);
19146: }
19147: }
19148: }
19149: if (@{$email_rule{$type}}) {
19150: $cancreate{'emailoptions'}{$type} = 'custom';
19151: if (ref($curr_rule{$type}) eq 'ARRAY') {
19152: if (@{$curr_rule{$type}} > 0) {
19153: foreach my $rule (@{$curr_rule{$type}}) {
19154: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19155: push(@{$changes{'email_rule'}},$type);
19156: }
19157: }
19158: }
19159: foreach my $type (@{$email_rule{$type}}) {
19160: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19161: push(@{$changes{'email_rule'}},$type);
19162: }
19163: }
19164: } else {
19165: push(@{$changes{'email_rule'}},$type);
19166: }
19167: }
19168: } else {
19169: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19170: }
19171: }
19172: }
19173: if (@types) {
19174: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19175: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19176: if (@changed) {
19177: push(@{$changes{'inststatus'}},'inststatusguest');
19178: }
19179: } else {
19180: push(@{$changes{'inststatus'}},'inststatusguest');
19181: }
19182: }
19183: } else {
19184: delete($env{'form.cancreate_email'});
19185: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19186: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19187: push(@{$changes{'inststatus'}},'inststatusguest');
19188: }
19189: }
19190: }
19191: } else {
19192: $save_inststatus{'inststatusguest'} = [];
19193: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19194: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19195: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19196: }
19197: }
1.224 raeburn 19198: }
19199: } else {
19200: if ($env{'form.cancreate_'.$item}) {
19201: push(@{$cancreate{'selfcreate'}},$item);
19202: }
19203: }
19204: }
1.305 raeburn 19205: my (%userinfo,%savecaptcha);
1.224 raeburn 19206: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19207: #
1.228 raeburn 19208: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19209: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19210: #
1.236 raeburn 19211:
1.244 raeburn 19212: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19213: push(@contexts,'emailusername');
1.305 raeburn 19214: if (@statuses) {
19215: foreach my $type (@statuses) {
1.228 raeburn 19216: if (ref($infofields) eq 'ARRAY') {
19217: foreach my $field (@{$infofields}) {
19218: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19219: $cancreate{'emailusername'}{$type}{$field} = $1;
19220: }
19221: }
1.224 raeburn 19222: }
19223: }
19224: }
19225: #
19226: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19227: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19228: #
19229:
19230: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19231: @approvalnotify = sort(@approvalnotify);
19232: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19233: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19234: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19235: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19236: push(@{$changes{'cancreate'}},'notify');
19237: }
19238: } else {
19239: if ($cancreate{'notify'}{'approval'}) {
19240: push(@{$changes{'cancreate'}},'notify');
19241: }
19242: }
19243: } elsif ($cancreate{'notify'}{'approval'}) {
19244: push(@{$changes{'cancreate'}},'notify');
19245: }
19246:
19247: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19248: }
19249: #
1.236 raeburn 19250: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19251: # institutional log-in.
19252: #
19253: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19254: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19255: ($domdefaults{'auth_def'} eq 'localauth'))) {
19256: $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.').' '.
19257: &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.');
19258: }
19259: }
19260: my @fields = ('lastname','firstname','middlename','generation',
19261: 'permanentemail','id');
1.240 raeburn 19262: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19263: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19264: #
19265: # Where usernames may created for institutional log-in and/or institutional single sign on:
19266: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19267: # may self-create accounts
19268: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19269: # which the user may supply, if institutional data is unavailable.
19270: #
19271: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19272: if (@types) {
1.305 raeburn 19273: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19274: push(@contexts,'statustocreate');
1.303 raeburn 19275: foreach my $type (@types) {
1.224 raeburn 19276: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19277: foreach my $field (@fields) {
19278: if (grep(/^\Q$field\E$/,@modifiable)) {
19279: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19280: } else {
19281: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19282: }
19283: }
19284: }
19285: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19286: foreach my $type (@types) {
1.224 raeburn 19287: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19288: foreach my $field (@fields) {
19289: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19290: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19291: push(@{$changes{'selfcreate'}},$type);
19292: last;
19293: }
19294: }
19295: }
19296: }
19297: } else {
1.303 raeburn 19298: foreach my $type (@types) {
1.224 raeburn 19299: push(@{$changes{'selfcreate'}},$type);
19300: }
19301: }
19302: }
1.240 raeburn 19303: foreach my $field (@shibfields) {
19304: if ($env{'form.shibenv_'.$field} ne '') {
19305: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19306: }
19307: }
19308: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19309: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19310: foreach my $field (@shibfields) {
19311: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19312: push(@{$changes{'cancreate'}},'shibenv');
19313: }
19314: }
19315: } else {
19316: foreach my $field (@shibfields) {
19317: if ($env{'form.shibenv_'.$field}) {
19318: push(@{$changes{'cancreate'}},'shibenv');
19319: last;
19320: }
19321: }
19322: }
19323: }
1.224 raeburn 19324: }
19325: foreach my $item (@contexts) {
19326: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19327: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19328: if (ref($cancreate{$item}) eq 'ARRAY') {
19329: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19330: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19331: push(@{$changes{'cancreate'}},$item);
19332: }
19333: }
19334: }
19335: }
19336: if (ref($cancreate{$item}) eq 'ARRAY') {
19337: foreach my $type (@{$cancreate{$item}}) {
19338: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19339: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19340: push(@{$changes{'cancreate'}},$item);
19341: }
19342: }
19343: }
19344: }
19345: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19346: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19347: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19348: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19349: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19350: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19351: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19352: push(@{$changes{'cancreate'}},$item);
19353: }
19354: }
19355: }
1.305 raeburn 19356: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19357: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19358: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19359: push(@{$changes{'cancreate'}},$item);
19360: }
1.224 raeburn 19361: }
19362: }
19363: }
1.305 raeburn 19364: foreach my $type (keys(%{$cancreate{$item}})) {
19365: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19366: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19367: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19368: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19369: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19370: push(@{$changes{'cancreate'}},$item);
19371: }
19372: }
19373: } else {
19374: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19375: push(@{$changes{'cancreate'}},$item);
19376: }
19377: }
19378: }
1.305 raeburn 19379: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19380: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19381: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19382: push(@{$changes{'cancreate'}},$item);
19383: }
1.224 raeburn 19384: }
19385: }
19386: }
19387: }
19388: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19389: if (ref($cancreate{$item}) eq 'ARRAY') {
19390: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19391: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19392: push(@{$changes{'cancreate'}},$item);
19393: }
19394: }
1.305 raeburn 19395: }
19396: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19397: if (ref($cancreate{$item}) eq 'HASH') {
19398: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19399: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19400: }
19401: }
19402: } elsif ($item eq 'emailusername') {
1.228 raeburn 19403: if (ref($cancreate{$item}) eq 'HASH') {
19404: foreach my $type (keys(%{$cancreate{$item}})) {
19405: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19406: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19407: if ($cancreate{$item}{$type}{$field}) {
19408: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19409: push(@{$changes{'cancreate'}},$item);
19410: }
19411: last;
19412: }
19413: }
19414: }
19415: }
1.224 raeburn 19416: }
19417: }
19418: }
19419: #
19420: # Populate %save_usercreate hash with updates to self-creation configuration.
19421: #
19422: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19423: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19424: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19425: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19426: if (ref($cancreate{'notify'}) eq 'HASH') {
19427: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19428: }
1.236 raeburn 19429: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19430: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19431: }
1.303 raeburn 19432: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19433: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19434: }
1.305 raeburn 19435: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19436: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19437: }
1.303 raeburn 19438: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19439: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19440: }
1.224 raeburn 19441: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19442: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19443: }
1.240 raeburn 19444: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19445: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19446: }
1.224 raeburn 19447: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19448: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19449:
19450: my %userconfig_hash = (
19451: usercreation => \%save_usercreate,
19452: usermodification => \%save_usermodify,
1.305 raeburn 19453: inststatus => \%save_inststatus,
1.224 raeburn 19454: );
1.305 raeburn 19455:
1.224 raeburn 19456: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19457: $dom);
19458: #
1.305 raeburn 19459: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19460: #
1.27 raeburn 19461: if ($putresult eq 'ok') {
19462: if (keys(%changes) > 0) {
19463: $resulttext = &mt('Changes made:').'<ul>';
19464: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19465: my %lt = &selfcreation_types();
1.34 raeburn 19466: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19467: my $chgtext = '';
1.45 raeburn 19468: if ($type eq 'selfcreate') {
1.50 raeburn 19469: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19470: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19471: } else {
1.224 raeburn 19472: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19473: '<ul>';
1.50 raeburn 19474: foreach my $case (@{$cancreate{$type}}) {
19475: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19476: }
19477: $chgtext .= '</ul>';
1.100 raeburn 19478: if (ref($cancreate{$type}) eq 'ARRAY') {
19479: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19480: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19481: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19482: $chgtext .= '<span class="LC_warning">'.
19483: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19484: '</span><br />';
19485: }
19486: }
19487: }
19488: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19489: if (!@statuses) {
19490: $chgtext .= '<span class="LC_warning">'.
19491: &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.").
19492: '</span><br />';
1.303 raeburn 19493:
1.100 raeburn 19494: }
19495: }
19496: }
1.43 raeburn 19497: }
1.240 raeburn 19498: } elsif ($type eq 'shibenv') {
19499: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19500: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19501: } else {
19502: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19503: '<ul>';
19504: foreach my $field (@shibfields) {
19505: next if ($cancreate{$type}{$field} eq '');
19506: if ($field eq 'inststatus') {
19507: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19508: } else {
19509: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19510: }
19511: }
19512: $chgtext .= '</ul>';
1.303 raeburn 19513: }
1.93 raeburn 19514: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19515: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19516: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19517: if (@{$cancreate{'selfcreate'}} > 0) {
19518: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19519: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19520: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19521: $chgtext .= '<br />'.
19522: '<span class="LC_warning">'.
19523: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19524: '</span>';
19525: }
1.303 raeburn 19526: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19527: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19528: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19529: } else {
19530: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19531: }
19532: $chgtext .= '<ul>';
19533: foreach my $case (@{$cancreate{$type}}) {
19534: if ($case eq 'default') {
19535: $chgtext .= '<li>'.$othertitle.'</li>';
19536: } else {
1.303 raeburn 19537: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19538: }
19539: }
1.100 raeburn 19540: $chgtext .= '</ul>';
19541: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19542: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19543: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19544: '</span>';
1.100 raeburn 19545: }
19546: }
19547: } else {
19548: if (@{$cancreate{$type}} == 0) {
19549: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19550: } else {
19551: $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 19552: }
19553: }
1.303 raeburn 19554: $chgtext .= '<br />';
1.93 raeburn 19555: }
1.236 raeburn 19556: } elsif ($type eq 'selfcreateprocessing') {
19557: my %choices = &Apache::lonlocal::texthash (
19558: automatic => 'Automatic approval',
19559: approval => 'Queued for approval',
19560: );
1.305 raeburn 19561: if (@types) {
19562: if (@statuses) {
1.303 raeburn 19563: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19564: '<ul>';
1.305 raeburn 19565: foreach my $status (@statuses) {
19566: if ($status eq 'default') {
19567: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19568: } else {
1.305 raeburn 19569: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19570: }
19571: }
19572: $chgtext .= '</ul>';
19573: }
19574: } else {
19575: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19576: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19577: }
19578: } elsif ($type eq 'emailverified') {
19579: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19580: all => 'Same as e-mail',
19581: first => 'Omit @domain',
19582: free => 'Free to choose',
1.303 raeburn 19583: );
1.305 raeburn 19584: if (@types) {
19585: if (@statuses) {
1.303 raeburn 19586: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19587: '<ul>';
1.305 raeburn 19588: foreach my $status (@statuses) {
1.362 raeburn 19589: if ($status eq 'default') {
1.305 raeburn 19590: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19591: } else {
1.305 raeburn 19592: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19593: }
19594: }
19595: $chgtext .= '</ul>';
19596: }
19597: } else {
1.305 raeburn 19598: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19599: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19600: }
1.305 raeburn 19601: } elsif ($type eq 'emailoptions') {
19602: my %options = &Apache::lonlocal::texthash (
19603: any => 'Any e-mail',
19604: inst => 'Institutional only',
19605: noninst => 'Non-institutional only',
19606: custom => 'Custom restrictions',
19607: );
19608: if (@types) {
19609: if (@statuses) {
19610: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19611: '<ul>';
19612: foreach my $status (@statuses) {
19613: if ($type eq 'default') {
19614: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19615: } else {
19616: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19617: }
19618: }
1.305 raeburn 19619: $chgtext .= '</ul>';
19620: }
19621: } else {
19622: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19623: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19624: } else {
19625: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19626: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19627: }
1.305 raeburn 19628: }
19629: } elsif ($type eq 'emaildomain') {
19630: my $output;
19631: if (@statuses) {
19632: foreach my $type (@statuses) {
19633: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19634: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19635: if ($type eq 'default') {
19636: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19637: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19638: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19639: } else {
19640: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19641: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19642: }
1.303 raeburn 19643: } else {
1.305 raeburn 19644: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19645: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19646: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19647: } else {
19648: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
19649: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19650: }
1.303 raeburn 19651: }
1.305 raeburn 19652: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19653: if ($type eq 'default') {
19654: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19655: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19656: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19657: } else {
19658: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19659: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19660: }
1.303 raeburn 19661: } else {
1.305 raeburn 19662: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19663: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19664: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19665: } else {
19666: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
19667: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19668: }
1.303 raeburn 19669: }
19670: }
19671: }
19672: }
1.305 raeburn 19673: }
19674: if ($output ne '') {
19675: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19676: '<ul>'.$output.'</ul>';
1.236 raeburn 19677: }
1.165 raeburn 19678: } elsif ($type eq 'captcha') {
1.224 raeburn 19679: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19680: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19681: } else {
19682: my %captchas = &captcha_phrases();
1.224 raeburn 19683: if ($captchas{$savecaptcha{$type}}) {
19684: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19685: } else {
1.210 raeburn 19686: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19687: }
19688: }
19689: } elsif ($type eq 'recaptchakeys') {
19690: my ($privkey,$pubkey);
1.224 raeburn 19691: if (ref($savecaptcha{$type}) eq 'HASH') {
19692: $pubkey = $savecaptcha{$type}{'public'};
19693: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19694: }
19695: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19696: if (!$pubkey) {
19697: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19698: } else {
19699: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19700: }
19701: if (!$privkey) {
19702: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19703: } else {
19704: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19705: }
19706: $chgtext .= '</ul>';
1.269 raeburn 19707: } elsif ($type eq 'recaptchaversion') {
19708: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19709: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19710: }
1.224 raeburn 19711: } elsif ($type eq 'emailusername') {
19712: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19713: if (@statuses) {
19714: foreach my $type (@statuses) {
1.228 raeburn 19715: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19716: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19717: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19718: '<ul>';
19719: foreach my $field (@{$infofields}) {
19720: if ($cancreate{'emailusername'}{$type}{$field}) {
19721: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19722: }
19723: }
1.245 raeburn 19724: $chgtext .= '</ul>';
19725: } else {
1.303 raeburn 19726: $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 19727: }
19728: } else {
1.303 raeburn 19729: $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 19730: }
19731: }
19732: }
19733: }
19734: } elsif ($type eq 'notify') {
1.303 raeburn 19735: my $numapprove = 0;
1.224 raeburn 19736: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19737: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19738: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19739: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19740: $numapprove ++;
1.224 raeburn 19741: }
19742: }
1.43 raeburn 19743: }
1.303 raeburn 19744: unless ($numapprove) {
19745: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19746: }
1.34 raeburn 19747: }
1.224 raeburn 19748: if ($chgtext) {
19749: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19750: }
19751: }
19752: }
1.305 raeburn 19753: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19754: my ($emailrules,$emailruleorder) =
19755: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19756: foreach my $type (@{$changes{'email_rule'}}) {
19757: if (ref($email_rule{$type}) eq 'ARRAY') {
19758: my $chgtext = '<ul>';
19759: foreach my $rule (@{$email_rule{$type}}) {
19760: if (ref($emailrules->{$rule}) eq 'HASH') {
19761: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19762: }
19763: }
19764: $chgtext .= '</ul>';
1.310 raeburn 19765: my $typename;
1.305 raeburn 19766: if (@types) {
19767: if ($type eq 'default') {
19768: $typename = $othertitle;
19769: } else {
19770: $typename = $usertypes{$type};
19771: }
19772: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19773: }
19774: if (@{$email_rule{$type}} > 0) {
19775: $resulttext .= '<li>'.
19776: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19777: $usertypes{$type}).
19778: $chgtext.
19779: '</li>';
19780: } else {
19781: $resulttext .= '<li>'.
1.310 raeburn 19782: &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 19783: '</li>'.
1.310 raeburn 19784: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19785: }
1.43 raeburn 19786: }
19787: }
1.305 raeburn 19788: }
19789: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19790: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19791: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19792: my $chgtext = '<ul>';
19793: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19794: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19795: }
19796: $chgtext .= '</ul>';
19797: $resulttext .= '<li>'.
19798: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19799: $chgtext.
19800: '</li>';
19801: } else {
19802: $resulttext .= '<li>'.
19803: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19804: '</li>';
19805: }
1.43 raeburn 19806: }
19807: }
1.224 raeburn 19808: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19809: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19810: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19811: foreach my $type (@{$changes{'selfcreate'}}) {
19812: my $typename = $type;
1.303 raeburn 19813: if (keys(%usertypes) > 0) {
19814: if ($usertypes{$type} ne '') {
19815: $typename = $usertypes{$type};
1.224 raeburn 19816: }
19817: }
19818: my @modifiable;
19819: $resulttext .= '<li>'.
19820: &mt('Self-creation of account by users with status: [_1]',
19821: '<span class="LC_cusr_emph">'.$typename.'</span>').
19822: ' - '.&mt('modifiable fields (if institutional data blank): ');
19823: foreach my $field (@fields) {
19824: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19825: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19826: }
19827: }
1.224 raeburn 19828: if (@modifiable > 0) {
19829: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19830: } else {
1.224 raeburn 19831: $resulttext .= &mt('none');
1.43 raeburn 19832: }
1.224 raeburn 19833: $resulttext .= '</li>';
1.28 raeburn 19834: }
1.224 raeburn 19835: $resulttext .= '</ul></li>';
1.28 raeburn 19836: }
1.27 raeburn 19837: $resulttext .= '</ul>';
1.305 raeburn 19838: my $cachetime = 24*60*60;
19839: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19840: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19841: if (ref($lastactref) eq 'HASH') {
19842: $lastactref->{'domdefaults'} = 1;
19843: }
1.27 raeburn 19844: } else {
1.224 raeburn 19845: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19846: }
19847: } else {
19848: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19849: &mt('An error occurred: [_1]',$putresult).'</span>';
19850: }
1.43 raeburn 19851: if ($warningmsg ne '') {
19852: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19853: }
1.23 raeburn 19854: return $resulttext;
19855: }
19856:
1.165 raeburn 19857: sub process_captcha {
1.369 raeburn 19858: my ($container,$changes,$newsettings,$currsettings) = @_;
19859: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19860: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19861: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19862: $newsettings->{'captcha'} = 'original';
19863: }
1.369 raeburn 19864: my %current;
19865: if (ref($currsettings) eq 'HASH') {
19866: %current = %{$currsettings};
19867: }
19868: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19869: if ($container eq 'cancreate') {
1.169 raeburn 19870: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19871: push(@{$changes->{'cancreate'}},'captcha');
19872: } elsif (!defined($changes->{'cancreate'})) {
19873: $changes->{'cancreate'} = ['captcha'];
19874: }
1.368 raeburn 19875: } elsif ($container eq 'passwords') {
19876: $changes->{'reset'} = 1;
1.169 raeburn 19877: } else {
19878: $changes->{'captcha'} = 1;
1.165 raeburn 19879: }
19880: }
1.269 raeburn 19881: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19882: if ($newsettings->{'captcha'} eq 'recaptcha') {
19883: $newpub = $env{'form.'.$container.'_recaptchapub'};
19884: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19885: $newpub =~ s/[^\w\-]//g;
19886: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19887: $newsettings->{'recaptchakeys'} = {
19888: public => $newpub,
19889: private => $newpriv,
19890: };
1.269 raeburn 19891: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19892: $newversion =~ s/\D//g;
19893: if ($newversion ne '2') {
19894: $newversion = 1;
19895: }
19896: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19897: }
1.369 raeburn 19898: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19899: $currpub = $current{'recaptchakeys'}{'public'};
19900: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19901: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19902: $newsettings->{'recaptchakeys'} = {
19903: public => '',
19904: private => '',
19905: }
19906: }
1.165 raeburn 19907: }
1.369 raeburn 19908: if ($current{'captcha'} eq 'recaptcha') {
19909: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19910: if ($currversion ne '2') {
19911: $currversion = 1;
19912: }
19913: }
19914: if ($currversion ne $newversion) {
19915: if ($container eq 'cancreate') {
19916: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19917: push(@{$changes->{'cancreate'}},'recaptchaversion');
19918: } elsif (!defined($changes->{'cancreate'})) {
19919: $changes->{'cancreate'} = ['recaptchaversion'];
19920: }
1.368 raeburn 19921: } elsif ($container eq 'passwords') {
19922: $changes->{'reset'} = 1;
1.269 raeburn 19923: } else {
19924: $changes->{'recaptchaversion'} = 1;
19925: }
19926: }
1.165 raeburn 19927: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19928: if ($container eq 'cancreate') {
19929: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19930: push(@{$changes->{'cancreate'}},'recaptchakeys');
19931: } elsif (!defined($changes->{'cancreate'})) {
19932: $changes->{'cancreate'} = ['recaptchakeys'];
19933: }
1.368 raeburn 19934: } elsif ($container eq 'passwords') {
19935: $changes->{'reset'} = 1;
1.169 raeburn 19936: } else {
1.210 raeburn 19937: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19938: }
19939: }
19940: return;
19941: }
19942:
1.33 raeburn 19943: sub modify_usermodification {
19944: my ($dom,%domconfig) = @_;
1.224 raeburn 19945: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19946: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19947: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19948: if ($key eq 'selfcreate') {
19949: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19950: } else {
19951: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19952: }
1.33 raeburn 19953: }
19954: }
1.224 raeburn 19955: my @contexts = ('author','course');
1.33 raeburn 19956: my %context_title = (
19957: author => 'In author context',
19958: course => 'In course context',
19959: );
19960: my @fields = ('lastname','firstname','middlename','generation',
19961: 'permanentemail','id');
19962: my %roles = (
19963: author => ['ca','aa'],
19964: course => ['st','ep','ta','in','cr'],
19965: );
19966: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19967: foreach my $context (@contexts) {
19968: foreach my $role (@{$roles{$context}}) {
19969: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19970: foreach my $item (@fields) {
19971: if (grep(/^\Q$item\E$/,@modifiable)) {
19972: $modifyhash{$context}{$role}{$item} = 1;
19973: } else {
19974: $modifyhash{$context}{$role}{$item} = 0;
19975: }
19976: }
19977: }
19978: if (ref($curr_usermodification{$context}) eq 'HASH') {
19979: foreach my $role (@{$roles{$context}}) {
19980: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19981: foreach my $field (@fields) {
19982: if ($modifyhash{$context}{$role}{$field} ne
19983: $curr_usermodification{$context}{$role}{$field}) {
19984: push(@{$changes{$context}},$role);
19985: last;
19986: }
19987: }
19988: }
19989: }
19990: } else {
19991: foreach my $context (@contexts) {
19992: foreach my $role (@{$roles{$context}}) {
19993: push(@{$changes{$context}},$role);
19994: }
19995: }
19996: }
19997: }
19998: my %usermodification_hash = (
19999: usermodification => \%modifyhash,
20000: );
20001: my $putresult = &Apache::lonnet::put_dom('configuration',
20002: \%usermodification_hash,$dom);
20003: if ($putresult eq 'ok') {
20004: if (keys(%changes) > 0) {
20005: $resulttext = &mt('Changes made: ').'<ul>';
20006: foreach my $context (@contexts) {
20007: if (ref($changes{$context}) eq 'ARRAY') {
20008: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
20009: if (ref($changes{$context}) eq 'ARRAY') {
20010: foreach my $role (@{$changes{$context}}) {
20011: my $rolename;
1.224 raeburn 20012: if ($role eq 'cr') {
20013: $rolename = &mt('Custom');
1.33 raeburn 20014: } else {
1.224 raeburn 20015: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 20016: }
20017: my @modifiable;
1.224 raeburn 20018: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 20019: foreach my $field (@fields) {
20020: if ($modifyhash{$context}{$role}{$field}) {
20021: push(@modifiable,$fieldtitles{$field});
20022: }
20023: }
20024: if (@modifiable > 0) {
20025: $resulttext .= join(', ',@modifiable);
20026: } else {
20027: $resulttext .= &mt('none');
20028: }
20029: $resulttext .= '</li>';
20030: }
20031: $resulttext .= '</ul></li>';
20032: }
20033: }
20034: }
20035: $resulttext .= '</ul>';
20036: } else {
20037: $resulttext = &mt('No changes made to user modification settings');
20038: }
20039: } else {
20040: $resulttext = '<span class="LC_error">'.
20041: &mt('An error occurred: [_1]',$putresult).'</span>';
20042: }
20043: return $resulttext;
20044: }
20045:
1.43 raeburn 20046: sub modify_defaults {
1.212 raeburn 20047: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 20048: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 20049: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 20050: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 20051: 'portal_def');
1.325 raeburn 20052: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 20053: foreach my $item (@items) {
20054: $newvalues{$item} = $env{'form.'.$item};
20055: if ($item eq 'auth_def') {
20056: if ($newvalues{$item} ne '') {
20057: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20058: push(@errors,$item);
20059: }
20060: }
20061: } elsif ($item eq 'lang_def') {
20062: if ($newvalues{$item} ne '') {
20063: if ($newvalues{$item} =~ /^(\w+)/) {
20064: my $langcode = $1;
1.103 raeburn 20065: if ($langcode ne 'x_chef') {
20066: if (code2language($langcode) eq '') {
20067: push(@errors,$item);
20068: }
1.43 raeburn 20069: }
20070: } else {
20071: push(@errors,$item);
20072: }
20073: }
1.54 raeburn 20074: } elsif ($item eq 'timezone_def') {
20075: if ($newvalues{$item} ne '') {
1.62 raeburn 20076: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20077: push(@errors,$item);
20078: }
20079: }
1.68 raeburn 20080: } elsif ($item eq 'datelocale_def') {
20081: if ($newvalues{$item} ne '') {
20082: my @datelocale_ids = DateTime::Locale->ids();
20083: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20084: push(@errors,$item);
20085: }
20086: }
1.141 raeburn 20087: } elsif ($item eq 'portal_def') {
20088: if ($newvalues{$item} ne '') {
1.414 raeburn 20089: 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])\/?$/) {
20090: foreach my $field ('email','web') {
20091: if ($env{'form.'.$item.'_'.$field}) {
20092: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20093: }
20094: }
20095: } else {
1.141 raeburn 20096: push(@errors,$item);
20097: }
20098: }
1.43 raeburn 20099: }
20100: if (grep(/^\Q$item\E$/,@errors)) {
20101: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20102: if ($item eq 'portal_def') {
20103: if ($domdefaults{$item}) {
20104: foreach my $field ('email','web') {
20105: if (exists($domdefaults{$item.'_'.$field})) {
20106: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20107: }
20108: }
20109: }
20110: }
1.43 raeburn 20111: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20112: $changes{$item} = 1;
20113: }
1.414 raeburn 20114: if ($item eq 'portal_def') {
20115: unless (grep(/^\Q$item\E$/,@errors)) {
20116: if ($newvalues{$item} eq '') {
20117: foreach my $field ('email','web') {
20118: if (exists($domdefaults{$item.'_'.$field})) {
20119: delete($domdefaults{$item.'_'.$field});
20120: }
20121: }
20122: } else {
20123: unless ($changes{$item}) {
20124: foreach my $field ('email','web') {
20125: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20126: $changes{$item} = 1;
20127: last;
20128: }
20129: }
20130: }
20131: foreach my $field ('email','web') {
20132: if ($newvalues{$item.'_'.$field}) {
20133: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20134: } elsif (exists($domdefaults{$item.'_'.$field})) {
20135: delete($domdefaults{$item.'_'.$field});
20136: }
20137: }
20138: }
20139: }
20140: }
1.72 raeburn 20141: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20142: }
1.354 raeburn 20143: my %staticdefaults = (
20144: 'intauth_cost' => 10,
20145: 'intauth_check' => 0,
20146: 'intauth_switch' => 0,
20147: );
20148: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20149: if (exists($domdefaults{$item})) {
20150: $newvalues{$item} = $domdefaults{$item};
20151: } else {
20152: $newvalues{$item} = $staticdefaults{$item};
20153: }
20154: }
1.409 raeburn 20155: my ($unamemaprules,$ruleorder);
20156: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20157: if (@possunamemaprules) {
20158: ($unamemaprules,$ruleorder) =
20159: &Apache::lonnet::inst_userrules($dom,'unamemap');
20160: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20161: if (@{$ruleorder} > 0) {
20162: my %possrules;
20163: map { $possrules{$_} = 1; } @possunamemaprules;
20164: foreach my $rule (@{$ruleorder}) {
20165: if ($possrules{$rule}) {
20166: push(@{$newvalues{'unamemap_rule'}},$rule);
20167: }
20168: }
20169: }
20170: }
20171: }
20172: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20173: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20174: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20175: $newvalues{'unamemap_rule'});
20176: if (@rulediffs) {
20177: $changes{'unamemap_rule'} = 1;
20178: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20179: }
20180: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20181: $changes{'unamemap_rule'} = 1;
20182: delete($domdefaults{'unamemap_rule'});
20183: }
20184: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20185: if (@{$newvalues{'unamemap_rule'}} > 0) {
20186: $changes{'unamemap_rule'} = 1;
20187: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20188: }
20189: }
1.43 raeburn 20190: my %defaults_hash = (
1.72 raeburn 20191: defaults => \%newvalues,
20192: );
1.43 raeburn 20193: my $title = &defaults_titles();
1.236 raeburn 20194:
20195: my $currinststatus;
20196: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20197: $currinststatus = $domconfig{'inststatus'};
20198: } else {
20199: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20200: $currinststatus = {
20201: inststatustypes => $usertypes,
20202: inststatusorder => $types,
20203: inststatusguest => [],
20204: };
20205: }
20206: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20207: my @allpos;
20208: my %alltypes;
1.305 raeburn 20209: my @inststatusguest;
20210: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20211: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20212: unless (grep(/^\Q$type\E$/,@todelete)) {
20213: push(@inststatusguest,$type);
20214: }
20215: }
20216: }
20217: my ($currtitles,$currorder);
1.236 raeburn 20218: if (ref($currinststatus) eq 'HASH') {
20219: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20220: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20221: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20222: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20223: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20224: }
20225: }
20226: unless (grep(/^\Q$type\E$/,@todelete)) {
20227: my $position = $env{'form.inststatus_pos_'.$type};
20228: $position =~ s/\D+//g;
20229: $allpos[$position] = $type;
20230: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20231: $alltypes{$type} =~ s/`//g;
20232: }
20233: }
20234: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20235: $currtitles =~ s/,$//;
20236: }
20237: }
20238: if ($env{'form.addinststatus'}) {
20239: my $newtype = $env{'form.addinststatus'};
20240: $newtype =~ s/\W//g;
20241: unless (exists($alltypes{$newtype})) {
20242: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20243: $alltypes{$newtype} =~ s/`//g;
20244: my $position = $env{'form.addinststatus_pos'};
20245: $position =~ s/\D+//g;
20246: if ($position ne '') {
20247: $allpos[$position] = $newtype;
20248: }
20249: }
20250: }
1.305 raeburn 20251: my @orderedstatus;
1.236 raeburn 20252: foreach my $type (@allpos) {
20253: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20254: push(@orderedstatus,$type);
20255: }
20256: }
20257: foreach my $type (keys(%alltypes)) {
20258: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20259: delete($alltypes{$type});
20260: }
20261: }
20262: $defaults_hash{'inststatus'} = {
20263: inststatustypes => \%alltypes,
20264: inststatusorder => \@orderedstatus,
1.305 raeburn 20265: inststatusguest => \@inststatusguest,
1.236 raeburn 20266: };
20267: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20268: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20269: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20270: }
20271: }
20272: if ($currorder ne join(',',@orderedstatus)) {
20273: $changes{'inststatus'}{'inststatusorder'} = 1;
20274: }
20275: my $newtitles;
20276: foreach my $item (@orderedstatus) {
20277: $newtitles .= $alltypes{$item}.',';
20278: }
20279: $newtitles =~ s/,$//;
20280: if ($currtitles ne $newtitles) {
20281: $changes{'inststatus'}{'inststatustypes'} = 1;
20282: }
1.43 raeburn 20283: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20284: $dom);
20285: if ($putresult eq 'ok') {
20286: if (keys(%changes) > 0) {
20287: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20288: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20289: 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";
20290: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20291: if ($item eq 'inststatus') {
20292: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20293: if (@orderedstatus) {
1.236 raeburn 20294: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20295: foreach my $type (@orderedstatus) {
20296: $resulttext .= $alltypes{$type}.', ';
20297: }
20298: $resulttext =~ s/, $//;
20299: $resulttext .= '</li>';
1.305 raeburn 20300: } else {
20301: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20302: }
20303: }
1.409 raeburn 20304: } elsif ($item eq 'unamemap_rule') {
20305: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20306: my @rulenames;
20307: if (ref($unamemaprules) eq 'HASH') {
20308: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20309: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20310: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20311: }
20312: }
20313: }
20314: if (@rulenames) {
20315: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20316: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20317: '</li>';
20318: } else {
20319: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20320: }
20321: } else {
20322: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20323: }
1.236 raeburn 20324: } else {
20325: my $value = $env{'form.'.$item};
20326: if ($value eq '') {
20327: $value = &mt('none');
20328: } elsif ($item eq 'auth_def') {
20329: my %authnames = &authtype_names();
20330: my %shortauth = (
20331: internal => 'int',
20332: krb4 => 'krb4',
20333: krb5 => 'krb5',
20334: localauth => 'loc',
1.325 raeburn 20335: lti => 'lti',
1.236 raeburn 20336: );
20337: $value = $authnames{$shortauth{$value}};
20338: }
20339: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20340: $mailmsgtext .= "$title->{$item} set to $value\n";
20341: if ($item eq 'portal_def') {
20342: if ($env{'form.'.$item} ne '') {
20343: foreach my $field ('email','web') {
20344: $value = $env{'form.'.$item.'_'.$field};
20345: if ($value) {
20346: $value = &mt('Yes');
20347: } else {
20348: $value = &mt('No');
20349: }
20350: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20351: }
20352: }
20353: }
1.43 raeburn 20354: }
20355: }
20356: $resulttext .= '</ul>';
20357: $mailmsgtext .= "\n";
20358: my $cachetime = 24*60*60;
1.72 raeburn 20359: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20360: if (ref($lastactref) eq 'HASH') {
20361: $lastactref->{'domdefaults'} = 1;
20362: }
1.68 raeburn 20363: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20364: my $notify = 1;
20365: if (ref($domconfig{'contacts'}) eq 'HASH') {
20366: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20367: $notify = 0;
20368: }
20369: }
20370: if ($notify) {
20371: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20372: "LON-CAPA Domain Settings Change - $dom",
20373: $mailmsgtext);
20374: }
1.54 raeburn 20375: }
1.43 raeburn 20376: } else {
1.54 raeburn 20377: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20378: }
20379: } else {
20380: $resulttext = '<span class="LC_error">'.
20381: &mt('An error occurred: [_1]',$putresult).'</span>';
20382: }
20383: if (@errors > 0) {
20384: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20385: foreach my $item (@errors) {
20386: $resulttext .= ' "'.$title->{$item}.'",';
20387: }
20388: $resulttext =~ s/,$//;
20389: }
20390: return $resulttext;
20391: }
20392:
1.46 raeburn 20393: sub modify_scantron {
1.205 raeburn 20394: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20395: my ($resulttext,%confhash,%changes,$errors);
20396: my $custom = 'custom.tab';
20397: my $default = 'default.tab';
20398: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20399: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20400: &config_check($dom,$confname,$servadm);
20401: if ($env{'form.scantronformat.filename'} ne '') {
20402: my $error;
20403: if ($configuserok eq 'ok') {
20404: if ($switchserver) {
1.130 raeburn 20405: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20406: } else {
20407: if ($author_ok eq 'ok') {
20408: my ($result,$scantronurl) =
20409: &publishlogo($r,'upload','scantronformat',$dom,
20410: $confname,'scantron','','',$custom);
20411: if ($result eq 'ok') {
20412: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20413: $changes{'scantronformat'} = 1;
1.46 raeburn 20414: } else {
20415: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20416: }
20417: } else {
20418: $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);
20419: }
20420: }
20421: } else {
20422: $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);
20423: }
20424: if ($error) {
20425: &Apache::lonnet::logthis($error);
20426: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20427: }
20428: }
1.48 raeburn 20429: if (ref($domconfig{'scantron'}) eq 'HASH') {
20430: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20431: if ($env{'form.scantronformat_del'}) {
20432: $confhash{'scantron'}{'scantronformat'} = '';
20433: $changes{'scantronformat'} = 1;
1.347 raeburn 20434: } else {
20435: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20436: }
20437: }
20438: }
1.347 raeburn 20439: my @options = ('hdr','pad','rem');
1.346 raeburn 20440: my @fields = &scantroncsv_fields();
20441: my %titles = &scantronconfig_titles();
1.347 raeburn 20442: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20443: my ($newdat,$currdat,%newcol,%currcol);
20444: if (grep(/^dat$/,@formats)) {
20445: $confhash{'scantron'}{config}{dat} = 1;
20446: $newdat = 1;
20447: } else {
20448: $newdat = 0;
20449: }
20450: if (grep(/^csv$/,@formats)) {
20451: my %bynum;
20452: foreach my $field (@fields) {
20453: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20454: my $posscol = $1;
20455: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20456: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20457: $bynum{$posscol} = $field;
20458: $newcol{$field} = $posscol;
20459: }
20460: }
20461: }
1.347 raeburn 20462: if (keys(%newcol)) {
20463: foreach my $option (@options) {
20464: if ($env{'form.scantroncsv_'.$option}) {
20465: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20466: }
20467: }
20468: }
1.346 raeburn 20469: }
20470: $currdat = 1;
20471: if (ref($domconfig{'scantron'}) eq 'HASH') {
20472: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20473: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20474: $currdat = 0;
20475: }
20476: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20477: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20478: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20479: }
1.346 raeburn 20480: }
20481: }
20482: }
20483: if ($currdat != $newdat) {
20484: $changes{'config'} = 1;
20485: } else {
20486: foreach my $field (@fields) {
20487: if ($currcol{$field} ne '') {
20488: if ($currcol{$field} ne $newcol{$field}) {
20489: $changes{'config'} = 1;
20490: last;
1.347 raeburn 20491: }
1.346 raeburn 20492: } elsif ($newcol{$field} ne '') {
20493: $changes{'config'} = 1;
20494: last;
20495: }
20496: }
20497: }
1.46 raeburn 20498: if (keys(%confhash) > 0) {
20499: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20500: $dom);
20501: if ($putresult eq 'ok') {
20502: if (keys(%changes) > 0) {
1.48 raeburn 20503: if (ref($confhash{'scantron'}) eq 'HASH') {
20504: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20505: if ($changes{'scantronformat'}) {
20506: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20507: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20508: } else {
20509: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20510: }
20511: }
1.347 raeburn 20512: if ($changes{'config'}) {
1.346 raeburn 20513: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20514: if ($confhash{'scantron'}{'config'}{'dat'}) {
20515: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20516: }
20517: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20518: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20519: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20520: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20521: foreach my $field (@fields) {
20522: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20523: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20524: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20525: }
20526: }
20527: $resulttext .= '</ul></li>';
20528: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20529: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20530: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20531: foreach my $option (@options) {
20532: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20533: $resulttext .= '<li>'.$titles{$option}.'</li>';
20534: }
20535: }
20536: $resulttext .= '</ul></li>';
20537: }
1.346 raeburn 20538: }
20539: }
20540: }
20541: }
20542: } else {
20543: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20544: }
1.46 raeburn 20545: }
1.48 raeburn 20546: $resulttext .= '</ul>';
20547: } else {
1.130 raeburn 20548: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20549: }
20550: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20551: if (ref($lastactref) eq 'HASH') {
20552: $lastactref->{'domainconfig'} = 1;
20553: }
1.46 raeburn 20554: } else {
1.346 raeburn 20555: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20556: }
20557: } else {
20558: $resulttext = '<span class="LC_error">'.
20559: &mt('An error occurred: [_1]',$putresult).'</span>';
20560: }
20561: } else {
1.130 raeburn 20562: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20563: }
20564: if ($errors) {
1.353 raeburn 20565: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20566: $errors.'</ul></p>';
1.46 raeburn 20567: }
20568: return $resulttext;
20569: }
20570:
1.48 raeburn 20571: sub modify_coursecategories {
1.239 raeburn 20572: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20573: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20574: $cathash);
1.48 raeburn 20575: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20576: my @catitems = ('unauth','auth');
20577: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20578: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20579: $cathash = $domconfig{'coursecategories'}{'cats'};
20580: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20581: $changes{'togglecats'} = 1;
20582: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20583: }
20584: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20585: $changes{'categorize'} = 1;
20586: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20587: }
1.120 raeburn 20588: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20589: $changes{'togglecatscomm'} = 1;
20590: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20591: }
20592: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20593: $changes{'categorizecomm'} = 1;
20594: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20595:
20596: }
20597: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20598: $changes{'togglecatsplace'} = 1;
20599: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20600: }
20601: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20602: $changes{'categorizeplace'} = 1;
20603: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20604: }
1.238 raeburn 20605: foreach my $item (@catitems) {
20606: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20607: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20608: $changes{$item} = 1;
20609: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20610: }
20611: }
20612: }
1.57 raeburn 20613: } else {
20614: $changes{'togglecats'} = 1;
20615: $changes{'categorize'} = 1;
1.124 raeburn 20616: $changes{'togglecatscomm'} = 1;
20617: $changes{'categorizecomm'} = 1;
1.272 raeburn 20618: $changes{'togglecatsplace'} = 1;
20619: $changes{'categorizeplace'} = 1;
1.87 raeburn 20620: $domconfig{'coursecategories'} = {
20621: togglecats => $env{'form.togglecats'},
20622: categorize => $env{'form.categorize'},
1.124 raeburn 20623: togglecatscomm => $env{'form.togglecatscomm'},
20624: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20625: togglecatsplace => $env{'form.togglecatsplace'},
20626: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20627: };
1.238 raeburn 20628: foreach my $item (@catitems) {
20629: if ($env{'form.coursecat_'.$item} ne 'std') {
20630: $changes{$item} = 1;
20631: }
20632: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20633: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20634: }
20635: }
1.57 raeburn 20636: }
20637: if (ref($cathash) eq 'HASH') {
20638: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20639: push (@deletecategory,'instcode::0');
20640: }
1.120 raeburn 20641: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20642: push(@deletecategory,'communities::0');
20643: }
1.272 raeburn 20644: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20645: push(@deletecategory,'placement::0');
20646: }
1.48 raeburn 20647: }
1.57 raeburn 20648: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20649: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20650: if (@deletecategory > 0) {
20651: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20652: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20653: foreach my $item (@deletecategory) {
1.57 raeburn 20654: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20655: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20656: $deletions{$item} = 1;
1.57 raeburn 20657: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20658: }
20659: }
20660: }
1.57 raeburn 20661: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20662: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20663: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20664: $reorderings{$item} = 1;
1.57 raeburn 20665: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20666: }
20667: if ($env{'form.addcategory_name_'.$item} ne '') {
20668: my $newcat = $env{'form.addcategory_name_'.$item};
20669: my $newdepth = $depth+1;
20670: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20671: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20672: $adds{$newitem} = 1;
20673: }
20674: if ($env{'form.subcat_'.$item} ne '') {
20675: my $newcat = $env{'form.subcat_'.$item};
20676: my $newdepth = $depth+1;
20677: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20678: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20679: $adds{$newitem} = 1;
20680: }
20681: }
20682: }
20683: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20684: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20685: my $newitem = 'instcode::0';
1.57 raeburn 20686: if ($cathash->{$newitem} eq '') {
20687: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20688: $adds{$newitem} = 1;
20689: }
20690: } else {
20691: my $newitem = 'instcode::0';
1.57 raeburn 20692: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20693: $adds{$newitem} = 1;
20694: }
20695: }
1.120 raeburn 20696: if ($env{'form.communities'} eq '1') {
20697: if (ref($cathash) eq 'HASH') {
20698: my $newitem = 'communities::0';
20699: if ($cathash->{$newitem} eq '') {
20700: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20701: $adds{$newitem} = 1;
20702: }
20703: } else {
20704: my $newitem = 'communities::0';
20705: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20706: $adds{$newitem} = 1;
20707: }
20708: }
1.272 raeburn 20709: if ($env{'form.placement'} eq '1') {
20710: if (ref($cathash) eq 'HASH') {
20711: my $newitem = 'placement::0';
20712: if ($cathash->{$newitem} eq '') {
20713: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20714: $adds{$newitem} = 1;
20715: }
20716: } else {
20717: my $newitem = 'placement::0';
20718: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20719: $adds{$newitem} = 1;
20720: }
20721: }
1.48 raeburn 20722: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20723: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20724: ($env{'form.addcategory_name'} ne 'communities') &&
20725: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20726: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20727: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20728: $adds{$newitem} = 1;
20729: }
1.48 raeburn 20730: }
1.57 raeburn 20731: my $putresult;
1.48 raeburn 20732: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20733: if (keys(%deletions) > 0) {
20734: foreach my $key (keys(%deletions)) {
20735: if ($predelallitems{$key} ne '') {
20736: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20737: }
20738: }
20739: }
20740: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20741: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20742: if (ref($chkcats[0]) eq 'ARRAY') {
20743: my $depth = 0;
20744: my $chg = 0;
20745: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20746: my $name = $chkcats[0][$i];
20747: my $item;
20748: if ($name eq '') {
20749: $chg ++;
20750: } else {
20751: $item = &escape($name).'::0';
20752: if ($chg) {
1.57 raeburn 20753: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20754: }
20755: $depth ++;
1.57 raeburn 20756: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20757: $depth --;
20758: }
20759: }
20760: }
1.57 raeburn 20761: }
20762: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20763: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20764: if ($putresult eq 'ok') {
1.57 raeburn 20765: my %title = (
1.120 raeburn 20766: togglecats => 'Show/Hide a course in catalog',
20767: categorize => 'Assign a category to a course',
20768: togglecatscomm => 'Show/Hide a community in catalog',
20769: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20770: );
20771: my %level = (
1.120 raeburn 20772: dom => 'set in Domain ("Modify Course/Community")',
20773: crs => 'set in Course ("Course Configuration")',
20774: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20775: none => 'No catalog',
20776: std => 'Standard catalog',
20777: domonly => 'Domain-only catalog',
20778: codesrch => 'Code search form',
1.57 raeburn 20779: );
1.48 raeburn 20780: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20781: if ($changes{'togglecats'}) {
20782: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20783: }
20784: if ($changes{'categorize'}) {
20785: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20786: }
1.120 raeburn 20787: if ($changes{'togglecatscomm'}) {
20788: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20789: }
20790: if ($changes{'categorizecomm'}) {
20791: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20792: }
1.238 raeburn 20793: if ($changes{'unauth'}) {
20794: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20795: }
20796: if ($changes{'auth'}) {
20797: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20798: }
1.57 raeburn 20799: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20800: my $cathash;
20801: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20802: $cathash = $domconfig{'coursecategories'}{'cats'};
20803: } else {
20804: $cathash = {};
20805: }
20806: my (@cats,@trails,%allitems);
20807: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20808: if (keys(%deletions) > 0) {
20809: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20810: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20811: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20812: }
20813: $resulttext .= '</ul></li>';
20814: }
20815: if (keys(%reorderings) > 0) {
20816: my %sort_by_trail;
20817: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20818: foreach my $key (keys(%reorderings)) {
20819: if ($allitems{$key} ne '') {
20820: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20821: }
1.48 raeburn 20822: }
1.57 raeburn 20823: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20824: $resulttext .= '<li>'.$trails[$trail].'</li>';
20825: }
20826: $resulttext .= '</ul></li>';
1.48 raeburn 20827: }
1.57 raeburn 20828: if (keys(%adds) > 0) {
20829: my %sort_by_trail;
20830: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20831: foreach my $key (keys(%adds)) {
20832: if ($allitems{$key} ne '') {
20833: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20834: }
20835: }
20836: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20837: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20838: }
1.57 raeburn 20839: $resulttext .= '</ul></li>';
1.48 raeburn 20840: }
1.364 raeburn 20841: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20842: if (ref($lastactref) eq 'HASH') {
20843: $lastactref->{'cats'} = 1;
20844: }
1.48 raeburn 20845: }
20846: $resulttext .= '</ul>';
1.239 raeburn 20847: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20848: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20849: if ($changes{'auth'}) {
20850: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20851: }
20852: if ($changes{'unauth'}) {
20853: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20854: }
20855: my $cachetime = 24*60*60;
20856: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20857: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20858: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20859: }
20860: }
1.48 raeburn 20861: } else {
20862: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20863: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20864: }
20865: } else {
1.120 raeburn 20866: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20867: }
20868: return $resulttext;
20869: }
20870:
1.69 raeburn 20871: sub modify_serverstatuses {
20872: my ($dom,%domconfig) = @_;
20873: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20874: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20875: %currserverstatus = %{$domconfig{'serverstatuses'}};
20876: }
20877: my @pages = &serverstatus_pages();
20878: foreach my $type (@pages) {
20879: $newserverstatus{$type}{'namedusers'} = '';
20880: $newserverstatus{$type}{'machines'} = '';
20881: if (defined($env{'form.'.$type.'_namedusers'})) {
20882: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20883: my @okusers;
20884: foreach my $user (@users) {
20885: my ($uname,$udom) = split(/:/,$user);
20886: if (($udom =~ /^$match_domain$/) &&
20887: (&Apache::lonnet::domain($udom)) &&
20888: ($uname =~ /^$match_username$/)) {
20889: if (!grep(/^\Q$user\E/,@okusers)) {
20890: push(@okusers,$user);
20891: }
20892: }
20893: }
20894: if (@okusers > 0) {
20895: @okusers = sort(@okusers);
20896: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20897: }
20898: }
20899: if (defined($env{'form.'.$type.'_machines'})) {
20900: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20901: my @okmachines;
20902: foreach my $ip (@machines) {
20903: my @parts = split(/\./,$ip);
20904: next if (@parts < 4);
20905: my $badip = 0;
20906: for (my $i=0; $i<4; $i++) {
20907: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20908: $badip = 1;
20909: last;
20910: }
20911: }
20912: if (!$badip) {
20913: push(@okmachines,$ip);
20914: }
20915: }
20916: @okmachines = sort(@okmachines);
20917: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20918: }
20919: }
20920: my %serverstatushash = (
20921: serverstatuses => \%newserverstatus,
20922: );
20923: foreach my $type (@pages) {
1.83 raeburn 20924: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20925: my (@current,@new);
1.83 raeburn 20926: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20927: if ($currserverstatus{$type}{$setting} ne '') {
20928: @current = split(/,/,$currserverstatus{$type}{$setting});
20929: }
20930: }
20931: if ($newserverstatus{$type}{$setting} ne '') {
20932: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20933: }
20934: if (@current > 0) {
20935: if (@new > 0) {
20936: foreach my $item (@current) {
20937: if (!grep(/^\Q$item\E$/,@new)) {
20938: $changes{$type}{$setting} = 1;
1.82 raeburn 20939: last;
20940: }
20941: }
1.84 raeburn 20942: foreach my $item (@new) {
20943: if (!grep(/^\Q$item\E$/,@current)) {
20944: $changes{$type}{$setting} = 1;
20945: last;
1.82 raeburn 20946: }
20947: }
20948: } else {
1.83 raeburn 20949: $changes{$type}{$setting} = 1;
1.69 raeburn 20950: }
1.83 raeburn 20951: } elsif (@new > 0) {
20952: $changes{$type}{$setting} = 1;
1.69 raeburn 20953: }
20954: }
20955: }
20956: if (keys(%changes) > 0) {
1.81 raeburn 20957: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20958: my $putresult = &Apache::lonnet::put_dom('configuration',
20959: \%serverstatushash,$dom);
20960: if ($putresult eq 'ok') {
20961: $resulttext .= &mt('Changes made:').'<ul>';
20962: foreach my $type (@pages) {
1.84 raeburn 20963: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20964: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20965: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20966: if ($newserverstatus{$type}{'namedusers'} eq '') {
20967: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20968: } else {
20969: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20970: }
1.84 raeburn 20971: }
20972: if ($changes{$type}{'machines'}) {
1.69 raeburn 20973: if ($newserverstatus{$type}{'machines'} eq '') {
20974: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20975: } else {
20976: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20977: }
20978:
20979: }
20980: $resulttext .= '</ul></li>';
20981: }
20982: }
20983: $resulttext .= '</ul>';
20984: } else {
20985: $resulttext = '<span class="LC_error">'.
20986: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20987:
20988: }
20989: } else {
20990: $resulttext = &mt('No changes made to access to server status pages');
20991: }
20992: return $resulttext;
20993: }
20994:
1.118 jms 20995: sub modify_helpsettings {
1.285 raeburn 20996: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20997: my ($resulttext,$errors,%changes,%helphash);
20998: my %defaultchecked = ('submitbugs' => 'on');
20999: my @offon = ('off','on');
1.118 jms 21000: my @toggles = ('submitbugs');
1.285 raeburn 21001: my %current = ('submitbugs' => '',
21002: 'adhoc' => {},
21003: );
1.118 jms 21004: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 21005: %current = %{$domconfig{'helpsettings'}};
21006: }
1.285 raeburn 21007: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 21008: foreach my $item (@toggles) {
21009: if ($defaultchecked{$item} eq 'on') {
21010: if ($current{$item} eq '') {
21011: if ($env{'form.'.$item} eq '0') {
21012: $changes{$item} = 1;
21013: }
21014: } elsif ($current{$item} ne $env{'form.'.$item}) {
21015: $changes{$item} = 1;
21016: }
21017: } elsif ($defaultchecked{$item} eq 'off') {
21018: if ($current{$item} eq '') {
21019: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 21020: $changes{$item} = 1;
21021: }
1.282 raeburn 21022: } elsif ($current{$item} ne $env{'form.'.$item}) {
21023: $changes{$item} = 1;
21024: }
21025: }
21026: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
21027: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
21028: }
21029: }
1.285 raeburn 21030: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 21031: my $confname = $dom.'-domainconfig';
21032: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 21033: my (@allpos,%newsettings,%changedprivs,$newrole);
21034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 21035: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 21036: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 21037: my %lt = &Apache::lonlocal::texthash(
21038: s => 'system',
21039: d => 'domain',
21040: order => 'Display order',
21041: access => 'Role usage',
1.291 raeburn 21042: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 21043: dh => 'All with domain helpdesk role',
21044: da => 'All with domain helpdesk assistant role',
1.285 raeburn 21045: none => 'None',
21046: status => 'Determined based on institutional status',
21047: inc => 'Include all, but exclude specific personnel',
21048: exc => 'Exclude all, but include specific personnel',
21049: );
21050: for (my $num=0; $num<=$maxnum; $num++) {
21051: my ($prefix,$identifier,$rolename,%curr);
21052: if ($num == $maxnum) {
21053: next unless ($env{'form.newcusthelp'} == $maxnum);
21054: $identifier = 'custhelp'.$num;
21055: $prefix = 'helproles_'.$num;
21056: $rolename = $env{'form.custhelpname'.$num};
21057: $rolename=~s/[^A-Za-z0-9]//gs;
21058: next if ($rolename eq '');
21059: next if (exists($existing{'rolesdef_'.$rolename}));
21060: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21061: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21062: $newprivs{'c'},$confname,$dom);
21063: if ($result ne 'ok') {
21064: $errors .= '<li><span class="LC_error">'.
21065: &mt('An error occurred storing the new custom role: [_1]',
21066: $result).'</span></li>';
21067: next;
21068: } else {
21069: $changedprivs{$rolename} = \%newprivs;
21070: $newrole = $rolename;
21071: }
21072: } else {
21073: $prefix = 'helproles_'.$num;
21074: $rolename = $env{'form.'.$prefix};
21075: next if ($rolename eq '');
21076: next unless (exists($existing{'rolesdef_'.$rolename}));
21077: $identifier = 'custhelp'.$num;
21078: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21079: my %currprivs;
1.289 raeburn 21080: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21081: split(/\_/,$existing{'rolesdef_'.$rolename});
21082: foreach my $level ('c','d','s') {
21083: if ($newprivs{$level} ne $currprivs{$level}) {
21084: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21085: $newprivs{'c'},$confname,$dom);
21086: if ($result ne 'ok') {
21087: $errors .= '<li><span class="LC_error">'.
21088: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21089: $rolename,$result).'</span></li>';
21090: } else {
21091: $changedprivs{$rolename} = \%newprivs;
21092: }
21093: last;
21094: }
21095: }
21096: if (ref($current{'adhoc'}) eq 'HASH') {
21097: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21098: %curr = %{$current{'adhoc'}{$rolename}};
21099: }
21100: }
21101: }
21102: my $newpos = $env{'form.'.$prefix.'_pos'};
21103: $newpos =~ s/\D+//g;
21104: $allpos[$newpos] = $rolename;
21105: my $newdesc = $env{'form.'.$prefix.'_desc'};
21106: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21107: if ($curr{'desc'}) {
21108: if ($curr{'desc'} ne $newdesc) {
21109: $changes{'customrole'}{$rolename}{'desc'} = 1;
21110: $newsettings{$rolename}{'desc'} = $newdesc;
21111: }
21112: } elsif ($newdesc ne '') {
21113: $changes{'customrole'}{$rolename}{'desc'} = 1;
21114: $newsettings{$rolename}{'desc'} = $newdesc;
21115: }
21116: my $access = $env{'form.'.$prefix.'_access'};
21117: if (grep(/^\Q$access\E$/,@accesstypes)) {
21118: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21119: if ($access eq 'status') {
21120: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21121: if (scalar(@statuses) == 0) {
1.289 raeburn 21122: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21123: } else {
21124: my (@shownstatus,$numtypes);
21125: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21126: if (ref($types) eq 'ARRAY') {
21127: $numtypes = scalar(@{$types});
21128: foreach my $type (sort(@statuses)) {
21129: if ($type eq 'default') {
21130: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21131: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21132: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21133: push(@shownstatus,$usertypes->{$type});
21134: }
21135: }
21136: }
21137: if (grep(/^default$/,@statuses)) {
21138: push(@shownstatus,$othertitle);
21139: }
21140: if (scalar(@shownstatus) == 1+$numtypes) {
21141: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21142: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21143: } else {
21144: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21145: if (ref($curr{'status'}) eq 'ARRAY') {
21146: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21147: if (@diffs) {
21148: $changes{'customrole'}{$rolename}{$access} = 1;
21149: }
21150: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21151: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21152: }
1.166 raeburn 21153: }
21154: }
1.285 raeburn 21155: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21156: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21157: my @newspecstaff;
21158: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21159: foreach my $person (sort(@personnel)) {
21160: if ($domhelpdesk{$person}) {
21161: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21162: }
21163: }
21164: if (ref($curr{$access}) eq 'ARRAY') {
21165: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21166: if (@diffs) {
21167: $changes{'customrole'}{$rolename}{$access} = 1;
21168: }
21169: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21170: $changes{'customrole'}{$rolename}{$access} = 1;
21171: }
21172: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21173: my ($uname,$udom) = split(/:/,$person);
21174: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21175: }
21176: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21177: }
1.285 raeburn 21178: } else {
21179: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21180: }
21181: unless ($curr{'access'} eq $access) {
21182: $changes{'customrole'}{$rolename}{'access'} = 1;
21183: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21184: }
21185: }
1.285 raeburn 21186: if (@allpos > 0) {
21187: my $idx = 0;
21188: foreach my $rolename (@allpos) {
21189: if ($rolename ne '') {
21190: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21191: if (ref($current{'adhoc'}) eq 'HASH') {
21192: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21193: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21194: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21195: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21196: }
21197: }
1.282 raeburn 21198: }
1.285 raeburn 21199: $idx ++;
1.166 raeburn 21200: }
21201: }
1.118 jms 21202: }
1.123 jms 21203: my $putresult;
21204: if (keys(%changes) > 0) {
1.166 raeburn 21205: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21206: if ($putresult eq 'ok') {
1.285 raeburn 21207: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21208: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21209: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21210: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21211: }
21212: }
21213: my $cachetime = 24*60*60;
21214: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21215: if (ref($lastactref) eq 'HASH') {
21216: $lastactref->{'domdefaults'} = 1;
21217: }
21218: } else {
21219: $errors .= '<li><span class="LC_error">'.
21220: &mt('An error occurred storing the settings: [_1]',
21221: $putresult).'</span></li>';
21222: }
21223: }
21224: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21225: $resulttext = &mt('Changes made:').'<ul>';
21226: my (%shownprivs,@levelorder);
21227: @levelorder = ('c','d','s');
21228: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21229: foreach my $item (sort(keys(%changes))) {
21230: if ($item eq 'submitbugs') {
21231: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21232: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21233: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21234: } elsif ($item eq 'customrole') {
21235: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21236: my @keyorder = ('order','desc','access','status','exc','inc');
21237: my %keytext = &Apache::lonlocal::texthash(
21238: order => 'Order',
21239: desc => 'Role description',
21240: access => 'Role usage',
1.300 droeschl 21241: status => 'Allowed institutional types',
1.285 raeburn 21242: exc => 'Allowed personnel',
21243: inc => 'Disallowed personnel',
21244: );
1.282 raeburn 21245: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21246: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21247: if ($role eq $newrole) {
21248: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21249: $role).'<ul>';
21250: } else {
21251: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21252: $role).'<ul>';
21253: }
21254: foreach my $key (@keyorder) {
21255: if ($changes{'customrole'}{$role}{$key}) {
21256: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21257: $keytext{$key},$newsettings{$role}{$key}).
21258: '</li>';
21259: }
21260: }
21261: if (ref($changedprivs{$role}) eq 'HASH') {
21262: $shownprivs{$role} = 1;
21263: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21264: foreach my $level (@levelorder) {
21265: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21266: next if ($item eq '');
21267: my ($priv) = split(/\&/,$item,2);
21268: if (&Apache::lonnet::plaintext($priv)) {
21269: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21270: unless ($level eq 'c') {
21271: $resulttext .= ' ('.$lt{$level}.')';
21272: }
21273: $resulttext .= '</li>';
21274: }
21275: }
21276: }
21277: $resulttext .= '</ul>';
21278: }
21279: $resulttext .= '</ul></li>';
21280: }
21281: }
21282: }
21283: }
21284: }
21285: }
21286: if (keys(%changedprivs)) {
21287: foreach my $role (sort(keys(%changedprivs))) {
21288: unless ($shownprivs{$role}) {
21289: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21290: $role).'<ul>'.
21291: '<li>'.&mt('Privileges set to :').'<ul>';
21292: foreach my $level (@levelorder) {
21293: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21294: next if ($item eq '');
21295: my ($priv) = split(/\&/,$item,2);
21296: if (&Apache::lonnet::plaintext($priv)) {
21297: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21298: unless ($level eq 'c') {
21299: $resulttext .= ' ('.$lt{$level}.')';
21300: }
21301: $resulttext .= '</li>';
21302: }
1.282 raeburn 21303: }
21304: }
1.285 raeburn 21305: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21306: }
21307: }
21308: }
1.285 raeburn 21309: $resulttext .= '</ul>';
21310: } else {
21311: $resulttext = &mt('No changes made to help settings');
1.118 jms 21312: }
21313: if ($errors) {
1.168 raeburn 21314: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21315: $errors.'</ul>';
1.118 jms 21316: }
21317: return $resulttext;
21318: }
21319:
1.121 raeburn 21320: sub modify_coursedefaults {
1.212 raeburn 21321: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21322: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21323: my %defaultchecked = (
21324: 'canuse_pdfforms' => 'off',
21325: 'uselcmath' => 'on',
1.398 raeburn 21326: 'usejsme' => 'on',
21327: 'inline_chem' => 'on',
1.404 raeburn 21328: 'ltiauth' => 'off',
1.257 raeburn 21329: );
1.404 raeburn 21330: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21331: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21332: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
21333: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
21334: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 21335: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21336: my %staticdefaults = (
21337: anonsurvey_threshold => 10,
21338: uploadquota => 500,
1.257 raeburn 21339: postsubmit => 60,
1.276 raeburn 21340: mysqltables => 172800,
1.198 raeburn 21341: );
1.314 raeburn 21342: my %texoptions = (
21343: MathJax => 'MathJax',
21344: mimetex => &mt('Convert to Images'),
21345: tth => &mt('TeX to HTML'),
21346: );
1.121 raeburn 21347: $defaultshash{'coursedefaults'} = {};
21348:
21349: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21350: if ($domconfig{'coursedefaults'} eq '') {
21351: $domconfig{'coursedefaults'} = {};
21352: }
21353: }
21354:
21355: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21356: foreach my $item (@toggles) {
21357: if ($defaultchecked{$item} eq 'on') {
21358: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21359: ($env{'form.'.$item} eq '0')) {
21360: $changes{$item} = 1;
1.192 raeburn 21361: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21362: $changes{$item} = 1;
21363: }
21364: } elsif ($defaultchecked{$item} eq 'off') {
21365: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21366: ($env{'form.'.$item} eq '1')) {
21367: $changes{$item} = 1;
21368: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21369: $changes{$item} = 1;
21370: }
21371: }
21372: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21373: }
1.198 raeburn 21374: foreach my $item (@numbers) {
21375: my ($currdef,$newdef);
1.208 raeburn 21376: $newdef = $env{'form.'.$item};
1.198 raeburn 21377: if ($item eq 'anonsurvey_threshold') {
21378: $currdef = $domconfig{'coursedefaults'}{$item};
21379: $newdef =~ s/\D//g;
21380: if ($newdef eq '' || $newdef < 1) {
21381: $newdef = 1;
21382: }
21383: $defaultshash{'coursedefaults'}{$item} = $newdef;
21384: } else {
1.276 raeburn 21385: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
21386: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21387: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21388: }
21389: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21390: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21391: }
21392: if ($currdef ne $newdef) {
21393: if ($item eq 'anonsurvey_threshold') {
21394: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21395: $changes{$item} = 1;
21396: }
1.276 raeburn 21397: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 21398: my $setting = $1;
1.276 raeburn 21399: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21400: $changes{$setting} = 1;
1.198 raeburn 21401: }
21402: }
1.139 raeburn 21403: }
21404: }
1.314 raeburn 21405: my $texengine;
21406: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21407: $texengine = $env{'form.texengine'};
1.349 raeburn 21408: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21409: if ($currdef eq '') {
21410: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21411: $changes{'texengine'} = 1;
21412: }
1.349 raeburn 21413: } elsif ($currdef ne $texengine) {
1.314 raeburn 21414: $changes{'texengine'} = 1;
21415: }
21416: }
21417: if ($texengine ne '') {
21418: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21419: }
1.264 raeburn 21420: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21421: my @currclonecode;
21422: if (ref($currclone) eq 'HASH') {
21423: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21424: @currclonecode = @{$currclone->{'instcode'}};
21425: }
21426: }
21427: my $newclone;
1.289 raeburn 21428: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21429: $newclone = $env{'form.canclone'};
21430: }
21431: if ($newclone eq 'instcode') {
21432: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21433: my (%codedefaults,@code_order,@clonecode);
21434: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21435: \@code_order);
21436: foreach my $item (@code_order) {
21437: if (grep(/^\Q$item\E$/,@newcodes)) {
21438: push(@clonecode,$item);
21439: }
21440: }
21441: if (@clonecode) {
21442: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21443: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21444: if (@diffs) {
21445: $changes{'canclone'} = 1;
21446: }
21447: } else {
21448: $newclone eq '';
21449: }
21450: } elsif ($newclone ne '') {
1.289 raeburn 21451: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21452: }
1.264 raeburn 21453: if ($newclone ne $currclone) {
21454: $changes{'canclone'} = 1;
21455: }
1.257 raeburn 21456: my %credits;
21457: foreach my $type (@types) {
21458: unless ($type eq 'community') {
21459: $credits{$type} = $env{'form.'.$type.'_credits'};
21460: $credits{$type} =~ s/[^\d.]+//g;
21461: }
21462: }
21463: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21464: ($env{'form.coursecredits'} eq '1')) {
21465: $changes{'coursecredits'} = 1;
21466: foreach my $type (keys(%credits)) {
21467: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21468: }
21469: } else {
1.289 raeburn 21470: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21471: foreach my $type (@types) {
21472: unless ($type eq 'community') {
1.289 raeburn 21473: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21474: $changes{'coursecredits'} = 1;
21475: }
21476: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21477: }
21478: }
21479: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21480: foreach my $type (@types) {
21481: unless ($type eq 'community') {
21482: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21483: $changes{'coursecredits'} = 1;
21484: last;
21485: }
21486: }
21487: }
21488: }
21489: }
21490: if ($env{'form.postsubmit'} eq '1') {
21491: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21492: my %currtimeout;
21493: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21494: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21495: $changes{'postsubmit'} = 1;
21496: }
21497: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21498: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21499: }
21500: } else {
21501: $changes{'postsubmit'} = 1;
21502: }
21503: foreach my $type (@types) {
21504: my $timeout = $env{'form.'.$type.'_timeout'};
21505: $timeout =~ s/\D//g;
21506: if ($timeout == $staticdefaults{'postsubmit'}) {
21507: $timeout = '';
21508: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21509: $timeout = '0';
21510: }
21511: unless ($timeout eq '') {
21512: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21513: }
21514: if (exists($currtimeout{$type})) {
21515: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21516: $changes{'postsubmit'} = 1;
1.257 raeburn 21517: }
21518: } elsif ($timeout ne '') {
21519: $changes{'postsubmit'} = 1;
21520: }
21521: }
21522: } else {
21523: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21524: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21525: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21526: $changes{'postsubmit'} = 1;
21527: }
21528: } else {
21529: $changes{'postsubmit'} = 1;
21530: }
1.192 raeburn 21531: }
1.121 raeburn 21532: }
21533: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21534: $dom);
21535: if ($putresult eq 'ok') {
21536: if (keys(%changes) > 0) {
1.213 raeburn 21537: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21538: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21539: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21540: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.404 raeburn 21541: ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
21542: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.257 raeburn 21543: if ($changes{$item}) {
21544: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21545: }
1.289 raeburn 21546: }
1.192 raeburn 21547: if ($changes{'coursecredits'}) {
21548: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21549: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21550: $domdefaults{$type.'credits'} =
21551: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21552: }
21553: }
21554: }
21555: if ($changes{'postsubmit'}) {
21556: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21557: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21558: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21559: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21560: $domdefaults{$type.'postsubtimeout'} =
21561: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21562: }
21563: }
1.192 raeburn 21564: }
21565: }
1.198 raeburn 21566: if ($changes{'uploadquota'}) {
21567: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21568: foreach my $type (@types) {
21569: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21570: }
21571: }
21572: }
1.264 raeburn 21573: if ($changes{'canclone'}) {
21574: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21575: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21576: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21577: if (@clonecodes) {
21578: $domdefaults{'canclone'} = join('+',@clonecodes);
21579: }
21580: }
21581: } else {
21582: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21583: }
21584: }
1.121 raeburn 21585: my $cachetime = 24*60*60;
21586: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21587: if (ref($lastactref) eq 'HASH') {
21588: $lastactref->{'domdefaults'} = 1;
21589: }
1.121 raeburn 21590: }
21591: $resulttext = &mt('Changes made:').'<ul>';
21592: foreach my $item (sort(keys(%changes))) {
21593: if ($item eq 'canuse_pdfforms') {
21594: if ($env{'form.'.$item} eq '1') {
21595: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21596: } else {
21597: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21598: }
1.257 raeburn 21599: } elsif ($item eq 'uselcmath') {
21600: if ($env{'form.'.$item} eq '1') {
21601: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21602: } else {
21603: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21604: }
21605: } elsif ($item eq 'usejsme') {
21606: if ($env{'form.'.$item} eq '1') {
21607: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21608: } else {
1.289 raeburn 21609: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21610: }
1.398 raeburn 21611: } elsif ($item eq 'inline_chem') {
21612: if ($env{'form.'.$item} eq '1') {
21613: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21614: } else {
21615: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21616: }
1.314 raeburn 21617: } elsif ($item eq 'texengine') {
21618: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21619: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21620: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21621: }
1.139 raeburn 21622: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21623: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21624: } elsif ($item eq 'uploadquota') {
21625: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21626: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21627: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21628: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21629: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21630: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21631: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21632: '</ul>'.
21633: '</li>';
21634: } else {
21635: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21636: }
1.276 raeburn 21637: } elsif ($item eq 'mysqltables') {
21638: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21639: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21640: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21641: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21642: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21643: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21644: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21645: '</ul>'.
21646: '</li>';
21647: } else {
21648: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21649: }
1.257 raeburn 21650: } elsif ($item eq 'postsubmit') {
21651: if ($domdefaults{'postsubmit'} eq 'off') {
21652: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21653: } else {
21654: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21655: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21656: $resulttext .= &mt('durations:').'<ul>';
21657: foreach my $type (@types) {
21658: $resulttext .= '<li>';
21659: my $timeout;
21660: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21661: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21662: }
21663: my $display;
21664: if ($timeout eq '0') {
21665: $display = &mt('unlimited');
21666: } elsif ($timeout eq '') {
21667: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21668: } else {
21669: $display = &mt('[quant,_1,second]',$timeout);
21670: }
21671: if ($type eq 'community') {
21672: $resulttext .= &mt('Communities');
21673: } elsif ($type eq 'official') {
21674: $resulttext .= &mt('Official courses');
21675: } elsif ($type eq 'unofficial') {
21676: $resulttext .= &mt('Unofficial courses');
21677: } elsif ($type eq 'textbook') {
21678: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21679: } elsif ($type eq 'placement') {
21680: $resulttext .= &mt('Placement tests');
1.257 raeburn 21681: }
21682: $resulttext .= ' -- '.$display.'</li>';
21683: }
21684: $resulttext .= '</ul>';
21685: }
1.289 raeburn 21686: $resulttext .= '</li>';
1.257 raeburn 21687: }
1.192 raeburn 21688: } elsif ($item eq 'coursecredits') {
21689: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21690: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21691: ($domdefaults{'unofficialcredits'} eq '') &&
21692: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21693: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21694: } else {
21695: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21696: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21697: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21698: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21699: '</ul>'.
21700: '</li>';
21701: }
21702: } else {
21703: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21704: }
1.264 raeburn 21705: } elsif ($item eq 'canclone') {
21706: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21707: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21708: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21709: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21710: }
21711: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21712: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21713: } else {
1.289 raeburn 21714: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21715: }
1.404 raeburn 21716: } elsif ($item eq 'ltiauth') {
21717: if ($env{'form.'.$item} eq '1') {
21718: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21719: } else {
21720: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21721: }
1.140 raeburn 21722: }
1.121 raeburn 21723: }
21724: $resulttext .= '</ul>';
21725: } else {
21726: $resulttext = &mt('No changes made to course defaults');
21727: }
21728: } else {
21729: $resulttext = '<span class="LC_error">'.
21730: &mt('An error occurred: [_1]',$putresult).'</span>';
21731: }
21732: return $resulttext;
21733: }
21734:
1.231 raeburn 21735: sub modify_selfenrollment {
21736: my ($dom,$lastactref,%domconfig) = @_;
21737: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21738: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21739: my %titles = &tool_titles();
1.232 raeburn 21740: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21741: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21742: $ordered{'default'} = ['types','registered','approval','limit'];
21743:
21744: my (%roles,%shown,%toplevel);
21745: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21746:
21747: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21748: if ($domconfig{'selfenrollment'} eq '') {
21749: $domconfig{'selfenrollment'} = {};
21750: }
21751: }
21752: %toplevel = (
21753: admin => 'Configuration Rights',
21754: default => 'Default settings',
21755: validation => 'Validation of self-enrollment requests',
21756: );
1.233 raeburn 21757: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21758:
21759: if (ref($ordered{'admin'}) eq 'ARRAY') {
21760: foreach my $item (@{$ordered{'admin'}}) {
21761: foreach my $type (@types) {
21762: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21763: $selfenrollhash{'admin'}{$type}{$item} = 1;
21764: } else {
21765: $selfenrollhash{'admin'}{$type}{$item} = 0;
21766: }
21767: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21768: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21769: if ($selfenrollhash{'admin'}{$type}{$item} ne
21770: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21771: push(@{$changes{'admin'}{$type}},$item);
21772: }
21773: } else {
21774: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21775: push(@{$changes{'admin'}{$type}},$item);
21776: }
21777: }
21778: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21779: push(@{$changes{'admin'}{$type}},$item);
21780: }
21781: }
21782: }
21783: }
21784:
21785: foreach my $item (@{$ordered{'default'}}) {
21786: foreach my $type (@types) {
21787: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21788: if ($item eq 'types') {
21789: unless (($value eq 'all') || ($value eq 'dom')) {
21790: $value = '';
21791: }
21792: } elsif ($item eq 'registered') {
21793: unless ($value eq '1') {
21794: $value = 0;
21795: }
21796: } elsif ($item eq 'approval') {
21797: unless ($value =~ /^[012]$/) {
21798: $value = 0;
21799: }
21800: } else {
21801: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21802: $value = 'none';
21803: }
21804: }
21805: $selfenrollhash{'default'}{$type}{$item} = $value;
21806: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21807: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21808: if ($selfenrollhash{'default'}{$type}{$item} ne
21809: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21810: push(@{$changes{'default'}{$type}},$item);
21811: }
21812: } else {
21813: push(@{$changes{'default'}{$type}},$item);
21814: }
21815: } else {
21816: push(@{$changes{'default'}{$type}},$item);
21817: }
21818: if ($item eq 'limit') {
21819: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21820: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21821: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21822: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21823: }
21824: } else {
21825: $selfenrollhash{'default'}{$type}{'cap'} = '';
21826: }
21827: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21828: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21829: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21830: push(@{$changes{'default'}{$type}},'cap');
21831: }
21832: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21833: push(@{$changes{'default'}{$type}},'cap');
21834: }
21835: }
21836: }
21837: }
21838:
21839: foreach my $item (@{$itemsref}) {
21840: if ($item eq 'fields') {
21841: my @changed;
21842: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21843: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21844: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21845: }
21846: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21847: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21848: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21849: $domconfig{'selfenrollment'}{'validation'}{$item});
21850: } else {
21851: @changed = @{$selfenrollhash{'validation'}{$item}};
21852: }
21853: } else {
21854: @changed = @{$selfenrollhash{'validation'}{$item}};
21855: }
21856: if (@changed) {
21857: if ($selfenrollhash{'validation'}{$item}) {
21858: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21859: } else {
21860: $changes{'validation'}{$item} = &mt('None');
21861: }
21862: }
21863: } else {
21864: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21865: if ($item eq 'markup') {
21866: if ($env{'form.selfenroll_validation_'.$item}) {
21867: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21868: }
21869: }
21870: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21871: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21872: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21873: }
21874: }
21875: }
21876: }
21877:
21878: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21879: $dom);
21880: if ($putresult eq 'ok') {
21881: if (keys(%changes) > 0) {
21882: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21883: $resulttext = &mt('Changes made:').'<ul>';
21884: foreach my $key ('admin','default','validation') {
21885: if (ref($changes{$key}) eq 'HASH') {
21886: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21887: if ($key eq 'validation') {
21888: foreach my $item (@{$itemsref}) {
21889: if (exists($changes{$key}{$item})) {
21890: if ($item eq 'markup') {
21891: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21892: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21893: } else {
21894: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21895: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21896: }
21897: }
21898: }
21899: } else {
21900: foreach my $type (@types) {
21901: if ($type eq 'community') {
21902: $roles{'1'} = &mt('Community personnel');
21903: } else {
21904: $roles{'1'} = &mt('Course personnel');
21905: }
21906: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21907: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21908: if ($key eq 'admin') {
21909: my @mgrdc = ();
21910: if (ref($ordered{$key}) eq 'ARRAY') {
21911: foreach my $item (@{$ordered{'admin'}}) {
21912: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21913: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21914: push(@mgrdc,$item);
21915: }
21916: }
21917: }
21918: if (@mgrdc) {
21919: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21920: } else {
21921: delete($domdefaults{$type.'selfenrolladmdc'});
21922: }
21923: }
21924: } else {
21925: if (ref($ordered{$key}) eq 'ARRAY') {
21926: foreach my $item (@{$ordered{$key}}) {
21927: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21928: $domdefaults{$type.'selfenroll'.$item} =
21929: $selfenrollhash{$key}{$type}{$item};
21930: }
21931: }
21932: }
21933: }
21934: }
1.231 raeburn 21935: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21936: foreach my $item (@{$ordered{$key}}) {
21937: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21938: $resulttext .= '<li>';
21939: if ($key eq 'admin') {
21940: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21941: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21942: } else {
21943: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21944: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21945: }
21946: $resulttext .= '</li>';
21947: }
21948: }
21949: $resulttext .= '</ul></li>';
21950: }
21951: }
21952: $resulttext .= '</ul></li>';
21953: }
21954: }
1.305 raeburn 21955: }
21956: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21957: my $cachetime = 24*60*60;
21958: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21959: if (ref($lastactref) eq 'HASH') {
21960: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21961: }
1.231 raeburn 21962: }
21963: $resulttext .= '</ul>';
21964: } else {
21965: $resulttext = &mt('No changes made to self-enrollment settings');
21966: }
21967: } else {
21968: $resulttext = '<span class="LC_error">'.
21969: &mt('An error occurred: [_1]',$putresult).'</span>';
21970: }
21971: return $resulttext;
21972: }
21973:
1.373 raeburn 21974: sub modify_wafproxy {
21975: my ($dom,$action,$lastactref,%domconfig) = @_;
21976: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21977: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21978: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21979: foreach my $server (sort(keys(%servers))) {
21980: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21981: if ($serverhome eq $server) {
21982: my $serverdom = &Apache::lonnet::host_domain($server);
21983: if ($serverdom eq $dom) {
21984: $canset{$server} = 1;
21985: }
21986: }
21987: }
1.381 raeburn 21988: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21989: %{$values{$dom}} = ();
21990: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21991: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21992: }
1.388 raeburn 21993: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21994: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21995: }
1.382 raeburn 21996: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21997: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21998: }
21999: }
1.373 raeburn 22000: my $output;
22001: if (keys(%canset)) {
22002: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22003: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22004: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22005: if ($env{'form.wafproxy_'.$dom}) {
22006: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22007: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22008: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22009: $changes{'alias'} = 1;
22010: }
1.388 raeburn 22011: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22012: $wafproxy{'saml'}{$key} = 1;
22013: }
22014: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22015: $changes{'saml'} = 1;
22016: }
1.381 raeburn 22017: } else {
22018: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22019: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22020: if ($curralias{$key}) {
22021: $changes{'alias'} = 1;
22022: }
1.388 raeburn 22023: if ($currsaml{$key}) {
22024: $changes{'saml'} = 1;
22025: }
1.373 raeburn 22026: }
22027: if ($wafproxy{'alias'}{$key} eq '') {
22028: if ($curralias{$key}) {
22029: $expirecache{$key} = 1;
22030: }
22031: delete($wafproxy{'alias'}{$key});
22032: }
1.388 raeburn 22033: if ($wafproxy{'saml'}{$key} eq '') {
22034: if ($currsaml{$key}) {
22035: $expiresaml{$key} = 1;
22036: }
22037: delete($wafproxy{'saml'}{$key});
22038: }
1.373 raeburn 22039: }
22040: unless (keys(%{$wafproxy{'alias'}})) {
22041: delete($wafproxy{'alias'});
22042: }
1.388 raeburn 22043: unless (keys(%{$wafproxy{'saml'}})) {
22044: delete($wafproxy{'saml'});
22045: }
22046: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22047: my %warn = (
22048: trusted => 'trusted IP range(s)',
1.381 raeburn 22049: vpnint => 'internal IP range(s) for VPN sessions(s)',
22050: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22051: );
1.382 raeburn 22052: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22053: my $possible = $env{'form.wafproxy_'.$item};
22054: $possible =~ s/^\s+|\s+$//g;
22055: if ($possible ne '') {
1.381 raeburn 22056: if ($item eq 'remoteip') {
22057: if ($possible =~ /^[mhn]$/) {
22058: $wafproxy{$item} = $possible;
22059: }
22060: } elsif ($item eq 'ipheader') {
22061: if ($wafproxy{'remoteip'} eq 'h') {
22062: $wafproxy{$item} = $possible;
22063: }
1.382 raeburn 22064: } elsif ($item eq 'sslopt') {
22065: if ($possible =~ /^0|1$/) {
22066: $wafproxy{$item} = $possible;
22067: }
1.373 raeburn 22068: } else {
22069: my (@ok,$count);
1.381 raeburn 22070: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22071: unless ($env{'form.wafproxy_vpnaccess'}) {
22072: $possible = '';
22073: }
22074: } elsif ($item eq 'trusted') {
22075: unless ($wafproxy{'remoteip'} eq 'h') {
22076: $possible = '';
22077: }
22078: }
22079: unless ($possible eq '') {
22080: $possible =~ s/[\r\n]+/\s/g;
22081: $possible =~ s/\s*-\s*/-/g;
22082: $possible =~ s/\s+/,/g;
1.393 raeburn 22083: $possible =~ s/,+/,/g;
1.381 raeburn 22084: }
1.373 raeburn 22085: $count = 0;
1.381 raeburn 22086: if ($possible ne '') {
1.373 raeburn 22087: foreach my $poss (split(/\,/,$possible)) {
22088: $count ++;
1.393 raeburn 22089: $poss = &validate_ip_pattern($poss);
22090: if ($poss ne '') {
1.373 raeburn 22091: push(@ok,$poss);
22092: }
22093: }
22094: my $diff = $count - scalar(@ok);
22095: if ($diff) {
22096: push(@warnings,'<li>'.
22097: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22098: $diff,$warn{$item}).
22099: '</li>');
22100: }
1.393 raeburn 22101: if (@ok) {
22102: my @cidr_list;
22103: foreach my $item (@ok) {
22104: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22105: }
22106: $wafproxy{$item} = join(',',@cidr_list);
22107: }
1.373 raeburn 22108: }
22109: }
1.381 raeburn 22110: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22111: $changes{$item} = 1;
22112: }
1.381 raeburn 22113: } elsif ($currvalue{$item}) {
22114: $changes{$item} = 1;
22115: }
22116: }
22117: } else {
22118: if (keys(%curralias)) {
22119: $changes{'alias'} = 1;
1.388 raeburn 22120: }
22121: if (keys(%currsaml)) {
22122: $changes{'saml'} = 1;
1.381 raeburn 22123: }
22124: if (keys(%currvalue)) {
22125: foreach my $key (keys(%currvalue)) {
22126: $changes{$key} = 1;
1.373 raeburn 22127: }
22128: }
22129: }
22130: if (keys(%changes)) {
22131: my %defaultshash = (
22132: wafproxy => \%wafproxy,
22133: );
22134: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22135: $dom);
22136: if ($putresult eq 'ok') {
22137: my $cachetime = 24*60*60;
22138: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22139: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22140: if ($changes{$item}) {
22141: unless ($updatedomdefs) {
22142: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22143: $updatedomdefs = 1;
22144: }
22145: if ($wafproxy{$item}) {
22146: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22147: } elsif (exists($domdefaults{'waf_'.$item})) {
22148: delete($domdefaults{'waf_'.$item});
22149: }
22150: }
22151: }
22152: if ($updatedomdefs) {
22153: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22154: if (ref($lastactref) eq 'HASH') {
22155: $lastactref->{'domdefaults'} = 1;
22156: }
22157: }
22158: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22159: my %updates = %expirecache;
22160: foreach my $key (keys(%expirecache)) {
22161: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22162: }
22163: if (ref($wafproxy{'alias'}) eq 'HASH') {
22164: my $cachetime = 24*60*60;
22165: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22166: $updates{$key} = 1;
22167: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22168: $cachetime);
22169: }
22170: }
22171: if (ref($lastactref) eq 'HASH') {
22172: $lastactref->{'proxyalias'} = \%updates;
22173: }
22174: }
1.388 raeburn 22175: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22176: my %samlupdates = %expiresaml;
22177: foreach my $key (keys(%expiresaml)) {
22178: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22179: }
22180: if (ref($wafproxy{'saml'}) eq 'HASH') {
22181: my $cachetime = 24*60*60;
22182: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22183: $samlupdates{$key} = 1;
22184: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22185: $cachetime);
22186: }
22187: }
22188: if (ref($lastactref) eq 'HASH') {
22189: $lastactref->{'proxysaml'} = \%samlupdates;
22190: }
22191: }
1.373 raeburn 22192: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22193: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22194: if ($changes{$item}) {
22195: if ($item eq 'alias') {
22196: my $numaliased = 0;
22197: if (ref($wafproxy{'alias'}) eq 'HASH') {
22198: my $shown;
22199: if (keys(%{$wafproxy{'alias'}})) {
22200: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22201: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22202: &Apache::lonnet::hostname($server),
22203: $wafproxy{'alias'}{$server}).'</li>';
22204: $numaliased ++;
22205: }
22206: if ($numaliased) {
22207: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22208: '<ul>'.$shown.'</ul>').'</li>';
22209: }
22210: }
22211: }
22212: unless ($numaliased) {
22213: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22214: }
1.388 raeburn 22215: } elsif ($item eq 'saml') {
22216: my $shown;
22217: if (ref($wafproxy{'saml'}) eq 'HASH') {
22218: if (keys(%{$wafproxy{'saml'}})) {
22219: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22220: }
22221: }
22222: if ($shown) {
1.396 raeburn 22223: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22224: $shown).'</li>';
22225: } else {
1.396 raeburn 22226: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22227: }
1.373 raeburn 22228: } else {
1.381 raeburn 22229: if ($item eq 'remoteip') {
22230: my %ip_methods = &remoteip_methods();
22231: if ($wafproxy{$item} =~ /^[mh]$/) {
22232: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22233: $ip_methods{$wafproxy{$item}}).'</li>';
22234: } else {
22235: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22236: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22237: '</li>';
22238: } else {
22239: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22240: }
22241: }
22242: } elsif ($item eq 'ipheader') {
1.373 raeburn 22243: if ($wafproxy{$item}) {
1.381 raeburn 22244: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22245: $wafproxy{$item}).'</li>';
22246: } else {
1.381 raeburn 22247: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22248: }
22249: } elsif ($item eq 'trusted') {
22250: if ($wafproxy{$item}) {
1.381 raeburn 22251: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22252: $wafproxy{$item}).'</li>';
22253: } else {
22254: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22255: }
1.381 raeburn 22256: } elsif ($item eq 'vpnint') {
22257: if ($wafproxy{$item}) {
22258: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22259: $wafproxy{$item}).'</li>';
22260: } else {
22261: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22262: }
22263: } elsif ($item eq 'vpnext') {
1.373 raeburn 22264: if ($wafproxy{$item}) {
1.381 raeburn 22265: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22266: $wafproxy{$item}).'</li>';
22267: } else {
1.381 raeburn 22268: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22269: }
1.382 raeburn 22270: } elsif ($item eq 'sslopt') {
22271: if ($wafproxy{$item}) {
22272: $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>';
22273: } else {
22274: $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>';
22275: }
1.373 raeburn 22276: }
22277: }
22278: }
22279: }
22280: } else {
22281: $output = '<span class="LC_error">'.
22282: &mt('An error occurred: [_1]',$putresult).'</span>';
22283: }
22284: } elsif (keys(%canset)) {
22285: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22286: }
22287: if (@warnings) {
22288: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22289: join("\n",@warnings).'</ul>';
22290: }
22291: return $output;
22292: }
22293:
22294: sub validate_ip_pattern {
22295: my ($pattern) = @_;
22296: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22297: my ($start,$end) = ($1,$2);
22298: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22299: if (($start !~ m{/}) && ($end !~ m{/})) {
22300: return $start.'-'.$end;
22301: }
22302: }
22303: } elsif ($pattern ne '') {
22304: $pattern = &Net::CIDR::cidrvalidate($pattern);
22305: if ($pattern ne '') {
22306: return $pattern;
1.373 raeburn 22307: }
22308: }
1.393 raeburn 22309: return;
1.373 raeburn 22310: }
22311:
1.137 raeburn 22312: sub modify_usersessions {
1.212 raeburn 22313: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22314: my @hostingtypes = ('version','excludedomain','includedomain');
22315: my @offloadtypes = ('primary','default');
22316: my %types = (
22317: remote => \@hostingtypes,
22318: hosted => \@hostingtypes,
22319: spares => \@offloadtypes,
22320: );
22321: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22322: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22323: my (%by_ip,%by_location,@intdoms,@instdoms);
22324: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22325: my @locations = sort(keys(%by_location));
1.137 raeburn 22326: my (%defaultshash,%changes);
22327: foreach my $prefix (@prefixes) {
22328: $defaultshash{'usersessions'}{$prefix} = {};
22329: }
1.212 raeburn 22330: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22331: my $resulttext;
1.138 raeburn 22332: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22333: foreach my $prefix (@prefixes) {
1.145 raeburn 22334: next if ($prefix eq 'spares');
22335: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22336: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22337: if ($type eq 'version') {
22338: my $value = $env{'form.'.$prefix.'_'.$type};
22339: my $okvalue;
22340: if ($value ne '') {
22341: if (grep(/^\Q$value\E$/,@lcversions)) {
22342: $okvalue = $value;
22343: }
22344: }
22345: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22346: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22347: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22348: if ($inuse == 0) {
22349: $changes{$prefix}{$type} = 1;
22350: } else {
22351: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22352: $changes{$prefix}{$type} = 1;
22353: }
22354: if ($okvalue ne '') {
22355: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22356: }
22357: }
22358: } else {
22359: if (($inuse == 1) && ($okvalue ne '')) {
22360: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22361: $changes{$prefix}{$type} = 1;
22362: }
22363: }
22364: } else {
22365: if (($inuse == 1) && ($okvalue ne '')) {
22366: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22367: $changes{$prefix}{$type} = 1;
22368: }
22369: }
22370: } else {
22371: if (($inuse == 1) && ($okvalue ne '')) {
22372: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22373: $changes{$prefix}{$type} = 1;
22374: }
22375: }
22376: } else {
22377: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22378: my @okvals;
22379: foreach my $val (@vals) {
1.138 raeburn 22380: if ($val =~ /:/) {
22381: my @items = split(/:/,$val);
22382: foreach my $item (@items) {
22383: if (ref($by_location{$item}) eq 'ARRAY') {
22384: push(@okvals,$item);
22385: }
22386: }
22387: } else {
22388: if (ref($by_location{$val}) eq 'ARRAY') {
22389: push(@okvals,$val);
22390: }
1.137 raeburn 22391: }
22392: }
22393: @okvals = sort(@okvals);
22394: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22395: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22396: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22397: if ($inuse == 0) {
22398: $changes{$prefix}{$type} = 1;
22399: } else {
22400: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22401: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22402: if (@changed > 0) {
22403: $changes{$prefix}{$type} = 1;
22404: }
22405: }
22406: } else {
22407: if ($inuse == 1) {
22408: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22409: $changes{$prefix}{$type} = 1;
22410: }
22411: }
22412: } else {
22413: if ($inuse == 1) {
22414: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22415: $changes{$prefix}{$type} = 1;
22416: }
22417: }
22418: } else {
22419: if ($inuse == 1) {
22420: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22421: $changes{$prefix}{$type} = 1;
22422: }
22423: }
22424: }
22425: }
22426: }
1.145 raeburn 22427:
22428: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22429: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22430: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22431: my $savespares;
22432:
22433: foreach my $lonhost (sort(keys(%servers))) {
22434: my $serverhomeID =
22435: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22436: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22437: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22438: my %spareschg;
22439: foreach my $type (@{$types{'spares'}}) {
22440: my @okspares;
22441: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22442: foreach my $server (@checked) {
1.152 raeburn 22443: if (&Apache::lonnet::hostname($server) ne '') {
22444: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22445: unless (grep(/^\Q$server\E$/,@okspares)) {
22446: push(@okspares,$server);
22447: }
1.145 raeburn 22448: }
22449: }
22450: }
22451: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22452: my $newspare;
1.152 raeburn 22453: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22454: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22455: $newspare = $new;
22456: }
22457: }
1.152 raeburn 22458: my @spares;
22459: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22460: @spares = sort(@okspares,$newspare);
22461: } else {
22462: @spares = sort(@okspares);
22463: }
22464: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22465: if (ref($spareid{$lonhost}) eq 'HASH') {
22466: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22467: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22468: if (@diffs > 0) {
22469: $spareschg{$type} = 1;
22470: }
22471: }
22472: }
22473: }
22474: if (keys(%spareschg) > 0) {
22475: $changes{'spares'}{$lonhost} = \%spareschg;
22476: }
22477: }
1.261 raeburn 22478: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22479: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22480: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22481: my @okoffload;
22482: if (@offloadnow) {
22483: foreach my $server (@offloadnow) {
22484: if (&Apache::lonnet::hostname($server) ne '') {
22485: unless (grep(/^\Q$server\E$/,@okoffload)) {
22486: push(@okoffload,$server);
22487: }
22488: }
22489: }
22490: if (@okoffload) {
22491: foreach my $lonhost (@okoffload) {
22492: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22493: }
22494: }
22495: }
1.371 raeburn 22496: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22497: my @okoffloadoth;
22498: if (@offloadoth) {
22499: foreach my $server (@offloadoth) {
22500: if (&Apache::lonnet::hostname($server) ne '') {
22501: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22502: push(@okoffloadoth,$server);
22503: }
22504: }
22505: }
22506: if (@okoffloadoth) {
22507: foreach my $lonhost (@okoffloadoth) {
22508: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22509: }
22510: }
22511: }
1.145 raeburn 22512: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22513: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22514: if (ref($changes{'spares'}) eq 'HASH') {
22515: if (keys(%{$changes{'spares'}}) > 0) {
22516: $savespares = 1;
22517: }
22518: }
22519: } else {
22520: $savespares = 1;
22521: }
1.371 raeburn 22522: foreach my $offload ('offloadnow','offloadoth') {
22523: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22524: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22525: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22526: $changes{$offload} = 1;
22527: last;
22528: }
1.261 raeburn 22529: }
1.371 raeburn 22530: unless ($changes{$offload}) {
22531: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22532: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22533: $changes{$offload} = 1;
22534: last;
22535: }
1.261 raeburn 22536: }
22537: }
1.371 raeburn 22538: } else {
22539: if (($offload eq 'offloadnow') && (@okoffload)) {
22540: $changes{'offloadnow'} = 1;
22541: }
22542: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22543: $changes{'offloadoth'} = 1;
22544: }
22545: }
22546: }
22547: } else {
22548: if (@okoffload) {
1.261 raeburn 22549: $changes{'offloadnow'} = 1;
22550: }
1.371 raeburn 22551: if (@okoffloadoth) {
22552: $changes{'offloadoth'} = 1;
22553: }
1.145 raeburn 22554: }
1.147 raeburn 22555: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22556: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22557: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22558: $dom);
22559: if ($putresult eq 'ok') {
22560: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22561: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22562: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22563: }
22564: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22565: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22566: }
1.261 raeburn 22567: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22568: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22569: }
1.371 raeburn 22570: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22571: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22572: }
1.137 raeburn 22573: }
22574: my $cachetime = 24*60*60;
22575: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22576: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22577: if (ref($lastactref) eq 'HASH') {
22578: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22579: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22580: }
1.147 raeburn 22581: if (keys(%changes) > 0) {
22582: my %lt = &usersession_titles();
22583: $resulttext = &mt('Changes made:').'<ul>';
22584: foreach my $prefix (@prefixes) {
22585: if (ref($changes{$prefix}) eq 'HASH') {
22586: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22587: if ($prefix eq 'spares') {
22588: if (ref($changes{$prefix}) eq 'HASH') {
22589: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22590: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22591: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22592: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22593: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22594: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22595: foreach my $type (@{$types{$prefix}}) {
22596: if ($changes{$prefix}{$lonhost}{$type}) {
22597: my $offloadto = &mt('None');
22598: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22599: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22600: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22601: }
1.145 raeburn 22602: }
1.147 raeburn 22603: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22604: }
1.137 raeburn 22605: }
22606: }
1.147 raeburn 22607: $resulttext .= '</li>';
1.137 raeburn 22608: }
22609: }
1.147 raeburn 22610: } else {
22611: foreach my $type (@{$types{$prefix}}) {
22612: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22613: my ($newvalue,$notinuse);
1.147 raeburn 22614: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22615: if (ref($defaultshash{'usersessions'}{$prefix})) {
22616: if ($type eq 'version') {
22617: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22618: } else {
22619: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22620: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22621: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22622: }
22623: } else {
22624: $notinuse = 1;
1.147 raeburn 22625: }
1.145 raeburn 22626: }
22627: }
22628: }
1.147 raeburn 22629: if ($newvalue eq '') {
22630: if ($type eq 'version') {
22631: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22632: } elsif ($notinuse) {
22633: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22634: } else {
22635: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22636: }
1.145 raeburn 22637: } else {
1.147 raeburn 22638: if ($type eq 'version') {
1.344 raeburn 22639: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22640: }
22641: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22642: }
1.137 raeburn 22643: }
22644: }
22645: }
1.147 raeburn 22646: $resulttext .= '</ul>';
1.137 raeburn 22647: }
22648: }
1.261 raeburn 22649: if ($changes{'offloadnow'}) {
22650: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22651: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22652: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22653: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22654: $resulttext .= '<li>'.$lonhost.'</li>';
22655: }
22656: $resulttext .= '</ul>';
22657: } else {
1.371 raeburn 22658: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22659: }
22660: } else {
22661: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22662: }
22663: }
22664: if ($changes{'offloadoth'}) {
22665: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22666: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22667: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22668: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22669: $resulttext .= '<li>'.$lonhost.'</li>';
22670: }
22671: $resulttext .= '</ul>';
22672: } else {
22673: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22674: }
22675: } else {
1.371 raeburn 22676: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22677: }
22678: }
1.147 raeburn 22679: $resulttext .= '</ul>';
22680: } else {
22681: $resulttext = $nochgmsg;
1.137 raeburn 22682: }
22683: } else {
22684: $resulttext = '<span class="LC_error">'.
22685: &mt('An error occurred: [_1]',$putresult).'</span>';
22686: }
22687: } else {
1.147 raeburn 22688: $resulttext = $nochgmsg;
1.137 raeburn 22689: }
22690: return $resulttext;
22691: }
22692:
1.275 raeburn 22693: sub modify_ssl {
22694: my ($dom,$lastactref,%domconfig) = @_;
22695: my (%by_ip,%by_location,@intdoms,@instdoms);
22696: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22697: my @locations = sort(keys(%by_location));
22698: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22699: my (%defaultshash,%changes);
22700: my $action = 'ssl';
1.293 raeburn 22701: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22702: foreach my $prefix (@prefixes) {
22703: $defaultshash{$action}{$prefix} = {};
22704: }
22705: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22706: my $resulttext;
22707: my %iphost = &Apache::lonnet::get_iphost();
22708: my @reptypes = ('certreq','nocertreq');
22709: my @connecttypes = ('dom','intdom','other');
22710: my %types = (
1.293 raeburn 22711: connto => \@connecttypes,
22712: connfrom => \@connecttypes,
22713: replication => \@reptypes,
1.275 raeburn 22714: );
22715: foreach my $prefix (sort(keys(%types))) {
22716: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22717: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22718: my $value = 'yes';
22719: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22720: $value = $env{'form.'.$prefix.'_'.$type};
22721: }
1.335 raeburn 22722: if (ref($domconfig{$action}) eq 'HASH') {
22723: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22724: if ($domconfig{$action}{$prefix}{$type} ne '') {
22725: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22726: $changes{$prefix}{$type} = 1;
22727: }
22728: $defaultshash{$action}{$prefix}{$type} = $value;
22729: } else {
22730: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22731: $changes{$prefix}{$type} = 1;
22732: }
22733: } else {
22734: $defaultshash{$action}{$prefix}{$type} = $value;
22735: $changes{$prefix}{$type} = 1;
22736: }
22737: } else {
22738: $defaultshash{$action}{$prefix}{$type} = $value;
22739: $changes{$prefix}{$type} = 1;
22740: }
22741: if (($type eq 'dom') && (keys(%servers) == 1)) {
22742: delete($changes{$prefix}{$type});
22743: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22744: delete($changes{$prefix}{$type});
22745: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22746: delete($changes{$prefix}{$type});
22747: }
22748: } elsif ($prefix eq 'replication') {
22749: if (@locations > 0) {
22750: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22751: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22752: my @okvals;
22753: foreach my $val (@vals) {
22754: if ($val =~ /:/) {
22755: my @items = split(/:/,$val);
22756: foreach my $item (@items) {
22757: if (ref($by_location{$item}) eq 'ARRAY') {
22758: push(@okvals,$item);
22759: }
22760: }
22761: } else {
22762: if (ref($by_location{$val}) eq 'ARRAY') {
22763: push(@okvals,$val);
22764: }
22765: }
22766: }
22767: @okvals = sort(@okvals);
22768: if (ref($domconfig{$action}) eq 'HASH') {
22769: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22770: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22771: if ($inuse == 0) {
22772: $changes{$prefix}{$type} = 1;
22773: } else {
22774: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22775: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22776: if (@changed > 0) {
22777: $changes{$prefix}{$type} = 1;
22778: }
22779: }
22780: } else {
22781: if ($inuse == 1) {
22782: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22783: $changes{$prefix}{$type} = 1;
22784: }
22785: }
22786: } else {
22787: if ($inuse == 1) {
22788: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22789: $changes{$prefix}{$type} = 1;
22790: }
22791: }
22792: } else {
22793: if ($inuse == 1) {
22794: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22795: $changes{$prefix}{$type} = 1;
22796: }
22797: }
22798: }
22799: }
22800: }
22801: }
1.336 raeburn 22802: if (keys(%changes)) {
22803: foreach my $prefix (keys(%changes)) {
22804: if (ref($changes{$prefix}) eq 'HASH') {
22805: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22806: delete($changes{$prefix});
22807: }
22808: } else {
22809: delete($changes{$prefix});
22810: }
22811: }
22812: }
1.275 raeburn 22813: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22814: if (keys(%changes) > 0) {
22815: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22816: $dom);
22817: if ($putresult eq 'ok') {
22818: if (ref($defaultshash{$action}) eq 'HASH') {
22819: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22820: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22821: }
1.293 raeburn 22822: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22823: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22824: }
22825: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22826: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22827: }
22828: }
22829: my $cachetime = 24*60*60;
22830: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22831: if (ref($lastactref) eq 'HASH') {
22832: $lastactref->{'domdefaults'} = 1;
22833: }
22834: if (keys(%changes) > 0) {
22835: my %titles = &ssl_titles();
22836: $resulttext = &mt('Changes made:').'<ul>';
22837: foreach my $prefix (@prefixes) {
22838: if (ref($changes{$prefix}) eq 'HASH') {
22839: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22840: foreach my $type (@{$types{$prefix}}) {
22841: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22842: my ($newvalue,$notinuse);
1.275 raeburn 22843: if (ref($defaultshash{$action}) eq 'HASH') {
22844: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22845: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22846: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22847: } else {
22848: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22849: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22850: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22851: }
22852: } else {
22853: $notinuse = 1;
1.275 raeburn 22854: }
22855: }
22856: }
1.344 raeburn 22857: if ($notinuse) {
22858: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22859: } elsif ($newvalue eq '') {
1.275 raeburn 22860: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22861: } else {
22862: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22863: }
22864: }
22865: }
22866: }
22867: $resulttext .= '</ul>';
22868: }
22869: }
22870: } else {
22871: $resulttext = $nochgmsg;
22872: }
22873: } else {
22874: $resulttext = '<span class="LC_error">'.
22875: &mt('An error occurred: [_1]',$putresult).'</span>';
22876: }
22877: } else {
22878: $resulttext = $nochgmsg;
22879: }
22880: return $resulttext;
22881: }
22882:
1.279 raeburn 22883: sub modify_trust {
22884: my ($dom,$lastactref,%domconfig) = @_;
22885: my (%by_ip,%by_location,@intdoms,@instdoms);
22886: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22887: my @locations = sort(keys(%by_location));
22888: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22889: my @types = ('exc','inc');
22890: my (%defaultshash,%changes);
22891: foreach my $prefix (@prefixes) {
22892: $defaultshash{'trust'}{$prefix} = {};
22893: }
22894: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22895: my $resulttext;
22896: foreach my $prefix (@prefixes) {
22897: foreach my $type (@types) {
22898: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22899: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22900: my @okvals;
22901: foreach my $val (@vals) {
22902: if ($val =~ /:/) {
22903: my @items = split(/:/,$val);
22904: foreach my $item (@items) {
22905: if (ref($by_location{$item}) eq 'ARRAY') {
22906: push(@okvals,$item);
22907: }
22908: }
22909: } else {
22910: if (ref($by_location{$val}) eq 'ARRAY') {
22911: push(@okvals,$val);
22912: }
22913: }
22914: }
22915: @okvals = sort(@okvals);
22916: if (ref($domconfig{'trust'}) eq 'HASH') {
22917: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22918: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22919: if ($inuse == 0) {
22920: $changes{$prefix}{$type} = 1;
22921: } else {
22922: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22923: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22924: if (@changed > 0) {
22925: $changes{$prefix}{$type} = 1;
22926: }
22927: }
22928: } else {
22929: if ($inuse == 1) {
22930: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22931: $changes{$prefix}{$type} = 1;
22932: }
22933: }
22934: } else {
22935: if ($inuse == 1) {
22936: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22937: $changes{$prefix}{$type} = 1;
22938: }
22939: }
22940: } else {
22941: if ($inuse == 1) {
22942: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22943: $changes{$prefix}{$type} = 1;
22944: }
22945: }
22946: }
22947: }
22948: my $nochgmsg = &mt('No changes made to trust settings.');
22949: if (keys(%changes) > 0) {
22950: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22951: $dom);
22952: if ($putresult eq 'ok') {
22953: if (ref($defaultshash{'trust'}) eq 'HASH') {
22954: foreach my $prefix (@prefixes) {
22955: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22956: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22957: }
22958: }
22959: }
22960: my $cachetime = 24*60*60;
22961: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22962: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22963: if (ref($lastactref) eq 'HASH') {
22964: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22965: $lastactref->{'trust'} = 1;
1.279 raeburn 22966: }
22967: if (keys(%changes) > 0) {
22968: my %lt = &trust_titles();
22969: $resulttext = &mt('Changes made:').'<ul>';
22970: foreach my $prefix (@prefixes) {
22971: if (ref($changes{$prefix}) eq 'HASH') {
22972: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22973: foreach my $type (@types) {
22974: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22975: my ($newvalue,$notinuse);
1.279 raeburn 22976: if (ref($defaultshash{'trust'}) eq 'HASH') {
22977: if (ref($defaultshash{'trust'}{$prefix})) {
22978: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22979: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22980: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22981: }
1.344 raeburn 22982: } else {
22983: $notinuse = 1;
1.279 raeburn 22984: }
22985: }
22986: }
1.344 raeburn 22987: if ($notinuse) {
22988: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22989: } elsif ($newvalue eq '') {
1.279 raeburn 22990: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22991: } else {
22992: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22993: }
22994: }
22995: }
22996: $resulttext .= '</ul>';
22997: }
22998: }
22999: $resulttext .= '</ul>';
23000: } else {
23001: $resulttext = $nochgmsg;
23002: }
23003: } else {
23004: $resulttext = '<span class="LC_error">'.
23005: &mt('An error occurred: [_1]',$putresult).'</span>';
23006: }
23007: } else {
23008: $resulttext = $nochgmsg;
23009: }
23010: return $resulttext;
23011: }
23012:
1.150 raeburn 23013: sub modify_loadbalancing {
23014: my ($dom,%domconfig) = @_;
23015: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23016: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23017: my ($othertitle,$usertypes,$types) =
23018: &Apache::loncommon::sorted_inst_types($dom);
23019: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23020: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23021: my @sparestypes = ('primary','default');
23022: my %typetitles = &sparestype_titles();
23023: my $resulttext;
1.342 raeburn 23024: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23025: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23026: %existing = %{$domconfig{'loadbalancing'}};
23027: }
23028: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23029: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23030: my ($saveloadbalancing,%defaultshash,%changes);
23031: my ($alltypes,$othertypes,$titles) =
23032: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23033: my %ruletitles = &offloadtype_text();
23034: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23035: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23036: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23037: if ($balancer eq '') {
23038: next;
23039: }
1.210 raeburn 23040: if (!exists($servers{$balancer})) {
1.171 raeburn 23041: if (exists($currbalancer{$balancer})) {
23042: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23043: }
1.171 raeburn 23044: next;
23045: }
23046: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23047: push(@{$changes{'delete'}},$balancer);
23048: next;
23049: }
23050: if (!exists($currbalancer{$balancer})) {
23051: push(@{$changes{'add'}},$balancer);
23052: }
23053: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23054: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23055: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23056: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23057: $saveloadbalancing = 1;
23058: }
23059: foreach my $sparetype (@sparestypes) {
23060: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23061: my @offloadto;
23062: foreach my $target (@targets) {
23063: if (($servers{$target}) && ($target ne $balancer)) {
23064: if ($sparetype eq 'default') {
23065: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23066: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23067: }
23068: }
1.171 raeburn 23069: unless(grep(/^\Q$target\E$/,@offloadto)) {
23070: push(@offloadto,$target);
23071: }
1.150 raeburn 23072: }
23073: }
1.284 raeburn 23074: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23075: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23076: push(@offloadto,$balancer);
23077: }
23078: }
23079: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23080: }
1.342 raeburn 23081: if ($env{'form.loadbalancing_cookie_'.$i}) {
23082: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
23083: if (exists($currbalancer{$balancer})) {
23084: unless ($currcookies{$balancer}) {
23085: $changes{'curr'}{$balancer}{'cookie'} = 1;
23086: }
23087: }
23088: } elsif (exists($currbalancer{$balancer})) {
23089: if ($currcookies{$balancer}) {
23090: $changes{'curr'}{$balancer}{'cookie'} = 1;
23091: }
23092: }
1.171 raeburn 23093: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23094: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23095: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23096: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23097: if (@targetdiffs > 0) {
1.171 raeburn 23098: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23099: }
1.171 raeburn 23100: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23101: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23102: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23103: }
23104: }
23105: }
23106: } else {
1.171 raeburn 23107: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23108: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23109: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23110: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23111: $changes{'curr'}{$balancer}{'targets'} = 1;
23112: }
1.150 raeburn 23113: }
23114: }
1.210 raeburn 23115: }
1.150 raeburn 23116: }
23117: my $ishomedom;
1.171 raeburn 23118: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23119: $ishomedom = 1;
1.150 raeburn 23120: }
23121: if (ref($alltypes) eq 'ARRAY') {
23122: foreach my $type (@{$alltypes}) {
23123: my $rule;
1.210 raeburn 23124: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23125: (!$ishomedom)) {
1.171 raeburn 23126: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23127: }
23128: if ($rule eq 'specific') {
1.255 raeburn 23129: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23130: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23131: $rule = $specifiedhost;
23132: }
1.150 raeburn 23133: }
1.171 raeburn 23134: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23135: if (ref($currrules{$balancer}) eq 'HASH') {
23136: if ($rule ne $currrules{$balancer}{$type}) {
23137: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23138: }
23139: } elsif ($rule ne '') {
1.171 raeburn 23140: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23141: }
23142: }
23143: }
1.171 raeburn 23144: }
23145: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23146: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23147: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23148: $defaultshash{'loadbalancing'} = {};
23149: }
23150: my $putresult = &Apache::lonnet::put_dom('configuration',
23151: \%defaultshash,$dom);
23152: if ($putresult eq 'ok') {
23153: if (keys(%changes) > 0) {
1.252 raeburn 23154: my %toupdate;
1.171 raeburn 23155: if (ref($changes{'delete'}) eq 'ARRAY') {
23156: foreach my $balancer (sort(@{$changes{'delete'}})) {
23157: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23158: $toupdate{$balancer} = 1;
1.150 raeburn 23159: }
1.171 raeburn 23160: }
23161: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23162: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23163: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23164: $toupdate{$balancer} = 1;
1.171 raeburn 23165: }
23166: }
23167: if (ref($changes{'curr'}) eq 'HASH') {
23168: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23169: $toupdate{$balancer} = 1;
1.171 raeburn 23170: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23171: if ($changes{'curr'}{$balancer}{'targets'}) {
23172: my %offloadstr;
23173: foreach my $sparetype (@sparestypes) {
23174: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23175: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23176: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23177: }
23178: }
1.150 raeburn 23179: }
1.171 raeburn 23180: if (keys(%offloadstr) == 0) {
23181: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23182: } else {
1.171 raeburn 23183: my $showoffload;
23184: foreach my $sparetype (@sparestypes) {
23185: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23186: if (defined($offloadstr{$sparetype})) {
23187: $showoffload .= $offloadstr{$sparetype};
23188: } else {
23189: $showoffload .= &mt('None');
23190: }
23191: $showoffload .= (' 'x3);
23192: }
23193: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23194: }
23195: }
23196: }
1.171 raeburn 23197: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23198: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23199: foreach my $type (@{$alltypes}) {
23200: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23201: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23202: my $balancetext;
23203: if ($rule eq '') {
23204: $balancetext = $ruletitles{'default'};
1.209 raeburn 23205: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23206: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23207: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23208: foreach my $sparetype (@sparestypes) {
23209: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23210: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23211: }
23212: }
1.253 raeburn 23213: foreach my $item (@{$alltypes}) {
23214: next if ($item =~ /^_LC_ipchange/);
23215: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23216: if ($hasrule eq 'homeserver') {
23217: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23218: } else {
23219: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23220: if ($servers{$hasrule}) {
23221: $toupdate{$hasrule} = 1;
23222: }
23223: }
23224: }
23225: }
1.254 raeburn 23226: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23227: $balancetext = $ruletitles{$rule};
23228: } else {
23229: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23230: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23231: if ($receiver) {
23232: $toupdate{$receiver};
23233: }
23234: }
23235: } else {
23236: $balancetext = $ruletitles{$rule};
1.252 raeburn 23237: }
1.171 raeburn 23238: } else {
23239: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23240: }
1.210 raeburn 23241: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23242: }
23243: }
23244: }
23245: }
1.342 raeburn 23246: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23247: if ($currcookies{$balancer}) {
23248: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23249: $balancer).'</li>';
23250: } else {
23251: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23252: $balancer).'</li>';
23253: }
1.342 raeburn 23254: }
1.375 raeburn 23255: }
23256: }
23257: if (keys(%toupdate)) {
23258: my %thismachine;
23259: my $updatedhere;
23260: my $cachetime = 60*60*24;
23261: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23262: foreach my $lonhost (keys(%toupdate)) {
23263: if ($thismachine{$lonhost}) {
23264: unless ($updatedhere) {
23265: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23266: $defaultshash{'loadbalancing'},
23267: $cachetime);
23268: $updatedhere = 1;
1.252 raeburn 23269: }
1.375 raeburn 23270: } else {
23271: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23272: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23273: }
1.150 raeburn 23274: }
1.171 raeburn 23275: }
23276: if ($resulttext ne '') {
23277: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23278: } else {
23279: $resulttext = $nochgmsg;
23280: }
23281: } else {
1.171 raeburn 23282: $resulttext = $nochgmsg;
1.150 raeburn 23283: }
23284: } else {
1.171 raeburn 23285: $resulttext = '<span class="LC_error">'.
23286: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23287: }
23288: } else {
1.171 raeburn 23289: $resulttext = $nochgmsg;
1.150 raeburn 23290: }
23291: return $resulttext;
23292: }
23293:
1.48 raeburn 23294: sub recurse_check {
23295: my ($chkcats,$categories,$depth,$name) = @_;
23296: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23297: my $chg = 0;
23298: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23299: my $category = $chkcats->[$depth]{$name}[$j];
23300: my $item;
23301: if ($category eq '') {
23302: $chg ++;
23303: } else {
23304: my $deeper = $depth + 1;
23305: $item = &escape($category).':'.&escape($name).':'.$depth;
23306: if ($chg) {
23307: $categories->{$item} -= $chg;
23308: }
23309: &recurse_check($chkcats,$categories,$deeper,$category);
23310: $deeper --;
23311: }
23312: }
23313: }
23314: return;
23315: }
23316:
23317: sub recurse_cat_deletes {
23318: my ($item,$coursecategories,$deletions) = @_;
23319: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23320: my $subdepth = $depth + 1;
23321: if (ref($coursecategories) eq 'HASH') {
23322: foreach my $subitem (keys(%{$coursecategories})) {
23323: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23324: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23325: delete($coursecategories->{$subitem});
23326: $deletions->{$subitem} = 1;
23327: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23328: }
1.48 raeburn 23329: }
23330: }
23331: return;
23332: }
23333:
1.125 raeburn 23334: sub active_dc_picker {
1.191 raeburn 23335: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23336: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23337: my @domcoord = keys(%domcoords);
23338: if (keys(%currhash)) {
23339: foreach my $dc (keys(%currhash)) {
23340: unless (exists($domcoords{$dc})) {
23341: push(@domcoord,$dc);
23342: }
23343: }
23344: }
23345: @domcoord = sort(@domcoord);
1.210 raeburn 23346: my $numdcs = scalar(@domcoord);
1.191 raeburn 23347: my $rows = 0;
23348: my $table;
1.125 raeburn 23349: if ($numdcs > 1) {
1.191 raeburn 23350: $table = '<table>';
23351: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23352: my $rem = $i%($numinrow);
23353: if ($rem == 0) {
23354: if ($i > 0) {
1.191 raeburn 23355: $table .= '</tr>';
1.125 raeburn 23356: }
1.191 raeburn 23357: $table .= '<tr>';
23358: $rows ++;
1.125 raeburn 23359: }
1.191 raeburn 23360: my $check = '';
23361: if ($inputtype eq 'radio') {
23362: if (keys(%currhash) == 0) {
23363: if (!$i) {
23364: $check = ' checked="checked"';
23365: }
23366: } elsif (exists($currhash{$domcoord[$i]})) {
23367: $check = ' checked="checked"';
23368: }
23369: } else {
23370: if (exists($currhash{$domcoord[$i]})) {
23371: $check = ' checked="checked"';
1.125 raeburn 23372: }
23373: }
1.191 raeburn 23374: if ($i == @domcoord - 1) {
1.125 raeburn 23375: my $colsleft = $numinrow - $rem;
23376: if ($colsleft > 1) {
1.191 raeburn 23377: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23378: } else {
1.191 raeburn 23379: $table .= '<td class="LC_left_item">';
1.125 raeburn 23380: }
23381: } else {
1.191 raeburn 23382: $table .= '<td class="LC_left_item">';
23383: }
23384: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23385: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23386: $table .= '<span class="LC_nobreak"><label>'.
23387: '<input type="'.$inputtype.'" name="'.$name.'"'.
23388: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23389: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23390: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23391: }
1.219 raeburn 23392: $table .= '</label></span></td>';
1.191 raeburn 23393: }
23394: $table .= '</tr></table>';
23395: } elsif ($numdcs == 1) {
1.219 raeburn 23396: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23397: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23398: if ($inputtype eq 'radio') {
1.247 raeburn 23399: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23400: if ($user ne $dcname.':'.$dcdom) {
23401: $table .= ' ('.$dcname.':'.$dcdom.')';
23402: }
1.191 raeburn 23403: } else {
23404: my $check;
23405: if (exists($currhash{$domcoord[0]})) {
23406: $check = ' checked="checked"';
1.125 raeburn 23407: }
1.247 raeburn 23408: $table = '<span class="LC_nobreak"><label>'.
23409: '<input type="checkbox" name="'.$name.'" '.
23410: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23411: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23412: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23413: }
1.220 raeburn 23414: $table .= '</label></span>';
1.191 raeburn 23415: $rows ++;
1.125 raeburn 23416: }
23417: }
1.191 raeburn 23418: return ($numdcs,$table,$rows);
1.125 raeburn 23419: }
23420:
1.137 raeburn 23421: sub usersession_titles {
23422: return &Apache::lonlocal::texthash(
23423: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23424: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23425: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23426: version => 'LON-CAPA version requirement',
1.138 raeburn 23427: excludedomain => 'Allow all, but exclude specific domains',
23428: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23429: primary => 'Primary (checked first)',
1.154 raeburn 23430: default => 'Default',
1.137 raeburn 23431: );
23432: }
23433:
1.152 raeburn 23434: sub id_for_thisdom {
23435: my (%servers) = @_;
23436: my %altids;
23437: foreach my $server (keys(%servers)) {
23438: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23439: if ($serverhome ne $server) {
23440: $altids{$serverhome} = $server;
23441: }
23442: }
23443: return %altids;
23444: }
23445:
1.150 raeburn 23446: sub count_servers {
23447: my ($currbalancer,%servers) = @_;
23448: my (@spares,$numspares);
23449: foreach my $lonhost (sort(keys(%servers))) {
23450: next if ($currbalancer eq $lonhost);
23451: push(@spares,$lonhost);
23452: }
23453: if ($currbalancer) {
23454: $numspares = scalar(@spares);
23455: } else {
23456: $numspares = scalar(@spares) - 1;
23457: }
23458: return ($numspares,@spares);
23459: }
23460:
23461: sub lonbalance_targets_js {
1.171 raeburn 23462: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23463: my $select = &mt('Select');
23464: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23465: if (ref($servers) eq 'HASH') {
23466: $alltargets = join("','",sort(keys(%{$servers})));
23467: my @homedoms;
23468: foreach my $server (sort(keys(%{$servers}))) {
23469: if (&Apache::lonnet::host_domain($server) eq $dom) {
23470: push(@homedoms,'1');
23471: } else {
23472: push(@homedoms,'0');
23473: }
23474: }
23475: $allishome = join("','",@homedoms);
23476: }
23477: if (ref($types) eq 'ARRAY') {
23478: if (@{$types} > 0) {
23479: @alltypes = @{$types};
23480: }
23481: }
23482: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23483: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23484: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23485: if (ref($settings) eq 'HASH') {
23486: %existing = %{$settings};
23487: }
23488: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23489: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23490: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23491: return <<"END";
23492:
23493: <script type="text/javascript">
23494: // <![CDATA[
23495:
1.171 raeburn 23496: currBalancers = new Array('$balancers');
23497:
23498: function toggleTargets(balnum) {
23499: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23500: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23501: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23502: var prevbalancer = prevhostitem.value;
23503: var baltotal = document.getElementById('loadbalancing_total').value;
23504: prevhostitem.value = balancer;
23505: if (prevbalancer != '') {
23506: var prevIdx = currBalancers.indexOf(prevbalancer);
23507: if (prevIdx != -1) {
23508: currBalancers.splice(prevIdx,1);
23509: }
23510: }
1.150 raeburn 23511: if (balancer == '') {
1.171 raeburn 23512: hideSpares(balnum);
1.150 raeburn 23513: } else {
1.171 raeburn 23514: var currIdx = currBalancers.indexOf(balancer);
23515: if (currIdx == -1) {
23516: currBalancers.push(balancer);
23517: }
1.150 raeburn 23518: var homedoms = new Array('$allishome');
1.171 raeburn 23519: var ishomedom = homedoms[lonhostitem.selectedIndex];
23520: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23521: }
1.171 raeburn 23522: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23523: return;
23524: }
23525:
1.171 raeburn 23526: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23527: var alltargets = new Array('$alltargets');
23528: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23529: var offloadtypes = new Array('primary','default');
23530:
1.171 raeburn 23531: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23532: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23533:
1.151 raeburn 23534: for (var i=0; i<offloadtypes.length; i++) {
23535: var count = 0;
23536: for (var j=0; j<alltargets.length; j++) {
23537: if (alltargets[j] != balancer) {
1.171 raeburn 23538: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23539: item.value = alltargets[j];
23540: item.style.textAlign='left';
23541: item.style.textFace='normal';
23542: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23543: if (currBalancers.indexOf(alltargets[j]) == -1) {
23544: item.disabled = '';
23545: } else {
23546: item.disabled = 'disabled';
23547: item.checked = false;
23548: }
1.151 raeburn 23549: count ++;
23550: }
1.150 raeburn 23551: }
23552: }
1.151 raeburn 23553: for (var k=0; k<insttypes.length; k++) {
23554: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23555: if (ishomedom == 1) {
1.171 raeburn 23556: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23557: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23558: } else {
1.171 raeburn 23559: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23560: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23561: }
23562: } else {
1.171 raeburn 23563: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23564: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23565: }
1.151 raeburn 23566: if ((insttypes[k] != '_LC_external') &&
23567: ((insttypes[k] != '_LC_internetdom') ||
23568: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23569: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23570: item.options.length = 0;
23571: item.options[0] = new Option("","",true,true);
1.210 raeburn 23572: var idx = 0;
1.151 raeburn 23573: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23574: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23575: idx ++;
23576: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23577: }
23578: }
23579: }
23580: }
23581: return;
23582: }
23583:
1.171 raeburn 23584: function hideSpares(balnum) {
1.150 raeburn 23585: var alltargets = new Array('$alltargets');
23586: var insttypes = new Array('$allinsttypes');
23587: var offloadtypes = new Array('primary','default');
23588:
1.171 raeburn 23589: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23590: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23591:
23592: var total = alltargets.length - 1;
23593: for (var i=0; i<offloadtypes; i++) {
23594: for (var j=0; j<total; j++) {
1.171 raeburn 23595: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23596: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23597: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23598: }
1.150 raeburn 23599: }
23600: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23601: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23602: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23603: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23604: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23605: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23606: }
23607: }
23608: return;
23609: }
23610:
1.171 raeburn 23611: function checkOffloads(item,balnum,type) {
1.150 raeburn 23612: var alltargets = new Array('$alltargets');
23613: var offloadtypes = new Array('primary','default');
23614: if (item.checked) {
23615: var total = alltargets.length - 1;
23616: var other;
23617: if (type == offloadtypes[0]) {
1.151 raeburn 23618: other = offloadtypes[1];
1.150 raeburn 23619: } else {
1.151 raeburn 23620: other = offloadtypes[0];
1.150 raeburn 23621: }
23622: for (var i=0; i<total; i++) {
1.171 raeburn 23623: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23624: if (server == item.value) {
1.171 raeburn 23625: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23626: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23627: }
23628: }
23629: }
23630: }
23631: return;
23632: }
23633:
1.171 raeburn 23634: function singleServerToggle(balnum,type) {
23635: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23636: if (offloadtoSelIdx == 0) {
1.171 raeburn 23637: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23638: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23639:
23640: } else {
1.171 raeburn 23641: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23642: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23643: }
23644: return;
23645: }
23646:
1.171 raeburn 23647: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23648: if (type == '_LC_external') {
1.171 raeburn 23649: return;
1.150 raeburn 23650: }
1.171 raeburn 23651: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23652: for (var i=0; i<typesRules.length; i++) {
23653: if (formname.elements[typesRules[i]].checked) {
23654: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23655: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23656: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23657: } else {
1.171 raeburn 23658: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23659: }
23660: }
23661: }
23662: return;
23663: }
23664:
23665: function balancerDeleteChange(balnum) {
23666: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23667: var baltotal = document.getElementById('loadbalancing_total').value;
23668: var addtarget;
23669: var removetarget;
23670: var action = 'delete';
23671: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23672: var lonhost = hostitem.value;
23673: var currIdx = currBalancers.indexOf(lonhost);
23674: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23675: if (currIdx != -1) {
23676: currBalancers.splice(currIdx,1);
23677: }
23678: addtarget = lonhost;
23679: } else {
23680: if (currIdx == -1) {
23681: currBalancers.push(lonhost);
23682: }
23683: removetarget = lonhost;
23684: action = 'undelete';
23685: }
23686: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23687: }
23688: return;
23689: }
23690:
23691: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23692: if (baltotal > 1) {
23693: var offloadtypes = new Array('primary','default');
23694: var alltargets = new Array('$alltargets');
23695: var insttypes = new Array('$allinsttypes');
23696: for (var i=0; i<baltotal; i++) {
23697: if (i != balnum) {
23698: for (var j=0; j<offloadtypes.length; j++) {
23699: var total = alltargets.length - 1;
23700: for (var k=0; k<total; k++) {
23701: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23702: var server = serveritem.value;
23703: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23704: if (server == addtarget) {
23705: serveritem.disabled = '';
23706: }
23707: }
23708: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23709: if (server == removetarget) {
23710: serveritem.disabled = 'disabled';
23711: serveritem.checked = false;
23712: }
23713: }
23714: }
23715: }
23716: for (var j=0; j<insttypes.length; j++) {
23717: if (insttypes[j] != '_LC_external') {
23718: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23719: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23720: var currSel = singleserver.selectedIndex;
23721: var currVal = singleserver.options[currSel].value;
23722: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23723: var numoptions = singleserver.options.length;
23724: var needsnew = 1;
23725: for (var k=0; k<numoptions; k++) {
23726: if (singleserver.options[k] == addtarget) {
23727: needsnew = 0;
23728: break;
23729: }
23730: }
23731: if (needsnew == 1) {
23732: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23733: }
23734: }
23735: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23736: singleserver.options.length = 0;
23737: if ((currVal) && (currVal != removetarget)) {
23738: singleserver.options[0] = new Option("","",false,false);
23739: } else {
23740: singleserver.options[0] = new Option("","",true,true);
23741: }
23742: var idx = 0;
23743: for (var m=0; m<alltargets.length; m++) {
23744: if (currBalancers.indexOf(alltargets[m]) == -1) {
23745: idx ++;
23746: if (currVal == alltargets[m]) {
23747: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23748: } else {
23749: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23750: }
23751: }
23752: }
23753: }
23754: }
23755: }
23756: }
1.150 raeburn 23757: }
23758: }
23759: }
23760: return;
23761: }
23762:
1.152 raeburn 23763: // ]]>
23764: </script>
23765:
23766: END
23767: }
23768:
1.372 raeburn 23769:
1.152 raeburn 23770: sub new_spares_js {
23771: my @sparestypes = ('primary','default');
23772: my $types = join("','",@sparestypes);
23773: my $select = &mt('Select');
23774: return <<"END";
23775:
23776: <script type="text/javascript">
23777: // <![CDATA[
23778:
23779: function updateNewSpares(formname,lonhost) {
23780: var types = new Array('$types');
23781: var include = new Array();
23782: var exclude = new Array();
23783: for (var i=0; i<types.length; i++) {
23784: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23785: for (var j=0; j<spareboxes.length; j++) {
23786: if (formname.elements[spareboxes[j]].checked) {
23787: exclude.push(formname.elements[spareboxes[j]].value);
23788: } else {
23789: include.push(formname.elements[spareboxes[j]].value);
23790: }
23791: }
23792: }
23793: for (var i=0; i<types.length; i++) {
23794: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23795: var selIdx = newSpare.selectedIndex;
23796: var currnew = newSpare.options[selIdx].value;
23797: var okSpares = new Array();
23798: for (var j=0; j<newSpare.options.length; j++) {
23799: var possible = newSpare.options[j].value;
23800: if (possible != '') {
23801: if (exclude.indexOf(possible) == -1) {
23802: okSpares.push(possible);
23803: } else {
23804: if (currnew == possible) {
23805: selIdx = 0;
23806: }
23807: }
23808: }
23809: }
23810: for (var k=0; k<include.length; k++) {
23811: if (okSpares.indexOf(include[k]) == -1) {
23812: okSpares.push(include[k]);
23813: }
23814: }
23815: okSpares.sort();
23816: newSpare.options.length = 0;
23817: if (selIdx == 0) {
23818: newSpare.options[0] = new Option("$select","",true,true);
23819: } else {
23820: newSpare.options[0] = new Option("$select","",false,false);
23821: }
23822: for (var m=0; m<okSpares.length; m++) {
23823: var idx = m+1;
23824: var selThis = 0;
23825: if (selIdx != 0) {
23826: if (okSpares[m] == currnew) {
23827: selThis = 1;
23828: }
23829: }
23830: if (selThis == 1) {
23831: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23832: } else {
23833: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23834: }
23835: }
23836: }
23837: return;
23838: }
23839:
23840: function checkNewSpares(lonhost,type) {
23841: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23842: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23843: if (chosen != '') {
1.152 raeburn 23844: var othertype;
23845: var othernewSpare;
23846: if (type == 'primary') {
23847: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23848: }
23849: if (type == 'default') {
23850: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23851: }
23852: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23853: othernewSpare.selectedIndex = 0;
23854: }
23855: }
23856: return;
23857: }
23858:
23859: // ]]>
23860: </script>
23861:
23862: END
23863:
23864: }
23865:
23866: sub common_domprefs_js {
23867: return <<"END";
23868:
23869: <script type="text/javascript">
23870: // <![CDATA[
23871:
1.150 raeburn 23872: function getIndicesByName(formname,item) {
1.152 raeburn 23873: var group = new Array();
1.150 raeburn 23874: for (var i=0;i<formname.elements.length;i++) {
23875: if (formname.elements[i].name == item) {
1.152 raeburn 23876: group.push(formname.elements[i].id);
1.150 raeburn 23877: }
23878: }
1.152 raeburn 23879: return group;
1.150 raeburn 23880: }
23881:
23882: // ]]>
23883: </script>
23884:
23885: END
1.152 raeburn 23886:
1.150 raeburn 23887: }
23888:
1.165 raeburn 23889: sub recaptcha_js {
23890: my %lt = &captcha_phrases();
23891: return <<"END";
23892:
23893: <script type="text/javascript">
23894: // <![CDATA[
23895:
23896: function updateCaptcha(caller,context) {
23897: var privitem;
23898: var pubitem;
23899: var privtext;
23900: var pubtext;
1.269 raeburn 23901: var versionitem;
23902: var versiontext;
1.165 raeburn 23903: if (document.getElementById(context+'_recaptchapub')) {
23904: pubitem = document.getElementById(context+'_recaptchapub');
23905: } else {
23906: return;
23907: }
23908: if (document.getElementById(context+'_recaptchapriv')) {
23909: privitem = document.getElementById(context+'_recaptchapriv');
23910: } else {
23911: return;
23912: }
23913: if (document.getElementById(context+'_recaptchapubtxt')) {
23914: pubtext = document.getElementById(context+'_recaptchapubtxt');
23915: } else {
23916: return;
23917: }
23918: if (document.getElementById(context+'_recaptchaprivtxt')) {
23919: privtext = document.getElementById(context+'_recaptchaprivtxt');
23920: } else {
23921: return;
23922: }
1.269 raeburn 23923: if (document.getElementById(context+'_recaptchaversion')) {
23924: versionitem = document.getElementById(context+'_recaptchaversion');
23925: } else {
23926: return;
23927: }
23928: if (document.getElementById(context+'_recaptchavertxt')) {
23929: versiontext = document.getElementById(context+'_recaptchavertxt');
23930: } else {
23931: return;
23932: }
1.165 raeburn 23933: if (caller.checked) {
23934: if (caller.value == 'recaptcha') {
23935: pubitem.type = 'text';
23936: privitem.type = 'text';
23937: pubitem.size = '40';
23938: privitem.size = '40';
23939: pubtext.innerHTML = "$lt{'pub'}";
23940: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23941: versionitem.type = 'text';
23942: versionitem.size = '3';
1.289 raeburn 23943: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23944: } else {
23945: pubitem.type = 'hidden';
23946: privitem.type = 'hidden';
1.269 raeburn 23947: versionitem.type = 'hidden';
1.165 raeburn 23948: pubtext.innerHTML = '';
23949: privtext.innerHTML = '';
1.269 raeburn 23950: versiontext.innerHTML = '';
1.165 raeburn 23951: }
23952: }
23953: return;
23954: }
23955:
23956: // ]]>
23957: </script>
23958:
23959: END
23960:
23961: }
23962:
1.236 raeburn 23963: sub toggle_display_js {
1.192 raeburn 23964: return <<"END";
23965:
23966: <script type="text/javascript">
23967: // <![CDATA[
23968:
1.236 raeburn 23969: function toggleDisplay(domForm,caller) {
23970: if (document.getElementById(caller)) {
23971: var divitem = document.getElementById(caller);
23972: var optionsElement = domForm.coursecredits;
1.264 raeburn 23973: var checkval = 1;
23974: var dispval = 'block';
1.303 raeburn 23975: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23976: if (caller == 'emailoptions') {
1.372 raeburn 23977: optionsElement = domForm.cancreate_email;
1.236 raeburn 23978: }
1.257 raeburn 23979: if (caller == 'studentsubmission') {
23980: optionsElement = domForm.postsubmit;
23981: }
1.264 raeburn 23982: if (caller == 'cloneinstcode') {
23983: optionsElement = domForm.canclone;
23984: checkval = 'instcode';
23985: }
1.303 raeburn 23986: if (selfcreateRegExp.test(caller)) {
23987: optionsElement = domForm.elements[caller];
23988: checkval = 'other';
23989: dispval = 'inline'
23990: }
1.236 raeburn 23991: if (optionsElement.length) {
1.192 raeburn 23992: var currval;
1.236 raeburn 23993: for (var i=0; i<optionsElement.length; i++) {
23994: if (optionsElement[i].checked) {
23995: currval = optionsElement[i].value;
1.192 raeburn 23996: }
23997: }
1.264 raeburn 23998: if (currval == checkval) {
23999: divitem.style.display = dispval;
1.192 raeburn 24000: } else {
1.236 raeburn 24001: divitem.style.display = 'none';
1.192 raeburn 24002: }
24003: }
24004: }
24005: return;
24006: }
24007:
24008: // ]]>
24009: </script>
24010:
24011: END
24012:
24013: }
24014:
1.165 raeburn 24015: sub captcha_phrases {
24016: return &Apache::lonlocal::texthash (
24017: priv => 'Private key',
24018: pub => 'Public key',
24019: original => 'original (CAPTCHA)',
24020: recaptcha => 'successor (ReCAPTCHA)',
24021: notused => 'unused',
1.289 raeburn 24022: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24023: );
24024: }
24025:
1.205 raeburn 24026: sub devalidate_remote_domconfs {
1.212 raeburn 24027: my ($dom,$cachekeys) = @_;
24028: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24029: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24030: my %thismachine;
24031: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24032: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24033: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24034: 'ipaccess','trust');
1.386 raeburn 24035: my %cache_by_lonhost;
24036: if (exists($cachekeys->{'samllanding'})) {
24037: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24038: my %landing = %{$cachekeys->{'samllanding'}};
24039: my %domservers = &Apache::lonnet::get_servers($dom);
24040: if (keys(%domservers)) {
24041: foreach my $server (keys(%domservers)) {
24042: my @cached;
24043: next if ($thismachine{$server});
24044: if ($landing{$server}) {
24045: push(@cached,&escape('samllanding').':'.&escape($server));
24046: }
24047: if (@cached) {
24048: $cache_by_lonhost{$server} = \@cached;
24049: }
24050: }
24051: }
24052: }
24053: }
1.260 raeburn 24054: if (keys(%servers)) {
1.205 raeburn 24055: foreach my $server (keys(%servers)) {
24056: next if ($thismachine{$server});
1.212 raeburn 24057: my @cached;
24058: foreach my $name (@posscached) {
24059: if ($cachekeys->{$name}) {
1.388 raeburn 24060: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24061: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24062: foreach my $key (keys(%{$cachekeys->{$name}})) {
24063: push(@cached,&escape($name).':'.&escape($key));
24064: }
24065: }
24066: } else {
24067: push(@cached,&escape($name).':'.&escape($dom));
24068: }
1.212 raeburn 24069: }
24070: }
1.386 raeburn 24071: if ((exists($cache_by_lonhost{$server})) &&
24072: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24073: push(@cached,@{$cache_by_lonhost{$server}});
24074: }
1.212 raeburn 24075: if (@cached) {
24076: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24077: }
1.205 raeburn 24078: }
24079: }
24080: return;
24081: }
24082:
1.3 raeburn 24083: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>