Annotation of loncom/interface/domainprefs.pm, revision 1.421
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.421 ! raeburn 4: # $Id: domainprefs.pm,v 1.420 2023/03/08 15:06:45 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.419 raeburn 170: use Apache::courseprefs();
1.69 raeburn 171: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 172: use LONCAPA::Enrollment;
1.81 raeburn 173: use LONCAPA::lonauthcgi();
1.275 raeburn 174: use LONCAPA::SSL;
1.9 raeburn 175: use File::Copy;
1.43 raeburn 176: use Locale::Language;
1.62 raeburn 177: use DateTime::TimeZone;
1.68 raeburn 178: use DateTime::Locale;
1.267 raeburn 179: use Time::HiRes qw( sleep );
1.373 raeburn 180: use Net::CIDR;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 ! raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
! 225: 'privacy','passwords','proctoring','wafproxy','ipaccess'],$dom);
1.320 raeburn 226: my %encconfig =
1.405 raeburn 227: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.297 raeburn 228: if (ref($domconfig{'ltitools'}) eq 'HASH') {
229: if (ref($encconfig{'ltitools'}) eq 'HASH') {
230: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 231: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
232: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 ! raeburn 233: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.297 raeburn 234: }
235: }
236: }
237: }
1.320 raeburn 238: if (ref($domconfig{'lti'}) eq 'HASH') {
239: if (ref($encconfig{'lti'}) eq 'HASH') {
240: foreach my $id (keys(%{$domconfig{'lti'}})) {
241: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
243: foreach my $item ('key','secret') {
244: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
245: }
246: }
247: }
248: }
249: }
1.405 raeburn 250: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 251: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 252: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 253: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
254: unless ($id =~ /^\d+$/) {
255: delete($domconfig{'ltisec'}{'linkprot'}{$id});
256: }
257: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 258: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
259: foreach my $item ('key','secret') {
1.406 raeburn 260: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 261: }
262: }
263: }
264: }
265: }
266: }
1.372 raeburn 267: if (ref($domconfig{'proctoring'}) eq 'HASH') {
268: if (ref($encconfig{'proctoring'}) eq 'HASH') {
269: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
270: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
271: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
272: foreach my $item ('key','secret') {
273: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
274: }
275: }
276: }
277: }
278: }
1.394 raeburn 279: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
280: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 281: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 282: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 283: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 284: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
285: 'trust','lti');
1.171 raeburn 286: my %existing;
287: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
288: %existing = %{$domconfig{'loadbalancing'}};
289: }
290: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 291: push(@prefs_order,'loadbalancing');
292: }
1.30 raeburn 293: my %prefs = (
294: 'rolecolors' =>
295: { text => 'Default color schemes',
1.67 raeburn 296: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 297: header => [{col1 => 'Student Settings',
298: col2 => '',},
299: {col1 => 'Coordinator Settings',
300: col2 => '',},
301: {col1 => 'Author Settings',
302: col2 => '',},
303: {col1 => 'Administrator Settings',
304: col2 => '',}],
1.230 raeburn 305: print => \&print_rolecolors,
306: modify => \&modify_rolecolors,
1.30 raeburn 307: },
1.110 raeburn 308: 'login' =>
1.30 raeburn 309: { text => 'Log-in page options',
1.67 raeburn 310: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 311: header => [{col1 => 'Log-in Page Items',
312: col2 => '',},
313: {col1 => 'Log-in Help',
1.256 raeburn 314: col2 => 'Value'},
315: {col1 => 'Custom HTML in document head',
1.386 raeburn 316: col2 => 'Value'},
317: {col1 => 'SSO',
318: col2 => 'Dual login: SSO and non-SSO options'},
319: ],
1.230 raeburn 320: print => \&print_login,
321: modify => \&modify_login,
1.30 raeburn 322: },
1.43 raeburn 323: 'defaults' =>
1.236 raeburn 324: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 325: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 326: header => [{col1 => 'Setting',
1.236 raeburn 327: col2 => 'Value'},
328: {col1 => 'Institutional user types',
1.409 raeburn 329: col2 => 'Name displayed'},
330: {col1 => 'Mapping for missing usernames via standard log-in',
331: col2 => 'Rules in use'}],
1.230 raeburn 332: print => \&print_defaults,
333: modify => \&modify_defaults,
1.43 raeburn 334: },
1.381 raeburn 335: 'wafproxy' =>
336: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 337: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 338: header => [{col1 => 'Domain(s)',
339: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 340: },
1.381 raeburn 341: {col1 => 'Domain(s)',
342: col2 => 'WAF Configuration',}],
1.373 raeburn 343: print => \&print_wafproxy,
1.381 raeburn 344: modify => \&modify_wafproxy,
1.373 raeburn 345: },
1.354 raeburn 346: 'passwords' =>
347: { text => 'Passwords (Internal authentication)',
348: help => 'Domain_Configuration_Passwords',
349: header => [{col1 => 'Resetting Forgotten Password',
350: col2 => 'Settings'},
351: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
352: col2 => 'Settings'},
353: {col1 => 'Rules for LON-CAPA Passwords',
354: col2 => 'Settings'},
355: {col1 => 'Course Owner Changing Student Passwords',
356: col2 => 'Settings'}],
357: print => \&print_passwords,
358: modify => \&modify_passwords,
359: },
1.30 raeburn 360: 'quotas' =>
1.413 raeburn 361: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 362: help => 'Domain_Configuration_Quotas',
1.77 raeburn 363: header => [{col1 => 'User affiliation',
1.72 raeburn 364: col2 => 'Available tools',
1.213 raeburn 365: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 366: print => \&print_quotas,
367: modify => \&modify_quotas,
1.30 raeburn 368: },
369: 'autoenroll' =>
370: { text => 'Auto-enrollment settings',
1.67 raeburn 371: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 372: header => [{col1 => 'Configuration setting',
373: col2 => 'Value(s)'}],
1.230 raeburn 374: print => \&print_autoenroll,
375: modify => \&modify_autoenroll,
1.30 raeburn 376: },
377: 'autoupdate' =>
378: { text => 'Auto-update settings',
1.67 raeburn 379: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 380: header => [{col1 => 'Setting',
381: col2 => 'Value',},
1.131 raeburn 382: {col1 => 'Setting',
383: col2 => 'Affiliation'},
1.43 raeburn 384: {col1 => 'User population',
1.227 bisitz 385: col2 => 'Updatable user data'}],
1.230 raeburn 386: print => \&print_autoupdate,
387: modify => \&modify_autoupdate,
1.30 raeburn 388: },
1.125 raeburn 389: 'autocreate' =>
390: { text => 'Auto-course creation settings',
391: help => 'Domain_Configuration_Auto_Creation',
392: header => [{col1 => 'Configuration Setting',
393: col2 => 'Value',}],
1.230 raeburn 394: print => \&print_autocreate,
395: modify => \&modify_autocreate,
1.125 raeburn 396: },
1.30 raeburn 397: 'directorysrch' =>
1.277 raeburn 398: { text => 'Directory searches',
1.67 raeburn 399: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 400: header => [{col1 => 'Institutional Directory Setting',
401: col2 => 'Value',},
402: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 403: col2 => 'Value',}],
1.230 raeburn 404: print => \&print_directorysrch,
405: modify => \&modify_directorysrch,
1.30 raeburn 406: },
407: 'contacts' =>
1.286 raeburn 408: { text => 'E-mail addresses and helpform',
1.67 raeburn 409: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 410: header => [{col1 => 'Default e-mail addresses',
411: col2 => 'Value',},
412: {col1 => 'Recipient(s) for notifications',
413: col2 => 'Value',},
1.340 raeburn 414: {col1 => 'Nightly status check e-mail',
415: col2 => 'Settings',},
1.286 raeburn 416: {col1 => 'Ask helpdesk form settings',
417: col2 => 'Value',},],
1.230 raeburn 418: print => \&print_contacts,
419: modify => \&modify_contacts,
1.30 raeburn 420: },
421: 'usercreation' =>
422: { text => 'User creation',
1.67 raeburn 423: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 424: header => [{col1 => 'Format rule type',
425: col2 => 'Format rules in force'},
1.34 raeburn 426: {col1 => 'User account creation',
427: col2 => 'Usernames which may be created',},
1.30 raeburn 428: {col1 => 'Context',
1.43 raeburn 429: col2 => 'Assignable authentication types'}],
1.230 raeburn 430: print => \&print_usercreation,
431: modify => \&modify_usercreation,
1.30 raeburn 432: },
1.224 raeburn 433: 'selfcreation' =>
434: { text => 'Users self-creating accounts',
435: help => 'Domain_Configuration_Self_Creation',
436: header => [{col1 => 'Self-creation with institutional username',
437: col2 => 'Enabled?'},
438: {col1 => 'Institutional user type (login/SSO self-creation)',
439: col2 => 'Information user can enter'},
1.303 raeburn 440: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 441: col2 => 'Settings'}],
1.230 raeburn 442: print => \&print_selfcreation,
443: modify => \&modify_selfcreation,
1.224 raeburn 444: },
1.69 raeburn 445: 'usermodification' =>
1.33 raeburn 446: { text => 'User modification',
1.67 raeburn 447: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 448: header => [{col1 => 'Target user has role',
1.227 bisitz 449: col2 => 'User information updatable in author context'},
1.33 raeburn 450: {col1 => 'Target user has role',
1.227 bisitz 451: col2 => 'User information updatable in course context'}],
1.230 raeburn 452: print => \&print_usermodification,
453: modify => \&modify_usermodification,
1.33 raeburn 454: },
1.69 raeburn 455: 'scantron' =>
1.346 raeburn 456: { text => 'Bubblesheet format',
1.67 raeburn 457: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 458: header => [ {col1 => 'Bubblesheet format file',
459: col2 => ''},
460: {col1 => 'Bubblesheet data upload formats',
461: col2 => 'Settings'}],
1.230 raeburn 462: print => \&print_scantron,
463: modify => \&modify_scantron,
1.46 raeburn 464: },
1.86 raeburn 465: 'requestcourses' =>
466: {text => 'Request creation of courses',
467: help => 'Domain_Configuration_Request_Courses',
468: header => [{col1 => 'User affiliation',
1.102 raeburn 469: col2 => 'Availability/Processing of requests',},
470: {col1 => 'Setting',
1.216 raeburn 471: col2 => 'Value'},
472: {col1 => 'Available textbooks',
1.235 raeburn 473: col2 => ''},
1.242 raeburn 474: {col1 => 'Available templates',
475: col2 => ''},
1.235 raeburn 476: {col1 => 'Validation (not official courses)',
477: col2 => 'Value'},],
1.230 raeburn 478: print => \&print_quotas,
479: modify => \&modify_quotas,
1.86 raeburn 480: },
1.163 raeburn 481: 'requestauthor' =>
1.223 bisitz 482: {text => 'Request Authoring Space',
1.163 raeburn 483: help => 'Domain_Configuration_Request_Author',
484: header => [{col1 => 'User affiliation',
485: col2 => 'Availability/Processing of requests',},
486: {col1 => 'Setting',
487: col2 => 'Value'}],
1.230 raeburn 488: print => \&print_quotas,
489: modify => \&modify_quotas,
1.163 raeburn 490: },
1.69 raeburn 491: 'coursecategories' =>
1.120 raeburn 492: { text => 'Cataloging of courses/communities',
1.67 raeburn 493: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 494: header => [{col1 => 'Catalog type/availability',
495: col2 => '',},
496: {col1 => 'Category settings for standard catalog',
1.57 raeburn 497: col2 => '',},
498: {col1 => 'Categories',
499: col2 => '',
500: }],
1.230 raeburn 501: print => \&print_coursecategories,
502: modify => \&modify_coursecategories,
1.69 raeburn 503: },
504: 'serverstatuses' =>
1.77 raeburn 505: {text => 'Access to server status pages',
1.69 raeburn 506: help => 'Domain_Configuration_Server_Status',
507: header => [{col1 => 'Status Page',
508: col2 => 'Other named users',
509: col3 => 'Specific IPs',
510: }],
1.230 raeburn 511: print => \&print_serverstatuses,
512: modify => \&modify_serverstatuses,
1.69 raeburn 513: },
1.118 jms 514: 'helpsettings' =>
1.282 raeburn 515: {text => 'Support settings',
1.118 jms 516: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 517: header => [{col1 => 'Help Page Settings (logged-in users)',
518: col2 => 'Value'},
519: {col1 => 'Helpdesk Roles',
520: col2 => 'Settings'},],
1.230 raeburn 521: print => \&print_helpsettings,
522: modify => \&modify_helpsettings,
1.118 jms 523: },
1.121 raeburn 524: 'coursedefaults' =>
525: {text => 'Course/Community defaults',
526: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 527: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
528: col2 => 'Value',},
529: {col1 => 'Defaults which can be overridden for each course by a DC',
530: col2 => 'Value',},],
1.230 raeburn 531: print => \&print_coursedefaults,
532: modify => \&modify_coursedefaults,
1.121 raeburn 533: },
1.231 raeburn 534: 'selfenrollment' =>
535: {text => 'Self-enrollment in Course/Community',
536: help => 'Domain_Configuration_Selfenrollment',
537: header => [{col1 => 'Configuration Rights',
538: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
539: {col1 => 'Defaults',
540: col2 => 'Value'},
541: {col1 => 'Self-enrollment validation (optional)',
542: col2 => 'Value'},],
543: print => \&print_selfenrollment,
544: modify => \&modify_selfenrollment,
545: },
1.120 raeburn 546: 'privacy' =>
1.357 raeburn 547: {text => 'Availability of User Information',
1.120 raeburn 548: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 549: header => [{col1 => 'Role assigned in different domain',
550: col2 => 'Approval options'},
551: {col1 => 'Role assigned in different domain to user of type',
552: col2 => 'User information available in that domain'},
553: {col1 => "Role assigned in user's domain",
554: col2 => 'Information viewable by privileged user'},
555: {col1 => "Role assigned in user's domain",
556: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 557: print => \&print_privacy,
558: modify => \&modify_privacy,
1.120 raeburn 559: },
1.141 raeburn 560: 'usersessions' =>
1.145 raeburn 561: {text => 'User session hosting/offloading',
1.137 raeburn 562: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 563: header => [{col1 => 'Domain server',
564: col2 => 'Servers to offload sessions to when busy'},
565: {col1 => 'Hosting of users from other domains',
1.137 raeburn 566: col2 => 'Rules'},
567: {col1 => "Hosting domain's own users elsewhere",
568: col2 => 'Rules'}],
1.230 raeburn 569: print => \&print_usersessions,
570: modify => \&modify_usersessions,
1.137 raeburn 571: },
1.279 raeburn 572: 'loadbalancing' =>
1.185 raeburn 573: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 574: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 575: header => [{col1 => 'Balancers',
1.150 raeburn 576: col2 => 'Default destinations',
1.183 bisitz 577: col3 => 'User affiliation',
1.150 raeburn 578: col4 => 'Overrides'},
579: ],
1.230 raeburn 580: print => \&print_loadbalancing,
581: modify => \&modify_loadbalancing,
1.150 raeburn 582: },
1.279 raeburn 583: 'ltitools' =>
1.267 raeburn 584: {text => 'External Tools (LTI)',
1.296 raeburn 585: help => 'Domain_Configuration_LTI_Tools',
1.421 ! raeburn 586: header => [{col1 => 'Encryption of shared secrets',
! 587: col2 => 'Settings'},
! 588: {col1 => 'Rules for shared secrets',
! 589: col2 => 'Settings'},
! 590: {col1 => 'Providers',
! 591: col2 => 'Settings',}],
1.267 raeburn 592: print => \&print_ltitools,
593: modify => \&modify_ltitools,
594: },
1.372 raeburn 595: 'proctoring' =>
596: {text => 'Remote Proctoring Integration',
597: help => 'Domain_Configuration_Proctoring',
598: header => [{col1 => 'Name',
599: col2 => 'Configuration'}],
600: print => \&print_proctoring,
601: modify => \&modify_proctoring,
602: },
1.279 raeburn 603: 'ssl' =>
1.275 raeburn 604: {text => 'LON-CAPA Network (SSL)',
605: help => 'Domain_Configuration_Network_SSL',
606: header => [{col1 => 'Server',
607: col2 => 'Certificate Status'},
608: {col1 => 'Connections to other servers',
609: col2 => 'Rules'},
1.293 raeburn 610: {col1 => 'Connections from other servers',
611: col2 => 'Rules'},
1.275 raeburn 612: {col1 => "Replicating domain's published content",
613: col2 => 'Rules'}],
614: print => \&print_ssl,
615: modify => \&modify_ssl,
616: },
1.279 raeburn 617: 'trust' =>
618: {text => 'Trust Settings',
619: help => 'Domain_Configuration_Trust',
620: header => [{col1 => "Access to this domain's content by others",
621: col2 => 'Rules'},
622: {col1 => "Access to other domain's content by this domain",
623: col2 => 'Rules'},
624: {col1 => "Enrollment in this domain's courses by others",
625: col2 => 'Rules',},
626: {col1 => "Co-author roles in this domain for others",
627: col2 => 'Rules',},
628: {col1 => "Co-author roles for this domain's users elsewhere",
629: col2 => 'Rules',},
630: {col1 => "Domain roles in this domain assignable to others",
631: col2 => 'Rules'},
632: {col1 => "Course catalog for this domain displayed elsewhere",
633: col2 => 'Rules'},
634: {col1 => "Requests for creation of courses in this domain by others",
635: col2 => 'Rules'},
636: {col1 => "Users in other domains can send messages to this domain",
637: col2 => 'Rules'},],
638: print => \&print_trust,
639: modify => \&modify_trust,
640: },
1.320 raeburn 641: 'lti' =>
1.405 raeburn 642: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 643: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 644: header => [{col1 => 'Encryption of shared secrets',
645: col2 => 'Settings'},
646: {col1 => 'Rules for shared secrets',
647: col2 => 'Settings'},
1.406 raeburn 648: {col1 => 'Link Protectors',
1.405 raeburn 649: col2 => 'Settings'},
650: {col1 => 'Consumers',
651: col2 => 'Settings'},],
1.320 raeburn 652: print => \&print_lti,
653: modify => \&modify_lti,
654: },
1.394 raeburn 655: 'ipaccess' =>
656: {text => 'IP-based access control',
657: help => 'Domain_Configuration_IP_Access',
658: header => [{col1 => 'Setting',
659: col2 => 'Value'},],
660: print => \&print_ipaccess,
661: modify => \&modify_ipaccess,
662: },
1.3 raeburn 663: );
1.110 raeburn 664: if (keys(%servers) > 1) {
665: $prefs{'login'} = { text => 'Log-in page options',
666: help => 'Domain_Configuration_Login_Page',
667: header => [{col1 => 'Log-in Service',
668: col2 => 'Server Setting',},
669: {col1 => 'Log-in Page Items',
1.405 raeburn 670: col2 => 'Settings'},
1.168 raeburn 671: {col1 => 'Log-in Help',
1.256 raeburn 672: col2 => 'Value'},
673: {col1 => 'Custom HTML in document head',
1.386 raeburn 674: col2 => 'Value'},
675: {col1 => 'SSO',
676: col2 => 'Dual login: SSO and non-SSO options'},
677: ],
1.230 raeburn 678: print => \&print_login,
679: modify => \&modify_login,
1.110 raeburn 680: };
681: }
1.174 foxr 682:
1.6 raeburn 683: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 684: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 685: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 686: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 687: text=>"Settings to display/modify"});
1.9 raeburn 688: my $confname = $dom.'-domainconfig';
1.174 foxr 689:
1.3 raeburn 690: if ($phase eq 'process') {
1.212 raeburn 691: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
692: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 693: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 694: $r->rflush();
1.212 raeburn 695: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 696: }
1.30 raeburn 697: } elsif ($phase eq 'display') {
1.192 raeburn 698: my $js = &recaptcha_js().
1.236 raeburn 699: &toggle_display_js();
1.171 raeburn 700: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 701: my ($othertitle,$usertypes,$types) =
702: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 703: $js .= &lonbalance_targets_js($dom,$types,\%servers,
704: $domconfig{'loadbalancing'}).
1.170 raeburn 705: &new_spares_js().
706: &common_domprefs_js().
707: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 708: }
1.216 raeburn 709: if (grep(/^requestcourses$/,@actions)) {
710: my $javascript_validations;
711: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
712: $js .= <<END;
713: <script type="text/javascript">
714: $javascript_validations
715: </script>
716: $coursebrowserjs
717: END
1.394 raeburn 718: } elsif (grep(/^ipaccess$/,@actions)) {
719: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 720: }
1.305 raeburn 721: if (grep(/^selfcreation$/,@actions)) {
722: $js .= &selfcreate_javascript();
723: }
1.286 raeburn 724: if (grep(/^contacts$/,@actions)) {
725: $js .= &contacts_javascript();
726: }
1.346 raeburn 727: if (grep(/^scantron$/,@actions)) {
728: $js .= &scantron_javascript();
729: }
1.150 raeburn 730: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 731: } else {
1.180 raeburn 732: # check if domconfig user exists for the domain.
733: my $servadm = $r->dir_config('lonAdmEMail');
734: my ($configuserok,$author_ok,$switchserver) =
735: &config_check($dom,$confname,$servadm);
736: unless ($configuserok eq 'ok') {
1.181 raeburn 737: &Apache::lonconfigsettings::print_header($r,$phase,$context);
738: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 739: $confname).
1.181 raeburn 740: '<br />'
741: );
1.180 raeburn 742: if ($switchserver) {
1.181 raeburn 743: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
744: '<br />'.
745: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
746: '<br />'.
747: &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).
748: '<br />'.
749: &mt('To do that now, use the following link: [_1]',$switchserver)
750: );
751: } else {
752: $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.').
753: '<br />'.
754: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
755: );
1.180 raeburn 756: }
757: $r->print(&Apache::loncommon::end_page());
758: return OK;
759: }
1.21 raeburn 760: if (keys(%domconfig) == 0) {
761: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 762: my @ids=&Apache::lonnet::current_machine_ids();
763: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 764: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 765: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 766: my $custom_img_count = 0;
767: foreach my $img (@loginimages) {
768: if ($designhash{$dom.'.login.'.$img} ne '') {
769: $custom_img_count ++;
770: }
771: }
772: foreach my $role (@roles) {
773: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
774: $custom_img_count ++;
775: }
776: }
777: if ($custom_img_count > 0) {
1.94 raeburn 778: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 779: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 780: $r->print(
781: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
782: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
783: &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 />'.
784: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
785: if ($switch_server) {
1.30 raeburn 786: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 787: }
1.91 raeburn 788: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 789: return OK;
790: }
791: }
792: }
1.91 raeburn 793: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 794: }
795: return OK;
796: }
797:
798: sub process_changes {
1.205 raeburn 799: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 800: my %domconfig;
801: if (ref($values) eq 'HASH') {
802: %domconfig = %{$values};
803: }
1.3 raeburn 804: my $output;
805: if ($action eq 'login') {
1.205 raeburn 806: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 807: } elsif ($action eq 'rolecolors') {
1.9 raeburn 808: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 809: $lastactref,%domconfig);
1.3 raeburn 810: } elsif ($action eq 'quotas') {
1.216 raeburn 811: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 812: } elsif ($action eq 'autoenroll') {
1.205 raeburn 813: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 814: } elsif ($action eq 'autoupdate') {
815: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 816: } elsif ($action eq 'autocreate') {
817: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 818: } elsif ($action eq 'directorysrch') {
1.295 raeburn 819: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 820: } elsif ($action eq 'usercreation') {
1.28 raeburn 821: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 822: } elsif ($action eq 'selfcreation') {
1.305 raeburn 823: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 824: } elsif ($action eq 'usermodification') {
825: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 826: } elsif ($action eq 'contacts') {
1.205 raeburn 827: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 828: } elsif ($action eq 'defaults') {
1.212 raeburn 829: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 830: } elsif ($action eq 'scantron') {
1.205 raeburn 831: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 832: } elsif ($action eq 'coursecategories') {
1.239 raeburn 833: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 834: } elsif ($action eq 'serverstatuses') {
835: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 836: } elsif ($action eq 'requestcourses') {
1.216 raeburn 837: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 838: } elsif ($action eq 'requestauthor') {
1.216 raeburn 839: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 840: } elsif ($action eq 'helpsettings') {
1.285 raeburn 841: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 842: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 843: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 844: } elsif ($action eq 'selfenrollment') {
845: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 846: } elsif ($action eq 'usersessions') {
1.212 raeburn 847: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 848: } elsif ($action eq 'loadbalancing') {
849: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 850: } elsif ($action eq 'ltitools') {
851: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 852: } elsif ($action eq 'proctoring') {
853: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 854: } elsif ($action eq 'ssl') {
855: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 856: } elsif ($action eq 'trust') {
857: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 858: } elsif ($action eq 'lti') {
859: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 860: } elsif ($action eq 'privacy') {
861: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 862: } elsif ($action eq 'passwords') {
863: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 864: } elsif ($action eq 'wafproxy') {
865: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 866: } elsif ($action eq 'ipaccess') {
867: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 868: }
869: return $output;
870: }
871:
872: sub print_config_box {
1.9 raeburn 873: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 874: my $rowtotal = 0;
1.49 raeburn 875: my $output;
876: if ($action eq 'coursecategories') {
877: $output = &coursecategories_javascript($settings);
1.236 raeburn 878: } elsif ($action eq 'defaults') {
879: $output = &defaults_javascript($settings);
1.354 raeburn 880: } elsif ($action eq 'passwords') {
1.405 raeburn 881: $output = &passwords_javascript($action);
1.282 raeburn 882: } elsif ($action eq 'helpsettings') {
883: my (%privs,%levelscurrent);
884: my %full=();
885: my %levels=(
886: course => {},
887: domain => {},
888: system => {},
889: );
890: my $context = 'domain';
891: my $crstype = 'Course';
892: my $formname = 'display';
893: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
894: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
895: $output =
896: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
897: \@templateroles);
1.334 raeburn 898: } elsif ($action eq 'ltitools') {
1.421 ! raeburn 899: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 900: } elsif ($action eq 'lti') {
1.421 ! raeburn 901: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 902: <i_javascript($dom,$settings);
1.372 raeburn 903: } elsif ($action eq 'proctoring') {
904: $output .= &proctoring_javascript($settings);
1.381 raeburn 905: } elsif ($action eq 'wafproxy') {
906: $output .= &wafproxy_javascript($dom);
1.385 raeburn 907: } elsif ($action eq 'autoupdate') {
908: $output .= &autoupdate_javascript();
1.399 raeburn 909: } elsif ($action eq 'autoenroll') {
910: $output .= &autoenroll_javascript();
1.386 raeburn 911: } elsif ($action eq 'login') {
912: $output .= &saml_javascript();
1.394 raeburn 913: } elsif ($action eq 'ipaccess') {
914: $output .= &ipaccess_javascript($settings);
1.91 raeburn 915: }
1.236 raeburn 916: $output .=
1.30 raeburn 917: '<table class="LC_nested_outer">
1.3 raeburn 918: <tr>
1.306 raeburn 919: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 920: &mt($item->{text}).' '.
921: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
922: '</tr>';
1.30 raeburn 923: $rowtotal ++;
1.110 raeburn 924: my $numheaders = 1;
925: if (ref($item->{'header'}) eq 'ARRAY') {
926: $numheaders = scalar(@{$item->{'header'}});
927: }
928: if ($numheaders > 1) {
1.64 raeburn 929: my $colspan = '';
1.145 raeburn 930: my $rightcolspan = '';
1.369 raeburn 931: my $leftnobr = '';
1.238 raeburn 932: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 933: ($action eq 'directorysrch') ||
1.386 raeburn 934: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 935: $colspan = ' colspan="2"';
936: }
1.145 raeburn 937: if ($action eq 'usersessions') {
938: $rightcolspan = ' colspan="3"';
939: }
1.369 raeburn 940: if ($action eq 'passwords') {
941: $leftnobr = ' LC_nobreak';
942: }
1.30 raeburn 943: $output .= '
1.3 raeburn 944: <tr>
945: <td>
946: <table class="LC_nested">
947: <tr class="LC_info_row">
1.369 raeburn 948: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 949: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 950: </tr>';
1.69 raeburn 951: $rowtotal ++;
1.230 raeburn 952: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 953: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 954: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 955: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 ! raeburn 956: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
! 957: ($action eq 'lti') || ($action eq 'ltitools')) {
1.230 raeburn 958: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 959: } elsif ($action eq 'passwords') {
960: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 961: } elsif ($action eq 'coursecategories') {
1.230 raeburn 962: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 963: } elsif ($action eq 'scantron') {
964: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 965: } elsif ($action eq 'login') {
1.386 raeburn 966: if ($numheaders == 5) {
1.168 raeburn 967: $colspan = ' colspan="2"';
968: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
969: } else {
970: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
971: }
1.230 raeburn 972: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 973: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 974: } elsif ($action eq 'rolecolors') {
1.30 raeburn 975: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 976: }
1.30 raeburn 977: $output .= '
1.6 raeburn 978: </table>
979: </td>
980: </tr>
981: <tr>
982: <td>
983: <table class="LC_nested">
984: <tr class="LC_info_row">
1.230 raeburn 985: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 986: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 987: </tr>';
988: $rowtotal ++;
1.230 raeburn 989: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
990: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 991: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 992: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 ! raeburn 993: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
! 994: ($action eq 'ltitools')) {
1.238 raeburn 995: if ($action eq 'coursecategories') {
996: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
997: $colspan = ' colspan="2"';
1.279 raeburn 998: } elsif ($action eq 'trust') {
999: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1000: } elsif ($action eq 'passwords') {
1001: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 1002: } else {
1003: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1004: }
1.279 raeburn 1005: if ($action eq 'trust') {
1006: $output .= '
1007: </table>
1008: </td>
1009: </tr>';
1010: my @trusthdrs = qw(2 3 4 5 6 7);
1011: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1012: for (my $i=0; $i<@trusthdrs; $i++) {
1013: $output .= '
1014: <tr>
1015: <td>
1016: <table class="LC_nested">
1017: <tr class="LC_info_row">
1018: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1019: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1020: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1021: </table>
1022: </td>
1023: </tr>';
1024: }
1025: $output .= '
1026: <tr>
1027: <td>
1028: <table class="LC_nested">
1029: <tr class="LC_info_row">
1030: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1031: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1032: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1033: } else {
1034: $output .= '
1.63 raeburn 1035: </table>
1036: </td>
1037: </tr>
1038: <tr>
1039: <td>
1040: <table class="LC_nested">
1041: <tr class="LC_info_row">
1042: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1043: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1044: </tr>'."\n";
1.279 raeburn 1045: if ($action eq 'coursecategories') {
1046: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1047: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1048: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1049: if ($action eq 'passwords') {
1050: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1051: } else {
1052: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1053: }
1054: $output .= '
1.340 raeburn 1055: </tr>
1056: </table>
1057: </td>
1058: </tr>
1059: <tr>
1060: <td>
1061: <table class="LC_nested">
1062: <tr class="LC_info_row">
1.369 raeburn 1063: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1064: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1065: if ($action eq 'passwords') {
1066: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1067: } else {
1068: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1069: }
1070: $output .= '
1.340 raeburn 1071: </table>
1072: </td>
1073: </tr>
1074: <tr>';
1.279 raeburn 1075: } else {
1076: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1077: }
1.238 raeburn 1078: }
1.63 raeburn 1079: $rowtotal ++;
1.236 raeburn 1080: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1081: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1082: ($action eq 'wafproxy')) {
1.230 raeburn 1083: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1084: } elsif ($action eq 'scantron') {
1085: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1086: } elsif ($action eq 'ssl') {
1087: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1088: </table>
1089: </td>
1090: </tr>
1091: <tr>
1092: <td>
1093: <table class="LC_nested">
1094: <tr class="LC_info_row">
1095: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1096: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1097: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1098: </table>
1099: </td>
1100: </tr>
1101: <tr>
1102: <td>
1103: <table class="LC_nested">
1104: <tr class="LC_info_row">
1105: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1106: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1107: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1108: } elsif ($action eq 'login') {
1.386 raeburn 1109: if ($numheaders == 5) {
1.168 raeburn 1110: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1111: </table>
1112: </td>
1113: </tr>
1114: <tr>
1115: <td>
1116: <table class="LC_nested">
1117: <tr class="LC_info_row">
1118: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1119: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1120: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1121: $rowtotal ++;
1122: } else {
1123: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1124: }
1.256 raeburn 1125: $output .= '
1126: </table>
1127: </td>
1128: </tr>
1129: <tr>
1130: <td>
1131: <table class="LC_nested">
1132: <tr class="LC_info_row">';
1.386 raeburn 1133: if ($numheaders == 5) {
1.256 raeburn 1134: $output .= '
1135: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1136: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1137: </tr>';
1138: } else {
1139: $output .= '
1140: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1141: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1142: </tr>';
1143: }
1144: $rowtotal ++;
1.386 raeburn 1145: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1146: </table>
1147: </td>
1148: </tr>
1149: <tr>
1150: <td>
1151: <table class="LC_nested">
1152: <tr class="LC_info_row">';
1153: if ($numheaders == 5) {
1154: $output .= '
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1157: </tr>';
1158: } else {
1159: $output .= '
1160: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1161: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1162: </tr>';
1163: }
1164: $rowtotal ++;
1165: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1166: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1167: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1168: $rowtotal ++;
1169: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1170: </table>
1171: </td>
1172: </tr>
1173: <tr>
1174: <td>
1175: <table class="LC_nested">
1176: <tr class="LC_info_row">
1177: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1178: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1179: &textbookcourses_javascript($settings).
1180: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1181: </table>
1182: </td>
1183: </tr>
1184: <tr>
1185: <td>
1186: <table class="LC_nested">
1187: <tr class="LC_info_row">
1188: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1189: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1190: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1191: </table>
1192: </td>
1193: </tr>
1194: <tr>
1195: <td>
1196: <table class="LC_nested">
1197: <tr class="LC_info_row">
1.306 raeburn 1198: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1199: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1200: </tr>'.
1201: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1202: } elsif ($action eq 'requestauthor') {
1203: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1204: $rowtotal ++;
1.122 jms 1205: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1206: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1207: </table>
1208: </td>
1209: </tr>
1210: <tr>
1211: <td>
1212: <table class="LC_nested">
1213: <tr class="LC_info_row">
1.306 raeburn 1214: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1215: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1216: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1217: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1218: </tr>'.
1.30 raeburn 1219: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1220: </table>
1221: </td>
1222: </tr>
1223: <tr>
1224: <td>
1225: <table class="LC_nested">
1226: <tr class="LC_info_row">
1.59 bisitz 1227: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1228: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1229: </tr>'.
1.30 raeburn 1230: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1231: $rowtotal += 2;
1.6 raeburn 1232: }
1.3 raeburn 1233: } else {
1.30 raeburn 1234: $output .= '
1.3 raeburn 1235: <tr>
1236: <td>
1237: <table class="LC_nested">
1.30 raeburn 1238: <tr class="LC_info_row">';
1.277 raeburn 1239: if ($action eq 'login') {
1.30 raeburn 1240: $output .= '
1.59 bisitz 1241: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1242: } elsif ($action eq 'serverstatuses') {
1243: $output .= '
1.306 raeburn 1244: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1245: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1246:
1.6 raeburn 1247: } else {
1.30 raeburn 1248: $output .= '
1.306 raeburn 1249: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1250: }
1.72 raeburn 1251: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1252: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1253: &mt($item->{'header'}->[0]->{'col2'});
1254: if ($action eq 'serverstatuses') {
1255: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1256: }
1.69 raeburn 1257: } else {
1.306 raeburn 1258: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1259: &mt($item->{'header'}->[0]->{'col2'});
1260: }
1261: $output .= '</td>';
1262: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1263: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1264: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1265: &mt($item->{'header'}->[0]->{'col3'});
1266: } else {
1.306 raeburn 1267: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1268: &mt($item->{'header'}->[0]->{'col3'});
1269: }
1.69 raeburn 1270: if ($action eq 'serverstatuses') {
1271: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1272: }
1273: $output .= '</td>';
1.6 raeburn 1274: }
1.150 raeburn 1275: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1276: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1277: &mt($item->{'header'}->[0]->{'col4'});
1278: }
1.69 raeburn 1279: $output .= '</tr>';
1.48 raeburn 1280: $rowtotal ++;
1.168 raeburn 1281: if ($action eq 'quotas') {
1.86 raeburn 1282: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1283: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1284: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 ! raeburn 1285: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1286: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1287: }
1.3 raeburn 1288: }
1.30 raeburn 1289: $output .= '
1.3 raeburn 1290: </table>
1291: </td>
1292: </tr>
1.30 raeburn 1293: </table><br />';
1294: return ($output,$rowtotal);
1.1 raeburn 1295: }
1296:
1.3 raeburn 1297: sub print_login {
1.168 raeburn 1298: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1299: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1300: my %choices = &login_choices();
1.386 raeburn 1301: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1302: %lt = &login_file_options();
1303: $switchserver = &check_switchserver($dom,$confname);
1304: }
1.168 raeburn 1305: if ($caller eq 'service') {
1.149 raeburn 1306: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1307: my $choice = $choices{'disallowlogin'};
1308: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1309: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1310: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1311: '<th>'.$choices{'server'}.'</th>'.
1312: '<th>'.$choices{'serverpath'}.'</th>'.
1313: '<th>'.$choices{'custompath'}.'</th>'.
1314: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1315: my %disallowed;
1316: if (ref($settings) eq 'HASH') {
1317: if (ref($settings->{'loginvia'}) eq 'HASH') {
1318: %disallowed = %{$settings->{'loginvia'}};
1319: }
1320: }
1321: foreach my $lonhost (sort(keys(%servers))) {
1322: my $direct = 'selected="selected"';
1.128 raeburn 1323: if (ref($disallowed{$lonhost}) eq 'HASH') {
1324: if ($disallowed{$lonhost}{'server'} ne '') {
1325: $direct = '';
1326: }
1.110 raeburn 1327: }
1.115 raeburn 1328: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1329: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1330: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1331: '</option>';
1.184 raeburn 1332: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1333: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1334: my $selected = '';
1.128 raeburn 1335: if (ref($disallowed{$lonhost}) eq 'HASH') {
1336: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1337: $selected = 'selected="selected"';
1338: }
1.110 raeburn 1339: }
1340: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1341: $servers{$hostid}.'</option>';
1342: }
1.128 raeburn 1343: $datatable .= '</select></td>'.
1344: '<td><select name="'.$lonhost.'_serverpath">';
1345: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1346: my $pathname = $path;
1347: if ($path eq 'custom') {
1348: $pathname = &mt('Custom Path').' ->';
1349: }
1350: my $selected = '';
1351: if (ref($disallowed{$lonhost}) eq 'HASH') {
1352: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1353: $selected = 'selected="selected"';
1354: }
1355: } elsif ($path eq '') {
1356: $selected = 'selected="selected"';
1357: }
1358: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1359: }
1360: $datatable .= '</select></td>';
1361: my ($custom,$exempt);
1362: if (ref($disallowed{$lonhost}) eq 'HASH') {
1363: $custom = $disallowed{$lonhost}{'custompath'};
1364: $exempt = $disallowed{$lonhost}{'exempt'};
1365: }
1366: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1367: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1368: '</tr>';
1.110 raeburn 1369: }
1370: $datatable .= '</table></td></tr>';
1371: return $datatable;
1.168 raeburn 1372: } elsif ($caller eq 'page') {
1373: my %defaultchecked = (
1374: 'coursecatalog' => 'on',
1.188 raeburn 1375: 'helpdesk' => 'on',
1.168 raeburn 1376: 'adminmail' => 'off',
1377: 'newuser' => 'off',
1378: );
1.188 raeburn 1379: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1380: my (%checkedon,%checkedoff);
1.42 raeburn 1381: foreach my $item (@toggles) {
1.168 raeburn 1382: if ($defaultchecked{$item} eq 'on') {
1383: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1384: $checkedoff{$item} = ' ';
1.168 raeburn 1385: } elsif ($defaultchecked{$item} eq 'off') {
1386: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1387: $checkedon{$item} = ' ';
1388: }
1.1 raeburn 1389: }
1.168 raeburn 1390: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1391: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1392: my @logintext = ('textcol','bgcol');
1393: my @bgs = ('pgbg','mainbg','sidebg');
1394: my @links = ('link','alink','vlink');
1395: my %designhash = &Apache::loncommon::get_domainconf($dom);
1396: my %defaultdesign = %Apache::loncommon::defaultdesign;
1397: my (%is_custom,%designs);
1398: my %defaults = (
1399: font => $defaultdesign{'login.font'},
1400: );
1.6 raeburn 1401: foreach my $item (@images) {
1.168 raeburn 1402: $defaults{$item} = $defaultdesign{'login.'.$item};
1403: $defaults{'showlogo'}{$item} = 1;
1404: }
1405: foreach my $item (@bgs) {
1406: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1407: }
1.41 raeburn 1408: foreach my $item (@logintext) {
1.168 raeburn 1409: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1410: }
1.168 raeburn 1411: foreach my $item (@links) {
1412: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1413: }
1.168 raeburn 1414: if (ref($settings) eq 'HASH') {
1415: foreach my $item (@toggles) {
1416: if ($settings->{$item} eq '1') {
1417: $checkedon{$item} = ' checked="checked" ';
1418: $checkedoff{$item} = ' ';
1419: } elsif ($settings->{$item} eq '0') {
1420: $checkedoff{$item} = ' checked="checked" ';
1421: $checkedon{$item} = ' ';
1422: }
1423: }
1424: foreach my $item (@images) {
1425: if (defined($settings->{$item})) {
1426: $designs{$item} = $settings->{$item};
1427: $is_custom{$item} = 1;
1428: }
1429: if (defined($settings->{'showlogo'}{$item})) {
1430: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1431: }
1432: }
1.402 raeburn 1433: foreach my $item (@alttext) {
1434: if (ref($settings->{'alttext'}) eq 'HASH') {
1435: if ($settings->{'alttext'}->{$item} ne '') {
1436: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1437: }
1438: }
1439: }
1.168 raeburn 1440: foreach my $item (@logintext) {
1441: if ($settings->{$item} ne '') {
1442: $designs{'logintext'}{$item} = $settings->{$item};
1443: $is_custom{$item} = 1;
1444: }
1445: }
1446: if ($settings->{'font'} ne '') {
1447: $designs{'font'} = $settings->{'font'};
1448: $is_custom{'font'} = 1;
1449: }
1450: foreach my $item (@bgs) {
1451: if ($settings->{$item} ne '') {
1452: $designs{'bgs'}{$item} = $settings->{$item};
1453: $is_custom{$item} = 1;
1454: }
1455: }
1456: foreach my $item (@links) {
1457: if ($settings->{$item} ne '') {
1458: $designs{'links'}{$item} = $settings->{$item};
1459: $is_custom{$item} = 1;
1460: }
1461: }
1462: } else {
1463: if ($designhash{$dom.'.login.font'} ne '') {
1464: $designs{'font'} = $designhash{$dom.'.login.font'};
1465: $is_custom{'font'} = 1;
1466: }
1467: foreach my $item (@images) {
1468: if ($designhash{$dom.'.login.'.$item} ne '') {
1469: $designs{$item} = $designhash{$dom.'.login.'.$item};
1470: $is_custom{$item} = 1;
1471: }
1472: }
1473: foreach my $item (@bgs) {
1474: if ($designhash{$dom.'.login.'.$item} ne '') {
1475: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1476: $is_custom{$item} = 1;
1477: }
1.6 raeburn 1478: }
1.168 raeburn 1479: foreach my $item (@links) {
1480: if ($designhash{$dom.'.login.'.$item} ne '') {
1481: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1482: $is_custom{$item} = 1;
1483: }
1.6 raeburn 1484: }
1485: }
1.168 raeburn 1486: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1487: logo => 'Institution Logo',
1488: domlogo => 'Domain Logo',
1489: login => 'Login box');
1490: my $itemcount = 1;
1491: foreach my $item (@toggles) {
1492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1493: $datatable .=
1494: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1495: '</td><td>'.
1496: '<span class="LC_nobreak"><label><input type="radio" name="'.
1497: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1498: '</label> <label><input type="radio" name="'.$item.'"'.
1499: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1500: '</tr>';
1501: $itemcount ++;
1.6 raeburn 1502: }
1.168 raeburn 1503: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1504: $datatable .= '</tr></table></td></tr>';
1505: } elsif ($caller eq 'help') {
1.386 raeburn 1506: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1507: my $itemcount = 1;
1508: $defaulturl = '/adm/loginproblems.html';
1509: $defaulttype = 'default';
1510: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1511: my @currlangs;
1512: if (ref($settings) eq 'HASH') {
1513: if (ref($settings->{'helpurl'}) eq 'HASH') {
1514: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1515: next if ($settings->{'helpurl'}{$key} eq '');
1516: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1517: $type{$key} = 'custom';
1518: unless ($key eq 'nolang') {
1519: push(@currlangs,$key);
1520: }
1521: }
1522: } elsif ($settings->{'helpurl'} ne '') {
1523: $type{'nolang'} = 'custom';
1524: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1525: }
1526: }
1.168 raeburn 1527: foreach my $lang ('nolang',sort(@currlangs)) {
1528: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1529: $datatable .= '<tr'.$css_class.'>';
1530: if ($url{$lang} eq '') {
1531: $url{$lang} = $defaulturl;
1532: }
1533: if ($type{$lang} eq '') {
1534: $type{$lang} = $defaulttype;
1535: }
1536: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1537: if ($lang eq 'nolang') {
1538: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1539: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1540: } else {
1541: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1542: $langchoices{$lang},
1543: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1544: }
1545: $datatable .= '</span></td>'."\n".
1546: '<td class="LC_left_item">';
1547: if ($type{$lang} eq 'custom') {
1548: $datatable .= '<span class="LC_nobreak"><label>'.
1549: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1550: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1551: } else {
1552: $datatable .= $lt{'upl'};
1553: }
1554: $datatable .='<br />';
1555: if ($switchserver) {
1556: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1557: } else {
1558: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1559: }
1.168 raeburn 1560: $datatable .= '</td></tr>';
1561: $itemcount ++;
1.6 raeburn 1562: }
1.168 raeburn 1563: my @addlangs;
1564: foreach my $lang (sort(keys(%langchoices))) {
1565: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1566: push(@addlangs,$lang);
1567: }
1568: if (@addlangs > 0) {
1569: my %toadd;
1570: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1571: $toadd{''} = &mt('Select');
1572: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1573: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1574: &mt('Add log-in help page for a specific language:').' '.
1575: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1576: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1577: if ($switchserver) {
1578: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1579: } else {
1580: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1581: }
1.168 raeburn 1582: $datatable .= '</td></tr>';
1.169 raeburn 1583: $itemcount ++;
1.6 raeburn 1584: }
1.169 raeburn 1585: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1586: } elsif ($caller eq 'headtag') {
1587: my %domservers = &Apache::lonnet::get_servers($dom);
1588: my $choice = $choices{'headtag'};
1589: $css_class = ' class="LC_odd_row"';
1590: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1591: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1592: '<th>'.$choices{'current'}.'</th>'.
1593: '<th>'.$choices{'action'}.'</th>'.
1594: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1595: my (%currurls,%currexempt);
1596: if (ref($settings) eq 'HASH') {
1597: if (ref($settings->{'headtag'}) eq 'HASH') {
1598: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1599: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1600: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1601: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1602: }
1603: }
1604: }
1605: }
1606: foreach my $lonhost (sort(keys(%domservers))) {
1607: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1608: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1609: if ($currurls{$lonhost}) {
1610: $datatable .= '<td class="LC_right_item"><a href="'.
1611: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1612: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1613: '">'.$lt{'curr'}.'</a></td>'.
1614: '<td><span class="LC_nobreak"><label>'.
1615: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1616: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1617: } else {
1618: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1619: }
1620: $datatable .='<br />';
1621: if ($switchserver) {
1622: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1623: } else {
1624: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1625: }
1.330 raeburn 1626: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1627: }
1628: $datatable .= '</table></td></tr>';
1.386 raeburn 1629: } elsif ($caller eq 'saml') {
1630: my %domservers = &Apache::lonnet::get_servers($dom);
1631: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1632: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1633: '<th>'.$choices{'samllanding'}.'</th>'.
1634: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1635: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1636: foreach my $lonhost (keys(%domservers)) {
1637: $samlurl{$lonhost} = '/adm/sso';
1638: $styleon{$lonhost} = 'display:none';
1639: $styleoff{$lonhost} = '';
1640: }
1.411 raeburn 1641: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1642: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1643: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1644: $saml{$lonhost} = 1;
1645: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1646: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1647: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1648: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1649: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1650: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1651: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1652: $styleon{$lonhost} = '';
1653: $styleoff{$lonhost} = 'display:none';
1654: } else {
1655: $styleon{$lonhost} = 'display:none';
1656: $styleoff{$lonhost} = '';
1657: }
1658: }
1659: }
1660: my $itemcount = 1;
1661: foreach my $lonhost (sort(keys(%domservers))) {
1662: my $samlon = ' ';
1663: my $samloff = ' checked="checked" ';
1664: if ($saml{$lonhost}) {
1665: $samlon = $samloff;
1666: $samloff = ' ';
1667: }
1.412 raeburn 1668: my $samlwinon = '';
1669: my $samlwinoff = ' checked="checked"';
1670: if ($samlwindow{$lonhost}) {
1671: $samlwinon = $samlwinoff;
1672: $samlwinoff = '';
1673: }
1.386 raeburn 1674: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1675: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1676: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1677: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1678: &mt('No').'</label>'.(' 'x2).
1679: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1680: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1681: &mt('Yes').'</label></span></td>'.
1682: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1683: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1684: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1685: '<th>'.&mt('Alt Text').'</th></tr>'.
1686: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1687: $samltext{$lonhost}.'" /></td><td>';
1688: if ($samlimg{$lonhost}) {
1689: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1690: '<span class="LC_nobreak"><label>'.
1691: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1692: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1693: } else {
1694: $datatable .= $lt{'upl'};
1695: }
1696: $datatable .='<br />';
1697: if ($switchserver) {
1698: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1699: } else {
1700: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1701: }
1702: $datatable .= '</td>'.
1.412 raeburn 1703: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1704: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1705: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1706: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1707: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1708: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1709: '<tr'.$css_class.'>'.
1710: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1711: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1712: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1713: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1714: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1715: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1716: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1717: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1718: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1719: '</table></td>'.
1720: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1721: $itemcount ++;
1722: }
1723: $datatable .= '</table></td></tr>';
1.1 raeburn 1724: }
1.6 raeburn 1725: return $datatable;
1726: }
1727:
1728: sub login_choices {
1729: my %choices =
1730: &Apache::lonlocal::texthash (
1.116 bisitz 1731: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1732: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1733: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1734: disallowlogin => "Login page requests redirected",
1735: hostid => "Server",
1.128 raeburn 1736: server => "Redirect to:",
1737: serverpath => "Path",
1738: custompath => "Custom",
1739: exempt => "Exempt IP(s)",
1.110 raeburn 1740: directlogin => "No redirect",
1741: newuser => "Link to create a user account",
1742: img => "Header",
1743: logo => "Main Logo",
1744: domlogo => "Domain Logo",
1745: login => "Log-in Header",
1746: textcol => "Text color",
1747: bgcol => "Box color",
1748: bgs => "Background colors",
1749: links => "Link colors",
1750: font => "Font color",
1751: pgbg => "Header",
1752: mainbg => "Page",
1753: sidebg => "Login box",
1754: link => "Link",
1755: alink => "Active link",
1756: vlink => "Visited link",
1.256 raeburn 1757: headtag => "Custom markup",
1758: action => "Action",
1759: current => "Current",
1.386 raeburn 1760: samllanding => "Dual login?",
1761: samloptions => "Options",
1.402 raeburn 1762: alttext => "Alt text",
1.6 raeburn 1763: );
1764: return %choices;
1765: }
1766:
1.386 raeburn 1767: sub login_file_options {
1768: return &Apache::lonlocal::texthash(
1769: del => 'Delete?',
1770: rep => 'Replace:',
1771: upl => 'Upload:',
1772: curr => 'View contents',
1773: default => 'Default',
1774: custom => 'Custom',
1775: none => 'None',
1776: );
1777: }
1778:
1.394 raeburn 1779: sub print_ipaccess {
1780: my ($dom,$settings,$rowtotal) = @_;
1781: my $css_class;
1782: my $itemcount = 0;
1783: my $datatable;
1784: my %ordered;
1785: if (ref($settings) eq 'HASH') {
1786: foreach my $item (keys(%{$settings})) {
1787: if (ref($settings->{$item}) eq 'HASH') {
1788: my $num = $settings->{$item}{'order'};
1789: if ($num eq '') {
1790: $num = scalar(keys(%{$settings}));
1791: }
1792: $ordered{$num} = $item;
1793: }
1794: }
1795: }
1796: my $maxnum = scalar(keys(%ordered));
1797: if (keys(%ordered)) {
1798: my @items = sort { $a <=> $b } keys(%ordered);
1799: for (my $i=0; $i<@items; $i++) {
1800: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1801: my $item = $ordered{$items[$i]};
1802: my ($name,$ipranges,%commblocks,%courses);
1803: if (ref($settings->{$item}) eq 'HASH') {
1804: $name = $settings->{$item}->{'name'};
1805: $ipranges = $settings->{$item}->{'ip'};
1806: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1807: %commblocks = %{$settings->{$item}->{'commblocks'}};
1808: }
1809: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1810: %courses = %{$settings->{$item}->{'courses'}};
1811: }
1812: }
1813: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1814: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1815: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1816: for (my $k=0; $k<=$maxnum; $k++) {
1817: my $vpos = $k+1;
1818: my $selstr;
1819: if ($k == $i) {
1820: $selstr = ' selected="selected" ';
1821: }
1822: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1823: }
1824: $datatable .= '</select>'.(' 'x2).
1825: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1826: &mt('Delete?').'</label></span></td>'.
1827: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1828: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1829: '</td></tr>';
1830: $itemcount ++;
1831: }
1832: }
1833: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1834: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1835: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1836: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1837: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1838: for (my $k=0; $k<$maxnum+1; $k++) {
1839: my $vpos = $k+1;
1840: my $selstr;
1841: if ($k == $maxnum) {
1842: $selstr = ' selected="selected" ';
1843: }
1844: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1845: }
1846: $datatable .= '</select> '."\n".
1847: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1848: '<td colspan="2">'.
1849: &ipaccess_options('add',$itemcount,$dom).
1850: '</td>'."\n".
1851: '</tr>'."\n";
1852: $$rowtotal ++;
1853: return $datatable;
1854: }
1855:
1856: sub ipaccess_options {
1857: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1858: my (%currblocks,%currcourses,$output);
1859: if (ref($blocksref) eq 'HASH') {
1860: %currblocks = %{$blocksref};
1861: }
1862: if (ref($coursesref) eq 'HASH') {
1863: %currcourses = %{$coursesref};
1864: }
1865: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1866: '<span class="LC_nobreak">'.&mt('Name').': '.
1867: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1868: '</span></fieldset>'.
1869: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1870: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1871: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1872: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1873: $ipranges.'</textarea></fieldset>'.
1874: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1875: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1876: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1877: '<table>';
1878: foreach my $cid (sort(keys(%currcourses))) {
1879: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1880: $output .= '<tr><td><span class="LC_nobreak">'.
1881: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1882: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1883: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1884: }
1885: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1886: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1887: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1888: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1889: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1890: '</span></td></tr></table>'."\n".
1891: '</fieldset>';
1892: return $output;
1893: }
1894:
1895: sub blocker_checkboxes {
1896: my ($num,$blocks) = @_;
1897: my ($typeorder,$types) = &commblocktype_text();
1898: my $numinrow = 6;
1899: my $output = '<table>';
1900: for (my $i=0; $i<@{$typeorder}; $i++) {
1901: my $block = $typeorder->[$i];
1902: my $blockstatus;
1903: if (ref($blocks) eq 'HASH') {
1904: if ($blocks->{$block} eq 'on') {
1905: $blockstatus = 'checked="checked"';
1906: }
1907: }
1908: my $rem = $i%($numinrow);
1909: if ($rem == 0) {
1910: if ($i > 0) {
1911: $output .= '</tr>';
1912: }
1913: $output .= '<tr>';
1914: }
1915: if ($i == scalar(@{$typeorder})-1) {
1916: my $colsleft = $numinrow-$rem;
1917: if ($colsleft > 1) {
1918: $output .= '<td colspan="'.$colsleft.'">';
1919: } else {
1920: $output .= '<td>';
1921: }
1922: } else {
1923: $output .= '<td>';
1924: }
1925: my $item = 'ipaccess_block_'.$num;
1926: if ($blockstatus) {
1927: $blockstatus = ' '.$blockstatus;
1928: }
1929: $output .= '<span class="LC_nobreak"><label>'."\n".
1930: '<input type="checkbox" name="'.$item.'"'.
1931: $blockstatus.' value="'.$block.'"'.' />'.
1932: $types->{$block}.'</label></span>'."\n".
1933: '<br /></td>';
1934: }
1935: $output .= '</tr></table>';
1936: return $output;
1937: }
1938:
1939: sub commblocktype_text {
1940: my %types = &Apache::lonlocal::texthash(
1941: 'com' => 'Messaging',
1942: 'chat' => 'Chat Room',
1943: 'boards' => 'Discussion',
1944: 'port' => 'Portfolio',
1945: 'groups' => 'Groups',
1946: 'blogs' => 'Blogs',
1947: 'about' => 'User Information',
1948: 'printout' => 'Printouts',
1949: 'passwd' => 'Change Password',
1950: 'grades' => 'Gradebook',
1.397 raeburn 1951: 'search' => 'Course search',
1952: 'wishlist' => 'Stored links',
1953: 'annotate' => 'Annotations',
1.394 raeburn 1954: );
1.397 raeburn 1955: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1956: return ($typeorder,\%types);
1957: }
1958:
1.6 raeburn 1959: sub print_rolecolors {
1.30 raeburn 1960: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1961: my %choices = &color_font_choices();
1962: my @bgs = ('pgbg','tabbg','sidebg');
1963: my @links = ('link','alink','vlink');
1964: my @images = ('img');
1965: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1966: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1967: my %defaultdesign = %Apache::loncommon::defaultdesign;
1968: my (%is_custom,%designs);
1.200 raeburn 1969: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1970: if (ref($settings) eq 'HASH') {
1971: if (ref($settings->{$role}) eq 'HASH') {
1972: if ($settings->{$role}->{'img'} ne '') {
1973: $designs{'img'} = $settings->{$role}->{'img'};
1974: $is_custom{'img'} = 1;
1975: }
1976: if ($settings->{$role}->{'font'} ne '') {
1977: $designs{'font'} = $settings->{$role}->{'font'};
1978: $is_custom{'font'} = 1;
1979: }
1.97 tempelho 1980: if ($settings->{$role}->{'fontmenu'} ne '') {
1981: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1982: $is_custom{'fontmenu'} = 1;
1983: }
1.6 raeburn 1984: foreach my $item (@bgs) {
1985: if ($settings->{$role}->{$item} ne '') {
1986: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1987: $is_custom{$item} = 1;
1988: }
1989: }
1990: foreach my $item (@links) {
1991: if ($settings->{$role}->{$item} ne '') {
1992: $designs{'links'}{$item} = $settings->{$role}->{$item};
1993: $is_custom{$item} = 1;
1994: }
1995: }
1996: }
1997: } else {
1998: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1999: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2000: $is_custom{'img'} = 1;
2001: }
1.97 tempelho 2002: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2003: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2004: $is_custom{'fontmenu'} = 1;
2005: }
1.6 raeburn 2006: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2007: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2008: $is_custom{'font'} = 1;
2009: }
2010: foreach my $item (@bgs) {
2011: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2012: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2013: $is_custom{$item} = 1;
2014:
2015: }
2016: }
2017: foreach my $item (@links) {
2018: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2019: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2020: $is_custom{$item} = 1;
2021: }
2022: }
2023: }
2024: my $itemcount = 1;
1.30 raeburn 2025: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2026: $datatable .= '</tr></table></td></tr>';
2027: return $datatable;
2028: }
2029:
1.200 raeburn 2030: sub role_defaults {
2031: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2032: my %defaults;
2033: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2034: return %defaults;
2035: }
2036: my %defaultdesign = %Apache::loncommon::defaultdesign;
2037: if ($role eq 'login') {
2038: %defaults = (
2039: font => $defaultdesign{$role.'.font'},
2040: );
2041: if (ref($logintext) eq 'ARRAY') {
2042: foreach my $item (@{$logintext}) {
2043: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2044: }
2045: }
2046: foreach my $item (@{$images}) {
2047: $defaults{'showlogo'}{$item} = 1;
2048: }
2049: } else {
2050: %defaults = (
2051: img => $defaultdesign{$role.'.img'},
2052: font => $defaultdesign{$role.'.font'},
2053: fontmenu => $defaultdesign{$role.'.fontmenu'},
2054: );
2055: }
2056: foreach my $item (@{$bgs}) {
2057: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2058: }
2059: foreach my $item (@{$links}) {
2060: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2061: }
2062: foreach my $item (@{$images}) {
2063: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2064: }
2065: return %defaults;
2066: }
2067:
1.6 raeburn 2068: sub display_color_options {
1.9 raeburn 2069: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2070: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2071: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2072: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2073: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2074: '<td>'.$choices->{'font'}.'</td>';
2075: if (!$is_custom->{'font'}) {
1.329 raeburn 2076: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2077: } else {
2078: $datatable .= '<td> </td>';
2079: }
1.174 foxr 2080: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2081:
1.8 raeburn 2082: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2083: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2084: ' value="'.$current_color.'" /> '.
1.329 raeburn 2085: ' </span></td></tr>';
1.107 raeburn 2086: unless ($role eq 'login') {
2087: $datatable .= '<tr'.$css_class.'>'.
2088: '<td>'.$choices->{'fontmenu'}.'</td>';
2089: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2090: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2091: } else {
2092: $datatable .= '<td> </td>';
2093: }
1.202 raeburn 2094: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2095: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2096: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2097: '<input class="colorchooser" type="text" size="10" name="'
2098: .$role.'_fontmenu"'.
2099: ' value="'.$current_color.'" /> '.
1.329 raeburn 2100: ' </span></td></tr>';
1.97 tempelho 2101: }
1.9 raeburn 2102: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2103: foreach my $img (@{$images}) {
1.18 albertel 2104: $itemcount ++;
1.6 raeburn 2105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2106: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2107: '<td>'.$choices->{$img};
1.402 raeburn 2108: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2109: if ($role eq 'login') {
2110: if ($img eq 'login') {
2111: $login_hdr_pick =
1.135 bisitz 2112: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2113: $logincolors =
2114: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2115: $designs,$defaults);
1.402 raeburn 2116: } else {
2117: if ($img ne 'domlogo') {
2118: $datatable.= &logo_display_options($img,$defaults,$designs);
2119: }
2120: if (ref($designs->{'alttext'}) eq 'HASH') {
2121: $alttext = $designs->{'alttext'}{$img};
2122: }
1.70 raeburn 2123: }
2124: }
2125: $datatable .= '</td>';
1.6 raeburn 2126: if ($designs->{$img} ne '') {
2127: $imgfile = $designs->{$img};
1.18 albertel 2128: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2129: } else {
2130: $imgfile = $defaults->{$img};
2131: }
2132: if ($imgfile) {
1.9 raeburn 2133: my ($showfile,$fullsize);
2134: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2135: my $urldir = $1;
2136: my $filename = $2;
2137: my @info = &Apache::lonnet::stat_file($designs->{$img});
2138: if (@info) {
2139: my $thumbfile = 'tn-'.$filename;
2140: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2141: if (@thumb) {
2142: $showfile = $urldir.'/'.$thumbfile;
2143: } else {
2144: $showfile = $imgfile;
2145: }
2146: } else {
2147: $showfile = '';
2148: }
2149: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2150: $showfile = $imgfile;
1.6 raeburn 2151: my $imgdir = $1;
2152: my $filename = $2;
1.159 raeburn 2153: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2154: $showfile = "/$imgdir/tn-".$filename;
2155: } else {
1.159 raeburn 2156: my $input = $londocroot.$imgfile;
2157: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2158: if (!-e $output) {
1.9 raeburn 2159: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2160: my ($fullwidth,$fullheight) = &check_dimensions($input);
2161: if ($fullwidth ne '' && $fullheight ne '') {
2162: if ($fullwidth > $width && $fullheight > $height) {
2163: my $size = $width.'x'.$height;
1.316 raeburn 2164: my @args = ('convert','-sample',$size,$input,$output);
2165: system({$args[0]} @args);
1.159 raeburn 2166: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2167: }
2168: }
1.6 raeburn 2169: }
2170: }
1.16 raeburn 2171: }
1.6 raeburn 2172: if ($showfile) {
1.40 raeburn 2173: if ($showfile =~ m{^/(adm|res)/}) {
2174: if ($showfile =~ m{^/res/}) {
2175: my $local_showfile =
2176: &Apache::lonnet::filelocation('',$showfile);
2177: &Apache::lonnet::repcopy($local_showfile);
2178: }
2179: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2180: }
2181: if ($imgfile) {
2182: if ($imgfile =~ m{^/(adm|res)/}) {
2183: if ($imgfile =~ m{^/res/}) {
2184: my $local_imgfile =
2185: &Apache::lonnet::filelocation('',$imgfile);
2186: &Apache::lonnet::repcopy($local_imgfile);
2187: }
2188: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2189: } else {
2190: $fullsize = $imgfile;
2191: }
2192: }
1.41 raeburn 2193: $datatable .= '<td>';
2194: if ($img eq 'login') {
1.135 bisitz 2195: $datatable .= $login_hdr_pick;
2196: }
1.41 raeburn 2197: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2198: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2199: } else {
1.201 raeburn 2200: $datatable .= '<td> </td><td class="LC_left_item">'.
2201: &mt('Upload:').'<br />';
1.6 raeburn 2202: }
2203: } else {
1.201 raeburn 2204: $datatable .= '<td> </td><td class="LC_left_item">'.
2205: &mt('Upload:').'<br />';
1.6 raeburn 2206: }
1.9 raeburn 2207: if ($switchserver) {
2208: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2209: } else {
1.135 bisitz 2210: if ($img ne 'login') { # suppress file selection for Log-in header
2211: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2212: }
1.9 raeburn 2213: }
1.402 raeburn 2214: if (($role eq 'login') && ($img ne 'login')) {
2215: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2216: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2217: '</label></span>';
2218: }
1.9 raeburn 2219: $datatable .= '</td></tr>';
1.6 raeburn 2220: }
2221: $itemcount ++;
2222: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2223: $datatable .= '<tr'.$css_class.'>'.
2224: '<td>'.$choices->{'bgs'}.'</td>';
2225: my $bgs_def;
2226: foreach my $item (@{$bgs}) {
2227: if (!$is_custom->{$item}) {
1.329 raeburn 2228: $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 2229: }
2230: }
2231: if ($bgs_def) {
1.8 raeburn 2232: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2233: } else {
2234: $datatable .= '<td> </td>';
2235: }
2236: $datatable .= '<td class="LC_right_item">'.
2237: '<table border="0"><tr>';
1.174 foxr 2238:
1.6 raeburn 2239: foreach my $item (@{$bgs}) {
1.306 raeburn 2240: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2241: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2242: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2243: $datatable .= ' ';
1.6 raeburn 2244: }
1.174 foxr 2245: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2246: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2247: }
2248: $datatable .= '</tr></table></td></tr>';
2249: $itemcount ++;
2250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2251: $datatable .= '<tr'.$css_class.'>'.
2252: '<td>'.$choices->{'links'}.'</td>';
2253: my $links_def;
2254: foreach my $item (@{$links}) {
2255: if (!$is_custom->{$item}) {
1.329 raeburn 2256: $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 2257: }
2258: }
2259: if ($links_def) {
1.8 raeburn 2260: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2261: } else {
2262: $datatable .= '<td> </td>';
2263: }
2264: $datatable .= '<td class="LC_right_item">'.
2265: '<table border="0"><tr>';
2266: foreach my $item (@{$links}) {
1.234 raeburn 2267: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2268: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2269: if ($designs->{'links'}{$item}) {
1.174 foxr 2270: $datatable.=' ';
1.6 raeburn 2271: }
1.174 foxr 2272: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2273: '" /></td>';
2274: }
1.30 raeburn 2275: $$rowtotal += $itemcount;
1.3 raeburn 2276: return $datatable;
2277: }
2278:
1.70 raeburn 2279: sub logo_display_options {
2280: my ($img,$defaults,$designs) = @_;
2281: my $checkedon;
2282: if (ref($defaults) eq 'HASH') {
2283: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2284: if ($defaults->{'showlogo'}{$img}) {
2285: $checkedon = 'checked="checked" ';
2286: }
2287: }
2288: }
2289: if (ref($designs) eq 'HASH') {
2290: if (ref($designs->{'showlogo'}) eq 'HASH') {
2291: if (defined($designs->{'showlogo'}{$img})) {
2292: if ($designs->{'showlogo'}{$img} == 0) {
2293: $checkedon = '';
2294: } elsif ($designs->{'showlogo'}{$img} == 1) {
2295: $checkedon = 'checked="checked" ';
2296: }
2297: }
2298: }
2299: }
2300: return '<br /><label> <input type="checkbox" name="'.
2301: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2302: &mt('show').'</label>'."\n";
2303: }
2304:
1.41 raeburn 2305: sub login_header_options {
1.135 bisitz 2306: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2307: my $output = '';
1.41 raeburn 2308: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2309: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2310: if (!$is_custom->{'textcol'}) {
2311: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2312: ' ';
2313: }
2314: if (!$is_custom->{'bgcol'}) {
2315: $output .= $choices->{'bgcol'}.': '.
2316: '<span id="css_'.$role.'_font" style="background-color: '.
2317: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2318: }
2319: $output .= '<br />';
2320: }
2321: $output .='<br />';
2322: return $output;
2323: }
2324:
2325: sub login_text_colors {
1.201 raeburn 2326: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2327: my $color_menu = '<table border="0"><tr>';
2328: foreach my $item (@{$logintext}) {
1.306 raeburn 2329: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2330: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2331: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2332: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2333: }
2334: $color_menu .= '</tr></table><br />';
2335: return $color_menu;
2336: }
2337:
2338: sub image_changes {
2339: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2340: my $output;
1.135 bisitz 2341: if ($img eq 'login') {
1.331 raeburn 2342: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2343: } elsif (!$is_custom) {
1.70 raeburn 2344: if ($img ne 'domlogo') {
1.331 raeburn 2345: $output = &mt('Default image:').'<br />';
1.41 raeburn 2346: } else {
1.331 raeburn 2347: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2348: }
2349: }
1.331 raeburn 2350: if ($img ne 'login') {
1.135 bisitz 2351: if ($img_import) {
2352: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2353: }
2354: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2355: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2356: if ($is_custom) {
2357: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2358: '<input type="checkbox" name="'.
2359: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2360: '</label> '.&mt('Replace:').'</span><br />';
2361: } else {
1.306 raeburn 2362: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2363: }
1.41 raeburn 2364: }
2365: return $output;
2366: }
2367:
1.3 raeburn 2368: sub print_quotas {
1.86 raeburn 2369: my ($dom,$settings,$rowtotal,$action) = @_;
2370: my $context;
2371: if ($action eq 'quotas') {
2372: $context = 'tools';
2373: } else {
2374: $context = $action;
2375: }
1.197 raeburn 2376: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2377: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2378: my $typecount = 0;
1.101 raeburn 2379: my ($css_class,%titles);
1.86 raeburn 2380: if ($context eq 'requestcourses') {
1.325 raeburn 2381: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2382: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2383: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2384: %titles = &courserequest_titles();
1.163 raeburn 2385: } elsif ($context eq 'requestauthor') {
2386: @usertools = ('author');
2387: @options = ('norequest','approval','automatic');
1.210 raeburn 2388: %titles = &authorrequest_titles();
1.86 raeburn 2389: } else {
1.413 raeburn 2390: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2391: %titles = &tool_titles();
1.86 raeburn 2392: }
1.26 raeburn 2393: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2394: foreach my $type (@{$types}) {
1.197 raeburn 2395: my ($currdefquota,$currauthorquota);
1.163 raeburn 2396: unless (($context eq 'requestcourses') ||
2397: ($context eq 'requestauthor')) {
1.86 raeburn 2398: if (ref($settings) eq 'HASH') {
2399: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2400: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2401: } else {
2402: $currdefquota = $settings->{$type};
2403: }
1.197 raeburn 2404: if (ref($settings->{authorquota}) eq 'HASH') {
2405: $currauthorquota = $settings->{authorquota}->{$type};
2406: }
1.78 raeburn 2407: }
1.72 raeburn 2408: }
1.3 raeburn 2409: if (defined($usertypes->{$type})) {
2410: $typecount ++;
2411: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2412: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2413: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2414: '<td class="LC_left_item">';
1.101 raeburn 2415: if ($context eq 'requestcourses') {
2416: $datatable .= '<table><tr>';
2417: }
2418: my %cell;
1.72 raeburn 2419: foreach my $item (@usertools) {
1.101 raeburn 2420: if ($context eq 'requestcourses') {
2421: my ($curroption,$currlimit);
2422: if (ref($settings) eq 'HASH') {
2423: if (ref($settings->{$item}) eq 'HASH') {
2424: $curroption = $settings->{$item}->{$type};
2425: if ($curroption =~ /^autolimit=(\d*)$/) {
2426: $currlimit = $1;
2427: }
2428: }
2429: }
2430: if (!$curroption) {
2431: $curroption = 'norequest';
2432: }
2433: $datatable .= '<th>'.$titles{$item}.'</th>';
2434: foreach my $option (@options) {
2435: my $val = $option;
2436: if ($option eq 'norequest') {
2437: $val = 0;
2438: }
2439: if ($option eq 'validate') {
2440: my $canvalidate = 0;
2441: if (ref($validations{$item}) eq 'HASH') {
2442: if ($validations{$item}{$type}) {
2443: $canvalidate = 1;
2444: }
2445: }
2446: next if (!$canvalidate);
2447: }
2448: my $checked = '';
2449: if ($option eq $curroption) {
2450: $checked = ' checked="checked"';
2451: } elsif ($option eq 'autolimit') {
2452: if ($curroption =~ /^autolimit/) {
2453: $checked = ' checked="checked"';
2454: }
2455: }
2456: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2457: '<input type="radio" name="crsreq_'.$item.
2458: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2459: $titles{$option}.'</label>';
1.101 raeburn 2460: if ($option eq 'autolimit') {
1.127 raeburn 2461: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2462: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2463: 'value="'.$currlimit.'" />';
1.101 raeburn 2464: }
1.127 raeburn 2465: $cell{$item} .= '</span> ';
1.103 raeburn 2466: if ($option eq 'autolimit') {
1.127 raeburn 2467: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2468: }
1.101 raeburn 2469: }
1.163 raeburn 2470: } elsif ($context eq 'requestauthor') {
2471: my $curroption;
2472: if (ref($settings) eq 'HASH') {
2473: $curroption = $settings->{$type};
2474: }
2475: if (!$curroption) {
2476: $curroption = 'norequest';
2477: }
2478: foreach my $option (@options) {
2479: my $val = $option;
2480: if ($option eq 'norequest') {
2481: $val = 0;
2482: }
2483: my $checked = '';
2484: if ($option eq $curroption) {
2485: $checked = ' checked="checked"';
2486: }
2487: $datatable .= '<span class="LC_nobreak"><label>'.
2488: '<input type="radio" name="authorreq_'.$type.
2489: '" value="'.$val.'"'.$checked.' />'.
2490: $titles{$option}.'</label></span> ';
2491: }
1.101 raeburn 2492: } else {
2493: my $checked = 'checked="checked" ';
1.413 raeburn 2494: if ($item eq 'timezone') {
2495: $checked = '';
2496: }
1.101 raeburn 2497: if (ref($settings) eq 'HASH') {
2498: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2499: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2500: $checked = '';
2501: } elsif ($settings->{$item}->{$type} == 1) {
2502: $checked = 'checked="checked" ';
2503: }
1.78 raeburn 2504: }
1.72 raeburn 2505: }
1.101 raeburn 2506: $datatable .= '<span class="LC_nobreak"><label>'.
2507: '<input type="checkbox" name="'.$context.'_'.$item.
2508: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2509: '</label></span> ';
1.72 raeburn 2510: }
1.101 raeburn 2511: }
2512: if ($context eq 'requestcourses') {
2513: $datatable .= '</tr><tr>';
2514: foreach my $item (@usertools) {
1.106 raeburn 2515: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2516: }
2517: $datatable .= '</tr></table>';
1.72 raeburn 2518: }
1.86 raeburn 2519: $datatable .= '</td>';
1.163 raeburn 2520: unless (($context eq 'requestcourses') ||
2521: ($context eq 'requestauthor')) {
1.86 raeburn 2522: $datatable .=
1.197 raeburn 2523: '<td class="LC_right_item">'.
2524: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2525: '<input type="text" name="quota_'.$type.
1.72 raeburn 2526: '" value="'.$currdefquota.
1.197 raeburn 2527: '" size="5" /></span>'.(' ' x 2).
2528: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2529: '<input type="text" name="authorquota_'.$type.
2530: '" value="'.$currauthorquota.
2531: '" size="5" /></span></td>';
1.86 raeburn 2532: }
2533: $datatable .= '</tr>';
1.3 raeburn 2534: }
2535: }
2536: }
1.163 raeburn 2537: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2538: $defaultquota = '20';
1.197 raeburn 2539: $authorquota = '500';
1.86 raeburn 2540: if (ref($settings) eq 'HASH') {
2541: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2542: $defaultquota = $settings->{'defaultquota'}->{'default'};
2543: } elsif (defined($settings->{'default'})) {
2544: $defaultquota = $settings->{'default'};
2545: }
1.197 raeburn 2546: if (ref($settings->{'authorquota'}) eq 'HASH') {
2547: $authorquota = $settings->{'authorquota'}->{'default'};
2548: }
1.3 raeburn 2549: }
2550: }
2551: $typecount ++;
2552: $css_class = $typecount%2?' class="LC_odd_row"':'';
2553: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2554: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2555: '<td class="LC_left_item">';
1.101 raeburn 2556: if ($context eq 'requestcourses') {
2557: $datatable .= '<table><tr>';
2558: }
2559: my %defcell;
1.72 raeburn 2560: foreach my $item (@usertools) {
1.101 raeburn 2561: if ($context eq 'requestcourses') {
2562: my ($curroption,$currlimit);
2563: if (ref($settings) eq 'HASH') {
2564: if (ref($settings->{$item}) eq 'HASH') {
2565: $curroption = $settings->{$item}->{'default'};
2566: if ($curroption =~ /^autolimit=(\d*)$/) {
2567: $currlimit = $1;
2568: }
2569: }
2570: }
2571: if (!$curroption) {
2572: $curroption = 'norequest';
2573: }
2574: $datatable .= '<th>'.$titles{$item}.'</th>';
2575: foreach my $option (@options) {
2576: my $val = $option;
2577: if ($option eq 'norequest') {
2578: $val = 0;
2579: }
2580: if ($option eq 'validate') {
2581: my $canvalidate = 0;
2582: if (ref($validations{$item}) eq 'HASH') {
2583: if ($validations{$item}{'default'}) {
2584: $canvalidate = 1;
2585: }
2586: }
2587: next if (!$canvalidate);
2588: }
2589: my $checked = '';
2590: if ($option eq $curroption) {
2591: $checked = ' checked="checked"';
2592: } elsif ($option eq 'autolimit') {
2593: if ($curroption =~ /^autolimit/) {
2594: $checked = ' checked="checked"';
2595: }
2596: }
2597: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2598: '<input type="radio" name="crsreq_'.$item.
2599: '_default" value="'.$val.'"'.$checked.' />'.
2600: $titles{$option}.'</label>';
2601: if ($option eq 'autolimit') {
1.127 raeburn 2602: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2603: $item.'_limit_default" size="1" '.
2604: 'value="'.$currlimit.'" />';
2605: }
1.127 raeburn 2606: $defcell{$item} .= '</span> ';
1.104 raeburn 2607: if ($option eq 'autolimit') {
1.127 raeburn 2608: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2609: }
1.101 raeburn 2610: }
1.163 raeburn 2611: } elsif ($context eq 'requestauthor') {
2612: my $curroption;
2613: if (ref($settings) eq 'HASH') {
1.172 raeburn 2614: $curroption = $settings->{'default'};
1.163 raeburn 2615: }
2616: if (!$curroption) {
2617: $curroption = 'norequest';
2618: }
2619: foreach my $option (@options) {
2620: my $val = $option;
2621: if ($option eq 'norequest') {
2622: $val = 0;
2623: }
2624: my $checked = '';
2625: if ($option eq $curroption) {
2626: $checked = ' checked="checked"';
2627: }
2628: $datatable .= '<span class="LC_nobreak"><label>'.
2629: '<input type="radio" name="authorreq_default"'.
2630: ' value="'.$val.'"'.$checked.' />'.
2631: $titles{$option}.'</label></span> ';
2632: }
1.101 raeburn 2633: } else {
2634: my $checked = 'checked="checked" ';
2635: if (ref($settings) eq 'HASH') {
2636: if (ref($settings->{$item}) eq 'HASH') {
2637: if ($settings->{$item}->{'default'} == 0) {
2638: $checked = '';
2639: } elsif ($settings->{$item}->{'default'} == 1) {
2640: $checked = 'checked="checked" ';
2641: }
1.78 raeburn 2642: }
1.72 raeburn 2643: }
1.101 raeburn 2644: $datatable .= '<span class="LC_nobreak"><label>'.
2645: '<input type="checkbox" name="'.$context.'_'.$item.
2646: '" value="default" '.$checked.'/>'.$titles{$item}.
2647: '</label></span> ';
2648: }
2649: }
2650: if ($context eq 'requestcourses') {
2651: $datatable .= '</tr><tr>';
2652: foreach my $item (@usertools) {
1.106 raeburn 2653: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2654: }
1.101 raeburn 2655: $datatable .= '</tr></table>';
1.72 raeburn 2656: }
1.86 raeburn 2657: $datatable .= '</td>';
1.163 raeburn 2658: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2659: $datatable .= '<td class="LC_right_item">'.
2660: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2661: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2662: $defaultquota.'" size="5" /></span>'.(' ' x2).
2663: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2664: '<input type="text" name="authorquota" value="'.
2665: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2666: }
2667: $datatable .= '</tr>';
1.72 raeburn 2668: $typecount ++;
2669: $css_class = $typecount%2?' class="LC_odd_row"':'';
2670: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2671: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2672: if ($context eq 'requestcourses') {
1.109 raeburn 2673: $datatable .= &mt('(overrides affiliation, if set)').
2674: '</td>'.
2675: '<td class="LC_left_item">'.
2676: '<table><tr>';
1.101 raeburn 2677: } else {
1.109 raeburn 2678: $datatable .= &mt('(overrides affiliation, if checked)').
2679: '</td>'.
2680: '<td class="LC_left_item" colspan="2">'.
2681: '<br />';
1.101 raeburn 2682: }
2683: my %advcell;
1.72 raeburn 2684: foreach my $item (@usertools) {
1.101 raeburn 2685: if ($context eq 'requestcourses') {
2686: my ($curroption,$currlimit);
2687: if (ref($settings) eq 'HASH') {
2688: if (ref($settings->{$item}) eq 'HASH') {
2689: $curroption = $settings->{$item}->{'_LC_adv'};
2690: if ($curroption =~ /^autolimit=(\d*)$/) {
2691: $currlimit = $1;
2692: }
2693: }
2694: }
2695: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2696: my $checked = '';
2697: if ($curroption eq '') {
2698: $checked = ' checked="checked"';
2699: }
2700: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2701: '<input type="radio" name="crsreq_'.$item.
2702: '__LC_adv" value=""'.$checked.' />'.
2703: &mt('No override set').'</label></span> ';
1.101 raeburn 2704: foreach my $option (@options) {
2705: my $val = $option;
2706: if ($option eq 'norequest') {
2707: $val = 0;
2708: }
2709: if ($option eq 'validate') {
2710: my $canvalidate = 0;
2711: if (ref($validations{$item}) eq 'HASH') {
2712: if ($validations{$item}{'_LC_adv'}) {
2713: $canvalidate = 1;
2714: }
2715: }
2716: next if (!$canvalidate);
2717: }
2718: my $checked = '';
1.104 raeburn 2719: if ($val eq $curroption) {
1.101 raeburn 2720: $checked = ' checked="checked"';
2721: } elsif ($option eq 'autolimit') {
2722: if ($curroption =~ /^autolimit/) {
2723: $checked = ' checked="checked"';
2724: }
2725: }
2726: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2727: '<input type="radio" name="crsreq_'.$item.
2728: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2729: $titles{$option}.'</label>';
2730: if ($option eq 'autolimit') {
1.127 raeburn 2731: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2732: $item.'_limit__LC_adv" size="1" '.
2733: 'value="'.$currlimit.'" />';
2734: }
1.127 raeburn 2735: $advcell{$item} .= '</span> ';
1.104 raeburn 2736: if ($option eq 'autolimit') {
1.127 raeburn 2737: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2738: }
1.101 raeburn 2739: }
1.163 raeburn 2740: } elsif ($context eq 'requestauthor') {
2741: my $curroption;
2742: if (ref($settings) eq 'HASH') {
2743: $curroption = $settings->{'_LC_adv'};
2744: }
2745: my $checked = '';
2746: if ($curroption eq '') {
2747: $checked = ' checked="checked"';
2748: }
2749: $datatable .= '<span class="LC_nobreak"><label>'.
2750: '<input type="radio" name="authorreq__LC_adv"'.
2751: ' value=""'.$checked.' />'.
2752: &mt('No override set').'</label></span> ';
2753: foreach my $option (@options) {
2754: my $val = $option;
2755: if ($option eq 'norequest') {
2756: $val = 0;
2757: }
2758: my $checked = '';
2759: if ($val eq $curroption) {
2760: $checked = ' checked="checked"';
2761: }
2762: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2763: '<input type="radio" name="authorreq__LC_adv"'.
2764: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2765: $titles{$option}.'</label></span> ';
2766: }
1.101 raeburn 2767: } else {
2768: my $checked = 'checked="checked" ';
2769: if (ref($settings) eq 'HASH') {
2770: if (ref($settings->{$item}) eq 'HASH') {
2771: if ($settings->{$item}->{'_LC_adv'} == 0) {
2772: $checked = '';
2773: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2774: $checked = 'checked="checked" ';
2775: }
1.79 raeburn 2776: }
1.72 raeburn 2777: }
1.101 raeburn 2778: $datatable .= '<span class="LC_nobreak"><label>'.
2779: '<input type="checkbox" name="'.$context.'_'.$item.
2780: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2781: '</label></span> ';
2782: }
2783: }
2784: if ($context eq 'requestcourses') {
2785: $datatable .= '</tr><tr>';
2786: foreach my $item (@usertools) {
1.106 raeburn 2787: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2788: }
1.101 raeburn 2789: $datatable .= '</tr></table>';
1.72 raeburn 2790: }
1.98 raeburn 2791: $datatable .= '</td></tr>';
1.30 raeburn 2792: $$rowtotal += $typecount;
1.3 raeburn 2793: return $datatable;
2794: }
2795:
1.163 raeburn 2796: sub print_requestmail {
1.305 raeburn 2797: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2798: my ($now,$datatable,%currapp);
1.102 raeburn 2799: $now = time;
2800: if (ref($settings) eq 'HASH') {
2801: if (ref($settings->{'notify'}) eq 'HASH') {
2802: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2803: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2804: }
2805: }
2806: }
1.191 raeburn 2807: my $numinrow = 2;
1.224 raeburn 2808: my $css_class;
1.305 raeburn 2809: if ($$rowtotal%2) {
2810: $css_class = 'LC_odd_row';
2811: }
2812: if ($customcss) {
2813: $css_class .= " $customcss";
2814: }
2815: $css_class =~ s/^\s+//;
2816: if ($css_class) {
2817: $css_class = ' class="'.$css_class.'"';
2818: }
2819: if ($rowstyle) {
2820: $css_class .= ' style="'.$rowstyle.'"';
2821: }
1.163 raeburn 2822: my $text;
2823: if ($action eq 'requestcourses') {
2824: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2825: } elsif ($action eq 'requestauthor') {
2826: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2827: } else {
1.224 raeburn 2828: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2829: }
1.224 raeburn 2830: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2831: ' <td>'.$text.'</td>'.
1.102 raeburn 2832: ' <td class="LC_left_item">';
1.191 raeburn 2833: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2834: $action.'notifyapproval',%currapp);
1.191 raeburn 2835: if ($numdc > 0) {
2836: $datatable .= $table;
1.102 raeburn 2837: } else {
2838: $datatable .= &mt('There are no active Domain Coordinators');
2839: }
2840: $datatable .='</td></tr>';
2841: return $datatable;
2842: }
2843:
1.216 raeburn 2844: sub print_studentcode {
2845: my ($settings,$rowtotal) = @_;
2846: my $rownum = 0;
1.218 raeburn 2847: my ($output,%current);
1.325 raeburn 2848: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2849: if (ref($settings) eq 'HASH') {
2850: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2851: foreach my $type (@crstypes) {
2852: $current{$type} = $settings->{'uniquecode'}{$type};
2853: }
1.218 raeburn 2854: }
2855: }
2856: $output .= '<tr>'.
2857: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2858: '<td class="LC_left_item">';
2859: foreach my $type (@crstypes) {
2860: my $check = ' ';
2861: if ($current{$type}) {
2862: $check = ' checked="checked" ';
2863: }
2864: $output .= '<span class="LC_nobreak"><label>'.
2865: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2866: &mt($type).'</label></span>'.(' 'x2).' ';
2867: }
2868: $output .= '</td></tr>';
2869: $$rowtotal ++;
2870: return $output;
1.216 raeburn 2871: }
2872:
2873: sub print_textbookcourses {
1.242 raeburn 2874: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2875: my $rownum = 0;
2876: my $css_class;
2877: my $itemcount = 1;
2878: my $maxnum = 0;
2879: my $bookshash;
2880: if (ref($settings) eq 'HASH') {
1.242 raeburn 2881: $bookshash = $settings->{$type};
1.216 raeburn 2882: }
2883: my %ordered;
2884: if (ref($bookshash) eq 'HASH') {
2885: foreach my $item (keys(%{$bookshash})) {
2886: if (ref($bookshash->{$item}) eq 'HASH') {
2887: my $num = $bookshash->{$item}{'order'};
2888: $ordered{$num} = $item;
2889: }
2890: }
2891: }
2892: my $confname = $dom.'-domainconfig';
2893: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2894: my $maxnum = scalar(keys(%ordered));
2895: my $datatable;
1.216 raeburn 2896: if (keys(%ordered)) {
2897: my @items = sort { $a <=> $b } keys(%ordered);
2898: for (my $i=0; $i<@items; $i++) {
2899: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2900: my $key = $ordered{$items[$i]};
2901: my %coursehash=&Apache::lonnet::coursedescription($key);
2902: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2903: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2904: if (ref($bookshash->{$key}) eq 'HASH') {
2905: $subject = $bookshash->{$key}->{'subject'};
2906: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2907: if ($type eq 'textbooks') {
1.243 raeburn 2908: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2909: $author = $bookshash->{$key}->{'author'};
2910: $image = $bookshash->{$key}->{'image'};
2911: if ($image ne '') {
2912: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2913: my $imagethumb = "$path/tn-".$imagefile;
2914: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2915: }
1.216 raeburn 2916: }
2917: }
1.242 raeburn 2918: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2919: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2920: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2921: for (my $k=0; $k<=$maxnum; $k++) {
2922: my $vpos = $k+1;
2923: my $selstr;
2924: if ($k == $i) {
2925: $selstr = ' selected="selected" ';
2926: }
2927: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2928: }
2929: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2930: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2931: &mt('Delete?').'</label></span></td>'.
2932: '<td colspan="2">'.
1.242 raeburn 2933: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2934: (' 'x2).
1.242 raeburn 2935: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2936: if ($type eq 'textbooks') {
2937: $datatable .= (' 'x2).
1.243 raeburn 2938: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2939: (' 'x2).
1.242 raeburn 2940: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2941: (' 'x2).
2942: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2943: if ($image) {
1.267 raeburn 2944: $datatable .= $imgsrc.
1.242 raeburn 2945: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2946: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2947: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2948: }
2949: if ($switchserver) {
2950: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2951: } else {
2952: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2953: }
1.216 raeburn 2954: }
1.242 raeburn 2955: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2956: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2957: $coursetitle.'</span></td></tr>'."\n";
2958: $itemcount ++;
2959: }
2960: }
2961: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2962: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2963: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2964: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2965: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2966: for (my $k=0; $k<$maxnum+1; $k++) {
2967: my $vpos = $k+1;
2968: my $selstr;
2969: if ($k == $maxnum) {
2970: $selstr = ' selected="selected" ';
2971: }
2972: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2973: }
2974: $datatable .= '</select> '."\n".
1.334 raeburn 2975: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2976: '<td colspan="2">'.
1.242 raeburn 2977: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2978: (' 'x2).
1.242 raeburn 2979: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2980: (' 'x2);
2981: if ($type eq 'textbooks') {
1.243 raeburn 2982: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2983: (' 'x2).
2984: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2985: (' 'x2).
2986: '<span class="LC_nobreak">'.&mt('Image:').' ';
2987: if ($switchserver) {
2988: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2989: } else {
2990: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2991: }
1.334 raeburn 2992: $datatable .= '</span>'."\n";
1.216 raeburn 2993: }
1.334 raeburn 2994: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2995: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2996: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2997: &Apache::loncommon::selectcourse_link
1.334 raeburn 2998: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2999: '</span></td>'."\n".
3000: '</tr>'."\n";
3001: $itemcount ++;
3002: return $datatable;
3003: }
3004:
1.217 raeburn 3005: sub textbookcourses_javascript {
1.242 raeburn 3006: my ($settings) = @_;
3007: return unless(ref($settings) eq 'HASH');
3008: my (%ordered,%total,%jstext);
3009: foreach my $type ('textbooks','templates') {
3010: $total{$type} = 0;
3011: if (ref($settings->{$type}) eq 'HASH') {
3012: foreach my $item (keys(%{$settings->{$type}})) {
3013: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3014: my $num = $settings->{$type}->{$item}{'order'};
3015: $ordered{$type}{$num} = $item;
3016: }
3017: }
3018: $total{$type} = scalar(keys(%{$settings->{$type}}));
3019: }
3020: my @jsarray = ();
3021: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3022: push(@jsarray,$ordered{$type}{$item});
3023: }
3024: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3025: }
3026: return <<"ENDSCRIPT";
3027: <script type="text/javascript">
3028: // <![CDATA[
1.242 raeburn 3029: function reorderBooks(form,item,caller) {
1.217 raeburn 3030: var changedVal;
1.242 raeburn 3031: $jstext{'textbooks'};
3032: $jstext{'templates'};
3033: var newpos;
3034: var maxh;
3035: if (caller == 'textbooks') {
3036: newpos = 'textbooks_addbook_pos';
3037: maxh = 1 + $total{'textbooks'};
3038: } else {
3039: newpos = 'templates_addbook_pos';
3040: maxh = 1 + $total{'templates'};
3041: }
1.217 raeburn 3042: var current = new Array;
3043: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3044: if (item == newpos) {
3045: changedVal = newitemVal;
3046: } else {
3047: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3048: current[newitemVal] = newpos;
3049: }
1.242 raeburn 3050: if (caller == 'textbooks') {
3051: for (var i=0; i<textbooks.length; i++) {
3052: var elementName = 'textbooks_'+textbooks[i];
3053: if (elementName != item) {
3054: if (form.elements[elementName]) {
3055: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3056: current[currVal] = elementName;
3057: }
3058: }
3059: }
3060: }
3061: if (caller == 'templates') {
3062: for (var i=0; i<templates.length; i++) {
3063: var elementName = 'templates_'+templates[i];
3064: if (elementName != item) {
3065: if (form.elements[elementName]) {
3066: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3067: current[currVal] = elementName;
3068: }
1.217 raeburn 3069: }
3070: }
3071: }
3072: var oldVal;
3073: for (var j=0; j<maxh; j++) {
3074: if (current[j] == undefined) {
3075: oldVal = j;
3076: }
3077: }
3078: if (oldVal < changedVal) {
3079: for (var k=oldVal+1; k<=changedVal ; k++) {
3080: var elementName = current[k];
3081: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3082: }
3083: } else {
3084: for (var k=changedVal; k<oldVal; k++) {
3085: var elementName = current[k];
3086: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3087: }
3088: }
3089: return;
3090: }
3091:
3092: // ]]>
3093: </script>
3094:
3095: ENDSCRIPT
3096: }
3097:
1.267 raeburn 3098: sub ltitools_javascript {
3099: my ($settings) = @_;
1.319 raeburn 3100: my $togglejs = <itools_toggle_js();
3101: unless (ref($settings) eq 'HASH') {
3102: return $togglejs;
3103: }
1.267 raeburn 3104: my (%ordered,$total,%jstext);
3105: $total = 0;
3106: foreach my $item (keys(%{$settings})) {
3107: if (ref($settings->{$item}) eq 'HASH') {
3108: my $num = $settings->{$item}{'order'};
3109: $ordered{$num} = $item;
3110: }
3111: }
3112: $total = scalar(keys(%{$settings}));
3113: my @jsarray = ();
3114: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3115: push(@jsarray,$ordered{$item});
3116: }
3117: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3118: return <<"ENDSCRIPT";
3119: <script type="text/javascript">
3120: // <![CDATA[
1.319 raeburn 3121: function reorderLTITools(form,item) {
1.267 raeburn 3122: var changedVal;
3123: $jstext
3124: var newpos = 'ltitools_add_pos';
3125: var maxh = 1 + $total;
3126: var current = new Array;
3127: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3128: if (item == newpos) {
3129: changedVal = newitemVal;
3130: } else {
3131: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3132: current[newitemVal] = newpos;
3133: }
3134: for (var i=0; i<ltitools.length; i++) {
3135: var elementName = 'ltitools_'+ltitools[i];
3136: if (elementName != item) {
3137: if (form.elements[elementName]) {
3138: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3139: current[currVal] = elementName;
3140: }
3141: }
3142: }
3143: var oldVal;
3144: for (var j=0; j<maxh; j++) {
3145: if (current[j] == undefined) {
3146: oldVal = j;
3147: }
3148: }
3149: if (oldVal < changedVal) {
3150: for (var k=oldVal+1; k<=changedVal ; k++) {
3151: var elementName = current[k];
3152: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3153: }
3154: } else {
3155: for (var k=changedVal; k<oldVal; k++) {
3156: var elementName = current[k];
3157: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3158: }
3159: }
3160: return;
3161: }
3162:
3163: // ]]>
3164: </script>
3165:
1.319 raeburn 3166: $togglejs
3167:
3168: ENDSCRIPT
3169: }
3170:
3171: sub ltitools_toggle_js {
3172: return <<"ENDSCRIPT";
3173: <script type="text/javascript">
3174: // <![CDATA[
3175:
3176: function toggleLTITools(form,setting,item) {
3177: var radioname = '';
3178: var divid = '';
3179: if ((setting == 'passback') || (setting == 'roster')) {
3180: radioname = 'ltitools_'+setting+'_'+item;
3181: divid = 'ltitools_'+setting+'time_'+item;
3182: var num = form.elements[radioname].length;
3183: if (num) {
3184: var setvis = '';
3185: for (var i=0; i<num; i++) {
3186: if (form.elements[radioname][i].checked) {
3187: if (form.elements[radioname][i].value == '1') {
3188: if (document.getElementById(divid)) {
3189: document.getElementById(divid).style.display = 'inline-block';
3190: }
3191: setvis = 1;
3192: }
3193: break;
3194: }
3195: }
3196: }
3197: if (!setvis) {
3198: if (document.getElementById(divid)) {
3199: document.getElementById(divid).style.display = 'none';
3200: }
3201: }
3202: }
1.324 raeburn 3203: if (setting == 'user') {
3204: divid = 'ltitools_'+setting+'_div_'+item;
3205: var checkid = 'ltitools_'+setting+'_field_'+item;
3206: if (document.getElementById(divid)) {
3207: if (document.getElementById(checkid)) {
3208: if (document.getElementById(checkid).checked) {
3209: document.getElementById(divid).style.display = 'inline-block';
3210: } else {
3211: document.getElementById(divid).style.display = 'none';
3212: }
3213: }
3214: }
3215: }
1.319 raeburn 3216: return;
3217: }
3218: // ]]>
3219: </script>
3220:
1.267 raeburn 3221: ENDSCRIPT
3222: }
3223:
1.381 raeburn 3224: sub wafproxy_javascript {
3225: my ($dom) = @_;
3226: return <<"ENDSCRIPT";
3227: <script type="text/javascript">
3228: // <![CDATA[
3229: function updateWAF() {
3230: if (document.getElementById('wafproxy_remoteip')) {
3231: var wafremote = 0;
3232: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3233: wafremote = 1;
3234: }
3235: var fields = new Array('header','trust');
3236: for (var i=0; i<fields.length; i++) {
3237: if (document.getElementById('wafproxy_'+fields[i])) {
3238: if (wafremote == 1) {
3239: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3240: }
3241: else {
3242: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3243: }
3244: }
3245: }
3246: if (document.getElementById('wafproxyranges_$dom')) {
3247: if (wafremote == 1) {
3248: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3249: } else {
3250: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3251: if (document.display.wafproxy_vpnaccess[i].checked) {
3252: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3253: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3254: }
3255: }
3256: }
3257: }
3258: }
3259: }
3260: return;
3261: }
3262:
3263: function checkWAF() {
3264: if (document.getElementById('wafproxy_remoteip')) {
3265: var wafvpn = 0;
3266: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3267: if (document.display.wafproxy_vpnaccess[i].checked) {
3268: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3269: wafvpn = 1;
3270: }
3271: break;
3272: }
3273: }
3274: var vpn = new Array('vpnint','vpnext');
3275: for (var i=0; i<vpn.length; i++) {
3276: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3277: if (wafvpn == 1) {
3278: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3279: }
3280: else {
3281: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3282: }
3283: }
3284: }
3285: if (document.getElementById('wafproxyranges_$dom')) {
3286: if (wafvpn == 1) {
3287: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3288: }
3289: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3290: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3291: }
3292: }
3293: }
3294: return;
3295: }
3296:
3297: function toggleWAF() {
3298: if (document.getElementById('wafproxy_table')) {
3299: var wafproxy = 0;
3300: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3301: if (document.display.wafproxy_${dom}[i].checked) {
3302: if (document.display.wafproxy_${dom}[i].value == 1) {
3303: wafproxy = 1;
3304: break;
3305: }
3306: }
3307: }
3308: if (wafproxy == 1) {
3309: document.getElementById('wafproxy_table').style.display='inline';
3310: }
3311: else {
3312: document.getElementById('wafproxy_table').style.display='none';
3313: }
3314: if (document.getElementById('wafproxyrow_${dom}')) {
3315: if (wafproxy == 1) {
3316: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3317: }
3318: else {
3319: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3320: }
3321: }
3322: if (document.getElementById('nowafproxyrow_$dom')) {
3323: if (wafproxy == 1) {
3324: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3325: }
3326: else {
3327: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3328: }
3329: }
3330: }
3331: return;
3332: }
3333: // ]]>
3334: </script>
3335:
3336: ENDSCRIPT
3337: }
3338:
1.372 raeburn 3339: sub proctoring_javascript {
3340: my ($settings) = @_;
3341: my (%ordered,$total,%jstext);
3342: $total = 0;
3343: if (ref($settings) eq 'HASH') {
3344: foreach my $item (keys(%{$settings})) {
3345: if (ref($settings->{$item}) eq 'HASH') {
3346: my $num = $settings->{$item}{'order'};
3347: $ordered{$num} = $item;
3348: }
3349: }
3350: $total = scalar(keys(%{$settings}));
3351: } else {
3352: %ordered = (
3353: 0 => 'proctorio',
3354: 1 => 'examity',
3355: );
3356: $total = 2;
3357: }
3358: my @jsarray = ();
3359: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3360: push(@jsarray,$ordered{$item});
3361: }
3362: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3363: return <<"ENDSCRIPT";
3364: <script type="text/javascript">
3365: // <![CDATA[
3366: function reorderProctoring(form,item) {
3367: var changedVal;
3368: $jstext
3369: var maxh = $total;
3370: var current = new Array;
3371: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3372: for (var i=0; i<proctors.length; i++) {
3373: var elementName = 'proctoring_pos_'+proctors[i];
3374: if (elementName != item) {
3375: if (form.elements[elementName]) {
3376: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3377: current[currVal] = elementName;
3378: }
3379: }
3380: }
3381: var oldVal;
3382: for (var j=0; j<maxh; j++) {
3383: if (current[j] == undefined) {
3384: oldVal = j;
3385: }
3386: }
3387: if (oldVal < changedVal) {
3388: for (var k=oldVal+1; k<=changedVal ; k++) {
3389: var elementName = current[k];
3390: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3391: }
3392: } else {
3393: for (var k=changedVal; k<oldVal; k++) {
3394: var elementName = current[k];
3395: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3396: }
3397: }
3398: return;
3399: }
3400:
3401: function toggleProctoring(form,item) {
3402: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3403: if (fieldsets.length) {
3404: var radioname = 'proctoring_available_'+item;
3405: var num = form.elements[radioname].length;
3406: if (num) {
3407: var setvis = '';
3408: for (var i=0; i<num; i++) {
3409: if (form.elements[radioname][i].checked) {
3410: if (form.elements[radioname][i].value == '1') {
3411: setvis = 1;
3412: break;
3413: }
3414: }
3415: }
3416: for (var j=0; j<fieldsets.length; j++) {
3417: if (setvis) {
3418: fieldsets[j].style.display = 'block';
3419: } else {
3420: fieldsets[j].style.display = 'none';
3421: }
3422: }
3423: }
3424: }
3425: return;
3426: }
3427:
3428: // ]]>
3429: </script>
3430:
3431: ENDSCRIPT
3432: }
3433:
3434:
1.320 raeburn 3435: sub lti_javascript {
1.405 raeburn 3436: my ($dom,$settings) = @_;
3437: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3438: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3439: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3440: return $togglejs.'
3441: <script type="text/javascript">
3442: // <![CDATA[
3443:
3444: '.$linkprot_js.'
3445:
3446: // ]]>
3447: </script>
3448: ';
1.320 raeburn 3449: }
3450: my (%ordered,$total,%jstext);
1.390 raeburn 3451: $total = scalar(keys(%{$settings}));
1.320 raeburn 3452: foreach my $item (keys(%{$settings})) {
3453: if (ref($settings->{$item}) eq 'HASH') {
3454: my $num = $settings->{$item}{'order'};
1.390 raeburn 3455: if ($num eq '') {
3456: $num = $total - 1;
3457: }
1.320 raeburn 3458: $ordered{$num} = $item;
3459: }
3460: }
3461: my @jsarray = ();
3462: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3463: push(@jsarray,$ordered{$item});
3464: }
3465: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3466: return <<"ENDSCRIPT";
3467: <script type="text/javascript">
3468: // <![CDATA[
3469: function reorderLTI(form,item) {
3470: var changedVal;
3471: $jstext
3472: var newpos = 'lti_pos_add';
3473: var maxh = 1 + $total;
3474: var current = new Array;
3475: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3476: if (item == newpos) {
3477: changedVal = newitemVal;
3478: } else {
3479: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3480: current[newitemVal] = newpos;
3481: }
3482: for (var i=0; i<lti.length; i++) {
3483: var elementName = 'lti_pos_'+lti[i];
3484: if (elementName != item) {
3485: if (form.elements[elementName]) {
3486: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3487: current[currVal] = elementName;
3488: }
3489: }
3490: }
3491: var oldVal;
3492: for (var j=0; j<maxh; j++) {
3493: if (current[j] == undefined) {
3494: oldVal = j;
3495: }
3496: }
3497: if (oldVal < changedVal) {
3498: for (var k=oldVal+1; k<=changedVal ; k++) {
3499: var elementName = current[k];
3500: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3501: }
3502: } else {
3503: for (var k=changedVal; k<oldVal; k++) {
3504: var elementName = current[k];
3505: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3506: }
3507: }
3508: return;
3509: }
1.406 raeburn 3510:
3511: $linkprot_js
3512:
1.320 raeburn 3513: // ]]>
3514: </script>
3515:
3516: $togglejs
3517:
3518: ENDSCRIPT
3519: }
3520:
3521: sub lti_toggle_js {
1.405 raeburn 3522: my ($dom) = @_;
1.325 raeburn 3523: my %lcauthparmtext = &Apache::lonlocal::texthash (
3524: localauth => 'Local auth argument',
3525: krb => 'Kerberos domain',
3526: );
1.391 raeburn 3527: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3528: &js_escape(\$crsincalert);
1.405 raeburn 3529: my %servers = &Apache::lonnet::get_servers($dom,'library');
3530: my $primary = &Apache::lonnet::domain($dom,'primary');
3531: my $course_servers = "'".join("','",keys(%servers))."'";
3532:
1.320 raeburn 3533: return <<"ENDSCRIPT";
3534: <script type="text/javascript">
3535: // <![CDATA[
3536:
3537: function toggleLTI(form,setting,item) {
1.391 raeburn 3538: if ((setting == 'requser') || (setting == 'crsinc')) {
3539: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3540: var setvis = '';
3541: var radioname = 'lti_requser_'+item;
3542: var num = form.elements[radioname].length;
3543: if (num) {
3544: for (var i=0; i<num; i++) {
3545: if (form.elements[radioname][i].checked) {
3546: if (form.elements[radioname][i].value == '1') {
3547: setvis = 1;
3548: break;
3549: }
3550: }
3551: }
3552: }
3553: if (usrfieldsets.length) {
3554: for (var j=0; j<usrfieldsets.length; j++) {
3555: if (setvis) {
3556: usrfieldsets[j].style.display = 'block';
3557: } else {
3558: usrfieldsets[j].style.display = 'none';
3559: }
3560: }
3561: }
3562: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3563: if (crsfieldsets.length) {
3564: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3565: var num = form.elements[radioname].length;
3566: if (num) {
1.391 raeburn 3567: var crsvis = '';
1.345 raeburn 3568: for (var i=0; i<num; i++) {
3569: if (form.elements[radioname][i].checked) {
3570: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3571: if (setvis == '') {
3572: if (setting == 'crsinc'){
3573: alert("$crsincalert");
3574: form.elements[radioname][0].checked = true;
3575: }
3576: } else {
3577: crsvis = 1;
3578: }
3579: break;
1.345 raeburn 3580: }
3581: }
3582: }
1.391 raeburn 3583: setvis = crsvis;
3584: }
3585: for (var j=0; j<crsfieldsets.length; j++) {
3586: if (setvis) {
3587: crsfieldsets[j].style.display = 'block';
3588: } else {
3589: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3590: }
3591: }
3592: }
1.363 raeburn 3593: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3594: var radioname = '';
3595: var divid = '';
3596: if (setting == 'user') {
3597: radioname = 'lti_mapuser_'+item;
3598: divid = 'lti_userfield_'+item;
1.343 raeburn 3599: } else if (setting == 'crs') {
1.320 raeburn 3600: radioname = 'lti_mapcrs_'+item;
3601: divid = 'lti_crsfield_'+item;
1.363 raeburn 3602: } else if (setting == 'callback') {
3603: radioname = 'lti_callback_'+item;
3604: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3605: } else {
1.351 raeburn 3606: radioname = 'lti_passback_'+item;
1.337 raeburn 3607: divid = 'lti_passback_'+item;
1.320 raeburn 3608: }
3609: var num = form.elements[radioname].length;
3610: if (num) {
3611: var setvis = '';
3612: for (var i=0; i<num; i++) {
3613: if (form.elements[radioname][i].checked) {
1.363 raeburn 3614: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3615: if (form.elements[radioname][i].value == '1') {
3616: if (document.getElementById(divid)) {
3617: document.getElementById(divid).style.display = 'inline-block';
3618: }
3619: setvis = 1;
3620: break;
3621: }
3622: } else {
3623: if (form.elements[radioname][i].value == 'other') {
3624: if (document.getElementById(divid)) {
3625: document.getElementById(divid).style.display = 'inline-block';
3626: }
3627: setvis = 1;
3628: break;
1.320 raeburn 3629: }
3630: }
3631: }
3632: }
3633: if (!setvis) {
3634: if (document.getElementById(divid)) {
3635: document.getElementById(divid).style.display = 'none';
3636: }
3637: }
3638: }
3639: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3640: var numsec = form.elements['lti_crssec_'+item].length;
3641: if (numsec) {
3642: var setvis = '';
3643: for (var i=0; i<numsec; i++) {
3644: if (form.elements['lti_crssec_'+item][i].checked) {
3645: if (form.elements['lti_crssec_'+item][i].value == '1') {
3646: if (document.getElementById('lti_crssecfield_'+item)) {
3647: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3648: setvis = 1;
3649: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3650: if (numsrcsec) {
3651: var setsrcvis = '';
3652: for (var j=0; j<numsrcsec; j++) {
3653: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3654: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3655: if (document.getElementById('lti_secsrcfield_'+item)) {
3656: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3657: setsrcvis = 1;
3658: }
3659: }
3660: }
3661: }
3662: if (!setsrcvis) {
3663: if (document.getElementById('lti_secsrcfield_'+item)) {
3664: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3665: }
3666: }
3667: }
3668: }
3669: }
3670: }
3671: }
3672: if (!setvis) {
3673: if (document.getElementById('lti_crssecfield_'+item)) {
3674: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3675: }
3676: if (document.getElementById('lti_secsrcfield_'+item)) {
3677: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3678: }
3679: }
3680: }
1.325 raeburn 3681: } else if (setting == 'lcauth') {
3682: var numauth = form.elements['lti_lcauth_'+item].length;
3683: if (numauth) {
3684: for (var i=0; i<numauth; i++) {
3685: if (form.elements['lti_lcauth_'+item][i].checked) {
3686: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3687: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3688: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3689: } else {
3690: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3691: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3692: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3693: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3694: } else {
3695: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3696: }
3697: }
3698: }
3699: }
3700: }
3701: }
3702: }
1.326 raeburn 3703: } else if (setting == 'lcmenu') {
3704: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3705: var divid = 'lti_menufield_'+item;
3706: var setvis = '';
3707: for (var i=0; i<menus.length; i++) {
3708: var radioname = menus[i];
3709: var num = form.elements[radioname].length;
3710: if (num) {
3711: for (var j=0; j<num; j++) {
3712: if (form.elements[radioname][j].checked) {
3713: if (form.elements[radioname][j].value == '1') {
3714: if (document.getElementById(divid)) {
3715: document.getElementById(divid).style.display = 'inline-block';
3716: }
3717: setvis = 1;
3718: break;
3719: }
3720: }
3721: }
3722: }
3723: if (setvis == 1) {
3724: break;
3725: }
3726: }
3727: if (!setvis) {
3728: if (document.getElementById(divid)) {
3729: document.getElementById(divid).style.display = 'none';
3730: }
3731: }
1.320 raeburn 3732: }
3733: return;
3734: }
1.405 raeburn 3735:
1.320 raeburn 3736: // ]]>
3737: </script>
3738:
3739: ENDSCRIPT
3740: }
3741:
1.385 raeburn 3742: sub autoupdate_javascript {
3743: return <<"ENDSCRIPT";
3744: <script type="text/javascript">
3745: // <![CDATA[
3746: function toggleLastActiveDays(form) {
3747: var radioname = 'lastactive';
3748: var divid = 'lastactive_div';
3749: var num = form.elements[radioname].length;
3750: if (num) {
3751: var setvis = '';
3752: for (var i=0; i<num; i++) {
3753: if (form.elements[radioname][i].checked) {
3754: if (form.elements[radioname][i].value == '1') {
3755: if (document.getElementById(divid)) {
3756: document.getElementById(divid).style.display = 'inline-block';
3757: }
3758: setvis = 1;
3759: }
3760: break;
3761: }
3762: }
3763: if (!setvis) {
3764: if (document.getElementById(divid)) {
3765: document.getElementById(divid).style.display = 'none';
3766: }
3767: }
3768: }
3769: return;
3770: }
3771: // ]]>
3772: </script>
3773:
3774: ENDSCRIPT
3775: }
3776:
1.399 raeburn 3777: sub autoenroll_javascript {
3778: return <<"ENDSCRIPT";
3779: <script type="text/javascript">
3780: // <![CDATA[
3781: function toggleFailsafe(form) {
3782: var radioname = 'autoenroll_failsafe';
3783: var divid = 'autoenroll_failsafe_div';
3784: var num = form.elements[radioname].length;
3785: if (num) {
3786: var setvis = '';
3787: for (var i=0; i<num; i++) {
3788: if (form.elements[radioname][i].checked) {
3789: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3790: if (document.getElementById(divid)) {
3791: document.getElementById(divid).style.display = 'inline-block';
3792: }
3793: setvis = 1;
3794: }
3795: break;
3796: }
3797: }
3798: if (!setvis) {
3799: if (document.getElementById(divid)) {
3800: document.getElementById(divid).style.display = 'none';
3801: }
3802: }
3803: }
3804: return;
3805: }
3806: // ]]>
3807: </script>
3808:
3809: ENDSCRIPT
3810: }
3811:
1.386 raeburn 3812: sub saml_javascript {
3813: return <<"ENDSCRIPT";
3814: <script type="text/javascript">
3815: // <![CDATA[
3816: function toggleSamlOptions(form,hostid) {
3817: var radioname = 'saml_'+hostid;
3818: var tablecellon = 'samloptionson_'+hostid;
3819: var tablecelloff = 'samloptionsoff_'+hostid;
3820: var num = form.elements[radioname].length;
3821: if (num) {
3822: var setvis = '';
3823: for (var i=0; i<num; i++) {
3824: if (form.elements[radioname][i].checked) {
3825: if (form.elements[radioname][i].value == '1') {
3826: if (document.getElementById(tablecellon)) {
3827: document.getElementById(tablecellon).style.display='';
3828: }
3829: if (document.getElementById(tablecelloff)) {
3830: document.getElementById(tablecelloff).style.display='none';
3831: }
3832: setvis = 1;
3833: }
3834: break;
3835: }
3836: }
3837: if (!setvis) {
3838: if (document.getElementById(tablecellon)) {
3839: document.getElementById(tablecellon).style.display='none';
3840: }
3841: if (document.getElementById(tablecelloff)) {
3842: document.getElementById(tablecelloff).style.display='';
3843: }
3844: }
3845: }
3846: return;
3847: }
3848: // ]]>
3849: </script>
3850:
3851: ENDSCRIPT
3852: }
3853:
1.394 raeburn 3854: sub ipaccess_javascript {
3855: my ($settings) = @_;
3856: my (%ordered,$total,%jstext);
3857: $total = 0;
3858: if (ref($settings) eq 'HASH') {
3859: foreach my $item (keys(%{$settings})) {
3860: if (ref($settings->{$item}) eq 'HASH') {
3861: my $num = $settings->{$item}{'order'};
3862: $ordered{$num} = $item;
3863: }
3864: }
3865: $total = scalar(keys(%{$settings}));
3866: }
3867: my @jsarray = ();
3868: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3869: push(@jsarray,$ordered{$item});
3870: }
3871: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3872: return <<"ENDSCRIPT";
3873: <script type="text/javascript">
3874: // <![CDATA[
3875: function reorderIPaccess(form,item) {
3876: var changedVal;
3877: $jstext
3878: var newpos = 'ipaccess_pos_add';
3879: var maxh = 1 + $total;
3880: var current = new Array;
3881: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3882: if (item == newpos) {
3883: changedVal = newitemVal;
3884: } else {
3885: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3886: current[newitemVal] = newpos;
3887: }
3888: for (var i=0; i<ipaccess.length; i++) {
3889: var elementName = 'ipaccess_pos_'+ipaccess[i];
3890: if (elementName != item) {
3891: if (form.elements[elementName]) {
3892: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3893: current[currVal] = elementName;
3894: }
3895: }
3896: }
3897: var oldVal;
3898: for (var j=0; j<maxh; j++) {
3899: if (current[j] == undefined) {
3900: oldVal = j;
3901: }
3902: }
3903: if (oldVal < changedVal) {
3904: for (var k=oldVal+1; k<=changedVal ; k++) {
3905: var elementName = current[k];
3906: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3907: }
3908: } else {
3909: for (var k=changedVal; k<oldVal; k++) {
3910: var elementName = current[k];
3911: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3912: }
3913: }
3914: return;
3915: }
3916: // ]]>
3917: </script>
3918:
3919: ENDSCRIPT
3920: }
3921:
1.3 raeburn 3922: sub print_autoenroll {
1.30 raeburn 3923: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3924: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3925: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3926: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3927: $failsafesty = 'none';
3928: %failsafechecked = (
3929: off => ' checked="checked"',
3930: );
1.3 raeburn 3931: if (ref($settings) eq 'HASH') {
3932: if (exists($settings->{'run'})) {
3933: if ($settings->{'run'} eq '0') {
3934: $runoff = ' checked="checked" ';
3935: $runon = ' ';
3936: } else {
3937: $runon = ' checked="checked" ';
3938: $runoff = ' ';
3939: }
3940: } else {
3941: if ($autorun) {
3942: $runon = ' checked="checked" ';
3943: $runoff = ' ';
3944: } else {
3945: $runoff = ' checked="checked" ';
3946: $runon = ' ';
3947: }
3948: }
1.129 raeburn 3949: if (exists($settings->{'co-owners'})) {
3950: if ($settings->{'co-owners'} eq '0') {
3951: $coownersoff = ' checked="checked" ';
3952: $coownerson = ' ';
3953: } else {
3954: $coownerson = ' checked="checked" ';
3955: $coownersoff = ' ';
3956: }
3957: } else {
3958: $coownersoff = ' checked="checked" ';
3959: $coownerson = ' ';
3960: }
1.3 raeburn 3961: if (exists($settings->{'sender_domain'})) {
3962: $defdom = $settings->{'sender_domain'};
3963: }
1.399 raeburn 3964: if (exists($settings->{'failsafe'})) {
3965: $failsafe = $settings->{'failsafe'};
3966: if ($failsafe eq 'zero') {
1.400 raeburn 3967: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 3968: $failsafechecked{'off'} = '';
3969: $failsafesty = 'inline-block';
3970: } elsif ($failsafe eq 'any') {
3971: $failsafechecked{'any'} = ' checked="checked"';
3972: $failsafechecked{'off'} = '';
3973: }
3974: $autofailsafe = $settings->{'autofailsafe'};
3975: } elsif (exists($settings->{'autofailsafe'})) {
3976: $autofailsafe = $settings->{'autofailsafe'};
3977: if ($autofailsafe ne '') {
3978: $failsafechecked{'zero'} = ' checked="checked"';
3979: $failsafe = 'zero';
1.400 raeburn 3980: $failsafechecked{'off'} = '';
1.399 raeburn 3981: }
1.274 raeburn 3982: }
1.14 raeburn 3983: } else {
3984: if ($autorun) {
3985: $runon = ' checked="checked" ';
3986: $runoff = ' ';
3987: } else {
3988: $runoff = ' checked="checked" ';
3989: $runon = ' ';
3990: }
1.3 raeburn 3991: }
3992: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3993: my $notif_sender;
3994: if (ref($settings) eq 'HASH') {
3995: $notif_sender = $settings->{'sender_uname'};
3996: }
1.3 raeburn 3997: my $datatable='<tr class="LC_odd_row">'.
3998: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3999: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4000: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4001: $runon.' value="1" />'.&mt('Yes').'</label> '.
4002: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4003: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4004: '</tr><tr>'.
4005: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4006: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4007: &mt('username').': '.
4008: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4009: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4010: ': '.$domform.'</span></td></tr>'.
4011: '<tr class="LC_odd_row">'.
4012: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4013: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4014: '<input type="radio" name="autoassign_coowners"'.
4015: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4016: '<label><input type="radio" name="autoassign_coowners"'.
4017: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4018: '</tr><tr>'.
4019: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4020: '<td class="LC_left_item"><span class="LC_nobreak">'.
4021: '<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> '.
4022: '<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 />'.
4023: '<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 4024: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4025: '<span class="LC_nobreak">'.
4026: &mt('Threshold for number of students in section to drop: [_1]',
4027: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4028: '</span></div></td></tr>';
1.274 raeburn 4029: $$rowtotal += 4;
1.3 raeburn 4030: return $datatable;
4031: }
4032:
4033: sub print_autoupdate {
1.30 raeburn 4034: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4035: my ($enable,$datatable);
1.3 raeburn 4036: if ($position eq 'top') {
1.385 raeburn 4037: my %choices = &Apache::lonlocal::texthash (
4038: run => 'Auto-update active?',
4039: classlists => 'Update information in classlists?',
4040: unexpired => 'Skip updates for users without active or future roles?',
4041: lastactive => 'Skip updates for inactive users?',
4042: );
4043: my $itemcount = 0;
1.3 raeburn 4044: my $updateon = ' ';
4045: my $updateoff = ' checked="checked" ';
4046: if (ref($settings) eq 'HASH') {
4047: if ($settings->{'run'} eq '1') {
4048: $updateon = $updateoff;
4049: $updateoff = ' ';
4050: }
4051: }
1.385 raeburn 4052: $enable = '<tr class="LC_odd_row">'.
4053: '<td>'.$choices{'run'}.'</td>'.
4054: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4055: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4056: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4057: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4058: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4059: '</tr>';
1.385 raeburn 4060: my @toggles = ('classlists','unexpired');
4061: my %defaultchecked = ('classlists' => 'off',
4062: 'unexpired' => 'off'
4063: );
4064: $$rowtotal ++;
4065: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4066: \%choices,$itemcount,'','','left','no');
4067: $datatable = $enable.$datatable;
4068: $$rowtotal += $itemcount;
4069: my $lastactiveon = ' ';
4070: my $lastactiveoff = ' checked="checked" ';
4071: my $lastactivestyle = 'none';
4072: my $lastactivedays;
4073: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4074: if (ref($settings) eq 'HASH') {
4075: if ($settings->{'lastactive'} =~ /^\d+$/) {
4076: $lastactiveon = $lastactiveoff;
4077: $lastactiveoff = ' ';
4078: $lastactivestyle = 'inline-block';
4079: $lastactivedays = $settings->{'lastactive'};
4080: }
4081: }
4082: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4083: $datatable .= '<tr'.$css_class.'>'.
4084: '<td>'.$choices{'lastactive'}.'</td>'.
4085: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4086: '<input type="radio" name="lastactive"'.
4087: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4088: ' <label>'.
4089: '<input type="radio" name="lastactive"'.
4090: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4091: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4092: ': '.&mt('inactive = no activity in last [_1] days',
4093: '<input type="text" size="5" name="lastactivedays" value="'.
4094: $lastactivedays.'" />').
4095: '</span></td>'.
4096: '</tr>';
4097: $$rowtotal ++;
1.131 raeburn 4098: } elsif ($position eq 'middle') {
4099: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4100: my $numinrow = 3;
4101: my $locknamesettings;
4102: $datatable .= &insttypes_row($settings,$types,$usertypes,
4103: $dom,$numinrow,$othertitle,
1.305 raeburn 4104: 'lockablenames',$rowtotal);
1.131 raeburn 4105: $$rowtotal ++;
1.3 raeburn 4106: } else {
1.44 raeburn 4107: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4108: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4109: 'permanentemail','id');
1.33 raeburn 4110: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4111: my $numrows = 0;
1.26 raeburn 4112: if (ref($types) eq 'ARRAY') {
4113: if (@{$types} > 0) {
4114: $datatable =
4115: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4116: \@fields,$types,\$numrows);
1.30 raeburn 4117: $$rowtotal += @{$types};
1.26 raeburn 4118: }
1.3 raeburn 4119: }
4120: $datatable .=
4121: &usertype_update_row($settings,{'default' => $othertitle},
4122: \%fieldtitles,\@fields,['default'],
4123: \$numrows);
1.30 raeburn 4124: $$rowtotal ++;
1.3 raeburn 4125: }
4126: return $datatable;
4127: }
4128:
1.125 raeburn 4129: sub print_autocreate {
4130: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4131: my (%createon,%createoff,%currhash);
1.125 raeburn 4132: my @types = ('xml','req');
4133: if (ref($settings) eq 'HASH') {
4134: foreach my $item (@types) {
4135: $createoff{$item} = ' checked="checked" ';
4136: $createon{$item} = ' ';
4137: if (exists($settings->{$item})) {
4138: if ($settings->{$item}) {
4139: $createon{$item} = ' checked="checked" ';
4140: $createoff{$item} = ' ';
4141: }
4142: }
4143: }
1.210 raeburn 4144: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4145: $currhash{$settings->{'xmldc'}} = 1;
4146: }
1.125 raeburn 4147: } else {
4148: foreach my $item (@types) {
4149: $createoff{$item} = ' checked="checked" ';
4150: $createon{$item} = ' ';
4151: }
4152: }
4153: $$rowtotal += 2;
1.191 raeburn 4154: my $numinrow = 2;
1.125 raeburn 4155: my $datatable='<tr class="LC_odd_row">'.
4156: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4157: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4158: '<input type="radio" name="autocreate_xml"'.
4159: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4160: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4161: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4162: '</td></tr><tr>'.
4163: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4164: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4165: '<input type="radio" name="autocreate_req"'.
4166: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4167: '<label><input type="radio" name="autocreate_req"'.
4168: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4169: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4170: 'autocreate_xmldc',%currhash);
1.247 raeburn 4171: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4172: if ($numdc > 1) {
1.247 raeburn 4173: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4174: '</td><td class="LC_left_item">';
1.125 raeburn 4175: } else {
1.247 raeburn 4176: $datatable .= &mt('Course creation processed as:').
4177: '</td><td class="LC_right_item">';
1.125 raeburn 4178: }
1.247 raeburn 4179: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4180: $$rowtotal += $rows;
1.125 raeburn 4181: return $datatable;
4182: }
4183:
1.23 raeburn 4184: sub print_directorysrch {
1.277 raeburn 4185: my ($position,$dom,$settings,$rowtotal) = @_;
4186: my $datatable;
4187: if ($position eq 'top') {
4188: my $instsrchon = ' ';
4189: my $instsrchoff = ' checked="checked" ';
4190: my ($exacton,$containson,$beginson);
4191: my $instlocalon = ' ';
4192: my $instlocaloff = ' checked="checked" ';
4193: if (ref($settings) eq 'HASH') {
4194: if ($settings->{'available'} eq '1') {
4195: $instsrchon = $instsrchoff;
4196: $instsrchoff = ' ';
4197: }
4198: if ($settings->{'localonly'} eq '1') {
4199: $instlocalon = $instlocaloff;
4200: $instlocaloff = ' ';
4201: }
4202: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4203: foreach my $type (@{$settings->{'searchtypes'}}) {
4204: if ($type eq 'exact') {
4205: $exacton = ' checked="checked" ';
4206: } elsif ($type eq 'contains') {
4207: $containson = ' checked="checked" ';
4208: } elsif ($type eq 'begins') {
4209: $beginson = ' checked="checked" ';
4210: }
4211: }
4212: } else {
4213: if ($settings->{'searchtypes'} eq 'exact') {
4214: $exacton = ' checked="checked" ';
4215: } elsif ($settings->{'searchtypes'} eq 'contains') {
4216: $containson = ' checked="checked" ';
4217: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4218: $exacton = ' checked="checked" ';
4219: $containson = ' checked="checked" ';
4220: }
4221: }
1.277 raeburn 4222: }
4223: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4224: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4225:
4226: my $numinrow = 4;
4227: my $cansrchrow = 0;
4228: $datatable='<tr class="LC_odd_row">'.
4229: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4230: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4231: '<input type="radio" name="dirsrch_available"'.
4232: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4233: '<label><input type="radio" name="dirsrch_available"'.
4234: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4235: '</tr><tr>'.
4236: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4237: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4238: '<input type="radio" name="dirsrch_instlocalonly"'.
4239: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4240: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4241: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4242: '</tr>';
4243: $$rowtotal += 2;
4244: if (ref($usertypes) eq 'HASH') {
4245: if (keys(%{$usertypes}) > 0) {
4246: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4247: $numinrow,$othertitle,'cansearch',
4248: $rowtotal);
1.277 raeburn 4249: $cansrchrow = 1;
1.25 raeburn 4250: }
1.23 raeburn 4251: }
1.277 raeburn 4252: if ($cansrchrow) {
4253: $$rowtotal ++;
4254: $datatable .= '<tr>';
4255: } else {
4256: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4257: }
1.277 raeburn 4258: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4259: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4260: foreach my $title (@{$titleorder}) {
4261: if (defined($searchtitles->{$title})) {
4262: my $check = ' ';
4263: if (ref($settings) eq 'HASH') {
4264: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4265: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4266: $check = ' checked="checked" ';
4267: }
1.39 raeburn 4268: }
1.25 raeburn 4269: }
1.277 raeburn 4270: $datatable .= '<td class="LC_left_item">'.
4271: '<span class="LC_nobreak"><label>'.
4272: '<input type="checkbox" name="searchby" '.
4273: 'value="'.$title.'"'.$check.'/>'.
4274: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4275: }
4276: }
1.277 raeburn 4277: $datatable .= '</tr></table></td></tr>';
4278: $$rowtotal ++;
4279: if ($cansrchrow) {
4280: $datatable .= '<tr class="LC_odd_row">';
4281: } else {
4282: $datatable .= '<tr>';
4283: }
4284: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4285: '<td class="LC_left_item" colspan="2">'.
4286: '<span class="LC_nobreak"><label>'.
4287: '<input type="checkbox" name="searchtypes" '.
4288: $exacton.' value="exact" />'.&mt('Exact match').
4289: '</label> '.
4290: '<label><input type="checkbox" name="searchtypes" '.
4291: $beginson.' value="begins" />'.&mt('Begins with').
4292: '</label> '.
4293: '<label><input type="checkbox" name="searchtypes" '.
4294: $containson.' value="contains" />'.&mt('Contains').
4295: '</label></span></td></tr>';
4296: $$rowtotal ++;
1.26 raeburn 4297: } else {
1.277 raeburn 4298: my $domsrchon = ' checked="checked" ';
4299: my $domsrchoff = ' ';
4300: my $domlocalon = ' ';
4301: my $domlocaloff = ' checked="checked" ';
4302: if (ref($settings) eq 'HASH') {
4303: if ($settings->{'lclocalonly'} eq '1') {
4304: $domlocalon = $domlocaloff;
4305: $domlocaloff = ' ';
4306: }
4307: if ($settings->{'lcavailable'} eq '0') {
4308: $domsrchoff = $domsrchon;
4309: $domsrchon = ' ';
4310: }
4311: }
4312: $datatable='<tr class="LC_odd_row">'.
4313: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4314: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4315: '<input type="radio" name="dirsrch_domavailable"'.
4316: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4317: '<label><input type="radio" name="dirsrch_domavailable"'.
4318: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4319: '</tr><tr>'.
4320: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4321: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4322: '<input type="radio" name="dirsrch_domlocalonly"'.
4323: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4324: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4325: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4326: '</tr>';
4327: $$rowtotal += 2;
1.26 raeburn 4328: }
1.25 raeburn 4329: return $datatable;
4330: }
4331:
1.28 raeburn 4332: sub print_contacts {
1.286 raeburn 4333: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4334: my $datatable;
4335: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4336: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4337: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4338: if ($position eq 'top') {
4339: if (ref($settings) eq 'HASH') {
4340: foreach my $item (@contacts) {
4341: if (exists($settings->{$item})) {
4342: $to{$item} = $settings->{$item};
4343: }
4344: }
4345: }
4346: } elsif ($position eq 'middle') {
4347: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4348: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4349: foreach my $type (@mailings) {
4350: $otheremails{$type} = '';
4351: }
1.340 raeburn 4352: } elsif ($position eq 'lower') {
4353: if (ref($settings) eq 'HASH') {
4354: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4355: %lonstatus = %{$settings->{'lonstatus'}};
4356: }
4357: }
1.286 raeburn 4358: } else {
4359: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4360: foreach my $type (@mailings) {
4361: $otheremails{$type} = '';
4362: }
1.286 raeburn 4363: $bccemails{'helpdeskmail'} = '';
4364: $bccemails{'otherdomsmail'} = '';
4365: $includestr{'helpdeskmail'} = '';
4366: $includestr{'otherdomsmail'} = '';
4367: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4368: }
1.28 raeburn 4369: if (ref($settings) eq 'HASH') {
1.340 raeburn 4370: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4371: foreach my $type (@mailings) {
4372: if (exists($settings->{$type})) {
4373: if (ref($settings->{$type}) eq 'HASH') {
4374: foreach my $item (@contacts) {
4375: if ($settings->{$type}{$item}) {
4376: $checked{$type}{$item} = ' checked="checked" ';
4377: }
4378: }
4379: $otheremails{$type} = $settings->{$type}{'others'};
4380: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4381: $bccemails{$type} = $settings->{$type}{'bcc'};
4382: if ($settings->{$type}{'include'} ne '') {
4383: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4384: $includestr{$type} = &unescape($includestr{$type});
4385: }
4386: }
4387: }
4388: } elsif ($type eq 'lonstatusmail') {
4389: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4390: }
1.28 raeburn 4391: }
4392: }
1.286 raeburn 4393: if ($position eq 'bottom') {
4394: foreach my $type (@mailings) {
4395: $bccemails{$type} = $settings->{$type}{'bcc'};
4396: if ($settings->{$type}{'include'} ne '') {
4397: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4398: $includestr{$type} = &unescape($includestr{$type});
4399: }
4400: }
4401: if (ref($settings->{'helpform'}) eq 'HASH') {
4402: if (ref($fields) eq 'ARRAY') {
4403: foreach my $field (@{$fields}) {
4404: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4405: }
1.286 raeburn 4406: }
4407: if (exists($settings->{'helpform'}{'maxsize'})) {
4408: $maxsize = $settings->{'helpform'}{'maxsize'};
4409: } else {
1.289 raeburn 4410: $maxsize = '1.0';
1.286 raeburn 4411: }
4412: } else {
4413: if (ref($fields) eq 'ARRAY') {
4414: foreach my $field (@{$fields}) {
4415: $currfield{$field} = 'yes';
1.134 raeburn 4416: }
1.28 raeburn 4417: }
1.286 raeburn 4418: $maxsize = '1.0';
1.28 raeburn 4419: }
4420: }
4421: } else {
1.286 raeburn 4422: if ($position eq 'top') {
4423: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4424: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4425: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4426: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4427: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4428: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4429: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4430: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4431: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4432: } elsif ($position eq 'bottom') {
4433: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4434: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4435: if (ref($fields) eq 'ARRAY') {
4436: foreach my $field (@{$fields}) {
4437: $currfield{$field} = 'yes';
4438: }
4439: }
4440: $maxsize = '1.0';
4441: }
1.28 raeburn 4442: }
4443: my ($titles,$short_titles) = &contact_titles();
4444: my $rownum = 0;
4445: my $css_class;
1.286 raeburn 4446: if ($position eq 'top') {
4447: foreach my $item (@contacts) {
4448: $css_class = $rownum%2?' class="LC_odd_row"':'';
4449: $datatable .= '<tr'.$css_class.'>'.
4450: '<td><span class="LC_nobreak">'.$titles->{$item}.
4451: '</span></td><td class="LC_right_item">'.
4452: '<input type="text" name="'.$item.'" value="'.
4453: $to{$item}.'" /></td></tr>';
4454: $rownum ++;
4455: }
1.315 raeburn 4456: } elsif ($position eq 'bottom') {
4457: $css_class = $rownum%2?' class="LC_odd_row"':'';
4458: $datatable .= '<tr'.$css_class.'>'.
4459: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4460: &mt('(e-mail, subject, and description always shown)').
4461: '</td><td class="LC_left_item">';
4462: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4463: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4464: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4465: foreach my $field (@{$fields}) {
4466: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4467: if (($field eq 'screenshot') || ($field eq 'cc')) {
4468: $datatable .= ' '.&mt('(logged-in users)');
4469: }
4470: $datatable .='</td><td>';
4471: my $clickaction;
4472: if ($field eq 'screenshot') {
4473: $clickaction = ' onclick="screenshotSize(this);"';
4474: }
4475: if (ref($possoptions->{$field}) eq 'ARRAY') {
4476: foreach my $option (@{$possoptions->{$field}}) {
4477: my $checked;
4478: if ($currfield{$field} eq $option) {
4479: $checked = ' checked="checked"';
4480: }
4481: $datatable .= '<span class="LC_nobreak"><label>'.
4482: '<input type="radio" name="helpform_'.$field.'" '.
4483: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4484: '</label></span>'.(' 'x2);
4485: }
4486: }
4487: if ($field eq 'screenshot') {
4488: my $display;
4489: if ($currfield{$field} eq 'no') {
4490: $display = ' style="display:none"';
4491: }
1.334 raeburn 4492: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4493: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4494: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4495: }
4496: $datatable .= '</td></tr>';
4497: }
4498: $datatable .= '</table>';
4499: }
4500: $datatable .= '</td></tr>'."\n";
4501: $rownum ++;
4502: }
1.340 raeburn 4503: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4504: foreach my $type (@mailings) {
4505: $css_class = $rownum%2?' class="LC_odd_row"':'';
4506: $datatable .= '<tr'.$css_class.'>'.
4507: '<td><span class="LC_nobreak">'.
4508: $titles->{$type}.': </span></td>'.
4509: '<td class="LC_left_item">';
4510: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4511: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4512: }
4513: $datatable .= '<span class="LC_nobreak">';
4514: foreach my $item (@contacts) {
4515: $datatable .= '<label>'.
4516: '<input type="checkbox" name="'.$type.'"'.
4517: $checked{$type}{$item}.
4518: ' value="'.$item.'" />'.$short_titles->{$item}.
4519: '</label> ';
4520: }
4521: $datatable .= '</span><br />'.&mt('Others').': '.
4522: '<input type="text" name="'.$type.'_others" '.
4523: 'value="'.$otheremails{$type}.'" />';
4524: my %locchecked;
4525: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4526: foreach my $loc ('s','b') {
4527: if ($includeloc{$type} eq $loc) {
4528: $locchecked{$loc} = ' checked="checked"';
4529: last;
4530: }
4531: }
4532: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4533: '<input type="text" name="'.$type.'_bcc" '.
4534: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4535: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4536: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4537: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4538: '<span class="LC_nobreak">'.&mt('Location:').' '.
4539: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4540: (' 'x2).
4541: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4542: '</span></fieldset>';
4543: }
4544: $datatable .= '</td></tr>'."\n";
4545: $rownum ++;
4546: }
1.28 raeburn 4547: }
1.286 raeburn 4548: if ($position eq 'middle') {
4549: my %choices;
1.340 raeburn 4550: my $corelink = &core_link_msu();
4551: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4552: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4553: $corelink);
4554: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4555: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4556: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4557: 'reportupdates' => 'on',
4558: 'reportstatus' => 'on');
1.286 raeburn 4559: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4560: \%choices,$rownum);
4561: $datatable .= $reports;
1.340 raeburn 4562: } elsif ($position eq 'lower') {
1.378 raeburn 4563: my (%current,%excluded,%weights);
1.340 raeburn 4564: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4565: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4566: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4567: } else {
1.378 raeburn 4568: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4569: }
4570: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4571: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4572: } else {
1.378 raeburn 4573: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4574: }
4575: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4576: foreach my $type ('E','W','N','U') {
1.340 raeburn 4577: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4578: $weights{$type} = $lonstatus{'weights'}{$type};
4579: } else {
4580: $weights{$type} = $defaults->{$type};
4581: }
4582: }
4583: } else {
1.341 raeburn 4584: foreach my $type ('E','W','N','U') {
1.340 raeburn 4585: $weights{$type} = $defaults->{$type};
4586: }
4587: }
4588: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4589: if (@{$lonstatus{'excluded'}} > 0) {
4590: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4591: }
4592: }
1.378 raeburn 4593: foreach my $item ('errorthreshold','errorsysmail') {
4594: $css_class = $rownum%2?' class="LC_odd_row"':'';
4595: $datatable .= '<tr'.$css_class.'>'.
4596: '<td class="LC_left_item"><span class="LC_nobreak">'.
4597: $titles->{$item}.
4598: '</span></td><td class="LC_left_item">'.
4599: '<input type="text" name="'.$item.'" value="'.
4600: $current{$item}.'" size="5" /></td></tr>';
4601: $rownum ++;
4602: }
1.340 raeburn 4603: $css_class = $rownum%2?' class="LC_odd_row"':'';
4604: $datatable .= '<tr'.$css_class.'>'.
4605: '<td class="LC_left_item">'.
4606: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4607: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4608: foreach my $type ('E','W','N','U') {
1.340 raeburn 4609: $datatable .= '<td>'.$names->{$type}.'<br />'.
4610: '<input type="text" name="errorweights_'.$type.'" value="'.
4611: $weights{$type}.'" size="5" /></td>';
4612: }
4613: $datatable .= '</tr></table></tr>';
4614: $rownum ++;
4615: $css_class = $rownum%2?' class="LC_odd_row"':'';
4616: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4617: $titles->{'errorexcluded'}.'</td>'.
4618: '<td class="LC_left_item"><table>';
4619: my $numinrow = 4;
4620: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4621: for (my $i=0; $i<@ids; $i++) {
4622: my $rem = $i%($numinrow);
4623: if ($rem == 0) {
4624: if ($i > 0) {
4625: $datatable .= '</tr>';
4626: }
4627: $datatable .= '<tr>';
4628: }
4629: my $check;
4630: if ($excluded{$ids[$i]}) {
4631: $check = ' checked="checked" ';
4632: }
4633: $datatable .= '<td class="LC_left_item">'.
4634: '<span class="LC_nobreak"><label>'.
4635: '<input type="checkbox" name="errorexcluded" '.
4636: 'value="'.$ids[$i].'"'.$check.' />'.
4637: $ids[$i].'</label></span></td>';
4638: }
4639: my $colsleft = $numinrow - @ids%($numinrow);
4640: if ($colsleft > 1 ) {
4641: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4642: ' </td>';
4643: } elsif ($colsleft == 1) {
4644: $datatable .= '<td class="LC_left_item"> </td>';
4645: }
4646: $datatable .= '</tr></table></td></tr>';
4647: $rownum ++;
1.286 raeburn 4648: } elsif ($position eq 'bottom') {
1.315 raeburn 4649: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4650: my (@posstypes,%usertypeshash);
4651: if (ref($types) eq 'ARRAY') {
4652: @posstypes = @{$types};
4653: }
4654: if (@posstypes) {
4655: if (ref($usertypes) eq 'HASH') {
4656: %usertypeshash = %{$usertypes};
4657: }
4658: my @overridden;
4659: my $numinrow = 4;
4660: if (ref($settings) eq 'HASH') {
4661: if (ref($settings->{'overrides'}) eq 'HASH') {
4662: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4663: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4664: push(@overridden,$key);
4665: foreach my $item (@contacts) {
4666: if ($settings->{'overrides'}{$key}{$item}) {
4667: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4668: }
4669: }
4670: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4671: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4672: $includeloc{'override_'.$key} = '';
4673: $includestr{'override_'.$key} = '';
4674: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4675: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4676: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4677: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4678: }
1.286 raeburn 4679: }
4680: }
4681: }
1.315 raeburn 4682: }
4683: my $customclass = 'LC_helpdesk_override';
4684: my $optionsprefix = 'LC_options_helpdesk_';
4685:
4686: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4687:
4688: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4689: $numinrow,$othertitle,'overrides',
4690: \$rownum,$onclicktypes,$customclass);
4691: $rownum ++;
4692: $usertypeshash{'default'} = $othertitle;
4693: foreach my $status (@posstypes) {
4694: my $css_class;
4695: if ($rownum%2) {
4696: $css_class = 'LC_odd_row ';
4697: }
4698: $css_class .= $customclass;
4699: my $rowid = $optionsprefix.$status;
4700: my $hidden = 1;
4701: my $currstyle = 'display:none';
4702: if (grep(/^\Q$status\E$/,@overridden)) {
4703: $currstyle = 'display:table-row';
4704: $hidden = 0;
4705: }
4706: my $key = 'override_'.$status;
4707: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4708: $includeloc{$key},$includestr{$key},$status,$rowid,
4709: $usertypeshash{$status},$css_class,$currstyle,
4710: \@contacts,$short_titles);
4711: unless ($hidden) {
4712: $rownum ++;
1.286 raeburn 4713: }
4714: }
1.134 raeburn 4715: }
1.28 raeburn 4716: }
1.30 raeburn 4717: $$rowtotal += $rownum;
1.28 raeburn 4718: return $datatable;
4719: }
4720:
1.340 raeburn 4721: sub core_link_msu {
4722: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4723: &mt('LON-CAPA core group - MSU'),600,500);
4724: }
4725:
1.315 raeburn 4726: sub overridden_helpdesk {
4727: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4728: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4729: my $class = 'LC_left_item';
4730: if ($css_class) {
4731: $css_class = ' class="'.$css_class.'"';
4732: }
4733: if ($rowid) {
4734: $rowid = ' id="'.$rowid.'"';
4735: }
4736: if ($rowstyle) {
4737: $rowstyle = ' style="'.$rowstyle.'"';
4738: }
4739: my ($output,$description);
4740: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4741: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4742: "<td>$description</td>\n".
4743: '<td class="'.$class.'" colspan="2">'.
4744: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4745: '<span class="LC_nobreak">';
4746: if (ref($contacts) eq 'ARRAY') {
4747: foreach my $item (@{$contacts}) {
4748: my $check;
4749: if (ref($checked) eq 'HASH') {
4750: $check = $checked->{$item};
4751: }
4752: my $title;
4753: if (ref($short_titles) eq 'HASH') {
4754: $title = $short_titles->{$item};
4755: }
4756: $output .= '<label>'.
4757: '<input type="checkbox" name="override_'.$type.'"'.$check.
4758: ' value="'.$item.'" />'.$title.'</label> ';
4759: }
4760: }
4761: $output .= '</span><br />'.&mt('Others').': '.
4762: '<input type="text" name="override_'.$type.'_others" '.
4763: 'value="'.$otheremails.'" />';
4764: my %locchecked;
4765: foreach my $loc ('s','b') {
4766: if ($includeloc eq $loc) {
4767: $locchecked{$loc} = ' checked="checked"';
4768: last;
4769: }
4770: }
4771: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4772: '<input type="text" name="override_'.$type.'_bcc" '.
4773: 'value="'.$bccemails.'" /></fieldset>'.
4774: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4775: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4776: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4777: '<span class="LC_nobreak">'.&mt('Location:').' '.
4778: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4779: (' 'x2).
4780: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4781: '</span></fieldset>'.
4782: '</td></tr>'."\n";
4783: return $output;
4784: }
4785:
1.286 raeburn 4786: sub contacts_javascript {
4787: return <<"ENDSCRIPT";
4788:
4789: <script type="text/javascript">
4790: // <![CDATA[
4791:
4792: function screenshotSize(field) {
4793: if (document.getElementById('help_screenshotsize')) {
4794: if (field.value == 'no') {
1.289 raeburn 4795: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4796: } else {
4797: document.getElementById('help_screenshotsize').style.display="";
4798: }
4799: }
4800: return;
4801: }
4802:
1.315 raeburn 4803: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4804: if (form.elements[checkbox].length != undefined) {
4805: var count = 0;
4806: if (docount) {
4807: for (var i=0; i<form.elements[checkbox].length; i++) {
4808: if (form.elements[checkbox][i].checked) {
4809: count ++;
4810: }
4811: }
4812: }
4813: for (var i=0; i<form.elements[checkbox].length; i++) {
4814: var type = form.elements[checkbox][i].value;
4815: if (document.getElementById(prefix+type)) {
4816: if (form.elements[checkbox][i].checked) {
4817: document.getElementById(prefix+type).style.display = 'table-row';
4818: if (count % 2 == 1) {
4819: document.getElementById(prefix+type).className = target+' LC_odd_row';
4820: } else {
4821: document.getElementById(prefix+type).className = target;
4822: }
4823: count ++;
4824: } else {
4825: document.getElementById(prefix+type).style.display = 'none';
4826: }
4827: }
4828: }
4829: }
4830: return;
4831: }
4832:
4833:
1.286 raeburn 4834: // ]]>
4835: </script>
4836:
4837: ENDSCRIPT
4838: }
4839:
1.118 jms 4840: sub print_helpsettings {
1.282 raeburn 4841: my ($position,$dom,$settings,$rowtotal) = @_;
4842: my $confname = $dom.'-domainconfig';
1.285 raeburn 4843: my $formname = 'display';
1.168 raeburn 4844: my ($datatable,$itemcount);
1.282 raeburn 4845: if ($position eq 'top') {
4846: $itemcount = 1;
4847: my (%choices,%defaultchecked,@toggles);
4848: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4849: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4850: &mt('LON-CAPA bug tracker'),600,500));
4851: %defaultchecked = ('submitbugs' => 'on');
4852: @toggles = ('submitbugs');
4853: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4854: \%choices,$itemcount);
4855: $$rowtotal ++;
4856: } else {
4857: my $css_class;
4858: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4859: my (%customroles,%ordered,%current);
1.301 raeburn 4860: if (ref($settings) eq 'HASH') {
4861: if (ref($settings->{'adhoc'}) eq 'HASH') {
4862: %current = %{$settings->{'adhoc'}};
4863: }
1.285 raeburn 4864: }
4865: my $count = 0;
4866: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4867: if ($key=~/^rolesdef\_(\w+)$/) {
4868: my $rolename = $1;
1.285 raeburn 4869: my (%privs,$order);
1.282 raeburn 4870: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4871: $customroles{$rolename} = \%privs;
1.285 raeburn 4872: if (ref($current{$rolename}) eq 'HASH') {
4873: $order = $current{$rolename}{'order'};
4874: }
4875: if ($order eq '') {
4876: $order = $count;
4877: }
4878: $ordered{$order} = $rolename;
4879: $count++;
4880: }
4881: }
4882: my $maxnum = scalar(keys(%ordered));
4883: my @roles_by_num = ();
4884: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4885: push(@roles_by_num,$item);
4886: }
4887: my $context = 'domprefs';
4888: my $crstype = 'Course';
4889: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4890: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4891: my ($numstatustypes,@jsarray);
4892: if (ref($types) eq 'ARRAY') {
4893: if (@{$types} > 0) {
4894: $numstatustypes = scalar(@{$types});
4895: push(@accesstypes,'status');
4896: @jsarray = ('bystatus');
1.282 raeburn 4897: }
4898: }
1.290 raeburn 4899: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4900: if (keys(%domhelpdesk)) {
4901: push(@accesstypes,('inc','exc'));
4902: push(@jsarray,('notinc','notexc'));
4903: }
4904: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4905: my $context = 'domprefs';
4906: my $crstype = 'Course';
1.285 raeburn 4907: my $prefix = 'helproles_';
4908: my $add_class = 'LC_hidden';
4909: foreach my $num (@roles_by_num) {
4910: my $role = $ordered{$num};
4911: my ($desc,$access,@statuses);
4912: if (ref($current{$role}) eq 'HASH') {
4913: $desc = $current{$role}{'desc'};
4914: $access = $current{$role}{'access'};
4915: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4916: @statuses = @{$current{$role}{'insttypes'}};
4917: }
4918: }
4919: if ($desc eq '') {
4920: $desc = $role;
4921: }
4922: my $identifier = 'custhelp'.$num;
1.282 raeburn 4923: my %full=();
4924: my %levels= (
4925: course => {},
4926: domain => {},
4927: system => {},
4928: );
4929: my %levelscurrent=(
4930: course => {},
4931: domain => {},
4932: system => {},
4933: );
4934: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4935: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4936: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4937: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4938: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4939: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4940: for (my $k=0; $k<=$maxnum; $k++) {
4941: my $vpos = $k+1;
4942: my $selstr;
4943: if ($k == $num) {
4944: $selstr = ' selected="selected" ';
4945: }
4946: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4947: }
4948: $datatable .= '</select>'.(' 'x2).
4949: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4950: '</td>'.
4951: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4952: &mt('Name shown to users:').
4953: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4954: '</fieldset>'.
4955: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4956: $othertitle,$usertypes,$types,\%domhelpdesk).
4957: '<fieldset>'.
4958: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4959: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4960: \%levelscurrent,$identifier,
4961: 'LC_hidden',$prefix.$num.'_privs').
4962: '</fieldset></td>';
1.282 raeburn 4963: $itemcount ++;
4964: }
4965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4966: my $newcust = 'custhelp'.$count;
4967: my (%privs,%levelscurrent);
4968: my %full=();
4969: my %levels= (
4970: course => {},
4971: domain => {},
4972: system => {},
4973: );
4974: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4975: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4976: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4977: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4978: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4979: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4980: for (my $k=0; $k<$maxnum+1; $k++) {
4981: my $vpos = $k+1;
4982: my $selstr;
4983: if ($k == $maxnum) {
4984: $selstr = ' selected="selected" ';
4985: }
4986: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4987: }
4988: $datatable .= '</select> '."\n".
1.282 raeburn 4989: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4990: '</label></span></td>'.
1.285 raeburn 4991: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4992: '<span class="LC_nobreak">'.
4993: &mt('Internal name:').
4994: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4995: '</span>'.(' 'x4).
4996: '<span class="LC_nobreak">'.
4997: &mt('Name shown to users:').
4998: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4999: '</span></fieldset>'.
5000: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5001: $usertypes,$types,\%domhelpdesk).
5002: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5003: &Apache::lonuserutils::custom_role_header($context,$crstype,
5004: \@templateroles,$newcust).
5005: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5006: \%levelscurrent,$newcust).
1.334 raeburn 5007: '</fieldset>'.
5008: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5009: '</td></tr>';
1.282 raeburn 5010: $count ++;
5011: $$rowtotal += $count;
5012: }
1.166 raeburn 5013: return $datatable;
1.121 raeburn 5014: }
5015:
1.285 raeburn 5016: sub adhocbutton {
5017: my ($prefix,$num,$field,$visibility) = @_;
5018: my %lt = &Apache::lonlocal::texthash(
5019: show => 'Show details',
5020: hide => 'Hide details',
5021: );
5022: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5023: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5024: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5025: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5026: }
5027:
5028: sub helpsettings_javascript {
5029: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5030: return unless(ref($roles_by_num) eq 'ARRAY');
5031: my %html_js_lt = &Apache::lonlocal::texthash(
5032: show => 'Show details',
5033: hide => 'Hide details',
5034: );
5035: &html_escape(\%html_js_lt);
5036: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5037: return <<"ENDSCRIPT";
5038: <script type="text/javascript">
5039: // <![CDATA[
5040:
5041: function reorderHelpRoles(form,item) {
5042: var changedVal;
5043: $jstext
5044: var newpos = 'helproles_${total}_pos';
5045: var maxh = 1 + $total;
5046: var current = new Array();
5047: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5048: if (item == newpos) {
5049: changedVal = newitemVal;
5050: } else {
5051: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5052: current[newitemVal] = newpos;
5053: }
5054: for (var i=0; i<helproles.length; i++) {
5055: var elementName = 'helproles_'+helproles[i]+'_pos';
5056: if (elementName != item) {
5057: if (form.elements[elementName]) {
5058: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5059: current[currVal] = elementName;
5060: }
5061: }
5062: }
5063: var oldVal;
5064: for (var j=0; j<maxh; j++) {
5065: if (current[j] == undefined) {
5066: oldVal = j;
5067: }
5068: }
5069: if (oldVal < changedVal) {
5070: for (var k=oldVal+1; k<=changedVal ; k++) {
5071: var elementName = current[k];
5072: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5073: }
5074: } else {
5075: for (var k=changedVal; k<oldVal; k++) {
5076: var elementName = current[k];
5077: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5078: }
5079: }
5080: return;
5081: }
5082:
5083: function helpdeskAccess(num) {
5084: var curraccess = null;
5085: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5086: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5087: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5088: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5089: }
5090: }
5091: }
5092: var shown = Array();
5093: var hidden = Array();
5094: if (curraccess == 'none') {
5095: hidden = Array('$hiddenstr');
5096: } else {
5097: if (curraccess == 'status') {
5098: shown = Array('bystatus');
5099: hidden = Array('notinc','notexc');
5100: } else {
5101: if (curraccess == 'exc') {
5102: shown = Array('notexc');
5103: hidden = Array('notinc','bystatus');
5104: }
5105: if (curraccess == 'inc') {
5106: shown = Array('notinc');
5107: hidden = Array('notexc','bystatus');
5108: }
1.293 raeburn 5109: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5110: hidden = Array('notinc','notexc','bystatus');
5111: }
5112: }
5113: }
5114: if (hidden.length > 0) {
5115: for (var i=0; i<hidden.length; i++) {
5116: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5117: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5118: }
5119: }
5120: }
5121: if (shown.length > 0) {
5122: for (var i=0; i<shown.length; i++) {
5123: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5124: if (shown[i] == 'privs') {
5125: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5126: } else {
5127: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5128: }
5129: }
5130: }
5131: }
5132: return;
5133: }
5134:
5135: function toggleHelpdeskItem(num,field) {
5136: if (document.getElementById('helproles_'+num+'_'+field)) {
5137: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5138: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5139: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5140: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5141: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5142: }
5143: } else {
5144: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5145: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5146: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5147: }
5148: }
5149: }
5150: return;
5151: }
5152:
5153: // ]]>
5154: </script>
5155:
5156: ENDSCRIPT
5157: }
5158:
5159: sub helpdeskroles_access {
5160: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5161: $usertypes,$types,$domhelpdesk) = @_;
5162: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5163: my %lt = &Apache::lonlocal::texthash(
5164: 'rou' => 'Role usage',
5165: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5166: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5167: 'dh' => 'All with domain helpdesk role',
5168: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5169: 'none' => 'None',
5170: 'status' => 'Determined based on institutional status',
5171: 'inc' => 'Include all, but exclude specific personnel',
5172: 'exc' => 'Exclude all, but include specific personnel',
5173: );
5174: my %usecheck = (
5175: all => ' checked="checked"',
5176: );
5177: my %displaydiv = (
5178: status => 'none',
5179: inc => 'none',
5180: exc => 'none',
5181: priv => 'block',
5182: );
5183: my $output;
5184: if (ref($current) eq 'HASH') {
5185: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5186: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5187: $usecheck{$current->{access}} = $usecheck{'all'};
5188: delete($usecheck{'all'});
5189: if ($current->{access} =~ /^(status|inc|exc)$/) {
5190: my $access = $1;
5191: $displaydiv{$access} = 'inline';
5192: } elsif ($current->{access} eq 'none') {
5193: $displaydiv{'priv'} = 'none';
5194: }
5195: }
5196: }
5197: }
5198: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5199: '<p>'.$lt{'whi'}.'</p>';
5200: foreach my $access (@{$accesstypes}) {
5201: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5202: ' onclick="helpdeskAccess('."'$num'".');" />'.
5203: $lt{$access}.'</label>';
5204: if ($access eq 'status') {
5205: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5206: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5207: $othertitle,$usertypes,$types).
5208: '</div>';
5209: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5210: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5211: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5212: '</div>';
5213: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5214: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5215: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5216: '</div>';
5217: }
5218: $output .= '</p>';
5219: }
5220: $output .= '</fieldset>';
5221: return $output;
5222: }
5223:
1.121 raeburn 5224: sub radiobutton_prefs {
1.192 raeburn 5225: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5226: $additional,$align,$firstval) = @_;
1.121 raeburn 5227: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5228: (ref($choices) eq 'HASH'));
5229:
1.170 raeburn 5230: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5231:
5232: foreach my $item (@{$toggles}) {
5233: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5234: $checkedon{$item} = ' checked="checked" ';
5235: $checkedoff{$item} = ' ';
1.121 raeburn 5236: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5237: $checkedoff{$item} = ' checked="checked" ';
5238: $checkedon{$item} = ' ';
5239: }
5240: }
5241: if (ref($settings) eq 'HASH') {
1.121 raeburn 5242: foreach my $item (@{$toggles}) {
1.118 jms 5243: if ($settings->{$item} eq '1') {
5244: $checkedon{$item} = ' checked="checked" ';
5245: $checkedoff{$item} = ' ';
5246: } elsif ($settings->{$item} eq '0') {
5247: $checkedoff{$item} = ' checked="checked" ';
5248: $checkedon{$item} = ' ';
5249: }
5250: }
1.121 raeburn 5251: }
1.192 raeburn 5252: if ($onclick) {
5253: $onclick = ' onclick="'.$onclick.'"';
5254: }
1.121 raeburn 5255: foreach my $item (@{$toggles}) {
1.118 jms 5256: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5257: $datatable .=
1.306 raeburn 5258: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5259: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5260: '</span></td>';
5261: if ($align eq 'left') {
5262: $datatable .= '<td class="LC_left_item">';
5263: } else {
5264: $datatable .= '<td class="LC_right_item">';
5265: }
1.385 raeburn 5266: $datatable .= '<span class="LC_nobreak">';
5267: if ($firstval eq 'no') {
5268: $datatable .=
5269: '<label><input type="radio" name="'.
5270: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5271: '</label> <label><input type="radio" name="'.$item.'" '.
5272: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5273: } else {
5274: $datatable .=
5275: '<label><input type="radio" name="'.
5276: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5277: '</label> <label><input type="radio" name="'.$item.'" '.
5278: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5279: }
5280: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5281: $itemcount ++;
1.121 raeburn 5282: }
5283: return ($datatable,$itemcount);
5284: }
5285:
1.267 raeburn 5286: sub print_ltitools {
1.421 ! raeburn 5287: my ($position,$dom,$settings,$rowtotal) = @_;
! 5288: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5289: if (ref($settings) eq 'HASH') {
1.421 ! raeburn 5290: if ($position eq 'top') {
! 5291: if (exists($settings->{'encrypt'})) {
! 5292: if (ref($settings->{'encrypt'}) eq 'HASH') {
! 5293: foreach my $key (keys(%{$settings->{'encrypt'}})) {
! 5294: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5295: }
5296: }
1.267 raeburn 5297: }
1.421 ! raeburn 5298: if (exists($settings->{'private'})) {
! 5299: if (ref($settings->{'private'}) eq 'HASH') {
! 5300: if (ref($settings->{'private'}) eq 'HASH') {
! 5301: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
! 5302: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5303: }
5304: }
5305: }
5306: }
1.421 ! raeburn 5307: } elsif ($position eq 'middle') {
! 5308: if (exists($settings->{'rules'})) {
! 5309: if (ref($settings->{'rules'}) eq 'HASH') {
! 5310: %rules = %{$settings->{'rules'}};
1.273 raeburn 5311: }
5312: }
1.421 ! raeburn 5313: } else {
! 5314: foreach my $key ('encrypt','private','rules') {
! 5315: if (exists($settings->{$key})) {
! 5316: delete($settings->{$key});
1.267 raeburn 5317: }
5318: }
5319: }
5320: }
1.421 ! raeburn 5321: my $datatable;
! 5322: my $itemcount = 1;
! 5323: if ($position eq 'top') {
! 5324: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
! 5325: } elsif ($position eq 'middle') {
! 5326: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
! 5327: $$rowtotal += $itemcount;
! 5328: } else {
! 5329: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5330: }
5331: return $datatable;
5332: }
5333:
5334: sub ltitools_names {
5335: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5336: 'title' => 'Title',
5337: 'version' => 'Version',
5338: 'msgtype' => 'Message Type',
1.323 raeburn 5339: 'sigmethod' => 'Signature Method',
1.296 raeburn 5340: 'url' => 'URL',
5341: 'key' => 'Key',
1.322 raeburn 5342: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5343: 'secret' => 'Secret',
5344: 'icon' => 'Icon',
1.324 raeburn 5345: 'user' => 'User',
1.296 raeburn 5346: 'fullname' => 'Full Name',
5347: 'firstname' => 'First Name',
5348: 'lastname' => 'Last Name',
5349: 'email' => 'E-mail',
5350: 'roles' => 'Role',
1.298 raeburn 5351: 'window' => 'Window',
5352: 'tab' => 'Tab',
1.296 raeburn 5353: 'iframe' => 'iFrame',
5354: 'height' => 'Height',
5355: 'width' => 'Width',
5356: 'linktext' => 'Default Link Text',
5357: 'explanation' => 'Default Explanation',
5358: 'passback' => 'Tool can return grades:',
5359: 'roster' => 'Tool can retrieve roster:',
5360: 'crstarget' => 'Display target',
5361: 'crslabel' => 'Course label',
5362: 'crstitle' => 'Course title',
5363: 'crslinktext' => 'Link Text',
5364: 'crsexplanation' => 'Explanation',
1.318 raeburn 5365: 'crsappend' => 'Provider URL',
1.267 raeburn 5366: );
5367: return %lt;
5368: }
5369:
1.421 ! raeburn 5370: sub secrets_form {
! 5371: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
! 5372: my @ids=&Apache::lonnet::current_machine_ids();
! 5373: my %servers = &Apache::lonnet::get_servers($dom,'library');
! 5374: my $primary = &Apache::lonnet::domain($dom,'primary');
! 5375: my ($css_class,$extra,$numshown,$itemcount,$output);
! 5376: $itemcount = 0;
! 5377: foreach my $hostid (sort(keys(%servers))) {
! 5378: my ($showextra,$divsty,$switch);
! 5379: if ($hostid eq $primary) {
! 5380: if ($context eq 'ltisec') {
! 5381: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
! 5382: $showextra = 1;
! 5383: }
! 5384: if ($encrypt->{'ltisec_crslinkprot'}) {
! 5385: $showextra = 1;
! 5386: }
! 5387: } else {
! 5388: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
! 5389: $showextra = 1;
! 5390: }
! 5391: }
! 5392: unless (grep(/^\Q$hostid\E$/,@ids)) {
! 5393: $switch = 1;
! 5394: }
! 5395: if ($showextra) {
! 5396: $numshown ++;
! 5397: $divsty = 'display:inline-block';
! 5398: } else {
! 5399: $divsty = 'display:none';
! 5400: }
! 5401: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
! 5402: '<legend>'.$hostid.'</legend>';
! 5403: if ($switch) {
! 5404: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
! 5405: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
! 5406: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
! 5407: if (exists($privkeys->{$hostid})) {
! 5408: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
! 5409: '<span class="LC_nobreak">'.
! 5410: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
! 5411: '<span class="LC_nobreak">'.&mt('Change?').
! 5412: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
! 5413: (' 'x2).
! 5414: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
! 5415: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
! 5416: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
! 5417: '</span></div>';
! 5418: } else {
! 5419: $extra .= '<span class="LC_nobreak">'.
! 5420: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
! 5421: '</span>'."\n";
! 5422: }
! 5423: } elsif (exists($privkeys->{$hostid})) {
! 5424: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
! 5425: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
! 5426: '<span class="LC_nobreak">'.&mt('Change?').
! 5427: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
! 5428: (' 'x2).
! 5429: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
! 5430: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
! 5431: '<span class="LC_nobreak">'.&mt('New Key').':'.
! 5432: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
! 5433: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
! 5434: '</span></div>';
! 5435: } else {
! 5436: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
! 5437: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
! 5438: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
! 5439: }
! 5440: $extra .= '</fieldset>';
! 5441: }
! 5442: }
! 5443: my (%choices,@toggles,%defaultchecked);
! 5444: if ($context eq 'ltisec') {
! 5445: %choices = &Apache::lonlocal::texthash (
! 5446: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
! 5447: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
! 5448: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
! 5449: );
! 5450: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
! 5451: %defaultchecked = (
! 5452: 'ltisec_crslinkprot' => 'off',
! 5453: 'ltisec_domlinkprot' => 'off',
! 5454: 'ltisec_consumers' => 'off',
! 5455: );
! 5456: } else {
! 5457: %choices = &Apache::lonlocal::texthash (
! 5458: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
! 5459: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
! 5460: );
! 5461: @toggles = qw(toolsec_crs toolsec_dom);
! 5462: %defaultchecked = (
! 5463: 'toolsec_crs' => 'off',
! 5464: 'toolsec_dom' => 'off',
! 5465: );
! 5466: }
! 5467: my ($onclick,$itemcount);
! 5468: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
! 5469: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
! 5470: \%choices,$itemcount,$onclick,'','left','no');
! 5471:
! 5472: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 5473: my $noprivkeysty = 'display:inline-block';
! 5474: if ($numshown) {
! 5475: $noprivkeysty = 'display:none';
! 5476: }
! 5477: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
! 5478: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
! 5479: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
! 5480: $extra.
! 5481: '</td></tr>';
! 5482: $itemcount ++;
! 5483: $$rowtotal += $itemcount;
! 5484: return $output;
! 5485: }
! 5486:
1.372 raeburn 5487: sub print_proctoring {
5488: my ($dom,$settings,$rowtotal) = @_;
5489: my $itemcount = 1;
5490: my (%ordered,%providernames,%current,%currentdef);
5491: my $confname = $dom.'-domainconfig';
5492: my $switchserver = &check_switchserver($dom,$confname);
5493: if (ref($settings) eq 'HASH') {
5494: foreach my $item (keys(%{$settings})) {
5495: if (ref($settings->{$item}) eq 'HASH') {
5496: my $num = $settings->{$item}{'order'};
5497: $ordered{$num} = $item;
5498: }
5499: }
5500: } else {
5501: %ordered = (
5502: 1 => 'proctorio',
5503: 2 => 'examity',
5504: );
5505: }
5506: %providernames = &proctoring_providernames();
5507: my $maxnum = scalar(keys(%ordered));
5508: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5509: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5510: if (ref($requref) eq 'HASH') {
5511: %requserfields = %{$requref};
5512: }
5513: if (ref($opturef) eq 'HASH') {
5514: %optuserfields = %{$opturef};
5515: }
5516: if (ref($defref) eq 'HASH') {
5517: %defaults = %{$defref};
5518: }
5519: if (ref($extref) eq 'HASH') {
5520: %extended = %{$extref};
5521: }
5522: if (ref($crsref) eq 'HASH') {
5523: %crsconf = %{$crsref};
5524: }
5525: if (ref($rolesref) eq 'ARRAY') {
5526: @courseroles = @{$rolesref};
5527: }
5528: if (ref($ltiref) eq 'ARRAY') {
5529: @ltiroles = @{$ltiref};
5530: }
5531: my $datatable;
5532: my $css_class;
5533: if (keys(%ordered)) {
5534: my @items = sort { $a <=> $b } keys(%ordered);
5535: for (my $i=0; $i<@items; $i++) {
5536: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5537: my $provider = $ordered{$items[$i]};
5538: my $optionsty = 'none';
5539: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5540: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5541: if (ref($settings) eq 'HASH') {
5542: if (ref($settings->{$provider}) eq 'HASH') {
5543: %current = %{$settings->{$provider}};
5544: if ($current{'available'}) {
5545: $optionsty = 'block';
5546: $available = 1;
5547: }
5548: if ($current{'lifetime'} =~ /^\d+$/) {
5549: $lifetime = $current{'lifetime'};
5550: }
5551: if ($current{'version'} =~ /^\d+\.\d+$/) {
5552: $version = $current{'version'};
5553: }
5554: if ($current{'image'} ne '') {
5555: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5556: }
5557: if (ref($current{'fields'}) eq 'ARRAY') {
5558: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5559: }
5560: $userincdom = $current{'incdom'};
5561: if (ref($current{'roles'}) eq 'HASH') {
5562: %rolemaps = %{$current{'roles'}};
5563: $checkedfields{'roles'} = 1;
5564: }
5565: if (ref($current{'defaults'}) eq 'ARRAY') {
5566: foreach my $val (@{$current{'defaults'}}) {
5567: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5568: $inuse{$val} = 1;
5569: } else {
5570: foreach my $poss (keys(%{$extended{$provider}})) {
5571: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5572: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5573: $inuse{$poss} = $val;
5574: last;
5575: }
5576: }
5577: }
5578: }
5579: }
5580: } elsif (ref($current{'defaults'}) eq 'HASH') {
5581: foreach my $key (keys(%{$current{'defaults'}})) {
5582: my $currval = $current{'defaults'}{$key};
5583: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5584: $inuse{$key} = 1;
5585: } else {
5586: my $match;
5587: foreach my $poss (keys(%{$extended{$provider}})) {
5588: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5589: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5590: $inuse{$poss} = $key;
5591: last;
5592: }
5593: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5594: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5595: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5596: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5597: $currentdef{$inner} = $currval;
5598: $match = 1;
5599: last;
5600: }
5601: } elsif ($inner eq $key) {
5602: $currentdef{$key} = $currval;
5603: $match = 1;
5604: last;
5605: }
5606: }
5607: }
5608: last if ($match);
5609: }
5610: }
5611: }
5612: }
5613: if (ref($current{'crsconf'}) eq 'ARRAY') {
5614: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5615: }
5616: }
5617: }
5618: my %lt = &proctoring_titles($provider);
5619: my %fieldtitles = &proctoring_fieldtitles($provider);
5620: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5621: my %checkedavailable = (
5622: yes => '',
5623: no => ' checked="checked"',
5624: );
5625: if ($available) {
5626: $checkedavailable{'yes'} = $checkedavailable{'no'};
5627: $checkedavailable{'no'} = '';
5628: }
5629: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5630: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5631: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5632: for (my $k=0; $k<$maxnum; $k++) {
5633: my $vpos = $k+1;
5634: my $selstr;
5635: if ($k == $i) {
5636: $selstr = ' selected="selected" ';
5637: }
5638: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5639: }
5640: if ($version eq '') {
5641: if ($provider eq 'proctorio') {
5642: $version = '1.0';
5643: } elsif ($provider eq 'examity') {
5644: $version = '1.1';
5645: }
5646: }
5647: if ($lifetime eq '') {
5648: $lifetime = '300';
5649: }
5650: $datatable .=
5651: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5652: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5653: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5654: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5655: '</td>'.
5656: '<td colspan="2">'.
5657: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5658: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5659: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5660: (' 'x2).
5661: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5662: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5663: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5664: (' 'x2).
5665: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5666: '<br />'.
5667: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5668: '<br />'.
5669: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5670: (' 'x2).
5671: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5672: '<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";
5673: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5674: if ($imgsrc) {
5675: $datatable .= $imgsrc.
5676: '<label><input type="checkbox" name="proctoring_image_del"'.
5677: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5678: '<span class="LC_nobreak"> '.&mt('Replace:');
5679: }
5680: $datatable .= ' ';
5681: if ($switchserver) {
5682: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5683: } else {
5684: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5685: }
5686: unless ($imgsrc) {
5687: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5688: }
5689: $datatable .= '</fieldset>'."\n";
5690: if (ref($requserfields{$provider}) eq 'ARRAY') {
5691: if (@{$requserfields{$provider}} > 0) {
5692: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5693: foreach my $field (@{$requserfields{$provider}}) {
5694: $datatable .= '<span class="LC_nobreak">'.
5695: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5696: $lt{$field}.'</label>';
5697: if ($field eq 'user') {
5698: my $seluserdom = '';
5699: my $unseluserdom = ' selected="selected"';
5700: if ($userincdom) {
5701: $seluserdom = $unseluserdom;
5702: $unseluserdom = '';
5703: }
5704: $datatable .= ': '.
5705: '<select name="proctoring_userincdom_'.$provider.'">'.
5706: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5707: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5708: '</select> ';
5709: } else {
5710: $datatable .= ' ';
5711: if ($field eq 'roles') {
5712: $showroles = 1;
5713: }
5714: }
5715: $datatable .= '</span> ';
5716: }
5717: }
5718: $datatable .= '</fieldset>'."\n";
5719: }
5720: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5721: if (@{$optuserfields{$provider}} > 0) {
5722: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5723: foreach my $field (@{$optuserfields{$provider}}) {
5724: my $checked;
5725: if ($checkedfields{$field}) {
5726: $checked = ' checked="checked"';
5727: }
5728: $datatable .= '<span class="LC_nobreak">'.
5729: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5730: }
5731: $datatable .= '</fieldset>'."\n";
5732: }
5733: }
5734: if (ref($defaults{$provider}) eq 'ARRAY') {
5735: if (@{$defaults{$provider}}) {
5736: my (%options,@selectboxes);
5737: if (ref($extended{$provider}) eq 'HASH') {
5738: %options = %{$extended{$provider}};
5739: }
5740: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5741: my ($rem,$numinrow,$dropdowns);
5742: if ($provider eq 'proctorio') {
5743: $datatable .= '<table>';
5744: $numinrow = 4;
5745: }
5746: my $i = 0;
5747: foreach my $field (@{$defaults{$provider}}) {
5748: my $checked;
5749: if ($inuse{$field}) {
5750: $checked = ' checked="checked"';
5751: }
5752: if ($provider eq 'examity') {
5753: if ($field eq 'display') {
5754: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5755: foreach my $option ('iframe','tab','window') {
5756: my $checkdisp;
5757: if ($currentdef{'target'} eq $option) {
5758: $checkdisp = ' checked="checked"';
5759: }
5760: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5761: $fieldtitles{$option}.'</label>'.(' 'x2);
5762: }
5763: $datatable .= (' 'x4);
5764: foreach my $dimen ('width','height') {
5765: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5766: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5767: 'value="'.$currentdef{$dimen}.'" /></label>'.
5768: (' 'x2);
5769: }
5770: $datatable .= '</span><br />'.
5771: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5772: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5773: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5774: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5775: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5776: $currentdef{'explanation'}.
5777: '</textarea></div><div style=""></div><br />';
5778: }
5779: } else {
5780: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5781: my ($output,$selnone);
5782: unless ($checked) {
5783: $selnone = ' selected="selected"';
5784: }
5785: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5786: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5787: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5788: foreach my $option (@{$options{$field}}) {
5789: my $sel;
5790: if ($inuse{$field} eq $option) {
5791: $sel = ' selected="selected"';
5792: }
5793: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5794: }
5795: $output .= '</select></span>';
5796: push(@selectboxes,$output);
5797: } else {
5798: $rem = $i%($numinrow);
5799: if ($rem == 0) {
5800: if ($i > 0) {
5801: $datatable .= '</tr>';
5802: }
5803: $datatable .= '<tr>';
5804: }
5805: $datatable .= '<td class="LC_left_item">'.
5806: '<span class="LC_nobreak">'.
5807: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5808: $fieldtitles{$field}.'</label></span></td>';
5809: $i++;
5810: }
5811: }
5812: }
5813: if ($provider eq 'proctorio') {
5814: if ($numinrow) {
5815: $rem = $i%$numinrow;
5816: }
5817: my $colsleft = $numinrow - $rem;
5818: if ($colsleft > 1) {
5819: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5820: } else {
5821: $datatable .= '<td class="LC_left_item">';
5822: }
5823: $datatable .= ' '.
5824: '</td></tr></table>';
5825: if (@selectboxes) {
5826: $datatable .= '<hr /><table>';
5827: $numinrow = 2;
5828: for (my $i=0; $i<@selectboxes; $i++) {
5829: $rem = $i%($numinrow);
5830: if ($rem == 0) {
5831: if ($i > 0) {
5832: $datatable .= '</tr>';
5833: }
5834: $datatable .= '<tr>';
5835: }
5836: $datatable .= '<td class="LC_left_item">'.
5837: $selectboxes[$i].'</td>';
5838: }
5839: if ($numinrow) {
5840: $rem = $i%$numinrow;
5841: }
5842: $colsleft = $numinrow - $rem;
5843: if ($colsleft > 1) {
5844: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5845: } else {
5846: $datatable .= '<td class="LC_left_item">';
5847: }
5848: $datatable .= ' '.
5849: '</td></tr></table>';
5850: }
5851: }
5852: $datatable .= '</fieldset>';
5853: }
5854: if (ref($crsconf{$provider}) eq 'ARRAY') {
5855: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5856: '<legend>'.&mt('Configurable in course').'</legend>';
5857: my ($rem,$numinrow);
5858: if ($provider eq 'proctorio') {
5859: $datatable .= '<table>';
5860: $numinrow = 4;
5861: }
5862: my $i = 0;
5863: foreach my $item (@{$crsconf{$provider}}) {
5864: my $name;
5865: if ($provider eq 'examity') {
5866: $name = $lt{'crs'.$item};
5867: } elsif ($provider eq 'proctorio') {
5868: $name = $fieldtitles{$item};
5869: $rem = $i%($numinrow);
5870: if ($rem == 0) {
5871: if ($i > 0) {
5872: $datatable .= '</tr>';
5873: }
5874: $datatable .= '<tr>';
5875: }
5876: $datatable .= '<td class="LC_left_item>';
5877: }
5878: my $checked;
5879: if ($crsconfig{$item}) {
5880: $checked = ' checked="checked"';
5881: }
5882: $datatable .= '<span class="LC_nobreak"><label>'.
5883: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5884: $name.'</label></span>';
5885: if ($provider eq 'examity') {
5886: $datatable .= ' ';
5887: }
5888: $datatable .= "\n";
5889: $i++;
5890: }
5891: if ($provider eq 'proctorio') {
5892: if ($numinrow) {
5893: $rem = $i%$numinrow;
5894: }
5895: my $colsleft = $numinrow - $rem;
5896: if ($colsleft > 1) {
5897: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5898: } else {
5899: $datatable .= '<td class="LC_left_item">';
5900: }
5901: $datatable .= ' '.
5902: '</td></tr></table>';
5903: }
5904: $datatable .= '</fieldset>';
5905: }
5906: if ($showroles) {
5907: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5908: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5909: foreach my $role (@courseroles) {
5910: my ($selected,$selectnone);
5911: if (!$rolemaps{$role}) {
5912: $selectnone = ' selected="selected"';
5913: }
5914: $datatable .= '<td style="text-align: center">'.
5915: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5916: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5917: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5918: foreach my $ltirole (@ltiroles) {
5919: unless ($selectnone) {
5920: if ($rolemaps{$role} eq $ltirole) {
5921: $selected = ' selected="selected"';
5922: } else {
5923: $selected = '';
5924: }
5925: }
5926: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5927: }
5928: $datatable .= '</select></td>';
5929: }
5930: $datatable .= '</tr></table></fieldset>'.
5931: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5932: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5933: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5934: '<tr><td></td><td>lms</td>'.
5935: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5936: ' value="Loncapa" disabled="disabled"/></td></tr>';
5937: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5938: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5939: my %custom = %{$settings->{$provider}->{'custom'}};
5940: if (keys(%custom) > 0) {
5941: foreach my $key (sort(keys(%custom))) {
5942: next if ($key eq 'lms');
5943: $datatable .= '<tr><td><span class="LC_nobreak">'.
5944: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5945: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5946: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5947: ' value="'.$custom{$key}.'" /></td></tr>';
5948: }
5949: }
5950: }
5951: $datatable .= '<tr><td><span class="LC_nobreak">'.
5952: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5953: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5954: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5955: '</table></fieldset></td></tr>'."\n";
5956: }
5957: $datatable .= '</td></tr>';
5958: }
5959: $itemcount ++;
5960: }
5961: }
5962: return $datatable;
5963: }
5964:
5965: sub proctoring_data {
5966: my $requserfields = {
5967: proctorio => ['user'],
5968: examity => ['roles','user'],
5969: };
5970: my $optuserfields = {
5971: proctorio => ['fullname'],
5972: examity => ['fullname','firstname','lastname','email'],
5973: };
5974: my $defaults = {
5975: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5976: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5977: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5978: 'closetabs','onescreen','print','downloads','cache','rightclick',
5979: 'reentry','calculator','whiteboard'],
5980: examity => ['display'],
5981: };
5982: my $extended = {
5983: proctorio => {
5984: verifyid => ['verifyidauto','verifyidlive'],
5985: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5986: tabslinks => ['notabs','linksonly'],
5987: reentry => ['noreentry','agentreentry'],
5988: calculator => ['calculatorbasic','calculatorsci'],
5989: },
5990: examity => {
5991: display => {
5992: target => ['iframe','tab','window'],
5993: width => '',
5994: height => '',
5995: linktext => '',
5996: explanation => '',
5997: },
5998: },
5999: };
6000: my $crsconf = {
6001: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6002: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6003: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6004: 'closetabs','onescreen','print','downloads','cache','rightclick',
6005: 'reentry','calculator','whiteboard'],
6006: examity => ['label','title','target','linktext','explanation','append'],
6007: };
6008: my $courseroles = ['cc','in','ta','ep','st'];
6009: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6010: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6011: }
6012:
6013: sub proctoring_titles {
6014: my ($item) = @_;
6015: my (%common_lt,%custom_lt);
6016: %common_lt = &Apache::lonlocal::texthash (
6017: 'avai' => 'Available?',
6018: 'base' => 'Basic Settings',
6019: 'requ' => 'User data required to be sent on launch',
6020: 'optu' => 'User data optionally sent on launch',
6021: 'udsl' => 'User data sent on launch',
6022: 'defa' => 'Defaults for items configurable in course',
6023: 'sigmethod' => 'Signature Method',
6024: 'key' => 'Key',
6025: 'lifetime' => 'Nonce lifetime (s)',
6026: 'secret' => 'Secret',
6027: 'icon' => 'Icon',
6028: 'fullname' => 'Full Name',
6029: 'visible' => 'Visible input',
6030: 'username' => 'username',
6031: 'user' => 'User',
6032: );
6033: if ($item eq 'proctorio') {
6034: %custom_lt = &Apache::lonlocal::texthash (
6035: 'version' => 'OAuth version',
6036: 'url' => 'API URL',
6037: 'uname:dom' => 'username-domain',
6038: );
6039: } elsif ($item eq 'examity') {
6040: %custom_lt = &Apache::lonlocal::texthash (
6041: 'version' => 'LTI Version',
6042: 'url' => 'URL',
6043: 'uname:dom' => 'username:domain',
6044: 'msgtype' => 'Message Type',
6045: 'firstname' => 'First Name',
6046: 'lastname' => 'Last Name',
6047: 'email' => 'E-mail',
6048: 'roles' => 'Role',
6049: 'crstarget' => 'Display target',
6050: 'crslabel' => 'Course label',
6051: 'crstitle' => 'Course title',
6052: 'crslinktext' => 'Link Text',
6053: 'crsexplanation' => 'Explanation',
6054: 'crsappend' => 'Provider URL',
6055: );
6056: }
6057: my %lt = (%common_lt,%custom_lt);
6058: return %lt;
6059: }
6060:
6061: sub proctoring_fieldtitles {
6062: my ($item) = @_;
6063: if ($item eq 'proctorio') {
6064: return &Apache::lonlocal::texthash (
6065: 'recordvideo' => 'Record video',
6066: 'recordaudio' => 'Record audio',
6067: 'recordscreen' => 'Record screen',
6068: 'recordwebtraffic' => 'Record web traffic',
6069: 'recordroomstart' => 'Record room scan',
6070: 'verifyvideo' => 'Verify webcam',
6071: 'verifyaudio' => 'Verify microphone',
6072: 'verifydesktop' => 'Verify desktop recording',
6073: 'verifyid' => 'Photo ID verification',
6074: 'verifysignature' => 'Require signature',
6075: 'fullscreen' => 'Fullscreen',
6076: 'clipboard' => 'Disable copy/paste',
6077: 'tabslinks' => 'New tabs/windows',
6078: 'closetabs' => 'Close other tabs',
6079: 'onescreen' => 'Limit to single screen',
6080: 'print' => 'Disable Printing',
6081: 'downloads' => 'Disable Downloads',
6082: 'cache' => 'Empty cache after exam',
6083: 'rightclick' => 'Disable right click',
6084: 'reentry' => 'Re-entry to exam',
6085: 'calculator' => 'Onscreen calculator',
6086: 'whiteboard' => 'Onscreen whiteboard',
6087: 'verifyidauto' => 'Automated verification',
6088: 'verifyidlive' => 'Live agent verification',
6089: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6090: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6091: 'fullscreensever' => 'Forced, navigation away ends exam',
6092: 'notabs' => 'Disaallowed',
6093: 'linksonly' => 'Allowed from links in exam',
6094: 'noreentry' => 'Disallowed',
6095: 'agentreentry' => 'Agent required for re-entry',
6096: 'calculatorbasic' => 'Basic',
6097: 'calculatorsci' => 'Scientific',
6098: );
6099: } elsif ($item eq 'examity') {
6100: return &Apache::lonlocal::texthash (
6101: 'target' => 'Display target',
6102: 'window' => 'Window',
6103: 'tab' => 'Tab',
6104: 'iframe' => 'iFrame',
6105: 'height' => 'Height (pixels)',
6106: 'width' => 'Width (pixels)',
6107: 'linktext' => 'Default Link Text',
6108: 'explanation' => 'Default Explanation',
6109: 'append' => 'Provider URL',
6110: );
6111: }
6112: }
6113:
6114: sub proctoring_providernames {
6115: return (
6116: proctorio => 'Proctorio',
6117: examity => 'Examity',
6118: );
6119: }
6120:
1.320 raeburn 6121: sub print_lti {
1.405 raeburn 6122: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6123: my $itemcount = 1;
1.405 raeburn 6124: my ($datatable,$css_class);
6125: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6126: if (ref($settings) eq 'HASH') {
1.405 raeburn 6127: if ($position eq 'top') {
6128: if (exists($settings->{'encrypt'})) {
6129: if (ref($settings->{'encrypt'}) eq 'HASH') {
6130: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6131: if ($key eq 'consumers') {
6132: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6133: } else {
6134: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6135: }
6136: }
6137: }
6138: }
6139: if (exists($settings->{'private'})) {
6140: if (ref($settings->{'private'}) eq 'HASH') {
6141: if (ref($settings->{'private'}) eq 'HASH') {
6142: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6143: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6144: }
6145: }
6146: }
6147: }
6148: } elsif ($position eq 'middle') {
6149: if (exists($settings->{'rules'})) {
6150: if (ref($settings->{'rules'}) eq 'HASH') {
6151: %rules = %{$settings->{'rules'}};
6152: }
6153: }
6154: } elsif ($position eq 'lower') {
6155: if (exists($settings->{'linkprot'})) {
6156: if (ref($settings->{'linkprot'}) eq 'HASH') {
6157: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6158: if ($linkprot{'lock'}) {
6159: delete($linkprot{'lock'});
6160: }
1.405 raeburn 6161: }
6162: }
6163: } else {
6164: foreach my $key ('encrypt','private','rules','linkprot') {
6165: if (exists($settings->{$key})) {
6166: delete($settings->{$key});
1.390 raeburn 6167: }
1.320 raeburn 6168: }
6169: }
6170: }
1.405 raeburn 6171: if ($position eq 'top') {
1.421 ! raeburn 6172: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
! 6173: } elsif ($position eq 'middle') {
! 6174: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
! 6175: $$rowtotal += $itemcount;
! 6176: } elsif ($position eq 'lower') {
! 6177: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
! 6178: } else {
! 6179: my $maxnum = 0;
! 6180: my %ordered;
! 6181: if (ref($settings) eq 'HASH') {
! 6182: foreach my $item (keys(%{$settings})) {
! 6183: if (ref($settings->{$item}) eq 'HASH') {
! 6184: my $num = $settings->{$item}{'order'};
! 6185: if ($num eq '') {
! 6186: $num = scalar(keys(%{$settings}));
! 6187: }
! 6188: $ordered{$num} = $item;
1.405 raeburn 6189: }
1.352 raeburn 6190: }
1.405 raeburn 6191: }
6192: $maxnum = scalar(keys(%ordered));
6193: my %lt = <i_names();
6194: if (keys(%ordered)) {
6195: my @items = sort { $a <=> $b } keys(%ordered);
6196: for (my $i=0; $i<@items; $i++) {
6197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6198: my $item = $ordered{$items[$i]};
6199: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
6200: if (ref($settings->{$item}) eq 'HASH') {
6201: $key = $settings->{$item}->{'key'};
6202: $secret = $settings->{$item}->{'secret'};
6203: $lifetime = $settings->{$item}->{'lifetime'};
6204: $consumer = $settings->{$item}->{'consumer'};
6205: $requser = $settings->{$item}->{'requser'};
6206: $crsinc = $settings->{$item}->{'crsinc'};
6207: $current = $settings->{$item};
6208: }
6209: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6210: my %checkedrequser = (
6211: yes => ' checked="checked"',
6212: no => '',
6213: );
6214: if (!$requser) {
6215: $checkedrequser{'no'} = $checkedrequser{'yes'};
6216: $checkedrequser{'yes'} = '';
6217: }
6218: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6219: my %checkedcrsinc = (
1.391 raeburn 6220: yes => ' checked="checked"',
6221: no => '',
1.405 raeburn 6222: );
6223: if (!$crsinc) {
6224: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6225: $checkedcrsinc{'yes'} = '';
6226: }
6227: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6228: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6229: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6230: for (my $k=0; $k<=$maxnum; $k++) {
6231: my $vpos = $k+1;
6232: my $selstr;
6233: if ($k == $i) {
6234: $selstr = ' selected="selected" ';
6235: }
6236: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6237: }
1.405 raeburn 6238: $datatable .= '</select>'.(' 'x2).
6239: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6240: &mt('Delete?').'</label></span></td>'.
6241: '<td colspan="2">'.
6242: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6243: '<span class="LC_nobreak">'.$lt{'consumer'}.
6244: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6245: (' 'x2).
6246: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6247: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6248: (' 'x2).
6249: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
6250: 'value="'.$lifetime.'" size="3" /></span>'.
6251: (' 'x2).
6252: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6253: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6254: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6255: '<br /><br />'.
6256: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6257: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6258: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6259: (' 'x4).
6260: '<span class="LC_nobreak">'.$lt{'key'}.
6261: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6262: (' 'x2).
6263: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6264: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6265: '<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>'.
6266: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6267: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6268: $itemcount ++;
1.320 raeburn 6269: }
6270: }
1.405 raeburn 6271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6272: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6273: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6274: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6275: '<select name="lti_pos_add"'.$chgstr.'>';
6276: for (my $k=0; $k<$maxnum+1; $k++) {
6277: my $vpos = $k+1;
6278: my $selstr;
6279: if ($k == $maxnum) {
6280: $selstr = ' selected="selected" ';
6281: }
6282: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6283: }
1.405 raeburn 6284: $datatable .= '</select> '."\n".
6285: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6286: '<td colspan="2">'.
6287: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6288: '<span class="LC_nobreak">'.$lt{'consumer'}.
6289: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6290: (' 'x2).
6291: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6292: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6293: (' 'x2).
6294: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6295: (' 'x2).
6296: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6297: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6298: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6299: '<br /><br />'.
6300: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6301: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6302: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6303: (' 'x4).
6304: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6305: (' 'x2).
6306: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6307: '<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".
6308: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6309: '</td>'."\n".
6310: '</tr>'."\n";
6311: $itemcount ++;
1.320 raeburn 6312: }
1.405 raeburn 6313: $$rowtotal += $itemcount;
6314: return $datatable;
1.320 raeburn 6315: }
6316:
6317: sub lti_names {
6318: my %lt = &Apache::lonlocal::texthash(
6319: 'version' => 'LTI Version',
6320: 'url' => 'URL',
6321: 'key' => 'Key',
1.322 raeburn 6322: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6323: 'consumer' => 'Consumer',
1.320 raeburn 6324: 'secret' => 'Secret',
1.345 raeburn 6325: 'requser' => "User's identity sent",
1.391 raeburn 6326: 'crsinc' => "Course's identity sent",
1.320 raeburn 6327: 'email' => 'Email address',
6328: 'sourcedid' => 'User ID',
6329: 'other' => 'Other',
6330: 'passback' => 'Can return grades to Consumer:',
6331: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6332: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6333: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6334: );
6335: return %lt;
6336: }
6337:
6338: sub lti_options {
1.325 raeburn 6339: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6340: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6341: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6342: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6343: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6344: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6345: $checked{'mapcrstype'} = {};
6346: $checked{'makeuser'} = {};
6347: $checked{'selfenroll'} = {};
6348: $checked{'crssec'} = {};
6349: $checked{'crssecsrc'} = {};
1.325 raeburn 6350: $checked{'lcauth'} = {};
1.326 raeburn 6351: $checked{'menuitem'} = {};
1.325 raeburn 6352: if ($num eq 'add') {
6353: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6354: }
1.320 raeburn 6355: my $userfieldsty = 'none';
6356: my $crsfieldsty = 'none';
6357: my $crssecfieldsty = 'none';
6358: my $secsrcfieldsty = 'none';
1.363 raeburn 6359: my $callbacksty = 'none';
1.337 raeburn 6360: my $passbacksty = 'none';
1.345 raeburn 6361: my $optionsty = 'block';
1.391 raeburn 6362: my $crssty = 'block';
1.325 raeburn 6363: my $lcauthparm;
6364: my $lcauthparmstyle = 'display:none';
6365: my $lcauthparmtext;
1.326 raeburn 6366: my $menusty;
1.325 raeburn 6367: my $numinrow = 4;
1.326 raeburn 6368: my %menutitles = <imenu_titles();
1.320 raeburn 6369:
6370: if (ref($current) eq 'HASH') {
1.345 raeburn 6371: if (!$current->{'requser'}) {
6372: $optionsty = 'none';
1.391 raeburn 6373: $crssty = 'none';
6374: } elsif (!$current->{'crsinc'}) {
6375: $crssty = 'none';
1.345 raeburn 6376: }
1.320 raeburn 6377: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6378: $checked{'mapuser'}{'sourcedid'} = '';
6379: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6380: $checked{'mapuser'}{'email'} = ' checked="checked"';
6381: } else {
6382: $checked{'mapuser'}{'other'} = ' checked="checked"';
6383: $userfield = $current->{'mapuser'};
6384: $userfieldsty = 'inline-block';
6385: }
6386: }
6387: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6388: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6389: if ($current->{'mapcrs'} eq 'context_id') {
6390: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6391: } else {
6392: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6393: $cidfield = $current->{'mapcrs'};
6394: $crsfieldsty = 'inline-block';
6395: }
6396: }
6397: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6398: foreach my $type (@{$current->{'mapcrstype'}}) {
6399: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6400: }
6401: }
1.392 raeburn 6402: if (!$current->{'storecrs'}) {
6403: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6404: $checked{'storecrs'}{'Y'} = '';
6405: }
1.345 raeburn 6406: if ($current->{'makecrs'}) {
1.320 raeburn 6407: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6408: }
1.320 raeburn 6409: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6410: foreach my $role (@{$current->{'makeuser'}}) {
6411: $checked{'makeuser'}{$role} = ' checked="checked"';
6412: }
6413: }
1.325 raeburn 6414: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6415: $checked{'lcauth'}{$1} = ' checked="checked"';
6416: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6417: $lcauthparm = $current->{'lcauthparm'};
6418: $lcauthparmstyle = 'display:table-row';
6419: if ($current->{'lcauth'} eq 'localauth') {
6420: $lcauthparmtext = &mt('Local auth argument');
6421: } else {
6422: $lcauthparmtext = &mt('Kerberos domain');
6423: }
6424: }
6425: }
1.320 raeburn 6426: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6427: foreach my $role (@{$current->{'selfenroll'}}) {
6428: $checked{'selfenroll'}{$role} = ' checked="checked"';
6429: }
6430: }
6431: if (ref($current->{'maproles'}) eq 'HASH') {
6432: %rolemaps = %{$current->{'maproles'}};
6433: }
6434: if ($current->{'section'} ne '') {
6435: $checked{'crssec'}{'Y'} = ' checked="checked"';
6436: $crssecfieldsty = 'inline-block';
6437: if ($current->{'section'} eq 'course_section_sourcedid') {
6438: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6439: } else {
6440: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6441: $crssecsrc = $current->{'section'};
6442: $secsrcfieldsty = 'inline-block';
6443: }
6444: } else {
6445: $checked{'crssec'}{'N'} = ' checked="checked"';
6446: }
1.363 raeburn 6447: if ($current->{'callback'} ne '') {
6448: $callback = $current->{'callback'};
6449: $checked{'callback'}{'Y'} = ' checked="checked"';
6450: $callbacksty = 'inline-block';
6451: } else {
6452: $checked{'callback'}{'N'} = ' checked="checked"';
6453: }
1.326 raeburn 6454: if ($current->{'topmenu'}) {
6455: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6456: } else {
6457: $checked{'topmenu'}{'N'} = ' checked="checked"';
6458: }
6459: if ($current->{'inlinemenu'}) {
6460: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6461: } else {
6462: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6463: }
6464: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6465: $menusty = 'inline-block';
6466: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6467: foreach my $item (@{$current->{'lcmenu'}}) {
6468: if (exists($menutitles{$item})) {
6469: $checked{'menuitem'}{$item} = ' checked="checked"';
6470: }
6471: }
6472: }
6473: } else {
6474: $menusty = 'none';
6475: }
1.320 raeburn 6476: } else {
6477: $checked{'makecrs'}{'N'} = ' checked="checked"';
6478: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6479: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6480: $checked{'topmenu'}{'N'} = ' checked="checked"';
6481: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6482: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6483: $menusty = 'inline-block';
1.320 raeburn 6484: }
1.325 raeburn 6485: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6486: my %coursetypetitles = &Apache::lonlocal::texthash (
6487: official => 'Official',
6488: unofficial => 'Unofficial',
6489: community => 'Community',
6490: textbook => 'Textbook',
6491: placement => 'Placement Test',
1.325 raeburn 6492: lti => 'LTI Provider',
1.320 raeburn 6493: );
1.325 raeburn 6494: my @authtypes = ('internal','krb4','krb5','localauth');
6495: my %shortauth = (
6496: internal => 'int',
6497: krb4 => 'krb4',
6498: krb5 => 'krb5',
6499: localauth => 'loc'
6500: );
6501: my %authnames = &authtype_names();
1.320 raeburn 6502: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6503: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6504: my @courseroles = ('cc','in','ta','ep','st');
6505: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6506: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6507: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6508: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6509: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6510: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6511: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6512: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6513: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6514: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6515: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6516: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6517: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6518: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6519: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6520: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6521: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6522: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6523: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6524: foreach my $option ('sourcedid','email','other') {
6525: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6526: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6527: ($option eq 'other' ? '' : (' 'x2) );
6528: }
6529: $output .= '</span></div>'.
6530: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6531: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6532: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6533: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6534: foreach my $ltirole (@ltiroles) {
6535: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6536: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6537: }
6538: $output .= '</fieldset>'.
1.391 raeburn 6539: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6540: '<table>'.
6541: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6542: '</table>'.
6543: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6544: '<td class="LC_left_item">';
6545: foreach my $auth ('lti',@authtypes) {
6546: my $authtext;
6547: if ($auth eq 'lti') {
6548: $authtext = &mt('None');
6549: } else {
6550: $authtext = $authnames{$shortauth{$auth}};
6551: }
6552: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6553: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6554: $authtext.'</label></span> ';
6555: }
6556: $output .= '</td></tr>'.
6557: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6558: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6559: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6560: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6561: '</table></fieldset>'.
1.391 raeburn 6562: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6563: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6564: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6565: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6566: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6567: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6568: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6569: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6570: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6571: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6572: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6573: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6574: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6575: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6576: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6577: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6578: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6579: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6580: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6581: (' 'x2);
6582: }
6583: $output .= '</span></div></fieldset>'.
6584: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6585: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6586: &mt('Unique course identifier').': ';
6587: foreach my $option ('course_offering_sourcedid','context_id','other') {
6588: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6589: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6590: ($option eq 'other' ? '' : (' 'x2) );
6591: }
1.334 raeburn 6592: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6593: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6594: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6595: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6596: foreach my $type (@coursetypes) {
6597: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6598: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6599: (' 'x2);
6600: }
1.392 raeburn 6601: $output .= '</span><br /><br />'.
6602: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6603: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6604: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6605: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6606: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6607: '</fieldset>'.
1.391 raeburn 6608: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6609: foreach my $ltirole (@lticourseroles) {
6610: my ($selected,$selectnone);
6611: if ($rolemaps{$ltirole} eq '') {
6612: $selectnone = ' selected="selected"';
6613: }
6614: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6615: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6616: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6617: foreach my $role (@courseroles) {
6618: unless ($selectnone) {
6619: if ($rolemaps{$ltirole} eq $role) {
6620: $selected = ' selected="selected"';
6621: } else {
6622: $selected = '';
6623: }
6624: }
6625: $output .= '<option value="'.$role.'"'.$selected.'>'.
6626: &Apache::lonnet::plaintext($role,'Course').
6627: '</option>';
6628: }
6629: $output .= '</select></td>';
6630: }
6631: $output .= '</tr></table></fieldset>'.
6632: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6633: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6634: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6635: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6636: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6637: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6638: '</fieldset>'.
1.391 raeburn 6639: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6640: foreach my $lticrsrole (@lticourseroles) {
6641: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6642: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6643: }
6644: $output .= '</fieldset>'.
1.391 raeburn 6645: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6646: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6647: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6648: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6649: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6650: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6651: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6652: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6653: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6654: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6655: &mt('Standard field').'</label>'.(' 'x2).
6656: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6657: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6658: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6659: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6660: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6661: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6662: foreach my $extra ('roster','passback') {
1.320 raeburn 6663: my $checkedon = '';
6664: my $checkedoff = ' checked="checked"';
1.337 raeburn 6665: if ($extra eq 'passback') {
6666: $pb1p1chk = ' checked="checked"';
6667: $pb1p0chk = '';
6668: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6669: } else {
6670: $onclickpb = '';
6671: }
1.320 raeburn 6672: if (ref($current) eq 'HASH') {
6673: if (($current->{$extra})) {
6674: $checkedon = $checkedoff;
6675: $checkedoff = '';
1.337 raeburn 6676: if ($extra eq 'passback') {
6677: $passbacksty = 'inline-block';
6678: }
6679: if ($current->{'passbackformat'} eq '1.0') {
6680: $pb1p0chk = ' checked="checked"';
6681: $pb1p1chk = '';
6682: }
1.320 raeburn 6683: }
6684: }
6685: $output .= $lt{$extra}.' '.
1.337 raeburn 6686: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6687: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6688: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6689: &mt('Yes').'</label><br />';
6690: }
1.337 raeburn 6691: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6692: '<span class="LC_nobreak">'.&mt('Grade format').
6693: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6694: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6695: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6696: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6697: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6698: $output .= '</span></div></fieldset>';
1.320 raeburn 6699: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6700: #
6701: # $output .= '</fieldset>'.
6702: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6703: return $output;
6704: }
6705:
1.326 raeburn 6706: sub ltimenu_titles {
6707: return &Apache::lonlocal::texthash(
6708: fullname => 'Full name',
6709: coursetitle => 'Course title',
6710: role => 'Role',
6711: logout => 'Logout',
6712: grades => 'Grades',
6713: );
6714: }
6715:
1.405 raeburn 6716: sub check_switchserver {
6717: my ($home) = @_;
6718: my $switchserver;
6719: if ($home ne '') {
6720: my $allowed;
6721: my @ids=&Apache::lonnet::current_machine_ids();
6722: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6723: if (!$allowed) {
6724: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
6725: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
6726: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6727: }
6728: }
6729: return $switchserver;
6730: }
6731:
1.121 raeburn 6732: sub print_coursedefaults {
1.139 raeburn 6733: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6734: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6735: my $itemcount = 1;
1.192 raeburn 6736: my %choices = &Apache::lonlocal::texthash (
6737: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6738: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6739: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6740: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6741: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6742: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6743: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6744: texengine => 'Default method to display mathematics',
1.257 raeburn 6745: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6746: canclone => "People who may clone a course (besides course's owner and coordinators)",
6747: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6748: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.192 raeburn 6749: );
1.198 raeburn 6750: my %staticdefaults = (
6751: anonsurvey_threshold => 10,
6752: uploadquota => 500,
1.257 raeburn 6753: postsubmit => 60,
1.276 raeburn 6754: mysqltables => 172800,
1.198 raeburn 6755: );
1.139 raeburn 6756: if ($position eq 'top') {
1.257 raeburn 6757: %defaultchecked = (
6758: 'canuse_pdfforms' => 'off',
6759: 'uselcmath' => 'on',
6760: 'usejsme' => 'on',
1.398 raeburn 6761: 'inline_chem' => 'on',
1.289 raeburn 6762: 'canclone' => 'none',
1.257 raeburn 6763: );
1.398 raeburn 6764: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6765: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6766: if (ref($settings) eq 'HASH') {
6767: if ($settings->{'texengine'}) {
6768: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6769: $deftex = $settings->{'texengine'};
6770: }
6771: }
6772: }
6773: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6774: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6775: '<span class="LC_nobreak">'.$choices{'texengine'}.
6776: '</span></td><td class="LC_right_item">'.
6777: '<select name="texengine">'."\n";
6778: my %texoptions = (
6779: MathJax => 'MathJax',
6780: mimetex => &mt('Convert to Images'),
6781: tth => &mt('TeX to HTML'),
6782: );
6783: foreach my $renderer ('MathJax','mimetex','tth') {
6784: my $selected = '';
6785: if ($renderer eq $deftex) {
6786: $selected = ' selected="selected"';
6787: }
6788: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6789: }
6790: $mathdisp .= '</select></td></tr>'."\n";
6791: $itemcount ++;
1.139 raeburn 6792: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6793: \%choices,$itemcount);
1.314 raeburn 6794: $datatable = $mathdisp.$datatable;
1.264 raeburn 6795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6796: $datatable .=
1.306 raeburn 6797: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6798: '<span class="LC_nobreak">'.$choices{'canclone'}.
6799: '</span></td><td class="LC_left_item">';
6800: my $currcanclone = 'none';
6801: my $onclick;
6802: my @cloneoptions = ('none','domain');
1.380 raeburn 6803: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6804: none => 'No additional course requesters',
6805: domain => "Any course requester in course's domain",
6806: instcode => 'Course requests for official courses ...',
6807: );
6808: my (%codedefaults,@code_order,@posscodes);
6809: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6810: \@code_order) eq 'ok') {
6811: if (@code_order > 0) {
6812: push(@cloneoptions,'instcode');
6813: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6814: }
6815: }
6816: if (ref($settings) eq 'HASH') {
6817: if ($settings->{'canclone'}) {
6818: if (ref($settings->{'canclone'}) eq 'HASH') {
6819: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6820: if (@code_order > 0) {
6821: $currcanclone = 'instcode';
6822: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6823: }
6824: }
6825: } elsif ($settings->{'canclone'} eq 'domain') {
6826: $currcanclone = $settings->{'canclone'};
6827: }
6828: }
1.289 raeburn 6829: }
1.264 raeburn 6830: foreach my $option (@cloneoptions) {
6831: my ($checked,$additional);
6832: if ($currcanclone eq $option) {
6833: $checked = ' checked="checked"';
6834: }
6835: if ($option eq 'instcode') {
6836: if (@code_order) {
6837: my $show = 'none';
6838: if ($checked) {
6839: $show = 'block';
6840: }
1.317 raeburn 6841: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6842: &mt('Institutional codes for new and cloned course have identical:').
6843: '<br />';
6844: foreach my $item (@code_order) {
6845: my $codechk;
6846: if ($checked) {
6847: if (grep(/^\Q$item\E$/,@posscodes)) {
6848: $codechk = ' checked="checked"';
6849: }
6850: }
6851: $additional .= '<label>'.
6852: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6853: $item.'</label>';
6854: }
6855: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6856: }
6857: }
6858: $datatable .=
6859: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6860: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6861: '</label> '.$additional.'</span><br />';
6862: }
6863: $datatable .= '</td>'.
6864: '</tr>';
6865: $itemcount ++;
1.139 raeburn 6866: } else {
6867: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6868: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6869: my $currusecredits = 0;
1.257 raeburn 6870: my $postsubmitclient = 1;
1.405 raeburn 6871: my $ltiauth = 0;
1.271 raeburn 6872: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6873: if (ref($settings) eq 'HASH') {
1.404 raeburn 6874: if ($settings->{'ltiauth'}) {
6875: $ltiauth = 1;
1.405 raeburn 6876: }
1.139 raeburn 6877: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6878: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6879: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6880: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6881: }
6882: }
1.192 raeburn 6883: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6884: foreach my $type (@types) {
6885: next if ($type eq 'community');
6886: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6887: if ($defcredits{$type} ne '') {
6888: $currusecredits = 1;
6889: }
6890: }
6891: }
6892: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6893: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6894: $postsubmitclient = 0;
6895: foreach my $type (@types) {
6896: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6897: }
6898: } else {
6899: foreach my $type (@types) {
6900: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6901: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6902: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6903: } else {
6904: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6905: }
6906: } else {
6907: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6908: }
6909: }
6910: }
6911: } else {
6912: foreach my $type (@types) {
6913: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6914: }
6915: }
1.276 raeburn 6916: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6917: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6918: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6919: }
6920: } else {
6921: foreach my $type (@types) {
6922: $currmysql{$type} = $staticdefaults{'mysqltables'};
6923: }
6924: }
1.258 raeburn 6925: } else {
6926: foreach my $type (@types) {
6927: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6928: }
1.139 raeburn 6929: }
6930: if (!$currdefresponder) {
1.198 raeburn 6931: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6932: } elsif ($currdefresponder < 1) {
6933: $currdefresponder = 1;
6934: }
1.198 raeburn 6935: foreach my $type (@types) {
6936: if ($curruploadquota{$type} eq '') {
6937: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6938: }
6939: }
1.139 raeburn 6940: $datatable .=
1.192 raeburn 6941: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6942: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6943: '</span></td>'.
6944: '<td class="LC_right_item"><span class="LC_nobreak">'.
6945: '<input type="text" name="anonsurvey_threshold"'.
6946: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6947: '</td></tr>'."\n";
6948: $itemcount ++;
6949: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6950: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6951: $choices{'uploadquota'}.
6952: '</span></td>'.
1.306 raeburn 6953: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6954: '<table><tr>';
1.198 raeburn 6955: foreach my $type (@types) {
1.306 raeburn 6956: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6957: '<input type="text" name="uploadquota_'.$type.'"'.
6958: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6959: }
6960: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6961: $itemcount ++;
1.236 raeburn 6962: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6963: my $display = 'none';
1.192 raeburn 6964: if ($currusecredits) {
6965: $display = 'block';
6966: }
6967: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6968: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6969: foreach my $type (@types) {
6970: next if ($type eq 'community');
1.306 raeburn 6971: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6972: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6973: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6974: }
6975: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6976: %defaultchecked = ('coursecredits' => 'off');
6977: @toggles = ('coursecredits');
6978: my $current = {
6979: 'coursecredits' => $currusecredits,
6980: };
6981: (my $table,$itemcount) =
6982: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6983: \%choices,$itemcount,$onclick,$additional,'left');
6984: $datatable .= $table;
6985: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6986: my $display = 'none';
6987: if ($postsubmitclient) {
6988: $display = 'block';
6989: }
6990: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6991: &mt('Number of seconds submit is disabled').'<br />'.
6992: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6993: '<table><tr>';
1.257 raeburn 6994: foreach my $type (@types) {
1.306 raeburn 6995: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6996: '<input type="text" name="'.$type.'_timeout" value="'.
6997: $deftimeout{$type}.'" size="5" /></td>';
6998: }
6999: $additional .= '</tr></table></div>'."\n";
7000: %defaultchecked = ('postsubmit' => 'on');
7001: @toggles = ('postsubmit');
1.280 raeburn 7002: $current = {
7003: 'postsubmit' => $postsubmitclient,
7004: };
1.257 raeburn 7005: ($table,$itemcount) =
7006: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7007: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7008: $datatable .= $table;
1.276 raeburn 7009: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7010: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7011: $choices{'mysqltables'}.
7012: '</span></td>'.
1.306 raeburn 7013: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7014: '<table><tr>';
7015: foreach my $type (@types) {
1.306 raeburn 7016: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7017: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7018: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7019: }
7020: $datatable .= '</tr></table></td></tr>'."\n";
7021: $itemcount ++;
1.404 raeburn 7022: %defaultchecked = ('ltiauth' => 'off');
7023: @toggles = ('ltiauth');
7024: $current = {
7025: 'ltiauth' => $ltiauth,
7026: };
7027: ($table,$itemcount) =
7028: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7029: \%choices,$itemcount,undef,undef,'left');
7030: $datatable .= $table;
7031: $itemcount ++;
1.139 raeburn 7032: }
1.192 raeburn 7033: $$rowtotal += $itemcount;
1.121 raeburn 7034: return $datatable;
1.118 jms 7035: }
7036:
1.231 raeburn 7037: sub print_selfenrollment {
7038: my ($position,$dom,$settings,$rowtotal) = @_;
7039: my ($css_class,$datatable);
7040: my $itemcount = 1;
1.271 raeburn 7041: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7042: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7043: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7044: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7045: my @rows;
7046: my $key;
7047: if ($position eq 'top') {
7048: $key = 'admin';
7049: if (ref($rowsref) eq 'ARRAY') {
7050: @rows = @{$rowsref};
7051: }
7052: } elsif ($position eq 'middle') {
7053: $key = 'default';
7054: @rows = ('types','registered','approval','limit');
7055: }
7056: foreach my $row (@rows) {
7057: if (defined($titlesref->{$row})) {
7058: $itemcount ++;
7059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7060: $datatable .= '<tr'.$css_class.'>'.
7061: '<td>'.$titlesref->{$row}.'</td>'.
7062: '<td class="LC_left_item">'.
7063: '<table><tr>';
7064: my (%current,%currentcap);
7065: if (ref($settings) eq 'HASH') {
7066: if (ref($settings->{$key}) eq 'HASH') {
7067: foreach my $type (@types) {
7068: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7069: $current{$type} = $settings->{$key}->{$type}->{$row};
7070: }
7071: if (($row eq 'limit') && ($key eq 'default')) {
7072: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7073: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7074: }
7075: }
7076: }
7077: }
7078: }
7079: my %roles = (
7080: '0' => &Apache::lonnet::plaintext('dc'),
7081: );
7082:
7083: foreach my $type (@types) {
7084: unless (($row eq 'registered') && ($key eq 'default')) {
7085: $datatable .= '<th>'.&mt($type).'</th>';
7086: }
7087: }
7088: unless (($row eq 'registered') && ($key eq 'default')) {
7089: $datatable .= '</tr><tr>';
7090: }
7091: foreach my $type (@types) {
7092: if ($type eq 'community') {
7093: $roles{'1'} = &mt('Community personnel');
7094: } else {
7095: $roles{'1'} = &mt('Course personnel');
7096: }
7097: $datatable .= '<td style="vertical-align: top">';
7098: if ($position eq 'top') {
7099: my %checked;
7100: if ($current{$type} eq '0') {
7101: $checked{'0'} = ' checked="checked"';
7102: } else {
7103: $checked{'1'} = ' checked="checked"';
7104: }
7105: foreach my $role ('1','0') {
7106: $datatable .= '<span class="LC_nobreak"><label>'.
7107: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7108: 'value="'.$role.'"'.$checked{$role}.' />'.
7109: $roles{$role}.'</label></span> ';
7110: }
7111: } else {
7112: if ($row eq 'types') {
7113: my %checked;
7114: if ($current{$type} =~ /^(all|dom)$/) {
7115: $checked{$1} = ' checked="checked"';
7116: } else {
7117: $checked{''} = ' checked="checked"';
7118: }
7119: foreach my $val ('','dom','all') {
7120: $datatable .= '<span class="LC_nobreak"><label>'.
7121: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7122: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7123: }
7124: } elsif ($row eq 'registered') {
7125: my %checked;
7126: if ($current{$type} eq '1') {
7127: $checked{'1'} = ' checked="checked"';
7128: } else {
7129: $checked{'0'} = ' checked="checked"';
7130: }
7131: foreach my $val ('0','1') {
7132: $datatable .= '<span class="LC_nobreak"><label>'.
7133: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7134: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7135: }
7136: } elsif ($row eq 'approval') {
7137: my %checked;
7138: if ($current{$type} =~ /^([12])$/) {
7139: $checked{$1} = ' checked="checked"';
7140: } else {
7141: $checked{'0'} = ' checked="checked"';
7142: }
7143: for my $val (0..2) {
7144: $datatable .= '<span class="LC_nobreak"><label>'.
7145: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7146: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7147: }
7148: } elsif ($row eq 'limit') {
7149: my %checked;
7150: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7151: $checked{$1} = ' checked="checked"';
7152: } else {
7153: $checked{'none'} = ' checked="checked"';
7154: }
7155: my $cap;
7156: if ($currentcap{$type} =~ /^\d+$/) {
7157: $cap = $currentcap{$type};
7158: }
7159: foreach my $val ('none','allstudents','selfenrolled') {
7160: $datatable .= '<span class="LC_nobreak"><label>'.
7161: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7162: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7163: }
7164: $datatable .= '<br />'.
7165: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7166: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7167: '</span>';
7168: }
7169: }
7170: $datatable .= '</td>';
7171: }
7172: $datatable .= '</tr>';
7173: }
7174: $datatable .= '</table></td></tr>';
7175: }
7176: } elsif ($position eq 'bottom') {
1.235 raeburn 7177: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7178: }
7179: $$rowtotal += $itemcount;
7180: return $datatable;
7181: }
7182:
7183: sub print_validation_rows {
7184: my ($caller,$dom,$settings,$rowtotal) = @_;
7185: my ($itemsref,$namesref,$fieldsref);
7186: if ($caller eq 'selfenroll') {
7187: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7188: } elsif ($caller eq 'requestcourses') {
7189: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7190: }
7191: my %currvalidation;
7192: if (ref($settings) eq 'HASH') {
7193: if (ref($settings->{'validation'}) eq 'HASH') {
7194: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7195: }
1.235 raeburn 7196: }
7197: my $datatable;
7198: my $itemcount = 0;
7199: foreach my $item (@{$itemsref}) {
7200: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7201: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7202: $namesref->{$item}.
7203: '</span></td>'.
7204: '<td class="LC_left_item">';
7205: if (($item eq 'url') || ($item eq 'button')) {
7206: $datatable .= '<span class="LC_nobreak">'.
7207: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7208: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7209: } elsif ($item eq 'fields') {
7210: my @currfields;
7211: if (ref($currvalidation{$item}) eq 'ARRAY') {
7212: @currfields = @{$currvalidation{$item}};
7213: }
7214: foreach my $field (@{$fieldsref}) {
7215: my $check = '';
7216: if (grep(/^\Q$field\E$/,@currfields)) {
7217: $check = ' checked="checked"';
7218: }
7219: $datatable .= '<span class="LC_nobreak"><label>'.
7220: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7221: ' value="'.$field.'"'.$check.' />'.$field.
7222: '</label></span> ';
7223: }
7224: } elsif ($item eq 'markup') {
1.334 raeburn 7225: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7226: $currvalidation{$item}.
1.231 raeburn 7227: '</textarea>';
1.235 raeburn 7228: }
7229: $datatable .= '</td></tr>'."\n";
7230: if (ref($rowtotal)) {
1.231 raeburn 7231: $itemcount ++;
7232: }
7233: }
1.235 raeburn 7234: if ($caller eq 'requestcourses') {
7235: my %currhash;
1.248 raeburn 7236: if (ref($settings) eq 'HASH') {
7237: if (ref($settings->{'validation'}) eq 'HASH') {
7238: if ($settings->{'validation'}{'dc'} ne '') {
7239: $currhash{$settings->{'validation'}{'dc'}} = 1;
7240: }
1.235 raeburn 7241: }
7242: }
7243: my $numinrow = 2;
7244: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7245: 'validationdc',%currhash);
1.247 raeburn 7246: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7247: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7248: if ($numdc > 1) {
1.247 raeburn 7249: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7250: } else {
1.247 raeburn 7251: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7252: }
1.247 raeburn 7253: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7254: $itemcount ++;
7255: }
7256: if (ref($rowtotal)) {
7257: $$rowtotal += $itemcount;
7258: }
1.231 raeburn 7259: return $datatable;
7260: }
7261:
1.357 raeburn 7262: sub print_privacy {
7263: my ($position,$dom,$settings,$rowtotal) = @_;
7264: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7265: my $itemcount = 0;
1.417 raeburn 7266: if ($position eq 'top') {
7267: $numinrow = 2;
7268: } else {
1.357 raeburn 7269: @items = ('domain','author','course','community');
7270: %names = &Apache::lonlocal::texthash (
7271: domain => 'Assigned domain role(s)',
7272: author => 'Assigned co-author role(s)',
7273: course => 'Assigned course role(s)',
1.416 raeburn 7274: community => 'Assigned community role(s)',
1.357 raeburn 7275: );
7276: $numinrow = 4;
7277: ($othertitle,$usertypes,$types) =
7278: &Apache::loncommon::sorted_inst_types($dom);
7279: }
7280: if (($position eq 'top') || ($position eq 'middle')) {
7281: my (%by_ip,%by_location,@intdoms,@instdoms);
7282: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7283: if ($position eq 'top') {
7284: my %curr;
7285: my @options = ('none','user','domain','auto');
7286: my %titles = &Apache::lonlocal::texthash (
7287: none => 'Not allowed',
7288: user => 'User authorizes',
7289: domain => 'DC authorizes',
7290: auto => 'Unrestricted',
7291: instdom => 'Other domain shares institution/provider',
7292: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7293: notify => 'Notify when role needs authorization',
1.357 raeburn 7294: );
7295: my %names = &Apache::lonlocal::texthash (
7296: domain => 'Domain role',
7297: author => 'Co-author role',
7298: course => 'Course role',
7299: community => 'Community role',
7300: );
7301: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7302: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7303: foreach my $domtype ('instdom','extdom') {
7304: my (%checked,$skip);
7305: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7306: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7307: '<td class="LC_left_item">';
7308: if ($domtype eq 'instdom') {
7309: unless (@instdoms > 1) {
7310: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7311: $skip = 1;
7312: }
7313: } elsif ($domtype eq 'extdom') {
7314: if (keys(%by_location) == 0) {
7315: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7316: $skip = 1;
7317: }
7318: }
7319: unless ($skip) {
7320: foreach my $roletype ('domain','author','course','community') {
7321: $checked{'auto'} = ' checked="checked"';
7322: if (ref($settings) eq 'HASH') {
7323: if (ref($settings->{approval}) eq 'HASH') {
7324: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7325: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7326: $checked{$1} = ' checked="checked"';
7327: $checked{'auto'} = '';
7328: }
7329: }
7330: }
7331: }
7332: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7333: foreach my $option (@options) {
7334: $datatable .= '<span class="LC_nobreak"><label>'.
7335: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7336: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7337: '</label></span> ';
7338: }
7339: $datatable .= '</fieldset>';
7340: }
7341: }
7342: $datatable .= '</td></tr>';
7343: $itemcount ++;
7344: }
1.417 raeburn 7345: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7346: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7347: '<td class="LC_left_item">';
7348: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7349: my %curr;
7350: if (ref($settings) eq 'HASH') {
7351: if ($settings->{'notify'} ne '') {
7352: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7353: }
7354: }
7355: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7356: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7357: 'privacy_notify',%curr);
7358: if ($numdc > 0) {
7359: $datatable .= $table;
7360: } else {
7361: $datatable .= &mt('There are no active Domain Coordinators');
7362: }
7363: } else {
7364: $datatable .= &mt('Nothing to set here, as there are no other domains');
7365: }
7366: $datatable .='</td></tr>';
1.357 raeburn 7367: } elsif ($position eq 'middle') {
7368: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7369: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7370: foreach my $item (@{$types}) {
7371: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7372: $numinrow,$itemcount,'','','','','',
7373: '',$usertypes->{$item});
7374: $itemcount ++;
7375: }
7376: }
7377: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7378: $numinrow,$itemcount,'','','','','',
7379: '',$othertitle);
7380: $itemcount ++;
7381: } else {
1.360 raeburn 7382: my (@insttypes,%insttitles);
7383: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7384: @insttypes = @{$types};
7385: %insttitles = %{$usertypes};
7386: }
7387: foreach my $item (@insttypes,'default') {
7388: my $title;
7389: if ($item eq 'default') {
7390: $title = $othertitle;
7391: } else {
7392: $title = $insttitles{$item};
7393: }
7394: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7395: $datatable .= '<tr'.$css_class.'>'.
7396: '<td class="LC_left_item">'.$title.'</td>'.
7397: '<td class="LC_left_item">'.
7398: &mt('Nothing to set here, as there are no other domains').
7399: '</td></tr>';
7400: $itemcount ++;
7401: }
1.357 raeburn 7402: }
7403: }
7404: } else {
7405: my $prefix;
7406: if ($position eq 'lower') {
7407: $prefix = 'priv';
7408: } else {
7409: $prefix = 'unpriv';
7410: }
7411: foreach my $item (@items) {
7412: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7413: $numinrow,$itemcount,'','','','','',
7414: '',$names{$item});
7415: $itemcount ++;
7416: }
7417: }
7418: if (ref($rowtotal)) {
7419: $$rowtotal += $itemcount;
7420: }
7421: return $datatable;
7422: }
7423:
1.354 raeburn 7424: sub print_passwords {
7425: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7426: my ($datatable,$css_class);
7427: my $itemcount = 0;
7428: my %titles = &Apache::lonlocal::texthash (
7429: captcha => '"Forgot Password" CAPTCHA validation',
7430: link => 'Reset link expiration (hours)',
7431: case => 'Case-sensitive usernames/e-mail',
7432: prelink => 'Information required (form 1)',
7433: postlink => 'Information required (form 2)',
7434: emailsrc => 'LON-CAPA e-mail address type(s)',
7435: customtext => 'Domain specific text (HTML)',
7436: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7437: intauth_check => 'Check bcrypt cost if authenticated',
7438: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7439: permanent => 'Permanent e-mail address',
7440: critical => 'Critical notification address',
7441: notify => 'Notification address',
7442: min => 'Minimum password length',
7443: max => 'Maximum password length',
7444: chars => 'Required characters',
7445: expire => 'Password expiration (days)',
1.356 raeburn 7446: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7447: );
7448: if ($position eq 'top') {
7449: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7450: my $shownlinklife = 2;
7451: my $prelink = 'both';
7452: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7453: if (ref($settings) eq 'HASH') {
7454: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7455: $shownlinklife = $settings->{resetlink};
7456: }
7457: if (ref($settings->{resetcase}) eq 'ARRAY') {
7458: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7459: }
7460: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7461: $prelink = $settings->{resetprelink};
7462: }
7463: if (ref($settings->{resetpostlink}) eq 'HASH') {
7464: %postlink = %{$settings->{resetpostlink}};
7465: }
7466: if (ref($settings->{resetemail}) eq 'ARRAY') {
7467: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7468: }
7469: if ($settings->{resetremove}) {
7470: $nostdtext = 1;
7471: }
7472: if ($settings->{resetcustom}) {
7473: $customurl = $settings->{resetcustom};
7474: }
7475: } else {
7476: if (ref($types) eq 'ARRAY') {
7477: foreach my $item (@{$types}) {
7478: $casesens{$item} = 1;
7479: $postlink{$item} = ['username','email'];
7480: }
7481: }
7482: $casesens{'default'} = 1;
7483: $postlink{'default'} = ['username','email'];
7484: $prelink = 'both';
7485: %emailsrc = (
7486: permanent => 1,
7487: critical => 1,
7488: notify => 1,
7489: );
7490: }
7491: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7492: $itemcount ++;
7493: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7494: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7495: '<td class="LC_left_item">'.
7496: '<input type="textbox" value="'.$shownlinklife.'" '.
7497: 'name="passwords_link" size="3" /></td></tr>';
7498: $itemcount ++;
7499: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7500: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7501: '<td class="LC_left_item">';
7502: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7503: foreach my $item (@{$types}) {
7504: my $checkedcase;
7505: if ($casesens{$item}) {
7506: $checkedcase = ' checked="checked"';
7507: }
7508: $datatable .= '<span class="LC_nobreak"><label>'.
7509: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7510: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7511: '</span> ';
1.354 raeburn 7512: }
7513: }
7514: my $checkedcase;
7515: if ($casesens{'default'}) {
7516: $checkedcase = ' checked="checked"';
7517: }
7518: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7519: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7520: $othertitle.'</label></span></td>';
7521: $itemcount ++;
7522: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7523: my %checkedpre = (
7524: both => ' checked="checked"',
7525: either => '',
7526: );
7527: if ($prelink eq 'either') {
7528: $checkedpre{either} = ' checked="checked"';
7529: $checkedpre{both} = '';
7530: }
7531: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7532: '<td class="LC_left_item"><span class="LC_nobreak">'.
7533: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7534: &mt('Both username and e-mail address').'</label></span> '.
7535: '<span class="LC_nobreak"><label>'.
7536: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7537: &mt('Either username or e-mail address').'</label></span></td></tr>';
7538: $itemcount ++;
7539: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7540: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7541: '<td class="LC_left_item">';
7542: my %postlinked;
7543: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7544: foreach my $item (@{$types}) {
7545: undef(%postlinked);
7546: $datatable .= '<fieldset style="display: inline-block;">'.
7547: '<legend>'.$usertypes->{$item}.'</legend>';
7548: if (ref($postlink{$item}) eq 'ARRAY') {
7549: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7550: }
7551: foreach my $field ('email','username') {
7552: my $checked;
7553: if ($postlinked{$field}) {
7554: $checked = ' checked="checked"';
7555: }
7556: $datatable .= '<span class="LC_nobreak"><label>'.
7557: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7558: $field.'"'.$checked.' />'.$field.'</label>'.
7559: '<span> ';
7560: }
7561: $datatable .= '</fieldset>';
7562: }
7563: }
7564: if (ref($postlink{'default'}) eq 'ARRAY') {
7565: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7566: }
7567: $datatable .= '<fieldset style="display: inline-block;">'.
7568: '<legend>'.$othertitle.'</legend>';
7569: foreach my $field ('email','username') {
7570: my $checked;
7571: if ($postlinked{$field}) {
7572: $checked = ' checked="checked"';
7573: }
7574: $datatable .= '<span class="LC_nobreak"><label>'.
7575: '<input type="checkbox" name="passwords_postlink_default" value="'.
7576: $field.'"'.$checked.' />'.$field.'</label>'.
7577: '<span> ';
7578: }
7579: $datatable .= '</fieldset></td></tr>';
7580: $itemcount ++;
7581: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7582: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7583: '<td class="LC_left_item">';
7584: foreach my $type ('permanent','critical','notify') {
7585: my $checkedemail;
7586: if ($emailsrc{$type}) {
7587: $checkedemail = ' checked="checked"';
7588: }
7589: $datatable .= '<span class="LC_nobreak"><label>'.
7590: '<input type="checkbox" name="passwords_emailsrc" value="'.
7591: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7592: '<span> ';
7593: }
7594: $datatable .= '</td></tr>';
7595: $itemcount ++;
7596: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7597: my $switchserver = &check_switchserver($dom,$confname);
7598: my ($showstd,$noshowstd);
7599: if ($nostdtext) {
7600: $noshowstd = ' checked="checked"';
7601: } else {
7602: $showstd = ' checked="checked"';
7603: }
7604: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7605: '<td class="LC_left_item"><span class="LC_nobreak">'.
7606: &mt('Retain standard text:').
7607: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7608: &mt('Yes').'</label>'.' '.
7609: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7610: &mt('No').'</label></span><br />'.
7611: '<span class="LC_fontsize_small">'.
7612: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7613: &mt('Include custom text:');
7614: if ($customurl) {
1.369 raeburn 7615: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7616: undef,undef,undef,undef,'background-color:#ffffff');
7617: $datatable .= '<span class="LC_nobreak"> '.$link.
7618: '<label><input type="checkbox" name="passwords_custom_del"'.
7619: ' value="1" />'.&mt('Delete?').'</label></span>'.
7620: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7621: }
7622: if ($switchserver) {
7623: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7624: } else {
7625: $datatable .='<span class="LC_nobreak"> '.
7626: '<input type="file" name="passwords_customfile" /></span>';
7627: }
7628: $datatable .= '</td></tr>';
7629: } elsif ($position eq 'middle') {
7630: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7631: my @items = ('intauth_cost','intauth_check','intauth_switch');
7632: my %defaults;
7633: if (ref($domconf{'defaults'}) eq 'HASH') {
7634: %defaults = %{$domconf{'defaults'}};
7635: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7636: $defaults{'intauth_cost'} = 10;
7637: }
7638: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7639: $defaults{'intauth_check'} = 0;
7640: }
7641: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7642: $defaults{'intauth_switch'} = 0;
7643: }
7644: } else {
7645: %defaults = (
7646: 'intauth_cost' => 10,
7647: 'intauth_check' => 0,
7648: 'intauth_switch' => 0,
7649: );
7650: }
7651: foreach my $item (@items) {
7652: if ($itemcount%2) {
7653: $css_class = '';
7654: } else {
7655: $css_class = ' class="LC_odd_row" ';
7656: }
7657: $datatable .= '<tr'.$css_class.'>'.
7658: '<td><span class="LC_nobreak">'.$titles{$item}.
7659: '</span></td><td class="LC_left_item" colspan="3">';
7660: if ($item eq 'intauth_switch') {
7661: my @options = (0,1,2);
7662: my %optiondesc = &Apache::lonlocal::texthash (
7663: 0 => 'No',
7664: 1 => 'Yes',
7665: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7666: );
7667: $datatable .= '<table width="100%">';
7668: foreach my $option (@options) {
7669: my $checked = ' ';
7670: if ($defaults{$item} eq $option) {
7671: $checked = ' checked="checked"';
7672: }
7673: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7674: '<label><input type="radio" name="'.$item.
7675: '" value="'.$option.'"'.$checked.' />'.
7676: $optiondesc{$option}.'</label></span></td></tr>';
7677: }
7678: $datatable .= '</table>';
7679: } elsif ($item eq 'intauth_check') {
7680: my @options = (0,1,2);
7681: my %optiondesc = &Apache::lonlocal::texthash (
7682: 0 => 'No',
7683: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7684: 2 => 'Yes, disallow login if stored cost is less than domain default',
7685: );
7686: $datatable .= '<table width="100%">';
7687: foreach my $option (@options) {
7688: my $checked = ' ';
7689: my $onclick;
7690: if ($defaults{$item} eq $option) {
7691: $checked = ' checked="checked"';
7692: }
7693: if ($option == 2) {
7694: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7695: }
7696: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7697: '<label><input type="radio" name="'.$item.
7698: '" value="'.$option.'"'.$checked.$onclick.' />'.
7699: $optiondesc{$option}.'</label></span></td></tr>';
7700: }
7701: $datatable .= '</table>';
7702: } else {
7703: $datatable .= '<input type="text" name="'.$item.'" value="'.
7704: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7705: }
7706: $datatable .= '</td></tr>';
7707: $itemcount ++;
7708: }
7709: } elsif ($position eq 'lower') {
1.405 raeburn 7710: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 7711: } else {
1.359 raeburn 7712: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7713: my %ownerchg = (
7714: by => {},
7715: for => {},
7716: );
7717: my %ownertitles = &Apache::lonlocal::texthash (
7718: by => 'Course owner status(es) allowed',
7719: for => 'Student status(es) allowed',
7720: );
1.354 raeburn 7721: if (ref($settings) eq 'HASH') {
1.359 raeburn 7722: if (ref($settings->{crsownerchg}) eq 'HASH') {
7723: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7724: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7725: }
7726: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7727: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7728: }
1.354 raeburn 7729: }
7730: }
7731: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7732: $datatable .= '<tr '.$css_class.'>'.
7733: '<td>'.
7734: &mt('Requirements').'<ul>'.
1.359 raeburn 7735: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7736: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7737: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7738: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7739: '</ul>'.
7740: '</td>'.
1.359 raeburn 7741: '<td class="LC_left_item">';
7742: foreach my $item ('by','for') {
7743: $datatable .= '<fieldset style="display: inline-block;">'.
7744: '<legend>'.$ownertitles{$item}.'</legend>';
7745: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7746: foreach my $type (@{$types}) {
7747: my $checked;
7748: if ($ownerchg{$item}{$type}) {
7749: $checked = ' checked="checked"';
7750: }
7751: $datatable .= '<span class="LC_nobreak"><label>'.
7752: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7753: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7754: '</span> ';
1.359 raeburn 7755: }
7756: }
7757: my $checked;
7758: if ($ownerchg{$item}{'default'}) {
7759: $checked = ' checked="checked"';
7760: }
7761: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7762: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7763: $othertitle.'</label></span></fieldset>';
7764: }
7765: $datatable .= '</td></tr>';
1.354 raeburn 7766: }
7767: return $datatable;
7768: }
7769:
1.405 raeburn 7770: sub password_rules {
7771: my ($prefix,$itemcountref,$settings) = @_;
7772: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
7773: my %titles;
7774: if ($prefix eq 'passwords') {
7775: %titles = &Apache::lonlocal::texthash (
7776: min => 'Minimum password length',
7777: max => 'Maximum password length',
7778: chars => 'Required characters',
7779: );
1.421 ! raeburn 7780: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 7781: %titles = &Apache::lonlocal::texthash (
7782: min => 'Minimum secret length',
7783: max => 'Maximum secret length',
7784: chars => 'Required characters',
7785: );
7786: }
7787: $min = $Apache::lonnet::passwdmin;
7788: my $datatable;
7789: my $itemcount;
7790: if (ref($itemcountref)) {
7791: $itemcount = $$itemcountref;
7792: }
7793: if (ref($settings) eq 'HASH') {
7794: if ($settings->{min}) {
7795: $min = $settings->{min};
7796: }
7797: if ($settings->{max}) {
7798: $max = $settings->{max};
7799: }
7800: if (ref($settings->{chars}) eq 'ARRAY') {
7801: map { $chars{$_} = 1; } (@{$settings->{chars}});
7802: }
7803: if ($prefix eq 'passwords') {
7804: if ($settings->{expire}) {
7805: $expire = $settings->{expire};
7806: }
7807: if ($settings->{numsaved}) {
7808: $numsaved = $settings->{numsaved};
7809: }
7810: }
7811: }
7812: my %rulenames = &Apache::lonlocal::texthash(
7813: uc => 'At least one upper case letter',
7814: lc => 'At least one lower case letter',
7815: num => 'At least one number',
7816: spec => 'At least one non-alphanumeric',
7817: );
7818: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7819: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7820: '<td class="LC_left_item"><span class="LC_nobreak">'.
7821: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7822: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7823: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7824: '</span></td></tr>';
7825: $itemcount ++;
7826: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7827: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7828: '<td class="LC_left_item"><span class="LC_nobreak">'.
7829: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7830: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7831: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7832: '</span></td></tr>';
7833: $itemcount ++;
7834: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7835: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7836: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7837: '</span></td>';
7838: my $numinrow = 2;
7839: my @possrules = ('uc','lc','num','spec');
7840: $datatable .= '<td class="LC_left_item"><table>';
7841: for (my $i=0; $i<@possrules; $i++) {
7842: my ($rem,$checked);
7843: if ($chars{$possrules[$i]}) {
7844: $checked = ' checked="checked"';
7845: }
7846: $rem = $i%($numinrow);
7847: if ($rem == 0) {
7848: if ($i > 0) {
7849: $datatable .= '</tr>';
7850: }
7851: $datatable .= '<tr>';
7852: }
7853: $datatable .= '<td><span class="LC_nobreak"><label>'.
7854: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7855: $rulenames{$possrules[$i]}.'</label></span></td>';
7856: }
7857: my $rem = @possrules%($numinrow);
7858: my $colsleft = $numinrow - $rem;
7859: if ($colsleft > 1 ) {
7860: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7861: ' </td>';
7862: } elsif ($colsleft == 1) {
7863: $datatable .= '<td class="LC_left_item"> </td>';
7864: }
7865: $datatable .='</table></td></tr>';
7866: $itemcount ++;
7867: if ($prefix eq 'passwords') {
7868: $titles{'expire'} = &mt('Password expiration (days)');
7869: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7870: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7871: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7872: '<td class="LC_left_item"><span class="LC_nobreak">'.
7873: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
7874: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7875: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7876: '</span></td></tr>';
7877: $itemcount ++;
7878: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7879: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7880: '<td class="LC_left_item"><span class="LC_nobreak">'.
7881: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7882: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7883: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7884: '</span></td></tr>';
7885: $itemcount ++;
7886: }
7887: if (ref($itemcountref)) {
7888: $$itemcountref += $itemcount;
7889: }
7890: return $datatable;
7891: }
7892:
1.373 raeburn 7893: sub print_wafproxy {
7894: my ($position,$dom,$settings,$rowtotal) = @_;
7895: my $css_class;
7896: my $itemcount = 0;
7897: my $datatable;
7898: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7899: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7900: my %lt = &wafproxy_titles();
1.373 raeburn 7901: foreach my $server (sort(keys(%servers))) {
7902: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7903: next if ($serverhome eq '');
1.373 raeburn 7904: my $serverdom;
7905: if ($serverhome ne $server) {
7906: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7907: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7908: $othercontrol{$server} = $serverdom;
7909: }
1.373 raeburn 7910: } else {
7911: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7912: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7913: if ($serverdom ne $dom) {
7914: $othercontrol{$server} = $serverdom;
7915: } else {
7916: $setdom = 1;
7917: if (ref($settings) eq 'HASH') {
7918: if (ref($settings->{'alias'}) eq 'HASH') {
7919: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7920: if ($aliases{$dom} ne '') {
7921: $showdom = 1;
7922: }
1.373 raeburn 7923: }
1.388 raeburn 7924: if (ref($settings->{'saml'}) eq 'HASH') {
7925: $saml{$dom} = $settings->{'saml'};
7926: }
1.373 raeburn 7927: }
7928: }
7929: }
7930: }
1.381 raeburn 7931: if ($setdom) {
7932: %{$values{$dom}} = ();
7933: if (ref($settings) eq 'HASH') {
7934: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7935: $values{$dom}{$item} = $settings->{$item};
7936: }
7937: }
7938: }
1.373 raeburn 7939: if (keys(%othercontrol)) {
7940: %otherdoms = reverse(%othercontrol);
7941: foreach my $domain (keys(%otherdoms)) {
7942: %{$values{$domain}} = ();
7943: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 7944: if (ref($config{'wafproxy'}) eq 'HASH') {
7945: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 7946: if (exists($config{'wafproxy'}{'saml'})) {
7947: $saml{$domain} = $config{'wafproxy'}{'saml'};
7948: }
1.383 raeburn 7949: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7950: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 7951: }
7952: }
7953: }
7954: }
7955: if ($position eq 'top') {
7956: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7957: my %aliasinfo;
1.373 raeburn 7958: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7959: $itemcount ++;
7960: my $dom_in_effect;
7961: my $aliasrows = '<tr>'.
1.383 raeburn 7962: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7963: &mt('Hostname').': '.
7964: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 7965: if ($othercontrol{$server}) {
1.381 raeburn 7966: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 7967: my ($current,$forsaml);
1.383 raeburn 7968: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7969: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 7970: }
1.388 raeburn 7971: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7972: if ($saml{$dom_in_effect}{$server}) {
7973: $forsaml = 1;
7974: }
7975: }
1.383 raeburn 7976: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7977: &mt('Alias').': ';
1.373 raeburn 7978: if ($current) {
1.381 raeburn 7979: $aliasrows .= $current;
1.388 raeburn 7980: if ($forsaml) {
1.396 raeburn 7981: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 7982: }
1.373 raeburn 7983: } else {
1.383 raeburn 7984: $aliasrows .= &mt('None');
1.373 raeburn 7985: }
1.383 raeburn 7986: $aliasrows .= ' <span class="LC_small">('.
7987: &mt('controlled by domain: [_1]',
7988: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 7989: } else {
1.381 raeburn 7990: $dom_in_effect = $dom;
1.388 raeburn 7991: my ($current,$samlon,$samloff);
7992: $samloff = ' checked="checked"';
1.373 raeburn 7993: if (ref($aliases{$dom}) eq 'HASH') {
7994: if ($aliases{$dom}{$server}) {
7995: $current = $aliases{$dom}{$server};
7996: }
7997: }
1.388 raeburn 7998: if (ref($saml{$dom}) eq 'HASH') {
7999: if ($saml{$dom}{$server}) {
8000: $samlon = $samloff;
8001: undef($samloff);
8002: }
8003: }
1.383 raeburn 8004: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8005: &mt('Alias').': '.
1.381 raeburn 8006: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8007: 'value="'.$current.'" size="30" />'.
8008: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8009: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8010: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
8011: &mt('No').'</label> <label>'.
8012: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8013: &mt('Yes').'</label></span>'.
8014: '</td>';
1.381 raeburn 8015: }
8016: $aliasrows .= '</tr>';
8017: $aliasinfo{$dom_in_effect} .= $aliasrows;
8018: }
8019: if ($aliasinfo{$dom}) {
8020: my ($onclick,$wafon,$wafoff,$showtable);
8021: $onclick = ' onclick="javascript:toggleWAF();"';
8022: $wafoff = ' checked="checked"';
8023: $showtable = ' style="display:none";';
8024: if ($showdom) {
8025: $wafon = $wafoff;
8026: $wafoff = '';
8027: $showtable = ' style="display:inline;"';
8028: }
8029: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8030: $datatable = '<tr'.$css_class.'>'.
8031: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8032: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8033: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8034: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8035: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8036: &mt('No').'</label></span></td>'.
8037: '<td class="LC_left_item">'.
8038: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8039: '</table></td></tr>';
8040: $itemcount++;
8041: }
1.383 raeburn 8042: if (keys(%otherdoms)) {
8043: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8044: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8045: $datatable .= '<tr'.$css_class.'>'.
8046: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8047: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8048: '</table></td></tr>';
1.381 raeburn 8049: $itemcount++;
1.373 raeburn 8050: }
8051: }
8052: } else {
1.383 raeburn 8053: my %ip_methods = &remoteip_methods();
1.373 raeburn 8054: if ($setdom) {
8055: $itemcount ++;
8056: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8057: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8058: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8059: $wafstyle = ' style="display:none;"';
8060: $nowafstyle = ' style="display:table-row;"';
8061: $currwafdisplay = ' style="display: none"';
8062: $wafrangestyle = ' style="display: none"';
8063: $curr_remotip = 'n';
1.382 raeburn 8064: $ssltossl = ' checked="checked"';
1.381 raeburn 8065: if ($showdom) {
8066: $wafstyle = ' style="display:table-row;"';
8067: $nowafstyle = ' style="display:none;"';
8068: if (keys(%{$values{$dom}})) {
8069: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8070: $curr_remotip = $values{$dom}{remoteip};
8071: }
8072: if ($curr_remotip eq 'h') {
8073: $currwafdisplay = ' style="display:table-row"';
8074: $wafrangestyle = ' style="display:inline-block;"';
8075: }
1.382 raeburn 8076: if ($values{$dom}{'sslopt'}) {
8077: $alltossl = ' checked="checked"';
8078: $ssltossl = '';
8079: }
1.381 raeburn 8080: }
8081: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8082: $vpndircheck = ' checked="checked"';
8083: $currwafvpn = ' style="display:table-row;"';
8084: $wafrangestyle = ' style="display:inline-block;"';
8085: } else {
8086: $vpnaliascheck = ' checked="checked"';
8087: $currwafvpn = ' style="display:none;"';
8088: }
8089: }
8090: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8091: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8092: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8093: '</tr>'.
8094: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8095: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8096: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8097: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8098: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8099: '<td class="LC_left_item"><table>'.
8100: '<tr>'.
8101: '<td valign="top">'.$lt{'remoteip'}.': '.
8102: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8103: foreach my $option ('m','h','n') {
8104: my $sel;
8105: if ($option eq $curr_remotip) {
8106: $sel = ' selected="selected"';
8107: }
8108: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8109: $ip_methods{$option}.'</option>';
8110: }
8111: $datatable .= '</select></td></tr>'."\n".
8112: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8113: $lt{'ipheader'}.': '.
8114: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8115: 'name="wafproxy_ipheader" />'.
8116: '</td></tr>'."\n".
8117: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8118: $lt{'trusted'}.':<br />'.
1.381 raeburn 8119: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8120: $values{$dom}{'trusted'}.'</textarea>'.
8121: '</td></tr>'."\n".
8122: '<tr><td><hr /></td></tr>'."\n".
8123: '<tr>'.
8124: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8125: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8126: $lt{'vpndirect'}.'</label>'.(' 'x2).
8127: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8128: $lt{'vpnaliased'}.'</label></span></td></tr>';
8129: foreach my $item ('vpnint','vpnext') {
8130: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8131: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8132: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8133: $values{$dom}{$item}.'</textarea>'.
8134: '</td></tr>'."\n";
1.373 raeburn 8135: }
1.382 raeburn 8136: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8137: '<tr>'.
8138: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8139: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8140: $lt{'alltossl'}.'</label>'.(' 'x2).
8141: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8142: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8143: '</table></td></tr>';
1.373 raeburn 8144: }
8145: if (keys(%otherdoms)) {
8146: foreach my $domain (sort(keys(%otherdoms))) {
8147: $itemcount ++;
8148: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8149: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8150: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8151: '<td class="LC_left_item"><table>';
1.382 raeburn 8152: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8153: my $showval = &mt('None');
1.382 raeburn 8154: if ($item eq 'ssl') {
8155: $showval = $lt{'ssltossl'};
8156: }
1.373 raeburn 8157: if ($values{$domain}{$item}) {
1.381 raeburn 8158: $showval = $values{$domain}{$item};
1.382 raeburn 8159: if ($item eq 'ssl') {
8160: $showval = $lt{'alltossl'};
1.383 raeburn 8161: } elsif ($item eq 'remoteip') {
8162: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8163: }
1.373 raeburn 8164: }
8165: $datatable .= '<tr>'.
8166: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8167: }
1.381 raeburn 8168: $datatable .= '</table></td></tr>';
1.373 raeburn 8169: }
8170: }
8171: }
8172: $$rowtotal += $itemcount;
8173: return $datatable;
8174: }
8175:
8176: sub wafproxy_titles {
8177: return &Apache::lonlocal::texthash(
1.381 raeburn 8178: remoteip => "Method for determining user's IP",
8179: ipheader => 'Request header containing remote IP',
8180: trusted => 'Trusted IP range(s)',
8181: vpnaccess => 'Access from institutional VPN',
8182: vpndirect => 'via regular hostname (no WAF)',
8183: vpnaliased => 'via aliased hostname (WAF)',
8184: vpnint => 'Internal IP Range(s) for VPN sessions',
8185: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8186: sslopt => 'Forwarding http/https',
1.381 raeburn 8187: alltossl => 'WAF forwards both http and https requests to https',
8188: ssltossl => 'WAF forwards http requests to http and https to https',
8189: );
8190: }
8191:
8192: sub remoteip_methods {
8193: return &Apache::lonlocal::texthash(
8194: m => 'Use Apache mod_remoteip',
8195: h => 'Use headers parsed by LON-CAPA',
8196: n => 'Not in use',
1.373 raeburn 8197: );
8198: }
8199:
1.137 raeburn 8200: sub print_usersessions {
8201: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8202: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8203: my (%by_ip,%by_location,@intdoms,@instdoms);
8204: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8205:
8206: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8207: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8209: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8210: if ($position eq 'top') {
1.152 raeburn 8211: if (keys(%serverhomes) > 1) {
1.145 raeburn 8212: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8213: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8214: if (ref($settings) eq 'HASH') {
8215: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8216: $curroffloadnow = $settings->{'offloadnow'};
8217: }
1.371 raeburn 8218: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8219: $curroffloadoth = $settings->{'offloadoth'};
8220: }
1.261 raeburn 8221: }
1.371 raeburn 8222: my $other_insts = scalar(keys(%by_location));
8223: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8224: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8225: } else {
1.140 raeburn 8226: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8227: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8228: '</td></tr>';
1.140 raeburn 8229: }
1.137 raeburn 8230: } else {
1.279 raeburn 8231: my %titles = &usersession_titles();
8232: my ($prefix,@types);
8233: if ($position eq 'bottom') {
8234: $prefix = 'remote';
8235: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8236: } else {
1.279 raeburn 8237: $prefix = 'hosted';
8238: @types = ('excludedomain','includedomain');
8239: }
8240: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8241: }
8242: $$rowtotal += $itemcount;
8243: return $datatable;
8244: }
8245:
8246: sub rules_by_location {
8247: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8248: my ($datatable,$itemcount,$css_class);
8249: if (keys(%{$by_location}) == 0) {
8250: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8251: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8252: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8253: '</td></tr>';
8254: $itemcount = 1;
8255: } else {
8256: $itemcount = 0;
8257: my $numinrow = 5;
8258: my (%current,%checkedon,%checkedoff);
8259: my @locations = sort(keys(%{$by_location}));
8260: foreach my $type (@{$types}) {
8261: $checkedon{$type} = '';
8262: $checkedoff{$type} = ' checked="checked"';
8263: }
8264: if (ref($settings) eq 'HASH') {
8265: if (ref($settings->{$prefix}) eq 'HASH') {
8266: foreach my $key (keys(%{$settings->{$prefix}})) {
8267: $current{$key} = $settings->{$prefix}{$key};
8268: if ($key eq 'version') {
8269: if ($current{$key} ne '') {
1.145 raeburn 8270: $checkedon{$key} = ' checked="checked"';
8271: $checkedoff{$key} = '';
8272: }
1.279 raeburn 8273: } elsif (ref($current{$key}) eq 'ARRAY') {
8274: $checkedon{$key} = ' checked="checked"';
8275: $checkedoff{$key} = '';
1.137 raeburn 8276: }
8277: }
8278: }
1.279 raeburn 8279: }
8280: foreach my $type (@{$types}) {
8281: next if ($type ne 'version' && !@locations);
8282: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8283: $datatable .= '<tr'.$css_class.'>
8284: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8285: <span class="LC_nobreak">
8286: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8287: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8288: if ($type eq 'version') {
8289: my @lcversions = &Apache::lonnet::all_loncaparevs();
8290: my $selector = '<select name="'.$prefix.'_version">';
8291: foreach my $version (@lcversions) {
8292: my $selected = '';
8293: if ($current{'version'} eq $version) {
8294: $selected = ' selected="selected"';
1.145 raeburn 8295: }
1.279 raeburn 8296: $selector .= ' <option value="'.$version.'"'.
8297: $selected.'>'.$version.'</option>';
8298: }
8299: $selector .= '</select> ';
8300: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8301: } else {
8302: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8303: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8304: ' />'.(' 'x2).
8305: '<input type="button" value="'.&mt('uncheck all').'" '.
8306: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8307: "\n".
8308: '</div><div><table>';
8309: my $rem;
8310: for (my $i=0; $i<@locations; $i++) {
8311: my ($showloc,$value,$checkedtype);
8312: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8313: my $ip = $by_location->{$locations[$i]}->[0];
8314: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8315: $value = join(':',@{$by_ip->{$ip}});
8316: $showloc = join(', ',@{$by_ip->{$ip}});
8317: if (ref($current{$type}) eq 'ARRAY') {
8318: foreach my $loc (@{$by_ip->{$ip}}) {
8319: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8320: $checkedtype = ' checked="checked"';
8321: last;
1.145 raeburn 8322: }
1.138 raeburn 8323: }
8324: }
8325: }
1.137 raeburn 8326: }
1.279 raeburn 8327: $rem = $i%($numinrow);
8328: if ($rem == 0) {
8329: if ($i > 0) {
8330: $datatable .= '</tr>';
8331: }
8332: $datatable .= '<tr>';
8333: }
8334: $datatable .= '<td class="LC_left_item">'.
8335: '<span class="LC_nobreak"><label>'.
8336: '<input type="checkbox" name="'.$prefix.'_'.$type.
8337: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8338: '</label></span></td>';
8339: }
8340: $rem = @locations%($numinrow);
8341: my $colsleft = $numinrow - $rem;
8342: if ($colsleft > 1 ) {
8343: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8344: ' </td>';
8345: } elsif ($colsleft == 1) {
8346: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8347: }
1.279 raeburn 8348: $datatable .= '</tr></table>';
1.137 raeburn 8349: }
1.279 raeburn 8350: $datatable .= '</td></tr>';
8351: $itemcount ++;
1.137 raeburn 8352: }
8353: }
1.279 raeburn 8354: return ($datatable,$itemcount);
1.137 raeburn 8355: }
8356:
1.275 raeburn 8357: sub print_ssl {
8358: my ($position,$dom,$settings,$rowtotal) = @_;
8359: my ($css_class,$datatable);
8360: my $itemcount = 1;
8361: if ($position eq 'top') {
1.281 raeburn 8362: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8363: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8364: my $same_institution;
8365: if ($intdom ne '') {
8366: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8367: if (ref($internet_names) eq 'ARRAY') {
8368: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8369: $same_institution = 1;
8370: }
8371: }
8372: }
1.275 raeburn 8373: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8374: $datatable = '<tr'.$css_class.'><td colspan="2">';
8375: if ($same_institution) {
8376: my %domservers = &Apache::lonnet::get_servers($dom);
8377: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8378: } else {
8379: $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.");
8380: }
8381: $datatable .= '</td></tr>';
1.275 raeburn 8382: $itemcount ++;
8383: } else {
8384: my %titles = &ssl_titles();
8385: my (%by_ip,%by_location,@intdoms,@instdoms);
8386: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8387: my @alldoms = &Apache::lonnet::all_domains();
8388: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8389: my @domservers = &Apache::lonnet::get_servers($dom);
8390: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8391: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8392: if (($position eq 'connto') || ($position eq 'connfrom')) {
8393: my $legacy;
8394: unless (ref($settings) eq 'HASH') {
8395: my $name;
8396: if ($position eq 'connto') {
8397: $name = 'loncAllowInsecure';
8398: } else {
8399: $name = 'londAllowInsecure';
8400: }
8401: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8402: my @ids=&Apache::lonnet::current_machine_ids();
8403: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8404: my %what = (
8405: $name => 1,
8406: );
8407: my ($result,$returnhash) =
8408: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8409: if ($result eq 'ok') {
8410: if (ref($returnhash) eq 'HASH') {
8411: $legacy = $returnhash->{$name};
8412: }
8413: }
8414: } else {
8415: $legacy = $Apache::lonnet::perlvar{$name};
8416: }
8417: }
1.275 raeburn 8418: foreach my $type ('dom','intdom','other') {
8419: my %checked;
8420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8421: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8422: '<td class="LC_right_item">';
8423: my $skip;
8424: if ($type eq 'dom') {
8425: unless (keys(%servers) > 1) {
8426: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8427: $skip = 1;
8428: }
8429: }
8430: if ($type eq 'intdom') {
8431: unless (@instdoms > 1) {
8432: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8433: $skip = 1;
8434: }
8435: } elsif ($type eq 'other') {
8436: if (keys(%by_location) == 0) {
8437: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8438: $skip = 1;
8439: }
8440: }
8441: unless ($skip) {
8442: $checked{'yes'} = ' checked="checked"';
8443: if (ref($settings) eq 'HASH') {
1.293 raeburn 8444: if (ref($settings->{$position}) eq 'HASH') {
8445: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8446: $checked{$1} = $checked{'yes'};
8447: delete($checked{'yes'});
8448: }
8449: }
1.293 raeburn 8450: } else {
8451: if ($legacy == 0) {
8452: $checked{'req'} = $checked{'yes'};
8453: delete($checked{'yes'});
8454: }
1.275 raeburn 8455: }
8456: foreach my $option ('no','yes','req') {
8457: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8458: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8459: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8460: '</label></span>'.(' 'x2);
8461: }
8462: }
8463: $datatable .= '</td></tr>';
8464: $itemcount ++;
8465: }
8466: } else {
8467: my $prefix = 'replication';
8468: my @types = ('certreq','nocertreq');
1.279 raeburn 8469: if (keys(%by_location) == 0) {
8470: $datatable .= '<tr'.$css_class.'><td>'.
8471: &mt('Nothing to set here, as there are no other institutions').
8472: '</td></tr>';
8473: $itemcount ++;
1.275 raeburn 8474: } else {
1.279 raeburn 8475: ($datatable,$itemcount) =
8476: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8477: }
8478: }
8479: }
8480: $$rowtotal += $itemcount;
8481: return $datatable;
8482: }
8483:
8484: sub ssl_titles {
8485: return &Apache::lonlocal::texthash (
8486: dom => 'LON-CAPA servers/VMs from same domain',
8487: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8488: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8489: connto => 'Connections to other servers',
8490: connfrom => 'Connections from other servers',
1.275 raeburn 8491: replication => 'Replicating content to other institutions',
8492: certreq => 'Client certificate required, but specific domains exempt',
8493: nocertreq => 'No client certificate required, except for specific domains',
8494: no => 'SSL not used',
8495: yes => 'SSL Optional (used if available)',
8496: req => 'SSL Required',
8497: );
1.279 raeburn 8498: }
8499:
8500: sub print_trust {
8501: my ($prefix,$dom,$settings,$rowtotal) = @_;
8502: my ($css_class,$datatable,%checked,%choices);
8503: my (%by_ip,%by_location,@intdoms,@instdoms);
8504: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8505: my $itemcount = 1;
8506: my %titles = &trust_titles();
8507: my @types = ('exc','inc');
8508: if ($prefix eq 'top') {
8509: $prefix = 'content';
8510: } elsif ($prefix eq 'bottom') {
8511: $prefix = 'msg';
8512: }
8513: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8514: $$rowtotal += $itemcount;
8515: return $datatable;
8516: }
8517:
8518: sub trust_titles {
8519: return &Apache::lonlocal::texthash(
8520: content => "Access to this domain's content by others",
8521: shared => "Access to other domain's content by this domain",
8522: enroll => "Enrollment in this domain's courses by others",
8523: othcoau => "Co-author roles in this domain for others",
8524: coaurem => "Co-author roles for this domain's users elsewhere",
8525: domroles => "Domain roles in this domain assignable to others",
8526: catalog => "Course Catalog for this domain displayed elsewhere",
8527: reqcrs => "Requests for creation of courses in this domain by others",
8528: msg => "Users in other domains can send messages to this domain",
8529: exc => "Allow all, but exclude specific domains",
8530: inc => "Deny all, but include specific domains",
8531: );
1.275 raeburn 8532: }
8533:
1.138 raeburn 8534: sub build_location_hashes {
1.275 raeburn 8535: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8536: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8537: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8538: my %iphost = &Apache::lonnet::get_iphost();
8539: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8540: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8541: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8542: foreach my $id (@{$iphost{$primary_ip}}) {
8543: my $intdom = &Apache::lonnet::internet_dom($id);
8544: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8545: push(@{$intdoms},$intdom);
8546: }
8547: }
8548: }
8549: foreach my $ip (keys(%iphost)) {
8550: if (ref($iphost{$ip}) eq 'ARRAY') {
8551: foreach my $id (@{$iphost{$ip}}) {
8552: my $location = &Apache::lonnet::internet_dom($id);
8553: if ($location) {
1.275 raeburn 8554: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8555: my $dom = &Apache::lonnet::host_domain($id);
8556: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8557: push(@{$instdoms},$dom);
8558: }
8559: next;
8560: }
1.138 raeburn 8561: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8562: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8563: push(@{$by_ip->{$ip}},$location);
8564: }
8565: } else {
8566: $by_ip->{$ip} = [$location];
8567: }
8568: }
8569: }
8570: }
8571: }
8572: foreach my $ip (sort(keys(%{$by_ip}))) {
8573: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8574: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8575: my $first = $by_ip->{$ip}->[0];
8576: if (ref($by_location->{$first}) eq 'ARRAY') {
8577: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8578: push(@{$by_location->{$first}},$ip);
8579: }
8580: } else {
8581: $by_location->{$first} = [$ip];
8582: }
8583: }
8584: }
8585: return;
8586: }
8587:
1.145 raeburn 8588: sub current_offloads_to {
8589: my ($dom,$settings,$servers) = @_;
8590: my (%spareid,%otherdomconfigs);
1.152 raeburn 8591: if (ref($servers) eq 'HASH') {
1.145 raeburn 8592: foreach my $lonhost (sort(keys(%{$servers}))) {
8593: my $gotspares;
1.152 raeburn 8594: if (ref($settings) eq 'HASH') {
8595: if (ref($settings->{'spares'}) eq 'HASH') {
8596: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8597: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8598: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8599: $gotspares = 1;
8600: }
1.145 raeburn 8601: }
8602: }
8603: unless ($gotspares) {
8604: my $gotspares;
8605: my $serverhomeID =
8606: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8607: my $serverhomedom =
8608: &Apache::lonnet::host_domain($serverhomeID);
8609: if ($serverhomedom ne $dom) {
8610: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8611: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8612: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8613: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8614: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8615: $gotspares = 1;
8616: }
8617: }
8618: } else {
8619: $otherdomconfigs{$serverhomedom} =
8620: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8621: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8622: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8623: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8624: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8625: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8626: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8627: $gotspares = 1;
8628: }
8629: }
8630: }
8631: }
8632: }
8633: }
8634: }
8635: unless ($gotspares) {
8636: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8637: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8638: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8639: } else {
8640: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8641: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8642: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8643: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8644: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8645: } else {
1.150 raeburn 8646: my %what = (
8647: spareid => 1,
8648: );
8649: my ($result,$returnhash) =
8650: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8651: if ($result eq 'ok') {
8652: if (ref($returnhash) eq 'HASH') {
8653: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8654: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8655: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8656: }
8657: }
1.145 raeburn 8658: }
8659: }
8660: }
8661: }
8662: }
8663: }
8664: return %spareid;
8665: }
8666:
8667: sub spares_row {
1.371 raeburn 8668: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8669: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8670: my $css_class;
8671: my $numinrow = 4;
8672: my $itemcount = 1;
8673: my $datatable;
1.152 raeburn 8674: my %typetitles = &sparestype_titles();
8675: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8676: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8677: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8678: my ($othercontrol,$serverdom);
8679: if ($serverhome ne $server) {
8680: $serverdom = &Apache::lonnet::host_domain($serverhome);
8681: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8682: } else {
8683: $serverdom = &Apache::lonnet::host_domain($server);
8684: if ($serverdom ne $dom) {
8685: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8686: }
8687: }
8688: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8689: my ($checkednow,$checkedoth);
1.261 raeburn 8690: if (ref($curroffloadnow) eq 'HASH') {
8691: if ($curroffloadnow->{$server}) {
8692: $checkednow = ' checked="checked"';
8693: }
8694: }
1.371 raeburn 8695: if (ref($curroffloadoth) eq 'HASH') {
8696: if ($curroffloadoth->{$server}) {
8697: $checkedoth = ' checked="checked"';
8698: }
8699: }
1.145 raeburn 8700: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8701: $datatable .= '<tr'.$css_class.'>
8702: <td rowspan="2">
1.183 bisitz 8703: <span class="LC_nobreak">'.
8704: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8705: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8706: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8707: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8708: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8709: "\n";
1.371 raeburn 8710: if ($other_insts) {
8711: $datatable .= '<br />'.
8712: '<span class="LC_nobreak">'."\n".
8713: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8714: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8715: "\n";
8716: }
1.145 raeburn 8717: my (%current,%canselect);
1.152 raeburn 8718: my @choices =
8719: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8720: foreach my $type ('primary','default') {
8721: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8722: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8723: my @spares = @{$spareid->{$server}{$type}};
8724: if (@spares > 0) {
1.152 raeburn 8725: if ($othercontrol) {
8726: $current{$type} = join(', ',@spares);
8727: } else {
8728: $current{$type} .= '<table>';
8729: my $numspares = scalar(@spares);
8730: for (my $i=0; $i<@spares; $i++) {
8731: my $rem = $i%($numinrow);
8732: if ($rem == 0) {
8733: if ($i > 0) {
8734: $current{$type} .= '</tr>';
8735: }
8736: $current{$type} .= '<tr>';
1.145 raeburn 8737: }
1.152 raeburn 8738: $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'".');" /> '.
8739: $spareid->{$server}{$type}[$i].
8740: '</label></td>'."\n";
8741: }
8742: my $rem = @spares%($numinrow);
8743: my $colsleft = $numinrow - $rem;
8744: if ($colsleft > 1 ) {
8745: $current{$type} .= '<td colspan="'.$colsleft.
8746: '" class="LC_left_item">'.
8747: ' </td>';
8748: } elsif ($colsleft == 1) {
8749: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8750: }
1.152 raeburn 8751: $current{$type} .= '</tr></table>';
1.150 raeburn 8752: }
1.145 raeburn 8753: }
8754: }
8755: if ($current{$type} eq '') {
8756: $current{$type} = &mt('None specified');
8757: }
1.152 raeburn 8758: if ($othercontrol) {
8759: if ($type eq 'primary') {
8760: $canselect{$type} = $othercontrol;
8761: }
8762: } else {
8763: $canselect{$type} =
8764: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8765: '<select name="newspare_'.$type.'_'.$server.'" '.
8766: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8767: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8768: if (@choices > 0) {
8769: foreach my $lonhost (@choices) {
8770: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8771: }
8772: }
8773: $canselect{$type} .= '</select>'."\n";
8774: }
8775: } else {
8776: $current{$type} = &mt('Could not be determined');
8777: if ($type eq 'primary') {
8778: $canselect{$type} = $othercontrol;
8779: }
1.145 raeburn 8780: }
1.152 raeburn 8781: if ($type eq 'default') {
8782: $datatable .= '<tr'.$css_class.'>';
8783: }
8784: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8785: '<td>'.$current{$type}.'</td>'."\n".
8786: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8787: }
8788: $itemcount ++;
8789: }
8790: }
8791: $$rowtotal += $itemcount;
8792: return $datatable;
8793: }
8794:
1.152 raeburn 8795: sub possible_newspares {
8796: my ($server,$currspares,$serverhomes,$altids) = @_;
8797: my $serverhostname = &Apache::lonnet::hostname($server);
8798: my %excluded;
8799: if ($serverhostname ne '') {
8800: %excluded = (
8801: $serverhostname => 1,
8802: );
8803: }
8804: if (ref($currspares) eq 'HASH') {
8805: foreach my $type (keys(%{$currspares})) {
8806: if (ref($currspares->{$type}) eq 'ARRAY') {
8807: if (@{$currspares->{$type}} > 0) {
8808: foreach my $curr (@{$currspares->{$type}}) {
8809: my $hostname = &Apache::lonnet::hostname($curr);
8810: $excluded{$hostname} = 1;
8811: }
8812: }
8813: }
8814: }
8815: }
8816: my @choices;
8817: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8818: if (keys(%{$serverhomes}) > 1) {
8819: foreach my $name (sort(keys(%{$serverhomes}))) {
8820: unless ($excluded{$name}) {
8821: if (exists($altids->{$serverhomes->{$name}})) {
8822: push(@choices,$altids->{$serverhomes->{$name}});
8823: } else {
8824: push(@choices,$serverhomes->{$name});
1.145 raeburn 8825: }
8826: }
8827: }
8828: }
8829: }
1.152 raeburn 8830: return sort(@choices);
1.145 raeburn 8831: }
8832:
1.150 raeburn 8833: sub print_loadbalancing {
8834: my ($dom,$settings,$rowtotal) = @_;
8835: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8836: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8837: my $numinrow = 1;
8838: my $datatable;
8839: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8840: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8841: if (ref($settings) eq 'HASH') {
8842: %existing = %{$settings};
8843: }
8844: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8845: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8846: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8847: } else {
8848: return;
8849: }
8850: my ($othertitle,$usertypes,$types) =
8851: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8852: my $rownum = 8;
1.150 raeburn 8853: if (ref($types) eq 'ARRAY') {
8854: $rownum += scalar(@{$types});
8855: }
1.171 raeburn 8856: my @css_class = ('LC_odd_row','LC_even_row');
8857: my $balnum = 0;
8858: my $islast;
8859: my (@toshow,$disabledtext);
8860: if (keys(%currbalancer) > 0) {
8861: @toshow = sort(keys(%currbalancer));
8862: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8863: push(@toshow,'');
8864: }
8865: } else {
8866: @toshow = ('');
8867: $disabledtext = &mt('No existing load balancer');
8868: }
8869: foreach my $lonhost (@toshow) {
8870: if ($balnum == scalar(@toshow)-1) {
8871: $islast = 1;
8872: } else {
8873: $islast = 0;
8874: }
8875: my $cssidx = $balnum%2;
8876: my $targets_div_style = 'display: none';
8877: my $disabled_div_style = 'display: block';
8878: my $homedom_div_style = 'display: none';
8879: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8880: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8881: '<p>';
8882: if ($lonhost eq '') {
1.210 raeburn 8883: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8884: if (keys(%currbalancer) > 0) {
8885: $datatable .= &mt('Add balancer:');
8886: } else {
8887: $datatable .= &mt('Enable balancer:');
8888: }
8889: $datatable .= ' '.
8890: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8891: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8892: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8893: '<option value="" selected="selected">'.&mt('None').
8894: '</option>'."\n";
8895: foreach my $server (sort(keys(%servers))) {
8896: next if ($currbalancer{$server});
8897: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8898: }
1.210 raeburn 8899: $datatable .=
1.171 raeburn 8900: '</select>'."\n".
8901: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8902: } else {
8903: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8904: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8905: &mt('Stop balancing').'</label>'.
8906: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8907: $targets_div_style = 'display: block';
8908: $disabled_div_style = 'display: none';
8909: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8910: $homedom_div_style = 'display: block';
8911: }
8912: }
1.306 raeburn 8913: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8914: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8915: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8916: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8917: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8918: my @sparestypes = ('primary','default');
8919: my %typetitles = &sparestype_titles();
1.284 raeburn 8920: my %hostherechecked = (
8921: no => ' checked="checked"',
8922: );
1.342 raeburn 8923: my %balcookiechecked = (
8924: no => ' checked="checked"',
8925: );
1.171 raeburn 8926: foreach my $sparetype (@sparestypes) {
8927: my $targettable;
8928: for (my $i=0; $i<$numspares; $i++) {
8929: my $checked;
8930: if (ref($currtargets{$lonhost}) eq 'HASH') {
8931: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8932: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8933: $checked = ' checked="checked"';
8934: }
8935: }
8936: }
8937: my ($chkboxval,$disabled);
8938: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8939: $chkboxval = $spares[$i];
8940: }
8941: if (exists($currbalancer{$spares[$i]})) {
8942: $disabled = ' disabled="disabled"';
8943: }
1.210 raeburn 8944: $targettable .=
1.253 raeburn 8945: '<td><span class="LC_nobreak"><label>'.
8946: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8947: $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 8948: '</span></label></span></td>';
1.171 raeburn 8949: my $rem = $i%($numinrow);
8950: if ($rem == 0) {
8951: if (($i > 0) && ($i < $numspares-1)) {
8952: $targettable .= '</tr>';
8953: }
8954: if ($i < $numspares-1) {
8955: $targettable .= '<tr>';
1.150 raeburn 8956: }
8957: }
8958: }
1.171 raeburn 8959: if ($targettable ne '') {
8960: my $rem = $numspares%($numinrow);
8961: my $colsleft = $numinrow - $rem;
8962: if ($colsleft > 1 ) {
8963: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8964: ' </td>';
8965: } elsif ($colsleft == 1) {
8966: $targettable .= '<td class="LC_left_item"> </td>';
8967: }
8968: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8969: '<table><tr>'.$targettable.'</tr></table><br />';
8970: }
1.284 raeburn 8971: $hostherechecked{$sparetype} = '';
8972: if (ref($currtargets{$lonhost}) eq 'HASH') {
8973: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8974: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8975: $hostherechecked{$sparetype} = ' checked="checked"';
8976: $hostherechecked{'no'} = '';
8977: }
8978: }
8979: }
8980: }
1.342 raeburn 8981: if ($currcookies{$lonhost}) {
8982: %balcookiechecked = (
8983: yes => ' checked="checked"',
8984: );
8985: }
1.284 raeburn 8986: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8987: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8988: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8989: foreach my $sparetype (@sparestypes) {
8990: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8991: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8992: '</i></label><br />';
1.171 raeburn 8993: }
1.342 raeburn 8994: $datatable .= &mt('Use balancer cookie').'<br />'.
8995: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8996: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8997: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8998: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8999: '</div></td></tr>'.
1.171 raeburn 9000: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9001: $othertitle,$usertypes,$types,\%servers,
9002: \%currbalancer,$lonhost,
9003: $targets_div_style,$homedom_div_style,
9004: $css_class[$cssidx],$balnum,$islast);
9005: $$rowtotal += $rownum;
9006: $balnum ++;
9007: }
9008: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9009: return $datatable;
9010: }
9011:
9012: sub get_loadbalancers_config {
1.342 raeburn 9013: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9014: return unless ((ref($servers) eq 'HASH') &&
9015: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9016: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9017: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9018: if (keys(%{$existing}) > 0) {
9019: my $oldlonhost;
9020: foreach my $key (sort(keys(%{$existing}))) {
9021: if ($key eq 'lonhost') {
9022: $oldlonhost = $existing->{'lonhost'};
9023: $currbalancer->{$oldlonhost} = 1;
9024: } elsif ($key eq 'targets') {
9025: if ($oldlonhost) {
9026: $currtargets->{$oldlonhost} = $existing->{'targets'};
9027: }
9028: } elsif ($key eq 'rules') {
9029: if ($oldlonhost) {
9030: $currrules->{$oldlonhost} = $existing->{'rules'};
9031: }
9032: } elsif (ref($existing->{$key}) eq 'HASH') {
9033: $currbalancer->{$key} = 1;
9034: $currtargets->{$key} = $existing->{$key}{'targets'};
9035: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9036: if ($existing->{$key}{'cookie'}) {
9037: $currcookies->{$key} = 1;
9038: }
1.150 raeburn 9039: }
9040: }
1.171 raeburn 9041: } else {
9042: my ($balancerref,$targetsref) =
9043: &Apache::lonnet::get_lonbalancer_config($servers);
9044: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9045: foreach my $server (sort(keys(%{$balancerref}))) {
9046: $currbalancer->{$server} = 1;
9047: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9048: }
9049: }
9050: }
1.171 raeburn 9051: return;
1.150 raeburn 9052: }
9053:
9054: sub loadbalancing_rules {
9055: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9056: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9057: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9058: my $output;
1.171 raeburn 9059: my $num = 0;
1.210 raeburn 9060: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9061: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9062: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9063: foreach my $type (@{$alltypes}) {
1.171 raeburn 9064: $num ++;
1.150 raeburn 9065: my $current;
9066: if (ref($currrules) eq 'HASH') {
9067: $current = $currrules->{$type};
9068: }
1.253 raeburn 9069: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9070: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9071: $current = '';
9072: }
9073: }
9074: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9075: $servers,$currbalancer,$lonhost,$dom,
9076: $targets_div_style,$homedom_div_style,
9077: $css_class,$balnum,$num,$islast);
1.150 raeburn 9078: }
9079: }
9080: return $output;
9081: }
9082:
9083: sub loadbalancing_titles {
9084: my ($dom,$intdom,$usertypes,$types) = @_;
9085: my %othertypes = (
9086: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9087: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9088: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9089: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9090: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9091: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9092: );
1.209 raeburn 9093: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9094: my @available;
1.150 raeburn 9095: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9096: @available = @{$types};
1.150 raeburn 9097: }
1.302 raeburn 9098: unless (grep(/^default$/,@available)) {
9099: push(@available,'default');
9100: }
9101: unshift(@alltypes,@available);
1.150 raeburn 9102: my %titles;
9103: foreach my $type (@alltypes) {
9104: if ($type =~ /^_LC_/) {
9105: $titles{$type} = $othertypes{$type};
9106: } elsif ($type eq 'default') {
9107: $titles{$type} = &mt('All users from [_1]',$dom);
9108: if (ref($types) eq 'ARRAY') {
9109: if (@{$types} > 0) {
9110: $titles{$type} = &mt('Other users from [_1]',$dom);
9111: }
9112: }
9113: } elsif (ref($usertypes) eq 'HASH') {
9114: $titles{$type} = $usertypes->{$type};
9115: }
9116: }
9117: return (\@alltypes,\%othertypes,\%titles);
9118: }
9119:
9120: sub loadbalance_rule_row {
1.171 raeburn 9121: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9122: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9123: my @rulenames;
1.150 raeburn 9124: my %ruletitles = &offloadtype_text();
1.209 raeburn 9125: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9126: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9127: } else {
1.209 raeburn 9128: @rulenames = ('default','homeserver');
9129: if ($type eq '_LC_external') {
9130: push(@rulenames,'externalbalancer');
9131: } else {
9132: push(@rulenames,'specific');
9133: }
9134: push(@rulenames,'none');
1.150 raeburn 9135: }
9136: my $style = $targets_div_style;
1.253 raeburn 9137: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9138: $style = $homedom_div_style;
9139: }
1.171 raeburn 9140: my $space;
9141: if ($islast && $num == 1) {
1.317 raeburn 9142: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9143: }
1.210 raeburn 9144: my $output =
1.306 raeburn 9145: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9146: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9147: '<td valaign="top">'.$space.
9148: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9149: for (my $i=0; $i<@rulenames; $i++) {
9150: my $rule = $rulenames[$i];
9151: my ($checked,$extra);
9152: if ($rulenames[$i] eq 'default') {
9153: $rule = '';
9154: }
9155: if ($rulenames[$i] eq 'specific') {
9156: if (ref($servers) eq 'HASH') {
9157: my $default;
9158: if (($current ne '') && (exists($servers->{$current}))) {
9159: $checked = ' checked="checked"';
9160: }
9161: unless ($checked) {
9162: $default = ' selected="selected"';
9163: }
1.210 raeburn 9164: $extra =
1.171 raeburn 9165: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9166: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9167: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9168: '<option value=""'.$default.'></option>'."\n";
9169: foreach my $server (sort(keys(%{$servers}))) {
9170: if (ref($currbalancer) eq 'HASH') {
9171: next if (exists($currbalancer->{$server}));
9172: }
1.150 raeburn 9173: my $selected;
1.171 raeburn 9174: if ($server eq $current) {
1.150 raeburn 9175: $selected = ' selected="selected"';
9176: }
1.171 raeburn 9177: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9178: }
9179: $extra .= '</select>';
9180: }
9181: } elsif ($rule eq $current) {
9182: $checked = ' checked="checked"';
9183: }
9184: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9185: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9186: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9187: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9188: ')"'.$checked.' /> ';
9189: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9190: $output .= $ruletitles{'particular'};
9191: } else {
9192: $output .= $ruletitles{$rulenames[$i]};
9193: }
9194: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9195: }
9196: $output .= '</div></td></tr>'."\n";
9197: return $output;
9198: }
9199:
9200: sub offloadtype_text {
9201: my %ruletitles = &Apache::lonlocal::texthash (
9202: 'default' => 'Offloads to default destinations',
9203: 'homeserver' => "Offloads to user's home server",
9204: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9205: 'specific' => 'Offloads to specific server',
1.161 raeburn 9206: 'none' => 'No offload',
1.209 raeburn 9207: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9208: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9209: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9210: );
9211: return %ruletitles;
9212: }
9213:
9214: sub sparestype_titles {
9215: my %typestitles = &Apache::lonlocal::texthash (
9216: 'primary' => 'primary',
9217: 'default' => 'default',
9218: );
9219: return %typestitles;
9220: }
9221:
1.28 raeburn 9222: sub contact_titles {
9223: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9224: 'supportemail' => 'Support E-mail address',
9225: 'adminemail' => 'Default Server Admin E-mail address',
9226: 'errormail' => 'Error reports to be e-mailed to',
9227: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9228: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9229: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9230: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9231: 'requestsmail' => 'E-mail from course requests requiring approval',
9232: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9233: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9234: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9235: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9236: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9237: 'errorweights' => 'Weights used to compute error count',
9238: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9239: );
9240: my %short_titles = &Apache::lonlocal::texthash (
9241: adminemail => 'Admin E-mail address',
9242: supportemail => 'Support E-mail',
9243: );
9244: return (\%titles,\%short_titles);
9245: }
9246:
1.286 raeburn 9247: sub helpform_fields {
9248: my %titles = &Apache::lonlocal::texthash (
9249: 'username' => 'Name',
9250: 'user' => 'Username/domain',
9251: 'phone' => 'Phone',
9252: 'cc' => 'Cc e-mail',
9253: 'course' => 'Course Details',
9254: 'section' => 'Sections',
1.289 raeburn 9255: 'screenshot' => 'File upload',
1.286 raeburn 9256: );
9257: my @fields = ('username','phone','user','course','section','cc','screenshot');
9258: my %possoptions = (
9259: username => ['yes','no','req'],
1.289 raeburn 9260: phone => ['yes','no','req'],
1.286 raeburn 9261: user => ['yes','no'],
1.289 raeburn 9262: cc => ['yes','no'],
1.286 raeburn 9263: course => ['yes','no'],
9264: section => ['yes','no'],
9265: screenshot => ['yes','no'],
9266: );
9267: my %fieldoptions = &Apache::lonlocal::texthash (
9268: 'yes' => 'Optional',
9269: 'req' => 'Required',
9270: 'no' => "Not shown",
9271: );
9272: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9273: }
9274:
1.72 raeburn 9275: sub tool_titles {
9276: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9277: aboutme => 'Personal web page',
1.86 raeburn 9278: blog => 'Blog',
1.162 raeburn 9279: webdav => 'WebDAV',
1.86 raeburn 9280: portfolio => 'Portfolio',
1.413 raeburn 9281: timezone => 'Can set time zone',
1.88 bisitz 9282: official => 'Official courses (with institutional codes)',
9283: unofficial => 'Unofficial courses',
1.98 raeburn 9284: community => 'Communities',
1.216 raeburn 9285: textbook => 'Textbook courses',
1.271 raeburn 9286: placement => 'Placement tests',
1.86 raeburn 9287: );
1.72 raeburn 9288: return %titles;
9289: }
9290:
1.101 raeburn 9291: sub courserequest_titles {
9292: my %titles = &Apache::lonlocal::texthash (
9293: official => 'Official',
9294: unofficial => 'Unofficial',
9295: community => 'Communities',
1.216 raeburn 9296: textbook => 'Textbook',
1.271 raeburn 9297: placement => 'Placement tests',
1.325 raeburn 9298: lti => 'LTI Provider',
1.101 raeburn 9299: norequest => 'Not allowed',
1.325 raeburn 9300: approval => 'Approval by DC',
1.101 raeburn 9301: validate => 'With validation',
9302: autolimit => 'Numerical limit',
1.103 raeburn 9303: unlimited => '(blank for unlimited)',
1.101 raeburn 9304: );
9305: return %titles;
9306: }
9307:
1.163 raeburn 9308: sub authorrequest_titles {
9309: my %titles = &Apache::lonlocal::texthash (
9310: norequest => 'Not allowed',
9311: approval => 'Approval by Dom. Coord.',
9312: automatic => 'Automatic approval',
9313: );
9314: return %titles;
1.210 raeburn 9315: }
1.163 raeburn 9316:
1.101 raeburn 9317: sub courserequest_conditions {
9318: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9319: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9320: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9321: );
9322: return %conditions;
9323: }
9324:
9325:
1.27 raeburn 9326: sub print_usercreation {
1.30 raeburn 9327: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9328: my $numinrow = 4;
1.28 raeburn 9329: my $datatable;
9330: if ($position eq 'top') {
1.30 raeburn 9331: $$rowtotal ++;
1.34 raeburn 9332: my $rowcount = 0;
1.32 raeburn 9333: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9334: if (ref($rules) eq 'HASH') {
9335: if (keys(%{$rules}) > 0) {
1.32 raeburn 9336: $datatable .= &user_formats_row('username',$settings,$rules,
9337: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9338: $$rowtotal ++;
1.32 raeburn 9339: $rowcount ++;
9340: }
9341: }
9342: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9343: if (ref($idrules) eq 'HASH') {
9344: if (keys(%{$idrules}) > 0) {
9345: $datatable .= &user_formats_row('id',$settings,$idrules,
9346: $idruleorder,$numinrow,$rowcount);
9347: $$rowtotal ++;
9348: $rowcount ++;
1.28 raeburn 9349: }
9350: }
1.39 raeburn 9351: if ($rowcount == 0) {
9352: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9353: $$rowtotal ++;
9354: $rowcount ++;
9355: }
1.34 raeburn 9356: } elsif ($position eq 'middle') {
1.224 raeburn 9357: my @creators = ('author','course','requestcrs');
1.37 raeburn 9358: my ($rules,$ruleorder) =
9359: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9360: my %lt = &usercreation_types();
9361: my %checked;
9362: if (ref($settings) eq 'HASH') {
9363: if (ref($settings->{'cancreate'}) eq 'HASH') {
9364: foreach my $item (@creators) {
9365: $checked{$item} = $settings->{'cancreate'}{$item};
9366: }
9367: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9368: foreach my $item (@creators) {
9369: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9370: $checked{$item} = 'none';
9371: }
9372: }
9373: }
9374: }
9375: my $rownum = 0;
9376: foreach my $item (@creators) {
9377: $rownum ++;
1.224 raeburn 9378: if ($checked{$item} eq '') {
9379: $checked{$item} = 'any';
1.34 raeburn 9380: }
9381: my $css_class;
9382: if ($rownum%2) {
9383: $css_class = '';
9384: } else {
9385: $css_class = ' class="LC_odd_row" ';
9386: }
9387: $datatable .= '<tr'.$css_class.'>'.
9388: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9389: '</span></td><td style="text-align: right">';
1.224 raeburn 9390: my @options = ('any');
9391: if (ref($rules) eq 'HASH') {
9392: if (keys(%{$rules}) > 0) {
9393: push(@options,('official','unofficial'));
1.37 raeburn 9394: }
9395: }
1.224 raeburn 9396: push(@options,'none');
1.37 raeburn 9397: foreach my $option (@options) {
1.50 raeburn 9398: my $type = 'radio';
1.34 raeburn 9399: my $check = ' ';
1.224 raeburn 9400: if ($checked{$item} eq $option) {
9401: $check = ' checked="checked" ';
1.34 raeburn 9402: }
9403: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9404: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9405: $item.'" value="'.$option.'"'.$check.'/> '.
9406: $lt{$option}.'</label> </span>';
9407: }
9408: $datatable .= '</td></tr>';
9409: }
1.28 raeburn 9410: } else {
9411: my @contexts = ('author','course','domain');
1.325 raeburn 9412: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9413: my %checked;
9414: if (ref($settings) eq 'HASH') {
9415: if (ref($settings->{'authtypes'}) eq 'HASH') {
9416: foreach my $item (@contexts) {
9417: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9418: foreach my $auth (@authtypes) {
9419: if ($settings->{'authtypes'}{$item}{$auth}) {
9420: $checked{$item}{$auth} = ' checked="checked" ';
9421: }
9422: }
9423: }
9424: }
1.27 raeburn 9425: }
1.35 raeburn 9426: } else {
9427: foreach my $item (@contexts) {
1.36 raeburn 9428: foreach my $auth (@authtypes) {
1.35 raeburn 9429: $checked{$item}{$auth} = ' checked="checked" ';
9430: }
9431: }
1.27 raeburn 9432: }
1.28 raeburn 9433: my %title = &context_names();
9434: my %authname = &authtype_names();
9435: my $rownum = 0;
9436: my $css_class;
9437: foreach my $item (@contexts) {
9438: if ($rownum%2) {
9439: $css_class = '';
9440: } else {
9441: $css_class = ' class="LC_odd_row" ';
9442: }
1.30 raeburn 9443: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9444: '<td>'.$title{$item}.
9445: '</td><td class="LC_left_item">'.
9446: '<span class="LC_nobreak">';
9447: foreach my $auth (@authtypes) {
9448: $datatable .= '<label>'.
9449: '<input type="checkbox" name="'.$item.'_auth" '.
9450: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9451: $authname{$auth}.'</label> ';
9452: }
9453: $datatable .= '</span></td></tr>';
9454: $rownum ++;
1.27 raeburn 9455: }
1.30 raeburn 9456: $$rowtotal += $rownum;
1.27 raeburn 9457: }
9458: return $datatable;
9459: }
9460:
1.224 raeburn 9461: sub print_selfcreation {
9462: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9463: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9464: $emaildomain,$datatable);
1.224 raeburn 9465: if (ref($settings) eq 'HASH') {
9466: if (ref($settings->{'cancreate'}) eq 'HASH') {
9467: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9468: if (ref($createsettings) eq 'HASH') {
9469: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9470: @selfcreate = @{$createsettings->{'selfcreate'}};
9471: } elsif ($createsettings->{'selfcreate'} ne '') {
9472: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9473: @selfcreate = ('email','login','sso');
9474: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9475: @selfcreate = ($createsettings->{'selfcreate'});
9476: }
9477: }
9478: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9479: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9480: }
1.305 raeburn 9481: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9482: $emailoptions = $createsettings->{'emailoptions'};
9483: }
1.303 raeburn 9484: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9485: $emailverified = $createsettings->{'emailverified'};
9486: }
9487: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9488: $emaildomain = $createsettings->{'emaildomain'};
9489: }
1.224 raeburn 9490: }
9491: }
9492: }
9493: my %radiohash;
9494: my $numinrow = 4;
9495: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9496: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9497: if ($position eq 'top') {
9498: my %choices = &Apache::lonlocal::texthash (
9499: cancreate_login => 'Institutional Login',
9500: cancreate_sso => 'Institutional Single Sign On',
9501: );
9502: my @toggles = sort(keys(%choices));
9503: my %defaultchecked = (
9504: 'cancreate_login' => 'off',
9505: 'cancreate_sso' => 'off',
9506: );
1.228 raeburn 9507: my ($onclick,$itemcount);
1.224 raeburn 9508: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9509: \%choices,$itemcount,$onclick);
1.228 raeburn 9510: $$rowtotal += $itemcount;
9511:
1.224 raeburn 9512: if (ref($usertypes) eq 'HASH') {
9513: if (keys(%{$usertypes}) > 0) {
9514: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9515: $dom,$numinrow,$othertitle,
1.305 raeburn 9516: 'statustocreate',$rowtotal);
1.224 raeburn 9517: $$rowtotal ++;
9518: }
9519: }
1.240 raeburn 9520: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9521: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9522: $fieldtitles{'inststatus'} = &mt('Institutional status');
9523: my $rem;
9524: my $numperrow = 2;
9525: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9526: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9527: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9528: '<td class="LC_left_item">'."\n".
1.334 raeburn 9529: '<table>'."\n";
1.240 raeburn 9530: for (my $i=0; $i<@fields; $i++) {
9531: $rem = $i%($numperrow);
9532: if ($rem == 0) {
9533: if ($i > 0) {
9534: $datatable .= '</tr>';
9535: }
9536: $datatable .= '<tr>';
9537: }
9538: my $currval;
1.248 raeburn 9539: if (ref($createsettings) eq 'HASH') {
9540: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9541: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9542: }
1.240 raeburn 9543: }
9544: $datatable .= '<td class="LC_left_item">'.
9545: '<span class="LC_nobreak">'.
9546: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9547: 'value="'.$currval.'" size="10" /> '.
9548: $fieldtitles{$fields[$i]}.'</span></td>';
9549: }
9550: my $colsleft = $numperrow - $rem;
9551: if ($colsleft > 1 ) {
9552: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9553: ' </td>';
9554: } elsif ($colsleft == 1) {
9555: $datatable .= '<td class="LC_left_item"> </td>';
9556: }
9557: $datatable .= '</tr></table></td></tr>';
9558: $$rowtotal ++;
1.224 raeburn 9559: } elsif ($position eq 'middle') {
9560: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9561: my @posstypes;
1.224 raeburn 9562: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9563: @posstypes = @{$types};
9564: }
9565: unless (grep(/^default$/,@posstypes)) {
9566: push(@posstypes,'default');
9567: }
9568: my %usertypeshash;
9569: if (ref($usertypes) eq 'HASH') {
9570: %usertypeshash = %{$usertypes};
9571: }
9572: $usertypeshash{'default'} = $othertitle;
9573: foreach my $status (@posstypes) {
9574: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9575: $numinrow,$$rowtotal,\%usertypeshash);
9576: $$rowtotal ++;
1.224 raeburn 9577: }
9578: } else {
1.236 raeburn 9579: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9580: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9581: );
9582: my @toggles = sort(keys(%choices));
9583: my %defaultchecked = (
9584: 'cancreate_email' => 'off',
9585: );
1.305 raeburn 9586: my $customclass = 'LC_selfcreate_email';
9587: my $classprefix = 'LC_canmodify_emailusername_';
9588: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9589: my $display = 'none';
1.305 raeburn 9590: my $rowstyle = 'display:none';
1.236 raeburn 9591: if (grep(/^\Qemail\E$/,@selfcreate)) {
9592: $display = 'block';
1.305 raeburn 9593: $rowstyle = 'display:table-row';
1.236 raeburn 9594: }
1.305 raeburn 9595: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9596: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9597: \%choices,$$rowtotal,$onclick);
9598: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9599: $rowstyle);
9600: $$rowtotal ++;
9601: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9602: $rowstyle);
9603: $$rowtotal ++;
9604: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9605: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9606: my ($emailrules,$emailruleorder) =
9607: &Apache::lonnet::inst_userrules($dom,'email');
9608: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9609: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9610: if (ref($types) eq 'ARRAY') {
9611: @posstypes = @{$types};
9612: }
9613: if (@posstypes) {
9614: unless (grep(/^default$/,@posstypes)) {
9615: push(@posstypes,'default');
1.302 raeburn 9616: }
9617: if (ref($usertypes) eq 'HASH') {
9618: %usertypeshash = %{$usertypes};
9619: }
1.305 raeburn 9620: my $currassign;
9621: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9622: $currassign = {
9623: selfassign => $domdefaults{'inststatusguest'},
9624: };
9625: @ordered = @{$domdefaults{'inststatusguest'}};
9626: } else {
9627: $currassign = { selfassign => [] };
9628: }
9629: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9630: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9631: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9632: $numinrow,$othertitle,'selfassign',
9633: $rowtotal,$onclicktypes,$customclass,
9634: $rowstyle);
9635: $$rowtotal ++;
1.302 raeburn 9636: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9637: foreach my $status (@posstypes) {
9638: my $css_class;
9639: if ($$rowtotal%2) {
9640: $css_class = 'LC_odd_row ';
9641: }
9642: $css_class .= $customclass;
9643: my $rowid = $optionsprefix.$status;
9644: my $hidden = 1;
9645: my $currstyle = 'display:none';
9646: if (grep(/^\Q$status\E$/,@ordered)) {
9647: $currstyle = $rowstyle;
9648: $hidden = 0;
9649: }
9650: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9651: $emailrules,$emailruleorder,$settings,$status,$rowid,
9652: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9653: unless ($hidden) {
9654: $$rowtotal ++;
9655: }
1.224 raeburn 9656: }
1.302 raeburn 9657: } else {
1.305 raeburn 9658: my $css_class;
9659: if ($$rowtotal%2) {
9660: $css_class = 'LC_odd_row ';
9661: }
9662: $css_class .= $customclass;
1.302 raeburn 9663: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9664: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9665: $emailrules,$emailruleorder,$settings,'default','',
9666: $othertitle,$css_class,$rowstyle,$intdom);
9667: $$rowtotal ++;
1.224 raeburn 9668: }
9669: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9670: $numinrow = 1;
1.305 raeburn 9671: if (@posstypes) {
9672: foreach my $status (@posstypes) {
9673: my $rowid = $classprefix.$status;
9674: my $datarowstyle = 'display:none';
9675: if (grep(/^\Q$status\E$/,@ordered)) {
9676: $datarowstyle = $rowstyle;
9677: }
9678: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9679: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9680: $infotitles,$rowid,$customclass,$datarowstyle);
9681: unless ($datarowstyle eq 'display:none') {
9682: $$rowtotal ++;
9683: }
1.224 raeburn 9684: }
1.305 raeburn 9685: } else {
9686: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9687: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9688: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9689: }
9690: }
9691: return $datatable;
9692: }
9693:
1.305 raeburn 9694: sub selfcreate_javascript {
9695: return <<"ENDSCRIPT";
9696:
9697: <script type="text/javascript">
9698: // <![CDATA[
9699:
9700: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9701: var x = document.getElementsByClassName(target);
9702: var insttypes = 0;
9703: var insttypeRegExp = new RegExp(prefix);
9704: if ((x.length != undefined) && (x.length > 0)) {
9705: if (form.elements[radio].length != undefined) {
9706: for (var i=0; i<form.elements[radio].length; i++) {
9707: if (form.elements[radio][i].checked) {
9708: if (form.elements[radio][i].value == 1) {
9709: for (var j=0; j<x.length; j++) {
9710: if (x[j].id == 'undefined') {
9711: x[j].style.display = 'table-row';
9712: } else if (insttypeRegExp.test(x[j].id)) {
9713: insttypes ++;
9714: } else {
9715: x[j].style.display = 'table-row';
9716: }
9717: }
9718: } else {
9719: for (var j=0; j<x.length; j++) {
9720: x[j].style.display = 'none';
9721: }
1.236 raeburn 9722: }
1.305 raeburn 9723: break;
9724: }
9725: }
9726: if (insttypes > 0) {
9727: toggleDataRow(form,checkbox,target,altprefix);
9728: toggleDataRow(form,checkbox,target,prefix,1);
9729: }
9730: }
9731: }
9732: return;
9733: }
9734:
9735: function toggleDataRow(form,checkbox,target,prefix,docount) {
9736: if (form.elements[checkbox].length != undefined) {
9737: var count = 0;
9738: if (docount) {
9739: for (var i=0; i<form.elements[checkbox].length; i++) {
9740: if (form.elements[checkbox][i].checked) {
9741: count ++;
1.236 raeburn 9742: }
1.305 raeburn 9743: }
9744: }
9745: for (var i=0; i<form.elements[checkbox].length; i++) {
9746: var type = form.elements[checkbox][i].value;
9747: if (document.getElementById(prefix+type)) {
9748: if (form.elements[checkbox][i].checked) {
9749: document.getElementById(prefix+type).style.display = 'table-row';
9750: if (count % 2 == 1) {
9751: document.getElementById(prefix+type).className = target+' LC_odd_row';
9752: } else {
9753: document.getElementById(prefix+type).className = target;
1.236 raeburn 9754: }
1.305 raeburn 9755: count ++;
1.236 raeburn 9756: } else {
1.305 raeburn 9757: document.getElementById(prefix+type).style.display = 'none';
9758: }
9759: }
9760: }
9761: }
9762: return;
9763: }
9764:
9765: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9766: var caller = radio+'_'+status;
9767: if (form.elements[caller].length != undefined) {
9768: for (var i=0; i<form.elements[caller].length; i++) {
9769: if (form.elements[caller][i].checked) {
9770: if (document.getElementById(altprefix+'_inst_'+status)) {
9771: var curr = form.elements[caller][i].value;
9772: if (prefix) {
9773: document.getElementById(prefix+'_'+status).style.display = 'none';
9774: }
9775: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9776: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9777: if (curr == 'custom') {
9778: if (prefix) {
9779: document.getElementById(prefix+'_'+status).style.display = 'inline';
9780: }
9781: } else if (curr == 'inst') {
9782: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9783: } else if (curr == 'noninst') {
9784: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9785: }
1.305 raeburn 9786: break;
1.236 raeburn 9787: }
9788: }
9789: }
9790: }
9791: }
9792:
1.305 raeburn 9793: // ]]>
9794: </script>
9795:
9796: ENDSCRIPT
9797: }
9798:
9799: sub noninst_users {
9800: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9801: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9802: my $class = 'LC_left_item';
9803: if ($css_class) {
9804: $css_class = ' class="'.$css_class.'"';
9805: }
9806: if ($rowid) {
9807: $rowid = ' id="'.$rowid.'"';
9808: }
9809: if ($rowstyle) {
9810: $rowstyle = ' style="'.$rowstyle.'"';
9811: }
9812: my ($output,$description);
9813: if ($type eq 'default') {
9814: $description = &mt('Requests for: [_1]',$typetitle);
9815: } else {
9816: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9817: }
9818: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9819: "<td>$description</td>\n".
9820: '<td class="'.$class.'" colspan="2">'.
9821: '<table><tr>';
9822: my %headers = &Apache::lonlocal::texthash(
9823: approve => 'Processing',
9824: email => 'E-mail',
9825: username => 'Username',
9826: );
9827: foreach my $item ('approve','email','username') {
9828: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9829: }
1.305 raeburn 9830: $output .= '</tr><tr>';
9831: foreach my $item ('approve','email','username') {
1.306 raeburn 9832: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9833: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9834: if ($item eq 'approve') {
9835: %choices = &Apache::lonlocal::texthash (
9836: automatic => 'Automatically approved',
9837: approval => 'Queued for approval',
9838: );
9839: @options = ('automatic','approval');
9840: $hashref = $processing;
9841: $defoption = 'automatic';
9842: $name = 'cancreate_emailprocess_'.$type;
9843: } elsif ($item eq 'email') {
9844: %choices = &Apache::lonlocal::texthash (
9845: any => 'Any e-mail',
9846: inst => 'Institutional only',
9847: noninst => 'Non-institutional only',
9848: custom => 'Custom restrictions',
9849: );
9850: @options = ('any','inst','noninst');
9851: my $showcustom;
9852: if (ref($emailrules) eq 'HASH') {
9853: if (keys(%{$emailrules}) > 0) {
9854: push(@options,'custom');
9855: $showcustom = 'cancreate_emailrule';
9856: if (ref($settings) eq 'HASH') {
9857: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9858: foreach my $rule (@{$settings->{'email_rule'}}) {
9859: if (exists($emailrules->{$rule})) {
9860: $hascustom ++;
9861: }
9862: }
9863: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9864: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9865: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9866: if (exists($emailrules->{$rule})) {
9867: $hascustom ++;
9868: }
9869: }
9870: }
9871: }
9872: }
9873: }
9874: }
9875: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9876: "'cancreate_emaildomain','$type'".');"';
9877: $hashref = $emailoptions;
9878: $defoption = 'any';
9879: $name = 'cancreate_emailoptions_'.$type;
9880: } elsif ($item eq 'username') {
9881: %choices = &Apache::lonlocal::texthash (
9882: all => 'Same as e-mail',
9883: first => 'Omit @domain',
9884: free => 'Free to choose',
9885: );
9886: @options = ('all','first','free');
9887: $hashref = $emailverified;
9888: $defoption = 'all';
9889: $name = 'cancreate_usernameoptions_'.$type;
9890: }
9891: foreach my $option (@options) {
9892: my $checked;
9893: if (ref($hashref) eq 'HASH') {
9894: if ($type eq '') {
9895: if (!exists($hashref->{'default'})) {
9896: if ($option eq $defoption) {
9897: $checked = ' checked="checked"';
9898: }
9899: } else {
9900: if ($hashref->{'default'} eq $option) {
9901: $checked = ' checked="checked"';
9902: }
1.303 raeburn 9903: }
9904: } else {
1.305 raeburn 9905: if (!exists($hashref->{$type})) {
9906: if ($option eq $defoption) {
9907: $checked = ' checked="checked"';
9908: }
9909: } else {
9910: if ($hashref->{$type} eq $option) {
9911: $checked = ' checked="checked"';
9912: }
1.303 raeburn 9913: }
9914: }
1.305 raeburn 9915: } elsif (($item eq 'email') && ($hascustom)) {
9916: if ($option eq 'custom') {
9917: $checked = ' checked="checked"';
9918: }
9919: } elsif ($option eq $defoption) {
9920: $checked = ' checked="checked"';
9921: }
9922: $output .= '<span class="LC_nobreak"><label>'.
9923: '<input type="radio" name="'.$name.'"'.
9924: $checked.' value="'.$option.'"'.$onclick.' />'.
9925: $choices{$option}.'</label></span><br />';
9926: if ($item eq 'email') {
9927: if ($option eq 'custom') {
9928: my $id = 'cancreate_emailrule_'.$type;
9929: my $display = 'none';
9930: if ($checked) {
9931: $display = 'inline';
1.303 raeburn 9932: }
1.305 raeburn 9933: my $numinrow = 2;
9934: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9935: '<legend>'.&mt('Disallow').'</legend><table>'.
9936: &user_formats_row('email',$settings,$emailrules,
9937: $emailruleorder,$numinrow,'',$type);
9938: '</table></fieldset>';
9939: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9940: my %text = &Apache::lonlocal::texthash (
9941: inst => 'must end:',
9942: noninst => 'cannot end:',
9943: );
9944: my $value;
9945: if (ref($emaildomain) eq 'HASH') {
9946: if (ref($emaildomain->{$type}) eq 'HASH') {
9947: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9948: }
9949: }
1.305 raeburn 9950: if ($value eq '') {
9951: $value = '@'.$intdom;
9952: }
9953: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9954: my $display = 'none';
9955: if ($checked) {
9956: $display = 'inline';
9957: }
9958: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9959: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9960: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9961: '</div>';
1.303 raeburn 9962: }
9963: }
9964: }
1.305 raeburn 9965: $output .= '</td>'."\n";
1.303 raeburn 9966: }
1.305 raeburn 9967: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9968: return $output;
9969: }
9970:
1.165 raeburn 9971: sub captcha_choice {
1.305 raeburn 9972: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9973: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9974: $vertext,$currver);
1.165 raeburn 9975: my %lt = &captcha_phrases();
9976: $keyentry = 'hidden';
1.354 raeburn 9977: my $colspan=2;
1.165 raeburn 9978: if ($context eq 'cancreate') {
1.224 raeburn 9979: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9980: } elsif ($context eq 'login') {
9981: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9982: } elsif ($context eq 'passwords') {
9983: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9984: $colspan=1;
1.165 raeburn 9985: }
9986: if (ref($settings) eq 'HASH') {
9987: if ($settings->{'captcha'}) {
9988: $checked{$settings->{'captcha'}} = ' checked="checked"';
9989: } else {
9990: $checked{'original'} = ' checked="checked"';
9991: }
9992: if ($settings->{'captcha'} eq 'recaptcha') {
9993: $pubtext = $lt{'pub'};
9994: $privtext = $lt{'priv'};
9995: $keyentry = 'text';
1.269 raeburn 9996: $vertext = $lt{'ver'};
9997: $currver = $settings->{'recaptchaversion'};
9998: if ($currver ne '2') {
9999: $currver = 1;
10000: }
1.165 raeburn 10001: }
10002: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10003: $currpub = $settings->{'recaptchakeys'}{'public'};
10004: $currpriv = $settings->{'recaptchakeys'}{'private'};
10005: }
10006: } else {
10007: $checked{'original'} = ' checked="checked"';
10008: }
1.305 raeburn 10009: my $css_class;
10010: if ($itemcount%2) {
10011: $css_class = 'LC_odd_row';
10012: }
10013: if ($customcss) {
10014: $css_class .= " $customcss";
10015: }
10016: $css_class =~ s/^\s+//;
10017: if ($css_class) {
10018: $css_class = ' class="'.$css_class.'"';
10019: }
10020: if ($rowstyle) {
10021: $css_class .= ' style="'.$rowstyle.'"';
10022: }
1.169 raeburn 10023: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10024: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10025: '<table><tr><td>'."\n";
10026: foreach my $option ('original','recaptcha','notused') {
10027: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10028: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10029: $lt{$option}.'</label></span>';
10030: unless ($option eq 'notused') {
10031: $output .= (' 'x2)."\n";
10032: }
10033: }
10034: #
10035: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10036: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10037: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10038: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10039: #
1.165 raeburn 10040: $output .= '</td></tr>'."\n".
1.305 raeburn 10041: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10042: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10043: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10044: $currpub.'" size="40" /></span><br />'."\n".
10045: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10046: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10047: $currpriv.'" size="40" /></span><br />'.
10048: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10049: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10050: $currver.'" size="3" /></span><br />'.
10051: '</td></tr></table>'."\n".
1.165 raeburn 10052: '</td></tr>';
10053: return $output;
10054: }
10055:
1.32 raeburn 10056: sub user_formats_row {
1.305 raeburn 10057: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10058: my $output;
10059: my %text = (
10060: 'username' => 'new usernames',
10061: 'id' => 'IDs',
10062: );
1.409 raeburn 10063: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10064: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10065: $output = '<tr '.$css_class.'>'.
10066: '<td><span class="LC_nobreak">'.
10067: &mt("Format rules to check for $text{$type}: ").
10068: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10069: }
1.27 raeburn 10070: my $rem;
10071: if (ref($ruleorder) eq 'ARRAY') {
10072: for (my $i=0; $i<@{$ruleorder}; $i++) {
10073: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10074: my $rem = $i%($numinrow);
10075: if ($rem == 0) {
10076: if ($i > 0) {
10077: $output .= '</tr>';
10078: }
10079: $output .= '<tr>';
10080: }
10081: my $check = ' ';
1.39 raeburn 10082: if (ref($settings) eq 'HASH') {
10083: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10084: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10085: $check = ' checked="checked" ';
10086: }
1.305 raeburn 10087: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10088: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10089: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10090: $check = ' checked="checked" ';
10091: }
10092: }
1.27 raeburn 10093: }
10094: }
1.305 raeburn 10095: my $name = $type.'_rule';
10096: if ($type eq 'email') {
10097: $name .= '_'.$status;
10098: }
1.27 raeburn 10099: $output .= '<td class="LC_left_item">'.
10100: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10101: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10102: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10103: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10104: }
10105: }
10106: $rem = @{$ruleorder}%($numinrow);
10107: }
1.305 raeburn 10108: my $colsleft;
10109: if ($rem) {
10110: $colsleft = $numinrow - $rem;
10111: }
1.27 raeburn 10112: if ($colsleft > 1 ) {
10113: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10114: ' </td>';
10115: } elsif ($colsleft == 1) {
10116: $output .= '<td class="LC_left_item"> </td>';
10117: }
1.409 raeburn 10118: $output .= '</tr>';
10119: unless (($type eq 'email') || ($type eq 'unamemap')) {
10120: $output .= '</table></td></tr>';
1.305 raeburn 10121: }
1.27 raeburn 10122: return $output;
10123: }
10124:
1.34 raeburn 10125: sub usercreation_types {
10126: my %lt = &Apache::lonlocal::texthash (
10127: author => 'When adding a co-author',
10128: course => 'When adding a user to a course',
1.100 raeburn 10129: requestcrs => 'When requesting a course',
1.34 raeburn 10130: any => 'Any',
10131: official => 'Institutional only ',
10132: unofficial => 'Non-institutional only',
10133: none => 'None',
10134: );
10135: return %lt;
1.48 raeburn 10136: }
1.34 raeburn 10137:
1.224 raeburn 10138: sub selfcreation_types {
10139: my %lt = &Apache::lonlocal::texthash (
10140: selfcreate => 'User creates own account',
10141: any => 'Any',
10142: official => 'Institutional only ',
10143: unofficial => 'Non-institutional only',
10144: email => 'E-mail address',
10145: login => 'Institutional Login',
10146: sso => 'SSO',
10147: );
10148: }
10149:
1.28 raeburn 10150: sub authtype_names {
10151: my %lt = &Apache::lonlocal::texthash(
10152: int => 'Internal',
10153: krb4 => 'Kerberos 4',
10154: krb5 => 'Kerberos 5',
10155: loc => 'Local',
1.325 raeburn 10156: lti => 'LTI',
1.28 raeburn 10157: );
10158: return %lt;
10159: }
10160:
10161: sub context_names {
10162: my %context_title = &Apache::lonlocal::texthash(
10163: author => 'Creating users when an Author',
10164: course => 'Creating users when in a course',
10165: domain => 'Creating users when a Domain Coordinator',
10166: );
10167: return %context_title;
10168: }
10169:
1.33 raeburn 10170: sub print_usermodification {
10171: my ($position,$dom,$settings,$rowtotal) = @_;
10172: my $numinrow = 4;
10173: my ($context,$datatable,$rowcount);
10174: if ($position eq 'top') {
10175: $rowcount = 0;
10176: $context = 'author';
10177: foreach my $role ('ca','aa') {
10178: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10179: $numinrow,$rowcount);
10180: $$rowtotal ++;
10181: $rowcount ++;
10182: }
1.230 raeburn 10183: } elsif ($position eq 'bottom') {
1.33 raeburn 10184: $context = 'course';
10185: $rowcount = 0;
10186: foreach my $role ('st','ep','ta','in','cr') {
10187: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10188: $numinrow,$rowcount);
10189: $$rowtotal ++;
10190: $rowcount ++;
10191: }
10192: }
10193: return $datatable;
10194: }
10195:
1.43 raeburn 10196: sub print_defaults {
1.236 raeburn 10197: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10198: my $rownum = 0;
1.294 raeburn 10199: my ($datatable,$css_class,$titles);
10200: unless ($position eq 'bottom') {
10201: $titles = &defaults_titles($dom);
10202: }
1.236 raeburn 10203: if ($position eq 'top') {
10204: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10205: 'datelocale_def','portal_def');
10206: my %defaults;
10207: if (ref($settings) eq 'HASH') {
10208: %defaults = %{$settings};
1.43 raeburn 10209: } else {
1.236 raeburn 10210: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10211: foreach my $item (@items) {
10212: $defaults{$item} = $domdefaults{$item};
10213: }
1.43 raeburn 10214: }
1.236 raeburn 10215: foreach my $item (@items) {
10216: if ($rownum%2) {
10217: $css_class = '';
10218: } else {
10219: $css_class = ' class="LC_odd_row" ';
10220: }
10221: $datatable .= '<tr'.$css_class.'>'.
10222: '<td><span class="LC_nobreak">'.$titles->{$item}.
10223: '</span></td><td class="LC_right_item" colspan="3">';
10224: if ($item eq 'auth_def') {
1.325 raeburn 10225: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10226: my %shortauth = (
10227: internal => 'int',
10228: krb4 => 'krb4',
10229: krb5 => 'krb5',
1.325 raeburn 10230: localauth => 'loc',
10231: lti => 'lti',
1.236 raeburn 10232: );
10233: my %authnames = &authtype_names();
10234: foreach my $auth (@authtypes) {
10235: my $checked = ' ';
10236: if ($defaults{$item} eq $auth) {
10237: $checked = ' checked="checked" ';
10238: }
10239: $datatable .= '<label><input type="radio" name="'.$item.
10240: '" value="'.$auth.'"'.$checked.'/>'.
10241: $authnames{$shortauth{$auth}}.'</label> ';
10242: }
10243: } elsif ($item eq 'timezone_def') {
10244: my $includeempty = 1;
10245: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10246: } elsif ($item eq 'datelocale_def') {
10247: my $includeempty = 1;
10248: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10249: } elsif ($item eq 'lang_def') {
1.263 raeburn 10250: my $includeempty = 1;
10251: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10252: } elsif ($item eq 'portal_def') {
10253: $datatable .= '<input type="text" name="'.$item.'" value="'.
10254: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10255: my $portalsty = 'none';
10256: if ($defaults{$item}) {
10257: $portalsty = 'block';
10258: }
10259: foreach my $field ('email','web') {
10260: my $checkedoff = ' checked="checked"';
10261: my $checkedon;
10262: if ($defaults{$item.'_'.$field}) {
10263: $checkedon = $checkedoff;
10264: $checkedoff = '';
10265: }
10266: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10267: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10268: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10269: (' 'x2).
10270: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10271: '</div>';
10272: }
1.236 raeburn 10273: } else {
1.414 raeburn 10274: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10275: }
1.236 raeburn 10276: $datatable .= '</td></tr>';
10277: $rownum ++;
10278: }
1.409 raeburn 10279: } elsif ($position eq 'middle') {
1.294 raeburn 10280: my %defaults;
10281: if (ref($settings) eq 'HASH') {
1.354 raeburn 10282: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10283: my $maxnum = @{$settings->{'inststatusorder'}};
10284: for (my $i=0; $i<$maxnum; $i++) {
10285: $css_class = $rownum%2?' class="LC_odd_row"':'';
10286: my $item = $settings->{'inststatusorder'}->[$i];
10287: my $title = $settings->{'inststatustypes'}->{$item};
10288: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10289: $datatable .= '<tr'.$css_class.'>'.
10290: '<td><span class="LC_nobreak">'.
10291: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10292: for (my $k=0; $k<=$maxnum; $k++) {
10293: my $vpos = $k+1;
10294: my $selstr;
10295: if ($k == $i) {
10296: $selstr = ' selected="selected" ';
10297: }
10298: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10299: }
10300: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10301: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10302: &mt('delete').'</span></td>'.
1.380 raeburn 10303: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10304: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10305: '</span></td></tr>';
10306: }
10307: $css_class = $rownum%2?' class="LC_odd_row"':'';
10308: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10309: $datatable .= '<tr '.$css_class.'>'.
10310: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10311: for (my $k=0; $k<=$maxnum; $k++) {
10312: my $vpos = $k+1;
10313: my $selstr;
10314: if ($k == $maxnum) {
10315: $selstr = ' selected="selected" ';
10316: }
10317: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10318: }
10319: $datatable .= '</select> '.&mt('Internal ID:').
10320: '<input type="text" size="10" name="addinststatus" value="" />'.
10321: ' '.&mt('(new)').
10322: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10323: &mt('Name displayed').':'.
1.354 raeburn 10324: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10325: '</tr>'."\n";
10326: $rownum ++;
1.294 raeburn 10327: }
1.354 raeburn 10328: }
1.409 raeburn 10329: } else {
10330: my ($unamemaprules,$ruleorder) =
10331: &Apache::lonnet::inst_userrules($dom,'unamemap');
10332: $css_class = $rownum%2?' class="LC_odd_row"':'';
10333: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10334: my $numinrow = 2;
10335: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10336: &user_formats_row('unamemap',$settings,$unamemaprules,
10337: $ruleorder,$numinrow).
10338: '</table></td></tr>';
10339: }
10340: if ($datatable eq '') {
10341: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10342: &mt('No rules set for domain in customized localenroll.pm').
10343: '</td></tr>';
10344: }
1.354 raeburn 10345: }
10346: $$rowtotal += $rownum;
1.43 raeburn 10347: return $datatable;
10348: }
10349:
1.168 raeburn 10350: sub get_languages_hash {
10351: my %langchoices;
10352: foreach my $id (&Apache::loncommon::languageids()) {
10353: my $code = &Apache::loncommon::supportedlanguagecode($id);
10354: if ($code ne '') {
10355: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10356: }
10357: }
10358: return %langchoices;
10359: }
10360:
1.43 raeburn 10361: sub defaults_titles {
1.141 raeburn 10362: my ($dom) = @_;
1.43 raeburn 10363: my %titles = &Apache::lonlocal::texthash (
10364: 'auth_def' => 'Default authentication type',
10365: 'auth_arg_def' => 'Default authentication argument',
10366: 'lang_def' => 'Default language',
1.54 raeburn 10367: 'timezone_def' => 'Default timezone',
1.68 raeburn 10368: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10369: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10370: 'email' => 'Email links use portal URL',
10371: 'web' => 'Public web links use portal URL',
1.294 raeburn 10372: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10373: 'intauth_check' => 'Check bcrypt cost if authenticated',
10374: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10375: );
1.141 raeburn 10376: if ($dom) {
10377: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10378: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10379: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10380: $protocol = 'http' if ($protocol ne 'https');
10381: if ($uint_dom) {
10382: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10383: $uint_dom);
10384: }
10385: }
1.43 raeburn 10386: return (\%titles);
10387: }
10388:
1.346 raeburn 10389: sub print_scantron {
10390: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10391: if ($position eq 'top') {
10392: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10393: } else {
10394: return &print_scantronconfig($dom,$settings,\$rowtotal);
10395: }
10396: }
10397:
10398: sub scantron_javascript {
10399: return <<"ENDSCRIPT";
10400:
10401: <script type="text/javascript">
10402: // <![CDATA[
10403:
10404: function toggleScantron(form) {
1.347 raeburn 10405: var csvfieldset = new Array();
1.346 raeburn 10406: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10407: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10408: }
10409: if (document.getElementById('scantroncsv_options')) {
10410: csvfieldset.push(document.getElementById('scantroncsv_options'));
10411: }
10412: if (csvfieldset.length) {
1.346 raeburn 10413: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10414: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10415: if (scantroncsv.checked) {
1.347 raeburn 10416: for (var i=0; i<csvfieldset.length; i++) {
10417: csvfieldset[i].style.display = 'block';
10418: }
1.346 raeburn 10419: } else {
1.347 raeburn 10420: for (var i=0; i<csvfieldset.length; i++) {
10421: csvfieldset[i].style.display = 'none';
10422: }
1.346 raeburn 10423: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10424: if (csvselects.length) {
10425: for (var j=0; j<csvselects.length; j++) {
10426: csvselects[j].selectedIndex = 0;
10427: }
10428: }
10429: }
10430: }
10431: }
10432: return;
10433: }
10434: // ]]>
10435: </script>
10436:
10437: ENDSCRIPT
10438:
10439: }
10440:
1.46 raeburn 10441: sub print_scantronformat {
10442: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10443: my $itemcount = 1;
1.60 raeburn 10444: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10445: %confhash);
1.46 raeburn 10446: my $switchserver = &check_switchserver($dom,$confname);
10447: my %lt = &Apache::lonlocal::texthash (
1.95 www 10448: default => 'Default bubblesheet format file error',
10449: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10450: );
10451: my %scantronfiles = (
10452: default => 'default.tab',
10453: custom => 'custom.tab',
10454: );
10455: foreach my $key (keys(%scantronfiles)) {
10456: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10457: .$scantronfiles{$key};
10458: }
10459: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10460: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10461: if (!$switchserver) {
10462: my $servadm = $r->dir_config('lonAdmEMail');
10463: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10464: if ($configuserok eq 'ok') {
10465: if ($author_ok eq 'ok') {
10466: my %legacyfile = (
1.346 raeburn 10467: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10468: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10469: );
10470: my %md5chk;
10471: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10472: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10473: chomp($md5chk{$type});
1.46 raeburn 10474: }
10475: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10476: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10477: ($scantronurls{$type},my $error) =
1.46 raeburn 10478: &legacy_scantronformat($r,$dom,$confname,
10479: $type,$legacyfile{$type},
10480: $scantronurls{$type},
10481: $scantronfiles{$type});
1.60 raeburn 10482: if ($error ne '') {
10483: $error{$type} = $error;
10484: }
10485: }
10486: if (keys(%error) == 0) {
10487: $is_custom = 1;
1.346 raeburn 10488: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10489: $scantronurls{'custom'};
1.346 raeburn 10490: my $putresult =
1.60 raeburn 10491: &Apache::lonnet::put_dom('configuration',
10492: \%confhash,$dom);
10493: if ($putresult ne 'ok') {
1.346 raeburn 10494: $error{'custom'} =
1.60 raeburn 10495: '<span class="LC_error">'.
10496: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10497: }
1.46 raeburn 10498: }
10499: } else {
1.60 raeburn 10500: ($scantronurls{'default'},my $error) =
1.46 raeburn 10501: &legacy_scantronformat($r,$dom,$confname,
10502: 'default',$legacyfile{'default'},
10503: $scantronurls{'default'},
10504: $scantronfiles{'default'});
1.60 raeburn 10505: if ($error eq '') {
10506: $confhash{'scantron'}{'scantronformat'} = '';
10507: my $putresult =
10508: &Apache::lonnet::put_dom('configuration',
10509: \%confhash,$dom);
10510: if ($putresult ne 'ok') {
10511: $error{'default'} =
10512: '<span class="LC_error">'.
10513: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10514: }
10515: } else {
10516: $error{'default'} = $error;
10517: }
1.46 raeburn 10518: }
10519: }
10520: }
10521: } else {
1.95 www 10522: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10523: }
10524: }
10525: if (ref($settings) eq 'HASH') {
10526: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10527: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10528: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10529: $scantronurl = '';
10530: } else {
10531: $scantronurl = $settings->{'scantronformat'};
10532: }
10533: $is_custom = 1;
10534: } else {
10535: $scantronurl = $scantronurls{'default'};
10536: }
10537: } else {
1.60 raeburn 10538: if ($is_custom) {
10539: $scantronurl = $scantronurls{'custom'};
10540: } else {
10541: $scantronurl = $scantronurls{'default'};
10542: }
1.46 raeburn 10543: }
10544: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10545: $datatable .= '<tr'.$css_class.'>';
10546: if (!$is_custom) {
1.65 raeburn 10547: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10548: '<span class="LC_nobreak">';
1.46 raeburn 10549: if ($scantronurl) {
1.199 raeburn 10550: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10551: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10552: } else {
10553: $datatable = &mt('File unavailable for display');
10554: }
1.65 raeburn 10555: $datatable .= '</span></td>';
1.60 raeburn 10556: if (keys(%error) == 0) {
1.306 raeburn 10557: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10558: if (!$switchserver) {
10559: $datatable .= &mt('Upload:').'<br />';
10560: }
10561: } else {
10562: my $errorstr;
10563: foreach my $key (sort(keys(%error))) {
10564: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10565: }
10566: $datatable .= '<td>'.$errorstr;
10567: }
1.46 raeburn 10568: } else {
10569: if (keys(%error) > 0) {
10570: my $errorstr;
10571: foreach my $key (sort(keys(%error))) {
10572: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10573: }
1.60 raeburn 10574: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10575: } elsif ($scantronurl) {
1.199 raeburn 10576: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10577: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10578: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10579: $link.
10580: '<label><input type="checkbox" name="scantronformat_del"'.
10581: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10582: '<td><span class="LC_nobreak"> '.
10583: &mt('Replace:').'</span><br />';
1.46 raeburn 10584: }
10585: }
10586: if (keys(%error) == 0) {
10587: if ($switchserver) {
10588: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10589: } else {
1.65 raeburn 10590: $datatable .='<span class="LC_nobreak"> '.
10591: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10592: }
10593: }
10594: $datatable .= '</td></tr>';
10595: $$rowtotal ++;
10596: return $datatable;
10597: }
10598:
10599: sub legacy_scantronformat {
10600: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10601: my ($url,$error);
10602: my @statinfo = &Apache::lonnet::stat_file($newurl);
10603: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 ! raeburn 10604: my $modified = [];
1.46 raeburn 10605: (my $result,$url) =
1.421 ! raeburn 10606: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
! 10607: 'scantron','','',$newfile,$modified);
! 10608: if ($result eq 'ok') {
! 10609: &update_modify_urls($r,$modified);
! 10610: } else {
1.130 raeburn 10611: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10612: }
10613: }
10614: return ($url,$error);
10615: }
1.43 raeburn 10616:
1.346 raeburn 10617: sub print_scantronconfig {
10618: my ($dom,$settings,$rowtotal) = @_;
10619: my $itemcount = 2;
10620: my $is_checked = ' checked="checked"';
1.347 raeburn 10621: my %optionson = (
10622: hdr => ' checked="checked"',
10623: pad => ' checked="checked"',
10624: rem => ' checked="checked"',
10625: );
10626: my %optionsoff = (
10627: hdr => '',
10628: pad => '',
10629: rem => '',
10630: );
1.346 raeburn 10631: my $currcsvsty = 'none';
1.347 raeburn 10632: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10633: my @fields = &scantroncsv_fields();
10634: my %titles = &scantronconfig_titles();
10635: if (ref($settings) eq 'HASH') {
10636: if (ref($settings->{config}) eq 'HASH') {
10637: if ($settings->{config}->{dat}) {
10638: $checked{'dat'} = $is_checked;
10639: }
10640: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10641: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10642: %csvfields = %{$settings->{config}->{csv}->{fields}};
10643: if (keys(%csvfields) > 0) {
10644: $checked{'csv'} = $is_checked;
10645: $currcsvsty = 'block';
10646: }
10647: }
10648: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10649: %csvoptions = %{$settings->{config}->{csv}->{options}};
10650: foreach my $option (keys(%optionson)) {
10651: unless ($csvoptions{$option}) {
10652: $optionsoff{$option} = $optionson{$option};
10653: $optionson{$option} = '';
10654: }
10655: }
1.346 raeburn 10656: }
10657: }
10658: } else {
10659: $checked{'dat'} = $is_checked;
10660: }
10661: } else {
10662: $checked{'dat'} = $is_checked;
10663: }
10664: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10665: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10666: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10667: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10668: foreach my $item ('dat','csv') {
10669: my $id;
10670: if ($item eq 'csv') {
10671: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10672: }
1.346 raeburn 10673: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10674: $titles{$item}.'</label>'.(' 'x3);
10675: if ($item eq 'csv') {
10676: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10677: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10678: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10679: foreach my $col (@fields) {
10680: my $selnone;
10681: if ($csvfields{$col} eq '') {
10682: $selnone = ' selected="selected"';
10683: }
10684: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10685: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10686: '<option value=""'.$selnone.'></option>';
10687: for (my $i=0; $i<20; $i++) {
10688: my $shown = $i+1;
10689: my $sel;
10690: unless ($selnone) {
10691: if (exists($csvfields{$col})) {
10692: if ($csvfields{$col} == $i) {
10693: $sel = ' selected="selected"';
10694: }
10695: }
10696: }
10697: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10698: }
10699: $datatable .= '</select></td></tr>';
10700: }
1.347 raeburn 10701: $datatable .= '</table></fieldset>'.
10702: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10703: '<legend>'.&mt('CSV Options').'</legend>';
10704: foreach my $option ('hdr','pad','rem') {
10705: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10706: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10707: &mt('Yes').'</label>'.(' 'x2)."\n".
10708: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10709: }
10710: $datatable .= '</fieldset>';
1.346 raeburn 10711: $itemcount ++;
10712: }
10713: }
10714: $datatable .= '</td></tr>';
10715: $$rowtotal ++;
10716: return $datatable;
10717: }
10718:
10719: sub scantronconfig_titles {
10720: return &Apache::lonlocal::texthash(
10721: dat => 'Standard format (.dat)',
10722: csv => 'Comma separated values (.csv)',
1.347 raeburn 10723: hdr => 'Remove first line in file (contains column titles)',
10724: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10725: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10726: CODE => 'CODE',
10727: ID => 'Student ID',
10728: PaperID => 'Paper ID',
10729: FirstName => 'First Name',
10730: LastName => 'Last Name',
10731: FirstQuestion => 'First Question Response',
10732: Section => 'Section',
10733: );
10734: }
10735:
10736: sub scantroncsv_fields {
10737: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10738: }
10739:
1.49 raeburn 10740: sub print_coursecategories {
1.57 raeburn 10741: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10742: my $datatable;
10743: if ($position eq 'top') {
1.238 raeburn 10744: my (%checked);
10745: my @catitems = ('unauth','auth');
10746: my @cattypes = ('std','domonly','codesrch','none');
10747: $checked{'unauth'} = 'std';
10748: $checked{'auth'} = 'std';
10749: if (ref($settings) eq 'HASH') {
10750: foreach my $type (@cattypes) {
10751: if ($type eq $settings->{'unauth'}) {
10752: $checked{'unauth'} = $type;
10753: }
10754: if ($type eq $settings->{'auth'}) {
10755: $checked{'auth'} = $type;
10756: }
10757: }
10758: }
10759: my %lt = &Apache::lonlocal::texthash (
10760: unauth => 'Catalog type for unauthenticated users',
10761: auth => 'Catalog type for authenticated users',
10762: none => 'No catalog',
10763: std => 'Standard catalog',
10764: domonly => 'Domain-only catalog',
10765: codesrch => "Code search form",
10766: );
10767: my $itemcount = 0;
10768: foreach my $item (@catitems) {
10769: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10770: $datatable .= '<tr '.$css_class.'>'.
10771: '<td>'.$lt{$item}.'</td>'.
10772: '<td class="LC_right_item"><span class="LC_nobreak">';
10773: foreach my $type (@cattypes) {
10774: my $ischecked;
10775: if ($checked{$item} eq $type) {
10776: $ischecked=' checked="checked"';
10777: }
10778: $datatable .= '<label>'.
10779: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10780: ' />'.$lt{$type}.'</label> ';
10781: }
1.327 raeburn 10782: $datatable .= '</span></td></tr>';
1.238 raeburn 10783: $itemcount ++;
10784: }
10785: $$rowtotal += $itemcount;
10786: } elsif ($position eq 'middle') {
1.57 raeburn 10787: my $toggle_cats_crs = ' ';
10788: my $toggle_cats_dom = ' checked="checked" ';
10789: my $can_cat_crs = ' ';
10790: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10791: my $toggle_catscomm_comm = ' ';
10792: my $toggle_catscomm_dom = ' checked="checked" ';
10793: my $can_catcomm_comm = ' ';
10794: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10795: my $toggle_catsplace_place = ' ';
10796: my $toggle_catsplace_dom = ' checked="checked" ';
10797: my $can_catplace_place = ' ';
10798: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10799:
1.57 raeburn 10800: if (ref($settings) eq 'HASH') {
10801: if ($settings->{'togglecats'} eq 'crs') {
10802: $toggle_cats_crs = $toggle_cats_dom;
10803: $toggle_cats_dom = ' ';
10804: }
10805: if ($settings->{'categorize'} eq 'crs') {
10806: $can_cat_crs = $can_cat_dom;
10807: $can_cat_dom = ' ';
10808: }
1.120 raeburn 10809: if ($settings->{'togglecatscomm'} eq 'comm') {
10810: $toggle_catscomm_comm = $toggle_catscomm_dom;
10811: $toggle_catscomm_dom = ' ';
10812: }
10813: if ($settings->{'categorizecomm'} eq 'comm') {
10814: $can_catcomm_comm = $can_catcomm_dom;
10815: $can_catcomm_dom = ' ';
10816: }
1.272 raeburn 10817: if ($settings->{'togglecatsplace'} eq 'place') {
10818: $toggle_catsplace_place = $toggle_catsplace_dom;
10819: $toggle_catsplace_dom = ' ';
10820: }
10821: if ($settings->{'categorizeplace'} eq 'place') {
10822: $can_catplace_place = $can_catplace_dom;
10823: $can_catplace_dom = ' ';
10824: }
1.57 raeburn 10825: }
10826: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10827: togglecats => 'Show/Hide a course in catalog',
10828: togglecatscomm => 'Show/Hide a community in catalog',
10829: togglecatsplace => 'Show/Hide a placement test in catalog',
10830: categorize => 'Assign a category to a course',
10831: categorizecomm => 'Assign a category to a community',
10832: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10833: );
10834: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10835: dom => 'Set in Domain',
10836: crs => 'Set in Course',
10837: comm => 'Set in Community',
10838: place => 'Set in Placement Test',
1.57 raeburn 10839: );
10840: $datatable = '<tr class="LC_odd_row">'.
10841: '<td>'.$title{'togglecats'}.'</td>'.
10842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10843: '<input type="radio" name="togglecats"'.
10844: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10845: '<label><input type="radio" name="togglecats"'.
10846: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10847: '</tr><tr>'.
10848: '<td>'.$title{'categorize'}.'</td>'.
10849: '<td class="LC_right_item"><span class="LC_nobreak">'.
10850: '<label><input type="radio" name="categorize"'.
10851: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10852: '<label><input type="radio" name="categorize"'.
10853: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10854: '</tr><tr class="LC_odd_row">'.
10855: '<td>'.$title{'togglecatscomm'}.'</td>'.
10856: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10857: '<input type="radio" name="togglecatscomm"'.
10858: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10859: '<label><input type="radio" name="togglecatscomm"'.
10860: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10861: '</tr><tr>'.
10862: '<td>'.$title{'categorizecomm'}.'</td>'.
10863: '<td class="LC_right_item"><span class="LC_nobreak">'.
10864: '<label><input type="radio" name="categorizecomm"'.
10865: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10866: '<label><input type="radio" name="categorizecomm"'.
10867: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10868: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10869: '<td>'.$title{'togglecatsplace'}.'</td>'.
10870: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10871: '<input type="radio" name="togglecatsplace"'.
10872: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10873: '<label><input type="radio" name="togglecatscomm"'.
10874: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10875: '</tr><tr>'.
10876: '<td>'.$title{'categorizeplace'}.'</td>'.
10877: '<td class="LC_right_item"><span class="LC_nobreak">'.
10878: '<label><input type="radio" name="categorizeplace"'.
10879: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10880: '<label><input type="radio" name="categorizeplace"'.
10881: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10882: '</tr>';
1.272 raeburn 10883: $$rowtotal += 6;
1.57 raeburn 10884: } else {
10885: my $css_class;
10886: my $itemcount = 1;
10887: my $cathash;
10888: if (ref($settings) eq 'HASH') {
10889: $cathash = $settings->{'cats'};
10890: }
10891: if (ref($cathash) eq 'HASH') {
10892: my (@cats,@trails,%allitems,%idx,@jsarray);
10893: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10894: \%allitems,\%idx,\@jsarray);
10895: my $maxdepth = scalar(@cats);
10896: my $colattrib = '';
10897: if ($maxdepth > 2) {
10898: $colattrib = ' colspan="2" ';
10899: }
10900: my @path;
10901: if (@cats > 0) {
10902: if (ref($cats[0]) eq 'ARRAY') {
10903: my $numtop = @{$cats[0]};
10904: my $maxnum = $numtop;
1.120 raeburn 10905: my %default_names = (
10906: instcode => &mt('Official courses'),
10907: communities => &mt('Communities'),
1.272 raeburn 10908: placement => &mt('Placement Tests'),
1.120 raeburn 10909: );
10910:
10911: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10912: ($cathash->{'instcode::0'} eq '') ||
10913: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10914: ($cathash->{'communities::0'} eq '') ||
10915: (!grep(/^placement$/,@{$cats[0]})) ||
10916: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10917: $maxnum ++;
10918: }
10919: my $lastidx;
10920: for (my $i=0; $i<$numtop; $i++) {
10921: my $parent = $cats[0][$i];
10922: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10923: my $item = &escape($parent).'::0';
10924: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10925: $lastidx = $idx{$item};
10926: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10927: .'<select name="'.$item.'"'.$chgstr.'>';
10928: for (my $k=0; $k<=$maxnum; $k++) {
10929: my $vpos = $k+1;
10930: my $selstr;
10931: if ($k == $i) {
10932: $selstr = ' selected="selected" ';
10933: }
10934: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10935: }
1.214 raeburn 10936: $datatable .= '</select></span></td><td>';
1.272 raeburn 10937: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10938: $datatable .= '<span class="LC_nobreak">'
10939: .$default_names{$parent}.'</span>';
10940: if ($parent eq 'instcode') {
10941: $datatable .= '<br /><span class="LC_nobreak">('
10942: .&mt('with institutional codes')
10943: .')</span></td><td'.$colattrib.'>';
10944: } else {
10945: $datatable .= '<table><tr><td>';
10946: }
10947: $datatable .= '<span class="LC_nobreak">'
10948: .'<label><input type="radio" name="'
10949: .$parent.'" value="1" checked="checked" />'
10950: .&mt('Display').'</label>';
10951: if ($parent eq 'instcode') {
10952: $datatable .= ' ';
10953: } else {
10954: $datatable .= '</span></td></tr><tr><td>'
10955: .'<span class="LC_nobreak">';
10956: }
10957: $datatable .= '<label><input type="radio" name="'
10958: .$parent.'" value="0" />'
10959: .&mt('Do not display').'</label></span>';
1.272 raeburn 10960: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10961: $datatable .= '</td></tr></table>';
10962: }
10963: $datatable .= '</td>';
1.57 raeburn 10964: } else {
10965: $datatable .= $parent
1.214 raeburn 10966: .' <span class="LC_nobreak"><label>'
10967: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10968: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10969: }
10970: my $depth = 1;
10971: push(@path,$parent);
10972: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10973: pop(@path);
10974: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10975: $itemcount ++;
10976: }
1.48 raeburn 10977: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10978: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10979: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10980: for (my $k=0; $k<=$maxnum; $k++) {
10981: my $vpos = $k+1;
10982: my $selstr;
1.57 raeburn 10983: if ($k == $numtop) {
1.48 raeburn 10984: $selstr = ' selected="selected" ';
10985: }
10986: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10987: }
1.59 bisitz 10988: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10989: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10990: .'</tr>'."\n";
1.48 raeburn 10991: $itemcount ++;
1.272 raeburn 10992: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10993: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10994: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10995: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10996: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10997: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10998: for (my $k=0; $k<=$maxnum; $k++) {
10999: my $vpos = $k+1;
11000: my $selstr;
11001: if ($k == $maxnum) {
11002: $selstr = ' selected="selected" ';
11003: }
11004: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11005: }
1.120 raeburn 11006: $datatable .= '</select></span></td>'.
11007: '<td><span class="LC_nobreak">'.
11008: $default_names{$default}.'</span>';
11009: if ($default eq 'instcode') {
11010: $datatable .= '<br /><span class="LC_nobreak">('
11011: .&mt('with institutional codes').')</span>';
11012: }
11013: $datatable .= '</td>'
11014: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11015: .&mt('Display').'</label> '
11016: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11017: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11018: }
11019: }
11020: }
1.57 raeburn 11021: } else {
11022: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11023: }
11024: } else {
1.327 raeburn 11025: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11026: .&initialize_categories($itemcount);
1.48 raeburn 11027: }
1.57 raeburn 11028: $$rowtotal += $itemcount;
1.48 raeburn 11029: }
11030: return $datatable;
11031: }
11032:
1.69 raeburn 11033: sub print_serverstatuses {
11034: my ($dom,$settings,$rowtotal) = @_;
11035: my $datatable;
11036: my @pages = &serverstatus_pages();
11037: my (%namedaccess,%machineaccess);
11038: foreach my $type (@pages) {
11039: $namedaccess{$type} = '';
11040: $machineaccess{$type}= '';
11041: }
11042: if (ref($settings) eq 'HASH') {
11043: foreach my $type (@pages) {
11044: if (exists($settings->{$type})) {
11045: if (ref($settings->{$type}) eq 'HASH') {
11046: foreach my $key (keys(%{$settings->{$type}})) {
11047: if ($key eq 'namedusers') {
11048: $namedaccess{$type} = $settings->{$type}->{$key};
11049: } elsif ($key eq 'machines') {
11050: $machineaccess{$type} = $settings->{$type}->{$key};
11051: }
11052: }
11053: }
11054: }
11055: }
11056: }
1.81 raeburn 11057: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11058: my $rownum = 0;
11059: my $css_class;
11060: foreach my $type (@pages) {
11061: $rownum ++;
11062: $css_class = $rownum%2?' class="LC_odd_row"':'';
11063: $datatable .= '<tr'.$css_class.'>'.
11064: '<td><span class="LC_nobreak">'.
11065: $titles->{$type}.'</span></td>'.
11066: '<td class="LC_left_item">'.
11067: '<input type="text" name="'.$type.'_namedusers" '.
11068: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11069: '<td class="LC_right_item">'.
11070: '<span class="LC_nobreak">'.
11071: '<input type="text" name="'.$type.'_machines" '.
11072: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11073: '</span></td></tr>'."\n";
1.69 raeburn 11074: }
11075: $$rowtotal += $rownum;
11076: return $datatable;
11077: }
11078:
11079: sub serverstatus_pages {
11080: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11081: 'checksums','clusterstatus','certstatus','metadata_keywords',
11082: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11083: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11084: }
11085:
1.236 raeburn 11086: sub defaults_javascript {
11087: my ($settings) = @_;
1.354 raeburn 11088: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11089: my $portal_js = <<"ENDPORTAL";
11090:
11091: function portalExtras(caller) {
11092: var x = caller.value;
11093: var y = new Array('email','web');
11094: for (var i=0; i<y.length; i++) {
11095: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11096: var z = document.getElementById('portal_def_'+y[i]+'_div');
11097: if (x.length > 0) {
11098: z.style.display = 'block';
11099: } else {
11100: z.style.display = 'none';
11101: }
11102: }
11103: }
11104: }
11105: ENDPORTAL
1.236 raeburn 11106: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11107: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11108: if ($maxnum eq '') {
11109: $maxnum = 0;
11110: }
11111: $maxnum ++;
1.249 raeburn 11112: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11113: return <<"ENDSCRIPT";
11114: <script type="text/javascript">
11115: // <![CDATA[
11116: function reorderTypes(form,caller) {
11117: var changedVal;
11118: $jstext
11119: var newpos = 'addinststatus_pos';
11120: var current = new Array;
11121: var maxh = $maxnum;
11122: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11123: var oldVal;
11124: if (caller == newpos) {
11125: changedVal = newitemVal;
11126: } else {
11127: var curritem = 'inststatus_pos_'+caller;
11128: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11129: current[newitemVal] = newpos;
11130: }
11131: for (var i=0; i<inststatuses.length; i++) {
11132: if (inststatuses[i] != caller) {
11133: var elementName = 'inststatus_pos_'+inststatuses[i];
11134: if (form.elements[elementName]) {
11135: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11136: current[currVal] = elementName;
11137: }
11138: }
11139: }
11140: for (var j=0; j<maxh; j++) {
11141: if (current[j] == undefined) {
11142: oldVal = j;
11143: }
11144: }
11145: if (oldVal < changedVal) {
11146: for (var k=oldVal+1; k<=changedVal ; k++) {
11147: var elementName = current[k];
11148: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11149: }
11150: } else {
11151: for (var k=changedVal; k<oldVal; k++) {
11152: var elementName = current[k];
11153: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11154: }
11155: }
11156: return;
11157: }
11158:
1.414 raeburn 11159: $portal_js
11160:
11161: // ]]>
11162: </script>
11163:
11164: ENDSCRIPT
11165: } else {
11166: return <<"ENDSCRIPT";
11167: <script type="text/javascript">
11168: // <![CDATA[
11169: $portal_js
1.236 raeburn 11170: // ]]>
11171: </script>
11172:
11173: ENDSCRIPT
11174: }
1.354 raeburn 11175: return;
11176: }
11177:
11178: sub passwords_javascript {
1.405 raeburn 11179: my ($prefix) = @_;
11180: my %intalert;
11181: if ($prefix eq 'passwords') {
11182: %intalert = &Apache::lonlocal::texthash (
11183: 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.',
11184: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11185: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11186: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11187: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11188: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11189: );
1.421 ! raeburn 11190: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11191: %intalert = &Apache::lonlocal::texthash (
11192: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11193: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11194: );
11195: }
1.365 raeburn 11196: &js_escape(\%intalert);
11197: my $defmin = $Apache::lonnet::passwdmin;
1.405 raeburn 11198: my $intauthjs;
11199: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11200:
11201: function warnIntAuth(field) {
11202: if (field.name == 'intauth_check') {
11203: if (field.value == '2') {
1.365 raeburn 11204: alert('$intalert{authcheck}');
1.354 raeburn 11205: }
11206: }
11207: if (field.name == 'intauth_cost') {
11208: field.value.replace(/\s/g,'');
11209: if (field.value != '') {
11210: var regexdigit=/^\\d+\$/;
11211: if (!regexdigit.test(field.value)) {
1.365 raeburn 11212: alert('$intalert{authcost}');
11213: }
11214: }
11215: }
11216: return;
11217: }
11218:
1.405 raeburn 11219: ENDSCRIPT
11220:
11221: }
11222:
11223: $intauthjs .= <<"ENDSCRIPT";
11224:
11225: function warnInt$prefix(field) {
1.365 raeburn 11226: field.value.replace(/^\s+/,'');
11227: field.value.replace(/\s+\$/,'');
11228: var regexdigit=/^\\d+\$/;
1.408 raeburn 11229: if (field.name == '${prefix}_min') {
1.365 raeburn 11230: if (field.value == '') {
11231: alert('$intalert{passmin}');
11232: field.value = '$defmin';
11233: } else {
11234: if (!regexdigit.test(field.value)) {
11235: alert('$intalert{passmin}');
11236: field.value = '$defmin';
11237: }
1.366 raeburn 11238: var minval = parseInt(field.value,10);
1.365 raeburn 11239: if (minval < $defmin) {
11240: alert('$intalert{passmin}');
11241: field.value = '$defmin';
11242: }
11243: }
11244: } else {
11245: if (field.value == '0') {
11246: field.value = '';
11247: }
11248: if (field.value != '') {
1.408 raeburn 11249: if (field.name == '${prefix}_expire') {
1.365 raeburn 11250: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11251: if (!regexpposnum.test(field.value)) {
11252: alert('$intalert{passexp}');
11253: field.value = '';
11254: } else {
11255: var expval = parseFloat(field.value);
11256: if (expval == 0) {
11257: alert('$intalert{passexp}');
11258: field.value = '';
11259: }
11260: }
11261: } else {
11262: if (!regexdigit.test(field.value)) {
1.408 raeburn 11263: if (field.name == '${prefix}_max') {
1.365 raeburn 11264: alert('$intalert{passmax}');
11265: } else {
1.408 raeburn 11266: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11267: alert('$intalert{passnum}');
11268: }
11269: }
1.370 raeburn 11270: field.value = '';
1.365 raeburn 11271: }
1.354 raeburn 11272: }
11273: }
11274: }
11275: return;
11276: }
11277:
11278: ENDSCRIPT
11279: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11280: }
11281:
1.49 raeburn 11282: sub coursecategories_javascript {
11283: my ($settings) = @_;
1.57 raeburn 11284: my ($output,$jstext,$cathash);
1.49 raeburn 11285: if (ref($settings) eq 'HASH') {
1.57 raeburn 11286: $cathash = $settings->{'cats'};
11287: }
11288: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11289: my (@cats,@jsarray,%idx);
1.57 raeburn 11290: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11291: if (@jsarray > 0) {
11292: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11293: for (my $i=0; $i<@jsarray; $i++) {
11294: if (ref($jsarray[$i]) eq 'ARRAY') {
11295: my $catstr = join('","',@{$jsarray[$i]});
11296: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11297: }
11298: }
11299: }
11300: } else {
11301: $jstext = ' var categories = Array(1);'."\n".
11302: ' categories[0] = Array("instcode_pos");'."\n";
11303: }
1.237 bisitz 11304: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11305: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11306: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11307: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11308: &js_escape(\$instcode_reserved);
11309: &js_escape(\$communities_reserved);
1.272 raeburn 11310: &js_escape(\$placement_reserved);
1.265 damieng 11311: &js_escape(\$choose_again);
1.49 raeburn 11312: $output = <<"ENDSCRIPT";
11313: <script type="text/javascript">
1.109 raeburn 11314: // <![CDATA[
1.49 raeburn 11315: function reorderCats(form,parent,item,idx) {
11316: var changedVal;
11317: $jstext
11318: var newpos = 'addcategory_pos';
11319: if (parent == '') {
11320: var has_instcode = 0;
11321: var maxtop = categories[idx].length;
11322: for (var j=0; j<maxtop; j++) {
11323: if (categories[idx][j] == 'instcode::0') {
11324: has_instcode == 1;
11325: }
11326: }
11327: if (has_instcode == 0) {
11328: categories[idx][maxtop] = 'instcode_pos';
11329: }
11330: } else {
11331: newpos += '_'+parent;
11332: }
11333: var maxh = 1 + categories[idx].length;
11334: var current = new Array;
11335: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11336: if (item == newpos) {
11337: changedVal = newitemVal;
11338: } else {
11339: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11340: current[newitemVal] = newpos;
11341: }
11342: for (var i=0; i<categories[idx].length; i++) {
11343: var elementName = categories[idx][i];
11344: if (elementName != item) {
11345: if (form.elements[elementName]) {
11346: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11347: current[currVal] = elementName;
11348: }
11349: }
11350: }
11351: var oldVal;
11352: for (var j=0; j<maxh; j++) {
11353: if (current[j] == undefined) {
11354: oldVal = j;
11355: }
11356: }
11357: if (oldVal < changedVal) {
11358: for (var k=oldVal+1; k<=changedVal ; k++) {
11359: var elementName = current[k];
11360: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11361: }
11362: } else {
11363: for (var k=changedVal; k<oldVal; k++) {
11364: var elementName = current[k];
11365: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11366: }
11367: }
11368: return;
11369: }
1.120 raeburn 11370:
11371: function categoryCheck(form) {
11372: if (form.elements['addcategory_name'].value == 'instcode') {
11373: alert('$instcode_reserved\\n$choose_again');
11374: return false;
11375: }
11376: if (form.elements['addcategory_name'].value == 'communities') {
11377: alert('$communities_reserved\\n$choose_again');
11378: return false;
11379: }
1.272 raeburn 11380: if (form.elements['addcategory_name'].value == 'placement') {
11381: alert('$placement_reserved\\n$choose_again');
11382: return false;
11383: }
1.120 raeburn 11384: return true;
11385: }
11386:
1.109 raeburn 11387: // ]]>
1.49 raeburn 11388: </script>
11389:
11390: ENDSCRIPT
11391: return $output;
11392: }
11393:
1.48 raeburn 11394: sub initialize_categories {
11395: my ($itemcount) = @_;
1.120 raeburn 11396: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11397: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11398: instcode => 'Official courses (with institutional codes)',
11399: communities => 'Communities',
1.272 raeburn 11400: placement => 'Placement Tests',
1.120 raeburn 11401: );
1.328 raeburn 11402: my %selnum = (
11403: instcode => '0',
11404: communities => '1',
11405: placement => '2',
11406: );
11407: my %selected;
1.272 raeburn 11408: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11409: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11410: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11411: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11412: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11413: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11414: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11415: .'<option value="0"'.$selected{'0'}.'>1</option>'
11416: .'<option value="1"'.$selected{'1'}.'>2</option>'
11417: .'<option value="2"'.$selected{'2'}.'>3</option>'
11418: .'<option value="3">4</option></select> '
1.120 raeburn 11419: .$default_names{$default}
11420: .'</span></td><td><span class="LC_nobreak">'
11421: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11422: .&mt('Display').'</label> <label>'
11423: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11424: .'</label></span></td></tr>';
1.120 raeburn 11425: $itemcount ++;
11426: }
1.48 raeburn 11427: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11428: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11429: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11430: .'<select name="addcategory_pos"'.$chgstr.'>'
11431: .'<option value="0">1</option>'
11432: .'<option value="1">2</option>'
1.328 raeburn 11433: .'<option value="2">3</option>'
11434: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11435: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11436: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11437: .'</td></tr>';
1.48 raeburn 11438: return $datatable;
11439: }
11440:
11441: sub build_category_rows {
1.49 raeburn 11442: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11443: my ($text,$name,$item,$chgstr);
1.48 raeburn 11444: if (ref($cats) eq 'ARRAY') {
11445: my $maxdepth = scalar(@{$cats});
11446: if (ref($cats->[$depth]) eq 'HASH') {
11447: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11448: my $numchildren = @{$cats->[$depth]{$parent}};
11449: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11450: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11451: my ($idxnum,$parent_name,$parent_item);
11452: my $higher = $depth - 1;
11453: if ($higher == 0) {
11454: $parent_name = &escape($parent).'::'.$higher;
11455: } else {
11456: if (ref($path) eq 'ARRAY') {
11457: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11458: }
11459: }
11460: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11461: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11462: if ($j < $numchildren) {
1.48 raeburn 11463: $name = $cats->[$depth]{$parent}[$j];
11464: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11465: $idxnum = $idx->{$item};
11466: } else {
11467: $name = $parent_name;
11468: $item = $parent_item;
1.48 raeburn 11469: }
1.49 raeburn 11470: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11471: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11472: for (my $i=0; $i<=$numchildren; $i++) {
11473: my $vpos = $i+1;
11474: my $selstr;
11475: if ($j == $i) {
11476: $selstr = ' selected="selected" ';
11477: }
11478: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11479: }
11480: $text .= '</select> ';
11481: if ($j < $numchildren) {
11482: my $deeper = $depth+1;
11483: $text .= $name.' '
11484: .'<label><input type="checkbox" name="deletecategory" value="'
11485: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11486: if(ref($path) eq 'ARRAY') {
11487: push(@{$path},$name);
1.49 raeburn 11488: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11489: pop(@{$path});
11490: }
11491: } else {
1.330 raeburn 11492: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11493: if ($j == $numchildren) {
11494: $text .= $name;
11495: } else {
11496: $text .= $item;
11497: }
11498: $text .= '" value="" />';
11499: }
11500: $text .= '</td></tr>';
11501: }
11502: $text .= '</table></td>';
11503: } else {
11504: my $higher = $depth-1;
11505: if ($higher == 0) {
11506: $name = &escape($parent).'::'.$higher;
11507: } else {
11508: if (ref($path) eq 'ARRAY') {
11509: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11510: }
11511: }
11512: my $colspan;
11513: if ($parent ne 'instcode') {
11514: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11515: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11516: }
11517: }
11518: }
11519: }
11520: return $text;
11521: }
11522:
1.33 raeburn 11523: sub modifiable_userdata_row {
1.305 raeburn 11524: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11525: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11526: my ($role,$rolename,$statustype);
11527: $role = $item;
1.224 raeburn 11528: if ($context eq 'cancreate') {
1.305 raeburn 11529: if ($item =~ /^(emailusername)_(.+)$/) {
11530: $role = $1;
11531: $statustype = $2;
1.228 raeburn 11532: if (ref($usertypes) eq 'HASH') {
11533: if ($usertypes->{$statustype}) {
11534: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11535: } else {
11536: $rolename = &mt('Data provided by user');
11537: }
11538: }
1.224 raeburn 11539: }
11540: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11541: if (ref($usertypes) eq 'HASH') {
11542: $rolename = $usertypes->{$role};
11543: } else {
11544: $rolename = $role;
11545: }
1.325 raeburn 11546: } elsif ($context eq 'lti') {
11547: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11548: } elsif ($context eq 'privacy') {
11549: $rolename = $itemdesc;
1.33 raeburn 11550: } else {
1.63 raeburn 11551: if ($role eq 'cr') {
11552: $rolename = &mt('Custom role');
11553: } else {
11554: $rolename = &Apache::lonnet::plaintext($role);
11555: }
1.33 raeburn 11556: }
1.224 raeburn 11557: my (@fields,%fieldtitles);
11558: if (ref($fieldsref) eq 'ARRAY') {
11559: @fields = @{$fieldsref};
11560: } else {
11561: @fields = ('lastname','firstname','middlename','generation',
11562: 'permanentemail','id');
11563: }
11564: if ((ref($titlesref) eq 'HASH')) {
11565: %fieldtitles = %{$titlesref};
11566: } else {
11567: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11568: }
1.33 raeburn 11569: my $output;
1.305 raeburn 11570: my $css_class;
11571: if ($rowcount%2) {
11572: $css_class = 'LC_odd_row';
11573: }
11574: if ($customcss) {
11575: $css_class .= " $customcss";
11576: }
11577: $css_class =~ s/^\s+//;
11578: if ($css_class) {
11579: $css_class = ' class="'.$css_class.'"';
11580: }
11581: if ($rowstyle) {
11582: $css_class .= ' style="'.$rowstyle.'"';
11583: }
11584: if ($rowid) {
11585: $rowid = ' id="'.$rowid.'"';
11586: }
11587: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11588: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11589: '<td class="LC_left_item" colspan="2"><table>';
11590: my $rem;
11591: my %checks;
1.325 raeburn 11592: my %current;
1.33 raeburn 11593: if (ref($settings) eq 'HASH') {
1.325 raeburn 11594: my $hashref;
11595: if ($context eq 'lti') {
11596: if (ref($settings) eq 'HASH') {
11597: $hashref = $settings->{'instdata'};
11598: }
1.357 raeburn 11599: } elsif ($context eq 'privacy') {
11600: my ($key,$inner) = split(/_/,$role);
11601: if (ref($settings) eq 'HASH') {
11602: if (ref($settings->{$key}) eq 'HASH') {
11603: $hashref = $settings->{$key}->{$inner};
11604: }
11605: }
1.325 raeburn 11606: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11607: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11608: $hashref = $settings->{'lti_instdata'};
11609: }
11610: if ($role eq 'emailusername') {
11611: if ($statustype) {
11612: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11613: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11614: }
1.325 raeburn 11615: }
11616: }
11617: }
11618: if (ref($hashref) eq 'HASH') {
11619: foreach my $field (@fields) {
11620: if ($hashref->{$field}) {
11621: if ($role eq 'emailusername') {
11622: $checks{$field} = $hashref->{$field};
11623: } else {
11624: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11625: }
11626: }
11627: }
11628: }
11629: }
1.305 raeburn 11630:
11631: my $total = scalar(@fields);
11632: for (my $i=0; $i<$total; $i++) {
11633: $rem = $i%($numinrow);
1.33 raeburn 11634: if ($rem == 0) {
11635: if ($i > 0) {
11636: $output .= '</tr>';
11637: }
11638: $output .= '<tr>';
11639: }
11640: my $check = ' ';
1.228 raeburn 11641: unless ($role eq 'emailusername') {
11642: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11643: $check = $checks{$fields[$i]};
1.357 raeburn 11644: } elsif ($context eq 'privacy') {
11645: if ($role =~ /^priv_(domain|course)$/) {
11646: if (ref($settings) ne 'HASH') {
11647: $check = ' checked="checked" ';
11648: }
11649: } elsif ($role =~ /^priv_(author|community)$/) {
11650: if (ref($settings) ne 'HASH') {
11651: unless ($fields[$i] eq 'id') {
11652: $check = ' checked="checked" ';
11653: }
11654: }
11655: } elsif ($role =~ /^(unpriv|othdom)_/) {
11656: if (ref($settings) ne 'HASH') {
11657: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11658: $check = ' checked="checked" ';
11659: }
11660: }
11661: }
1.325 raeburn 11662: } elsif ($context ne 'lti') {
1.228 raeburn 11663: if ($role eq 'st') {
11664: if (ref($settings) ne 'HASH') {
11665: $check = ' checked="checked" ';
11666: }
1.33 raeburn 11667: }
11668: }
11669: }
11670: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11671: '<span class="LC_nobreak">';
1.325 raeburn 11672: my $prefix = 'canmodify';
1.228 raeburn 11673: if ($role eq 'emailusername') {
11674: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11675: $checks{$fields[$i]} = 'omit';
11676: }
11677: foreach my $option ('required','optional','omit') {
11678: my $checked='';
11679: if ($checks{$fields[$i]} eq $option) {
11680: $checked='checked="checked" ';
11681: }
11682: $output .= '<label>'.
1.325 raeburn 11683: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11684: &mt($option).'</label>'.(' ' x2);
11685: }
11686: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11687: } else {
1.325 raeburn 11688: if ($context eq 'lti') {
11689: $prefix = 'lti';
1.357 raeburn 11690: } elsif ($context eq 'privacy') {
11691: $prefix = 'privacy';
1.325 raeburn 11692: }
1.228 raeburn 11693: $output .= '<label>'.
1.325 raeburn 11694: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11695: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11696: '</label>';
11697: }
11698: $output .= '</span></td>';
1.33 raeburn 11699: }
1.305 raeburn 11700: $rem = $total%$numinrow;
11701: my $colsleft;
11702: if ($rem) {
11703: $colsleft = $numinrow - $rem;
11704: }
11705: if ($colsleft > 1) {
1.33 raeburn 11706: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11707: ' </td>';
11708: } elsif ($colsleft == 1) {
11709: $output .= '<td class="LC_left_item"> </td>';
11710: }
11711: $output .= '</tr></table></td></tr>';
11712: return $output;
11713: }
1.28 raeburn 11714:
1.93 raeburn 11715: sub insttypes_row {
1.305 raeburn 11716: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11717: $customcss,$rowstyle) = @_;
1.93 raeburn 11718: my %lt = &Apache::lonlocal::texthash (
11719: cansearch => 'Users allowed to search',
11720: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11721: lockablenames => 'User preference to lock name',
1.305 raeburn 11722: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11723: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11724: );
11725: my $showdom;
11726: if ($context eq 'cansearch') {
11727: $showdom = ' ('.$dom.')';
11728: }
1.165 raeburn 11729: my $class = 'LC_left_item';
11730: if ($context eq 'statustocreate') {
11731: $class = 'LC_right_item';
11732: }
1.305 raeburn 11733: my $css_class;
11734: if ($$rowtotal%2) {
11735: $css_class = 'LC_odd_row';
11736: }
11737: if ($customcss) {
11738: $css_class .= ' '.$customcss;
11739: }
11740: $css_class =~ s/^\s+//;
11741: if ($css_class) {
11742: $css_class = ' class="'.$css_class.'"';
11743: }
11744: if ($rowstyle) {
11745: $css_class .= ' style="'.$rowstyle.'"';
11746: }
11747: if ($onclick) {
11748: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11749: }
11750: my $output = '<tr'.$css_class.'>'.
11751: '<td>'.$lt{$context}.$showdom.
11752: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11753: my $rem;
11754: if (ref($types) eq 'ARRAY') {
11755: for (my $i=0; $i<@{$types}; $i++) {
11756: if (defined($usertypes->{$types->[$i]})) {
11757: my $rem = $i%($numinrow);
11758: if ($rem == 0) {
11759: if ($i > 0) {
11760: $output .= '</tr>';
11761: }
11762: $output .= '<tr>';
1.23 raeburn 11763: }
1.26 raeburn 11764: my $check = ' ';
1.99 raeburn 11765: if (ref($settings) eq 'HASH') {
11766: if (ref($settings->{$context}) eq 'ARRAY') {
11767: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11768: $check = ' checked="checked" ';
11769: }
1.315 raeburn 11770: } elsif (ref($settings->{$context}) eq 'HASH') {
11771: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11772: $check = ' checked="checked" ';
11773: }
1.99 raeburn 11774: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11775: $check = ' checked="checked" ';
11776: }
1.23 raeburn 11777: }
1.26 raeburn 11778: $output .= '<td class="LC_left_item">'.
11779: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11780: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11781: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11782: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11783: }
11784: }
1.26 raeburn 11785: $rem = @{$types}%($numinrow);
1.23 raeburn 11786: }
11787: my $colsleft = $numinrow - $rem;
1.315 raeburn 11788: if ($context eq 'overrides') {
11789: if ($colsleft > 1) {
11790: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11791: } else {
11792: $output .= '<td class="LC_left_item">';
11793: }
11794: $output .= ' ';
1.23 raeburn 11795: } else {
1.334 raeburn 11796: if ($rem == 0) {
1.315 raeburn 11797: $output .= '<tr>';
11798: }
11799: if ($colsleft > 1) {
11800: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11801: } else {
11802: $output .= '<td class="LC_left_item">';
11803: }
11804: my $defcheck = ' ';
11805: if (ref($settings) eq 'HASH') {
11806: if (ref($settings->{$context}) eq 'ARRAY') {
11807: if (grep(/^default$/,@{$settings->{$context}})) {
11808: $defcheck = ' checked="checked" ';
11809: }
11810: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11811: $defcheck = ' checked="checked" ';
11812: }
1.26 raeburn 11813: }
1.315 raeburn 11814: $output .= '<span class="LC_nobreak"><label>'.
11815: '<input type="checkbox" name="'.$context.'" '.
11816: 'value="default"'.$defcheck.$onclick.' />'.
11817: $othertitle.'</label></span>';
1.23 raeburn 11818: }
1.315 raeburn 11819: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11820: return $output;
1.23 raeburn 11821: }
11822:
11823: sub sorted_searchtitles {
11824: my %searchtitles = &Apache::lonlocal::texthash(
11825: 'uname' => 'username',
11826: 'lastname' => 'last name',
11827: 'lastfirst' => 'last name, first name',
11828: );
11829: my @titleorder = ('uname','lastname','lastfirst');
11830: return (\%searchtitles,\@titleorder);
11831: }
11832:
1.25 raeburn 11833: sub sorted_searchtypes {
11834: my %srchtypes_desc = (
11835: exact => 'is exact match',
11836: contains => 'contains ..',
11837: begins => 'begins with ..',
11838: );
11839: my @srchtypeorder = ('exact','begins','contains');
11840: return (\%srchtypes_desc,\@srchtypeorder);
11841: }
11842:
1.3 raeburn 11843: sub usertype_update_row {
11844: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11845: my $datatable;
11846: my $numinrow = 4;
11847: foreach my $type (@{$types}) {
11848: if (defined($usertypes->{$type})) {
11849: $$rownums ++;
11850: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11851: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11852: '</td><td class="LC_left_item"><table>';
11853: for (my $i=0; $i<@{$fields}; $i++) {
11854: my $rem = $i%($numinrow);
11855: if ($rem == 0) {
11856: if ($i > 0) {
11857: $datatable .= '</tr>';
11858: }
11859: $datatable .= '<tr>';
11860: }
11861: my $check = ' ';
1.39 raeburn 11862: if (ref($settings) eq 'HASH') {
11863: if (ref($settings->{'fields'}) eq 'HASH') {
11864: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11865: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11866: $check = ' checked="checked" ';
11867: }
1.3 raeburn 11868: }
11869: }
11870: }
11871:
11872: if ($i == @{$fields}-1) {
11873: my $colsleft = $numinrow - $rem;
11874: if ($colsleft > 1) {
11875: $datatable .= '<td colspan="'.$colsleft.'">';
11876: } else {
11877: $datatable .= '<td>';
11878: }
11879: } else {
11880: $datatable .= '<td>';
11881: }
1.8 raeburn 11882: $datatable .= '<span class="LC_nobreak"><label>'.
11883: '<input type="checkbox" name="updateable_'.$type.
11884: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11885: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11886: }
11887: $datatable .= '</tr></table></td></tr>';
11888: }
11889: }
11890: return $datatable;
1.1 raeburn 11891: }
11892:
11893: sub modify_login {
1.205 raeburn 11894: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11895: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11896: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 11897: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 11898: %title = ( coursecatalog => 'Display course catalog',
11899: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11900: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11901: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11902: loginheader => 'Log-in box header',
11903: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11904: @offon = ('off','on');
1.112 raeburn 11905: if (ref($domconfig{login}) eq 'HASH') {
11906: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11907: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11908: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11909: }
11910: }
1.386 raeburn 11911: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11912: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11913: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11914: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11915: $saml{$lonhost} = 1;
11916: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11917: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11918: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11919: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11920: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 11921: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 11922: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11923: }
11924: }
11925: }
1.112 raeburn 11926: }
1.9 raeburn 11927: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11928: \%domconfig,\%loginhash);
1.188 raeburn 11929: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11930: foreach my $item (@toggles) {
11931: $loginhash{login}{$item} = $env{'form.'.$item};
11932: }
1.41 raeburn 11933: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11934: if (ref($colchanges{'login'}) eq 'HASH') {
11935: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11936: \%loginhash);
11937: }
1.110 raeburn 11938:
1.149 raeburn 11939: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11940: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11941: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11942: if (keys(%servers) > 1) {
11943: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11944: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11945: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11946: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11947: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11948: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11949: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11950: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11951: $changes{'loginvia'}{$lonhost} = 1;
11952: } else {
11953: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11954: $changes{'loginvia'}{$lonhost} = 1;
11955: }
11956: } else {
11957: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11958: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11959: $changes{'loginvia'}{$lonhost} = 1;
11960: }
11961: }
11962: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11963: foreach my $item (@loginvia_attribs) {
11964: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11965: }
11966: } else {
11967: foreach my $item (@loginvia_attribs) {
11968: my $new = $env{'form.'.$lonhost.'_'.$item};
11969: if (($item eq 'serverpath') && ($new eq 'custom')) {
11970: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11971: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11972: $new = '/';
11973: }
11974: }
11975: if (($item eq 'custompath') &&
11976: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11977: $new = '';
11978: }
11979: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11980: $changes{'loginvia'}{$lonhost} = 1;
11981: }
11982: if ($item eq 'exempt') {
1.256 raeburn 11983: $new = &check_exempt_addresses($new);
1.128 raeburn 11984: }
11985: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11986: }
11987: }
1.112 raeburn 11988: } else {
1.128 raeburn 11989: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11990: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11991: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11992: foreach my $item (@loginvia_attribs) {
11993: my $new = $env{'form.'.$lonhost.'_'.$item};
11994: if (($item eq 'serverpath') && ($new eq 'custom')) {
11995: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11996: $new = '/';
11997: }
11998: }
11999: if (($item eq 'custompath') &&
12000: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12001: $new = '';
12002: }
12003: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12004: }
1.110 raeburn 12005: }
12006: }
12007: }
12008: }
1.119 raeburn 12009:
1.168 raeburn 12010: my $servadm = $r->dir_config('lonAdmEMail');
12011: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12012: if (ref($domconfig{'login'}) eq 'HASH') {
12013: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12014: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12015: if ($lang eq 'nolang') {
12016: push(@currlangs,$lang);
12017: } elsif (defined($langchoices{$lang})) {
12018: push(@currlangs,$lang);
12019: } else {
12020: next;
12021: }
12022: }
12023: }
12024: }
12025: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12026: if (@currlangs > 0) {
12027: foreach my $lang (@currlangs) {
12028: if (grep(/^\Q$lang\E$/,@delurls)) {
12029: $changes{'helpurl'}{$lang} = 1;
12030: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12031: $changes{'helpurl'}{$lang} = 1;
12032: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12033: push(@newlangs,$lang);
12034: } else {
12035: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12036: }
12037: }
12038: }
12039: unless (grep(/^nolang$/,@currlangs)) {
12040: if ($env{'form.loginhelpurl_nolang.filename'}) {
12041: $changes{'helpurl'}{'nolang'} = 1;
12042: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12043: push(@newlangs,'nolang');
12044: }
12045: }
12046: if ($env{'form.loginhelpurl_add_lang'}) {
12047: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12048: ($env{'form.loginhelpurl_add_file.filename'})) {
12049: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12050: $addedfile = $env{'form.loginhelpurl_add_lang'};
12051: }
12052: }
12053: if ((@newlangs > 0) || ($addedfile)) {
12054: my $error;
12055: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12056: if ($configuserok eq 'ok') {
12057: if ($switchserver) {
12058: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12059: } elsif ($author_ok eq 'ok') {
12060: my @allnew = @newlangs;
12061: if ($addedfile ne '') {
12062: push(@allnew,$addedfile);
12063: }
1.421 ! raeburn 12064: my $modified = [];
1.168 raeburn 12065: foreach my $lang (@allnew) {
12066: my $formelem = 'loginhelpurl_'.$lang;
12067: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12068: $formelem = 'loginhelpurl_add_file';
12069: }
1.421 ! raeburn 12070: (my $result,$newurl{$lang}) =
! 12071: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
! 12072: "help/$lang",'','',$newfile{$lang},
! 12073: $modified);
1.168 raeburn 12074: if ($result eq 'ok') {
12075: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12076: $changes{'helpurl'}{$lang} = 1;
12077: } else {
12078: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12079: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12080: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12081: (!grep(/^\Q$lang\E$/,@delurls))) {
12082: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12083: }
12084: }
12085: }
1.421 ! raeburn 12086: &update_modify_urls($r,$modified);
1.168 raeburn 12087: } else {
12088: $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);
12089: }
12090: } else {
12091: $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);
12092: }
12093: if ($error) {
12094: &Apache::lonnet::logthis($error);
12095: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12096: }
12097: }
1.256 raeburn 12098:
12099: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12100: if (ref($domconfig{'login'}) eq 'HASH') {
12101: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12102: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12103: if ($domservers{$lonhost}) {
12104: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12105: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12106: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12107: }
12108: }
12109: }
12110: }
12111: }
12112: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12113: foreach my $lonhost (sort(keys(%domservers))) {
12114: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12115: $changes{'headtag'}{$lonhost} = 1;
12116: } else {
12117: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12118: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12119: }
12120: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12121: push(@newhosts,$lonhost);
12122: } elsif ($currheadtagurls{$lonhost}) {
12123: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12124: if ($currexempt{$lonhost}) {
1.289 raeburn 12125: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12126: $changes{'headtag'}{$lonhost} = 1;
12127: }
12128: } elsif ($possexempt{$lonhost}) {
12129: $changes{'headtag'}{$lonhost} = 1;
12130: }
12131: if ($possexempt{$lonhost}) {
12132: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12133: }
12134: }
12135: }
12136: }
12137: if (@newhosts) {
12138: my $error;
12139: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12140: if ($configuserok eq 'ok') {
12141: if ($switchserver) {
12142: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12143: } elsif ($author_ok eq 'ok') {
1.421 ! raeburn 12144: my $modified = [];
1.256 raeburn 12145: foreach my $lonhost (@newhosts) {
12146: my $formelem = 'loginheadtag_'.$lonhost;
1.421 ! raeburn 12147: (my $result,$newheadtagurls{$lonhost}) =
! 12148: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
! 12149: "login/headtag/$lonhost",'','',
! 12150: $env{'form.loginheadtag_'.$lonhost.'.filename'},
! 12151: $modified);
1.256 raeburn 12152: if ($result eq 'ok') {
12153: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12154: $changes{'headtag'}{$lonhost} = 1;
12155: if ($possexempt{$lonhost}) {
12156: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12157: }
12158: } else {
12159: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12160: $newheadtagurls{$lonhost},$result);
12161: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12162: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12163: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12164: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12165: }
12166: }
12167: }
1.421 ! raeburn 12168: &update_modify_urls($r,$modified);
1.256 raeburn 12169: } else {
12170: $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);
12171: }
12172: } else {
12173: $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);
12174: }
12175: if ($error) {
12176: &Apache::lonnet::logthis($error);
12177: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12178: }
12179: }
1.386 raeburn 12180: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12181: my @newsamlimgs;
12182: foreach my $lonhost (keys(%domservers)) {
12183: if ($env{'form.saml_'.$lonhost}) {
12184: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12185: push(@newsamlimgs,$lonhost);
12186: }
1.412 raeburn 12187: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12188: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12189: }
12190: if ($saml{$lonhost}) {
1.412 raeburn 12191: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12192: $env{'form.saml_window_'.$lonhost} = '';
12193: }
1.386 raeburn 12194: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12195: #FIXME Need to obsolete published image
12196: delete($currsaml{$lonhost}{'img'});
12197: $changes{'saml'}{$lonhost} = 1;
12198: }
12199: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12200: $changes{'saml'}{$lonhost} = 1;
12201: }
12202: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12203: $changes{'saml'}{$lonhost} = 1;
12204: }
12205: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12206: $changes{'saml'}{$lonhost} = 1;
12207: }
12208: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12209: $changes{'saml'}{$lonhost} = 1;
12210: }
1.412 raeburn 12211: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12212: $changes{'saml'}{$lonhost} = 1;
12213: }
1.386 raeburn 12214: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12215: $changes{'saml'}{$lonhost} = 1;
12216: }
12217: } else {
12218: $changes{'saml'}{$lonhost} = 1;
12219: }
1.412 raeburn 12220: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12221: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12222: }
12223: } else {
1.389 raeburn 12224: if ($saml{$lonhost}) {
12225: $changes{'saml'}{$lonhost} = 1;
12226: delete($currsaml{$lonhost});
12227: }
1.386 raeburn 12228: }
12229: }
12230: foreach my $posshost (keys(%currsaml)) {
12231: unless (exists($domservers{$posshost})) {
12232: delete($currsaml{$posshost});
12233: }
12234: }
12235: %{$loginhash{'login'}{'saml'}} = %currsaml;
12236: if (@newsamlimgs) {
12237: my $error;
12238: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12239: if ($configuserok eq 'ok') {
12240: if ($switchserver) {
12241: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12242: } elsif ($author_ok eq 'ok') {
1.421 ! raeburn 12243: my $modified = [];
1.386 raeburn 12244: foreach my $lonhost (@newsamlimgs) {
12245: my $formelem = 'saml_img_'.$lonhost;
1.421 ! raeburn 12246: my ($result,$imgurl) =
! 12247: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
! 12248: "login/saml/$lonhost",'','',
! 12249: $env{'form.saml_img_'.$lonhost.'.filename'},
! 12250: $modified);
1.386 raeburn 12251: if ($result eq 'ok') {
12252: $currsaml{$lonhost}{'img'} = $imgurl;
12253: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12254: $changes{'saml'}{$lonhost} = 1;
12255: } else {
12256: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12257: $lonhost,$result);
12258: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12259: }
12260: }
1.421 ! raeburn 12261: &update_modify_urls($r,$modified);
1.386 raeburn 12262: } else {
12263: $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);
12264: }
12265: } else {
12266: $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);
12267: }
12268: if ($error) {
12269: &Apache::lonnet::logthis($error);
12270: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12271: }
12272: }
1.169 raeburn 12273: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12274:
12275: my $defaulthelpfile = '/adm/loginproblems.html';
12276: my $defaulttext = &mt('Default in use');
12277:
1.1 raeburn 12278: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12279: $dom);
12280: if ($putresult eq 'ok') {
1.188 raeburn 12281: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12282: my %defaultchecked = (
12283: 'coursecatalog' => 'on',
1.188 raeburn 12284: 'helpdesk' => 'on',
1.42 raeburn 12285: 'adminmail' => 'off',
1.43 raeburn 12286: 'newuser' => 'off',
1.42 raeburn 12287: );
1.55 raeburn 12288: if (ref($domconfig{'login'}) eq 'HASH') {
12289: foreach my $item (@toggles) {
12290: if ($defaultchecked{$item} eq 'on') {
12291: if (($domconfig{'login'}{$item} eq '0') &&
12292: ($env{'form.'.$item} eq '1')) {
12293: $changes{$item} = 1;
12294: } elsif (($domconfig{'login'}{$item} eq '' ||
12295: $domconfig{'login'}{$item} eq '1') &&
12296: ($env{'form.'.$item} eq '0')) {
12297: $changes{$item} = 1;
12298: }
12299: } elsif ($defaultchecked{$item} eq 'off') {
12300: if (($domconfig{'login'}{$item} eq '1') &&
12301: ($env{'form.'.$item} eq '0')) {
12302: $changes{$item} = 1;
12303: } elsif (($domconfig{'login'}{$item} eq '' ||
12304: $domconfig{'login'}{$item} eq '0') &&
12305: ($env{'form.'.$item} eq '1')) {
12306: $changes{$item} = 1;
12307: }
1.42 raeburn 12308: }
12309: }
1.41 raeburn 12310: }
1.6 raeburn 12311: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12312: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12313: if (exists($changes{'saml'})) {
12314: my $hostid_in_use;
12315: my @hosts = &Apache::lonnet::current_machine_ids();
12316: if (@hosts > 1) {
12317: foreach my $hostid (@hosts) {
12318: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12319: $hostid_in_use = $hostid;
12320: last;
12321: }
12322: }
12323: } else {
12324: $hostid_in_use = $r->dir_config('lonHostID');
12325: }
12326: if (($hostid_in_use) &&
12327: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12328: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12329: }
12330: if (ref($lastactref) eq 'HASH') {
12331: if (ref($changes{'saml'}) eq 'HASH') {
12332: my %updates;
12333: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12334: $lastactref->{'samllanding'} = \%updates;
12335: }
12336: }
12337: }
1.212 raeburn 12338: if (ref($lastactref) eq 'HASH') {
12339: $lastactref->{'domainconfig'} = 1;
12340: }
1.1 raeburn 12341: $resulttext = &mt('Changes made:').'<ul>';
12342: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12343: if ($item eq 'loginvia') {
1.112 raeburn 12344: if (ref($changes{$item}) eq 'HASH') {
12345: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12346: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12347: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12348: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12349: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12350: $protocol = 'http' if ($protocol ne 'https');
12351: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12352:
12353: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12354: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12355: } else {
12356: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12357: }
12358: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12359: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12360: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12361: }
12362: $resulttext .= '</li>';
12363: } else {
12364: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12365: }
1.112 raeburn 12366: } else {
1.128 raeburn 12367: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12368: }
12369: }
1.128 raeburn 12370: $resulttext .= '</ul></li>';
1.112 raeburn 12371: }
1.168 raeburn 12372: } elsif ($item eq 'helpurl') {
12373: if (ref($changes{$item}) eq 'HASH') {
12374: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12375: if (grep(/^\Q$lang\E$/,@delurls)) {
12376: my ($chg,$link);
12377: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12378: if ($lang eq 'nolang') {
12379: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12380: } else {
12381: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12382: }
12383: $resulttext .= '<li>'.$chg.'</li>';
12384: } else {
12385: my $chg;
12386: if ($lang eq 'nolang') {
12387: $chg = &mt('custom log-in help file for no preferred language');
12388: } else {
12389: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12390: }
12391: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12392: $loginhash{'login'}{'helpurl'}{$lang}.
12393: '?inhibitmenu=yes',$chg,600,500).
12394: '</li>';
12395: }
12396: }
12397: }
1.256 raeburn 12398: } elsif ($item eq 'headtag') {
12399: if (ref($changes{$item}) eq 'HASH') {
12400: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12401: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12402: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12403: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12404: $resulttext .= '<li><a href="'.
12405: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12406: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12407: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12408: if ($possexempt{$lonhost}) {
12409: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12410: } else {
12411: $resulttext .= &mt('included for any client IP');
12412: }
12413: $resulttext .= '</li>';
12414: }
12415: }
12416: }
1.386 raeburn 12417: } elsif ($item eq 'saml') {
12418: if (ref($changes{$item}) eq 'HASH') {
12419: my %notlt = (
12420: text => 'Text for log-in by SSO',
12421: img => 'SSO button image',
12422: alt => 'Alt text for button image',
12423: url => 'SSO URL',
12424: title => 'Tooltip for SSO link',
1.412 raeburn 12425: window => 'Pop-up window if iframe',
1.386 raeburn 12426: notsso => 'Text for non-SSO log-in',
12427: );
12428: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12429: if (ref($currsaml{$lonhost}) eq 'HASH') {
12430: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12431: '<ul>';
1.412 raeburn 12432: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12433: if ($currsaml{$lonhost}{$key} eq '') {
12434: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12435: } else {
12436: my $value = "'$currsaml{$lonhost}{$key}'";
12437: if ($key eq 'img') {
12438: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12439: } elsif ($key eq 'window') {
12440: $value = 'On';
1.386 raeburn 12441: }
12442: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12443: $value).'</li>';
12444: }
12445: }
12446: $resulttext .= '</ul></li>';
12447: } else {
12448: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12449: }
12450: }
12451: }
1.169 raeburn 12452: } elsif ($item eq 'captcha') {
12453: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12454: my $chgtxt;
1.169 raeburn 12455: if ($loginhash{'login'}{$item} eq 'notused') {
12456: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12457: } else {
12458: my %captchas = &captcha_phrases();
12459: if ($captchas{$loginhash{'login'}{$item}}) {
12460: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12461: } else {
12462: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12463: }
12464: }
12465: $resulttext .= '<li>'.$chgtxt.'</li>';
12466: }
12467: } elsif ($item eq 'recaptchakeys') {
12468: if (ref($loginhash{'login'}) eq 'HASH') {
12469: my ($privkey,$pubkey);
12470: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12471: $pubkey = $loginhash{'login'}{$item}{'public'};
12472: $privkey = $loginhash{'login'}{$item}{'private'};
12473: }
12474: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12475: if (!$pubkey) {
12476: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12477: } else {
12478: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12479: }
12480: if (!$privkey) {
12481: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12482: } else {
1.251 raeburn 12483: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12484: }
12485: $chgtxt .= '</ul>';
12486: $resulttext .= '<li>'.$chgtxt.'</li>';
12487: }
1.269 raeburn 12488: } elsif ($item eq 'recaptchaversion') {
12489: if (ref($loginhash{'login'}) eq 'HASH') {
12490: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12491: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12492: '</li>';
12493: }
12494: }
1.41 raeburn 12495: } else {
12496: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12497: }
1.1 raeburn 12498: }
1.6 raeburn 12499: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12500: } else {
12501: $resulttext = &mt('No changes made to log-in page settings');
12502: }
12503: } else {
1.11 albertel 12504: $resulttext = '<span class="LC_error">'.
12505: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12506: }
1.6 raeburn 12507: if ($errors) {
1.9 raeburn 12508: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12509: $errors.'</ul>';
12510: }
12511: return $resulttext;
12512: }
12513:
1.256 raeburn 12514: sub check_exempt_addresses {
12515: my ($iplist) = @_;
12516: $iplist =~ s/^\s+//;
12517: $iplist =~ s/\s+$//;
12518: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12519: my (@okips,$new);
12520: foreach my $ip (@poss_ips) {
12521: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12522: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12523: push(@okips,$ip);
12524: }
12525: }
12526: }
12527: if (@okips > 0) {
12528: $new = join(',',@okips);
12529: } else {
12530: $new = '';
12531: }
12532: return $new;
12533: }
12534:
1.6 raeburn 12535: sub color_font_choices {
12536: my %choices =
12537: &Apache::lonlocal::texthash (
12538: img => "Header",
12539: bgs => "Background colors",
12540: links => "Link colors",
1.55 raeburn 12541: images => "Images",
1.6 raeburn 12542: font => "Font color",
1.201 raeburn 12543: fontmenu => "Font menu",
1.76 raeburn 12544: pgbg => "Page",
1.6 raeburn 12545: tabbg => "Header",
12546: sidebg => "Border",
12547: link => "Link",
12548: alink => "Active link",
12549: vlink => "Visited link",
12550: );
12551: return %choices;
12552: }
12553:
1.394 raeburn 12554: sub modify_ipaccess {
12555: my ($dom,$lastactref,%domconfig) = @_;
12556: my (@allpos,%changes,%confhash,$errors,$resulttext);
12557: my (@items,%deletions,%itemids,@warnings);
12558: my ($typeorder,$types) = &commblocktype_text();
12559: if ($env{'form.ipaccess_add'}) {
12560: my $name = $env{'form.ipaccess_name_add'};
12561: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12562: if ($newid) {
12563: $itemids{'add'} = $newid;
12564: push(@items,'add');
12565: $changes{$newid} = 1;
12566: } else {
12567: $error = &mt('Failed to acquire unique ID for new IP access control item');
12568: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12569: }
12570: }
12571: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12572: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12573: if (@todelete) {
12574: map { $deletions{$_} = 1; } @todelete;
12575: }
12576: my $maxnum = $env{'form.ipaccess_maxnum'};
12577: for (my $i=0; $i<$maxnum; $i++) {
12578: my $itemid = $env{'form.ipaccess_id_'.$i};
12579: $itemid =~ s/\D+//g;
12580: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12581: if ($deletions{$itemid}) {
12582: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12583: } else {
12584: push(@items,$i);
12585: $itemids{$i} = $itemid;
12586: }
12587: }
12588: }
12589: }
12590: foreach my $idx (@items) {
12591: my $itemid = $itemids{$idx};
12592: next unless ($itemid);
12593: my %current;
12594: unless ($idx eq 'add') {
12595: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12596: %current = %{$domconfig{'ipaccess'}{$itemid}};
12597: }
12598: }
12599: my $position = $env{'form.ipaccess_pos_'.$itemid};
12600: $position =~ s/\D+//g;
12601: if ($position ne '') {
12602: $allpos[$position] = $itemid;
12603: }
12604: my $name = $env{'form.ipaccess_name_'.$idx};
12605: $name =~ s/^\s+|\s+$//g;
12606: $confhash{$itemid}{'name'} = $name;
12607: my $possrange = $env{'form.ipaccess_range_'.$idx};
12608: $possrange =~ s/^\s+|\s+$//g;
12609: unless ($possrange eq '') {
12610: $possrange =~ s/[\r\n]+/\s/g;
12611: $possrange =~ s/\s*-\s*/-/g;
12612: $possrange =~ s/\s+/,/g;
12613: $possrange =~ s/,+/,/g;
12614: if ($possrange ne '') {
12615: my (@ok,$count);
12616: $count = 0;
12617: foreach my $poss (split(/\,/,$possrange)) {
12618: $count ++;
12619: $poss = &validate_ip_pattern($poss);
12620: if ($poss ne '') {
12621: push(@ok,$poss);
12622: }
12623: }
12624: my $diff = $count - scalar(@ok);
12625: if ($diff) {
12626: $errors .= '<li><span class="LC_error">'.
12627: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
12628: $diff,$name).
12629: '</span></li>';
12630: }
12631: if (@ok) {
12632: my @cidr_list;
12633: foreach my $item (@ok) {
12634: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
12635: }
12636: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
12637: }
12638: }
12639: }
12640: foreach my $field ('name','ip') {
12641: unless (($idx eq 'add') || ($changes{$itemid})) {
12642: if ($current{$field} ne $confhash{$itemid}{$field}) {
12643: $changes{$itemid} = 1;
12644: last;
12645: }
12646: }
12647: }
12648: $confhash{$itemid}{'commblocks'} = {};
12649:
12650: my %commblocks;
12651: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
12652: foreach my $type (@{$typeorder}) {
12653: if ($commblocks{$type}) {
12654: $confhash{$itemid}{'commblocks'}{$type} = 'on';
12655: }
12656: unless (($idx eq 'add') || ($changes{$itemid})) {
12657: if (ref($current{'commblocks'}) eq 'HASH') {
12658: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
12659: $changes{$itemid} = 1;
12660: }
12661: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
12662: $changes{$itemid} = 1;
12663: }
12664: }
12665: }
12666: $confhash{$itemid}{'courses'} = {};
12667: my %crsdeletions;
12668: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
12669: if (@delcrs) {
12670: map { $crsdeletions{$_} = 1; } @delcrs;
12671: }
12672: if (ref($current{'courses'}) eq 'HASH') {
12673: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
12674: if ($crsdeletions{$cid}) {
12675: $changes{$itemid} = 1;
12676: } else {
12677: $confhash{$itemid}{'courses'}{$cid} = 1;
12678: }
12679: }
12680: }
12681: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
12682: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
12683: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
12684: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
12685: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
12686: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
12687: $errors .= '<li><span class="LC_error">'.
12688: &mt('Invalid courseID [_1] omitted from list of allowed courses',
12689: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
12690: '</span></li>';
12691: } else {
12692: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
12693: $changes{$itemid} = 1;
12694: }
12695: }
12696: }
12697: if (@allpos > 0) {
12698: my $idx = 0;
12699: foreach my $itemid (@allpos) {
12700: if ($itemid ne '') {
12701: $confhash{$itemid}{'order'} = $idx;
12702: unless ($changes{$itemid}) {
12703: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12704: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12705: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
12706: $changes{$itemid} = 1;
12707: }
12708: }
12709: }
12710: }
12711: $idx ++;
12712: }
12713: }
12714: }
12715: if (keys(%changes)) {
12716: my %defaultshash = (
12717: ipaccess => \%confhash,
12718: );
12719: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12720: $dom);
12721: if ($putresult eq 'ok') {
12722: my $cachetime = 1800;
12723: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
12724: if (ref($lastactref) eq 'HASH') {
12725: $lastactref->{'ipaccess'} = 1;
12726: }
12727: $resulttext = &mt('Changes made:').'<ul>';
12728: my %bynum;
12729: foreach my $itemid (sort(keys(%changes))) {
12730: if (ref($confhash{$itemid}) eq 'HASH') {
12731: my $position = $confhash{$itemid}{'order'};
12732: if ($position =~ /^\d+$/) {
12733: $bynum{$position} = $itemid;
12734: }
12735: }
12736: }
12737: if (keys(%deletions)) {
12738: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
12739: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12740: }
12741: }
12742: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12743: my $itemid = $bynum{$pos};
12744: if (ref($confhash{$itemid}) eq 'HASH') {
12745: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
12746: my $position = $pos + 1;
12747: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12748: if ($confhash{$itemid}{'ip'} eq '') {
12749: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
12750: } else {
12751: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
12752: }
12753: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
12754: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
12755: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
12756: '</li>';
12757: } else {
12758: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
12759: }
12760: if (keys(%{$confhash{$itemid}{'courses'}})) {
12761: my @courses;
12762: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
12763: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
12764: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
12765: }
12766: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
12767: join('</li><li>',@courses).'</li></ul>';
12768: } else {
12769: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
12770: }
1.395 raeburn 12771: $resulttext .= '</ul></li>';
1.394 raeburn 12772: }
12773: }
1.395 raeburn 12774: $resulttext .= '</ul>';
1.394 raeburn 12775: } else {
12776: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12777: }
12778: } else {
12779: $resulttext = &mt('No changes made');
12780: }
12781: if ($errors) {
12782: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12783: $errors.'</ul></p>';
12784: }
12785: return $resulttext;
12786: }
12787:
12788: sub get_ipaccess_id {
12789: my ($domain,$location) = @_;
12790: # get lock on ipaccess db
12791: my $lockhash = {
12792: lock => $env{'user.name'}.
12793: ':'.$env{'user.domain'},
12794: };
12795: my $tries = 0;
12796: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12797: my ($id,$error);
12798:
12799: while (($gotlock ne 'ok') && ($tries<10)) {
12800: $tries ++;
12801: sleep (0.1);
12802: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12803: }
12804: if ($gotlock eq 'ok') {
12805: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12806: if ($currids{'lock'}) {
12807: delete($currids{'lock'});
12808: if (keys(%currids)) {
12809: my @curr = sort { $a <=> $b } keys(%currids);
12810: if ($curr[-1] =~ /^\d+$/) {
12811: $id = 1 + $curr[-1];
12812: }
12813: } else {
12814: $id = 1;
12815: }
12816: if ($id) {
12817: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12818: $error = 'nostore';
12819: }
12820: } else {
12821: $error = 'nonumber';
12822: }
12823: }
12824: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12825: } else {
12826: $error = 'nolock';
12827: }
12828: return ($id,$error);
12829: }
12830:
1.6 raeburn 12831: sub modify_rolecolors {
1.205 raeburn 12832: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12833: my ($resulttext,%rolehash);
12834: $rolehash{'rolecolors'} = {};
1.55 raeburn 12835: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12836: if ($domconfig{'rolecolors'} eq '') {
12837: $domconfig{'rolecolors'} = {};
12838: }
12839: }
1.9 raeburn 12840: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12841: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12842: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12843: $dom);
12844: if ($putresult eq 'ok') {
12845: if (keys(%changes) > 0) {
1.41 raeburn 12846: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12847: if (ref($lastactref) eq 'HASH') {
12848: $lastactref->{'domainconfig'} = 1;
12849: }
1.6 raeburn 12850: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12851: $rolehash{'rolecolors'});
12852: } else {
12853: $resulttext = &mt('No changes made to default color schemes');
12854: }
12855: } else {
1.11 albertel 12856: $resulttext = '<span class="LC_error">'.
12857: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12858: }
12859: if ($errors) {
12860: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12861: $errors.'</ul>';
12862: }
12863: return $resulttext;
12864: }
12865:
12866: sub modify_colors {
1.9 raeburn 12867: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12868: my (%changes,%choices);
1.51 raeburn 12869: my @bgs;
1.6 raeburn 12870: my @links = ('link','alink','vlink');
1.41 raeburn 12871: my @logintext;
1.6 raeburn 12872: my @images;
12873: my $servadm = $r->dir_config('lonAdmEMail');
12874: my $errors;
1.200 raeburn 12875: my %defaults;
1.6 raeburn 12876: foreach my $role (@{$roles}) {
12877: if ($role eq 'login') {
1.12 raeburn 12878: %choices = &login_choices();
1.41 raeburn 12879: @logintext = ('textcol','bgcol');
1.12 raeburn 12880: } else {
12881: %choices = &color_font_choices();
12882: }
12883: if ($role eq 'login') {
1.41 raeburn 12884: @images = ('img','logo','domlogo','login');
1.51 raeburn 12885: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12886: } else {
12887: @images = ('img');
1.200 raeburn 12888: @bgs = ('pgbg','tabbg','sidebg');
12889: }
12890: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12891: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12892: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12893: }
12894: if ($role eq 'login') {
12895: foreach my $item (@logintext) {
1.234 raeburn 12896: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12897: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12898: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12899: }
12900: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12901: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12902: }
12903: }
12904: } else {
1.234 raeburn 12905: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12906: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12907: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12908: }
12909: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12910: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12911: }
1.6 raeburn 12912: }
1.200 raeburn 12913: foreach my $item (@bgs) {
1.234 raeburn 12914: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12915: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12916: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12917: }
12918: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12919: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12920: }
12921: }
12922: foreach my $item (@links) {
1.234 raeburn 12923: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12924: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12925: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12926: }
12927: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12928: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12929: }
1.6 raeburn 12930: }
1.46 raeburn 12931: my ($configuserok,$author_ok,$switchserver) =
12932: &config_check($dom,$confname,$servadm);
1.9 raeburn 12933: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12934: if (ref($domconfig->{$role}) ne 'HASH') {
12935: $domconfig->{$role} = {};
12936: }
1.8 raeburn 12937: foreach my $img (@images) {
1.402 raeburn 12938: if ($role eq 'login') {
12939: if (($img eq 'img') || ($img eq 'logo')) {
12940: if (defined($env{'form.login_showlogo_'.$img})) {
12941: $confhash->{$role}{'showlogo'}{$img} = 1;
12942: } else {
12943: $confhash->{$role}{'showlogo'}{$img} = 0;
12944: }
12945: }
12946: if ($env{'form.login_alt_'.$img} ne '') {
12947: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 12948: }
1.402 raeburn 12949: }
1.18 albertel 12950: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12951: && !defined($domconfig->{$role}{$img})
12952: && !$env{'form.'.$role.'_del_'.$img}
12953: && $env{'form.'.$role.'_import_'.$img}) {
12954: # import the old configured image from the .tab setting
12955: # if they haven't provided a new one
12956: $domconfig->{$role}{$img} =
12957: $env{'form.'.$role.'_import_'.$img};
12958: }
1.6 raeburn 12959: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12960: my $error;
1.6 raeburn 12961: if ($configuserok eq 'ok') {
1.9 raeburn 12962: if ($switchserver) {
1.12 raeburn 12963: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12964: } else {
12965: if ($author_ok eq 'ok') {
1.421 ! raeburn 12966: my $modified = [];
1.9 raeburn 12967: my ($result,$logourl) =
1.421 ! raeburn 12968: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
! 12969: $dom,$confname,$img,$width,$height,
! 12970: '',$modified);
1.9 raeburn 12971: if ($result eq 'ok') {
12972: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12973: $changes{$role}{'images'}{$img} = 1;
1.421 ! raeburn 12974: &update_modify_urls($r,$modified);
1.9 raeburn 12975: } else {
1.12 raeburn 12976: $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 12977: }
12978: } else {
1.46 raeburn 12979: $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 12980: }
12981: }
12982: } else {
1.46 raeburn 12983: $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 12984: }
12985: if ($error) {
1.8 raeburn 12986: &Apache::lonnet::logthis($error);
1.11 albertel 12987: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12988: }
12989: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12990: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12991: my $error;
12992: if ($configuserok eq 'ok') {
12993: # is confname an author?
12994: if ($switchserver eq '') {
12995: if ($author_ok eq 'ok') {
1.421 ! raeburn 12996: my $modified = [];
1.9 raeburn 12997: my ($result,$logourl) =
1.421 ! raeburn 12998: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
! 12999: $dom,$confname,$img,$width,$height,
! 13000: '',$modified);
1.9 raeburn 13001: if ($result eq 'ok') {
13002: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13003: $changes{$role}{'images'}{$img} = 1;
1.421 ! raeburn 13004: &update_modify_urls($r,$modified);
1.9 raeburn 13005: }
13006: }
13007: }
13008: }
1.6 raeburn 13009: }
13010: }
13011: }
13012: if (ref($domconfig) eq 'HASH') {
13013: if (ref($domconfig->{$role}) eq 'HASH') {
13014: foreach my $img (@images) {
13015: if ($domconfig->{$role}{$img} ne '') {
13016: if ($env{'form.'.$role.'_del_'.$img}) {
13017: $confhash->{$role}{$img} = '';
1.12 raeburn 13018: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13019: } else {
1.9 raeburn 13020: if ($confhash->{$role}{$img} eq '') {
13021: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13022: }
1.6 raeburn 13023: }
13024: } else {
13025: if ($env{'form.'.$role.'_del_'.$img}) {
13026: $confhash->{$role}{$img} = '';
1.12 raeburn 13027: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13028: }
13029: }
1.402 raeburn 13030: if ($role eq 'login') {
13031: if (($img eq 'logo') || ($img eq 'img')) {
13032: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13033: if ($confhash->{$role}{'showlogo'}{$img} ne
13034: $domconfig->{$role}{'showlogo'}{$img}) {
13035: $changes{$role}{'showlogo'}{$img} = 1;
13036: }
13037: } else {
13038: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13039: $changes{$role}{'showlogo'}{$img} = 1;
13040: }
1.70 raeburn 13041: }
1.402 raeburn 13042: }
13043: if ($img ne 'login') {
13044: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13045: if ($confhash->{$role}{'alttext'}{$img} ne
13046: $domconfig->{$role}{'alttext'}{$img}) {
13047: $changes{$role}{'alttext'}{$img} = 1;
13048: }
13049: } else {
13050: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13051: $changes{$role}{'alttext'}{$img} = 1;
13052: }
1.70 raeburn 13053: }
13054: }
13055: }
13056: }
1.6 raeburn 13057: if ($domconfig->{$role}{'font'} ne '') {
13058: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13059: $changes{$role}{'font'} = 1;
13060: }
13061: } else {
13062: if ($confhash->{$role}{'font'}) {
13063: $changes{$role}{'font'} = 1;
13064: }
13065: }
1.107 raeburn 13066: if ($role ne 'login') {
13067: if ($domconfig->{$role}{'fontmenu'} ne '') {
13068: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13069: $changes{$role}{'fontmenu'} = 1;
13070: }
13071: } else {
13072: if ($confhash->{$role}{'fontmenu'}) {
13073: $changes{$role}{'fontmenu'} = 1;
13074: }
1.97 tempelho 13075: }
13076: }
1.6 raeburn 13077: foreach my $item (@bgs) {
13078: if ($domconfig->{$role}{$item} ne '') {
13079: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13080: $changes{$role}{'bgs'}{$item} = 1;
13081: }
13082: } else {
13083: if ($confhash->{$role}{$item}) {
13084: $changes{$role}{'bgs'}{$item} = 1;
13085: }
13086: }
13087: }
13088: foreach my $item (@links) {
13089: if ($domconfig->{$role}{$item} ne '') {
13090: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13091: $changes{$role}{'links'}{$item} = 1;
13092: }
13093: } else {
13094: if ($confhash->{$role}{$item}) {
13095: $changes{$role}{'links'}{$item} = 1;
13096: }
13097: }
13098: }
1.41 raeburn 13099: foreach my $item (@logintext) {
13100: if ($domconfig->{$role}{$item} ne '') {
13101: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13102: $changes{$role}{'logintext'}{$item} = 1;
13103: }
13104: } else {
13105: if ($confhash->{$role}{$item}) {
13106: $changes{$role}{'logintext'}{$item} = 1;
13107: }
13108: }
13109: }
1.6 raeburn 13110: } else {
13111: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13112: \@logintext,$confhash,\%changes);
1.6 raeburn 13113: }
13114: } else {
13115: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13116: \@logintext,$confhash,\%changes);
1.6 raeburn 13117: }
13118: }
13119: return ($errors,%changes);
13120: }
13121:
1.46 raeburn 13122: sub config_check {
13123: my ($dom,$confname,$servadm) = @_;
13124: my ($configuserok,$author_ok,$switchserver,%currroles);
13125: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13126: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13127: $confname,$servadm);
13128: if ($configuserok eq 'ok') {
13129: $switchserver = &check_switchserver($dom,$confname);
13130: if ($switchserver eq '') {
13131: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13132: }
13133: }
13134: return ($configuserok,$author_ok,$switchserver);
13135: }
13136:
1.6 raeburn 13137: sub default_change_checker {
1.41 raeburn 13138: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13139: foreach my $item (@{$links}) {
13140: if ($confhash->{$role}{$item}) {
13141: $changes->{$role}{'links'}{$item} = 1;
13142: }
13143: }
13144: foreach my $item (@{$bgs}) {
13145: if ($confhash->{$role}{$item}) {
13146: $changes->{$role}{'bgs'}{$item} = 1;
13147: }
13148: }
1.41 raeburn 13149: foreach my $item (@{$logintext}) {
13150: if ($confhash->{$role}{$item}) {
13151: $changes->{$role}{'logintext'}{$item} = 1;
13152: }
13153: }
1.6 raeburn 13154: foreach my $img (@{$images}) {
13155: if ($env{'form.'.$role.'_del_'.$img}) {
13156: $confhash->{$role}{$img} = '';
1.12 raeburn 13157: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13158: }
1.70 raeburn 13159: if ($role eq 'login') {
13160: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13161: $changes->{$role}{'showlogo'}{$img} = 1;
13162: }
1.402 raeburn 13163: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13164: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13165: $changes->{$role}{'alttext'}{$img} = 1;
13166: }
13167: }
1.70 raeburn 13168: }
1.6 raeburn 13169: }
13170: if ($confhash->{$role}{'font'}) {
13171: $changes->{$role}{'font'} = 1;
13172: }
1.48 raeburn 13173: }
1.6 raeburn 13174:
13175: sub display_colorchgs {
13176: my ($dom,$changes,$roles,$confhash) = @_;
13177: my (%choices,$resulttext);
13178: if (!grep(/^login$/,@{$roles})) {
13179: $resulttext = &mt('Changes made:').'<br />';
13180: }
13181: foreach my $role (@{$roles}) {
13182: if ($role eq 'login') {
13183: %choices = &login_choices();
13184: } else {
13185: %choices = &color_font_choices();
13186: }
13187: if (ref($changes->{$role}) eq 'HASH') {
13188: if ($role ne 'login') {
13189: $resulttext .= '<h4>'.&mt($role).'</h4>';
13190: }
13191: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13192: if ($role ne 'login') {
13193: $resulttext .= '<ul>';
13194: }
13195: if (ref($changes->{$role}{$key}) eq 'HASH') {
13196: if ($role ne 'login') {
13197: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13198: }
13199: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13200: if (($role eq 'login') && ($key eq 'showlogo')) {
13201: if ($confhash->{$role}{$key}{$item}) {
13202: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13203: } else {
13204: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13205: }
1.402 raeburn 13206: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13207: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13208: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13209: $confhash->{$role}{$key}{$item}).'</li>';
13210: } else {
13211: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13212: }
1.70 raeburn 13213: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13214: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13215: } else {
1.12 raeburn 13216: my $newitem = $confhash->{$role}{$item};
13217: if ($key eq 'images') {
1.306 raeburn 13218: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13219: }
13220: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13221: }
13222: }
13223: if ($role ne 'login') {
13224: $resulttext .= '</ul></li>';
13225: }
13226: } else {
13227: if ($confhash->{$role}{$key} eq '') {
13228: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13229: } else {
13230: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13231: }
13232: }
13233: if ($role ne 'login') {
13234: $resulttext .= '</ul>';
13235: }
13236: }
13237: }
13238: }
1.3 raeburn 13239: return $resulttext;
1.1 raeburn 13240: }
13241:
1.9 raeburn 13242: sub thumb_dimensions {
13243: return ('200','50');
13244: }
13245:
1.16 raeburn 13246: sub check_dimensions {
13247: my ($inputfile) = @_;
13248: my ($fullwidth,$fullheight);
13249: if ($inputfile =~ m|^[/\w.\-]+$|) {
13250: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13251: my $imageinfo = <PIPE>;
13252: if (!close(PIPE)) {
13253: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13254: }
13255: chomp($imageinfo);
13256: my ($fullsize) =
1.21 raeburn 13257: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13258: if ($fullsize) {
13259: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13260: }
13261: }
13262: }
13263: return ($fullwidth,$fullheight);
13264: }
13265:
1.9 raeburn 13266: sub check_configuser {
13267: my ($uhome,$dom,$confname,$servadm) = @_;
13268: my ($configuserok,%currroles);
13269: if ($uhome eq 'no_host') {
13270: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13271: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13272: $configuserok =
13273: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13274: $configpass,'','','','','',undef,$servadm);
13275: } else {
13276: $configuserok = 'ok';
13277: %currroles =
13278: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13279: }
13280: return ($configuserok,%currroles);
13281: }
13282:
13283: sub check_authorstatus {
13284: my ($dom,$confname,%currroles) = @_;
13285: my $author_ok;
1.40 raeburn 13286: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13287: my $start = time;
13288: my $end = 0;
13289: $author_ok =
13290: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13291: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13292: } else {
13293: $author_ok = 'ok';
13294: }
13295: return $author_ok;
13296: }
13297:
1.421 ! raeburn 13298: sub update_modify_urls {
! 13299: my ($r,$modified) = @_;
! 13300: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
! 13301: push(@{$modified_urls},$modified);
! 13302: unless ($registered_cleanup) {
! 13303: my $handlers = $r->get_handlers('PerlCleanupHandler');
! 13304: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
! 13305: $registered_cleanup=1;
1.9 raeburn 13306: }
13307: }
1.155 raeburn 13308: }
13309:
13310: sub notifysubscribed {
13311: foreach my $targetsource (@{$modified_urls}){
13312: next unless (ref($targetsource) eq 'ARRAY');
13313: my ($target,$source)=@{$targetsource};
13314: if ($source ne '') {
1.316 raeburn 13315: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13316: print $logfh "\nCleanup phase: Notifications\n";
13317: my @subscribed=&subscribed_hosts($target);
13318: foreach my $subhost (@subscribed) {
13319: print $logfh "\nNotifying host ".$subhost.':';
13320: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13321: print $logfh $reply;
13322: }
13323: my @subscribedmeta=&subscribed_hosts("$target.meta");
13324: foreach my $subhost (@subscribedmeta) {
13325: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13326: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13327: $subhost);
13328: print $logfh $reply;
13329: }
13330: print $logfh "\n============ Done ============\n";
1.160 raeburn 13331: close($logfh);
1.155 raeburn 13332: }
13333: }
13334: }
13335: return OK;
13336: }
13337:
13338: sub subscribed_hosts {
13339: my ($target) = @_;
13340: my @subscribed;
1.316 raeburn 13341: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13342: while (my $subline=<$fh>) {
13343: if ($subline =~ /^($match_lonid):/) {
13344: my $host = $1;
13345: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13346: unless (grep(/^\Q$host\E$/,@subscribed)) {
13347: push(@subscribed,$host);
13348: }
13349: }
13350: }
13351: }
13352: }
13353: return @subscribed;
1.9 raeburn 13354: }
13355:
13356: sub check_switchserver {
13357: my ($dom,$confname) = @_;
13358: my ($allowed,$switchserver);
13359: my $home = &Apache::lonnet::homeserver($confname,$dom);
13360: if ($home eq 'no_host') {
13361: $home = &Apache::lonnet::domain($dom,'primary');
13362: }
13363: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 13364: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
13365: if (!$allowed) {
1.180 raeburn 13366: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 13367: }
13368: return $switchserver;
13369: }
13370:
1.1 raeburn 13371: sub modify_quotas {
1.216 raeburn 13372: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 13373: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 13374: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 13375: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
13376: $validationfieldsref);
1.86 raeburn 13377: if ($action eq 'quotas') {
13378: $context = 'tools';
1.163 raeburn 13379: } else {
1.86 raeburn 13380: $context = $action;
13381: }
13382: if ($context eq 'requestcourses') {
1.325 raeburn 13383: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 13384: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 13385: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
13386: %titles = &courserequest_titles();
13387: $toolregexp = join('|',@usertools);
13388: %conditions = &courserequest_conditions();
1.216 raeburn 13389: $confname = $dom.'-domainconfig';
13390: my $servadm = $r->dir_config('lonAdmEMail');
13391: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 13392: ($validationitemsref,$validationnamesref,$validationfieldsref) =
13393: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 13394: } elsif ($context eq 'requestauthor') {
13395: @usertools = ('author');
13396: %titles = &authorrequest_titles();
1.86 raeburn 13397: } else {
1.413 raeburn 13398: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 13399: %titles = &tool_titles();
1.86 raeburn 13400: }
1.212 raeburn 13401: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 13402: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13403: foreach my $key (keys(%env)) {
1.101 raeburn 13404: if ($context eq 'requestcourses') {
13405: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
13406: my $item = $1;
13407: my $type = $2;
13408: if ($type =~ /^limit_(.+)/) {
13409: $limithash{$item}{$1} = $env{$key};
13410: } else {
13411: $confhash{$item}{$type} = $env{$key};
13412: }
13413: }
1.163 raeburn 13414: } elsif ($context eq 'requestauthor') {
13415: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
13416: $confhash{$1} = $env{$key};
13417: }
1.101 raeburn 13418: } else {
1.86 raeburn 13419: if ($key =~ /^form\.quota_(.+)$/) {
13420: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 13421: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
13422: $confhash{'authorquota'}{$1} = $env{$key};
13423: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 13424: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
13425: }
1.72 raeburn 13426: }
13427: }
1.163 raeburn 13428: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 13429: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 13430: @approvalnotify = sort(@approvalnotify);
13431: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 13432: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 13433: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
13434: foreach my $type (@hasuniquecode) {
13435: if (grep(/^\Q$type\E$/,@crstypes)) {
13436: $confhash{'uniquecode'}{$type} = 1;
13437: }
1.216 raeburn 13438: }
1.242 raeburn 13439: my (%newbook,%allpos);
1.216 raeburn 13440: if ($context eq 'requestcourses') {
1.242 raeburn 13441: foreach my $type ('textbooks','templates') {
13442: @{$allpos{$type}} = ();
13443: my $invalid;
13444: if ($type eq 'textbooks') {
13445: $invalid = &mt('Invalid LON-CAPA course for textbook');
13446: } else {
13447: $invalid = &mt('Invalid LON-CAPA course for template');
13448: }
13449: if ($env{'form.'.$type.'_addbook'}) {
13450: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
13451: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
13452: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
13453: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
13454: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
13455: } else {
13456: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
13457: my $position = $env{'form.'.$type.'_addbook_pos'};
13458: $position =~ s/\D+//g;
13459: if ($position ne '') {
13460: $allpos{$type}[$position] = $newbook{$type};
13461: }
1.216 raeburn 13462: }
1.242 raeburn 13463: } else {
13464: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 13465: }
13466: }
1.242 raeburn 13467: }
1.216 raeburn 13468: }
1.102 raeburn 13469: if (ref($domconfig{$action}) eq 'HASH') {
13470: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
13471: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
13472: $changes{'notify'}{'approval'} = 1;
13473: }
13474: } else {
1.144 raeburn 13475: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13476: $changes{'notify'}{'approval'} = 1;
13477: }
13478: }
1.218 raeburn 13479: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
13480: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13481: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
13482: unless ($confhash{'uniquecode'}{$crstype}) {
13483: $changes{'uniquecode'} = 1;
13484: }
13485: }
13486: unless ($changes{'uniquecode'}) {
13487: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
13488: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
13489: $changes{'uniquecode'} = 1;
13490: }
13491: }
13492: }
13493: } else {
13494: $changes{'uniquecode'} = 1;
13495: }
13496: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
13497: $changes{'uniquecode'} = 1;
1.216 raeburn 13498: }
13499: if ($context eq 'requestcourses') {
1.242 raeburn 13500: foreach my $type ('textbooks','templates') {
13501: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13502: my %deletions;
13503: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
13504: if (@todelete) {
13505: map { $deletions{$_} = 1; } @todelete;
13506: }
13507: my %imgdeletions;
13508: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
13509: if (@todeleteimages) {
13510: map { $imgdeletions{$_} = 1; } @todeleteimages;
13511: }
13512: my $maxnum = $env{'form.'.$type.'_maxnum'};
13513: for (my $i=0; $i<=$maxnum; $i++) {
13514: my $itemid = $env{'form.'.$type.'_id_'.$i};
13515: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13516: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13517: if ($deletions{$key}) {
13518: if ($domconfig{$action}{$type}{$key}{'image'}) {
13519: #FIXME need to obsolete item in RES space
13520: }
13521: next;
13522: } else {
13523: my $newpos = $env{'form.'.$itemid};
13524: $newpos =~ s/\D+//g;
1.243 raeburn 13525: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13526: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13527: ($type eq 'templates'));
1.242 raeburn 13528: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13529: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13530: $changes{$type}{$key} = 1;
13531: }
13532: }
13533: $allpos{$type}[$newpos] = $key;
13534: }
13535: if ($imgdeletions{$key}) {
13536: $changes{$type}{$key} = 1;
1.216 raeburn 13537: #FIXME need to obsolete item in RES space
1.242 raeburn 13538: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13539: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13540: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13541: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13542: } else {
13543: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13544: $cdom,$cnum,$type,$configuserok,
13545: $switchserver,$author_ok);
13546: if ($imgurl) {
13547: $confhash{$type}{$key}{'image'} = $imgurl;
13548: $changes{$type}{$key} = 1;
13549: }
13550: if ($error) {
13551: &Apache::lonnet::logthis($error);
13552: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13553: }
13554: }
1.242 raeburn 13555: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13556: $confhash{$type}{$key}{'image'} =
13557: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13558: }
13559: }
13560: }
13561: }
13562: }
13563: }
1.102 raeburn 13564: } else {
1.144 raeburn 13565: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13566: $changes{'notify'}{'approval'} = 1;
13567: }
1.218 raeburn 13568: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13569: $changes{'uniquecode'} = 1;
13570: }
13571: }
13572: if ($context eq 'requestcourses') {
1.242 raeburn 13573: foreach my $type ('textbooks','templates') {
13574: if ($newbook{$type}) {
13575: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13576: foreach my $item ('subject','title','publisher','author') {
13577: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13578: ($type eq 'template'));
1.242 raeburn 13579: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13580: if ($env{'form.'.$type.'_addbook_'.$item}) {
13581: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13582: }
13583: }
13584: if ($type eq 'textbooks') {
13585: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13586: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13587: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13588: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13589: } else {
13590: my ($imageurl,$error) =
13591: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13592: $configuserok,$switchserver,$author_ok);
13593: if ($imageurl) {
13594: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13595: }
13596: if ($error) {
13597: &Apache::lonnet::logthis($error);
13598: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13599: }
1.242 raeburn 13600: }
13601: }
1.216 raeburn 13602: }
13603: }
1.242 raeburn 13604: if (@{$allpos{$type}} > 0) {
13605: my $idx = 0;
13606: foreach my $item (@{$allpos{$type}}) {
13607: if ($item ne '') {
13608: $confhash{$type}{$item}{'order'} = $idx;
13609: if (ref($domconfig{$action}) eq 'HASH') {
13610: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13611: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13612: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13613: $changes{$type}{$item} = 1;
13614: }
1.216 raeburn 13615: }
13616: }
13617: }
1.242 raeburn 13618: $idx ++;
1.216 raeburn 13619: }
13620: }
13621: }
13622: }
1.235 raeburn 13623: if (ref($validationitemsref) eq 'ARRAY') {
13624: foreach my $item (@{$validationitemsref}) {
13625: if ($item eq 'fields') {
13626: my @changed;
13627: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13628: if (@{$confhash{'validation'}{$item}} > 0) {
13629: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13630: }
1.266 raeburn 13631: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13632: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13633: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13634: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13635: $domconfig{'requestcourses'}{'validation'}{$item});
13636: } else {
13637: @changed = @{$confhash{'validation'}{$item}};
13638: }
1.235 raeburn 13639: } else {
13640: @changed = @{$confhash{'validation'}{$item}};
13641: }
13642: } else {
13643: @changed = @{$confhash{'validation'}{$item}};
13644: }
13645: if (@changed) {
13646: if ($confhash{'validation'}{$item}) {
13647: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13648: } else {
13649: $changes{'validation'}{$item} = &mt('None');
13650: }
13651: }
13652: } else {
13653: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13654: if ($item eq 'markup') {
13655: if ($env{'form.requestcourses_validation_'.$item}) {
13656: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13657: }
13658: }
1.266 raeburn 13659: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13660: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13661: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13662: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13663: }
13664: } else {
13665: if ($confhash{'validation'}{$item} ne '') {
13666: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13667: }
1.235 raeburn 13668: }
13669: } else {
13670: if ($confhash{'validation'}{$item} ne '') {
13671: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13672: }
13673: }
13674: }
13675: }
13676: }
13677: if ($env{'form.validationdc'}) {
13678: my $newval = $env{'form.validationdc'};
1.285 raeburn 13679: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13680: if (exists($domcoords{$newval})) {
13681: $confhash{'validation'}{'dc'} = $newval;
13682: }
13683: }
13684: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13685: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13686: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13687: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13688: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13689: if ($confhash{'validation'}{'dc'} eq '') {
13690: $changes{'validation'}{'dc'} = &mt('None');
13691: } else {
13692: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13693: }
1.235 raeburn 13694: }
1.266 raeburn 13695: } elsif ($confhash{'validation'}{'dc'} ne '') {
13696: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13697: }
13698: } elsif ($confhash{'validation'}{'dc'} ne '') {
13699: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13700: }
13701: } elsif ($confhash{'validation'}{'dc'} ne '') {
13702: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13703: }
1.266 raeburn 13704: } else {
13705: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13706: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13707: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13708: $changes{'validation'}{'dc'} = &mt('None');
13709: }
13710: }
1.235 raeburn 13711: }
13712: }
1.102 raeburn 13713: }
13714: } else {
1.86 raeburn 13715: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13716: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13717: }
1.72 raeburn 13718: foreach my $item (@usertools) {
13719: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13720: my $unset;
1.101 raeburn 13721: if ($context eq 'requestcourses') {
1.104 raeburn 13722: $unset = '0';
13723: if ($type eq '_LC_adv') {
13724: $unset = '';
13725: }
1.101 raeburn 13726: if ($confhash{$item}{$type} eq 'autolimit') {
13727: $confhash{$item}{$type} .= '=';
13728: unless ($limithash{$item}{$type} =~ /\D/) {
13729: $confhash{$item}{$type} .= $limithash{$item}{$type};
13730: }
13731: }
1.163 raeburn 13732: } elsif ($context eq 'requestauthor') {
13733: $unset = '0';
13734: if ($type eq '_LC_adv') {
13735: $unset = '';
13736: }
1.72 raeburn 13737: } else {
1.101 raeburn 13738: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13739: $confhash{$item}{$type} = 1;
13740: } else {
13741: $confhash{$item}{$type} = 0;
13742: }
1.72 raeburn 13743: }
1.86 raeburn 13744: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13745: if ($action eq 'requestauthor') {
13746: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13747: $changes{$type} = 1;
13748: }
13749: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13750: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13751: $changes{$item}{$type} = 1;
13752: }
13753: } else {
13754: if ($context eq 'requestcourses') {
1.104 raeburn 13755: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13756: $changes{$item}{$type} = 1;
13757: }
13758: } else {
13759: if (!$confhash{$item}{$type}) {
13760: $changes{$item}{$type} = 1;
13761: }
13762: }
13763: }
13764: } else {
13765: if ($context eq 'requestcourses') {
1.104 raeburn 13766: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13767: $changes{$item}{$type} = 1;
13768: }
1.163 raeburn 13769: } elsif ($context eq 'requestauthor') {
13770: if ($confhash{$type} ne $unset) {
13771: $changes{$type} = 1;
13772: }
1.72 raeburn 13773: } else {
13774: if (!$confhash{$item}{$type}) {
13775: $changes{$item}{$type} = 1;
13776: }
13777: }
13778: }
1.1 raeburn 13779: }
13780: }
1.163 raeburn 13781: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13782: if (ref($domconfig{'quotas'}) eq 'HASH') {
13783: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13784: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13785: if (exists($confhash{'defaultquota'}{$key})) {
13786: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13787: $changes{'defaultquota'}{$key} = 1;
13788: }
13789: } else {
13790: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13791: }
13792: }
1.86 raeburn 13793: } else {
13794: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13795: if (exists($confhash{'defaultquota'}{$key})) {
13796: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13797: $changes{'defaultquota'}{$key} = 1;
13798: }
13799: } else {
13800: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13801: }
1.1 raeburn 13802: }
13803: }
1.197 raeburn 13804: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13805: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13806: if (exists($confhash{'authorquota'}{$key})) {
13807: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13808: $changes{'authorquota'}{$key} = 1;
13809: }
13810: } else {
13811: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13812: }
13813: }
13814: }
1.1 raeburn 13815: }
1.86 raeburn 13816: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13817: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13818: if (ref($domconfig{'quotas'}) eq 'HASH') {
13819: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13820: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13821: $changes{'defaultquota'}{$key} = 1;
13822: }
13823: } else {
13824: if (!exists($domconfig{'quotas'}{$key})) {
13825: $changes{'defaultquota'}{$key} = 1;
13826: }
1.72 raeburn 13827: }
13828: } else {
1.86 raeburn 13829: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13830: }
1.1 raeburn 13831: }
13832: }
1.197 raeburn 13833: if (ref($confhash{'authorquota'}) eq 'HASH') {
13834: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13835: if (ref($domconfig{'quotas'}) eq 'HASH') {
13836: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13837: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13838: $changes{'authorquota'}{$key} = 1;
13839: }
13840: } else {
13841: $changes{'authorquota'}{$key} = 1;
13842: }
13843: } else {
13844: $changes{'authorquota'}{$key} = 1;
13845: }
13846: }
13847: }
1.1 raeburn 13848: }
1.72 raeburn 13849:
1.163 raeburn 13850: if ($context eq 'requestauthor') {
13851: $domdefaults{'requestauthor'} = \%confhash;
13852: } else {
13853: foreach my $key (keys(%confhash)) {
1.242 raeburn 13854: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13855: $domdefaults{$key} = $confhash{$key};
13856: }
1.163 raeburn 13857: }
1.72 raeburn 13858: }
1.163 raeburn 13859:
1.1 raeburn 13860: my %quotahash = (
1.86 raeburn 13861: $action => { %confhash }
1.1 raeburn 13862: );
13863: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13864: $dom);
13865: if ($putresult eq 'ok') {
13866: if (keys(%changes) > 0) {
1.72 raeburn 13867: my $cachetime = 24*60*60;
13868: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13869: if (ref($lastactref) eq 'HASH') {
13870: $lastactref->{'domdefaults'} = 1;
13871: }
1.1 raeburn 13872: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13873: unless (($context eq 'requestcourses') ||
1.163 raeburn 13874: ($context eq 'requestauthor')) {
1.86 raeburn 13875: if (ref($changes{'defaultquota'}) eq 'HASH') {
13876: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13877: foreach my $type (@{$types},'default') {
13878: if (defined($changes{'defaultquota'}{$type})) {
13879: my $typetitle = $usertypes->{$type};
13880: if ($type eq 'default') {
13881: $typetitle = $othertitle;
13882: }
1.213 raeburn 13883: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13884: }
13885: }
1.86 raeburn 13886: $resulttext .= '</ul></li>';
1.72 raeburn 13887: }
1.197 raeburn 13888: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13889: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13890: foreach my $type (@{$types},'default') {
13891: if (defined($changes{'authorquota'}{$type})) {
13892: my $typetitle = $usertypes->{$type};
13893: if ($type eq 'default') {
13894: $typetitle = $othertitle;
13895: }
1.213 raeburn 13896: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13897: }
13898: }
13899: $resulttext .= '</ul></li>';
13900: }
1.72 raeburn 13901: }
1.80 raeburn 13902: my %newenv;
1.72 raeburn 13903: foreach my $item (@usertools) {
1.163 raeburn 13904: my (%haschgs,%inconf);
13905: if ($context eq 'requestauthor') {
13906: %haschgs = %changes;
1.210 raeburn 13907: %inconf = %confhash;
1.163 raeburn 13908: } else {
13909: if (ref($changes{$item}) eq 'HASH') {
13910: %haschgs = %{$changes{$item}};
13911: }
13912: if (ref($confhash{$item}) eq 'HASH') {
13913: %inconf = %{$confhash{$item}};
13914: }
13915: }
13916: if (keys(%haschgs) > 0) {
1.80 raeburn 13917: my $newacc =
13918: &Apache::lonnet::usertools_access($env{'user.name'},
13919: $env{'user.domain'},
1.86 raeburn 13920: $item,'reload',$context);
1.210 raeburn 13921: if (($context eq 'requestcourses') ||
1.163 raeburn 13922: ($context eq 'requestauthor')) {
1.108 raeburn 13923: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13924: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13925: }
13926: } else {
13927: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13928: $newenv{'environment.availabletools.'.$item} = $newacc;
13929: }
1.80 raeburn 13930: }
1.163 raeburn 13931: unless ($context eq 'requestauthor') {
13932: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13933: }
1.72 raeburn 13934: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 13935: if ($haschgs{$type}) {
1.72 raeburn 13936: my $typetitle = $usertypes->{$type};
13937: if ($type eq 'default') {
13938: $typetitle = $othertitle;
13939: } elsif ($type eq '_LC_adv') {
13940: $typetitle = 'LON-CAPA Advanced Users';
13941: }
1.163 raeburn 13942: if ($inconf{$type}) {
1.101 raeburn 13943: if ($context eq 'requestcourses') {
13944: my $cond;
1.163 raeburn 13945: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13946: if ($1 eq '') {
13947: $cond = &mt('(Automatic processing of any request).');
13948: } else {
13949: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13950: }
13951: } else {
1.163 raeburn 13952: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13953: }
13954: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 13955: } elsif ($context eq 'requestauthor') {
13956: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13957: $titles{$inconf{$type}},$typetitle);
13958:
1.101 raeburn 13959: } else {
13960: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13961: }
1.72 raeburn 13962: } else {
1.104 raeburn 13963: if ($type eq '_LC_adv') {
1.163 raeburn 13964: if ($inconf{$type} eq '0') {
1.104 raeburn 13965: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13966: } else {
13967: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13968: }
13969: } else {
13970: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13971: }
1.72 raeburn 13972: }
13973: }
1.26 raeburn 13974: }
1.163 raeburn 13975: unless ($context eq 'requestauthor') {
13976: $resulttext .= '</ul></li>';
13977: }
1.26 raeburn 13978: }
1.1 raeburn 13979: }
1.163 raeburn 13980: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13981: if (ref($changes{'notify'}) eq 'HASH') {
13982: if ($changes{'notify'}{'approval'}) {
13983: if (ref($confhash{'notify'}) eq 'HASH') {
13984: if ($confhash{'notify'}{'approval'}) {
13985: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13986: } else {
1.163 raeburn 13987: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13988: }
13989: }
13990: }
13991: }
13992: }
1.216 raeburn 13993: if ($action eq 'requestcourses') {
13994: my @offon = ('off','on');
13995: if ($changes{'uniquecode'}) {
1.218 raeburn 13996: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13997: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13998: $resulttext .= '<li>'.
13999: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14000: '</li>';
14001: } else {
14002: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14003: '</li>';
14004: }
1.216 raeburn 14005: }
1.242 raeburn 14006: foreach my $type ('textbooks','templates') {
14007: if (ref($changes{$type}) eq 'HASH') {
14008: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14009: foreach my $key (sort(keys(%{$changes{$type}}))) {
14010: my %coursehash = &Apache::lonnet::coursedescription($key);
14011: my $coursetitle = $coursehash{'description'};
14012: my $position = $confhash{$type}{$key}{'order'} + 1;
14013: $resulttext .= '<li>';
1.243 raeburn 14014: foreach my $item ('subject','title','publisher','author') {
14015: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14016: ($type eq 'templates'));
1.242 raeburn 14017: my $name = $item.':';
14018: $name =~ s/^(\w)/\U$1/;
14019: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14020: }
14021: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14022: if ($type eq 'textbooks') {
14023: if ($confhash{$type}{$key}{'image'}) {
14024: $resulttext .= ' '.&mt('Image: [_1]',
14025: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14026: ' alt="Textbook cover" />').'<br />';
14027: }
14028: }
14029: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14030: }
1.242 raeburn 14031: $resulttext .= '</ul></li>';
1.216 raeburn 14032: }
14033: }
1.235 raeburn 14034: if (ref($changes{'validation'}) eq 'HASH') {
14035: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14036: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14037: foreach my $item (@{$validationitemsref}) {
14038: if (exists($changes{'validation'}{$item})) {
14039: if ($item eq 'markup') {
14040: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14041: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14042: } else {
14043: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14044: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14045: }
14046: }
14047: }
14048: if (exists($changes{'validation'}{'dc'})) {
14049: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14050: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14051: }
14052: }
14053: }
1.216 raeburn 14054: }
1.1 raeburn 14055: $resulttext .= '</ul>';
1.80 raeburn 14056: if (keys(%newenv)) {
14057: &Apache::lonnet::appenv(\%newenv);
14058: }
1.1 raeburn 14059: } else {
1.86 raeburn 14060: if ($context eq 'requestcourses') {
14061: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14062: } elsif ($context eq 'requestauthor') {
14063: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14064: } else {
1.90 weissno 14065: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14066: }
1.1 raeburn 14067: }
14068: } else {
1.11 albertel 14069: $resulttext = '<span class="LC_error">'.
14070: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14071: }
1.216 raeburn 14072: if ($errors) {
14073: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14074: '<ul>'.$errors.'</ul></p>';
14075: }
1.3 raeburn 14076: return $resulttext;
1.1 raeburn 14077: }
14078:
1.216 raeburn 14079: sub process_textbook_image {
1.242 raeburn 14080: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14081: my $filename = $env{'form.'.$caller.'.filename'};
14082: my ($error,$url);
14083: my ($width,$height) = (50,50);
14084: if ($configuserok eq 'ok') {
14085: if ($switchserver) {
14086: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14087: $switchserver);
14088: } elsif ($author_ok eq 'ok') {
1.421 ! raeburn 14089: my $modified = [];
1.216 raeburn 14090: my ($result,$imageurl) =
1.421 ! raeburn 14091: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
! 14092: "$type/$cdom/$cnum/cover",$width,$height,
! 14093: '',$modified);
1.216 raeburn 14094: if ($result eq 'ok') {
14095: $url = $imageurl;
1.421 ! raeburn 14096: &update_modify_urls($r,$modified);
1.216 raeburn 14097: } else {
14098: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14099: }
14100: } else {
14101: $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);
14102: }
14103: } else {
14104: $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);
14105: }
14106: return ($url,$error);
14107: }
14108:
1.267 raeburn 14109: sub modify_ltitools {
14110: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 ! raeburn 14111: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
! 14112: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
! 14113:
1.267 raeburn 14114: my $confname = $dom.'-domainconfig';
14115: my $servadm = $r->dir_config('lonAdmEMail');
14116: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 ! raeburn 14117:
! 14118: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
! 14119: my $toolserror =
! 14120: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
! 14121: $lastactref,$configuserok,$switchserver,$author_ok);
! 14122:
! 14123: my $home = &Apache::lonnet::domain($dom,'primary');
! 14124: unless (($home eq 'no_host') || ($home eq '')) {
! 14125: my @ids=&Apache::lonnet::current_machine_ids();
! 14126: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
! 14127: }
! 14128:
! 14129: if (keys(%ltitoolschg)) {
! 14130: foreach my $id (keys(%ltitoolschg)) {
! 14131: if (ref($ltitoolschg{$id}) eq 'HASH') {
! 14132: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
! 14133: if (($inner eq 'secret') || ($inner eq 'key')) {
! 14134: if ($is_home) {
! 14135: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
! 14136: }
! 14137: }
! 14138: }
1.267 raeburn 14139: }
1.421 ! raeburn 14140: }
! 14141: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
! 14142: if (keys(%ltitoolschg)) {
! 14143: %newltitools = %ltitoolschg;
! 14144: }
! 14145: }
! 14146: if (ref($domconfig{'ltitools'}) eq 'HASH') {
! 14147: foreach my $id (%{$domconfig{'ltitools'}}) {
! 14148: next if ($id !~ /^\d+$/);
! 14149: unless (exists($ltitoolschg{$id})) {
! 14150: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
! 14151: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
! 14152: if (($inner eq 'secret') || ($inner eq 'key')) {
! 14153: if ($is_home) {
! 14154: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
! 14155: }
! 14156: } else {
! 14157: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
! 14158: }
! 14159: }
! 14160: } else {
! 14161: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14162: }
1.421 ! raeburn 14163: }
! 14164: }
! 14165: }
! 14166: if ($toolserror) {
! 14167: $errors = '<li>'.$toolserror.'</li>';
! 14168: }
! 14169: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
! 14170: $resulttext = &mt('No changes made.');
! 14171: if ($errors) {
! 14172: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
! 14173: $errors.'</ul>';
! 14174: }
! 14175: return $resulttext;
! 14176: }
! 14177: my %ltitoolshash = (
! 14178: $action => { %newltitools }
! 14179: );
! 14180: if (keys(%secchanges)) {
! 14181: $ltitoolshash{'toolsec'} = \%newtoolsec;
! 14182: }
! 14183: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
! 14184: if ($putresult eq 'ok') {
! 14185: my %keystore;
! 14186: if ($is_home) {
! 14187: my %toolsenchash = (
! 14188: $action => { %newtoolsenc }
! 14189: );
! 14190: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
! 14191: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
! 14192: }
! 14193: $resulttext = &mt('Changes made:').'<ul>';
! 14194: if (keys(%secchanges) > 0) {
! 14195: $resulttext .= <i_security_results('ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
! 14196: }
! 14197: if (keys(%ltitoolschg) > 0) {
! 14198: $resulttext .= $ltitoolsoutput;
! 14199: }
! 14200: } else {
! 14201: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
! 14202: }
! 14203: if ($errors) {
! 14204: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
! 14205: $errors.'</ul></p>';
! 14206: }
! 14207: return $resulttext;
! 14208: }
! 14209:
! 14210: sub fetch_secrets {
! 14211: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
! 14212: my %keyset;
! 14213: %{$currsec} = ();
! 14214: $newsec->{'private'}{'keys'} = [];
! 14215: $newsec->{'encrypt'} = {};
! 14216: $newsec->{'rules'} = {};
! 14217: if ($context eq 'ltisec') {
! 14218: $newsec->{'linkprot'} = {};
! 14219: }
! 14220: if (ref($domconfig->{$context}) eq 'HASH') {
! 14221: %{$currsec} = %{$domconfig->{$context}};
! 14222: if ($context eq 'ltisec') {
! 14223: if (ref($currsec->{'linkprot'}) eq 'HASH') {
! 14224: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
! 14225: unless ($id =~ /^\d+$/) {
! 14226: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14227: }
1.267 raeburn 14228: }
14229: }
1.421 ! raeburn 14230: }
! 14231: if (ref($currsec->{'private'}) eq 'HASH') {
! 14232: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
! 14233: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
! 14234: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14235: }
1.421 ! raeburn 14236: }
! 14237: }
! 14238: my @items= ('crs','dom');
! 14239: if ($context eq 'ltisec') {
! 14240: push(@items,'consumers');
! 14241: }
! 14242: foreach my $item (@items) {
! 14243: my $formelement;
! 14244: if (($context eq 'toolsec') || ($item eq 'consumers')) {
! 14245: $formelement = 'form.'.$context.'_'.$item;
! 14246: } else {
! 14247: $formelement = 'form.'.$context.'_'.$item.'linkprot';
! 14248: }
! 14249: if ($env{$formelement}) {
! 14250: $newsec->{'encrypt'}{$item} = 1;
! 14251: if (ref($currsec->{'encrypt'}) eq 'HASH') {
! 14252: unless ($currsec->{'encrypt'}{$item}) {
! 14253: $secchanges->{'encrypt'} = 1;
! 14254: }
! 14255: } else {
! 14256: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14257: }
1.421 ! raeburn 14258: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
! 14259: if ($currsec->{'encrypt'}{$item}) {
! 14260: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14261: }
1.421 ! raeburn 14262: }
! 14263: }
! 14264: my $secrets;
! 14265: if ($context eq 'ltisec') {
! 14266: $secrets = 'ltisecrets';
! 14267: } else {
! 14268: $secrets = 'toolsecrets';
! 14269: }
! 14270: unless (exists($currsec->{'rules'})) {
! 14271: $currsec->{'rules'} = {};
! 14272: }
! 14273: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
! 14274:
! 14275: my @ids=&Apache::lonnet::current_machine_ids();
! 14276: my %servers = &Apache::lonnet::get_servers($dom,'library');
! 14277:
! 14278: foreach my $hostid (keys(%servers)) {
! 14279: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
! 14280: my $newkey;
! 14281: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
! 14282: if (exists($env{$keyitem})) {
! 14283: $env{$keyitem} =~ s/(`)/'/g;
! 14284: if ($keyset{$hostid}) {
! 14285: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
! 14286: if ($env{$keyitem} ne '') {
! 14287: $secchanges->{'private'} = 1;
! 14288: $newkeyset->{$hostid} = $env{$keyitem};
! 14289: }
1.296 raeburn 14290: }
1.421 ! raeburn 14291: } elsif ($env{$keyitem} ne '') {
! 14292: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
! 14293: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14294: }
1.421 ! raeburn 14295: $secchanges->{'private'} = 1;
! 14296: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14297: }
14298: }
1.421 ! raeburn 14299: }
! 14300: }
! 14301: }
! 14302:
! 14303: sub store_security {
! 14304: my ($dom,$context,$secchanges,$newkeyset,$keystore,$lastactref) = @_;
! 14305: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
! 14306: (ref($keystore) eq 'HASH'));
! 14307: if (keys(%{$secchanges})) {
! 14308: if ($secchanges->{'private'}) {
! 14309: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
! 14310: foreach my $hostid (keys(%{$newkeyset})) {
! 14311: my $storehash = {
! 14312: key => $newkeyset->{$hostid},
! 14313: who => $env{'user.name'}.':'.$env{'user.domain'},
! 14314: };
! 14315: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
! 14316: $dom,$hostid);
! 14317: }
! 14318: }
! 14319: if (ref($lastactref) eq 'HASH') {
! 14320: if (($secchanges->{'encrypt'}) || ($secchanges->{'private'})) {
! 14321: $lastactref->{'domdefaults'} = 1;
! 14322: }
! 14323: }
! 14324: }
! 14325: }
! 14326:
! 14327: sub lti_security_results {
! 14328: my ($context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
! 14329: my $output;
! 14330: foreach my $item (keys(%{$secchanges})) {
! 14331: if ($item eq 'encrypt') {
! 14332: my %encrypted;
! 14333: if ($context eq 'lti') {
! 14334: %encrypted = (
! 14335: crs => {
! 14336: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
! 14337: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
! 14338: },
! 14339: dom => {
! 14340: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
! 14341: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
! 14342: },
! 14343: consumers => {
! 14344: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
! 14345: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
! 14346: },
! 14347: );
1.267 raeburn 14348: } else {
1.421 ! raeburn 14349: %encrypted = (
! 14350: crs => {
! 14351: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
! 14352: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
! 14353: },
! 14354: dom => {
! 14355: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
! 14356: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
! 14357: },
! 14358: );
! 14359:
! 14360: }
! 14361: my @types= ('crs','dom');
! 14362: if ($context eq 'lti') {
! 14363: push(@types,'consumers');
1.267 raeburn 14364: }
1.421 ! raeburn 14365: foreach my $type (@types) {
! 14366: my $shown = $encrypted{$type}{'off'};
! 14367: if (ref($newsec->{$item}) eq 'HASH') {
! 14368: if ($newsec->{$item}{$type}) {
! 14369: $shown = $encrypted{$type}{'on'};
1.319 raeburn 14370: }
1.267 raeburn 14371: }
1.421 ! raeburn 14372: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 14373: }
1.421 ! raeburn 14374: } elsif ($item eq 'rules') {
! 14375: my %titles = &Apache::lonlocal::texthash(
! 14376: min => 'Minimum password length',
! 14377: max => 'Maximum password length',
! 14378: chars => 'Required characters',
! 14379: );
! 14380: foreach my $rule ('min','max') {
! 14381: if ($newsec->{rules}{$rule} eq '') {
! 14382: if ($rule eq 'min') {
! 14383: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
! 14384: ' '.&mt('Default of [_1] will be used',
! 14385: $Apache::lonnet::passwdmin).'</li>';
! 14386: } else {
! 14387: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
! 14388: }
! 14389: } else {
! 14390: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
! 14391: }
! 14392: }
! 14393: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
! 14394: if (@{$newsec->{'rules'}{'chars'}} > 0) {
! 14395: my %rulenames = &Apache::lonlocal::texthash(
! 14396: uc => 'At least one upper case letter',
! 14397: lc => 'At least one lower case letter',
! 14398: num => 'At least one number',
! 14399: spec => 'At least one non-alphanumeric',
! 14400: );
! 14401: my $needed = '<ul><li>'.
! 14402: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
! 14403: '</li></ul>';
! 14404: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
! 14405: } else {
! 14406: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 14407: }
1.421 ! raeburn 14408: } else {
! 14409: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 14410: }
1.421 ! raeburn 14411: } elsif ($item eq 'private') {
! 14412: if (keys(%{$newkeyset})) {
! 14413: foreach my $hostid (sort(keys(%{$newkeyset}))) {
! 14414: if ($keystore->{$hostid} eq 'ok') {
! 14415: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.267 raeburn 14416: }
14417: }
14418: }
1.421 ! raeburn 14419: } elsif ($item eq 'linkprot') {
! 14420: next;
1.267 raeburn 14421: }
14422: }
1.421 ! raeburn 14423: return $output;
! 14424: }
! 14425:
! 14426: sub modify_proctoring {
! 14427: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
! 14428: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 14429: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
! 14430: my $confname = $dom.'-domainconfig';
! 14431: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 14432: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14433: my %providernames = &proctoring_providernames();
14434: my $maxnum = scalar(keys(%providernames));
14435:
14436: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14437: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14438: if (ref($requref) eq 'HASH') {
14439: %requserfields = %{$requref};
14440: }
14441: if (ref($opturef) eq 'HASH') {
14442: %optuserfields = %{$opturef};
14443: }
14444: if (ref($defref) eq 'HASH') {
14445: %defaults = %{$defref};
14446: }
14447: if (ref($extref) eq 'HASH') {
14448: %extended = %{$extref};
14449: }
14450: if (ref($crsref) eq 'HASH') {
14451: %crsconf = %{$crsref};
14452: }
14453: if (ref($rolesref) eq 'ARRAY') {
14454: @courseroles = @{$rolesref};
14455: }
14456: if (ref($ltiref) eq 'ARRAY') {
14457: @ltiroles = @{$ltiref};
14458: }
14459:
14460: if (ref($domconfig{$action}) eq 'HASH') {
14461: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14462: if (@todeleteimages) {
14463: map { $imgdeletions{$_} = 1; } @todeleteimages;
14464: }
14465: }
14466: my %customadds;
14467: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14468: if (@newcustom) {
14469: map { $customadds{$_} = 1; } @newcustom;
14470: }
14471: foreach my $provider (sort(keys(%providernames))) {
14472: $confhash{$provider} = {};
14473: my $pos = $env{'form.proctoring_pos_'.$provider};
14474: $pos =~ s/\D+//g;
14475: $allpos[$pos] = $provider;
14476: my (%current,%currentenc);
14477: my $showroles = 0;
14478: if (ref($domconfig{$action}) eq 'HASH') {
14479: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14480: %current = %{$domconfig{$action}{$provider}};
14481: foreach my $item ('key','secret') {
14482: $currentenc{$item} = $current{$item};
14483: delete($current{$item});
14484: }
14485: }
14486: }
14487: if ($env{'form.proctoring_available_'.$provider}) {
14488: $confhash{$provider}{'available'} = 1;
14489: unless ($current{'available'}) {
14490: $changes{$provider} = 1;
14491: }
14492: } else {
14493: %{$confhash{$provider}} = %current;
14494: %{$encconfhash{$provider}} = %currentenc;
14495: $confhash{$provider}{'available'} = 0;
14496: if ($current{'available'}) {
14497: $changes{$provider} = 1;
14498: }
14499: }
14500: if ($confhash{$provider}{'available'}) {
14501: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14502: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14503: if ($field eq 'lifetime') {
14504: if ($possval =~ /^\d+$/) {
14505: $confhash{$provider}{$field} = $possval;
14506: }
14507: } elsif ($field eq 'version') {
14508: if ($possval =~ /^\d+\.\d+$/) {
14509: $confhash{$provider}{$field} = $possval;
14510: }
14511: } elsif ($field eq 'sigmethod') {
14512: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14513: $confhash{$provider}{$field} = $possval;
14514: }
14515: } elsif ($field eq 'url') {
14516: $confhash{$provider}{$field} = $possval;
14517: } elsif (($field eq 'key') || ($field eq 'secret')) {
14518: $encconfhash{$provider}{$field} = $possval;
14519: unless ($currentenc{$field} eq $possval) {
14520: $changes{$provider} = 1;
14521: }
14522: }
14523: unless (($field eq 'key') || ($field eq 'secret')) {
14524: unless ($current{$field} eq $confhash{$provider}{$field}) {
14525: $changes{$provider} = 1;
14526: }
14527: }
14528: }
14529: if ($imgdeletions{$provider}) {
14530: $changes{$provider} = 1;
14531: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14532: my ($imageurl,$error) =
14533: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14534: $configuserok,$switchserver,$author_ok);
14535: if ($imageurl) {
14536: $confhash{$provider}{'image'} = $imageurl;
14537: $changes{$provider} = 1;
14538: }
14539: if ($error) {
14540: &Apache::lonnet::logthis($error);
14541: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14542: }
14543: } elsif (exists($current{'image'})) {
14544: $confhash{$provider}{'image'} = $current{'image'};
14545: }
14546: if (ref($requserfields{$provider}) eq 'ARRAY') {
14547: if (@{$requserfields{$provider}} > 0) {
14548: if (grep(/^user$/,@{$requserfields{$provider}})) {
14549: if ($env{'form.proctoring_userincdom_'.$provider}) {
14550: $confhash{$provider}{'incdom'} = 1;
14551: }
14552: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14553: $changes{$provider} = 1;
14554: }
14555: }
14556: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14557: $showroles = 1;
14558: }
14559: }
14560: }
14561: $confhash{$provider}{'fields'} = [];
14562: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14563: if (@{$optuserfields{$provider}} > 0) {
14564: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14565: foreach my $field (@{$optuserfields{$provider}}) {
14566: if (grep(/^\Q$field\E$/,@optfields)) {
14567: push(@{$confhash{$provider}{'fields'}},$field);
14568: }
14569: }
14570: }
14571: if (ref($current{'fields'}) eq 'ARRAY') {
14572: unless ($changes{$provider}) {
14573: my @new = sort(@{$confhash{$provider}{'fields'}});
14574: my @old = sort(@{$current{'fields'}});
14575: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14576: if (@diffs) {
14577: $changes{$provider} = 1;
14578: }
14579: }
14580: } elsif (@{$confhash{$provider}{'fields'}}) {
14581: $changes{$provider} = 1;
14582: }
14583: }
14584: if (ref($defaults{$provider}) eq 'ARRAY') {
14585: if (@{$defaults{$provider}} > 0) {
14586: my %options;
14587: if (ref($extended{$provider}) eq 'HASH') {
14588: %options = %{$extended{$provider}};
14589: }
14590: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14591: foreach my $field (@{$defaults{$provider}}) {
14592: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14593: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14594: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14595: push(@{$confhash{$provider}{'defaults'}},$poss);
14596: }
14597: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14598: foreach my $inner (keys(%{$options{$field}})) {
14599: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14600: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14601: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14602: $confhash{$provider}{'defaults'}{$inner} = $poss;
14603: }
14604: } else {
14605: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14606: }
14607: }
14608: } else {
14609: if (grep(/^\Q$field\E$/,@checked)) {
14610: push(@{$confhash{$provider}{'defaults'}},$field);
14611: }
14612: }
14613: }
14614: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14615: if (ref($current{'defaults'}) eq 'ARRAY') {
14616: unless ($changes{$provider}) {
14617: my @new = sort(@{$confhash{$provider}{'defaults'}});
14618: my @old = sort(@{$current{'defaults'}});
14619: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14620: if (@diffs) {
14621: $changes{$provider} = 1;
14622: }
14623: }
14624: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14625: if (@{$current{'defaults'}}) {
14626: $changes{$provider} = 1;
14627: }
14628: }
14629: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14630: if (ref($current{'defaults'}) eq 'HASH') {
14631: unless ($changes{$provider}) {
14632: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14633: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14634: $changes{$provider} = 1;
14635: last;
14636: }
14637: }
14638: }
14639: unless ($changes{$provider}) {
14640: foreach my $key (keys(%{$current{'defaults'}})) {
14641: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14642: $changes{$provider} = 1;
14643: last;
14644: }
14645: }
14646: }
14647: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14648: $changes{$provider} = 1;
14649: }
14650: }
14651: }
14652: }
14653: if (ref($crsconf{$provider}) eq 'ARRAY') {
14654: if (@{$crsconf{$provider}} > 0) {
14655: $confhash{$provider}{'crsconf'} = [];
14656: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14657: foreach my $crsfield (@{$crsconf{$provider}}) {
14658: if (grep(/^\Q$crsfield\E$/,@checked)) {
14659: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14660: }
14661: }
14662: if (ref($current{'crsconf'}) eq 'ARRAY') {
14663: unless ($changes{$provider}) {
14664: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14665: my @old = sort(@{$current{'crsconf'}});
14666: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14667: if (@diffs) {
14668: $changes{$provider} = 1;
14669: }
14670: }
14671: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14672: $changes{$provider} = 1;
14673: }
14674: }
14675: }
14676: if ($showroles) {
14677: $confhash{$provider}{'roles'} = {};
14678: foreach my $role (@courseroles) {
14679: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14680: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14681: $confhash{$provider}{'roles'}{$role} = $poss;
14682: }
14683: }
14684: unless ($changes{$provider}) {
14685: if (ref($current{'roles'}) eq 'HASH') {
14686: foreach my $role (keys(%{$current{'roles'}})) {
14687: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14688: $changes{$provider} = 1;
14689: last
14690: }
14691: }
14692: unless ($changes{$provider}) {
14693: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14694: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14695: $changes{$provider} = 1;
14696: last;
14697: }
14698: }
14699: }
14700: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14701: $changes{$provider} = 1;
14702: }
14703: }
14704: }
14705: if (ref($current{'custom'}) eq 'HASH') {
14706: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14707: foreach my $key (keys(%{$current{'custom'}})) {
14708: if (grep(/^\Q$key\E$/,@customdels)) {
14709: $changes{$provider} = 1;
14710: } else {
14711: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14712: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14713: $changes{$provider} = 1;
14714: }
14715: }
14716: }
14717: }
14718: if ($customadds{$provider}) {
14719: my $name = $env{'form.proctoring_custom_name_'.$provider};
14720: $name =~ s/(`)/'/g;
14721: $name =~ s/^\s+//;
14722: $name =~ s/\s+$//;
14723: my $value = $env{'form.proctoring_custom_value_'.$provider};
14724: $value =~ s/(`)/'/g;
14725: $value =~ s/^\s+//;
14726: $value =~ s/\s+$//;
14727: if ($name ne '') {
14728: $confhash{$provider}{'custom'}{$name} = $value;
14729: $changes{$provider} = 1;
14730: }
14731: }
14732: }
14733: }
14734: if (@allpos > 0) {
14735: my $idx = 0;
14736: foreach my $provider (@allpos) {
14737: if ($provider ne '') {
14738: $confhash{$provider}{'order'} = $idx;
14739: unless ($changes{$provider}) {
14740: if (ref($domconfig{$action}) eq 'HASH') {
14741: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14742: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14743: $changes{$provider} = 1;
14744: }
14745: }
14746: }
14747: }
14748: $idx ++;
14749: }
14750: }
14751: }
14752: my %proc_hash = (
14753: $action => { %confhash }
14754: );
14755: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14756: $dom);
14757: if ($putresult eq 'ok') {
14758: my %proc_enchash = (
14759: $action => { %encconfhash }
14760: );
1.384 raeburn 14761: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14762: if (keys(%changes) > 0) {
14763: my $cachetime = 24*60*60;
14764: my %procall = %confhash;
14765: foreach my $provider (keys(%procall)) {
14766: if (ref($encconfhash{$provider}) eq 'HASH') {
14767: foreach my $key ('key','secret') {
14768: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14769: }
14770: }
14771: }
14772: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14773: if (ref($lastactref) eq 'HASH') {
14774: $lastactref->{'proctoring'} = 1;
14775: }
14776: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14777: my %bynum;
14778: foreach my $provider (sort(keys(%changes))) {
14779: my $position = $confhash{$provider}{'order'};
14780: $bynum{$position} = $provider;
14781: }
14782: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14783: my $provider = $bynum{$pos};
14784: my %lt = &proctoring_titles($provider);
14785: my %fieldtitles = &proctoring_fieldtitles($provider);
14786: if (!$confhash{$provider}{'available'}) {
14787: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14788: } else {
14789: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14790: if ($confhash{$provider}{'image'}) {
14791: $resulttext .= ' '.
14792: '<img src="'.$confhash{$provider}{'image'}.'"'.
14793: ' alt="'.&mt('Proctoring icon').'" />';
14794: }
14795: $resulttext .= '<ul>';
14796: my $position = $pos + 1;
14797: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14798: foreach my $key ('version','sigmethod','url','lifetime') {
14799: if ($confhash{$provider}{$key} ne '') {
14800: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14801: }
14802: }
14803: if ($encconfhash{$provider}{'key'} ne '') {
14804: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14805: }
14806: if ($encconfhash{$provider}{'secret'} ne '') {
14807: $resulttext .= '<li>'.$lt{'secret'}.': ';
14808: my $num = length($encconfhash{$provider}{'secret'});
14809: $resulttext .= ('*'x$num).'</li>';
14810: }
14811: my (@fields,$showroles);
14812: if (ref($requserfields{$provider}) eq 'ARRAY') {
14813: push(@fields,@{$requserfields{$provider}});
14814: }
14815: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14816: push(@fields,@{$confhash{$provider}{'fields'}});
14817: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14818: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14819: }
14820: if (@fields) {
14821: if (grep(/^roles$/,@fields)) {
14822: $showroles = 1;
14823: }
14824: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14825: join('", "', map { $lt{$_}; } @fields).'"</li>';
14826: }
14827: if (ref($requserfields{$provider}) eq 'ARRAY') {
14828: if (grep(/^user$/,@{$requserfields{$provider}})) {
14829: if ($confhash{$provider}{'incdom'}) {
14830: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14831: } else {
14832: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14833: }
14834: }
14835: }
14836: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14837: if (@{$confhash{$provider}{'defaults'}} > 0) {
14838: $resulttext .= '<li>'.$lt{'defa'};
14839: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14840: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14841: }
14842: $resulttext =~ s/,$//;
14843: $resulttext .= '</li>';
14844: }
14845: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14846: if (keys(%{$confhash{$provider}{'defaults'}})) {
14847: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14848: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14849: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14850: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14851: }
14852: }
14853: $resulttext .= '</ul></li>';
14854: }
14855: }
14856: if (ref($crsconf{$provider}) eq 'ARRAY') {
14857: if (@{$crsconf{$provider}} > 0) {
14858: $resulttext .= '<li>'.&mt('Configurable in course:');
14859: my $numconfig = 0;
14860: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14861: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14862: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14863: $numconfig ++;
14864: if ($provider eq 'examity') {
14865: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14866: } else {
14867: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14868: }
14869: }
14870: $resulttext =~ s/,$//;
14871: }
14872: }
14873: if (!$numconfig) {
14874: $resulttext .= ' '.&mt('None');
14875: }
14876: $resulttext .= '</li>';
14877: }
14878: }
14879: if ($showroles) {
14880: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14881: my $rolemaps;
14882: foreach my $role (@courseroles) {
14883: if ($confhash{$provider}{'roles'}{$role}) {
14884: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14885: $confhash{$provider}{'roles'}{$role}.',';
14886: }
14887: }
14888: if ($rolemaps) {
14889: $rolemaps =~ s/,$//;
14890: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14891: }
14892: }
14893: }
14894: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
14895: my $customlist;
14896: if (keys(%{$confhash{$provider}{'custom'}})) {
14897: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
14898: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
14899: }
14900: $customlist =~ s/,$//;
14901: }
14902: if ($customlist) {
14903: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
14904: }
14905: }
14906: $resulttext .= '</ul></li>';
14907: }
14908: }
14909: $resulttext .= '</ul>';
14910: } else {
14911: $resulttext = &mt('No changes made.');
14912: }
14913: } else {
14914: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14915: }
14916: if ($errors) {
14917: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14918: $errors.'</ul>';
14919: }
14920: return $resulttext;
14921: }
14922:
14923: sub process_proctoring_image {
14924: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14925: my $filename = $env{'form.'.$caller.'.filename'};
14926: my ($error,$url);
14927: my ($width,$height) = (21,21);
14928: if ($configuserok eq 'ok') {
14929: if ($switchserver) {
14930: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14931: $switchserver);
14932: } elsif ($author_ok eq 'ok') {
1.421 ! raeburn 14933: my $modified = [];
1.372 raeburn 14934: my ($result,$imageurl,$madethumb) =
1.421 ! raeburn 14935: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
! 14936: "proctoring/$provider/icon",$width,$height,
! 14937: '',$modified);
1.372 raeburn 14938: if ($result eq 'ok') {
14939: if ($madethumb) {
14940: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14941: my $imagethumb = "$path/tn-".$imagefile;
14942: $url = $imagethumb;
14943: } else {
14944: $url = $imageurl;
14945: }
1.421 ! raeburn 14946: &update_modify_urls($r,$modified);
1.372 raeburn 14947: } else {
14948: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14949: }
14950: } else {
14951: $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);
14952: }
14953: } else {
14954: $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);
14955: }
14956: return ($url,$error);
14957: }
14958:
1.320 raeburn 14959: sub modify_lti {
14960: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14961: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14962: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14963: my (%posslti,%posslticrs,%posscrstype);
14964: my @courseroles = ('cc','in','ta','ep','st');
14965: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14966: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 14967: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 14968: my %coursetypetitles = &Apache::lonlocal::texthash (
14969: official => 'Official',
14970: unofficial => 'Unofficial',
14971: community => 'Community',
14972: textbook => 'Textbook',
14973: placement => 'Placement Test',
1.392 raeburn 14974: lti => 'LTI Provider',
1.320 raeburn 14975: );
1.325 raeburn 14976: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14977: my %lt = <i_names();
14978: map { $posslti{$_} = 1; } @ltiroles;
14979: map { $posslticrs{$_} = 1; } @lticourseroles;
14980: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14981:
1.326 raeburn 14982: my %menutitles = <imenu_titles();
1.421 ! raeburn 14983: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 14984:
1.421 ! raeburn 14985: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 14986:
1.406 raeburn 14987: my (%linkprotchg,$linkprotoutput,$is_home);
14988: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
14989: \%linkprotchg,'domain');
14990: my $home = &Apache::lonnet::domain($dom,'primary');
14991: unless (($home eq 'no_host') || ($home eq '')) {
14992: my @ids=&Apache::lonnet::current_machine_ids();
14993: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
14994: }
14995:
14996: if (keys(%linkprotchg)) {
14997: $secchanges{'linkprot'} = 1;
14998: my %oldlinkprot;
14999: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15000: %oldlinkprot = %{$currltisec{'linkprot'}};
15001: }
15002: foreach my $id (keys(%linkprotchg)) {
15003: if (ref($linkprotchg{$id}) eq 'HASH') {
15004: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15005: if (($inner eq 'secret') || ($inner eq 'key')) {
15006: if ($is_home) {
15007: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15008: }
15009: }
15010: }
15011: } else {
15012: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15013: }
15014: }
15015: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15016: if (keys(%linkprotchg)) {
15017: %{$newltisec{'linkprot'}} = %linkprotchg;
15018: }
15019: }
15020: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15021: foreach my $id (%{$currltisec{'linkprot'}}) {
15022: next if ($id !~ /^\d+$/);
15023: unless (exists($linkprotchg{$id})) {
15024: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15025: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15026: if (($inner eq 'secret') || ($inner eq 'key')) {
15027: if ($is_home) {
15028: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15029: }
15030: } else {
15031: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15032: }
15033: }
15034: } else {
15035: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15036: }
15037: }
15038: }
15039: }
15040: if ($proterror) {
15041: $errors .= '<li>'.$proterror.'</li>';
15042: }
1.320 raeburn 15043: my (@items,%deletions,%itemids);
15044: if ($env{'form.lti_add'}) {
15045: my $consumer = $env{'form.lti_consumer_add'};
15046: $consumer =~ s/(`)/'/g;
15047: ($newid,my $error) = &get_lti_id($dom,$consumer);
15048: if ($newid) {
15049: $itemids{'add'} = $newid;
15050: push(@items,'add');
15051: $changes{$newid} = 1;
15052: } else {
15053: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15054: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15055: }
15056: }
15057: if (ref($domconfig{$action}) eq 'HASH') {
15058: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15059: if (@todelete) {
15060: map { $deletions{$_} = 1; } @todelete;
15061: }
15062: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15063: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15064: my $itemid = $env{'form.lti_id_'.$i};
15065: $itemid =~ s/\D+//g;
15066: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15067: if ($deletions{$itemid}) {
15068: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15069: } else {
1.390 raeburn 15070: push(@items,$i);
15071: $itemids{$i} = $itemid;
1.320 raeburn 15072: }
15073: }
15074: }
15075: }
15076: foreach my $idx (@items) {
15077: my $itemid = $itemids{$idx};
15078: next unless ($itemid);
1.390 raeburn 15079: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15080: $position =~ s/\D+//g;
15081: if ($position ne '') {
15082: $allpos[$position] = $itemid;
15083: }
1.391 raeburn 15084: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 15085: my $formitem = 'form.lti_'.$item.'_'.$idx;
15086: $env{$formitem} =~ s/(`)/'/g;
15087: if ($item eq 'lifetime') {
15088: $env{$formitem} =~ s/[^\d.]//g;
15089: }
15090: if ($env{$formitem} ne '') {
15091: if (($item eq 'key') || ($item eq 'secret')) {
15092: $encconfig{$itemid}{$item} = $env{$formitem};
15093: } else {
15094: $confhash{$itemid}{$item} = $env{$formitem};
15095: unless (($idx eq 'add') || ($changes{$itemid})) {
15096: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
15097: $changes{$itemid} = 1;
15098: }
15099: }
15100: }
15101: }
15102: }
15103: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15104: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15105: }
1.345 raeburn 15106: if ($confhash{$itemid}{'requser'}) {
15107: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15108: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15109: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15110: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15111: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15112: my $mapuser = $env{'form.lti_customuser_'.$idx};
15113: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15114: $mapuser =~ s/^\s+|\s+$//g;
15115: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15116: }
15117: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15118: my @makeuser;
15119: foreach my $ltirole (sort(@possmakeuser)) {
15120: if ($posslti{$ltirole}) {
15121: push(@makeuser,$ltirole);
15122: }
15123: }
15124: $confhash{$itemid}{'makeuser'} = \@makeuser;
15125: if (@makeuser) {
15126: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15127: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15128: $confhash{$itemid}{'lcauth'} = $lcauth;
15129: if ($lcauth ne 'internal') {
15130: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15131: $lcauthparm =~ s/^(\s+|\s+)$//g;
15132: $lcauthparm =~ s/`//g;
15133: if ($lcauthparm ne '') {
15134: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15135: }
15136: }
15137: } else {
15138: $confhash{$itemid}{'lcauth'} = 'lti';
15139: }
1.320 raeburn 15140: }
1.345 raeburn 15141: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15142: if (@possinstdata) {
15143: foreach my $field (@possinstdata) {
15144: if (exists($fieldtitles{$field})) {
15145: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15146: }
15147: }
15148: }
1.363 raeburn 15149: if ($env{'form.lti_callback_'.$idx}) {
15150: if ($env{'form.lti_callbackparam_'.$idx}) {
15151: my $callback = $env{'form.lti_callbackparam_'.$idx};
15152: $callback =~ s/^\s+|\s+$//g;
15153: $confhash{$itemid}{'callback'} = $callback;
15154: }
15155: }
1.391 raeburn 15156: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15157: if ($env{'form.lti_'.$field.'_'.$idx}) {
15158: $confhash{$itemid}{$field} = 1;
15159: }
1.320 raeburn 15160: }
1.345 raeburn 15161: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15162: $confhash{$itemid}{lcmenu} = [];
15163: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15164: foreach my $field (@possmenu) {
15165: if (exists($menutitles{$field})) {
15166: if ($field eq 'grades') {
15167: next unless ($env{'form.lti_inlinemenu_'.$idx});
15168: }
15169: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15170: }
15171: }
15172: }
1.391 raeburn 15173: if ($confhash{$itemid}{'crsinc'}) {
15174: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15175: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15176: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15177: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15178: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15179: $mapcrs =~ s/(`)/'/g;
15180: $mapcrs =~ s/^\s+|\s+$//g;
15181: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15182: }
15183: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15184: my @crstypes;
15185: foreach my $type (sort(@posstypes)) {
15186: if ($posscrstype{$type}) {
15187: push(@crstypes,$type);
15188: }
15189: }
15190: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15191: if ($env{'form.lti_storecrs_'.$idx}) {
15192: $confhash{$itemid}{'storecrs'} = 1;
15193: }
1.391 raeburn 15194: if ($env{'form.lti_makecrs_'.$idx}) {
15195: $confhash{$itemid}{'makecrs'} = 1;
15196: }
15197: foreach my $ltirole (@lticourseroles) {
15198: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15199: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15200: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15201: }
15202: }
15203: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15204: my @selfenroll;
15205: foreach my $type (sort(@possenroll)) {
15206: if ($posslticrs{$type}) {
15207: push(@selfenroll,$type);
15208: }
15209: }
15210: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15211: if ($env{'form.lti_crssec_'.$idx}) {
15212: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15213: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15214: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15215: my $section = $env{'form.lti_customsection_'.$idx};
15216: $section =~ s/(`)/'/g;
15217: $section =~ s/^\s+|\s+$//g;
15218: if ($section ne '') {
15219: $confhash{$itemid}{'section'} = $section;
15220: }
15221: }
15222: }
15223: foreach my $field ('passback','roster') {
15224: if ($env{'form.lti_'.$field.'_'.$idx}) {
15225: $confhash{$itemid}{$field} = 1;
15226: }
15227: }
15228: if ($env{'form.lti_passback_'.$idx}) {
15229: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15230: $confhash{$itemid}{'passbackformat'} = '1.0';
15231: } else {
15232: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15233: }
15234: }
1.391 raeburn 15235: }
15236: unless (($idx eq 'add') || ($changes{$itemid})) {
15237: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15238: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 15239: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15240: $changes{$itemid} = 1;
15241: }
1.345 raeburn 15242: }
15243: unless ($changes{$itemid}) {
1.391 raeburn 15244: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
15245: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15246: $changes{$itemid} = 1;
15247: }
15248: }
1.345 raeburn 15249: }
1.391 raeburn 15250: foreach my $field ('mapcrstype','selfenroll') {
15251: unless ($changes{$itemid}) {
15252: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15253: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15254: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15255: $confhash{$itemid}{$field});
15256: if (@diffs) {
15257: $changes{$itemid} = 1;
15258: }
15259: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15260: $changes{$itemid} = 1;
15261: }
15262: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15263: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15264: $changes{$itemid} = 1;
15265: }
15266: }
1.391 raeburn 15267: }
15268: }
15269: unless ($changes{$itemid}) {
15270: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
15271: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15272: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
15273: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
15274: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15275: $changes{$itemid} = 1;
15276: last;
15277: }
15278: }
1.391 raeburn 15279: unless ($changes{$itemid}) {
15280: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15281: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
15282: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
15283: $changes{$itemid} = 1;
15284: last;
15285: }
15286: }
15287: }
15288: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
15289: $changes{$itemid} = 1;
1.345 raeburn 15290: }
1.391 raeburn 15291: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15292: unless ($changes{$itemid}) {
15293: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15294: $changes{$itemid} = 1;
15295: }
15296: }
15297: }
15298: }
15299: }
15300: unless ($changes{$itemid}) {
15301: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
15302: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15303: $changes{$itemid} = 1;
1.320 raeburn 15304: }
1.391 raeburn 15305: }
15306: unless ($changes{$itemid}) {
15307: foreach my $field ('makeuser','lcmenu') {
15308: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15309: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15310: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15311: $confhash{$itemid}{$field});
15312: if (@diffs) {
15313: $changes{$itemid} = 1;
15314: }
15315: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15316: $changes{$itemid} = 1;
15317: }
15318: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15319: if (@{$confhash{$itemid}{$field}} > 0) {
15320: $changes{$itemid} = 1;
15321: }
1.345 raeburn 15322: }
1.320 raeburn 15323: }
15324: }
15325: }
15326: }
15327: }
15328: }
15329: if (@allpos > 0) {
15330: my $idx = 0;
15331: foreach my $itemid (@allpos) {
15332: if ($itemid ne '') {
15333: $confhash{$itemid}{'order'} = $idx;
15334: if (ref($domconfig{$action}) eq 'HASH') {
15335: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15336: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15337: $changes{$itemid} = 1;
15338: }
15339: }
15340: }
15341: $idx ++;
15342: }
15343: }
15344: }
15345: my %ltihash = (
1.405 raeburn 15346: $action => { %confhash }
15347: );
1.406 raeburn 15348: my %ltienchash = (
15349: $action => { %encconfig }
15350: );
1.405 raeburn 15351: if (keys(%secchanges)) {
15352: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 15353: if ($secchanges{'linkprot'}) {
15354: if ($is_home) {
15355: $ltienchash{'linkprot'} = \%newltienc;
15356: }
15357: }
1.405 raeburn 15358: }
15359: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 15360: if ($putresult eq 'ok') {
1.405 raeburn 15361: my %keystore;
1.421 ! raeburn 15362: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore,$lastactref);
1.384 raeburn 15363: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 15364: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
15365: return &mt('No changes made.');
15366: }
15367: $resulttext = &mt('Changes made:').'<ul>';
15368: if (keys(%secchanges) > 0) {
1.421 ! raeburn 15369: $resulttext .= <i_security_results('lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
! 15370: if (exists($secchanges{'linkprot'})) {
! 15371: $resulttext .= $linkprotoutput;
1.405 raeburn 15372: }
15373: }
1.320 raeburn 15374: if (keys(%changes) > 0) {
15375: my $cachetime = 24*60*60;
15376: my %ltiall = %confhash;
15377: foreach my $id (keys(%ltiall)) {
15378: if (ref($encconfig{$id}) eq 'HASH') {
15379: foreach my $item ('key','secret') {
15380: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15381: }
15382: }
15383: }
15384: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15385: if (ref($lastactref) eq 'HASH') {
15386: $lastactref->{'lti'} = 1;
15387: }
15388: my %bynum;
15389: foreach my $itemid (sort(keys(%changes))) {
15390: my $position = $confhash{$itemid}{'order'};
15391: $bynum{$position} = $itemid;
15392: }
15393: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15394: my $itemid = $bynum{$pos};
15395: if (ref($confhash{$itemid}) ne 'HASH') {
15396: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15397: } else {
1.390 raeburn 15398: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15399: my $position = $pos + 1;
15400: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15401: foreach my $item ('version','lifetime') {
15402: if ($confhash{$itemid}{$item} ne '') {
15403: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15404: }
15405: }
15406: if ($encconfig{$itemid}{'key'} ne '') {
15407: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15408: }
15409: if ($encconfig{$itemid}{'secret'} ne '') {
15410: $resulttext .= '<li>'.$lt{'secret'}.': ';
15411: my $num = length($encconfig{$itemid}{'secret'});
15412: $resulttext .= ('*'x$num).'</li>';
15413: }
1.345 raeburn 15414: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 15415: if ($confhash{$itemid}{'callback'}) {
15416: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15417: } else {
1.392 raeburn 15418: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 15419: }
1.345 raeburn 15420: if ($confhash{$itemid}{'mapuser'}) {
15421: my $shownmapuser;
15422: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15423: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15424: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15425: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15426: } else {
15427: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15428: }
1.345 raeburn 15429: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15430: }
1.345 raeburn 15431: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15432: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15433: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15434: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15435: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15436: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15437: } else {
15438: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15439: $confhash{$itemid}{'lcauth'});
15440: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15441: $resulttext .= '; '.&mt('a randomly generated password will be created');
15442: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15443: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15444: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15445: }
15446: } else {
15447: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15448: }
15449: }
15450: $resulttext .= '</li>';
15451: } else {
15452: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15453: }
1.320 raeburn 15454: }
1.345 raeburn 15455: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15456: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15457: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15458: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15459: } else {
1.345 raeburn 15460: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15461: }
1.320 raeburn 15462: }
1.391 raeburn 15463: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15464: $resulttext .= '<li>'.$lt{$item}.': ';
15465: if ($confhash{$itemid}{$item}) {
15466: $resulttext .= &mt('Yes');
15467: } else {
15468: $resulttext .= &mt('No');
1.337 raeburn 15469: }
1.345 raeburn 15470: $resulttext .= '</li>';
1.320 raeburn 15471: }
1.345 raeburn 15472: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15473: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15474: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 15475: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15476: } else {
15477: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15478: }
15479: }
15480: if ($confhash{$itemid}{'crsinc'}) {
15481: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15482: my $rolemaps;
15483: foreach my $role (@ltiroles) {
15484: if ($confhash{$itemid}{'maproles'}{$role}) {
15485: $rolemaps .= (' 'x2).$role.'='.
15486: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15487: 'Course').',';
15488: }
15489: }
15490: if ($rolemaps) {
15491: $rolemaps =~ s/,$//;
15492: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15493: }
15494: }
15495: if ($confhash{$itemid}{'mapcrs'}) {
15496: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15497: }
15498: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15499: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15500: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15501: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15502: '</li>';
15503: } else {
15504: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15505: }
15506: }
1.392 raeburn 15507: if ($confhash{$itemid}{'storecrs'}) {
15508: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
15509: }
1.391 raeburn 15510: if ($confhash{$itemid}{'makecrs'}) {
15511: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
15512: } else {
15513: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
15514: }
15515: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15516: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15517: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15518: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15519: '</li>';
15520: } else {
15521: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15522: }
15523: }
15524: if ($confhash{$itemid}{'section'}) {
15525: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15526: $resulttext .= '<li>'.&mt('User section from standard field:').
15527: ' (course_section_sourcedid)'.'</li>';
15528: } else {
15529: $resulttext .= '<li>'.&mt('User section from:').' '.
15530: $confhash{$itemid}{'section'}.'</li>';
15531: }
1.345 raeburn 15532: } else {
1.391 raeburn 15533: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
15534: }
15535: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15536: $resulttext .= '<li>'.$lt{$item}.': ';
15537: if ($confhash{$itemid}{$item}) {
15538: $resulttext .= &mt('Yes');
15539: if ($item eq 'passback') {
15540: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15541: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15542: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15543: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15544: }
15545: }
15546: } else {
15547: $resulttext .= &mt('No');
15548: }
15549: $resulttext .= '</li>';
15550: }
15551: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15552: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15553: $resulttext .= '<li>'.&mt('Menu items:').' '.
15554: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15555: } else {
15556: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15557: }
1.345 raeburn 15558: }
1.326 raeburn 15559: }
15560: }
1.320 raeburn 15561: $resulttext .= '</ul></li>';
15562: }
15563: }
15564: }
1.405 raeburn 15565: $resulttext .= '</ul>';
1.320 raeburn 15566: } else {
15567: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15568: }
15569: if ($errors) {
15570: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15571: $errors.'</ul>';
15572: }
15573: return $resulttext;
15574: }
15575:
15576: sub get_lti_id {
15577: my ($domain,$consumer) = @_;
15578: # get lock on lti db
15579: my $lockhash = {
15580: lock => $env{'user.name'}.
15581: ':'.$env{'user.domain'},
15582: };
15583: my $tries = 0;
15584: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15585: my ($id,$error);
15586:
15587: while (($gotlock ne 'ok') && ($tries<10)) {
15588: $tries ++;
15589: sleep (0.1);
15590: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15591: }
15592: if ($gotlock eq 'ok') {
15593: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15594: if ($currids{'lock'}) {
15595: delete($currids{'lock'});
15596: if (keys(%currids)) {
15597: my @curr = sort { $a <=> $b } keys(%currids);
15598: if ($curr[-1] =~ /^\d+$/) {
15599: $id = 1 + $curr[-1];
15600: }
15601: } else {
15602: $id = 1;
15603: }
15604: if ($id) {
15605: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15606: $error = 'nostore';
15607: }
15608: } else {
15609: $error = 'nonumber';
15610: }
15611: }
15612: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15613: } else {
15614: $error = 'nolock';
15615: }
15616: return ($id,$error);
15617: }
15618:
1.3 raeburn 15619: sub modify_autoenroll {
1.205 raeburn 15620: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15621: my ($resulttext,%changes);
15622: my %currautoenroll;
15623: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15624: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15625: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15626: }
15627: }
15628: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15629: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15630: sender => 'Sender for notification messages',
1.274 raeburn 15631: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 15632: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15633: my @offon = ('off','on');
1.17 raeburn 15634: my $sender_uname = $env{'form.sender_uname'};
15635: my $sender_domain = $env{'form.sender_domain'};
15636: if ($sender_domain eq '') {
15637: $sender_uname = '';
15638: } elsif ($sender_uname eq '') {
15639: $sender_domain = '';
15640: }
1.129 raeburn 15641: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 15642: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
15643: $autofailsafe =~ s{^\s+|\s+$}{}g;
15644: if ($autofailsafe =~ /\D/) {
15645: undef($autofailsafe);
15646: }
1.274 raeburn 15647: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 15648: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
15649: $failsafe = 'off';
1.400 raeburn 15650: undef($autofailsafe);
1.274 raeburn 15651: }
1.1 raeburn 15652: my %autoenrollhash = (
1.129 raeburn 15653: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15654: 'sender_uname' => $sender_uname,
15655: 'sender_domain' => $sender_domain,
15656: 'co-owners' => $coowners,
1.399 raeburn 15657: 'autofailsafe' => $autofailsafe,
1.400 raeburn 15658: 'failsafe' => $failsafe,
1.1 raeburn 15659: }
15660: );
1.4 raeburn 15661: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15662: $dom);
1.1 raeburn 15663: if ($putresult eq 'ok') {
15664: if (exists($currautoenroll{'run'})) {
15665: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15666: $changes{'run'} = 1;
15667: }
15668: } elsif ($autorun) {
15669: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15670: $changes{'run'} = 1;
1.1 raeburn 15671: }
15672: }
1.17 raeburn 15673: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15674: $changes{'sender'} = 1;
15675: }
1.17 raeburn 15676: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15677: $changes{'sender'} = 1;
15678: }
1.129 raeburn 15679: if ($currautoenroll{'co-owners'} ne '') {
15680: if ($currautoenroll{'co-owners'} ne $coowners) {
15681: $changes{'coowners'} = 1;
15682: }
15683: } elsif ($coowners) {
15684: $changes{'coowners'} = 1;
1.274 raeburn 15685: }
1.399 raeburn 15686: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 15687: $changes{'autofailsafe'} = 1;
15688: }
1.399 raeburn 15689: if ($currautoenroll{'failsafe'} ne $failsafe) {
15690: $changes{'failsafe'} = 1;
15691: }
1.1 raeburn 15692: if (keys(%changes) > 0) {
15693: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15694: if ($changes{'run'}) {
1.1 raeburn 15695: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15696: }
15697: if ($changes{'sender'}) {
1.17 raeburn 15698: if ($sender_uname eq '' || $sender_domain eq '') {
15699: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15700: } else {
15701: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15702: }
1.1 raeburn 15703: }
1.129 raeburn 15704: if ($changes{'coowners'}) {
15705: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15706: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15707: if (ref($lastactref) eq 'HASH') {
15708: $lastactref->{'domainconfig'} = 1;
15709: }
1.129 raeburn 15710: }
1.274 raeburn 15711: if ($changes{'autofailsafe'}) {
1.399 raeburn 15712: if ($autofailsafe ne '') {
15713: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 15714: } else {
1.399 raeburn 15715: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 15716: }
1.399 raeburn 15717: }
15718: if ($changes{'failsafe'}) {
15719: if ($failsafe eq 'off') {
15720: unless ($changes{'autofailsafe'}) {
15721: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
15722: }
15723: } elsif ($failsafe eq 'zero') {
15724: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
15725: } else {
15726: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
15727: }
15728: }
15729: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 15730: &Apache::lonnet::get_domain_defaults($dom,1);
15731: if (ref($lastactref) eq 'HASH') {
15732: $lastactref->{'domdefaults'} = 1;
15733: }
15734: }
1.1 raeburn 15735: $resulttext .= '</ul>';
15736: } else {
15737: $resulttext = &mt('No changes made to auto-enrollment settings');
15738: }
15739: } else {
1.11 albertel 15740: $resulttext = '<span class="LC_error">'.
15741: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15742: }
1.3 raeburn 15743: return $resulttext;
1.1 raeburn 15744: }
15745:
15746: sub modify_autoupdate {
1.3 raeburn 15747: my ($dom,%domconfig) = @_;
1.1 raeburn 15748: my ($resulttext,%currautoupdate,%fields,%changes);
15749: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
15750: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
15751: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
15752: }
15753: }
15754: my @offon = ('off','on');
15755: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 15756: run => 'Auto-update:',
15757: classlists => 'Updates to user information in classlists?',
15758: unexpired => 'Skip updates for users without active or future roles?',
15759: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 15760: );
1.44 raeburn 15761: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 15762: my %fieldtitles = &Apache::lonlocal::texthash (
15763: id => 'Student/Employee ID',
1.20 raeburn 15764: permanentemail => 'E-mail address',
1.1 raeburn 15765: lastname => 'Last Name',
15766: firstname => 'First Name',
15767: middlename => 'Middle Name',
1.132 raeburn 15768: generation => 'Generation',
1.1 raeburn 15769: );
1.142 raeburn 15770: $othertitle = &mt('All users');
1.1 raeburn 15771: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 15772: $othertitle = &mt('Other users');
1.1 raeburn 15773: }
15774: foreach my $key (keys(%env)) {
15775: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 15776: my ($usertype,$item) = ($1,$2);
15777: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
15778: if ($usertype eq 'default') {
15779: push(@{$fields{$1}},$2);
15780: } elsif (ref($types) eq 'ARRAY') {
15781: if (grep(/^\Q$usertype\E$/,@{$types})) {
15782: push(@{$fields{$1}},$2);
15783: }
15784: }
15785: }
1.1 raeburn 15786: }
15787: }
1.131 raeburn 15788: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
15789: @lockablenames = sort(@lockablenames);
15790: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
15791: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15792: if (@changed) {
15793: $changes{'lockablenames'} = 1;
15794: }
15795: } else {
15796: if (@lockablenames) {
15797: $changes{'lockablenames'} = 1;
15798: }
15799: }
1.1 raeburn 15800: my %updatehash = (
15801: autoupdate => { run => $env{'form.autoupdate_run'},
15802: classlists => $env{'form.classlists'},
1.385 raeburn 15803: unexpired => $env{'form.unexpired'},
1.1 raeburn 15804: fields => {%fields},
1.131 raeburn 15805: lockablenames => \@lockablenames,
1.1 raeburn 15806: }
15807: );
1.385 raeburn 15808: my $lastactivedays;
15809: if ($env{'form.lastactive'}) {
15810: $lastactivedays = $env{'form.lastactivedays'};
15811: $lastactivedays =~ s/^\s+|\s+$//g;
15812: unless ($lastactivedays =~ /^\d+$/) {
15813: undef($lastactivedays);
15814: $env{'form.lastactive'} = 0;
15815: }
15816: }
15817: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 15818: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 15819: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 15820: if (exists($updatehash{autoupdate}{$key})) {
15821: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
15822: $changes{$key} = 1;
15823: }
15824: }
15825: } elsif ($key eq 'fields') {
15826: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 15827: foreach my $item (@{$types},'default') {
1.1 raeburn 15828: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
15829: my $change = 0;
15830: foreach my $type (@{$currautoupdate{$key}{$item}}) {
15831: if (!exists($fields{$item})) {
15832: $change = 1;
1.132 raeburn 15833: last;
1.1 raeburn 15834: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15835: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15836: $change = 1;
1.132 raeburn 15837: last;
1.1 raeburn 15838: }
15839: }
15840: }
15841: if ($change) {
15842: push(@{$changes{$key}},$item);
15843: }
1.26 raeburn 15844: }
1.1 raeburn 15845: }
15846: }
1.131 raeburn 15847: } elsif ($key eq 'lockablenames') {
15848: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15849: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15850: if (@changed) {
15851: $changes{'lockablenames'} = 1;
15852: }
15853: } else {
15854: if (@lockablenames) {
15855: $changes{'lockablenames'} = 1;
15856: }
15857: }
15858: }
15859: }
15860: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15861: if (@lockablenames) {
15862: $changes{'lockablenames'} = 1;
1.1 raeburn 15863: }
15864: }
1.385 raeburn 15865: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15866: if ($updatehash{'autoupdate'}{'unexpired'}) {
15867: $changes{'unexpired'} = 1;
15868: }
15869: }
15870: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15871: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15872: $changes{'lastactive'} = 1;
15873: }
15874: }
1.26 raeburn 15875: foreach my $item (@{$types},'default') {
15876: if (defined($fields{$item})) {
15877: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15878: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15879: my $change = 0;
15880: if (ref($fields{$item}) eq 'ARRAY') {
15881: foreach my $type (@{$fields{$item}}) {
15882: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15883: $change = 1;
15884: last;
15885: }
15886: }
15887: }
15888: if ($change) {
15889: push(@{$changes{'fields'}},$item);
15890: }
15891: } else {
1.26 raeburn 15892: push(@{$changes{'fields'}},$item);
15893: }
15894: } else {
15895: push(@{$changes{'fields'}},$item);
1.1 raeburn 15896: }
15897: }
15898: }
15899: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15900: $dom);
15901: if ($putresult eq 'ok') {
15902: if (keys(%changes) > 0) {
15903: $resulttext = &mt('Changes made:').'<ul>';
15904: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15905: if ($key eq 'lockablenames') {
15906: $resulttext .= '<li>';
15907: if (@lockablenames) {
15908: $usertypes->{'default'} = $othertitle;
15909: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15910: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15911: } else {
15912: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15913: }
15914: $resulttext .= '</li>';
15915: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15916: foreach my $item (@{$changes{$key}}) {
15917: my @newvalues;
15918: foreach my $type (@{$fields{$item}}) {
15919: push(@newvalues,$fieldtitles{$type});
15920: }
1.3 raeburn 15921: my $newvaluestr;
15922: if (@newvalues > 0) {
15923: $newvaluestr = join(', ',@newvalues);
15924: } else {
15925: $newvaluestr = &mt('none');
1.6 raeburn 15926: }
1.1 raeburn 15927: if ($item eq 'default') {
1.26 raeburn 15928: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15929: } else {
1.26 raeburn 15930: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15931: }
15932: }
15933: } else {
15934: my $newvalue;
15935: if ($key eq 'run') {
15936: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 15937: } elsif ($key eq 'lastactive') {
15938: $newvalue = $offon[$env{'form.lastactive'}];
15939: unless ($lastactivedays eq '') {
15940: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15941: }
1.1 raeburn 15942: } else {
15943: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15944: }
1.1 raeburn 15945: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15946: }
15947: }
15948: $resulttext .= '</ul>';
15949: } else {
1.3 raeburn 15950: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15951: }
15952: } else {
1.11 albertel 15953: $resulttext = '<span class="LC_error">'.
15954: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15955: }
1.3 raeburn 15956: return $resulttext;
1.1 raeburn 15957: }
15958:
1.125 raeburn 15959: sub modify_autocreate {
15960: my ($dom,%domconfig) = @_;
15961: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15962: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15963: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15964: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15965: }
15966: }
15967: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15968: req => 'Auto-creation of validated requests for official courses',
15969: xmldc => 'Identity of course creator of courses from XML files',
15970: );
15971: my @types = ('xml','req');
15972: foreach my $item (@types) {
15973: $newvals{$item} = $env{'form.autocreate_'.$item};
15974: $newvals{$item} =~ s/\D//g;
15975: $newvals{$item} = 0 if ($newvals{$item} eq '');
15976: }
15977: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 15978: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15979: unless (exists($domcoords{$newvals{'xmldc'}})) {
15980: $newvals{'xmldc'} = '';
15981: }
15982: %autocreatehash = (
15983: autocreate => { xml => $newvals{'xml'},
15984: req => $newvals{'req'},
15985: }
15986: );
15987: if ($newvals{'xmldc'} ne '') {
15988: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15989: }
15990: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15991: $dom);
15992: if ($putresult eq 'ok') {
15993: my @items = @types;
15994: if ($newvals{'xml'}) {
15995: push(@items,'xmldc');
15996: }
15997: foreach my $item (@items) {
15998: if (exists($currautocreate{$item})) {
15999: if ($currautocreate{$item} ne $newvals{$item}) {
16000: $changes{$item} = 1;
16001: }
16002: } elsif ($newvals{$item}) {
16003: $changes{$item} = 1;
16004: }
16005: }
16006: if (keys(%changes) > 0) {
16007: my @offon = ('off','on');
16008: $resulttext = &mt('Changes made:').'<ul>';
16009: foreach my $item (@types) {
16010: if ($changes{$item}) {
16011: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16012: $resulttext .= '<li>'.
16013: &mt("$title{$item} set to [_1]$newtxt [_2]",
16014: '<b>','</b>').
16015: '</li>';
1.125 raeburn 16016: }
16017: }
16018: if ($changes{'xmldc'}) {
16019: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16020: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16021: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16022: }
16023: $resulttext .= '</ul>';
16024: } else {
16025: $resulttext = &mt('No changes made to auto-creation settings');
16026: }
16027: } else {
16028: $resulttext = '<span class="LC_error">'.
16029: &mt('An error occurred: [_1]',$putresult).'</span>';
16030: }
16031: return $resulttext;
16032: }
16033:
1.23 raeburn 16034: sub modify_directorysrch {
1.295 raeburn 16035: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16036: my ($resulttext,%changes);
16037: my %currdirsrch;
16038: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16039: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16040: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16041: }
16042: }
1.277 raeburn 16043: my %title = ( available => 'Institutional directory search available',
16044: localonly => 'Other domains can search institution',
16045: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16046: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16047: searchby => 'Search types',
16048: searchtypes => 'Search latitude');
16049: my @offon = ('off','on');
1.24 raeburn 16050: my @otherdoms = ('Yes','No');
1.23 raeburn 16051:
1.25 raeburn 16052: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16053: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16054: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16055:
1.44 raeburn 16056: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16057: if (keys(%{$usertypes}) == 0) {
16058: @cansearch = ('default');
16059: } else {
16060: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16061: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16062: if (!grep(/^\Q$type\E$/,@cansearch)) {
16063: push(@{$changes{'cansearch'}},$type);
16064: }
1.23 raeburn 16065: }
1.26 raeburn 16066: foreach my $type (@cansearch) {
16067: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16068: push(@{$changes{'cansearch'}},$type);
16069: }
1.23 raeburn 16070: }
1.26 raeburn 16071: } else {
16072: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16073: }
16074: }
16075:
16076: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16077: foreach my $by (@{$currdirsrch{'searchby'}}) {
16078: if (!grep(/^\Q$by\E$/,@searchby)) {
16079: push(@{$changes{'searchby'}},$by);
16080: }
16081: }
16082: foreach my $by (@searchby) {
16083: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16084: push(@{$changes{'searchby'}},$by);
16085: }
16086: }
16087: } else {
16088: push(@{$changes{'searchby'}},@searchby);
16089: }
1.25 raeburn 16090:
16091: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16092: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16093: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16094: push(@{$changes{'searchtypes'}},$type);
16095: }
16096: }
16097: foreach my $type (@searchtypes) {
16098: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16099: push(@{$changes{'searchtypes'}},$type);
16100: }
16101: }
16102: } else {
16103: if (exists($currdirsrch{'searchtypes'})) {
16104: foreach my $type (@searchtypes) {
16105: if ($type ne $currdirsrch{'searchtypes'}) {
16106: push(@{$changes{'searchtypes'}},$type);
16107: }
16108: }
16109: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16110: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16111: }
16112: } else {
16113: push(@{$changes{'searchtypes'}},@searchtypes);
16114: }
16115: }
16116:
1.23 raeburn 16117: my %dirsrch_hash = (
16118: directorysrch => { available => $env{'form.dirsrch_available'},
16119: cansearch => \@cansearch,
1.277 raeburn 16120: localonly => $env{'form.dirsrch_instlocalonly'},
16121: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16122: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16123: searchby => \@searchby,
1.25 raeburn 16124: searchtypes => \@searchtypes,
1.23 raeburn 16125: }
16126: );
16127: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16128: $dom);
16129: if ($putresult eq 'ok') {
16130: if (exists($currdirsrch{'available'})) {
16131: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16132: $changes{'available'} = 1;
16133: }
16134: } else {
16135: if ($env{'form.dirsrch_available'} eq '1') {
16136: $changes{'available'} = 1;
16137: }
16138: }
1.277 raeburn 16139: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16140: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16141: $changes{'lcavailable'} = 1;
16142: }
1.277 raeburn 16143: } else {
16144: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16145: $changes{'lcavailable'} = 1;
16146: }
16147: }
1.24 raeburn 16148: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16149: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16150: $changes{'localonly'} = 1;
16151: }
1.24 raeburn 16152: } else {
1.277 raeburn 16153: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16154: $changes{'localonly'} = 1;
16155: }
16156: }
1.277 raeburn 16157: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16158: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16159: $changes{'lclocalonly'} = 1;
16160: }
1.277 raeburn 16161: } else {
16162: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16163: $changes{'lclocalonly'} = 1;
16164: }
16165: }
1.23 raeburn 16166: if (keys(%changes) > 0) {
16167: $resulttext = &mt('Changes made:').'<ul>';
16168: if ($changes{'available'}) {
16169: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16170: }
1.277 raeburn 16171: if ($changes{'lcavailable'}) {
16172: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16173: }
1.24 raeburn 16174: if ($changes{'localonly'}) {
1.277 raeburn 16175: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16176: }
1.277 raeburn 16177: if ($changes{'lclocalonly'}) {
16178: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16179: }
1.23 raeburn 16180: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16181: my $chgtext;
1.26 raeburn 16182: if (ref($usertypes) eq 'HASH') {
16183: if (keys(%{$usertypes}) > 0) {
16184: foreach my $type (@{$types}) {
16185: if (grep(/^\Q$type\E$/,@cansearch)) {
16186: $chgtext .= $usertypes->{$type}.'; ';
16187: }
16188: }
16189: if (grep(/^default$/,@cansearch)) {
16190: $chgtext .= $othertitle;
16191: } else {
16192: $chgtext =~ s/\; $//;
16193: }
1.210 raeburn 16194: $resulttext .=
1.178 raeburn 16195: '<li>'.
16196: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16197: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16198: '</li>';
1.23 raeburn 16199: }
16200: }
16201: }
16202: if (ref($changes{'searchby'}) eq 'ARRAY') {
16203: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16204: my $chgtext;
16205: foreach my $type (@{$titleorder}) {
16206: if (grep(/^\Q$type\E$/,@searchby)) {
16207: if (defined($searchtitles->{$type})) {
16208: $chgtext .= $searchtitles->{$type}.'; ';
16209: }
16210: }
16211: }
16212: $chgtext =~ s/\; $//;
16213: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16214: }
1.25 raeburn 16215: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16216: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16217: my $chgtext;
16218: foreach my $type (@{$srchtypeorder}) {
16219: if (grep(/^\Q$type\E$/,@searchtypes)) {
16220: if (defined($srchtypes_desc->{$type})) {
16221: $chgtext .= $srchtypes_desc->{$type}.'; ';
16222: }
16223: }
16224: }
16225: $chgtext =~ s/\; $//;
1.178 raeburn 16226: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16227: }
16228: $resulttext .= '</ul>';
1.295 raeburn 16229: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
16230: if (ref($lastactref) eq 'HASH') {
16231: $lastactref->{'directorysrch'} = 1;
16232: }
1.23 raeburn 16233: } else {
1.277 raeburn 16234: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 16235: }
16236: } else {
16237: $resulttext = '<span class="LC_error">'.
1.27 raeburn 16238: &mt('An error occurred: [_1]',$putresult).'</span>';
16239: }
16240: return $resulttext;
16241: }
16242:
1.28 raeburn 16243: sub modify_contacts {
1.205 raeburn 16244: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 16245: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
16246: if (ref($domconfig{'contacts'}) eq 'HASH') {
16247: foreach my $key (keys(%{$domconfig{'contacts'}})) {
16248: $currsetting{$key} = $domconfig{'contacts'}{$key};
16249: }
16250: }
1.286 raeburn 16251: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 16252: my @contacts = ('supportemail','adminemail');
1.286 raeburn 16253: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 16254: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 16255: my @toggles = ('reporterrors','reportupdates','reportstatus');
16256: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 16257: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 16258: foreach my $type (@mailings) {
16259: @{$newsetting{$type}} =
16260: &Apache::loncommon::get_env_multiple('form.'.$type);
16261: foreach my $item (@contacts) {
16262: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
16263: $contacts_hash{contacts}{$type}{$item} = 1;
16264: } else {
16265: $contacts_hash{contacts}{$type}{$item} = 0;
16266: }
1.289 raeburn 16267: }
1.28 raeburn 16268: $others{$type} = $env{'form.'.$type.'_others'};
16269: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 16270: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16271: $bcc{$type} = $env{'form.'.$type.'_bcc'};
16272: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 16273: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
16274: $includestr{$type} = $env{'form.'.$type.'_includestr'};
16275: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
16276: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16277: }
1.134 raeburn 16278: }
1.28 raeburn 16279: }
16280: foreach my $item (@contacts) {
16281: $to{$item} = $env{'form.'.$item};
16282: $contacts_hash{'contacts'}{$item} = $to{$item};
16283: }
1.203 raeburn 16284: foreach my $item (@toggles) {
16285: if ($env{'form.'.$item} =~ /^(0|1)$/) {
16286: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
16287: }
16288: }
1.340 raeburn 16289: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
16290: foreach my $item (@lonstatus) {
16291: if ($item eq 'excluded') {
16292: my (%serverhomes,@excluded);
16293: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16294: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16295: if (@possexcluded) {
16296: foreach my $id (sort(@possexcluded)) {
16297: if ($serverhomes{$id}) {
16298: push(@excluded,$id);
16299: }
16300: }
16301: }
16302: if (@excluded) {
16303: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16304: }
16305: } elsif ($item eq 'weights') {
1.377 raeburn 16306: foreach my $type ('E','W','N','U') {
1.340 raeburn 16307: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16308: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16309: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16310: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16311: $env{'form.error'.$item.'_'.$type};
16312: }
16313: }
16314: }
16315: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16316: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16317: if ($env{'form.error'.$item} =~ /^\d+$/) {
16318: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16319: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16320: }
16321: }
16322: }
16323: }
1.286 raeburn 16324: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16325: foreach my $field (@{$fields}) {
16326: if (ref($possoptions->{$field}) eq 'ARRAY') {
16327: my $value = $env{'form.helpform_'.$field};
16328: $value =~ s/^\s+|\s+$//g;
16329: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16330: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16331: if ($field eq 'screenshot') {
16332: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16333: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16334: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16335: }
16336: }
16337: }
16338: }
16339: }
16340: }
1.315 raeburn 16341: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16342: my (@statuses,%usertypeshash,@overrides);
16343: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16344: @statuses = @{$types};
16345: if (ref($usertypes) eq 'HASH') {
16346: %usertypeshash = %{$usertypes};
16347: }
16348: }
16349: if (@statuses) {
16350: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16351: foreach my $type (@possoverrides) {
16352: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16353: push(@overrides,$type);
16354: }
16355: }
16356: if (@overrides) {
16357: foreach my $type (@overrides) {
16358: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16359: foreach my $item (@contacts) {
16360: if (grep(/^\Q$item\E$/,@standard)) {
16361: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16362: $newsetting{'override_'.$type}{$item} = 1;
16363: } else {
16364: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16365: $newsetting{'override_'.$type}{$item} = 0;
16366: }
16367: }
16368: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16369: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16370: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16371: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16372: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16373: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16374: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16375: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16376: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16377: }
16378: }
16379: }
16380: }
1.28 raeburn 16381: if (keys(%currsetting) > 0) {
16382: foreach my $item (@contacts) {
16383: if ($to{$item} ne $currsetting{$item}) {
16384: $changes{$item} = 1;
16385: }
16386: }
16387: foreach my $type (@mailings) {
16388: foreach my $item (@contacts) {
16389: if (ref($currsetting{$type}) eq 'HASH') {
16390: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16391: push(@{$changes{$type}},$item);
16392: }
16393: } else {
16394: push(@{$changes{$type}},@{$newsetting{$type}});
16395: }
16396: }
16397: if ($others{$type} ne $currsetting{$type}{'others'}) {
16398: push(@{$changes{$type}},'others');
16399: }
1.289 raeburn 16400: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16401: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16402: push(@{$changes{$type}},'bcc');
16403: }
1.286 raeburn 16404: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16405: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16406: push(@{$changes{$type}},'include');
16407: }
16408: }
16409: }
16410: if (ref($fields) eq 'ARRAY') {
16411: if (ref($currsetting{'helpform'}) eq 'HASH') {
16412: foreach my $field (@{$fields}) {
16413: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16414: push(@{$changes{'helpform'}},$field);
16415: }
16416: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16417: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16418: push(@{$changes{'helpform'}},'maxsize');
16419: }
16420: }
16421: }
16422: } else {
16423: foreach my $field (@{$fields}) {
16424: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16425: push(@{$changes{'helpform'}},$field);
16426: }
16427: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16428: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16429: push(@{$changes{'helpform'}},'maxsize');
16430: }
16431: }
16432: }
1.134 raeburn 16433: }
1.28 raeburn 16434: }
1.315 raeburn 16435: if (@statuses) {
16436: if (ref($currsetting{'overrides'}) eq 'HASH') {
16437: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16438: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16439: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16440: foreach my $item (@contacts,'bcc','others','include') {
16441: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16442: push(@{$changes{'overrides'}},$key);
16443: last;
16444: }
16445: }
16446: } else {
16447: push(@{$changes{'overrides'}},$key);
16448: }
16449: }
16450: }
16451: foreach my $key (@overrides) {
16452: unless (exists($currsetting{'overrides'}{$key})) {
16453: push(@{$changes{'overrides'}},$key);
16454: }
16455: }
16456: } else {
16457: foreach my $key (@overrides) {
16458: push(@{$changes{'overrides'}},$key);
16459: }
16460: }
16461: }
1.340 raeburn 16462: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16463: foreach my $key ('excluded','weights','threshold','sysmail') {
16464: if ($key eq 'excluded') {
16465: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16466: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16467: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16468: (@{$currsetting{'lonstatus'}{$key}})) {
16469: my @diffs =
16470: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16471: $currsetting{'lonstatus'}{$key});
16472: if (@diffs) {
16473: push(@{$changes{'lonstatus'}},$key);
16474: }
16475: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16476: push(@{$changes{'lonstatus'}},$key);
16477: }
16478: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16479: (@{$currsetting{'lonstatus'}{$key}})) {
16480: push(@{$changes{'lonstatus'}},$key);
16481: }
16482: } elsif ($key eq 'weights') {
16483: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16484: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16485: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16486: foreach my $type ('E','W','N','U') {
1.340 raeburn 16487: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16488: $currsetting{'lonstatus'}{$key}{$type}) {
16489: push(@{$changes{'lonstatus'}},$key);
16490: last;
16491: }
16492: }
16493: } else {
1.341 raeburn 16494: foreach my $type ('E','W','N','U') {
1.340 raeburn 16495: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16496: push(@{$changes{'lonstatus'}},$key);
16497: last;
16498: }
16499: }
16500: }
16501: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16502: foreach my $type ('E','W','N','U') {
1.340 raeburn 16503: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16504: push(@{$changes{'lonstatus'}},$key);
16505: last;
16506: }
16507: }
16508: }
16509: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16510: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16511: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16512: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16513: push(@{$changes{'lonstatus'}},$key);
16514: }
16515: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16516: push(@{$changes{'lonstatus'}},$key);
16517: }
16518: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16519: push(@{$changes{'lonstatus'}},$key);
16520: }
16521: }
16522: }
16523: } else {
16524: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16525: foreach my $key ('excluded','weights','threshold','sysmail') {
16526: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16527: push(@{$changes{'lonstatus'}},$key);
16528: }
16529: }
16530: }
16531: }
1.28 raeburn 16532: } else {
16533: my %default;
16534: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16535: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16536: $default{'errormail'} = 'adminemail';
16537: $default{'packagesmail'} = 'adminemail';
16538: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16539: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16540: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16541: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16542: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16543: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16544: foreach my $item (@contacts) {
16545: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16546: $changes{$item} = 1;
1.203 raeburn 16547: }
1.28 raeburn 16548: }
16549: foreach my $type (@mailings) {
16550: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16551: push(@{$changes{$type}},@{$newsetting{$type}});
16552: }
16553: if ($others{$type} ne '') {
16554: push(@{$changes{$type}},'others');
1.134 raeburn 16555: }
1.286 raeburn 16556: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16557: if ($bcc{$type} ne '') {
16558: push(@{$changes{$type}},'bcc');
16559: }
1.286 raeburn 16560: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16561: push(@{$changes{$type}},'include');
16562: }
1.134 raeburn 16563: }
1.28 raeburn 16564: }
1.286 raeburn 16565: if (ref($fields) eq 'ARRAY') {
16566: foreach my $field (@{$fields}) {
16567: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16568: push(@{$changes{'helpform'}},$field);
16569: }
16570: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16571: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16572: push(@{$changes{'helpform'}},'maxsize');
16573: }
16574: }
16575: }
1.289 raeburn 16576: }
1.340 raeburn 16577: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16578: foreach my $key ('excluded','weights','threshold','sysmail') {
16579: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16580: push(@{$changes{'lonstatus'}},$key);
16581: }
16582: }
16583: }
1.28 raeburn 16584: }
1.203 raeburn 16585: foreach my $item (@toggles) {
16586: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16587: $changes{$item} = 1;
16588: } elsif ((!$env{'form.'.$item}) &&
16589: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16590: $changes{$item} = 1;
16591: }
16592: }
1.28 raeburn 16593: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16594: $dom);
16595: if ($putresult eq 'ok') {
16596: if (keys(%changes) > 0) {
1.205 raeburn 16597: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16598: if (ref($lastactref) eq 'HASH') {
16599: $lastactref->{'domainconfig'} = 1;
16600: }
1.28 raeburn 16601: my ($titles,$short_titles) = &contact_titles();
16602: $resulttext = &mt('Changes made:').'<ul>';
16603: foreach my $item (@contacts) {
16604: if ($changes{$item}) {
16605: $resulttext .= '<li>'.$titles->{$item}.
16606: &mt(' set to: ').
16607: '<span class="LC_cusr_emph">'.
16608: $to{$item}.'</span></li>';
16609: }
16610: }
16611: foreach my $type (@mailings) {
16612: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16613: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16614: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16615: } else {
16616: $resulttext .= '<li>'.$titles->{$type}.': ';
16617: }
1.28 raeburn 16618: my @text;
16619: foreach my $item (@{$newsetting{$type}}) {
16620: push(@text,$short_titles->{$item});
16621: }
16622: if ($others{$type} ne '') {
16623: push(@text,$others{$type});
16624: }
1.286 raeburn 16625: if (@text) {
16626: $resulttext .= '<span class="LC_cusr_emph">'.
16627: join(', ',@text).'</span>';
16628: }
16629: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16630: if ($bcc{$type} ne '') {
1.286 raeburn 16631: my $bcctext;
16632: if (@text) {
1.289 raeburn 16633: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16634: } else {
16635: $bcctext = '(Bcc)';
16636: }
16637: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16638: } elsif (!@text) {
16639: $resulttext .= &mt('No one');
16640: }
1.289 raeburn 16641: if ($includestr{$type} ne '') {
1.286 raeburn 16642: if ($includeloc{$type} eq 'b') {
16643: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16644: } elsif ($includeloc{$type} eq 's') {
16645: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16646: }
1.134 raeburn 16647: }
1.286 raeburn 16648: } elsif (!@text) {
16649: $resulttext .= &mt('No recipients');
1.134 raeburn 16650: }
16651: $resulttext .= '</li>';
1.28 raeburn 16652: }
16653: }
1.315 raeburn 16654: if (ref($changes{'overrides'}) eq 'ARRAY') {
16655: my @deletions;
16656: foreach my $type (@{$changes{'overrides'}}) {
16657: if ($usertypeshash{$type}) {
16658: if (grep(/^\Q$type\E/,@overrides)) {
16659: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16660: $usertypeshash{$type}).'<ul><li>';
16661: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16662: my @text;
16663: foreach my $item (@contacts) {
16664: if ($newsetting{'override_'.$type}{$item}) {
16665: push(@text,$short_titles->{$item});
16666: }
16667: }
16668: if ($newsetting{'override_'.$type}{'others'} ne '') {
16669: push(@text,$newsetting{'override_'.$type}{'others'});
16670: }
16671:
16672: if (@text) {
16673: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16674: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16675: }
16676: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16677: my $bcctext;
16678: if (@text) {
16679: $bcctext = ' '.&mt('with Bcc to');
16680: } else {
16681: $bcctext = '(Bcc)';
16682: }
16683: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16684: } elsif (!@text) {
16685: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16686: }
16687: $resulttext .= '</li>';
16688: if ($newsetting{'override_'.$type}{'include'} ne '') {
16689: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16690: if ($loc eq 'b') {
16691: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16692: } elsif ($loc eq 's') {
16693: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16694: }
16695: }
16696: }
16697: $resulttext .= '</li></ul></li>';
16698: } else {
16699: push(@deletions,$usertypeshash{$type});
16700: }
16701: }
16702: }
16703: if (@deletions) {
16704: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16705: join(', ',@deletions)).'</li>';
16706: }
16707: }
1.203 raeburn 16708: my @offon = ('off','on');
1.340 raeburn 16709: my $corelink = &core_link_msu();
1.203 raeburn 16710: if ($changes{'reporterrors'}) {
16711: $resulttext .= '<li>'.
16712: &mt('E-mail error reports to [_1] set to "'.
16713: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16714: $corelink).
1.203 raeburn 16715: '</li>';
16716: }
16717: if ($changes{'reportupdates'}) {
16718: $resulttext .= '<li>'.
16719: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16720: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16721: $corelink).
1.203 raeburn 16722: '</li>';
16723: }
1.340 raeburn 16724: if ($changes{'reportstatus'}) {
16725: $resulttext .= '<li>'.
16726: &mt('E-mail status if errors above threshold to [_1] set to "'.
16727: $offon[$env{'form.reportstatus'}].'".',
16728: $corelink).
16729: '</li>';
16730: }
16731: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16732: $resulttext .= '<li>'.
16733: &mt('Nightly status check e-mail settings').':<ul>';
16734: my (%defval,%use_def,%shown);
16735: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
16736: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
16737: $defval{'weights'} =
1.341 raeburn 16738: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 16739: $defval{'excluded'} = &mt('None');
16740: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
16741: foreach my $item ('threshold','sysmail','weights','excluded') {
16742: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
16743: if (($item eq 'threshold') || ($item eq 'sysmail')) {
16744: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
16745: } elsif ($item eq 'weights') {
16746: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 16747: foreach my $type ('E','W','N','U') {
1.340 raeburn 16748: $shown{$item} .= $lonstatus_names->{$type}.'=';
16749: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
16750: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
16751: } else {
16752: $shown{$item} .= $lonstatus_defs->{$type};
16753: }
16754: $shown{$item} .= ', ';
16755: }
16756: $shown{$item} =~ s/, $//;
16757: } else {
16758: $shown{$item} = $defval{$item};
16759: }
16760: } elsif ($item eq 'excluded') {
16761: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
16762: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
16763: } else {
16764: $shown{$item} = $defval{$item};
16765: }
16766: }
16767: } else {
16768: $shown{$item} = $defval{$item};
16769: }
16770: }
16771: } else {
16772: foreach my $item ('threshold','weights','excluded','sysmail') {
16773: $shown{$item} = $defval{$item};
16774: }
16775: }
16776: foreach my $item ('threshold','weights','excluded','sysmail') {
16777: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
16778: $shown{$item}).'</li>';
16779: }
16780: $resulttext .= '</ul></li>';
16781: }
1.286 raeburn 16782: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
16783: my (@optional,@required,@unused,$maxsizechg);
16784: foreach my $field (@{$changes{'helpform'}}) {
16785: if ($field eq 'maxsize') {
16786: $maxsizechg = 1;
16787: next;
16788: }
16789: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 16790: push(@optional,$field);
1.286 raeburn 16791: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
16792: push(@unused,$field);
16793: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 16794: push(@required,$field);
1.286 raeburn 16795: }
16796: }
16797: if (@optional) {
16798: $resulttext .= '<li>'.
16799: &mt('Help form fields changed to "Optional": [_1].',
16800: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
16801: '</li>';
16802: }
16803: if (@required) {
16804: $resulttext .= '<li>'.
16805: &mt('Help form fields changed to "Required": [_1].',
16806: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
16807: '</li>';
16808: }
16809: if (@unused) {
16810: $resulttext .= '<li>'.
16811: &mt('Help form fields changed to "Not shown": [_1].',
16812: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
16813: '</li>';
16814: }
16815: if ($maxsizechg) {
16816: $resulttext .= '<li>'.
16817: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
16818: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
16819: '</li>';
16820: }
16821: }
1.28 raeburn 16822: $resulttext .= '</ul>';
16823: } else {
1.288 raeburn 16824: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 16825: }
16826: } else {
16827: $resulttext = '<span class="LC_error">'.
16828: &mt('An error occurred: [_1].',$putresult).'</span>';
16829: }
16830: return $resulttext;
16831: }
16832:
1.357 raeburn 16833: sub modify_privacy {
16834: my ($dom,%domconfig) = @_;
16835: my ($resulttext,%current,%changes);
16836: if (ref($domconfig{'privacy'}) eq 'HASH') {
16837: %current = %{$domconfig{'privacy'}};
16838: }
16839: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
16840: my @items = ('domain','author','course','community');
16841: my %names = &Apache::lonlocal::texthash (
16842: domain => 'Assigned domain role(s)',
16843: author => 'Assigned co-author role(s)',
16844: course => 'Assigned course role(s)',
1.416 raeburn 16845: community => 'Assigned community role(s)',
1.357 raeburn 16846: );
16847: my %roles = &Apache::lonlocal::texthash (
16848: domain => 'Domain role',
16849: author => 'Co-author role',
16850: course => 'Course role',
16851: community => 'Community role',
16852: );
16853: my %titles = &Apache::lonlocal::texthash (
16854: approval => 'Approval for role in different domain',
16855: othdom => 'User information available in other domain',
16856: priv => 'Information viewable by privileged user in same domain',
16857: unpriv => 'Information viewable by unprivileged user in same domain',
16858: instdom => 'Other domain shares institution/provider',
16859: extdom => 'Other domain has different institution/provider',
16860: none => 'Not allowed',
16861: user => 'User authorizes',
16862: domain => 'Domain Coordinator authorizes',
16863: auto => 'Unrestricted',
1.418 raeburn 16864: notify => 'Notify when role needs authorization',
1.357 raeburn 16865: );
16866: my %fieldnames = &Apache::lonlocal::texthash (
16867: id => 'Student/Employee ID',
16868: permanentemail => 'E-mail address',
16869: lastname => 'Last Name',
16870: firstname => 'First Name',
16871: middlename => 'Middle Name',
16872: generation => 'Generation',
16873: );
16874: my ($othertitle,$usertypes,$types) =
16875: &Apache::loncommon::sorted_inst_types($dom);
16876: my (%by_ip,%by_location,@intdoms,@instdoms);
16877: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16878:
16879: my %privacyhash = (
16880: 'approval' => {
16881: instdom => {},
16882: extdom => {},
16883: },
16884: 'othdom' => {},
16885: 'priv' => {},
16886: 'unpriv' => {},
16887: );
16888: foreach my $item (@items) {
16889: if (@instdoms > 1) {
1.416 raeburn 16890: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 16891: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
16892: }
16893: if (ref($current{'approval'}) eq 'HASH') {
16894: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
16895: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
16896: $changes{'approval'} = 1;
16897: }
16898: }
16899: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
16900: $changes{'approval'} = 1;
16901: }
16902: }
16903: if (keys(%by_location) > 0) {
16904: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
16905: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
16906: }
16907: if (ref($current{'approval'}) eq 'HASH') {
16908: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
16909: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
16910: $changes{'approval'} = 1;
16911: }
16912: }
16913: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
16914: $changes{'approval'} = 1;
16915: }
16916: }
16917: foreach my $status ('priv','unpriv') {
16918: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
16919: my @newvalues;
16920: foreach my $field (@possibles) {
16921: if (grep(/^\Q$field\E$/,@fields)) {
16922: $privacyhash{$status}{$item}{$field} = 1;
16923: push(@newvalues,$field);
16924: }
16925: }
16926: @newvalues = sort(@newvalues);
16927: if (ref($current{$status}) eq 'HASH') {
16928: if (ref($current{$status}{$item}) eq 'HASH') {
16929: my @currvalues = sort(keys(%{$current{$status}{$item}}));
16930: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16931: if (@diffs > 0) {
16932: $changes{$status} = 1;
16933: }
16934: }
16935: } else {
16936: my @stdfields;
16937: foreach my $field (@fields) {
16938: if ($field eq 'id') {
16939: next if ($status eq 'unpriv');
16940: next if (($status eq 'priv') && ($item eq 'community'));
16941: }
16942: push(@stdfields,$field);
16943: }
16944: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16945: if (@diffs > 0) {
16946: $changes{$status} = 1;
16947: }
16948: }
16949: }
16950: }
16951: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
16952: my @statuses;
16953: if (ref($types) eq 'ARRAY') {
16954: @statuses = @{$types};
16955: }
16956: foreach my $type (@statuses,'default') {
16957: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
16958: my @newvalues;
16959: foreach my $field (sort(@possfields)) {
16960: if (grep(/^\Q$field\E$/,@fields)) {
16961: $privacyhash{'othdom'}{$type}{$field} = 1;
16962: push(@newvalues,$field);
16963: }
16964: }
16965: @newvalues = sort(@newvalues);
16966: if (ref($current{'othdom'}) eq 'HASH') {
16967: if (ref($current{'othdom'}{$type}) eq 'HASH') {
16968: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
16969: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16970: if (@diffs > 0) {
16971: $changes{'othdom'} = 1;
16972: }
16973: }
16974: } else {
16975: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
16976: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16977: if (@diffs > 0) {
16978: $changes{'othdom'} = 1;
16979: }
16980: }
16981: }
1.417 raeburn 16982: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
16983: my %notify;
16984: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
16985: if (exists($domcoords{$possdc})) {
16986: $notify{$possdc} = 1;
16987: }
16988: }
16989: my $notify = join(',',sort(keys(%notify)));
16990: if ($current{'notify'} ne $notify) {
16991: $changes{'notify'} = 1;
16992: }
16993: $privacyhash{'notify'} = $notify;
1.357 raeburn 16994: }
16995: my %confighash = (
16996: privacy => \%privacyhash,
16997: );
16998: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16999: if ($putresult eq 'ok') {
17000: if (keys(%changes) > 0) {
17001: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17002: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17003: if ($changes{$key}) {
17004: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17005: if ($key eq 'approval') {
17006: if (keys(%{$privacyhash{$key}{instdom}})) {
17007: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17008: foreach my $item (@items) {
17009: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17010: }
17011: $resulttext .= '</ul></li>';
17012: }
17013: if (keys(%{$privacyhash{$key}{extdom}})) {
17014: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17015: foreach my $item (@items) {
17016: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17017: }
17018: $resulttext .= '</ul></li>';
17019: }
1.417 raeburn 17020: } elsif ($key eq 'notify') {
17021: if ($privacyhash{$key}) {
17022: foreach my $dc (split(/,/,$privacyhash{$key})) {
17023: my ($dcname,$dcdom) = split(/:/,$dc);
17024: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17025: }
17026: } else {
17027: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17028: }
1.357 raeburn 17029: } elsif ($key eq 'othdom') {
17030: my @statuses;
17031: if (ref($types) eq 'ARRAY') {
17032: @statuses = @{$types};
17033: }
17034: if (ref($privacyhash{$key}) eq 'HASH') {
17035: foreach my $status (@statuses,'default') {
17036: if ($status eq 'default') {
17037: $resulttext .= '<li>'.$othertitle.': ';
17038: } elsif (ref($usertypes) eq 'HASH') {
17039: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17040: } else {
17041: next;
17042: }
17043: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17044: if (keys(%{$privacyhash{$key}{$status}})) {
17045: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17046: } else {
17047: $resulttext .= &mt('none');
17048: }
17049: }
17050: $resulttext .= '</li>';
17051: }
17052: }
17053: } else {
17054: foreach my $item (@items) {
17055: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17056: $resulttext .= '<li>'.$names{$item}.': ';
17057: if (keys(%{$privacyhash{$key}{$item}})) {
17058: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17059: } else {
17060: $resulttext .= &mt('none');
17061: }
17062: $resulttext .= '</li>';
17063: }
17064: }
17065: }
17066: $resulttext .= '</ul></li>';
17067: }
17068: }
1.421 ! raeburn 17069: $resulttext .= '</ul>';
1.357 raeburn 17070: } else {
17071: $resulttext = &mt('No changes made to user information settings');
17072: }
17073: } else {
17074: $resulttext = '<span class="LC_error">'.
17075: &mt('An error occurred: [_1]',$putresult).'</span>';
17076: }
17077: return $resulttext;
17078: }
17079:
1.354 raeburn 17080: sub modify_passwords {
17081: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17082: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17083: $updatedefaults,$updateconf);
1.354 raeburn 17084: my $customfn = 'resetpw.html';
17085: if (ref($domconfig{'passwords'}) eq 'HASH') {
17086: %current = %{$domconfig{'passwords'}};
17087: }
17088: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17089: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17090: if (ref($types) eq 'ARRAY') {
17091: @oktypes = @{$types};
17092: }
17093: push(@oktypes,'default');
17094:
17095: my %titles = &Apache::lonlocal::texthash (
17096: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17097: intauth_check => 'Check bcrypt cost if authenticated',
17098: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17099: permanent => 'Permanent e-mail address',
17100: critical => 'Critical notification address',
17101: notify => 'Notification address',
17102: min => 'Minimum password length',
17103: max => 'Maximum password length',
17104: chars => 'Required characters',
17105: expire => 'Password expiration (days)',
1.356 raeburn 17106: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17107: reset => 'Resetting Forgotten Password',
17108: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17109: rules => 'Rules for LON-CAPA Passwords',
17110: crsownerchg => 'Course Owner Changing Student Passwords',
17111: username => 'Username',
17112: email => 'E-mail address',
17113: );
17114:
17115: #
17116: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17117: #
17118: my (%curr_defaults,%save_defaults);
17119: if (ref($domconfig{'defaults'}) eq 'HASH') {
17120: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17121: if ($key =~ /^intauth_(cost|check|switch)$/) {
17122: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17123: } else {
17124: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17125: }
17126: }
17127: }
17128: my %staticdefaults = (
17129: 'resetlink' => 2,
17130: 'resetcase' => \@oktypes,
17131: 'resetprelink' => 'both',
17132: 'resetemail' => ['critical','notify','permanent'],
17133: 'intauth_cost' => 10,
17134: 'intauth_check' => 0,
17135: 'intauth_switch' => 0,
17136: );
1.365 raeburn 17137: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17138: foreach my $type (@oktypes) {
17139: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17140: }
17141: my $linklife = $env{'form.passwords_link'};
17142: $linklife =~ s/^\s+|\s+$//g;
17143: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17144: $newvalues{'resetlink'} = $linklife;
17145: if ($current{'resetlink'}) {
17146: if ($current{'resetlink'} ne $linklife) {
17147: $changes{'reset'} = 1;
17148: }
1.368 raeburn 17149: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17150: if ($staticdefaults{'resetlink'} ne $linklife) {
17151: $changes{'reset'} = 1;
17152: }
17153: }
17154: } elsif ($current{'resetlink'}) {
17155: $changes{'reset'} = 1;
17156: }
17157: my @casesens;
17158: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17159: foreach my $case (sort(@posscase)) {
17160: if (grep(/^\Q$case\E$/,@oktypes)) {
17161: push(@casesens,$case);
17162: }
17163: }
17164: $newvalues{'resetcase'} = \@casesens;
17165: if (ref($current{'resetcase'}) eq 'ARRAY') {
17166: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17167: if (@diffs > 0) {
17168: $changes{'reset'} = 1;
17169: }
1.368 raeburn 17170: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17171: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17172: if (@diffs > 0) {
17173: $changes{'reset'} = 1;
17174: }
17175: }
17176: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17177: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17178: if (exists($current{'resetprelink'})) {
17179: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17180: $changes{'reset'} = 1;
17181: }
1.368 raeburn 17182: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17183: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17184: $changes{'reset'} = 1;
17185: }
17186: }
17187: } elsif ($current{'resetprelink'}) {
17188: $changes{'reset'} = 1;
17189: }
17190: foreach my $type (@oktypes) {
17191: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17192: my @postlink;
17193: foreach my $item (sort(@possplink)) {
17194: if ($item =~ /^(email|username)$/) {
17195: push(@postlink,$item);
17196: }
17197: }
17198: $newvalues{'resetpostlink'}{$type} = \@postlink;
17199: unless ($changes{'reset'}) {
17200: if (ref($current{'resetpostlink'}) eq 'HASH') {
17201: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17202: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17203: if (@diffs > 0) {
17204: $changes{'reset'} = 1;
17205: }
17206: } else {
17207: $changes{'reset'} = 1;
17208: }
1.368 raeburn 17209: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17210: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
17211: if (@diffs > 0) {
17212: $changes{'reset'} = 1;
17213: }
17214: }
17215: }
17216: }
17217: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
17218: my @resetemail;
17219: foreach my $item (sort(@possemailsrc)) {
17220: if ($item =~ /^(permanent|critical|notify)$/) {
17221: push(@resetemail,$item);
17222: }
17223: }
17224: $newvalues{'resetemail'} = \@resetemail;
17225: unless ($changes{'reset'}) {
17226: if (ref($current{'resetemail'}) eq 'ARRAY') {
17227: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
17228: if (@diffs > 0) {
17229: $changes{'reset'} = 1;
17230: }
1.368 raeburn 17231: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17232: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
17233: if (@diffs > 0) {
17234: $changes{'reset'} = 1;
17235: }
17236: }
17237: }
17238: if ($env{'form.passwords_stdtext'} == 0) {
17239: $newvalues{'resetremove'} = 1;
17240: unless ($current{'resetremove'}) {
17241: $changes{'reset'} = 1;
17242: }
17243: } elsif ($current{'resetremove'}) {
17244: $changes{'reset'} = 1;
17245: }
17246: if ($env{'form.passwords_customfile.filename'} ne '') {
17247: my $servadm = $r->dir_config('lonAdmEMail');
17248: my ($configuserok,$author_ok,$switchserver) =
17249: &config_check($dom,$confname,$servadm);
17250: my $error;
17251: if ($configuserok eq 'ok') {
17252: if ($switchserver) {
17253: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
17254: } else {
17255: if ($author_ok eq 'ok') {
1.421 ! raeburn 17256: my $modified = [];
1.354 raeburn 17257: my ($result,$customurl) =
1.421 ! raeburn 17258: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
! 17259: $confname,'customtext/resetpw','','',$customfn,
! 17260: $modified);
1.354 raeburn 17261: if ($result eq 'ok') {
17262: $newvalues{'resetcustom'} = $customurl;
17263: $changes{'reset'} = 1;
1.421 ! raeburn 17264: &update_modify_urls($r,$modified);
1.354 raeburn 17265: } else {
17266: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
17267: }
17268: } else {
17269: $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);
17270: }
17271: }
17272: } else {
17273: $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);
17274: }
17275: if ($error) {
17276: &Apache::lonnet::logthis($error);
17277: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17278: }
17279: } elsif ($current{'resetcustom'}) {
17280: if ($env{'form.passwords_custom_del'}) {
17281: $changes{'reset'} = 1;
17282: } else {
17283: $newvalues{'resetcustom'} = $current{'resetcustom'};
17284: }
17285: }
17286: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
17287: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
17288: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
17289: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
17290: $changes{'intauth'} = 1;
17291: }
17292: } else {
17293: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
17294: }
17295: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
17296: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
17297: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
17298: $changes{'intauth'} = 1;
17299: }
17300: } else {
17301: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17302: }
17303: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
17304: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
17305: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
17306: $changes{'intauth'} = 1;
17307: }
17308: } else {
17309: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17310: }
17311: foreach my $item ('cost','check','switch') {
17312: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
17313: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
17314: $updatedefaults = 1;
17315: }
17316: }
1.405 raeburn 17317: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 17318: my %crsownerchg = (
17319: by => [],
17320: for => [],
17321: );
17322: foreach my $item ('by','for') {
17323: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17324: foreach my $type (sort(@posstypes)) {
17325: if (grep(/^\Q$type\E$/,@oktypes)) {
17326: push(@{$crsownerchg{$item}},$type);
17327: }
17328: }
17329: }
17330: $newvalues{'crsownerchg'} = \%crsownerchg;
17331: if (ref($current{'crsownerchg'}) eq 'HASH') {
17332: foreach my $item ('by','for') {
17333: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17334: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17335: if (@diffs > 0) {
17336: $changes{'crsownerchg'} = 1;
17337: last;
17338: }
17339: }
17340: }
1.368 raeburn 17341: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17342: foreach my $item ('by','for') {
17343: if (@{$crsownerchg{$item}} > 0) {
17344: $changes{'crsownerchg'} = 1;
17345: last;
17346: }
1.354 raeburn 17347: }
17348: }
17349:
17350: my %confighash = (
17351: defaults => \%save_defaults,
17352: passwords => \%newvalues,
17353: );
17354: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17355:
17356: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17357: if ($putresult eq 'ok') {
17358: if (keys(%changes) > 0) {
17359: $resulttext = &mt('Changes made: ').'<ul>';
17360: foreach my $key ('reset','intauth','rules','crsownerchg') {
17361: if ($changes{$key}) {
1.355 raeburn 17362: unless ($key eq 'intauth') {
17363: $updateconf = 1;
17364: }
1.354 raeburn 17365: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17366: if ($key eq 'reset') {
17367: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17368: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17369: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17370: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17371: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17372: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17373: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17374: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17375: }
1.354 raeburn 17376: } else {
17377: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17378: }
17379: if ($confighash{'passwords'}{'resetlink'}) {
17380: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17381: } else {
17382: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17383: &mt('Will default to 2 hours').'</li>';
17384: }
17385: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17386: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17387: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17388: } else {
17389: my $casesens;
17390: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17391: if ($type eq 'default') {
17392: $casesens .= $othertitle.', ';
17393: } elsif ($usertypes->{$type} ne '') {
17394: $casesens .= $usertypes->{$type}.', ';
17395: }
17396: }
17397: $casesens =~ s/\Q, \E$//;
17398: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17399: }
17400: } else {
17401: $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>';
17402: }
17403: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17404: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17405: } else {
17406: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17407: }
17408: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17409: my $output;
17410: if (ref($types) eq 'ARRAY') {
17411: foreach my $type (@{$types}) {
17412: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17413: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17414: $output .= $usertypes->{$type}.' -- '.&mt('none');
17415: } else {
17416: $output .= $usertypes->{$type}.' -- '.
17417: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17418: }
17419: }
17420: }
17421: }
17422: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17423: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17424: $output .= $othertitle.' -- '.&mt('none');
17425: } else {
17426: $output .= $othertitle.' -- '.
17427: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17428: }
17429: }
17430: if ($output) {
17431: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17432: } else {
17433: $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>';
17434: }
17435: } else {
17436: $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>';
17437: }
17438: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17439: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17440: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17441: } else {
17442: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17443: }
17444: } else {
1.379 raeburn 17445: $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 17446: }
17447: if ($confighash{'passwords'}{'resetremove'}) {
17448: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17449: } else {
17450: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17451: }
17452: if ($confighash{'passwords'}{'resetcustom'}) {
17453: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17454: &mt('custom text'),600,500,undef,undef,
17455: undef,undef,'background-color:#ffffff');
17456: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17457: } else {
17458: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17459: }
17460: } elsif ($key eq 'intauth') {
17461: foreach my $item ('cost','switch','check') {
17462: my $value = $save_defaults{$key.'_'.$item};
17463: if ($item eq 'switch') {
17464: my %optiondesc = &Apache::lonlocal::texthash (
17465: 0 => 'No',
17466: 1 => 'Yes',
17467: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17468: );
17469: if ($value =~ /^(0|1|2)$/) {
17470: $value = $optiondesc{$value};
17471: } else {
17472: $value = &mt('none -- defaults to No');
17473: }
17474: } elsif ($item eq 'check') {
17475: my %optiondesc = &Apache::lonlocal::texthash (
17476: 0 => 'No',
17477: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17478: 2 => 'Yes, disallow login if stored cost is less than domain default',
17479: );
17480: if ($value =~ /^(0|1|2)$/) {
17481: $value = $optiondesc{$value};
17482: } else {
17483: $value = &mt('none -- defaults to No');
17484: }
17485: }
17486: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17487: }
17488: } elsif ($key eq 'rules') {
1.356 raeburn 17489: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17490: if ($confighash{'passwords'}{$rule} eq '') {
17491: if ($rule eq 'min') {
1.356 raeburn 17492: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17493: ' '.&mt('Default of [_1] will be used',
17494: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17495: } else {
17496: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17497: }
17498: } else {
17499: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17500: }
17501: }
1.370 raeburn 17502: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17503: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17504: my %rulenames = &Apache::lonlocal::texthash(
17505: uc => 'At least one upper case letter',
17506: lc => 'At least one lower case letter',
17507: num => 'At least one number',
17508: spec => 'At least one non-alphanumeric',
17509: );
17510: my $needed = '<ul><li>'.
17511: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17512: '</li></ul>';
17513: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17514: } else {
17515: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17516: }
17517: } else {
17518: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17519: }
1.354 raeburn 17520: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17521: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17522: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17523: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17524: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17525: } else {
17526: my %crsownerstr;
17527: foreach my $item ('by','for') {
17528: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17529: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17530: if ($type eq 'default') {
17531: $crsownerstr{$item} .= $othertitle.', ';
17532: } elsif ($usertypes->{$type} ne '') {
17533: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17534: }
17535: }
17536: $crsownerstr{$item} =~ s/\Q, \E$//;
17537: }
17538: }
17539: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17540: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17541: }
1.354 raeburn 17542: } else {
1.359 raeburn 17543: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17544: }
17545: }
17546: $resulttext .= '</ul></li>';
17547: }
17548: }
17549: $resulttext .= '</ul>';
17550: } else {
17551: $resulttext = &mt('No changes made to password settings');
17552: }
1.355 raeburn 17553: my $cachetime = 24*60*60;
1.354 raeburn 17554: if ($updatedefaults) {
17555: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17556: if (ref($lastactref) eq 'HASH') {
17557: $lastactref->{'domdefaults'} = 1;
17558: }
17559: }
1.355 raeburn 17560: if ($updateconf) {
17561: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17562: if (ref($lastactref) eq 'HASH') {
17563: $lastactref->{'passwdconf'} = 1;
17564: }
17565: }
1.354 raeburn 17566: } else {
17567: $resulttext = '<span class="LC_error">'.
17568: &mt('An error occurred: [_1]',$putresult).'</span>';
17569: }
17570: if ($errors) {
17571: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17572: $errors.'</ul></p>';
17573: }
17574: return $resulttext;
17575: }
17576:
1.405 raeburn 17577: sub password_rule_changes {
17578: my ($prefix,$newvalues,$current,$changes) = @_;
17579: return unless ((ref($newvalues) eq 'HASH') &&
17580: (ref($current) eq 'HASH') &&
17581: (ref($changes) eq 'HASH'));
17582: my (@rules,%staticdefaults);
17583: if ($prefix eq 'passwords') {
17584: @rules = ('min','max','expire','numsaved');
1.421 ! raeburn 17585: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 17586: @rules = ('min','max');
17587: }
17588: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
17589: foreach my $rule (@rules) {
17590: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
17591: my $ruleok;
17592: if ($rule eq 'expire') {
17593: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17594: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
17595: $ruleok = 1;
17596: }
17597: } elsif ($rule eq 'min') {
17598: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
17599: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
17600: $ruleok = 1;
17601: }
17602: }
17603: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
17604: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
17605: $ruleok = 1;
17606: }
17607: if ($ruleok) {
17608: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
17609: if (exists($current->{$rule})) {
17610: if ($newvalues->{$rule} ne $current->{$rule}) {
17611: $changes->{'rules'} = 1;
17612: }
17613: } elsif ($rule eq 'min') {
17614: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
17615: $changes->{'rules'} = 1;
17616: }
17617: } else {
17618: $changes->{'rules'} = 1;
17619: }
17620: } elsif (exists($current->{$rule})) {
17621: $changes->{'rules'} = 1;
17622: }
17623: }
17624: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
17625: my @chars;
17626: foreach my $item (sort(@posschars)) {
17627: if ($item =~ /^(uc|lc|num|spec)$/) {
17628: push(@chars,$item);
17629: }
17630: }
17631: $newvalues->{'chars'} = \@chars;
17632: unless ($changes->{'rules'}) {
17633: if (ref($current->{'chars'}) eq 'ARRAY') {
17634: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
17635: if (@diffs > 0) {
17636: $changes->{'rules'} = 1;
17637: }
17638: } else {
17639: if (@chars > 0) {
17640: $changes->{'rules'} = 1;
17641: }
17642: }
17643: }
17644: return;
17645: }
17646:
1.28 raeburn 17647: sub modify_usercreation {
1.27 raeburn 17648: my ($dom,%domconfig) = @_;
1.224 raeburn 17649: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17650: my $warningmsg;
1.27 raeburn 17651: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17652: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17653: if ($key eq 'cancreate') {
17654: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17655: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17656: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17657: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17658: } else {
1.224 raeburn 17659: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17660: }
17661: }
17662: }
17663: } elsif ($key eq 'email_rule') {
17664: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17665: } else {
17666: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17667: }
1.27 raeburn 17668: }
17669: }
17670: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17671: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17672: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17673: foreach my $item(@contexts) {
1.224 raeburn 17674: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17675: }
1.34 raeburn 17676: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17677: foreach my $item (@contexts) {
1.224 raeburn 17678: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17679: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17680: }
1.27 raeburn 17681: }
1.34 raeburn 17682: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17683: foreach my $item (@contexts) {
1.43 raeburn 17684: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17685: if ($cancreate{$item} ne 'any') {
17686: push(@{$changes{'cancreate'}},$item);
17687: }
17688: } else {
17689: if ($cancreate{$item} ne 'none') {
17690: push(@{$changes{'cancreate'}},$item);
17691: }
1.27 raeburn 17692: }
17693: }
17694: } else {
1.43 raeburn 17695: foreach my $item (@contexts) {
1.34 raeburn 17696: push(@{$changes{'cancreate'}},$item);
17697: }
1.27 raeburn 17698: }
1.34 raeburn 17699:
1.27 raeburn 17700: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17701: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17702: if (!grep(/^\Q$type\E$/,@username_rule)) {
17703: push(@{$changes{'username_rule'}},$type);
17704: }
17705: }
17706: foreach my $type (@username_rule) {
17707: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17708: push(@{$changes{'username_rule'}},$type);
17709: }
17710: }
17711: } else {
17712: push(@{$changes{'username_rule'}},@username_rule);
17713: }
17714:
1.32 raeburn 17715: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17716: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17717: if (!grep(/^\Q$type\E$/,@id_rule)) {
17718: push(@{$changes{'id_rule'}},$type);
17719: }
17720: }
17721: foreach my $type (@id_rule) {
17722: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17723: push(@{$changes{'id_rule'}},$type);
17724: }
17725: }
17726: } else {
17727: push(@{$changes{'id_rule'}},@id_rule);
17728: }
17729:
1.43 raeburn 17730: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17731: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17732: my %authhash;
1.43 raeburn 17733: foreach my $item (@authen_contexts) {
1.28 raeburn 17734: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17735: foreach my $auth (@authtypes) {
17736: if (grep(/^\Q$auth\E$/,@authallowed)) {
17737: $authhash{$item}{$auth} = 1;
17738: } else {
17739: $authhash{$item}{$auth} = 0;
17740: }
17741: }
17742: }
17743: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17744: foreach my $item (@authen_contexts) {
1.28 raeburn 17745: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17746: foreach my $auth (@authtypes) {
17747: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17748: push(@{$changes{'authtypes'}},$item);
17749: last;
17750: }
17751: }
17752: }
17753: }
17754: } else {
1.43 raeburn 17755: foreach my $item (@authen_contexts) {
1.28 raeburn 17756: push(@{$changes{'authtypes'}},$item);
17757: }
17758: }
17759:
1.224 raeburn 17760: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17761: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17762: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17763: $save_usercreate{'id_rule'} = \@id_rule;
17764: $save_usercreate{'username_rule'} = \@username_rule,
17765: $save_usercreate{'authtypes'} = \%authhash;
17766:
1.27 raeburn 17767: my %usercreation_hash = (
1.224 raeburn 17768: usercreation => \%save_usercreate,
17769: );
1.27 raeburn 17770:
17771: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17772: $dom);
1.50 raeburn 17773:
1.224 raeburn 17774: if ($putresult eq 'ok') {
17775: if (keys(%changes) > 0) {
17776: $resulttext = &mt('Changes made:').'<ul>';
17777: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17778: my %lt = &usercreation_types();
17779: foreach my $type (@{$changes{'cancreate'}}) {
17780: my $chgtext = $lt{$type}.', ';
17781: if ($cancreate{$type} eq 'none') {
17782: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
17783: } elsif ($cancreate{$type} eq 'any') {
17784: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
17785: } elsif ($cancreate{$type} eq 'official') {
17786: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
17787: } elsif ($cancreate{$type} eq 'unofficial') {
17788: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
17789: }
17790: $resulttext .= '<li>'.$chgtext.'</li>';
17791: }
17792: }
17793: if (ref($changes{'username_rule'}) eq 'ARRAY') {
17794: my ($rules,$ruleorder) =
17795: &Apache::lonnet::inst_userrules($dom,'username');
17796: my $chgtext = '<ul>';
17797: foreach my $type (@username_rule) {
17798: if (ref($rules->{$type}) eq 'HASH') {
17799: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
17800: }
17801: }
17802: $chgtext .= '</ul>';
17803: if (@username_rule > 0) {
17804: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17805: } else {
17806: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
17807: }
17808: }
17809: if (ref($changes{'id_rule'}) eq 'ARRAY') {
17810: my ($idrules,$idruleorder) =
17811: &Apache::lonnet::inst_userrules($dom,'id');
17812: my $chgtext = '<ul>';
17813: foreach my $type (@id_rule) {
17814: if (ref($idrules->{$type}) eq 'HASH') {
17815: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
17816: }
17817: }
17818: $chgtext .= '</ul>';
17819: if (@id_rule > 0) {
17820: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17821: } else {
17822: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
17823: }
17824: }
17825: my %authname = &authtype_names();
17826: my %context_title = &context_names();
17827: if (ref($changes{'authtypes'}) eq 'ARRAY') {
17828: my $chgtext = '<ul>';
17829: foreach my $type (@{$changes{'authtypes'}}) {
17830: my @allowed;
17831: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
17832: foreach my $auth (@authtypes) {
17833: if ($authhash{$type}{$auth}) {
17834: push(@allowed,$authname{$auth});
17835: }
17836: }
17837: if (@allowed > 0) {
17838: $chgtext .= join(', ',@allowed).'</li>';
17839: } else {
17840: $chgtext .= &mt('none').'</li>';
17841: }
17842: }
17843: $chgtext .= '</ul>';
17844: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
17845: $resulttext .= '</li>';
17846: }
17847: $resulttext .= '</ul>';
17848: } else {
17849: $resulttext = &mt('No changes made to user creation settings');
17850: }
17851: } else {
17852: $resulttext = '<span class="LC_error">'.
17853: &mt('An error occurred: [_1]',$putresult).'</span>';
17854: }
17855: if ($warningmsg ne '') {
17856: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17857: }
17858: return $resulttext;
17859: }
17860:
17861: sub modify_selfcreation {
1.305 raeburn 17862: my ($dom,$lastactref,%domconfig) = @_;
17863: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
17864: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
17865: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 17866: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
17867: if (ref($typesref) eq 'ARRAY') {
17868: @types = @{$typesref};
17869: }
17870: if (ref($usertypesref) eq 'HASH') {
17871: %usertypes = %{$usertypesref};
1.228 raeburn 17872: }
1.303 raeburn 17873: $usertypes{'default'} = $othertitle;
1.224 raeburn 17874: #
17875: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
17876: #
17877: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17878: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
17879: if ($key eq 'cancreate') {
17880: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17881: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
17882: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 17883: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
17884: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
17885: ($item eq 'emailusername') || ($item eq 'shibenv') ||
17886: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 17887: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 17888: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17889: } else {
17890: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17891: }
17892: }
17893: }
17894: } elsif ($key eq 'email_rule') {
17895: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17896: } else {
17897: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17898: }
17899: }
17900: }
17901: #
17902: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
17903: #
17904: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17905: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
17906: if ($key eq 'selfcreate') {
17907: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
17908: } else {
17909: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
17910: }
17911: }
17912: }
1.305 raeburn 17913: #
17914: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
17915: #
17916: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17917: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
17918: if ($key eq 'inststatusguest') {
17919: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
17920: } else {
17921: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
17922: }
17923: }
17924: }
1.224 raeburn 17925:
17926: my @contexts = ('selfcreate');
17927: @{$cancreate{'selfcreate'}} = ();
17928: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 17929: if (@types) {
17930: @{$cancreate{'statustocreate'}} = ();
17931: }
1.236 raeburn 17932: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 17933: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 17934: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 17935: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 17936: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 17937: my %selfcreatetypes = (
17938: sso => 'users authenticated by institutional single sign on',
17939: login => 'users authenticated by institutional log-in',
1.303 raeburn 17940: email => 'users verified by e-mail',
1.50 raeburn 17941: );
1.224 raeburn 17942: #
17943: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
17944: # is permitted.
17945: #
1.305 raeburn 17946: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 17947:
1.305 raeburn 17948: my (@statuses,%email_rule);
1.228 raeburn 17949: foreach my $item ('login','sso','email') {
1.224 raeburn 17950: if ($item eq 'email') {
1.236 raeburn 17951: if ($env{'form.cancreate_email'}) {
1.305 raeburn 17952: if (@types) {
17953: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
17954: foreach my $status (@poss_statuses) {
17955: if (grep(/^\Q$status\E$/,(@types,'default'))) {
17956: push(@statuses,$status);
17957: }
17958: }
17959: $save_inststatus{'inststatusguest'} = \@statuses;
17960: } else {
17961: push(@statuses,'default');
17962: }
17963: if (@statuses) {
17964: my %curr_rule;
17965: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
17966: foreach my $type (@statuses) {
17967: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 17968: }
1.305 raeburn 17969: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
17970: foreach my $type (@statuses) {
17971: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
17972: }
17973: }
17974: push(@{$cancreate{'selfcreate'}},'email');
17975: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
17976: my %curremaildom;
17977: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
17978: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
17979: }
17980: foreach my $type (@statuses) {
17981: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
17982: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
17983: }
17984: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
17985: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
17986: }
17987: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
17988: #
17989: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
17990: #
17991: my $chosen = $1;
17992: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
17993: my $emaildom;
17994: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
17995: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
17996: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
17997: if (ref($curremaildom{$type}) eq 'HASH') {
17998: if (exists($curremaildom{$type}{$chosen})) {
17999: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18000: push(@{$changes{'cancreate'}},'emaildomain');
18001: }
18002: } elsif ($emaildom ne '') {
18003: push(@{$changes{'cancreate'}},'emaildomain');
18004: }
18005: } elsif ($emaildom ne '') {
18006: push(@{$changes{'cancreate'}},'emaildomain');
18007: }
18008: }
18009: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18010: } elsif ($chosen eq 'custom') {
18011: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18012: $email_rule{$type} = [];
18013: if (ref($emailrules) eq 'HASH') {
18014: foreach my $rule (@possemail_rules) {
18015: if (exists($emailrules->{$rule})) {
18016: push(@{$email_rule{$type}},$rule);
18017: }
18018: }
18019: }
18020: if (@{$email_rule{$type}}) {
18021: $cancreate{'emailoptions'}{$type} = 'custom';
18022: if (ref($curr_rule{$type}) eq 'ARRAY') {
18023: if (@{$curr_rule{$type}} > 0) {
18024: foreach my $rule (@{$curr_rule{$type}}) {
18025: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18026: push(@{$changes{'email_rule'}},$type);
18027: }
18028: }
18029: }
18030: foreach my $type (@{$email_rule{$type}}) {
18031: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18032: push(@{$changes{'email_rule'}},$type);
18033: }
18034: }
18035: } else {
18036: push(@{$changes{'email_rule'}},$type);
18037: }
18038: }
18039: } else {
18040: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18041: }
18042: }
18043: }
18044: if (@types) {
18045: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18046: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18047: if (@changed) {
18048: push(@{$changes{'inststatus'}},'inststatusguest');
18049: }
18050: } else {
18051: push(@{$changes{'inststatus'}},'inststatusguest');
18052: }
18053: }
18054: } else {
18055: delete($env{'form.cancreate_email'});
18056: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18057: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18058: push(@{$changes{'inststatus'}},'inststatusguest');
18059: }
18060: }
18061: }
18062: } else {
18063: $save_inststatus{'inststatusguest'} = [];
18064: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18065: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18066: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18067: }
18068: }
1.224 raeburn 18069: }
18070: } else {
18071: if ($env{'form.cancreate_'.$item}) {
18072: push(@{$cancreate{'selfcreate'}},$item);
18073: }
18074: }
18075: }
1.305 raeburn 18076: my (%userinfo,%savecaptcha);
1.224 raeburn 18077: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18078: #
1.228 raeburn 18079: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18080: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18081: #
1.236 raeburn 18082:
1.244 raeburn 18083: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18084: push(@contexts,'emailusername');
1.305 raeburn 18085: if (@statuses) {
18086: foreach my $type (@statuses) {
1.228 raeburn 18087: if (ref($infofields) eq 'ARRAY') {
18088: foreach my $field (@{$infofields}) {
18089: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18090: $cancreate{'emailusername'}{$type}{$field} = $1;
18091: }
18092: }
1.224 raeburn 18093: }
18094: }
18095: }
18096: #
18097: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18098: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18099: #
18100:
18101: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18102: @approvalnotify = sort(@approvalnotify);
18103: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18104: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18105: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18106: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18107: push(@{$changes{'cancreate'}},'notify');
18108: }
18109: } else {
18110: if ($cancreate{'notify'}{'approval'}) {
18111: push(@{$changes{'cancreate'}},'notify');
18112: }
18113: }
18114: } elsif ($cancreate{'notify'}{'approval'}) {
18115: push(@{$changes{'cancreate'}},'notify');
18116: }
18117:
18118: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18119: }
18120: #
1.236 raeburn 18121: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18122: # institutional log-in.
18123: #
18124: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18125: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18126: ($domdefaults{'auth_def'} eq 'localauth'))) {
18127: $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.').' '.
18128: &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.');
18129: }
18130: }
18131: my @fields = ('lastname','firstname','middlename','generation',
18132: 'permanentemail','id');
1.240 raeburn 18133: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18134: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18135: #
18136: # Where usernames may created for institutional log-in and/or institutional single sign on:
18137: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18138: # may self-create accounts
18139: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18140: # which the user may supply, if institutional data is unavailable.
18141: #
18142: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18143: if (@types) {
1.305 raeburn 18144: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18145: push(@contexts,'statustocreate');
1.303 raeburn 18146: foreach my $type (@types) {
1.224 raeburn 18147: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18148: foreach my $field (@fields) {
18149: if (grep(/^\Q$field\E$/,@modifiable)) {
18150: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18151: } else {
18152: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18153: }
18154: }
18155: }
18156: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18157: foreach my $type (@types) {
1.224 raeburn 18158: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18159: foreach my $field (@fields) {
18160: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18161: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18162: push(@{$changes{'selfcreate'}},$type);
18163: last;
18164: }
18165: }
18166: }
18167: }
18168: } else {
1.303 raeburn 18169: foreach my $type (@types) {
1.224 raeburn 18170: push(@{$changes{'selfcreate'}},$type);
18171: }
18172: }
18173: }
1.240 raeburn 18174: foreach my $field (@shibfields) {
18175: if ($env{'form.shibenv_'.$field} ne '') {
18176: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18177: }
18178: }
18179: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18180: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18181: foreach my $field (@shibfields) {
18182: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18183: push(@{$changes{'cancreate'}},'shibenv');
18184: }
18185: }
18186: } else {
18187: foreach my $field (@shibfields) {
18188: if ($env{'form.shibenv_'.$field}) {
18189: push(@{$changes{'cancreate'}},'shibenv');
18190: last;
18191: }
18192: }
18193: }
18194: }
1.224 raeburn 18195: }
18196: foreach my $item (@contexts) {
18197: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18198: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18199: if (ref($cancreate{$item}) eq 'ARRAY') {
18200: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18201: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18202: push(@{$changes{'cancreate'}},$item);
18203: }
18204: }
18205: }
18206: }
18207: if (ref($cancreate{$item}) eq 'ARRAY') {
18208: foreach my $type (@{$cancreate{$item}}) {
18209: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
18210: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18211: push(@{$changes{'cancreate'}},$item);
18212: }
18213: }
18214: }
18215: }
18216: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
18217: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 18218: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
18219: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18220: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
18221: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18222: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18223: push(@{$changes{'cancreate'}},$item);
18224: }
18225: }
18226: }
1.305 raeburn 18227: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18228: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18229: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18230: push(@{$changes{'cancreate'}},$item);
18231: }
1.224 raeburn 18232: }
18233: }
18234: }
1.305 raeburn 18235: foreach my $type (keys(%{$cancreate{$item}})) {
18236: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18237: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18238: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18239: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18240: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18241: push(@{$changes{'cancreate'}},$item);
18242: }
18243: }
18244: } else {
18245: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18246: push(@{$changes{'cancreate'}},$item);
18247: }
18248: }
18249: }
1.305 raeburn 18250: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18251: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18252: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18253: push(@{$changes{'cancreate'}},$item);
18254: }
1.224 raeburn 18255: }
18256: }
18257: }
18258: }
18259: } elsif ($curr_usercreation{'cancreate'}{$item}) {
18260: if (ref($cancreate{$item}) eq 'ARRAY') {
18261: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
18262: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18263: push(@{$changes{'cancreate'}},$item);
18264: }
18265: }
1.305 raeburn 18266: }
18267: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18268: if (ref($cancreate{$item}) eq 'HASH') {
18269: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18270: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 18271: }
18272: }
18273: } elsif ($item eq 'emailusername') {
1.228 raeburn 18274: if (ref($cancreate{$item}) eq 'HASH') {
18275: foreach my $type (keys(%{$cancreate{$item}})) {
18276: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18277: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18278: if ($cancreate{$item}{$type}{$field}) {
18279: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18280: push(@{$changes{'cancreate'}},$item);
18281: }
18282: last;
18283: }
18284: }
18285: }
18286: }
1.224 raeburn 18287: }
18288: }
18289: }
18290: #
18291: # Populate %save_usercreate hash with updates to self-creation configuration.
18292: #
18293: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
18294: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 18295: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 18296: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
18297: if (ref($cancreate{'notify'}) eq 'HASH') {
18298: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
18299: }
1.236 raeburn 18300: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
18301: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
18302: }
1.303 raeburn 18303: if (ref($cancreate{'emailverified'}) eq 'HASH') {
18304: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
18305: }
1.305 raeburn 18306: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
18307: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
18308: }
1.303 raeburn 18309: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
18310: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
18311: }
1.224 raeburn 18312: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18313: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
18314: }
1.240 raeburn 18315: if (ref($cancreate{'shibenv'}) eq 'HASH') {
18316: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
18317: }
1.224 raeburn 18318: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 18319: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 18320:
18321: my %userconfig_hash = (
18322: usercreation => \%save_usercreate,
18323: usermodification => \%save_usermodify,
1.305 raeburn 18324: inststatus => \%save_inststatus,
1.224 raeburn 18325: );
1.305 raeburn 18326:
1.224 raeburn 18327: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
18328: $dom);
18329: #
1.305 raeburn 18330: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 18331: #
1.27 raeburn 18332: if ($putresult eq 'ok') {
18333: if (keys(%changes) > 0) {
18334: $resulttext = &mt('Changes made:').'<ul>';
18335: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18336: my %lt = &selfcreation_types();
1.34 raeburn 18337: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18338: my $chgtext = '';
1.45 raeburn 18339: if ($type eq 'selfcreate') {
1.50 raeburn 18340: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18341: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18342: } else {
1.224 raeburn 18343: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18344: '<ul>';
1.50 raeburn 18345: foreach my $case (@{$cancreate{$type}}) {
18346: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18347: }
18348: $chgtext .= '</ul>';
1.100 raeburn 18349: if (ref($cancreate{$type}) eq 'ARRAY') {
18350: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18351: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18352: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18353: $chgtext .= '<span class="LC_warning">'.
18354: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18355: '</span><br />';
18356: }
18357: }
18358: }
18359: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18360: if (!@statuses) {
18361: $chgtext .= '<span class="LC_warning">'.
18362: &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.").
18363: '</span><br />';
1.303 raeburn 18364:
1.100 raeburn 18365: }
18366: }
18367: }
1.43 raeburn 18368: }
1.240 raeburn 18369: } elsif ($type eq 'shibenv') {
18370: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18371: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18372: } else {
18373: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18374: '<ul>';
18375: foreach my $field (@shibfields) {
18376: next if ($cancreate{$type}{$field} eq '');
18377: if ($field eq 'inststatus') {
18378: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18379: } else {
18380: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18381: }
18382: }
18383: $chgtext .= '</ul>';
1.303 raeburn 18384: }
1.93 raeburn 18385: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18386: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18387: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18388: if (@{$cancreate{'selfcreate'}} > 0) {
18389: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18390: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18391: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18392: $chgtext .= '<br />'.
18393: '<span class="LC_warning">'.
18394: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18395: '</span>';
18396: }
1.303 raeburn 18397: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18398: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18399: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18400: } else {
18401: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18402: }
18403: $chgtext .= '<ul>';
18404: foreach my $case (@{$cancreate{$type}}) {
18405: if ($case eq 'default') {
18406: $chgtext .= '<li>'.$othertitle.'</li>';
18407: } else {
1.303 raeburn 18408: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18409: }
18410: }
1.100 raeburn 18411: $chgtext .= '</ul>';
18412: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18413: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18414: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18415: '</span>';
1.100 raeburn 18416: }
18417: }
18418: } else {
18419: if (@{$cancreate{$type}} == 0) {
18420: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18421: } else {
18422: $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 18423: }
18424: }
1.303 raeburn 18425: $chgtext .= '<br />';
1.93 raeburn 18426: }
1.236 raeburn 18427: } elsif ($type eq 'selfcreateprocessing') {
18428: my %choices = &Apache::lonlocal::texthash (
18429: automatic => 'Automatic approval',
18430: approval => 'Queued for approval',
18431: );
1.305 raeburn 18432: if (@types) {
18433: if (@statuses) {
1.303 raeburn 18434: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18435: '<ul>';
1.305 raeburn 18436: foreach my $status (@statuses) {
18437: if ($status eq 'default') {
18438: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18439: } else {
1.305 raeburn 18440: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18441: }
18442: }
18443: $chgtext .= '</ul>';
18444: }
18445: } else {
18446: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18447: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18448: }
18449: } elsif ($type eq 'emailverified') {
18450: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18451: all => 'Same as e-mail',
18452: first => 'Omit @domain',
18453: free => 'Free to choose',
1.303 raeburn 18454: );
1.305 raeburn 18455: if (@types) {
18456: if (@statuses) {
1.303 raeburn 18457: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18458: '<ul>';
1.305 raeburn 18459: foreach my $status (@statuses) {
1.362 raeburn 18460: if ($status eq 'default') {
1.305 raeburn 18461: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18462: } else {
1.305 raeburn 18463: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18464: }
18465: }
18466: $chgtext .= '</ul>';
18467: }
18468: } else {
1.305 raeburn 18469: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18470: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18471: }
1.305 raeburn 18472: } elsif ($type eq 'emailoptions') {
18473: my %options = &Apache::lonlocal::texthash (
18474: any => 'Any e-mail',
18475: inst => 'Institutional only',
18476: noninst => 'Non-institutional only',
18477: custom => 'Custom restrictions',
18478: );
18479: if (@types) {
18480: if (@statuses) {
18481: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18482: '<ul>';
18483: foreach my $status (@statuses) {
18484: if ($type eq 'default') {
18485: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18486: } else {
18487: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18488: }
18489: }
1.305 raeburn 18490: $chgtext .= '</ul>';
18491: }
18492: } else {
18493: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18494: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18495: } else {
18496: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18497: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18498: }
1.305 raeburn 18499: }
18500: } elsif ($type eq 'emaildomain') {
18501: my $output;
18502: if (@statuses) {
18503: foreach my $type (@statuses) {
18504: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18505: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18506: if ($type eq 'default') {
18507: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18508: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18509: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18510: } else {
18511: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18512: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18513: }
1.303 raeburn 18514: } else {
1.305 raeburn 18515: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18516: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18517: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18518: } else {
18519: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 ! raeburn 18520: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 18521: }
1.303 raeburn 18522: }
1.305 raeburn 18523: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18524: if ($type eq 'default') {
18525: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18526: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18527: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18528: } else {
18529: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18530: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18531: }
1.303 raeburn 18532: } else {
1.305 raeburn 18533: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18534: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18535: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18536: } else {
18537: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 ! raeburn 18538: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 18539: }
1.303 raeburn 18540: }
18541: }
18542: }
18543: }
1.305 raeburn 18544: }
18545: if ($output ne '') {
18546: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18547: '<ul>'.$output.'</ul>';
1.236 raeburn 18548: }
1.165 raeburn 18549: } elsif ($type eq 'captcha') {
1.224 raeburn 18550: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18551: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18552: } else {
18553: my %captchas = &captcha_phrases();
1.224 raeburn 18554: if ($captchas{$savecaptcha{$type}}) {
18555: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18556: } else {
1.210 raeburn 18557: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18558: }
18559: }
18560: } elsif ($type eq 'recaptchakeys') {
18561: my ($privkey,$pubkey);
1.224 raeburn 18562: if (ref($savecaptcha{$type}) eq 'HASH') {
18563: $pubkey = $savecaptcha{$type}{'public'};
18564: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18565: }
18566: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18567: if (!$pubkey) {
18568: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18569: } else {
18570: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18571: }
18572: if (!$privkey) {
18573: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18574: } else {
18575: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18576: }
18577: $chgtext .= '</ul>';
1.269 raeburn 18578: } elsif ($type eq 'recaptchaversion') {
18579: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18580: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18581: }
1.224 raeburn 18582: } elsif ($type eq 'emailusername') {
18583: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18584: if (@statuses) {
18585: foreach my $type (@statuses) {
1.228 raeburn 18586: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18587: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18588: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18589: '<ul>';
18590: foreach my $field (@{$infofields}) {
18591: if ($cancreate{'emailusername'}{$type}{$field}) {
18592: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18593: }
18594: }
1.245 raeburn 18595: $chgtext .= '</ul>';
18596: } else {
1.303 raeburn 18597: $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 18598: }
18599: } else {
1.303 raeburn 18600: $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 18601: }
18602: }
18603: }
18604: }
18605: } elsif ($type eq 'notify') {
1.303 raeburn 18606: my $numapprove = 0;
1.224 raeburn 18607: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18608: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18609: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18610: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18611: $numapprove ++;
1.224 raeburn 18612: }
18613: }
1.43 raeburn 18614: }
1.303 raeburn 18615: unless ($numapprove) {
18616: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18617: }
1.34 raeburn 18618: }
1.224 raeburn 18619: if ($chgtext) {
18620: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18621: }
18622: }
18623: }
1.305 raeburn 18624: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18625: my ($emailrules,$emailruleorder) =
18626: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18627: foreach my $type (@{$changes{'email_rule'}}) {
18628: if (ref($email_rule{$type}) eq 'ARRAY') {
18629: my $chgtext = '<ul>';
18630: foreach my $rule (@{$email_rule{$type}}) {
18631: if (ref($emailrules->{$rule}) eq 'HASH') {
18632: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18633: }
18634: }
18635: $chgtext .= '</ul>';
1.310 raeburn 18636: my $typename;
1.305 raeburn 18637: if (@types) {
18638: if ($type eq 'default') {
18639: $typename = $othertitle;
18640: } else {
18641: $typename = $usertypes{$type};
18642: }
18643: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18644: }
18645: if (@{$email_rule{$type}} > 0) {
18646: $resulttext .= '<li>'.
18647: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18648: $usertypes{$type}).
18649: $chgtext.
18650: '</li>';
18651: } else {
18652: $resulttext .= '<li>'.
1.310 raeburn 18653: &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 18654: '</li>'.
1.310 raeburn 18655: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18656: }
1.43 raeburn 18657: }
18658: }
1.305 raeburn 18659: }
18660: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18661: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18662: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18663: my $chgtext = '<ul>';
18664: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18665: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18666: }
18667: $chgtext .= '</ul>';
18668: $resulttext .= '<li>'.
18669: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18670: $chgtext.
18671: '</li>';
18672: } else {
18673: $resulttext .= '<li>'.
18674: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18675: '</li>';
18676: }
1.43 raeburn 18677: }
18678: }
1.224 raeburn 18679: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18680: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18681: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18682: foreach my $type (@{$changes{'selfcreate'}}) {
18683: my $typename = $type;
1.303 raeburn 18684: if (keys(%usertypes) > 0) {
18685: if ($usertypes{$type} ne '') {
18686: $typename = $usertypes{$type};
1.224 raeburn 18687: }
18688: }
18689: my @modifiable;
18690: $resulttext .= '<li>'.
18691: &mt('Self-creation of account by users with status: [_1]',
18692: '<span class="LC_cusr_emph">'.$typename.'</span>').
18693: ' - '.&mt('modifiable fields (if institutional data blank): ');
18694: foreach my $field (@fields) {
18695: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18696: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18697: }
18698: }
1.224 raeburn 18699: if (@modifiable > 0) {
18700: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18701: } else {
1.224 raeburn 18702: $resulttext .= &mt('none');
1.43 raeburn 18703: }
1.224 raeburn 18704: $resulttext .= '</li>';
1.28 raeburn 18705: }
1.224 raeburn 18706: $resulttext .= '</ul></li>';
1.28 raeburn 18707: }
1.27 raeburn 18708: $resulttext .= '</ul>';
1.305 raeburn 18709: my $cachetime = 24*60*60;
18710: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18711: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18712: if (ref($lastactref) eq 'HASH') {
18713: $lastactref->{'domdefaults'} = 1;
18714: }
1.27 raeburn 18715: } else {
1.224 raeburn 18716: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18717: }
18718: } else {
18719: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18720: &mt('An error occurred: [_1]',$putresult).'</span>';
18721: }
1.43 raeburn 18722: if ($warningmsg ne '') {
18723: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18724: }
1.23 raeburn 18725: return $resulttext;
18726: }
18727:
1.165 raeburn 18728: sub process_captcha {
1.369 raeburn 18729: my ($container,$changes,$newsettings,$currsettings) = @_;
18730: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18731: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18732: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18733: $newsettings->{'captcha'} = 'original';
18734: }
1.369 raeburn 18735: my %current;
18736: if (ref($currsettings) eq 'HASH') {
18737: %current = %{$currsettings};
18738: }
18739: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18740: if ($container eq 'cancreate') {
1.169 raeburn 18741: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18742: push(@{$changes->{'cancreate'}},'captcha');
18743: } elsif (!defined($changes->{'cancreate'})) {
18744: $changes->{'cancreate'} = ['captcha'];
18745: }
1.368 raeburn 18746: } elsif ($container eq 'passwords') {
18747: $changes->{'reset'} = 1;
1.169 raeburn 18748: } else {
18749: $changes->{'captcha'} = 1;
1.165 raeburn 18750: }
18751: }
1.269 raeburn 18752: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18753: if ($newsettings->{'captcha'} eq 'recaptcha') {
18754: $newpub = $env{'form.'.$container.'_recaptchapub'};
18755: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18756: $newpub =~ s/[^\w\-]//g;
18757: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18758: $newsettings->{'recaptchakeys'} = {
18759: public => $newpub,
18760: private => $newpriv,
18761: };
1.269 raeburn 18762: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18763: $newversion =~ s/\D//g;
18764: if ($newversion ne '2') {
18765: $newversion = 1;
18766: }
18767: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18768: }
1.369 raeburn 18769: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18770: $currpub = $current{'recaptchakeys'}{'public'};
18771: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18772: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18773: $newsettings->{'recaptchakeys'} = {
18774: public => '',
18775: private => '',
18776: }
18777: }
1.165 raeburn 18778: }
1.369 raeburn 18779: if ($current{'captcha'} eq 'recaptcha') {
18780: $currversion = $current{'recaptchaversion'};
1.269 raeburn 18781: if ($currversion ne '2') {
18782: $currversion = 1;
18783: }
18784: }
18785: if ($currversion ne $newversion) {
18786: if ($container eq 'cancreate') {
18787: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18788: push(@{$changes->{'cancreate'}},'recaptchaversion');
18789: } elsif (!defined($changes->{'cancreate'})) {
18790: $changes->{'cancreate'} = ['recaptchaversion'];
18791: }
1.368 raeburn 18792: } elsif ($container eq 'passwords') {
18793: $changes->{'reset'} = 1;
1.269 raeburn 18794: } else {
18795: $changes->{'recaptchaversion'} = 1;
18796: }
18797: }
1.165 raeburn 18798: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 18799: if ($container eq 'cancreate') {
18800: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18801: push(@{$changes->{'cancreate'}},'recaptchakeys');
18802: } elsif (!defined($changes->{'cancreate'})) {
18803: $changes->{'cancreate'} = ['recaptchakeys'];
18804: }
1.368 raeburn 18805: } elsif ($container eq 'passwords') {
18806: $changes->{'reset'} = 1;
1.169 raeburn 18807: } else {
1.210 raeburn 18808: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 18809: }
18810: }
18811: return;
18812: }
18813:
1.33 raeburn 18814: sub modify_usermodification {
18815: my ($dom,%domconfig) = @_;
1.224 raeburn 18816: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 18817: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18818: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 18819: if ($key eq 'selfcreate') {
18820: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
18821: } else {
18822: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
18823: }
1.33 raeburn 18824: }
18825: }
1.224 raeburn 18826: my @contexts = ('author','course');
1.33 raeburn 18827: my %context_title = (
18828: author => 'In author context',
18829: course => 'In course context',
18830: );
18831: my @fields = ('lastname','firstname','middlename','generation',
18832: 'permanentemail','id');
18833: my %roles = (
18834: author => ['ca','aa'],
18835: course => ['st','ep','ta','in','cr'],
18836: );
18837: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18838: foreach my $context (@contexts) {
18839: foreach my $role (@{$roles{$context}}) {
18840: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
18841: foreach my $item (@fields) {
18842: if (grep(/^\Q$item\E$/,@modifiable)) {
18843: $modifyhash{$context}{$role}{$item} = 1;
18844: } else {
18845: $modifyhash{$context}{$role}{$item} = 0;
18846: }
18847: }
18848: }
18849: if (ref($curr_usermodification{$context}) eq 'HASH') {
18850: foreach my $role (@{$roles{$context}}) {
18851: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
18852: foreach my $field (@fields) {
18853: if ($modifyhash{$context}{$role}{$field} ne
18854: $curr_usermodification{$context}{$role}{$field}) {
18855: push(@{$changes{$context}},$role);
18856: last;
18857: }
18858: }
18859: }
18860: }
18861: } else {
18862: foreach my $context (@contexts) {
18863: foreach my $role (@{$roles{$context}}) {
18864: push(@{$changes{$context}},$role);
18865: }
18866: }
18867: }
18868: }
18869: my %usermodification_hash = (
18870: usermodification => \%modifyhash,
18871: );
18872: my $putresult = &Apache::lonnet::put_dom('configuration',
18873: \%usermodification_hash,$dom);
18874: if ($putresult eq 'ok') {
18875: if (keys(%changes) > 0) {
18876: $resulttext = &mt('Changes made: ').'<ul>';
18877: foreach my $context (@contexts) {
18878: if (ref($changes{$context}) eq 'ARRAY') {
18879: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
18880: if (ref($changes{$context}) eq 'ARRAY') {
18881: foreach my $role (@{$changes{$context}}) {
18882: my $rolename;
1.224 raeburn 18883: if ($role eq 'cr') {
18884: $rolename = &mt('Custom');
1.33 raeburn 18885: } else {
1.224 raeburn 18886: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 18887: }
18888: my @modifiable;
1.224 raeburn 18889: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 18890: foreach my $field (@fields) {
18891: if ($modifyhash{$context}{$role}{$field}) {
18892: push(@modifiable,$fieldtitles{$field});
18893: }
18894: }
18895: if (@modifiable > 0) {
18896: $resulttext .= join(', ',@modifiable);
18897: } else {
18898: $resulttext .= &mt('none');
18899: }
18900: $resulttext .= '</li>';
18901: }
18902: $resulttext .= '</ul></li>';
18903: }
18904: }
18905: }
18906: $resulttext .= '</ul>';
18907: } else {
18908: $resulttext = &mt('No changes made to user modification settings');
18909: }
18910: } else {
18911: $resulttext = '<span class="LC_error">'.
18912: &mt('An error occurred: [_1]',$putresult).'</span>';
18913: }
18914: return $resulttext;
18915: }
18916:
1.43 raeburn 18917: sub modify_defaults {
1.212 raeburn 18918: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 18919: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 18920: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 18921: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 18922: 'portal_def');
1.325 raeburn 18923: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 18924: foreach my $item (@items) {
18925: $newvalues{$item} = $env{'form.'.$item};
18926: if ($item eq 'auth_def') {
18927: if ($newvalues{$item} ne '') {
18928: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
18929: push(@errors,$item);
18930: }
18931: }
18932: } elsif ($item eq 'lang_def') {
18933: if ($newvalues{$item} ne '') {
18934: if ($newvalues{$item} =~ /^(\w+)/) {
18935: my $langcode = $1;
1.103 raeburn 18936: if ($langcode ne 'x_chef') {
18937: if (code2language($langcode) eq '') {
18938: push(@errors,$item);
18939: }
1.43 raeburn 18940: }
18941: } else {
18942: push(@errors,$item);
18943: }
18944: }
1.54 raeburn 18945: } elsif ($item eq 'timezone_def') {
18946: if ($newvalues{$item} ne '') {
1.62 raeburn 18947: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 18948: push(@errors,$item);
18949: }
18950: }
1.68 raeburn 18951: } elsif ($item eq 'datelocale_def') {
18952: if ($newvalues{$item} ne '') {
18953: my @datelocale_ids = DateTime::Locale->ids();
18954: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
18955: push(@errors,$item);
18956: }
18957: }
1.141 raeburn 18958: } elsif ($item eq 'portal_def') {
18959: if ($newvalues{$item} ne '') {
1.414 raeburn 18960: 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])\/?$/) {
18961: foreach my $field ('email','web') {
18962: if ($env{'form.'.$item.'_'.$field}) {
18963: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
18964: }
18965: }
18966: } else {
1.141 raeburn 18967: push(@errors,$item);
18968: }
18969: }
1.43 raeburn 18970: }
18971: if (grep(/^\Q$item\E$/,@errors)) {
18972: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 18973: if ($item eq 'portal_def') {
18974: if ($domdefaults{$item}) {
18975: foreach my $field ('email','web') {
18976: if (exists($domdefaults{$item.'_'.$field})) {
18977: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
18978: }
18979: }
18980: }
18981: }
1.43 raeburn 18982: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
18983: $changes{$item} = 1;
18984: }
1.414 raeburn 18985: if ($item eq 'portal_def') {
18986: unless (grep(/^\Q$item\E$/,@errors)) {
18987: if ($newvalues{$item} eq '') {
18988: foreach my $field ('email','web') {
18989: if (exists($domdefaults{$item.'_'.$field})) {
18990: delete($domdefaults{$item.'_'.$field});
18991: }
18992: }
18993: } else {
18994: unless ($changes{$item}) {
18995: foreach my $field ('email','web') {
18996: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
18997: $changes{$item} = 1;
18998: last;
18999: }
19000: }
19001: }
19002: foreach my $field ('email','web') {
19003: if ($newvalues{$item.'_'.$field}) {
19004: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19005: } elsif (exists($domdefaults{$item.'_'.$field})) {
19006: delete($domdefaults{$item.'_'.$field});
19007: }
19008: }
19009: }
19010: }
19011: }
1.72 raeburn 19012: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19013: }
1.354 raeburn 19014: my %staticdefaults = (
19015: 'intauth_cost' => 10,
19016: 'intauth_check' => 0,
19017: 'intauth_switch' => 0,
19018: );
19019: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19020: if (exists($domdefaults{$item})) {
19021: $newvalues{$item} = $domdefaults{$item};
19022: } else {
19023: $newvalues{$item} = $staticdefaults{$item};
19024: }
19025: }
1.409 raeburn 19026: my ($unamemaprules,$ruleorder);
19027: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19028: if (@possunamemaprules) {
19029: ($unamemaprules,$ruleorder) =
19030: &Apache::lonnet::inst_userrules($dom,'unamemap');
19031: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19032: if (@{$ruleorder} > 0) {
19033: my %possrules;
19034: map { $possrules{$_} = 1; } @possunamemaprules;
19035: foreach my $rule (@{$ruleorder}) {
19036: if ($possrules{$rule}) {
19037: push(@{$newvalues{'unamemap_rule'}},$rule);
19038: }
19039: }
19040: }
19041: }
19042: }
19043: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19044: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19045: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19046: $newvalues{'unamemap_rule'});
19047: if (@rulediffs) {
19048: $changes{'unamemap_rule'} = 1;
19049: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19050: }
19051: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19052: $changes{'unamemap_rule'} = 1;
19053: delete($domdefaults{'unamemap_rule'});
19054: }
19055: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19056: if (@{$newvalues{'unamemap_rule'}} > 0) {
19057: $changes{'unamemap_rule'} = 1;
19058: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19059: }
19060: }
1.43 raeburn 19061: my %defaults_hash = (
1.72 raeburn 19062: defaults => \%newvalues,
19063: );
1.43 raeburn 19064: my $title = &defaults_titles();
1.236 raeburn 19065:
19066: my $currinststatus;
19067: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19068: $currinststatus = $domconfig{'inststatus'};
19069: } else {
19070: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19071: $currinststatus = {
19072: inststatustypes => $usertypes,
19073: inststatusorder => $types,
19074: inststatusguest => [],
19075: };
19076: }
19077: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19078: my @allpos;
19079: my %alltypes;
1.305 raeburn 19080: my @inststatusguest;
19081: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19082: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19083: unless (grep(/^\Q$type\E$/,@todelete)) {
19084: push(@inststatusguest,$type);
19085: }
19086: }
19087: }
19088: my ($currtitles,$currorder);
1.236 raeburn 19089: if (ref($currinststatus) eq 'HASH') {
19090: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19091: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19092: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19093: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19094: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19095: }
19096: }
19097: unless (grep(/^\Q$type\E$/,@todelete)) {
19098: my $position = $env{'form.inststatus_pos_'.$type};
19099: $position =~ s/\D+//g;
19100: $allpos[$position] = $type;
19101: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19102: $alltypes{$type} =~ s/`//g;
19103: }
19104: }
19105: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19106: $currtitles =~ s/,$//;
19107: }
19108: }
19109: if ($env{'form.addinststatus'}) {
19110: my $newtype = $env{'form.addinststatus'};
19111: $newtype =~ s/\W//g;
19112: unless (exists($alltypes{$newtype})) {
19113: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19114: $alltypes{$newtype} =~ s/`//g;
19115: my $position = $env{'form.addinststatus_pos'};
19116: $position =~ s/\D+//g;
19117: if ($position ne '') {
19118: $allpos[$position] = $newtype;
19119: }
19120: }
19121: }
1.305 raeburn 19122: my @orderedstatus;
1.236 raeburn 19123: foreach my $type (@allpos) {
19124: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19125: push(@orderedstatus,$type);
19126: }
19127: }
19128: foreach my $type (keys(%alltypes)) {
19129: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19130: delete($alltypes{$type});
19131: }
19132: }
19133: $defaults_hash{'inststatus'} = {
19134: inststatustypes => \%alltypes,
19135: inststatusorder => \@orderedstatus,
1.305 raeburn 19136: inststatusguest => \@inststatusguest,
1.236 raeburn 19137: };
19138: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19139: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19140: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19141: }
19142: }
19143: if ($currorder ne join(',',@orderedstatus)) {
19144: $changes{'inststatus'}{'inststatusorder'} = 1;
19145: }
19146: my $newtitles;
19147: foreach my $item (@orderedstatus) {
19148: $newtitles .= $alltypes{$item}.',';
19149: }
19150: $newtitles =~ s/,$//;
19151: if ($currtitles ne $newtitles) {
19152: $changes{'inststatus'}{'inststatustypes'} = 1;
19153: }
1.43 raeburn 19154: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19155: $dom);
19156: if ($putresult eq 'ok') {
19157: if (keys(%changes) > 0) {
19158: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19159: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19160: 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";
19161: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19162: if ($item eq 'inststatus') {
19163: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19164: if (@orderedstatus) {
1.236 raeburn 19165: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19166: foreach my $type (@orderedstatus) {
19167: $resulttext .= $alltypes{$type}.', ';
19168: }
19169: $resulttext =~ s/, $//;
19170: $resulttext .= '</li>';
1.305 raeburn 19171: } else {
19172: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19173: }
19174: }
1.409 raeburn 19175: } elsif ($item eq 'unamemap_rule') {
19176: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19177: my @rulenames;
19178: if (ref($unamemaprules) eq 'HASH') {
19179: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
19180: if (ref($unamemaprules->{$rule}) eq 'HASH') {
19181: push(@rulenames,$unamemaprules->{$rule}->{'name'});
19182: }
19183: }
19184: }
19185: if (@rulenames) {
19186: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
19187: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
19188: '</li>';
19189: } else {
19190: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
19191: }
19192: } else {
19193: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
19194: }
1.236 raeburn 19195: } else {
19196: my $value = $env{'form.'.$item};
19197: if ($value eq '') {
19198: $value = &mt('none');
19199: } elsif ($item eq 'auth_def') {
19200: my %authnames = &authtype_names();
19201: my %shortauth = (
19202: internal => 'int',
19203: krb4 => 'krb4',
19204: krb5 => 'krb5',
19205: localauth => 'loc',
1.325 raeburn 19206: lti => 'lti',
1.236 raeburn 19207: );
19208: $value = $authnames{$shortauth{$value}};
19209: }
19210: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 19211: $mailmsgtext .= "$title->{$item} set to $value\n";
19212: if ($item eq 'portal_def') {
19213: if ($env{'form.'.$item} ne '') {
19214: foreach my $field ('email','web') {
19215: $value = $env{'form.'.$item.'_'.$field};
19216: if ($value) {
19217: $value = &mt('Yes');
19218: } else {
19219: $value = &mt('No');
19220: }
19221: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
19222: }
19223: }
19224: }
1.43 raeburn 19225: }
19226: }
19227: $resulttext .= '</ul>';
19228: $mailmsgtext .= "\n";
19229: my $cachetime = 24*60*60;
1.72 raeburn 19230: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19231: if (ref($lastactref) eq 'HASH') {
19232: $lastactref->{'domdefaults'} = 1;
19233: }
1.68 raeburn 19234: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 19235: my $notify = 1;
19236: if (ref($domconfig{'contacts'}) eq 'HASH') {
19237: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
19238: $notify = 0;
19239: }
19240: }
19241: if ($notify) {
19242: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
19243: "LON-CAPA Domain Settings Change - $dom",
19244: $mailmsgtext);
19245: }
1.54 raeburn 19246: }
1.43 raeburn 19247: } else {
1.54 raeburn 19248: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 19249: }
19250: } else {
19251: $resulttext = '<span class="LC_error">'.
19252: &mt('An error occurred: [_1]',$putresult).'</span>';
19253: }
19254: if (@errors > 0) {
19255: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
19256: foreach my $item (@errors) {
19257: $resulttext .= ' "'.$title->{$item}.'",';
19258: }
19259: $resulttext =~ s/,$//;
19260: }
19261: return $resulttext;
19262: }
19263:
1.46 raeburn 19264: sub modify_scantron {
1.205 raeburn 19265: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 19266: my ($resulttext,%confhash,%changes,$errors);
19267: my $custom = 'custom.tab';
19268: my $default = 'default.tab';
19269: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 19270: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 19271: &config_check($dom,$confname,$servadm);
19272: if ($env{'form.scantronformat.filename'} ne '') {
19273: my $error;
19274: if ($configuserok eq 'ok') {
19275: if ($switchserver) {
1.130 raeburn 19276: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 19277: } else {
19278: if ($author_ok eq 'ok') {
1.421 ! raeburn 19279: my $modified = [];
1.46 raeburn 19280: my ($result,$scantronurl) =
1.421 ! raeburn 19281: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
! 19282: $confname,'scantron','','',$custom,
! 19283: $modified);
1.46 raeburn 19284: if ($result eq 'ok') {
19285: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 19286: $changes{'scantronformat'} = 1;
1.421 ! raeburn 19287: &update_modify_urls($r,$modified);
1.46 raeburn 19288: } else {
19289: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
19290: }
19291: } else {
19292: $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);
19293: }
19294: }
19295: } else {
19296: $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);
19297: }
19298: if ($error) {
19299: &Apache::lonnet::logthis($error);
19300: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
19301: }
19302: }
1.48 raeburn 19303: if (ref($domconfig{'scantron'}) eq 'HASH') {
19304: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
19305: if ($env{'form.scantronformat_del'}) {
19306: $confhash{'scantron'}{'scantronformat'} = '';
19307: $changes{'scantronformat'} = 1;
1.347 raeburn 19308: } else {
19309: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 19310: }
19311: }
19312: }
1.347 raeburn 19313: my @options = ('hdr','pad','rem');
1.346 raeburn 19314: my @fields = &scantroncsv_fields();
19315: my %titles = &scantronconfig_titles();
1.347 raeburn 19316: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 19317: my ($newdat,$currdat,%newcol,%currcol);
19318: if (grep(/^dat$/,@formats)) {
19319: $confhash{'scantron'}{config}{dat} = 1;
19320: $newdat = 1;
19321: } else {
19322: $newdat = 0;
19323: }
19324: if (grep(/^csv$/,@formats)) {
19325: my %bynum;
19326: foreach my $field (@fields) {
19327: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
19328: my $posscol = $1;
19329: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 19330: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 19331: $bynum{$posscol} = $field;
19332: $newcol{$field} = $posscol;
19333: }
19334: }
19335: }
1.347 raeburn 19336: if (keys(%newcol)) {
19337: foreach my $option (@options) {
19338: if ($env{'form.scantroncsv_'.$option}) {
19339: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
19340: }
19341: }
19342: }
1.346 raeburn 19343: }
19344: $currdat = 1;
19345: if (ref($domconfig{'scantron'}) eq 'HASH') {
19346: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 19347: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 19348: $currdat = 0;
19349: }
19350: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19351: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19352: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
19353: }
1.346 raeburn 19354: }
19355: }
19356: }
19357: if ($currdat != $newdat) {
19358: $changes{'config'} = 1;
19359: } else {
19360: foreach my $field (@fields) {
19361: if ($currcol{$field} ne '') {
19362: if ($currcol{$field} ne $newcol{$field}) {
19363: $changes{'config'} = 1;
19364: last;
1.347 raeburn 19365: }
1.346 raeburn 19366: } elsif ($newcol{$field} ne '') {
19367: $changes{'config'} = 1;
19368: last;
19369: }
19370: }
19371: }
1.46 raeburn 19372: if (keys(%confhash) > 0) {
19373: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
19374: $dom);
19375: if ($putresult eq 'ok') {
19376: if (keys(%changes) > 0) {
1.48 raeburn 19377: if (ref($confhash{'scantron'}) eq 'HASH') {
19378: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 19379: if ($changes{'scantronformat'}) {
19380: if ($confhash{'scantron'}{'scantronformat'} eq '') {
19381: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
19382: } else {
19383: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
19384: }
19385: }
1.347 raeburn 19386: if ($changes{'config'}) {
1.346 raeburn 19387: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
19388: if ($confhash{'scantron'}{'config'}{'dat'}) {
19389: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
19390: }
19391: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19392: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19393: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
19394: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
19395: foreach my $field (@fields) {
19396: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
19397: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
19398: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
19399: }
19400: }
19401: $resulttext .= '</ul></li>';
19402: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
19403: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
19404: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
19405: foreach my $option (@options) {
19406: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
19407: $resulttext .= '<li>'.$titles{$option}.'</li>';
19408: }
19409: }
19410: $resulttext .= '</ul></li>';
19411: }
1.346 raeburn 19412: }
19413: }
19414: }
19415: }
19416: } else {
19417: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
19418: }
1.46 raeburn 19419: }
1.48 raeburn 19420: $resulttext .= '</ul>';
19421: } else {
1.130 raeburn 19422: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 19423: }
19424: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 19425: if (ref($lastactref) eq 'HASH') {
19426: $lastactref->{'domainconfig'} = 1;
19427: }
1.46 raeburn 19428: } else {
1.346 raeburn 19429: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 19430: }
19431: } else {
19432: $resulttext = '<span class="LC_error">'.
19433: &mt('An error occurred: [_1]',$putresult).'</span>';
19434: }
19435: } else {
1.130 raeburn 19436: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 19437: }
19438: if ($errors) {
1.353 raeburn 19439: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
19440: $errors.'</ul></p>';
1.46 raeburn 19441: }
19442: return $resulttext;
19443: }
19444:
1.48 raeburn 19445: sub modify_coursecategories {
1.239 raeburn 19446: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 19447: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19448: $cathash);
1.48 raeburn 19449: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19450: my @catitems = ('unauth','auth');
19451: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19452: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19453: $cathash = $domconfig{'coursecategories'}{'cats'};
19454: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19455: $changes{'togglecats'} = 1;
19456: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19457: }
19458: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19459: $changes{'categorize'} = 1;
19460: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19461: }
1.120 raeburn 19462: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19463: $changes{'togglecatscomm'} = 1;
19464: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19465: }
19466: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19467: $changes{'categorizecomm'} = 1;
19468: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19469:
19470: }
19471: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19472: $changes{'togglecatsplace'} = 1;
19473: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19474: }
19475: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19476: $changes{'categorizeplace'} = 1;
19477: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19478: }
1.238 raeburn 19479: foreach my $item (@catitems) {
19480: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19481: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19482: $changes{$item} = 1;
19483: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19484: }
19485: }
19486: }
1.57 raeburn 19487: } else {
19488: $changes{'togglecats'} = 1;
19489: $changes{'categorize'} = 1;
1.124 raeburn 19490: $changes{'togglecatscomm'} = 1;
19491: $changes{'categorizecomm'} = 1;
1.272 raeburn 19492: $changes{'togglecatsplace'} = 1;
19493: $changes{'categorizeplace'} = 1;
1.87 raeburn 19494: $domconfig{'coursecategories'} = {
19495: togglecats => $env{'form.togglecats'},
19496: categorize => $env{'form.categorize'},
1.124 raeburn 19497: togglecatscomm => $env{'form.togglecatscomm'},
19498: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19499: togglecatsplace => $env{'form.togglecatsplace'},
19500: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19501: };
1.238 raeburn 19502: foreach my $item (@catitems) {
19503: if ($env{'form.coursecat_'.$item} ne 'std') {
19504: $changes{$item} = 1;
19505: }
19506: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19507: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19508: }
19509: }
1.57 raeburn 19510: }
19511: if (ref($cathash) eq 'HASH') {
19512: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19513: push (@deletecategory,'instcode::0');
19514: }
1.120 raeburn 19515: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19516: push(@deletecategory,'communities::0');
19517: }
1.272 raeburn 19518: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19519: push(@deletecategory,'placement::0');
19520: }
1.48 raeburn 19521: }
1.57 raeburn 19522: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19523: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19524: if (@deletecategory > 0) {
19525: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19526: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19527: foreach my $item (@deletecategory) {
1.57 raeburn 19528: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19529: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19530: $deletions{$item} = 1;
1.57 raeburn 19531: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19532: }
19533: }
19534: }
1.57 raeburn 19535: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19536: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19537: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19538: $reorderings{$item} = 1;
1.57 raeburn 19539: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19540: }
19541: if ($env{'form.addcategory_name_'.$item} ne '') {
19542: my $newcat = $env{'form.addcategory_name_'.$item};
19543: my $newdepth = $depth+1;
19544: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19545: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19546: $adds{$newitem} = 1;
19547: }
19548: if ($env{'form.subcat_'.$item} ne '') {
19549: my $newcat = $env{'form.subcat_'.$item};
19550: my $newdepth = $depth+1;
19551: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19552: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19553: $adds{$newitem} = 1;
19554: }
19555: }
19556: }
19557: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19558: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19559: my $newitem = 'instcode::0';
1.57 raeburn 19560: if ($cathash->{$newitem} eq '') {
19561: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19562: $adds{$newitem} = 1;
19563: }
19564: } else {
19565: my $newitem = 'instcode::0';
1.57 raeburn 19566: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19567: $adds{$newitem} = 1;
19568: }
19569: }
1.120 raeburn 19570: if ($env{'form.communities'} eq '1') {
19571: if (ref($cathash) eq 'HASH') {
19572: my $newitem = 'communities::0';
19573: if ($cathash->{$newitem} eq '') {
19574: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19575: $adds{$newitem} = 1;
19576: }
19577: } else {
19578: my $newitem = 'communities::0';
19579: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19580: $adds{$newitem} = 1;
19581: }
19582: }
1.272 raeburn 19583: if ($env{'form.placement'} eq '1') {
19584: if (ref($cathash) eq 'HASH') {
19585: my $newitem = 'placement::0';
19586: if ($cathash->{$newitem} eq '') {
19587: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19588: $adds{$newitem} = 1;
19589: }
19590: } else {
19591: my $newitem = 'placement::0';
19592: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19593: $adds{$newitem} = 1;
19594: }
19595: }
1.48 raeburn 19596: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19597: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19598: ($env{'form.addcategory_name'} ne 'communities') &&
19599: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19600: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19601: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19602: $adds{$newitem} = 1;
19603: }
1.48 raeburn 19604: }
1.57 raeburn 19605: my $putresult;
1.48 raeburn 19606: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19607: if (keys(%deletions) > 0) {
19608: foreach my $key (keys(%deletions)) {
19609: if ($predelallitems{$key} ne '') {
19610: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19611: }
19612: }
19613: }
19614: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19615: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19616: if (ref($chkcats[0]) eq 'ARRAY') {
19617: my $depth = 0;
19618: my $chg = 0;
19619: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19620: my $name = $chkcats[0][$i];
19621: my $item;
19622: if ($name eq '') {
19623: $chg ++;
19624: } else {
19625: $item = &escape($name).'::0';
19626: if ($chg) {
1.57 raeburn 19627: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19628: }
19629: $depth ++;
1.57 raeburn 19630: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19631: $depth --;
19632: }
19633: }
19634: }
1.57 raeburn 19635: }
19636: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19637: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19638: if ($putresult eq 'ok') {
1.57 raeburn 19639: my %title = (
1.120 raeburn 19640: togglecats => 'Show/Hide a course in catalog',
19641: categorize => 'Assign a category to a course',
19642: togglecatscomm => 'Show/Hide a community in catalog',
19643: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19644: );
19645: my %level = (
1.120 raeburn 19646: dom => 'set in Domain ("Modify Course/Community")',
19647: crs => 'set in Course ("Course Configuration")',
19648: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19649: none => 'No catalog',
19650: std => 'Standard catalog',
19651: domonly => 'Domain-only catalog',
19652: codesrch => 'Code search form',
1.57 raeburn 19653: );
1.48 raeburn 19654: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19655: if ($changes{'togglecats'}) {
19656: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19657: }
19658: if ($changes{'categorize'}) {
19659: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19660: }
1.120 raeburn 19661: if ($changes{'togglecatscomm'}) {
19662: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19663: }
19664: if ($changes{'categorizecomm'}) {
19665: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19666: }
1.238 raeburn 19667: if ($changes{'unauth'}) {
19668: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19669: }
19670: if ($changes{'auth'}) {
19671: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19672: }
1.57 raeburn 19673: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19674: my $cathash;
19675: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19676: $cathash = $domconfig{'coursecategories'}{'cats'};
19677: } else {
19678: $cathash = {};
19679: }
19680: my (@cats,@trails,%allitems);
19681: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19682: if (keys(%deletions) > 0) {
19683: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19684: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19685: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19686: }
19687: $resulttext .= '</ul></li>';
19688: }
19689: if (keys(%reorderings) > 0) {
19690: my %sort_by_trail;
19691: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19692: foreach my $key (keys(%reorderings)) {
19693: if ($allitems{$key} ne '') {
19694: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19695: }
1.48 raeburn 19696: }
1.57 raeburn 19697: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19698: $resulttext .= '<li>'.$trails[$trail].'</li>';
19699: }
19700: $resulttext .= '</ul></li>';
1.48 raeburn 19701: }
1.57 raeburn 19702: if (keys(%adds) > 0) {
19703: my %sort_by_trail;
19704: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19705: foreach my $key (keys(%adds)) {
19706: if ($allitems{$key} ne '') {
19707: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19708: }
19709: }
19710: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19711: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19712: }
1.57 raeburn 19713: $resulttext .= '</ul></li>';
1.48 raeburn 19714: }
1.364 raeburn 19715: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19716: if (ref($lastactref) eq 'HASH') {
19717: $lastactref->{'cats'} = 1;
19718: }
1.48 raeburn 19719: }
19720: $resulttext .= '</ul>';
1.239 raeburn 19721: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19723: if ($changes{'auth'}) {
19724: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19725: }
19726: if ($changes{'unauth'}) {
19727: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19728: }
19729: my $cachetime = 24*60*60;
19730: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19731: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19732: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19733: }
19734: }
1.48 raeburn 19735: } else {
19736: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19737: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19738: }
19739: } else {
1.120 raeburn 19740: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19741: }
19742: return $resulttext;
19743: }
19744:
1.69 raeburn 19745: sub modify_serverstatuses {
19746: my ($dom,%domconfig) = @_;
19747: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19748: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19749: %currserverstatus = %{$domconfig{'serverstatuses'}};
19750: }
19751: my @pages = &serverstatus_pages();
19752: foreach my $type (@pages) {
19753: $newserverstatus{$type}{'namedusers'} = '';
19754: $newserverstatus{$type}{'machines'} = '';
19755: if (defined($env{'form.'.$type.'_namedusers'})) {
19756: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19757: my @okusers;
19758: foreach my $user (@users) {
19759: my ($uname,$udom) = split(/:/,$user);
19760: if (($udom =~ /^$match_domain$/) &&
19761: (&Apache::lonnet::domain($udom)) &&
19762: ($uname =~ /^$match_username$/)) {
19763: if (!grep(/^\Q$user\E/,@okusers)) {
19764: push(@okusers,$user);
19765: }
19766: }
19767: }
19768: if (@okusers > 0) {
19769: @okusers = sort(@okusers);
19770: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19771: }
19772: }
19773: if (defined($env{'form.'.$type.'_machines'})) {
19774: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19775: my @okmachines;
19776: foreach my $ip (@machines) {
19777: my @parts = split(/\./,$ip);
19778: next if (@parts < 4);
19779: my $badip = 0;
19780: for (my $i=0; $i<4; $i++) {
19781: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19782: $badip = 1;
19783: last;
19784: }
19785: }
19786: if (!$badip) {
19787: push(@okmachines,$ip);
19788: }
19789: }
19790: @okmachines = sort(@okmachines);
19791: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19792: }
19793: }
19794: my %serverstatushash = (
19795: serverstatuses => \%newserverstatus,
19796: );
19797: foreach my $type (@pages) {
1.83 raeburn 19798: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19799: my (@current,@new);
1.83 raeburn 19800: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19801: if ($currserverstatus{$type}{$setting} ne '') {
19802: @current = split(/,/,$currserverstatus{$type}{$setting});
19803: }
19804: }
19805: if ($newserverstatus{$type}{$setting} ne '') {
19806: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19807: }
19808: if (@current > 0) {
19809: if (@new > 0) {
19810: foreach my $item (@current) {
19811: if (!grep(/^\Q$item\E$/,@new)) {
19812: $changes{$type}{$setting} = 1;
1.82 raeburn 19813: last;
19814: }
19815: }
1.84 raeburn 19816: foreach my $item (@new) {
19817: if (!grep(/^\Q$item\E$/,@current)) {
19818: $changes{$type}{$setting} = 1;
19819: last;
1.82 raeburn 19820: }
19821: }
19822: } else {
1.83 raeburn 19823: $changes{$type}{$setting} = 1;
1.69 raeburn 19824: }
1.83 raeburn 19825: } elsif (@new > 0) {
19826: $changes{$type}{$setting} = 1;
1.69 raeburn 19827: }
19828: }
19829: }
19830: if (keys(%changes) > 0) {
1.81 raeburn 19831: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19832: my $putresult = &Apache::lonnet::put_dom('configuration',
19833: \%serverstatushash,$dom);
19834: if ($putresult eq 'ok') {
19835: $resulttext .= &mt('Changes made:').'<ul>';
19836: foreach my $type (@pages) {
1.84 raeburn 19837: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19838: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19839: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19840: if ($newserverstatus{$type}{'namedusers'} eq '') {
19841: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19842: } else {
19843: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19844: }
1.84 raeburn 19845: }
19846: if ($changes{$type}{'machines'}) {
1.69 raeburn 19847: if ($newserverstatus{$type}{'machines'} eq '') {
19848: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19849: } else {
19850: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19851: }
19852:
19853: }
19854: $resulttext .= '</ul></li>';
19855: }
19856: }
19857: $resulttext .= '</ul>';
19858: } else {
19859: $resulttext = '<span class="LC_error">'.
19860: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19861:
19862: }
19863: } else {
19864: $resulttext = &mt('No changes made to access to server status pages');
19865: }
19866: return $resulttext;
19867: }
19868:
1.118 jms 19869: sub modify_helpsettings {
1.285 raeburn 19870: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19871: my ($resulttext,$errors,%changes,%helphash);
19872: my %defaultchecked = ('submitbugs' => 'on');
19873: my @offon = ('off','on');
1.118 jms 19874: my @toggles = ('submitbugs');
1.285 raeburn 19875: my %current = ('submitbugs' => '',
19876: 'adhoc' => {},
19877: );
1.118 jms 19878: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19879: %current = %{$domconfig{'helpsettings'}};
19880: }
1.285 raeburn 19881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19882: foreach my $item (@toggles) {
19883: if ($defaultchecked{$item} eq 'on') {
19884: if ($current{$item} eq '') {
19885: if ($env{'form.'.$item} eq '0') {
19886: $changes{$item} = 1;
19887: }
19888: } elsif ($current{$item} ne $env{'form.'.$item}) {
19889: $changes{$item} = 1;
19890: }
19891: } elsif ($defaultchecked{$item} eq 'off') {
19892: if ($current{$item} eq '') {
19893: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 19894: $changes{$item} = 1;
19895: }
1.282 raeburn 19896: } elsif ($current{$item} ne $env{'form.'.$item}) {
19897: $changes{$item} = 1;
19898: }
19899: }
19900: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
19901: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
19902: }
19903: }
1.285 raeburn 19904: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 19905: my $confname = $dom.'-domainconfig';
19906: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 19907: my (@allpos,%newsettings,%changedprivs,$newrole);
19908: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 19909: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 19910: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 19911: my %lt = &Apache::lonlocal::texthash(
19912: s => 'system',
19913: d => 'domain',
19914: order => 'Display order',
19915: access => 'Role usage',
1.291 raeburn 19916: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 19917: dh => 'All with domain helpdesk role',
19918: da => 'All with domain helpdesk assistant role',
1.285 raeburn 19919: none => 'None',
19920: status => 'Determined based on institutional status',
19921: inc => 'Include all, but exclude specific personnel',
19922: exc => 'Exclude all, but include specific personnel',
19923: );
19924: for (my $num=0; $num<=$maxnum; $num++) {
19925: my ($prefix,$identifier,$rolename,%curr);
19926: if ($num == $maxnum) {
19927: next unless ($env{'form.newcusthelp'} == $maxnum);
19928: $identifier = 'custhelp'.$num;
19929: $prefix = 'helproles_'.$num;
19930: $rolename = $env{'form.custhelpname'.$num};
19931: $rolename=~s/[^A-Za-z0-9]//gs;
19932: next if ($rolename eq '');
19933: next if (exists($existing{'rolesdef_'.$rolename}));
19934: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19935: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19936: $newprivs{'c'},$confname,$dom);
19937: if ($result ne 'ok') {
19938: $errors .= '<li><span class="LC_error">'.
19939: &mt('An error occurred storing the new custom role: [_1]',
19940: $result).'</span></li>';
19941: next;
19942: } else {
19943: $changedprivs{$rolename} = \%newprivs;
19944: $newrole = $rolename;
19945: }
19946: } else {
19947: $prefix = 'helproles_'.$num;
19948: $rolename = $env{'form.'.$prefix};
19949: next if ($rolename eq '');
19950: next unless (exists($existing{'rolesdef_'.$rolename}));
19951: $identifier = 'custhelp'.$num;
19952: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19953: my %currprivs;
1.289 raeburn 19954: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 19955: split(/\_/,$existing{'rolesdef_'.$rolename});
19956: foreach my $level ('c','d','s') {
19957: if ($newprivs{$level} ne $currprivs{$level}) {
19958: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19959: $newprivs{'c'},$confname,$dom);
19960: if ($result ne 'ok') {
19961: $errors .= '<li><span class="LC_error">'.
19962: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
19963: $rolename,$result).'</span></li>';
19964: } else {
19965: $changedprivs{$rolename} = \%newprivs;
19966: }
19967: last;
19968: }
19969: }
19970: if (ref($current{'adhoc'}) eq 'HASH') {
19971: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19972: %curr = %{$current{'adhoc'}{$rolename}};
19973: }
19974: }
19975: }
19976: my $newpos = $env{'form.'.$prefix.'_pos'};
19977: $newpos =~ s/\D+//g;
19978: $allpos[$newpos] = $rolename;
19979: my $newdesc = $env{'form.'.$prefix.'_desc'};
19980: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
19981: if ($curr{'desc'}) {
19982: if ($curr{'desc'} ne $newdesc) {
19983: $changes{'customrole'}{$rolename}{'desc'} = 1;
19984: $newsettings{$rolename}{'desc'} = $newdesc;
19985: }
19986: } elsif ($newdesc ne '') {
19987: $changes{'customrole'}{$rolename}{'desc'} = 1;
19988: $newsettings{$rolename}{'desc'} = $newdesc;
19989: }
19990: my $access = $env{'form.'.$prefix.'_access'};
19991: if (grep(/^\Q$access\E$/,@accesstypes)) {
19992: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
19993: if ($access eq 'status') {
19994: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
19995: if (scalar(@statuses) == 0) {
1.289 raeburn 19996: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 19997: } else {
19998: my (@shownstatus,$numtypes);
19999: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20000: if (ref($types) eq 'ARRAY') {
20001: $numtypes = scalar(@{$types});
20002: foreach my $type (sort(@statuses)) {
20003: if ($type eq 'default') {
20004: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20005: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20006: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20007: push(@shownstatus,$usertypes->{$type});
20008: }
20009: }
20010: }
20011: if (grep(/^default$/,@statuses)) {
20012: push(@shownstatus,$othertitle);
20013: }
20014: if (scalar(@shownstatus) == 1+$numtypes) {
20015: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20016: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20017: } else {
20018: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20019: if (ref($curr{'status'}) eq 'ARRAY') {
20020: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20021: if (@diffs) {
20022: $changes{'customrole'}{$rolename}{$access} = 1;
20023: }
20024: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20025: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20026: }
1.166 raeburn 20027: }
20028: }
1.285 raeburn 20029: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20030: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20031: my @newspecstaff;
20032: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20033: foreach my $person (sort(@personnel)) {
20034: if ($domhelpdesk{$person}) {
20035: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20036: }
20037: }
20038: if (ref($curr{$access}) eq 'ARRAY') {
20039: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20040: if (@diffs) {
20041: $changes{'customrole'}{$rolename}{$access} = 1;
20042: }
20043: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20044: $changes{'customrole'}{$rolename}{$access} = 1;
20045: }
20046: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20047: my ($uname,$udom) = split(/:/,$person);
20048: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20049: }
20050: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20051: }
1.285 raeburn 20052: } else {
20053: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20054: }
20055: unless ($curr{'access'} eq $access) {
20056: $changes{'customrole'}{$rolename}{'access'} = 1;
20057: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20058: }
20059: }
1.285 raeburn 20060: if (@allpos > 0) {
20061: my $idx = 0;
20062: foreach my $rolename (@allpos) {
20063: if ($rolename ne '') {
20064: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20065: if (ref($current{'adhoc'}) eq 'HASH') {
20066: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20067: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20068: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20069: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20070: }
20071: }
1.282 raeburn 20072: }
1.285 raeburn 20073: $idx ++;
1.166 raeburn 20074: }
20075: }
1.118 jms 20076: }
1.123 jms 20077: my $putresult;
20078: if (keys(%changes) > 0) {
1.166 raeburn 20079: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20080: if ($putresult eq 'ok') {
1.285 raeburn 20081: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20082: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20083: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20084: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20085: }
20086: }
20087: my $cachetime = 24*60*60;
20088: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20089: if (ref($lastactref) eq 'HASH') {
20090: $lastactref->{'domdefaults'} = 1;
20091: }
20092: } else {
20093: $errors .= '<li><span class="LC_error">'.
20094: &mt('An error occurred storing the settings: [_1]',
20095: $putresult).'</span></li>';
20096: }
20097: }
20098: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20099: $resulttext = &mt('Changes made:').'<ul>';
20100: my (%shownprivs,@levelorder);
20101: @levelorder = ('c','d','s');
20102: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20103: foreach my $item (sort(keys(%changes))) {
20104: if ($item eq 'submitbugs') {
20105: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20106: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20107: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20108: } elsif ($item eq 'customrole') {
20109: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20110: my @keyorder = ('order','desc','access','status','exc','inc');
20111: my %keytext = &Apache::lonlocal::texthash(
20112: order => 'Order',
20113: desc => 'Role description',
20114: access => 'Role usage',
1.300 droeschl 20115: status => 'Allowed institutional types',
1.285 raeburn 20116: exc => 'Allowed personnel',
20117: inc => 'Disallowed personnel',
20118: );
1.282 raeburn 20119: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20120: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20121: if ($role eq $newrole) {
20122: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20123: $role).'<ul>';
20124: } else {
20125: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20126: $role).'<ul>';
20127: }
20128: foreach my $key (@keyorder) {
20129: if ($changes{'customrole'}{$role}{$key}) {
20130: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20131: $keytext{$key},$newsettings{$role}{$key}).
20132: '</li>';
20133: }
20134: }
20135: if (ref($changedprivs{$role}) eq 'HASH') {
20136: $shownprivs{$role} = 1;
20137: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20138: foreach my $level (@levelorder) {
20139: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20140: next if ($item eq '');
20141: my ($priv) = split(/\&/,$item,2);
20142: if (&Apache::lonnet::plaintext($priv)) {
20143: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20144: unless ($level eq 'c') {
20145: $resulttext .= ' ('.$lt{$level}.')';
20146: }
20147: $resulttext .= '</li>';
20148: }
20149: }
20150: }
20151: $resulttext .= '</ul>';
20152: }
20153: $resulttext .= '</ul></li>';
20154: }
20155: }
20156: }
20157: }
20158: }
20159: }
20160: if (keys(%changedprivs)) {
20161: foreach my $role (sort(keys(%changedprivs))) {
20162: unless ($shownprivs{$role}) {
20163: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20164: $role).'<ul>'.
20165: '<li>'.&mt('Privileges set to :').'<ul>';
20166: foreach my $level (@levelorder) {
20167: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20168: next if ($item eq '');
20169: my ($priv) = split(/\&/,$item,2);
20170: if (&Apache::lonnet::plaintext($priv)) {
20171: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20172: unless ($level eq 'c') {
20173: $resulttext .= ' ('.$lt{$level}.')';
20174: }
20175: $resulttext .= '</li>';
20176: }
1.282 raeburn 20177: }
20178: }
1.285 raeburn 20179: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20180: }
20181: }
20182: }
1.285 raeburn 20183: $resulttext .= '</ul>';
20184: } else {
20185: $resulttext = &mt('No changes made to help settings');
1.118 jms 20186: }
20187: if ($errors) {
1.168 raeburn 20188: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20189: $errors.'</ul>';
1.118 jms 20190: }
20191: return $resulttext;
20192: }
20193:
1.121 raeburn 20194: sub modify_coursedefaults {
1.212 raeburn 20195: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20196: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20197: my %defaultchecked = (
20198: 'canuse_pdfforms' => 'off',
20199: 'uselcmath' => 'on',
1.398 raeburn 20200: 'usejsme' => 'on',
20201: 'inline_chem' => 'on',
1.404 raeburn 20202: 'ltiauth' => 'off',
1.257 raeburn 20203: );
1.404 raeburn 20204: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 20205: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20206: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
20207: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
20208: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 20209: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 20210: my %staticdefaults = (
20211: anonsurvey_threshold => 10,
20212: uploadquota => 500,
1.257 raeburn 20213: postsubmit => 60,
1.276 raeburn 20214: mysqltables => 172800,
1.198 raeburn 20215: );
1.314 raeburn 20216: my %texoptions = (
20217: MathJax => 'MathJax',
20218: mimetex => &mt('Convert to Images'),
20219: tth => &mt('TeX to HTML'),
20220: );
1.121 raeburn 20221: $defaultshash{'coursedefaults'} = {};
20222:
20223: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
20224: if ($domconfig{'coursedefaults'} eq '') {
20225: $domconfig{'coursedefaults'} = {};
20226: }
20227: }
20228:
20229: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
20230: foreach my $item (@toggles) {
20231: if ($defaultchecked{$item} eq 'on') {
20232: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20233: ($env{'form.'.$item} eq '0')) {
20234: $changes{$item} = 1;
1.192 raeburn 20235: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 20236: $changes{$item} = 1;
20237: }
20238: } elsif ($defaultchecked{$item} eq 'off') {
20239: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20240: ($env{'form.'.$item} eq '1')) {
20241: $changes{$item} = 1;
20242: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
20243: $changes{$item} = 1;
20244: }
20245: }
20246: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
20247: }
1.198 raeburn 20248: foreach my $item (@numbers) {
20249: my ($currdef,$newdef);
1.208 raeburn 20250: $newdef = $env{'form.'.$item};
1.198 raeburn 20251: if ($item eq 'anonsurvey_threshold') {
20252: $currdef = $domconfig{'coursedefaults'}{$item};
20253: $newdef =~ s/\D//g;
20254: if ($newdef eq '' || $newdef < 1) {
20255: $newdef = 1;
20256: }
20257: $defaultshash{'coursedefaults'}{$item} = $newdef;
20258: } else {
1.276 raeburn 20259: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
20260: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
20261: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 20262: }
20263: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 20264: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 20265: }
20266: if ($currdef ne $newdef) {
20267: if ($item eq 'anonsurvey_threshold') {
20268: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
20269: $changes{$item} = 1;
20270: }
1.276 raeburn 20271: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 20272: my $setting = $1;
1.276 raeburn 20273: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
20274: $changes{$setting} = 1;
1.198 raeburn 20275: }
20276: }
1.139 raeburn 20277: }
20278: }
1.314 raeburn 20279: my $texengine;
20280: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
20281: $texengine = $env{'form.texengine'};
1.349 raeburn 20282: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
20283: if ($currdef eq '') {
20284: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 20285: $changes{'texengine'} = 1;
20286: }
1.349 raeburn 20287: } elsif ($currdef ne $texengine) {
1.314 raeburn 20288: $changes{'texengine'} = 1;
20289: }
20290: }
20291: if ($texengine ne '') {
20292: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
20293: }
1.264 raeburn 20294: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
20295: my @currclonecode;
20296: if (ref($currclone) eq 'HASH') {
20297: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
20298: @currclonecode = @{$currclone->{'instcode'}};
20299: }
20300: }
20301: my $newclone;
1.289 raeburn 20302: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 20303: $newclone = $env{'form.canclone'};
20304: }
20305: if ($newclone eq 'instcode') {
20306: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
20307: my (%codedefaults,@code_order,@clonecode);
20308: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
20309: \@code_order);
20310: foreach my $item (@code_order) {
20311: if (grep(/^\Q$item\E$/,@newcodes)) {
20312: push(@clonecode,$item);
20313: }
20314: }
20315: if (@clonecode) {
20316: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
20317: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
20318: if (@diffs) {
20319: $changes{'canclone'} = 1;
20320: }
20321: } else {
20322: $newclone eq '';
20323: }
20324: } elsif ($newclone ne '') {
1.289 raeburn 20325: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
20326: }
1.264 raeburn 20327: if ($newclone ne $currclone) {
20328: $changes{'canclone'} = 1;
20329: }
1.257 raeburn 20330: my %credits;
20331: foreach my $type (@types) {
20332: unless ($type eq 'community') {
20333: $credits{$type} = $env{'form.'.$type.'_credits'};
20334: $credits{$type} =~ s/[^\d.]+//g;
20335: }
20336: }
20337: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
20338: ($env{'form.coursecredits'} eq '1')) {
20339: $changes{'coursecredits'} = 1;
20340: foreach my $type (keys(%credits)) {
20341: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20342: }
20343: } else {
1.289 raeburn 20344: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 20345: foreach my $type (@types) {
20346: unless ($type eq 'community') {
1.289 raeburn 20347: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 20348: $changes{'coursecredits'} = 1;
20349: }
20350: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20351: }
20352: }
20353: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20354: foreach my $type (@types) {
20355: unless ($type eq 'community') {
20356: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
20357: $changes{'coursecredits'} = 1;
20358: last;
20359: }
20360: }
20361: }
20362: }
20363: }
20364: if ($env{'form.postsubmit'} eq '1') {
20365: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
20366: my %currtimeout;
20367: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20368: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
20369: $changes{'postsubmit'} = 1;
20370: }
20371: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20372: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
20373: }
20374: } else {
20375: $changes{'postsubmit'} = 1;
20376: }
20377: foreach my $type (@types) {
20378: my $timeout = $env{'form.'.$type.'_timeout'};
20379: $timeout =~ s/\D//g;
20380: if ($timeout == $staticdefaults{'postsubmit'}) {
20381: $timeout = '';
20382: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
20383: $timeout = '0';
20384: }
20385: unless ($timeout eq '') {
20386: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
20387: }
20388: if (exists($currtimeout{$type})) {
20389: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 20390: $changes{'postsubmit'} = 1;
1.257 raeburn 20391: }
20392: } elsif ($timeout ne '') {
20393: $changes{'postsubmit'} = 1;
20394: }
20395: }
20396: } else {
20397: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
20398: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20399: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
20400: $changes{'postsubmit'} = 1;
20401: }
20402: } else {
20403: $changes{'postsubmit'} = 1;
20404: }
1.192 raeburn 20405: }
1.121 raeburn 20406: }
20407: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20408: $dom);
20409: if ($putresult eq 'ok') {
20410: if (keys(%changes) > 0) {
1.213 raeburn 20411: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 20412: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 20413: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 20414: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.404 raeburn 20415: ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
20416: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.257 raeburn 20417: if ($changes{$item}) {
20418: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
20419: }
1.289 raeburn 20420: }
1.192 raeburn 20421: if ($changes{'coursecredits'}) {
20422: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 20423: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
20424: $domdefaults{$type.'credits'} =
20425: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
20426: }
20427: }
20428: }
20429: if ($changes{'postsubmit'}) {
20430: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20431: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
20432: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20433: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
20434: $domdefaults{$type.'postsubtimeout'} =
20435: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20436: }
20437: }
1.192 raeburn 20438: }
20439: }
1.198 raeburn 20440: if ($changes{'uploadquota'}) {
20441: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20442: foreach my $type (@types) {
20443: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
20444: }
20445: }
20446: }
1.264 raeburn 20447: if ($changes{'canclone'}) {
20448: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20449: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20450: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20451: if (@clonecodes) {
20452: $domdefaults{'canclone'} = join('+',@clonecodes);
20453: }
20454: }
20455: } else {
20456: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20457: }
20458: }
1.121 raeburn 20459: my $cachetime = 24*60*60;
20460: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20461: if (ref($lastactref) eq 'HASH') {
20462: $lastactref->{'domdefaults'} = 1;
20463: }
1.121 raeburn 20464: }
20465: $resulttext = &mt('Changes made:').'<ul>';
20466: foreach my $item (sort(keys(%changes))) {
20467: if ($item eq 'canuse_pdfforms') {
20468: if ($env{'form.'.$item} eq '1') {
20469: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20470: } else {
20471: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20472: }
1.257 raeburn 20473: } elsif ($item eq 'uselcmath') {
20474: if ($env{'form.'.$item} eq '1') {
20475: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20476: } else {
20477: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20478: }
20479: } elsif ($item eq 'usejsme') {
20480: if ($env{'form.'.$item} eq '1') {
20481: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20482: } else {
1.289 raeburn 20483: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20484: }
1.398 raeburn 20485: } elsif ($item eq 'inline_chem') {
20486: if ($env{'form.'.$item} eq '1') {
20487: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
20488: } else {
20489: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
20490: }
1.314 raeburn 20491: } elsif ($item eq 'texengine') {
20492: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20493: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20494: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20495: }
1.139 raeburn 20496: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20497: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20498: } elsif ($item eq 'uploadquota') {
20499: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20500: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20501: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20502: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20503: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20504: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20505: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20506: '</ul>'.
20507: '</li>';
20508: } else {
20509: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20510: }
1.276 raeburn 20511: } elsif ($item eq 'mysqltables') {
20512: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20513: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20514: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20515: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20516: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20517: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20518: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20519: '</ul>'.
20520: '</li>';
20521: } else {
20522: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20523: }
1.257 raeburn 20524: } elsif ($item eq 'postsubmit') {
20525: if ($domdefaults{'postsubmit'} eq 'off') {
20526: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20527: } else {
20528: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20529: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20530: $resulttext .= &mt('durations:').'<ul>';
20531: foreach my $type (@types) {
20532: $resulttext .= '<li>';
20533: my $timeout;
20534: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20535: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20536: }
20537: my $display;
20538: if ($timeout eq '0') {
20539: $display = &mt('unlimited');
20540: } elsif ($timeout eq '') {
20541: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20542: } else {
20543: $display = &mt('[quant,_1,second]',$timeout);
20544: }
20545: if ($type eq 'community') {
20546: $resulttext .= &mt('Communities');
20547: } elsif ($type eq 'official') {
20548: $resulttext .= &mt('Official courses');
20549: } elsif ($type eq 'unofficial') {
20550: $resulttext .= &mt('Unofficial courses');
20551: } elsif ($type eq 'textbook') {
20552: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20553: } elsif ($type eq 'placement') {
20554: $resulttext .= &mt('Placement tests');
1.257 raeburn 20555: }
20556: $resulttext .= ' -- '.$display.'</li>';
20557: }
20558: $resulttext .= '</ul>';
20559: }
1.289 raeburn 20560: $resulttext .= '</li>';
1.257 raeburn 20561: }
1.192 raeburn 20562: } elsif ($item eq 'coursecredits') {
20563: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20564: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20565: ($domdefaults{'unofficialcredits'} eq '') &&
20566: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20567: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20568: } else {
20569: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20570: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20571: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20572: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20573: '</ul>'.
20574: '</li>';
20575: }
20576: } else {
20577: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20578: }
1.264 raeburn 20579: } elsif ($item eq 'canclone') {
20580: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20581: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20582: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20583: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20584: }
20585: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20586: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20587: } else {
1.289 raeburn 20588: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20589: }
1.404 raeburn 20590: } elsif ($item eq 'ltiauth') {
20591: if ($env{'form.'.$item} eq '1') {
20592: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
20593: } else {
20594: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
20595: }
1.140 raeburn 20596: }
1.121 raeburn 20597: }
20598: $resulttext .= '</ul>';
20599: } else {
20600: $resulttext = &mt('No changes made to course defaults');
20601: }
20602: } else {
20603: $resulttext = '<span class="LC_error">'.
20604: &mt('An error occurred: [_1]',$putresult).'</span>';
20605: }
20606: return $resulttext;
20607: }
20608:
1.231 raeburn 20609: sub modify_selfenrollment {
20610: my ($dom,$lastactref,%domconfig) = @_;
20611: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20612: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20613: my %titles = &tool_titles();
1.232 raeburn 20614: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20615: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20616: $ordered{'default'} = ['types','registered','approval','limit'];
20617:
20618: my (%roles,%shown,%toplevel);
20619: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20620:
20621: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20622: if ($domconfig{'selfenrollment'} eq '') {
20623: $domconfig{'selfenrollment'} = {};
20624: }
20625: }
20626: %toplevel = (
20627: admin => 'Configuration Rights',
20628: default => 'Default settings',
20629: validation => 'Validation of self-enrollment requests',
20630: );
1.233 raeburn 20631: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20632:
20633: if (ref($ordered{'admin'}) eq 'ARRAY') {
20634: foreach my $item (@{$ordered{'admin'}}) {
20635: foreach my $type (@types) {
20636: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20637: $selfenrollhash{'admin'}{$type}{$item} = 1;
20638: } else {
20639: $selfenrollhash{'admin'}{$type}{$item} = 0;
20640: }
20641: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20642: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20643: if ($selfenrollhash{'admin'}{$type}{$item} ne
20644: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20645: push(@{$changes{'admin'}{$type}},$item);
20646: }
20647: } else {
20648: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20649: push(@{$changes{'admin'}{$type}},$item);
20650: }
20651: }
20652: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20653: push(@{$changes{'admin'}{$type}},$item);
20654: }
20655: }
20656: }
20657: }
20658:
20659: foreach my $item (@{$ordered{'default'}}) {
20660: foreach my $type (@types) {
20661: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20662: if ($item eq 'types') {
20663: unless (($value eq 'all') || ($value eq 'dom')) {
20664: $value = '';
20665: }
20666: } elsif ($item eq 'registered') {
20667: unless ($value eq '1') {
20668: $value = 0;
20669: }
20670: } elsif ($item eq 'approval') {
20671: unless ($value =~ /^[012]$/) {
20672: $value = 0;
20673: }
20674: } else {
20675: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20676: $value = 'none';
20677: }
20678: }
20679: $selfenrollhash{'default'}{$type}{$item} = $value;
20680: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20681: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20682: if ($selfenrollhash{'default'}{$type}{$item} ne
20683: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20684: push(@{$changes{'default'}{$type}},$item);
20685: }
20686: } else {
20687: push(@{$changes{'default'}{$type}},$item);
20688: }
20689: } else {
20690: push(@{$changes{'default'}{$type}},$item);
20691: }
20692: if ($item eq 'limit') {
20693: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20694: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20695: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20696: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20697: }
20698: } else {
20699: $selfenrollhash{'default'}{$type}{'cap'} = '';
20700: }
20701: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20702: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20703: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20704: push(@{$changes{'default'}{$type}},'cap');
20705: }
20706: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20707: push(@{$changes{'default'}{$type}},'cap');
20708: }
20709: }
20710: }
20711: }
20712:
20713: foreach my $item (@{$itemsref}) {
20714: if ($item eq 'fields') {
20715: my @changed;
20716: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20717: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20718: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20719: }
20720: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20721: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20722: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20723: $domconfig{'selfenrollment'}{'validation'}{$item});
20724: } else {
20725: @changed = @{$selfenrollhash{'validation'}{$item}};
20726: }
20727: } else {
20728: @changed = @{$selfenrollhash{'validation'}{$item}};
20729: }
20730: if (@changed) {
20731: if ($selfenrollhash{'validation'}{$item}) {
20732: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20733: } else {
20734: $changes{'validation'}{$item} = &mt('None');
20735: }
20736: }
20737: } else {
20738: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20739: if ($item eq 'markup') {
20740: if ($env{'form.selfenroll_validation_'.$item}) {
20741: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20742: }
20743: }
20744: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20745: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20746: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20747: }
20748: }
20749: }
20750: }
20751:
20752: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20753: $dom);
20754: if ($putresult eq 'ok') {
20755: if (keys(%changes) > 0) {
20756: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20757: $resulttext = &mt('Changes made:').'<ul>';
20758: foreach my $key ('admin','default','validation') {
20759: if (ref($changes{$key}) eq 'HASH') {
20760: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20761: if ($key eq 'validation') {
20762: foreach my $item (@{$itemsref}) {
20763: if (exists($changes{$key}{$item})) {
20764: if ($item eq 'markup') {
20765: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20766: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20767: } else {
20768: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20769: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20770: }
20771: }
20772: }
20773: } else {
20774: foreach my $type (@types) {
20775: if ($type eq 'community') {
20776: $roles{'1'} = &mt('Community personnel');
20777: } else {
20778: $roles{'1'} = &mt('Course personnel');
20779: }
20780: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20781: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20782: if ($key eq 'admin') {
20783: my @mgrdc = ();
20784: if (ref($ordered{$key}) eq 'ARRAY') {
20785: foreach my $item (@{$ordered{'admin'}}) {
20786: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20787: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20788: push(@mgrdc,$item);
20789: }
20790: }
20791: }
20792: if (@mgrdc) {
20793: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20794: } else {
20795: delete($domdefaults{$type.'selfenrolladmdc'});
20796: }
20797: }
20798: } else {
20799: if (ref($ordered{$key}) eq 'ARRAY') {
20800: foreach my $item (@{$ordered{$key}}) {
20801: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20802: $domdefaults{$type.'selfenroll'.$item} =
20803: $selfenrollhash{$key}{$type}{$item};
20804: }
20805: }
20806: }
20807: }
20808: }
1.231 raeburn 20809: $resulttext .= '<li>'.$titles{$type}.'<ul>';
20810: foreach my $item (@{$ordered{$key}}) {
20811: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20812: $resulttext .= '<li>';
20813: if ($key eq 'admin') {
20814: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
20815: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
20816: } else {
20817: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
20818: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
20819: }
20820: $resulttext .= '</li>';
20821: }
20822: }
20823: $resulttext .= '</ul></li>';
20824: }
20825: }
20826: $resulttext .= '</ul></li>';
20827: }
20828: }
1.305 raeburn 20829: }
20830: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
20831: my $cachetime = 24*60*60;
20832: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20833: if (ref($lastactref) eq 'HASH') {
20834: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 20835: }
1.231 raeburn 20836: }
20837: $resulttext .= '</ul>';
20838: } else {
20839: $resulttext = &mt('No changes made to self-enrollment settings');
20840: }
20841: } else {
20842: $resulttext = '<span class="LC_error">'.
20843: &mt('An error occurred: [_1]',$putresult).'</span>';
20844: }
20845: return $resulttext;
20846: }
20847:
1.373 raeburn 20848: sub modify_wafproxy {
20849: my ($dom,$action,$lastactref,%domconfig) = @_;
20850: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 20851: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
20852: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 20853: foreach my $server (sort(keys(%servers))) {
20854: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20855: if ($serverhome eq $server) {
20856: my $serverdom = &Apache::lonnet::host_domain($server);
20857: if ($serverdom eq $dom) {
20858: $canset{$server} = 1;
20859: }
20860: }
20861: }
1.381 raeburn 20862: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
20863: %{$values{$dom}} = ();
20864: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
20865: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
20866: }
1.388 raeburn 20867: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
20868: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
20869: }
1.382 raeburn 20870: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 20871: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
20872: }
20873: }
1.373 raeburn 20874: my $output;
20875: if (keys(%canset)) {
20876: %{$wafproxy{'alias'}} = ();
1.388 raeburn 20877: %{$wafproxy{'saml'}} = ();
1.373 raeburn 20878: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 20879: if ($env{'form.wafproxy_'.$dom}) {
20880: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
20881: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
20882: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
20883: $changes{'alias'} = 1;
20884: }
1.388 raeburn 20885: if ($env{'form.wafproxy_alias_saml_'.$key}) {
20886: $wafproxy{'saml'}{$key} = 1;
20887: }
20888: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
20889: $changes{'saml'} = 1;
20890: }
1.381 raeburn 20891: } else {
20892: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 20893: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 20894: if ($curralias{$key}) {
20895: $changes{'alias'} = 1;
20896: }
1.388 raeburn 20897: if ($currsaml{$key}) {
20898: $changes{'saml'} = 1;
20899: }
1.373 raeburn 20900: }
20901: if ($wafproxy{'alias'}{$key} eq '') {
20902: if ($curralias{$key}) {
20903: $expirecache{$key} = 1;
20904: }
20905: delete($wafproxy{'alias'}{$key});
20906: }
1.388 raeburn 20907: if ($wafproxy{'saml'}{$key} eq '') {
20908: if ($currsaml{$key}) {
20909: $expiresaml{$key} = 1;
20910: }
20911: delete($wafproxy{'saml'}{$key});
20912: }
1.373 raeburn 20913: }
20914: unless (keys(%{$wafproxy{'alias'}})) {
20915: delete($wafproxy{'alias'});
20916: }
1.388 raeburn 20917: unless (keys(%{$wafproxy{'saml'}})) {
20918: delete($wafproxy{'saml'});
20919: }
20920: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 20921: my %warn = (
20922: trusted => 'trusted IP range(s)',
1.381 raeburn 20923: vpnint => 'internal IP range(s) for VPN sessions(s)',
20924: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 20925: );
1.382 raeburn 20926: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20927: my $possible = $env{'form.wafproxy_'.$item};
20928: $possible =~ s/^\s+|\s+$//g;
20929: if ($possible ne '') {
1.381 raeburn 20930: if ($item eq 'remoteip') {
20931: if ($possible =~ /^[mhn]$/) {
20932: $wafproxy{$item} = $possible;
20933: }
20934: } elsif ($item eq 'ipheader') {
20935: if ($wafproxy{'remoteip'} eq 'h') {
20936: $wafproxy{$item} = $possible;
20937: }
1.382 raeburn 20938: } elsif ($item eq 'sslopt') {
20939: if ($possible =~ /^0|1$/) {
20940: $wafproxy{$item} = $possible;
20941: }
1.373 raeburn 20942: } else {
20943: my (@ok,$count);
1.381 raeburn 20944: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
20945: unless ($env{'form.wafproxy_vpnaccess'}) {
20946: $possible = '';
20947: }
20948: } elsif ($item eq 'trusted') {
20949: unless ($wafproxy{'remoteip'} eq 'h') {
20950: $possible = '';
20951: }
20952: }
20953: unless ($possible eq '') {
20954: $possible =~ s/[\r\n]+/\s/g;
20955: $possible =~ s/\s*-\s*/-/g;
20956: $possible =~ s/\s+/,/g;
1.393 raeburn 20957: $possible =~ s/,+/,/g;
1.381 raeburn 20958: }
1.373 raeburn 20959: $count = 0;
1.381 raeburn 20960: if ($possible ne '') {
1.373 raeburn 20961: foreach my $poss (split(/\,/,$possible)) {
20962: $count ++;
1.393 raeburn 20963: $poss = &validate_ip_pattern($poss);
20964: if ($poss ne '') {
1.373 raeburn 20965: push(@ok,$poss);
20966: }
20967: }
20968: my $diff = $count - scalar(@ok);
20969: if ($diff) {
20970: push(@warnings,'<li>'.
20971: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
20972: $diff,$warn{$item}).
20973: '</li>');
20974: }
1.393 raeburn 20975: if (@ok) {
20976: my @cidr_list;
20977: foreach my $item (@ok) {
20978: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
20979: }
20980: $wafproxy{$item} = join(',',@cidr_list);
20981: }
1.373 raeburn 20982: }
20983: }
1.381 raeburn 20984: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 20985: $changes{$item} = 1;
20986: }
1.381 raeburn 20987: } elsif ($currvalue{$item}) {
20988: $changes{$item} = 1;
20989: }
20990: }
20991: } else {
20992: if (keys(%curralias)) {
20993: $changes{'alias'} = 1;
1.388 raeburn 20994: }
20995: if (keys(%currsaml)) {
20996: $changes{'saml'} = 1;
1.381 raeburn 20997: }
20998: if (keys(%currvalue)) {
20999: foreach my $key (keys(%currvalue)) {
21000: $changes{$key} = 1;
1.373 raeburn 21001: }
21002: }
21003: }
21004: if (keys(%changes)) {
21005: my %defaultshash = (
21006: wafproxy => \%wafproxy,
21007: );
21008: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21009: $dom);
21010: if ($putresult eq 'ok') {
21011: my $cachetime = 24*60*60;
21012: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21013: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21014: if ($changes{$item}) {
21015: unless ($updatedomdefs) {
21016: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21017: $updatedomdefs = 1;
21018: }
21019: if ($wafproxy{$item}) {
21020: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21021: } elsif (exists($domdefaults{'waf_'.$item})) {
21022: delete($domdefaults{'waf_'.$item});
21023: }
21024: }
21025: }
21026: if ($updatedomdefs) {
21027: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21028: if (ref($lastactref) eq 'HASH') {
21029: $lastactref->{'domdefaults'} = 1;
21030: }
21031: }
21032: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21033: my %updates = %expirecache;
21034: foreach my $key (keys(%expirecache)) {
21035: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21036: }
21037: if (ref($wafproxy{'alias'}) eq 'HASH') {
21038: my $cachetime = 24*60*60;
21039: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21040: $updates{$key} = 1;
21041: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21042: $cachetime);
21043: }
21044: }
21045: if (ref($lastactref) eq 'HASH') {
21046: $lastactref->{'proxyalias'} = \%updates;
21047: }
21048: }
1.388 raeburn 21049: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21050: my %samlupdates = %expiresaml;
21051: foreach my $key (keys(%expiresaml)) {
21052: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21053: }
21054: if (ref($wafproxy{'saml'}) eq 'HASH') {
21055: my $cachetime = 24*60*60;
21056: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21057: $samlupdates{$key} = 1;
21058: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21059: $cachetime);
21060: }
21061: }
21062: if (ref($lastactref) eq 'HASH') {
21063: $lastactref->{'proxysaml'} = \%samlupdates;
21064: }
21065: }
1.373 raeburn 21066: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 21067: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21068: if ($changes{$item}) {
21069: if ($item eq 'alias') {
21070: my $numaliased = 0;
21071: if (ref($wafproxy{'alias'}) eq 'HASH') {
21072: my $shown;
21073: if (keys(%{$wafproxy{'alias'}})) {
21074: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21075: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21076: &Apache::lonnet::hostname($server),
21077: $wafproxy{'alias'}{$server}).'</li>';
21078: $numaliased ++;
21079: }
21080: if ($numaliased) {
21081: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21082: '<ul>'.$shown.'</ul>').'</li>';
21083: }
21084: }
21085: }
21086: unless ($numaliased) {
21087: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21088: }
1.388 raeburn 21089: } elsif ($item eq 'saml') {
21090: my $shown;
21091: if (ref($wafproxy{'saml'}) eq 'HASH') {
21092: if (keys(%{$wafproxy{'saml'}})) {
21093: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21094: }
21095: }
21096: if ($shown) {
1.396 raeburn 21097: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 21098: $shown).'</li>';
21099: } else {
1.396 raeburn 21100: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 21101: }
1.373 raeburn 21102: } else {
1.381 raeburn 21103: if ($item eq 'remoteip') {
21104: my %ip_methods = &remoteip_methods();
21105: if ($wafproxy{$item} =~ /^[mh]$/) {
21106: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
21107: $ip_methods{$wafproxy{$item}}).'</li>';
21108: } else {
21109: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
21110: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
21111: '</li>';
21112: } else {
21113: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
21114: }
21115: }
21116: } elsif ($item eq 'ipheader') {
1.373 raeburn 21117: if ($wafproxy{$item}) {
1.381 raeburn 21118: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 21119: $wafproxy{$item}).'</li>';
21120: } else {
1.381 raeburn 21121: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 21122: }
21123: } elsif ($item eq 'trusted') {
21124: if ($wafproxy{$item}) {
1.381 raeburn 21125: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 21126: $wafproxy{$item}).'</li>';
21127: } else {
21128: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
21129: }
1.381 raeburn 21130: } elsif ($item eq 'vpnint') {
21131: if ($wafproxy{$item}) {
21132: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
21133: $wafproxy{$item}).'</li>';
21134: } else {
21135: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
21136: }
21137: } elsif ($item eq 'vpnext') {
1.373 raeburn 21138: if ($wafproxy{$item}) {
1.381 raeburn 21139: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 21140: $wafproxy{$item}).'</li>';
21141: } else {
1.381 raeburn 21142: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 21143: }
1.382 raeburn 21144: } elsif ($item eq 'sslopt') {
21145: if ($wafproxy{$item}) {
21146: $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>';
21147: } else {
21148: $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>';
21149: }
1.373 raeburn 21150: }
21151: }
21152: }
21153: }
1.420 raeburn 21154: $output .= '</ul>';
1.373 raeburn 21155: } else {
21156: $output = '<span class="LC_error">'.
21157: &mt('An error occurred: [_1]',$putresult).'</span>';
21158: }
21159: } elsif (keys(%canset)) {
21160: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
21161: }
21162: if (@warnings) {
21163: $output .= '<br />'.&mt('Warnings:').'<ul>'.
21164: join("\n",@warnings).'</ul>';
21165: }
21166: return $output;
21167: }
21168:
21169: sub validate_ip_pattern {
21170: my ($pattern) = @_;
21171: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
21172: my ($start,$end) = ($1,$2);
21173: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 21174: if (($start !~ m{/}) && ($end !~ m{/})) {
21175: return $start.'-'.$end;
21176: }
21177: }
21178: } elsif ($pattern ne '') {
21179: $pattern = &Net::CIDR::cidrvalidate($pattern);
21180: if ($pattern ne '') {
21181: return $pattern;
1.373 raeburn 21182: }
21183: }
1.393 raeburn 21184: return;
1.373 raeburn 21185: }
21186:
1.137 raeburn 21187: sub modify_usersessions {
1.212 raeburn 21188: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 21189: my @hostingtypes = ('version','excludedomain','includedomain');
21190: my @offloadtypes = ('primary','default');
21191: my %types = (
21192: remote => \@hostingtypes,
21193: hosted => \@hostingtypes,
21194: spares => \@offloadtypes,
21195: );
21196: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 21197: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 21198: my (%by_ip,%by_location,@intdoms,@instdoms);
21199: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 21200: my @locations = sort(keys(%by_location));
1.137 raeburn 21201: my (%defaultshash,%changes);
21202: foreach my $prefix (@prefixes) {
21203: $defaultshash{'usersessions'}{$prefix} = {};
21204: }
1.212 raeburn 21205: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 21206: my $resulttext;
1.138 raeburn 21207: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 21208: foreach my $prefix (@prefixes) {
1.145 raeburn 21209: next if ($prefix eq 'spares');
21210: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 21211: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21212: if ($type eq 'version') {
21213: my $value = $env{'form.'.$prefix.'_'.$type};
21214: my $okvalue;
21215: if ($value ne '') {
21216: if (grep(/^\Q$value\E$/,@lcversions)) {
21217: $okvalue = $value;
21218: }
21219: }
21220: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21221: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21222: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
21223: if ($inuse == 0) {
21224: $changes{$prefix}{$type} = 1;
21225: } else {
21226: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
21227: $changes{$prefix}{$type} = 1;
21228: }
21229: if ($okvalue ne '') {
21230: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21231: }
21232: }
21233: } else {
21234: if (($inuse == 1) && ($okvalue ne '')) {
21235: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21236: $changes{$prefix}{$type} = 1;
21237: }
21238: }
21239: } else {
21240: if (($inuse == 1) && ($okvalue ne '')) {
21241: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21242: $changes{$prefix}{$type} = 1;
21243: }
21244: }
21245: } else {
21246: if (($inuse == 1) && ($okvalue ne '')) {
21247: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21248: $changes{$prefix}{$type} = 1;
21249: }
21250: }
21251: } else {
21252: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21253: my @okvals;
21254: foreach my $val (@vals) {
1.138 raeburn 21255: if ($val =~ /:/) {
21256: my @items = split(/:/,$val);
21257: foreach my $item (@items) {
21258: if (ref($by_location{$item}) eq 'ARRAY') {
21259: push(@okvals,$item);
21260: }
21261: }
21262: } else {
21263: if (ref($by_location{$val}) eq 'ARRAY') {
21264: push(@okvals,$val);
21265: }
1.137 raeburn 21266: }
21267: }
21268: @okvals = sort(@okvals);
21269: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21270: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21271: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21272: if ($inuse == 0) {
21273: $changes{$prefix}{$type} = 1;
21274: } else {
21275: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21276: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
21277: if (@changed > 0) {
21278: $changes{$prefix}{$type} = 1;
21279: }
21280: }
21281: } else {
21282: if ($inuse == 1) {
21283: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21284: $changes{$prefix}{$type} = 1;
21285: }
21286: }
21287: } else {
21288: if ($inuse == 1) {
21289: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21290: $changes{$prefix}{$type} = 1;
21291: }
21292: }
21293: } else {
21294: if ($inuse == 1) {
21295: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21296: $changes{$prefix}{$type} = 1;
21297: }
21298: }
21299: }
21300: }
21301: }
1.145 raeburn 21302:
21303: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 21304: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 21305: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
21306: my $savespares;
21307:
21308: foreach my $lonhost (sort(keys(%servers))) {
21309: my $serverhomeID =
21310: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 21311: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 21312: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
21313: my %spareschg;
21314: foreach my $type (@{$types{'spares'}}) {
21315: my @okspares;
21316: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
21317: foreach my $server (@checked) {
1.152 raeburn 21318: if (&Apache::lonnet::hostname($server) ne '') {
21319: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
21320: unless (grep(/^\Q$server\E$/,@okspares)) {
21321: push(@okspares,$server);
21322: }
1.145 raeburn 21323: }
21324: }
21325: }
21326: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
21327: my $newspare;
1.152 raeburn 21328: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
21329: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 21330: $newspare = $new;
21331: }
21332: }
1.152 raeburn 21333: my @spares;
21334: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
21335: @spares = sort(@okspares,$newspare);
21336: } else {
21337: @spares = sort(@okspares);
21338: }
21339: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 21340: if (ref($spareid{$lonhost}) eq 'HASH') {
21341: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 21342: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 21343: if (@diffs > 0) {
21344: $spareschg{$type} = 1;
21345: }
21346: }
21347: }
21348: }
21349: if (keys(%spareschg) > 0) {
21350: $changes{'spares'}{$lonhost} = \%spareschg;
21351: }
21352: }
1.261 raeburn 21353: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 21354: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 21355: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
21356: my @okoffload;
21357: if (@offloadnow) {
21358: foreach my $server (@offloadnow) {
21359: if (&Apache::lonnet::hostname($server) ne '') {
21360: unless (grep(/^\Q$server\E$/,@okoffload)) {
21361: push(@okoffload,$server);
21362: }
21363: }
21364: }
21365: if (@okoffload) {
21366: foreach my $lonhost (@okoffload) {
21367: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
21368: }
21369: }
21370: }
1.371 raeburn 21371: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
21372: my @okoffloadoth;
21373: if (@offloadoth) {
21374: foreach my $server (@offloadoth) {
21375: if (&Apache::lonnet::hostname($server) ne '') {
21376: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
21377: push(@okoffloadoth,$server);
21378: }
21379: }
21380: }
21381: if (@okoffloadoth) {
21382: foreach my $lonhost (@okoffloadoth) {
21383: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
21384: }
21385: }
21386: }
1.145 raeburn 21387: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21388: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
21389: if (ref($changes{'spares'}) eq 'HASH') {
21390: if (keys(%{$changes{'spares'}}) > 0) {
21391: $savespares = 1;
21392: }
21393: }
21394: } else {
21395: $savespares = 1;
21396: }
1.371 raeburn 21397: foreach my $offload ('offloadnow','offloadoth') {
21398: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
21399: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
21400: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
21401: $changes{$offload} = 1;
21402: last;
21403: }
1.261 raeburn 21404: }
1.371 raeburn 21405: unless ($changes{$offload}) {
21406: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
21407: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
21408: $changes{$offload} = 1;
21409: last;
21410: }
1.261 raeburn 21411: }
21412: }
1.371 raeburn 21413: } else {
21414: if (($offload eq 'offloadnow') && (@okoffload)) {
21415: $changes{'offloadnow'} = 1;
21416: }
21417: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
21418: $changes{'offloadoth'} = 1;
21419: }
21420: }
21421: }
21422: } else {
21423: if (@okoffload) {
1.261 raeburn 21424: $changes{'offloadnow'} = 1;
21425: }
1.371 raeburn 21426: if (@okoffloadoth) {
21427: $changes{'offloadoth'} = 1;
21428: }
1.145 raeburn 21429: }
1.147 raeburn 21430: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
21431: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 21432: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21433: $dom);
21434: if ($putresult eq 'ok') {
21435: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21436: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
21437: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
21438: }
21439: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
21440: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
21441: }
1.261 raeburn 21442: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21443: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
21444: }
1.371 raeburn 21445: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21446: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
21447: }
1.137 raeburn 21448: }
21449: my $cachetime = 24*60*60;
21450: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 21451: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 21452: if (ref($lastactref) eq 'HASH') {
21453: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 21454: $lastactref->{'usersessions'} = 1;
1.212 raeburn 21455: }
1.147 raeburn 21456: if (keys(%changes) > 0) {
21457: my %lt = &usersession_titles();
21458: $resulttext = &mt('Changes made:').'<ul>';
21459: foreach my $prefix (@prefixes) {
21460: if (ref($changes{$prefix}) eq 'HASH') {
21461: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21462: if ($prefix eq 'spares') {
21463: if (ref($changes{$prefix}) eq 'HASH') {
21464: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
21465: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 21466: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 21467: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
21468: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 21469: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
21470: foreach my $type (@{$types{$prefix}}) {
21471: if ($changes{$prefix}{$lonhost}{$type}) {
21472: my $offloadto = &mt('None');
21473: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
21474: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21475: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21476: }
1.145 raeburn 21477: }
1.147 raeburn 21478: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21479: }
1.137 raeburn 21480: }
21481: }
1.147 raeburn 21482: $resulttext .= '</li>';
1.137 raeburn 21483: }
21484: }
1.147 raeburn 21485: } else {
21486: foreach my $type (@{$types{$prefix}}) {
21487: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21488: my ($newvalue,$notinuse);
1.147 raeburn 21489: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21490: if (ref($defaultshash{'usersessions'}{$prefix})) {
21491: if ($type eq 'version') {
21492: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21493: } else {
21494: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21495: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21496: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21497: }
21498: } else {
21499: $notinuse = 1;
1.147 raeburn 21500: }
1.145 raeburn 21501: }
21502: }
21503: }
1.147 raeburn 21504: if ($newvalue eq '') {
21505: if ($type eq 'version') {
21506: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21507: } elsif ($notinuse) {
21508: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21509: } else {
21510: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21511: }
1.145 raeburn 21512: } else {
1.147 raeburn 21513: if ($type eq 'version') {
1.344 raeburn 21514: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21515: }
21516: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21517: }
1.137 raeburn 21518: }
21519: }
21520: }
1.147 raeburn 21521: $resulttext .= '</ul>';
1.137 raeburn 21522: }
21523: }
1.261 raeburn 21524: if ($changes{'offloadnow'}) {
21525: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21526: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21527: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21528: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21529: $resulttext .= '<li>'.$lonhost.'</li>';
21530: }
21531: $resulttext .= '</ul>';
21532: } else {
1.371 raeburn 21533: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21534: }
21535: } else {
21536: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21537: }
21538: }
21539: if ($changes{'offloadoth'}) {
21540: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21541: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21542: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21543: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21544: $resulttext .= '<li>'.$lonhost.'</li>';
21545: }
21546: $resulttext .= '</ul>';
21547: } else {
21548: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21549: }
21550: } else {
1.371 raeburn 21551: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21552: }
21553: }
1.147 raeburn 21554: $resulttext .= '</ul>';
21555: } else {
21556: $resulttext = $nochgmsg;
1.137 raeburn 21557: }
21558: } else {
21559: $resulttext = '<span class="LC_error">'.
21560: &mt('An error occurred: [_1]',$putresult).'</span>';
21561: }
21562: } else {
1.147 raeburn 21563: $resulttext = $nochgmsg;
1.137 raeburn 21564: }
21565: return $resulttext;
21566: }
21567:
1.275 raeburn 21568: sub modify_ssl {
21569: my ($dom,$lastactref,%domconfig) = @_;
21570: my (%by_ip,%by_location,@intdoms,@instdoms);
21571: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21572: my @locations = sort(keys(%by_location));
21573: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21574: my (%defaultshash,%changes);
21575: my $action = 'ssl';
1.293 raeburn 21576: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21577: foreach my $prefix (@prefixes) {
21578: $defaultshash{$action}{$prefix} = {};
21579: }
21580: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21581: my $resulttext;
21582: my %iphost = &Apache::lonnet::get_iphost();
21583: my @reptypes = ('certreq','nocertreq');
21584: my @connecttypes = ('dom','intdom','other');
21585: my %types = (
1.293 raeburn 21586: connto => \@connecttypes,
21587: connfrom => \@connecttypes,
21588: replication => \@reptypes,
1.275 raeburn 21589: );
21590: foreach my $prefix (sort(keys(%types))) {
21591: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21592: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21593: my $value = 'yes';
21594: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21595: $value = $env{'form.'.$prefix.'_'.$type};
21596: }
1.335 raeburn 21597: if (ref($domconfig{$action}) eq 'HASH') {
21598: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21599: if ($domconfig{$action}{$prefix}{$type} ne '') {
21600: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21601: $changes{$prefix}{$type} = 1;
21602: }
21603: $defaultshash{$action}{$prefix}{$type} = $value;
21604: } else {
21605: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21606: $changes{$prefix}{$type} = 1;
21607: }
21608: } else {
21609: $defaultshash{$action}{$prefix}{$type} = $value;
21610: $changes{$prefix}{$type} = 1;
21611: }
21612: } else {
21613: $defaultshash{$action}{$prefix}{$type} = $value;
21614: $changes{$prefix}{$type} = 1;
21615: }
21616: if (($type eq 'dom') && (keys(%servers) == 1)) {
21617: delete($changes{$prefix}{$type});
21618: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21619: delete($changes{$prefix}{$type});
21620: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21621: delete($changes{$prefix}{$type});
21622: }
21623: } elsif ($prefix eq 'replication') {
21624: if (@locations > 0) {
21625: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21626: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21627: my @okvals;
21628: foreach my $val (@vals) {
21629: if ($val =~ /:/) {
21630: my @items = split(/:/,$val);
21631: foreach my $item (@items) {
21632: if (ref($by_location{$item}) eq 'ARRAY') {
21633: push(@okvals,$item);
21634: }
21635: }
21636: } else {
21637: if (ref($by_location{$val}) eq 'ARRAY') {
21638: push(@okvals,$val);
21639: }
21640: }
21641: }
21642: @okvals = sort(@okvals);
21643: if (ref($domconfig{$action}) eq 'HASH') {
21644: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21645: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21646: if ($inuse == 0) {
21647: $changes{$prefix}{$type} = 1;
21648: } else {
21649: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21650: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21651: if (@changed > 0) {
21652: $changes{$prefix}{$type} = 1;
21653: }
21654: }
21655: } else {
21656: if ($inuse == 1) {
21657: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21658: $changes{$prefix}{$type} = 1;
21659: }
21660: }
21661: } else {
21662: if ($inuse == 1) {
21663: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21664: $changes{$prefix}{$type} = 1;
21665: }
21666: }
21667: } else {
21668: if ($inuse == 1) {
21669: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21670: $changes{$prefix}{$type} = 1;
21671: }
21672: }
21673: }
21674: }
21675: }
21676: }
1.336 raeburn 21677: if (keys(%changes)) {
21678: foreach my $prefix (keys(%changes)) {
21679: if (ref($changes{$prefix}) eq 'HASH') {
21680: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21681: delete($changes{$prefix});
21682: }
21683: } else {
21684: delete($changes{$prefix});
21685: }
21686: }
21687: }
1.275 raeburn 21688: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21689: if (keys(%changes) > 0) {
21690: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21691: $dom);
21692: if ($putresult eq 'ok') {
21693: if (ref($defaultshash{$action}) eq 'HASH') {
21694: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21695: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21696: }
1.293 raeburn 21697: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21698: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21699: }
21700: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21701: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21702: }
21703: }
21704: my $cachetime = 24*60*60;
21705: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21706: if (ref($lastactref) eq 'HASH') {
21707: $lastactref->{'domdefaults'} = 1;
21708: }
21709: if (keys(%changes) > 0) {
21710: my %titles = &ssl_titles();
21711: $resulttext = &mt('Changes made:').'<ul>';
21712: foreach my $prefix (@prefixes) {
21713: if (ref($changes{$prefix}) eq 'HASH') {
21714: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21715: foreach my $type (@{$types{$prefix}}) {
21716: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21717: my ($newvalue,$notinuse);
1.275 raeburn 21718: if (ref($defaultshash{$action}) eq 'HASH') {
21719: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21720: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21721: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21722: } else {
21723: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21724: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21725: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21726: }
21727: } else {
21728: $notinuse = 1;
1.275 raeburn 21729: }
21730: }
21731: }
1.344 raeburn 21732: if ($notinuse) {
21733: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21734: } elsif ($newvalue eq '') {
1.275 raeburn 21735: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21736: } else {
21737: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21738: }
21739: }
21740: }
21741: }
21742: $resulttext .= '</ul>';
21743: }
21744: }
21745: } else {
21746: $resulttext = $nochgmsg;
21747: }
21748: } else {
21749: $resulttext = '<span class="LC_error">'.
21750: &mt('An error occurred: [_1]',$putresult).'</span>';
21751: }
21752: } else {
21753: $resulttext = $nochgmsg;
21754: }
21755: return $resulttext;
21756: }
21757:
1.279 raeburn 21758: sub modify_trust {
21759: my ($dom,$lastactref,%domconfig) = @_;
21760: my (%by_ip,%by_location,@intdoms,@instdoms);
21761: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21762: my @locations = sort(keys(%by_location));
21763: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21764: my @types = ('exc','inc');
21765: my (%defaultshash,%changes);
21766: foreach my $prefix (@prefixes) {
21767: $defaultshash{'trust'}{$prefix} = {};
21768: }
21769: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21770: my $resulttext;
21771: foreach my $prefix (@prefixes) {
21772: foreach my $type (@types) {
21773: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21774: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21775: my @okvals;
21776: foreach my $val (@vals) {
21777: if ($val =~ /:/) {
21778: my @items = split(/:/,$val);
21779: foreach my $item (@items) {
21780: if (ref($by_location{$item}) eq 'ARRAY') {
21781: push(@okvals,$item);
21782: }
21783: }
21784: } else {
21785: if (ref($by_location{$val}) eq 'ARRAY') {
21786: push(@okvals,$val);
21787: }
21788: }
21789: }
21790: @okvals = sort(@okvals);
21791: if (ref($domconfig{'trust'}) eq 'HASH') {
21792: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21793: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21794: if ($inuse == 0) {
21795: $changes{$prefix}{$type} = 1;
21796: } else {
21797: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21798: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
21799: if (@changed > 0) {
21800: $changes{$prefix}{$type} = 1;
21801: }
21802: }
21803: } else {
21804: if ($inuse == 1) {
21805: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21806: $changes{$prefix}{$type} = 1;
21807: }
21808: }
21809: } else {
21810: if ($inuse == 1) {
21811: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21812: $changes{$prefix}{$type} = 1;
21813: }
21814: }
21815: } else {
21816: if ($inuse == 1) {
21817: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21818: $changes{$prefix}{$type} = 1;
21819: }
21820: }
21821: }
21822: }
21823: my $nochgmsg = &mt('No changes made to trust settings.');
21824: if (keys(%changes) > 0) {
21825: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21826: $dom);
21827: if ($putresult eq 'ok') {
21828: if (ref($defaultshash{'trust'}) eq 'HASH') {
21829: foreach my $prefix (@prefixes) {
21830: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
21831: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
21832: }
21833: }
21834: }
21835: my $cachetime = 24*60*60;
21836: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 21837: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 21838: if (ref($lastactref) eq 'HASH') {
21839: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 21840: $lastactref->{'trust'} = 1;
1.279 raeburn 21841: }
21842: if (keys(%changes) > 0) {
21843: my %lt = &trust_titles();
21844: $resulttext = &mt('Changes made:').'<ul>';
21845: foreach my $prefix (@prefixes) {
21846: if (ref($changes{$prefix}) eq 'HASH') {
21847: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21848: foreach my $type (@types) {
21849: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21850: my ($newvalue,$notinuse);
1.279 raeburn 21851: if (ref($defaultshash{'trust'}) eq 'HASH') {
21852: if (ref($defaultshash{'trust'}{$prefix})) {
21853: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21854: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
21855: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
21856: }
1.344 raeburn 21857: } else {
21858: $notinuse = 1;
1.279 raeburn 21859: }
21860: }
21861: }
1.344 raeburn 21862: if ($notinuse) {
21863: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
21864: } elsif ($newvalue eq '') {
1.279 raeburn 21865: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21866: } else {
21867: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
21868: }
21869: }
21870: }
21871: $resulttext .= '</ul>';
21872: }
21873: }
21874: $resulttext .= '</ul>';
21875: } else {
21876: $resulttext = $nochgmsg;
21877: }
21878: } else {
21879: $resulttext = '<span class="LC_error">'.
21880: &mt('An error occurred: [_1]',$putresult).'</span>';
21881: }
21882: } else {
21883: $resulttext = $nochgmsg;
21884: }
21885: return $resulttext;
21886: }
21887:
1.150 raeburn 21888: sub modify_loadbalancing {
21889: my ($dom,%domconfig) = @_;
21890: my $primary_id = &Apache::lonnet::domain($dom,'primary');
21891: my $intdom = &Apache::lonnet::internet_dom($primary_id);
21892: my ($othertitle,$usertypes,$types) =
21893: &Apache::loncommon::sorted_inst_types($dom);
21894: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 21895: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 21896: my @sparestypes = ('primary','default');
21897: my %typetitles = &sparestype_titles();
21898: my $resulttext;
1.342 raeburn 21899: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21900: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21901: %existing = %{$domconfig{'loadbalancing'}};
21902: }
21903: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 21904: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 21905: my ($saveloadbalancing,%defaultshash,%changes);
21906: my ($alltypes,$othertypes,$titles) =
21907: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
21908: my %ruletitles = &offloadtype_text();
21909: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
21910: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
21911: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
21912: if ($balancer eq '') {
21913: next;
21914: }
1.210 raeburn 21915: if (!exists($servers{$balancer})) {
1.171 raeburn 21916: if (exists($currbalancer{$balancer})) {
21917: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 21918: }
1.171 raeburn 21919: next;
21920: }
21921: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
21922: push(@{$changes{'delete'}},$balancer);
21923: next;
21924: }
21925: if (!exists($currbalancer{$balancer})) {
21926: push(@{$changes{'add'}},$balancer);
21927: }
21928: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
21929: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
21930: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
21931: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21932: $saveloadbalancing = 1;
21933: }
21934: foreach my $sparetype (@sparestypes) {
21935: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
21936: my @offloadto;
21937: foreach my $target (@targets) {
21938: if (($servers{$target}) && ($target ne $balancer)) {
21939: if ($sparetype eq 'default') {
21940: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
21941: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 21942: }
21943: }
1.171 raeburn 21944: unless(grep(/^\Q$target\E$/,@offloadto)) {
21945: push(@offloadto,$target);
21946: }
1.150 raeburn 21947: }
21948: }
1.284 raeburn 21949: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
21950: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
21951: push(@offloadto,$balancer);
21952: }
21953: }
21954: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 21955: }
1.342 raeburn 21956: if ($env{'form.loadbalancing_cookie_'.$i}) {
21957: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
21958: if (exists($currbalancer{$balancer})) {
21959: unless ($currcookies{$balancer}) {
21960: $changes{'curr'}{$balancer}{'cookie'} = 1;
21961: }
21962: }
21963: } elsif (exists($currbalancer{$balancer})) {
21964: if ($currcookies{$balancer}) {
21965: $changes{'curr'}{$balancer}{'cookie'} = 1;
21966: }
21967: }
1.171 raeburn 21968: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 21969: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21970: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
21971: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 21972: if (@targetdiffs > 0) {
1.171 raeburn 21973: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21974: }
1.171 raeburn 21975: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21976: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21977: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21978: }
21979: }
21980: }
21981: } else {
1.171 raeburn 21982: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 21983: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21984: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21985: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21986: $changes{'curr'}{$balancer}{'targets'} = 1;
21987: }
1.150 raeburn 21988: }
21989: }
1.210 raeburn 21990: }
1.150 raeburn 21991: }
21992: my $ishomedom;
1.171 raeburn 21993: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
21994: $ishomedom = 1;
1.150 raeburn 21995: }
21996: if (ref($alltypes) eq 'ARRAY') {
21997: foreach my $type (@{$alltypes}) {
21998: my $rule;
1.210 raeburn 21999: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22000: (!$ishomedom)) {
1.171 raeburn 22001: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22002: }
22003: if ($rule eq 'specific') {
1.255 raeburn 22004: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22005: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22006: $rule = $specifiedhost;
22007: }
1.150 raeburn 22008: }
1.171 raeburn 22009: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22010: if (ref($currrules{$balancer}) eq 'HASH') {
22011: if ($rule ne $currrules{$balancer}{$type}) {
22012: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22013: }
22014: } elsif ($rule ne '') {
1.171 raeburn 22015: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22016: }
22017: }
22018: }
1.171 raeburn 22019: }
22020: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22021: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22022: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22023: $defaultshash{'loadbalancing'} = {};
22024: }
22025: my $putresult = &Apache::lonnet::put_dom('configuration',
22026: \%defaultshash,$dom);
22027: if ($putresult eq 'ok') {
22028: if (keys(%changes) > 0) {
1.252 raeburn 22029: my %toupdate;
1.171 raeburn 22030: if (ref($changes{'delete'}) eq 'ARRAY') {
22031: foreach my $balancer (sort(@{$changes{'delete'}})) {
22032: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22033: $toupdate{$balancer} = 1;
1.150 raeburn 22034: }
1.171 raeburn 22035: }
22036: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22037: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22038: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22039: $toupdate{$balancer} = 1;
1.171 raeburn 22040: }
22041: }
22042: if (ref($changes{'curr'}) eq 'HASH') {
22043: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22044: $toupdate{$balancer} = 1;
1.171 raeburn 22045: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22046: if ($changes{'curr'}{$balancer}{'targets'}) {
22047: my %offloadstr;
22048: foreach my $sparetype (@sparestypes) {
22049: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22050: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22051: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22052: }
22053: }
1.150 raeburn 22054: }
1.171 raeburn 22055: if (keys(%offloadstr) == 0) {
22056: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22057: } else {
1.171 raeburn 22058: my $showoffload;
22059: foreach my $sparetype (@sparestypes) {
22060: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22061: if (defined($offloadstr{$sparetype})) {
22062: $showoffload .= $offloadstr{$sparetype};
22063: } else {
22064: $showoffload .= &mt('None');
22065: }
22066: $showoffload .= (' 'x3);
22067: }
22068: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22069: }
22070: }
22071: }
1.171 raeburn 22072: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22073: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22074: foreach my $type (@{$alltypes}) {
22075: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22076: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22077: my $balancetext;
22078: if ($rule eq '') {
22079: $balancetext = $ruletitles{'default'};
1.209 raeburn 22080: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22081: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22082: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22083: foreach my $sparetype (@sparestypes) {
22084: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22085: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22086: }
22087: }
1.253 raeburn 22088: foreach my $item (@{$alltypes}) {
22089: next if ($item =~ /^_LC_ipchange/);
22090: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22091: if ($hasrule eq 'homeserver') {
22092: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22093: } else {
22094: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22095: if ($servers{$hasrule}) {
22096: $toupdate{$hasrule} = 1;
22097: }
22098: }
22099: }
22100: }
1.254 raeburn 22101: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
22102: $balancetext = $ruletitles{$rule};
22103: } else {
22104: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22105: $balancetext = $ruletitles{'particular'}.' '.$receiver;
22106: if ($receiver) {
22107: $toupdate{$receiver};
22108: }
22109: }
22110: } else {
22111: $balancetext = $ruletitles{$rule};
1.252 raeburn 22112: }
1.171 raeburn 22113: } else {
22114: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
22115: }
1.210 raeburn 22116: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 22117: }
22118: }
22119: }
22120: }
1.342 raeburn 22121: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 22122: if ($currcookies{$balancer}) {
22123: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
22124: $balancer).'</li>';
22125: } else {
22126: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
22127: $balancer).'</li>';
22128: }
1.342 raeburn 22129: }
1.375 raeburn 22130: }
22131: }
22132: if (keys(%toupdate)) {
22133: my %thismachine;
22134: my $updatedhere;
22135: my $cachetime = 60*60*24;
22136: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
22137: foreach my $lonhost (keys(%toupdate)) {
22138: if ($thismachine{$lonhost}) {
22139: unless ($updatedhere) {
22140: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
22141: $defaultshash{'loadbalancing'},
22142: $cachetime);
22143: $updatedhere = 1;
1.252 raeburn 22144: }
1.375 raeburn 22145: } else {
22146: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
22147: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 22148: }
1.150 raeburn 22149: }
1.171 raeburn 22150: }
22151: if ($resulttext ne '') {
22152: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 22153: } else {
22154: $resulttext = $nochgmsg;
22155: }
22156: } else {
1.171 raeburn 22157: $resulttext = $nochgmsg;
1.150 raeburn 22158: }
22159: } else {
1.171 raeburn 22160: $resulttext = '<span class="LC_error">'.
22161: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 22162: }
22163: } else {
1.171 raeburn 22164: $resulttext = $nochgmsg;
1.150 raeburn 22165: }
22166: return $resulttext;
22167: }
22168:
1.48 raeburn 22169: sub recurse_check {
22170: my ($chkcats,$categories,$depth,$name) = @_;
22171: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
22172: my $chg = 0;
22173: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
22174: my $category = $chkcats->[$depth]{$name}[$j];
22175: my $item;
22176: if ($category eq '') {
22177: $chg ++;
22178: } else {
22179: my $deeper = $depth + 1;
22180: $item = &escape($category).':'.&escape($name).':'.$depth;
22181: if ($chg) {
22182: $categories->{$item} -= $chg;
22183: }
22184: &recurse_check($chkcats,$categories,$deeper,$category);
22185: $deeper --;
22186: }
22187: }
22188: }
22189: return;
22190: }
22191:
22192: sub recurse_cat_deletes {
22193: my ($item,$coursecategories,$deletions) = @_;
22194: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
22195: my $subdepth = $depth + 1;
22196: if (ref($coursecategories) eq 'HASH') {
22197: foreach my $subitem (keys(%{$coursecategories})) {
22198: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
22199: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
22200: delete($coursecategories->{$subitem});
22201: $deletions->{$subitem} = 1;
22202: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 22203: }
1.48 raeburn 22204: }
22205: }
22206: return;
22207: }
22208:
1.125 raeburn 22209: sub active_dc_picker {
1.191 raeburn 22210: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 22211: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 22212: my @domcoord = keys(%domcoords);
22213: if (keys(%currhash)) {
22214: foreach my $dc (keys(%currhash)) {
22215: unless (exists($domcoords{$dc})) {
22216: push(@domcoord,$dc);
22217: }
22218: }
22219: }
22220: @domcoord = sort(@domcoord);
1.210 raeburn 22221: my $numdcs = scalar(@domcoord);
1.191 raeburn 22222: my $rows = 0;
22223: my $table;
1.125 raeburn 22224: if ($numdcs > 1) {
1.191 raeburn 22225: $table = '<table>';
22226: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 22227: my $rem = $i%($numinrow);
22228: if ($rem == 0) {
22229: if ($i > 0) {
1.191 raeburn 22230: $table .= '</tr>';
1.125 raeburn 22231: }
1.191 raeburn 22232: $table .= '<tr>';
22233: $rows ++;
1.125 raeburn 22234: }
1.191 raeburn 22235: my $check = '';
22236: if ($inputtype eq 'radio') {
22237: if (keys(%currhash) == 0) {
22238: if (!$i) {
22239: $check = ' checked="checked"';
22240: }
22241: } elsif (exists($currhash{$domcoord[$i]})) {
22242: $check = ' checked="checked"';
22243: }
22244: } else {
22245: if (exists($currhash{$domcoord[$i]})) {
22246: $check = ' checked="checked"';
1.125 raeburn 22247: }
22248: }
1.191 raeburn 22249: if ($i == @domcoord - 1) {
1.125 raeburn 22250: my $colsleft = $numinrow - $rem;
22251: if ($colsleft > 1) {
1.191 raeburn 22252: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 22253: } else {
1.191 raeburn 22254: $table .= '<td class="LC_left_item">';
1.125 raeburn 22255: }
22256: } else {
1.191 raeburn 22257: $table .= '<td class="LC_left_item">';
22258: }
22259: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
22260: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
22261: $table .= '<span class="LC_nobreak"><label>'.
22262: '<input type="'.$inputtype.'" name="'.$name.'"'.
22263: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
22264: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 22265: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 22266: }
1.219 raeburn 22267: $table .= '</label></span></td>';
1.191 raeburn 22268: }
22269: $table .= '</tr></table>';
22270: } elsif ($numdcs == 1) {
1.219 raeburn 22271: my ($dcname,$dcdom) = split(':',$domcoord[0]);
22272: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 22273: if ($inputtype eq 'radio') {
1.247 raeburn 22274: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 22275: if ($user ne $dcname.':'.$dcdom) {
22276: $table .= ' ('.$dcname.':'.$dcdom.')';
22277: }
1.191 raeburn 22278: } else {
22279: my $check;
22280: if (exists($currhash{$domcoord[0]})) {
22281: $check = ' checked="checked"';
1.125 raeburn 22282: }
1.247 raeburn 22283: $table = '<span class="LC_nobreak"><label>'.
22284: '<input type="checkbox" name="'.$name.'" '.
22285: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 22286: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 22287: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 22288: }
1.220 raeburn 22289: $table .= '</label></span>';
1.191 raeburn 22290: $rows ++;
1.125 raeburn 22291: }
22292: }
1.191 raeburn 22293: return ($numdcs,$table,$rows);
1.125 raeburn 22294: }
22295:
1.137 raeburn 22296: sub usersession_titles {
22297: return &Apache::lonlocal::texthash(
22298: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
22299: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 22300: spares => 'Servers offloaded to, when busy',
1.137 raeburn 22301: version => 'LON-CAPA version requirement',
1.138 raeburn 22302: excludedomain => 'Allow all, but exclude specific domains',
22303: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 22304: primary => 'Primary (checked first)',
1.154 raeburn 22305: default => 'Default',
1.137 raeburn 22306: );
22307: }
22308:
1.152 raeburn 22309: sub id_for_thisdom {
22310: my (%servers) = @_;
22311: my %altids;
22312: foreach my $server (keys(%servers)) {
22313: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22314: if ($serverhome ne $server) {
22315: $altids{$serverhome} = $server;
22316: }
22317: }
22318: return %altids;
22319: }
22320:
1.150 raeburn 22321: sub count_servers {
22322: my ($currbalancer,%servers) = @_;
22323: my (@spares,$numspares);
22324: foreach my $lonhost (sort(keys(%servers))) {
22325: next if ($currbalancer eq $lonhost);
22326: push(@spares,$lonhost);
22327: }
22328: if ($currbalancer) {
22329: $numspares = scalar(@spares);
22330: } else {
22331: $numspares = scalar(@spares) - 1;
22332: }
22333: return ($numspares,@spares);
22334: }
22335:
22336: sub lonbalance_targets_js {
1.171 raeburn 22337: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 22338: my $select = &mt('Select');
22339: my ($alltargets,$allishome,$allinsttypes,@alltypes);
22340: if (ref($servers) eq 'HASH') {
22341: $alltargets = join("','",sort(keys(%{$servers})));
22342: my @homedoms;
22343: foreach my $server (sort(keys(%{$servers}))) {
22344: if (&Apache::lonnet::host_domain($server) eq $dom) {
22345: push(@homedoms,'1');
22346: } else {
22347: push(@homedoms,'0');
22348: }
22349: }
22350: $allishome = join("','",@homedoms);
22351: }
22352: if (ref($types) eq 'ARRAY') {
22353: if (@{$types} > 0) {
22354: @alltypes = @{$types};
22355: }
22356: }
22357: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
22358: $allinsttypes = join("','",@alltypes);
1.342 raeburn 22359: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22360: if (ref($settings) eq 'HASH') {
22361: %existing = %{$settings};
22362: }
22363: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 22364: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 22365: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 22366: return <<"END";
22367:
22368: <script type="text/javascript">
22369: // <![CDATA[
22370:
1.171 raeburn 22371: currBalancers = new Array('$balancers');
22372:
22373: function toggleTargets(balnum) {
22374: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22375: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
22376: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
22377: var prevbalancer = prevhostitem.value;
22378: var baltotal = document.getElementById('loadbalancing_total').value;
22379: prevhostitem.value = balancer;
22380: if (prevbalancer != '') {
22381: var prevIdx = currBalancers.indexOf(prevbalancer);
22382: if (prevIdx != -1) {
22383: currBalancers.splice(prevIdx,1);
22384: }
22385: }
1.150 raeburn 22386: if (balancer == '') {
1.171 raeburn 22387: hideSpares(balnum);
1.150 raeburn 22388: } else {
1.171 raeburn 22389: var currIdx = currBalancers.indexOf(balancer);
22390: if (currIdx == -1) {
22391: currBalancers.push(balancer);
22392: }
1.150 raeburn 22393: var homedoms = new Array('$allishome');
1.171 raeburn 22394: var ishomedom = homedoms[lonhostitem.selectedIndex];
22395: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 22396: }
1.171 raeburn 22397: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 22398: return;
22399: }
22400:
1.171 raeburn 22401: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 22402: var alltargets = new Array('$alltargets');
22403: var insttypes = new Array('$allinsttypes');
1.151 raeburn 22404: var offloadtypes = new Array('primary','default');
22405:
1.171 raeburn 22406: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
22407: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 22408:
1.151 raeburn 22409: for (var i=0; i<offloadtypes.length; i++) {
22410: var count = 0;
22411: for (var j=0; j<alltargets.length; j++) {
22412: if (alltargets[j] != balancer) {
1.171 raeburn 22413: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
22414: item.value = alltargets[j];
22415: item.style.textAlign='left';
22416: item.style.textFace='normal';
22417: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
22418: if (currBalancers.indexOf(alltargets[j]) == -1) {
22419: item.disabled = '';
22420: } else {
22421: item.disabled = 'disabled';
22422: item.checked = false;
22423: }
1.151 raeburn 22424: count ++;
22425: }
1.150 raeburn 22426: }
22427: }
1.151 raeburn 22428: for (var k=0; k<insttypes.length; k++) {
22429: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 22430: if (ishomedom == 1) {
1.171 raeburn 22431: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22432: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22433: } else {
1.171 raeburn 22434: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22435: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 22436: }
22437: } else {
1.171 raeburn 22438: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22439: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22440: }
1.151 raeburn 22441: if ((insttypes[k] != '_LC_external') &&
22442: ((insttypes[k] != '_LC_internetdom') ||
22443: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 22444: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
22445: item.options.length = 0;
22446: item.options[0] = new Option("","",true,true);
1.210 raeburn 22447: var idx = 0;
1.151 raeburn 22448: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 22449: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
22450: idx ++;
22451: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 22452: }
22453: }
22454: }
22455: }
22456: return;
22457: }
22458:
1.171 raeburn 22459: function hideSpares(balnum) {
1.150 raeburn 22460: var alltargets = new Array('$alltargets');
22461: var insttypes = new Array('$allinsttypes');
22462: var offloadtypes = new Array('primary','default');
22463:
1.171 raeburn 22464: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
22465: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 22466:
22467: var total = alltargets.length - 1;
22468: for (var i=0; i<offloadtypes; i++) {
22469: for (var j=0; j<total; j++) {
1.171 raeburn 22470: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
22471: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
22472: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 22473: }
1.150 raeburn 22474: }
22475: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 22476: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22477: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22478: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22479: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22480: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22481: }
22482: }
22483: return;
22484: }
22485:
1.171 raeburn 22486: function checkOffloads(item,balnum,type) {
1.150 raeburn 22487: var alltargets = new Array('$alltargets');
22488: var offloadtypes = new Array('primary','default');
22489: if (item.checked) {
22490: var total = alltargets.length - 1;
22491: var other;
22492: if (type == offloadtypes[0]) {
1.151 raeburn 22493: other = offloadtypes[1];
1.150 raeburn 22494: } else {
1.151 raeburn 22495: other = offloadtypes[0];
1.150 raeburn 22496: }
22497: for (var i=0; i<total; i++) {
1.171 raeburn 22498: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22499: if (server == item.value) {
1.171 raeburn 22500: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22501: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22502: }
22503: }
22504: }
22505: }
22506: return;
22507: }
22508:
1.171 raeburn 22509: function singleServerToggle(balnum,type) {
22510: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22511: if (offloadtoSelIdx == 0) {
1.171 raeburn 22512: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22513: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22514:
22515: } else {
1.171 raeburn 22516: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22517: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22518: }
22519: return;
22520: }
22521:
1.171 raeburn 22522: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22523: if (type == '_LC_external') {
1.171 raeburn 22524: return;
1.150 raeburn 22525: }
1.171 raeburn 22526: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22527: for (var i=0; i<typesRules.length; i++) {
22528: if (formname.elements[typesRules[i]].checked) {
22529: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22530: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22531: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22532: } else {
1.171 raeburn 22533: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22534: }
22535: }
22536: }
22537: return;
22538: }
22539:
22540: function balancerDeleteChange(balnum) {
22541: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22542: var baltotal = document.getElementById('loadbalancing_total').value;
22543: var addtarget;
22544: var removetarget;
22545: var action = 'delete';
22546: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22547: var lonhost = hostitem.value;
22548: var currIdx = currBalancers.indexOf(lonhost);
22549: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22550: if (currIdx != -1) {
22551: currBalancers.splice(currIdx,1);
22552: }
22553: addtarget = lonhost;
22554: } else {
22555: if (currIdx == -1) {
22556: currBalancers.push(lonhost);
22557: }
22558: removetarget = lonhost;
22559: action = 'undelete';
22560: }
22561: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22562: }
22563: return;
22564: }
22565:
22566: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22567: if (baltotal > 1) {
22568: var offloadtypes = new Array('primary','default');
22569: var alltargets = new Array('$alltargets');
22570: var insttypes = new Array('$allinsttypes');
22571: for (var i=0; i<baltotal; i++) {
22572: if (i != balnum) {
22573: for (var j=0; j<offloadtypes.length; j++) {
22574: var total = alltargets.length - 1;
22575: for (var k=0; k<total; k++) {
22576: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22577: var server = serveritem.value;
22578: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22579: if (server == addtarget) {
22580: serveritem.disabled = '';
22581: }
22582: }
22583: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22584: if (server == removetarget) {
22585: serveritem.disabled = 'disabled';
22586: serveritem.checked = false;
22587: }
22588: }
22589: }
22590: }
22591: for (var j=0; j<insttypes.length; j++) {
22592: if (insttypes[j] != '_LC_external') {
22593: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22594: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22595: var currSel = singleserver.selectedIndex;
22596: var currVal = singleserver.options[currSel].value;
22597: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22598: var numoptions = singleserver.options.length;
22599: var needsnew = 1;
22600: for (var k=0; k<numoptions; k++) {
22601: if (singleserver.options[k] == addtarget) {
22602: needsnew = 0;
22603: break;
22604: }
22605: }
22606: if (needsnew == 1) {
22607: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22608: }
22609: }
22610: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22611: singleserver.options.length = 0;
22612: if ((currVal) && (currVal != removetarget)) {
22613: singleserver.options[0] = new Option("","",false,false);
22614: } else {
22615: singleserver.options[0] = new Option("","",true,true);
22616: }
22617: var idx = 0;
22618: for (var m=0; m<alltargets.length; m++) {
22619: if (currBalancers.indexOf(alltargets[m]) == -1) {
22620: idx ++;
22621: if (currVal == alltargets[m]) {
22622: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22623: } else {
22624: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22625: }
22626: }
22627: }
22628: }
22629: }
22630: }
22631: }
1.150 raeburn 22632: }
22633: }
22634: }
22635: return;
22636: }
22637:
1.152 raeburn 22638: // ]]>
22639: </script>
22640:
22641: END
22642: }
22643:
1.372 raeburn 22644:
1.152 raeburn 22645: sub new_spares_js {
22646: my @sparestypes = ('primary','default');
22647: my $types = join("','",@sparestypes);
22648: my $select = &mt('Select');
22649: return <<"END";
22650:
22651: <script type="text/javascript">
22652: // <![CDATA[
22653:
22654: function updateNewSpares(formname,lonhost) {
22655: var types = new Array('$types');
22656: var include = new Array();
22657: var exclude = new Array();
22658: for (var i=0; i<types.length; i++) {
22659: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22660: for (var j=0; j<spareboxes.length; j++) {
22661: if (formname.elements[spareboxes[j]].checked) {
22662: exclude.push(formname.elements[spareboxes[j]].value);
22663: } else {
22664: include.push(formname.elements[spareboxes[j]].value);
22665: }
22666: }
22667: }
22668: for (var i=0; i<types.length; i++) {
22669: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22670: var selIdx = newSpare.selectedIndex;
22671: var currnew = newSpare.options[selIdx].value;
22672: var okSpares = new Array();
22673: for (var j=0; j<newSpare.options.length; j++) {
22674: var possible = newSpare.options[j].value;
22675: if (possible != '') {
22676: if (exclude.indexOf(possible) == -1) {
22677: okSpares.push(possible);
22678: } else {
22679: if (currnew == possible) {
22680: selIdx = 0;
22681: }
22682: }
22683: }
22684: }
22685: for (var k=0; k<include.length; k++) {
22686: if (okSpares.indexOf(include[k]) == -1) {
22687: okSpares.push(include[k]);
22688: }
22689: }
22690: okSpares.sort();
22691: newSpare.options.length = 0;
22692: if (selIdx == 0) {
22693: newSpare.options[0] = new Option("$select","",true,true);
22694: } else {
22695: newSpare.options[0] = new Option("$select","",false,false);
22696: }
22697: for (var m=0; m<okSpares.length; m++) {
22698: var idx = m+1;
22699: var selThis = 0;
22700: if (selIdx != 0) {
22701: if (okSpares[m] == currnew) {
22702: selThis = 1;
22703: }
22704: }
22705: if (selThis == 1) {
22706: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22707: } else {
22708: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22709: }
22710: }
22711: }
22712: return;
22713: }
22714:
22715: function checkNewSpares(lonhost,type) {
22716: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22717: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22718: if (chosen != '') {
1.152 raeburn 22719: var othertype;
22720: var othernewSpare;
22721: if (type == 'primary') {
22722: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22723: }
22724: if (type == 'default') {
22725: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22726: }
22727: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22728: othernewSpare.selectedIndex = 0;
22729: }
22730: }
22731: return;
22732: }
22733:
22734: // ]]>
22735: </script>
22736:
22737: END
22738:
22739: }
22740:
22741: sub common_domprefs_js {
22742: return <<"END";
22743:
22744: <script type="text/javascript">
22745: // <![CDATA[
22746:
1.150 raeburn 22747: function getIndicesByName(formname,item) {
1.152 raeburn 22748: var group = new Array();
1.150 raeburn 22749: for (var i=0;i<formname.elements.length;i++) {
22750: if (formname.elements[i].name == item) {
1.152 raeburn 22751: group.push(formname.elements[i].id);
1.150 raeburn 22752: }
22753: }
1.152 raeburn 22754: return group;
1.150 raeburn 22755: }
22756:
22757: // ]]>
22758: </script>
22759:
22760: END
1.152 raeburn 22761:
1.150 raeburn 22762: }
22763:
1.165 raeburn 22764: sub recaptcha_js {
22765: my %lt = &captcha_phrases();
22766: return <<"END";
22767:
22768: <script type="text/javascript">
22769: // <![CDATA[
22770:
22771: function updateCaptcha(caller,context) {
22772: var privitem;
22773: var pubitem;
22774: var privtext;
22775: var pubtext;
1.269 raeburn 22776: var versionitem;
22777: var versiontext;
1.165 raeburn 22778: if (document.getElementById(context+'_recaptchapub')) {
22779: pubitem = document.getElementById(context+'_recaptchapub');
22780: } else {
22781: return;
22782: }
22783: if (document.getElementById(context+'_recaptchapriv')) {
22784: privitem = document.getElementById(context+'_recaptchapriv');
22785: } else {
22786: return;
22787: }
22788: if (document.getElementById(context+'_recaptchapubtxt')) {
22789: pubtext = document.getElementById(context+'_recaptchapubtxt');
22790: } else {
22791: return;
22792: }
22793: if (document.getElementById(context+'_recaptchaprivtxt')) {
22794: privtext = document.getElementById(context+'_recaptchaprivtxt');
22795: } else {
22796: return;
22797: }
1.269 raeburn 22798: if (document.getElementById(context+'_recaptchaversion')) {
22799: versionitem = document.getElementById(context+'_recaptchaversion');
22800: } else {
22801: return;
22802: }
22803: if (document.getElementById(context+'_recaptchavertxt')) {
22804: versiontext = document.getElementById(context+'_recaptchavertxt');
22805: } else {
22806: return;
22807: }
1.165 raeburn 22808: if (caller.checked) {
22809: if (caller.value == 'recaptcha') {
22810: pubitem.type = 'text';
22811: privitem.type = 'text';
22812: pubitem.size = '40';
22813: privitem.size = '40';
22814: pubtext.innerHTML = "$lt{'pub'}";
22815: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 22816: versionitem.type = 'text';
22817: versionitem.size = '3';
1.289 raeburn 22818: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 22819: } else {
22820: pubitem.type = 'hidden';
22821: privitem.type = 'hidden';
1.269 raeburn 22822: versionitem.type = 'hidden';
1.165 raeburn 22823: pubtext.innerHTML = '';
22824: privtext.innerHTML = '';
1.269 raeburn 22825: versiontext.innerHTML = '';
1.165 raeburn 22826: }
22827: }
22828: return;
22829: }
22830:
22831: // ]]>
22832: </script>
22833:
22834: END
22835:
22836: }
22837:
1.236 raeburn 22838: sub toggle_display_js {
1.192 raeburn 22839: return <<"END";
22840:
22841: <script type="text/javascript">
22842: // <![CDATA[
22843:
1.236 raeburn 22844: function toggleDisplay(domForm,caller) {
22845: if (document.getElementById(caller)) {
22846: var divitem = document.getElementById(caller);
22847: var optionsElement = domForm.coursecredits;
1.264 raeburn 22848: var checkval = 1;
22849: var dispval = 'block';
1.303 raeburn 22850: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 22851: if (caller == 'emailoptions') {
1.372 raeburn 22852: optionsElement = domForm.cancreate_email;
1.236 raeburn 22853: }
1.257 raeburn 22854: if (caller == 'studentsubmission') {
22855: optionsElement = domForm.postsubmit;
22856: }
1.264 raeburn 22857: if (caller == 'cloneinstcode') {
22858: optionsElement = domForm.canclone;
22859: checkval = 'instcode';
22860: }
1.303 raeburn 22861: if (selfcreateRegExp.test(caller)) {
22862: optionsElement = domForm.elements[caller];
22863: checkval = 'other';
22864: dispval = 'inline'
22865: }
1.236 raeburn 22866: if (optionsElement.length) {
1.192 raeburn 22867: var currval;
1.236 raeburn 22868: for (var i=0; i<optionsElement.length; i++) {
22869: if (optionsElement[i].checked) {
22870: currval = optionsElement[i].value;
1.192 raeburn 22871: }
22872: }
1.264 raeburn 22873: if (currval == checkval) {
22874: divitem.style.display = dispval;
1.192 raeburn 22875: } else {
1.236 raeburn 22876: divitem.style.display = 'none';
1.192 raeburn 22877: }
22878: }
22879: }
22880: return;
22881: }
22882:
22883: // ]]>
22884: </script>
22885:
22886: END
22887:
22888: }
22889:
1.165 raeburn 22890: sub captcha_phrases {
22891: return &Apache::lonlocal::texthash (
22892: priv => 'Private key',
22893: pub => 'Public key',
22894: original => 'original (CAPTCHA)',
22895: recaptcha => 'successor (ReCAPTCHA)',
22896: notused => 'unused',
1.289 raeburn 22897: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 22898: );
22899: }
22900:
1.205 raeburn 22901: sub devalidate_remote_domconfs {
1.212 raeburn 22902: my ($dom,$cachekeys) = @_;
22903: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 22904: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22905: my %thismachine;
22906: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 22907: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 22908: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 22909: 'ipaccess','trust');
1.386 raeburn 22910: my %cache_by_lonhost;
22911: if (exists($cachekeys->{'samllanding'})) {
22912: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
22913: my %landing = %{$cachekeys->{'samllanding'}};
22914: my %domservers = &Apache::lonnet::get_servers($dom);
22915: if (keys(%domservers)) {
22916: foreach my $server (keys(%domservers)) {
22917: my @cached;
22918: next if ($thismachine{$server});
22919: if ($landing{$server}) {
22920: push(@cached,&escape('samllanding').':'.&escape($server));
22921: }
22922: if (@cached) {
22923: $cache_by_lonhost{$server} = \@cached;
22924: }
22925: }
22926: }
22927: }
22928: }
1.260 raeburn 22929: if (keys(%servers)) {
1.205 raeburn 22930: foreach my $server (keys(%servers)) {
22931: next if ($thismachine{$server});
1.212 raeburn 22932: my @cached;
22933: foreach my $name (@posscached) {
22934: if ($cachekeys->{$name}) {
1.388 raeburn 22935: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 22936: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 22937: foreach my $key (keys(%{$cachekeys->{$name}})) {
22938: push(@cached,&escape($name).':'.&escape($key));
22939: }
22940: }
22941: } else {
22942: push(@cached,&escape($name).':'.&escape($dom));
22943: }
1.212 raeburn 22944: }
22945: }
1.386 raeburn 22946: if ((exists($cache_by_lonhost{$server})) &&
22947: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
22948: push(@cached,@{$cache_by_lonhost{$server}});
22949: }
1.212 raeburn 22950: if (@cached) {
22951: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
22952: }
1.205 raeburn 22953: }
22954: }
22955: return;
22956: }
22957:
1.3 raeburn 22958: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>