Annotation of loncom/interface/domainprefs.pm, revision 1.413
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.413 ! raeburn 4: # $Id: domainprefs.pm,v 1.412 2022/08/24 20:58:50 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.1 raeburn 180:
1.155 raeburn 181: my $registered_cleanup;
182: my $modified_urls;
183:
1.1 raeburn 184: sub handler {
185: my $r=shift;
186: if ($r->header_only) {
187: &Apache::loncommon::content_type($r,'text/html');
188: $r->send_http_header;
189: return OK;
190: }
191:
1.91 raeburn 192: my $context = 'domain';
1.1 raeburn 193: my $dom = $env{'request.role.domain'};
1.5 albertel 194: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 195: if (&Apache::lonnet::allowed('mau',$dom)) {
196: &Apache::loncommon::content_type($r,'text/html');
197: $r->send_http_header;
198: } else {
199: $env{'user.error.msg'}=
200: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
201: return HTTP_NOT_ACCEPTABLE;
202: }
1.155 raeburn 203:
204: $registered_cleanup=0;
205: @{$modified_urls}=();
206:
1.1 raeburn 207: &Apache::lonhtmlcommon::clear_breadcrumbs();
208: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 209: ['phase','actions']);
1.30 raeburn 210: my $phase = 'pickactions';
1.3 raeburn 211: if ( exists($env{'form.phase'}) ) {
212: $phase = $env{'form.phase'};
213: }
1.150 raeburn 214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 215: my %domconfig =
1.6 raeburn 216: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 217: 'quotas','autoenroll','autoupdate','autocreate',
218: 'directorysrch','usercreation','usermodification',
219: 'contacts','defaults','scantron','coursecategories',
220: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 221: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 222: 'requestauthor','selfenrollment','inststatus',
1.405 raeburn 223: 'ltitools','ssl','trust','lti','ltisec','privacy','passwords',
1.394 raeburn 224: 'proctoring','wafproxy','ipaccess'],$dom);
1.320 raeburn 225: my %encconfig =
1.405 raeburn 226: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.297 raeburn 227: if (ref($domconfig{'ltitools'}) eq 'HASH') {
228: if (ref($encconfig{'ltitools'}) eq 'HASH') {
229: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 230: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
231: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 232: foreach my $item ('key','secret') {
233: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
234: }
235: }
236: }
237: }
238: }
1.320 raeburn 239: if (ref($domconfig{'lti'}) eq 'HASH') {
240: if (ref($encconfig{'lti'}) eq 'HASH') {
241: foreach my $id (keys(%{$domconfig{'lti'}})) {
242: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
243: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
244: foreach my $item ('key','secret') {
245: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
246: }
247: }
248: }
249: }
250: }
1.405 raeburn 251: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 252: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 253: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 254: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
255: unless ($id =~ /^\d+$/) {
256: delete($domconfig{'ltisec'}{'linkprot'}{$id});
257: }
258: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 259: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
260: foreach my $item ('key','secret') {
1.406 raeburn 261: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 262: }
263: }
264: }
265: }
266: }
267: }
1.372 raeburn 268: if (ref($domconfig{'proctoring'}) eq 'HASH') {
269: if (ref($encconfig{'proctoring'}) eq 'HASH') {
270: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
271: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
272: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
273: foreach my $item ('key','secret') {
274: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
275: }
276: }
277: }
278: }
279: }
1.394 raeburn 280: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
281: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 282: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 283: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 284: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 285: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
286: 'trust','lti');
1.171 raeburn 287: my %existing;
288: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
289: %existing = %{$domconfig{'loadbalancing'}};
290: }
291: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 292: push(@prefs_order,'loadbalancing');
293: }
1.30 raeburn 294: my %prefs = (
295: 'rolecolors' =>
296: { text => 'Default color schemes',
1.67 raeburn 297: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 298: header => [{col1 => 'Student Settings',
299: col2 => '',},
300: {col1 => 'Coordinator Settings',
301: col2 => '',},
302: {col1 => 'Author Settings',
303: col2 => '',},
304: {col1 => 'Administrator Settings',
305: col2 => '',}],
1.230 raeburn 306: print => \&print_rolecolors,
307: modify => \&modify_rolecolors,
1.30 raeburn 308: },
1.110 raeburn 309: 'login' =>
1.30 raeburn 310: { text => 'Log-in page options',
1.67 raeburn 311: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 312: header => [{col1 => 'Log-in Page Items',
313: col2 => '',},
314: {col1 => 'Log-in Help',
1.256 raeburn 315: col2 => 'Value'},
316: {col1 => 'Custom HTML in document head',
1.386 raeburn 317: col2 => 'Value'},
318: {col1 => 'SSO',
319: col2 => 'Dual login: SSO and non-SSO options'},
320: ],
1.230 raeburn 321: print => \&print_login,
322: modify => \&modify_login,
1.30 raeburn 323: },
1.43 raeburn 324: 'defaults' =>
1.236 raeburn 325: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 326: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 327: header => [{col1 => 'Setting',
1.236 raeburn 328: col2 => 'Value'},
329: {col1 => 'Institutional user types',
1.409 raeburn 330: col2 => 'Name displayed'},
331: {col1 => 'Mapping for missing usernames via standard log-in',
332: col2 => 'Rules in use'}],
1.230 raeburn 333: print => \&print_defaults,
334: modify => \&modify_defaults,
1.43 raeburn 335: },
1.381 raeburn 336: 'wafproxy' =>
337: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 338: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 339: header => [{col1 => 'Domain(s)',
340: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 341: },
1.381 raeburn 342: {col1 => 'Domain(s)',
343: col2 => 'WAF Configuration',}],
1.373 raeburn 344: print => \&print_wafproxy,
1.381 raeburn 345: modify => \&modify_wafproxy,
1.373 raeburn 346: },
1.354 raeburn 347: 'passwords' =>
348: { text => 'Passwords (Internal authentication)',
349: help => 'Domain_Configuration_Passwords',
350: header => [{col1 => 'Resetting Forgotten Password',
351: col2 => 'Settings'},
352: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
353: col2 => 'Settings'},
354: {col1 => 'Rules for LON-CAPA Passwords',
355: col2 => 'Settings'},
356: {col1 => 'Course Owner Changing Student Passwords',
357: col2 => 'Settings'}],
358: print => \&print_passwords,
359: modify => \&modify_passwords,
360: },
1.30 raeburn 361: 'quotas' =>
1.413 ! raeburn 362: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 363: help => 'Domain_Configuration_Quotas',
1.77 raeburn 364: header => [{col1 => 'User affiliation',
1.72 raeburn 365: col2 => 'Available tools',
1.213 raeburn 366: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 367: print => \&print_quotas,
368: modify => \&modify_quotas,
1.30 raeburn 369: },
370: 'autoenroll' =>
371: { text => 'Auto-enrollment settings',
1.67 raeburn 372: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 373: header => [{col1 => 'Configuration setting',
374: col2 => 'Value(s)'}],
1.230 raeburn 375: print => \&print_autoenroll,
376: modify => \&modify_autoenroll,
1.30 raeburn 377: },
378: 'autoupdate' =>
379: { text => 'Auto-update settings',
1.67 raeburn 380: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 381: header => [{col1 => 'Setting',
382: col2 => 'Value',},
1.131 raeburn 383: {col1 => 'Setting',
384: col2 => 'Affiliation'},
1.43 raeburn 385: {col1 => 'User population',
1.227 bisitz 386: col2 => 'Updatable user data'}],
1.230 raeburn 387: print => \&print_autoupdate,
388: modify => \&modify_autoupdate,
1.30 raeburn 389: },
1.125 raeburn 390: 'autocreate' =>
391: { text => 'Auto-course creation settings',
392: help => 'Domain_Configuration_Auto_Creation',
393: header => [{col1 => 'Configuration Setting',
394: col2 => 'Value',}],
1.230 raeburn 395: print => \&print_autocreate,
396: modify => \&modify_autocreate,
1.125 raeburn 397: },
1.30 raeburn 398: 'directorysrch' =>
1.277 raeburn 399: { text => 'Directory searches',
1.67 raeburn 400: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 401: header => [{col1 => 'Institutional Directory Setting',
402: col2 => 'Value',},
403: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 404: col2 => 'Value',}],
1.230 raeburn 405: print => \&print_directorysrch,
406: modify => \&modify_directorysrch,
1.30 raeburn 407: },
408: 'contacts' =>
1.286 raeburn 409: { text => 'E-mail addresses and helpform',
1.67 raeburn 410: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 411: header => [{col1 => 'Default e-mail addresses',
412: col2 => 'Value',},
413: {col1 => 'Recipient(s) for notifications',
414: col2 => 'Value',},
1.340 raeburn 415: {col1 => 'Nightly status check e-mail',
416: col2 => 'Settings',},
1.286 raeburn 417: {col1 => 'Ask helpdesk form settings',
418: col2 => 'Value',},],
1.230 raeburn 419: print => \&print_contacts,
420: modify => \&modify_contacts,
1.30 raeburn 421: },
422: 'usercreation' =>
423: { text => 'User creation',
1.67 raeburn 424: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 425: header => [{col1 => 'Format rule type',
426: col2 => 'Format rules in force'},
1.34 raeburn 427: {col1 => 'User account creation',
428: col2 => 'Usernames which may be created',},
1.30 raeburn 429: {col1 => 'Context',
1.43 raeburn 430: col2 => 'Assignable authentication types'}],
1.230 raeburn 431: print => \&print_usercreation,
432: modify => \&modify_usercreation,
1.30 raeburn 433: },
1.224 raeburn 434: 'selfcreation' =>
435: { text => 'Users self-creating accounts',
436: help => 'Domain_Configuration_Self_Creation',
437: header => [{col1 => 'Self-creation with institutional username',
438: col2 => 'Enabled?'},
439: {col1 => 'Institutional user type (login/SSO self-creation)',
440: col2 => 'Information user can enter'},
1.303 raeburn 441: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 442: col2 => 'Settings'}],
1.230 raeburn 443: print => \&print_selfcreation,
444: modify => \&modify_selfcreation,
1.224 raeburn 445: },
1.69 raeburn 446: 'usermodification' =>
1.33 raeburn 447: { text => 'User modification',
1.67 raeburn 448: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 449: header => [{col1 => 'Target user has role',
1.227 bisitz 450: col2 => 'User information updatable in author context'},
1.33 raeburn 451: {col1 => 'Target user has role',
1.227 bisitz 452: col2 => 'User information updatable in course context'}],
1.230 raeburn 453: print => \&print_usermodification,
454: modify => \&modify_usermodification,
1.33 raeburn 455: },
1.69 raeburn 456: 'scantron' =>
1.346 raeburn 457: { text => 'Bubblesheet format',
1.67 raeburn 458: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 459: header => [ {col1 => 'Bubblesheet format file',
460: col2 => ''},
461: {col1 => 'Bubblesheet data upload formats',
462: col2 => 'Settings'}],
1.230 raeburn 463: print => \&print_scantron,
464: modify => \&modify_scantron,
1.46 raeburn 465: },
1.86 raeburn 466: 'requestcourses' =>
467: {text => 'Request creation of courses',
468: help => 'Domain_Configuration_Request_Courses',
469: header => [{col1 => 'User affiliation',
1.102 raeburn 470: col2 => 'Availability/Processing of requests',},
471: {col1 => 'Setting',
1.216 raeburn 472: col2 => 'Value'},
473: {col1 => 'Available textbooks',
1.235 raeburn 474: col2 => ''},
1.242 raeburn 475: {col1 => 'Available templates',
476: col2 => ''},
1.235 raeburn 477: {col1 => 'Validation (not official courses)',
478: col2 => 'Value'},],
1.230 raeburn 479: print => \&print_quotas,
480: modify => \&modify_quotas,
1.86 raeburn 481: },
1.163 raeburn 482: 'requestauthor' =>
1.223 bisitz 483: {text => 'Request Authoring Space',
1.163 raeburn 484: help => 'Domain_Configuration_Request_Author',
485: header => [{col1 => 'User affiliation',
486: col2 => 'Availability/Processing of requests',},
487: {col1 => 'Setting',
488: col2 => 'Value'}],
1.230 raeburn 489: print => \&print_quotas,
490: modify => \&modify_quotas,
1.163 raeburn 491: },
1.69 raeburn 492: 'coursecategories' =>
1.120 raeburn 493: { text => 'Cataloging of courses/communities',
1.67 raeburn 494: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 495: header => [{col1 => 'Catalog type/availability',
496: col2 => '',},
497: {col1 => 'Category settings for standard catalog',
1.57 raeburn 498: col2 => '',},
499: {col1 => 'Categories',
500: col2 => '',
501: }],
1.230 raeburn 502: print => \&print_coursecategories,
503: modify => \&modify_coursecategories,
1.69 raeburn 504: },
505: 'serverstatuses' =>
1.77 raeburn 506: {text => 'Access to server status pages',
1.69 raeburn 507: help => 'Domain_Configuration_Server_Status',
508: header => [{col1 => 'Status Page',
509: col2 => 'Other named users',
510: col3 => 'Specific IPs',
511: }],
1.230 raeburn 512: print => \&print_serverstatuses,
513: modify => \&modify_serverstatuses,
1.69 raeburn 514: },
1.118 jms 515: 'helpsettings' =>
1.282 raeburn 516: {text => 'Support settings',
1.118 jms 517: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 518: header => [{col1 => 'Help Page Settings (logged-in users)',
519: col2 => 'Value'},
520: {col1 => 'Helpdesk Roles',
521: col2 => 'Settings'},],
1.230 raeburn 522: print => \&print_helpsettings,
523: modify => \&modify_helpsettings,
1.118 jms 524: },
1.121 raeburn 525: 'coursedefaults' =>
526: {text => 'Course/Community defaults',
527: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 528: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
529: col2 => 'Value',},
530: {col1 => 'Defaults which can be overridden for each course by a DC',
531: col2 => 'Value',},],
1.230 raeburn 532: print => \&print_coursedefaults,
533: modify => \&modify_coursedefaults,
1.121 raeburn 534: },
1.231 raeburn 535: 'selfenrollment' =>
536: {text => 'Self-enrollment in Course/Community',
537: help => 'Domain_Configuration_Selfenrollment',
538: header => [{col1 => 'Configuration Rights',
539: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
540: {col1 => 'Defaults',
541: col2 => 'Value'},
542: {col1 => 'Self-enrollment validation (optional)',
543: col2 => 'Value'},],
544: print => \&print_selfenrollment,
545: modify => \&modify_selfenrollment,
546: },
1.120 raeburn 547: 'privacy' =>
1.357 raeburn 548: {text => 'Availability of User Information',
1.120 raeburn 549: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 550: header => [{col1 => 'Role assigned in different domain',
551: col2 => 'Approval options'},
552: {col1 => 'Role assigned in different domain to user of type',
553: col2 => 'User information available in that domain'},
554: {col1 => "Role assigned in user's domain",
555: col2 => 'Information viewable by privileged user'},
556: {col1 => "Role assigned in user's domain",
557: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 558: print => \&print_privacy,
559: modify => \&modify_privacy,
1.120 raeburn 560: },
1.141 raeburn 561: 'usersessions' =>
1.145 raeburn 562: {text => 'User session hosting/offloading',
1.137 raeburn 563: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 564: header => [{col1 => 'Domain server',
565: col2 => 'Servers to offload sessions to when busy'},
566: {col1 => 'Hosting of users from other domains',
1.137 raeburn 567: col2 => 'Rules'},
568: {col1 => "Hosting domain's own users elsewhere",
569: col2 => 'Rules'}],
1.230 raeburn 570: print => \&print_usersessions,
571: modify => \&modify_usersessions,
1.137 raeburn 572: },
1.279 raeburn 573: 'loadbalancing' =>
1.185 raeburn 574: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 575: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 576: header => [{col1 => 'Balancers',
1.150 raeburn 577: col2 => 'Default destinations',
1.183 bisitz 578: col3 => 'User affiliation',
1.150 raeburn 579: col4 => 'Overrides'},
580: ],
1.230 raeburn 581: print => \&print_loadbalancing,
582: modify => \&modify_loadbalancing,
1.150 raeburn 583: },
1.279 raeburn 584: 'ltitools' =>
1.267 raeburn 585: {text => 'External Tools (LTI)',
1.296 raeburn 586: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 587: header => [{col1 => 'Setting',
588: col2 => 'Value',}],
589: print => \&print_ltitools,
590: modify => \&modify_ltitools,
591: },
1.372 raeburn 592: 'proctoring' =>
593: {text => 'Remote Proctoring Integration',
594: help => 'Domain_Configuration_Proctoring',
595: header => [{col1 => 'Name',
596: col2 => 'Configuration'}],
597: print => \&print_proctoring,
598: modify => \&modify_proctoring,
599: },
1.279 raeburn 600: 'ssl' =>
1.275 raeburn 601: {text => 'LON-CAPA Network (SSL)',
602: help => 'Domain_Configuration_Network_SSL',
603: header => [{col1 => 'Server',
604: col2 => 'Certificate Status'},
605: {col1 => 'Connections to other servers',
606: col2 => 'Rules'},
1.293 raeburn 607: {col1 => 'Connections from other servers',
608: col2 => 'Rules'},
1.275 raeburn 609: {col1 => "Replicating domain's published content",
610: col2 => 'Rules'}],
611: print => \&print_ssl,
612: modify => \&modify_ssl,
613: },
1.279 raeburn 614: 'trust' =>
615: {text => 'Trust Settings',
616: help => 'Domain_Configuration_Trust',
617: header => [{col1 => "Access to this domain's content by others",
618: col2 => 'Rules'},
619: {col1 => "Access to other domain's content by this domain",
620: col2 => 'Rules'},
621: {col1 => "Enrollment in this domain's courses by others",
622: col2 => 'Rules',},
623: {col1 => "Co-author roles in this domain for others",
624: col2 => 'Rules',},
625: {col1 => "Co-author roles for this domain's users elsewhere",
626: col2 => 'Rules',},
627: {col1 => "Domain roles in this domain assignable to others",
628: col2 => 'Rules'},
629: {col1 => "Course catalog for this domain displayed elsewhere",
630: col2 => 'Rules'},
631: {col1 => "Requests for creation of courses in this domain by others",
632: col2 => 'Rules'},
633: {col1 => "Users in other domains can send messages to this domain",
634: col2 => 'Rules'},],
635: print => \&print_trust,
636: modify => \&modify_trust,
637: },
1.320 raeburn 638: 'lti' =>
1.405 raeburn 639: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 640: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 641: header => [{col1 => 'Encryption of shared secrets',
642: col2 => 'Settings'},
643: {col1 => 'Rules for shared secrets',
644: col2 => 'Settings'},
1.406 raeburn 645: {col1 => 'Link Protectors',
1.405 raeburn 646: col2 => 'Settings'},
647: {col1 => 'Consumers',
648: col2 => 'Settings'},],
1.320 raeburn 649: print => \&print_lti,
650: modify => \&modify_lti,
651: },
1.394 raeburn 652: 'ipaccess' =>
653: {text => 'IP-based access control',
654: help => 'Domain_Configuration_IP_Access',
655: header => [{col1 => 'Setting',
656: col2 => 'Value'},],
657: print => \&print_ipaccess,
658: modify => \&modify_ipaccess,
659: },
1.3 raeburn 660: );
1.110 raeburn 661: if (keys(%servers) > 1) {
662: $prefs{'login'} = { text => 'Log-in page options',
663: help => 'Domain_Configuration_Login_Page',
664: header => [{col1 => 'Log-in Service',
665: col2 => 'Server Setting',},
666: {col1 => 'Log-in Page Items',
1.405 raeburn 667: col2 => 'Settings'},
1.168 raeburn 668: {col1 => 'Log-in Help',
1.256 raeburn 669: col2 => 'Value'},
670: {col1 => 'Custom HTML in document head',
1.386 raeburn 671: col2 => 'Value'},
672: {col1 => 'SSO',
673: col2 => 'Dual login: SSO and non-SSO options'},
674: ],
1.230 raeburn 675: print => \&print_login,
676: modify => \&modify_login,
1.110 raeburn 677: };
678: }
1.174 foxr 679:
1.6 raeburn 680: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 681: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 682: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 683: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 684: text=>"Settings to display/modify"});
1.9 raeburn 685: my $confname = $dom.'-domainconfig';
1.174 foxr 686:
1.3 raeburn 687: if ($phase eq 'process') {
1.212 raeburn 688: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
689: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 690: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 691: $r->rflush();
1.212 raeburn 692: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 693: }
1.30 raeburn 694: } elsif ($phase eq 'display') {
1.192 raeburn 695: my $js = &recaptcha_js().
1.236 raeburn 696: &toggle_display_js();
1.171 raeburn 697: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 698: my ($othertitle,$usertypes,$types) =
699: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 700: $js .= &lonbalance_targets_js($dom,$types,\%servers,
701: $domconfig{'loadbalancing'}).
1.170 raeburn 702: &new_spares_js().
703: &common_domprefs_js().
704: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 705: }
1.216 raeburn 706: if (grep(/^requestcourses$/,@actions)) {
707: my $javascript_validations;
708: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
709: $js .= <<END;
710: <script type="text/javascript">
711: $javascript_validations
712: </script>
713: $coursebrowserjs
714: END
1.394 raeburn 715: } elsif (grep(/^ipaccess$/,@actions)) {
716: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 717: }
1.305 raeburn 718: if (grep(/^selfcreation$/,@actions)) {
719: $js .= &selfcreate_javascript();
720: }
1.286 raeburn 721: if (grep(/^contacts$/,@actions)) {
722: $js .= &contacts_javascript();
723: }
1.346 raeburn 724: if (grep(/^scantron$/,@actions)) {
725: $js .= &scantron_javascript();
726: }
1.150 raeburn 727: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 728: } else {
1.180 raeburn 729: # check if domconfig user exists for the domain.
730: my $servadm = $r->dir_config('lonAdmEMail');
731: my ($configuserok,$author_ok,$switchserver) =
732: &config_check($dom,$confname,$servadm);
733: unless ($configuserok eq 'ok') {
1.181 raeburn 734: &Apache::lonconfigsettings::print_header($r,$phase,$context);
735: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 736: $confname).
1.181 raeburn 737: '<br />'
738: );
1.180 raeburn 739: if ($switchserver) {
1.181 raeburn 740: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
741: '<br />'.
742: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
743: '<br />'.
744: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
745: '<br />'.
746: &mt('To do that now, use the following link: [_1]',$switchserver)
747: );
748: } else {
749: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
750: '<br />'.
751: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
752: );
1.180 raeburn 753: }
754: $r->print(&Apache::loncommon::end_page());
755: return OK;
756: }
1.21 raeburn 757: if (keys(%domconfig) == 0) {
758: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 759: my @ids=&Apache::lonnet::current_machine_ids();
760: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 761: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 762: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 763: my $custom_img_count = 0;
764: foreach my $img (@loginimages) {
765: if ($designhash{$dom.'.login.'.$img} ne '') {
766: $custom_img_count ++;
767: }
768: }
769: foreach my $role (@roles) {
770: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
771: $custom_img_count ++;
772: }
773: }
774: if ($custom_img_count > 0) {
1.94 raeburn 775: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 776: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 777: $r->print(
778: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
779: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
780: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
781: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
782: if ($switch_server) {
1.30 raeburn 783: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 784: }
1.91 raeburn 785: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 786: return OK;
787: }
788: }
789: }
1.91 raeburn 790: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 791: }
792: return OK;
793: }
794:
795: sub process_changes {
1.205 raeburn 796: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 797: my %domconfig;
798: if (ref($values) eq 'HASH') {
799: %domconfig = %{$values};
800: }
1.3 raeburn 801: my $output;
802: if ($action eq 'login') {
1.205 raeburn 803: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 804: } elsif ($action eq 'rolecolors') {
1.9 raeburn 805: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 806: $lastactref,%domconfig);
1.3 raeburn 807: } elsif ($action eq 'quotas') {
1.216 raeburn 808: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 809: } elsif ($action eq 'autoenroll') {
1.205 raeburn 810: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 811: } elsif ($action eq 'autoupdate') {
812: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 813: } elsif ($action eq 'autocreate') {
814: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 815: } elsif ($action eq 'directorysrch') {
1.295 raeburn 816: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 817: } elsif ($action eq 'usercreation') {
1.28 raeburn 818: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 819: } elsif ($action eq 'selfcreation') {
1.305 raeburn 820: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 821: } elsif ($action eq 'usermodification') {
822: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 823: } elsif ($action eq 'contacts') {
1.205 raeburn 824: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 825: } elsif ($action eq 'defaults') {
1.212 raeburn 826: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 827: } elsif ($action eq 'scantron') {
1.205 raeburn 828: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 829: } elsif ($action eq 'coursecategories') {
1.239 raeburn 830: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 831: } elsif ($action eq 'serverstatuses') {
832: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 833: } elsif ($action eq 'requestcourses') {
1.216 raeburn 834: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 835: } elsif ($action eq 'requestauthor') {
1.216 raeburn 836: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 837: } elsif ($action eq 'helpsettings') {
1.285 raeburn 838: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 839: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 840: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 841: } elsif ($action eq 'selfenrollment') {
842: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 843: } elsif ($action eq 'usersessions') {
1.212 raeburn 844: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 845: } elsif ($action eq 'loadbalancing') {
846: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 847: } elsif ($action eq 'ltitools') {
848: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 849: } elsif ($action eq 'proctoring') {
850: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 851: } elsif ($action eq 'ssl') {
852: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 853: } elsif ($action eq 'trust') {
854: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 855: } elsif ($action eq 'lti') {
856: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 857: } elsif ($action eq 'privacy') {
858: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 859: } elsif ($action eq 'passwords') {
860: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 861: } elsif ($action eq 'wafproxy') {
862: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 863: } elsif ($action eq 'ipaccess') {
864: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 865: }
866: return $output;
867: }
868:
869: sub print_config_box {
1.9 raeburn 870: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 871: my $rowtotal = 0;
1.49 raeburn 872: my $output;
873: if ($action eq 'coursecategories') {
874: $output = &coursecategories_javascript($settings);
1.236 raeburn 875: } elsif ($action eq 'defaults') {
876: $output = &defaults_javascript($settings);
1.354 raeburn 877: } elsif ($action eq 'passwords') {
1.405 raeburn 878: $output = &passwords_javascript($action);
1.282 raeburn 879: } elsif ($action eq 'helpsettings') {
880: my (%privs,%levelscurrent);
881: my %full=();
882: my %levels=(
883: course => {},
884: domain => {},
885: system => {},
886: );
887: my $context = 'domain';
888: my $crstype = 'Course';
889: my $formname = 'display';
890: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
891: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
892: $output =
893: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
894: \@templateroles);
1.334 raeburn 895: } elsif ($action eq 'ltitools') {
896: $output .= <itools_javascript($settings);
897: } elsif ($action eq 'lti') {
1.405 raeburn 898: $output .= &passwords_javascript('secrets')."\n".
899: <i_javascript($dom,$settings);
1.372 raeburn 900: } elsif ($action eq 'proctoring') {
901: $output .= &proctoring_javascript($settings);
1.381 raeburn 902: } elsif ($action eq 'wafproxy') {
903: $output .= &wafproxy_javascript($dom);
1.385 raeburn 904: } elsif ($action eq 'autoupdate') {
905: $output .= &autoupdate_javascript();
1.399 raeburn 906: } elsif ($action eq 'autoenroll') {
907: $output .= &autoenroll_javascript();
1.386 raeburn 908: } elsif ($action eq 'login') {
909: $output .= &saml_javascript();
1.394 raeburn 910: } elsif ($action eq 'ipaccess') {
911: $output .= &ipaccess_javascript($settings);
1.91 raeburn 912: }
1.236 raeburn 913: $output .=
1.30 raeburn 914: '<table class="LC_nested_outer">
1.3 raeburn 915: <tr>
1.306 raeburn 916: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 917: &mt($item->{text}).' '.
918: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
919: '</tr>';
1.30 raeburn 920: $rowtotal ++;
1.110 raeburn 921: my $numheaders = 1;
922: if (ref($item->{'header'}) eq 'ARRAY') {
923: $numheaders = scalar(@{$item->{'header'}});
924: }
925: if ($numheaders > 1) {
1.64 raeburn 926: my $colspan = '';
1.145 raeburn 927: my $rightcolspan = '';
1.369 raeburn 928: my $leftnobr = '';
1.238 raeburn 929: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 930: ($action eq 'directorysrch') ||
1.386 raeburn 931: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 932: $colspan = ' colspan="2"';
933: }
1.145 raeburn 934: if ($action eq 'usersessions') {
935: $rightcolspan = ' colspan="3"';
936: }
1.369 raeburn 937: if ($action eq 'passwords') {
938: $leftnobr = ' LC_nobreak';
939: }
1.30 raeburn 940: $output .= '
1.3 raeburn 941: <tr>
942: <td>
943: <table class="LC_nested">
944: <tr class="LC_info_row">
1.369 raeburn 945: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 946: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 947: </tr>';
1.69 raeburn 948: $rowtotal ++;
1.230 raeburn 949: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 950: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 951: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 952: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.405 raeburn 953: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') || ($action eq 'lti')) {
1.230 raeburn 954: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 955: } elsif ($action eq 'passwords') {
956: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 957: } elsif ($action eq 'coursecategories') {
1.230 raeburn 958: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 959: } elsif ($action eq 'scantron') {
960: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 961: } elsif ($action eq 'login') {
1.386 raeburn 962: if ($numheaders == 5) {
1.168 raeburn 963: $colspan = ' colspan="2"';
964: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
965: } else {
966: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
967: }
1.230 raeburn 968: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 969: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 970: } elsif ($action eq 'rolecolors') {
1.30 raeburn 971: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 972: }
1.30 raeburn 973: $output .= '
1.6 raeburn 974: </table>
975: </td>
976: </tr>
977: <tr>
978: <td>
979: <table class="LC_nested">
980: <tr class="LC_info_row">
1.230 raeburn 981: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 982: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 983: </tr>';
984: $rowtotal ++;
1.230 raeburn 985: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
986: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 987: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 988: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.405 raeburn 989: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti')) {
1.238 raeburn 990: if ($action eq 'coursecategories') {
991: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
992: $colspan = ' colspan="2"';
1.279 raeburn 993: } elsif ($action eq 'trust') {
994: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 995: } elsif ($action eq 'passwords') {
996: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 997: } else {
998: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
999: }
1.279 raeburn 1000: if ($action eq 'trust') {
1001: $output .= '
1002: </table>
1003: </td>
1004: </tr>';
1005: my @trusthdrs = qw(2 3 4 5 6 7);
1006: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1007: for (my $i=0; $i<@trusthdrs; $i++) {
1008: $output .= '
1009: <tr>
1010: <td>
1011: <table class="LC_nested">
1012: <tr class="LC_info_row">
1013: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1014: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1015: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1016: </table>
1017: </td>
1018: </tr>';
1019: }
1020: $output .= '
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1026: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1027: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1028: } else {
1029: $output .= '
1.63 raeburn 1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">
1037: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1038: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1039: </tr>'."\n";
1.279 raeburn 1040: if ($action eq 'coursecategories') {
1041: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1042: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1043: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1044: if ($action eq 'passwords') {
1045: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1046: } else {
1047: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1048: }
1049: $output .= '
1.340 raeburn 1050: </tr>
1051: </table>
1052: </td>
1053: </tr>
1054: <tr>
1055: <td>
1056: <table class="LC_nested">
1057: <tr class="LC_info_row">
1.369 raeburn 1058: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1059: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1060: if ($action eq 'passwords') {
1061: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1062: } else {
1063: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1064: }
1065: $output .= '
1.340 raeburn 1066: </table>
1067: </td>
1068: </tr>
1069: <tr>';
1.279 raeburn 1070: } else {
1071: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1072: }
1.238 raeburn 1073: }
1.63 raeburn 1074: $rowtotal ++;
1.236 raeburn 1075: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1076: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1077: ($action eq 'wafproxy')) {
1.230 raeburn 1078: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1079: } elsif ($action eq 'scantron') {
1080: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1081: } elsif ($action eq 'ssl') {
1082: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1083: </table>
1084: </td>
1085: </tr>
1086: <tr>
1087: <td>
1088: <table class="LC_nested">
1089: <tr class="LC_info_row">
1090: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1091: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1092: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1093: </table>
1094: </td>
1095: </tr>
1096: <tr>
1097: <td>
1098: <table class="LC_nested">
1099: <tr class="LC_info_row">
1100: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1101: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1102: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1103: } elsif ($action eq 'login') {
1.386 raeburn 1104: if ($numheaders == 5) {
1.168 raeburn 1105: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1106: </table>
1107: </td>
1108: </tr>
1109: <tr>
1110: <td>
1111: <table class="LC_nested">
1112: <tr class="LC_info_row">
1113: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1114: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1115: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1116: $rowtotal ++;
1117: } else {
1118: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1119: }
1.256 raeburn 1120: $output .= '
1121: </table>
1122: </td>
1123: </tr>
1124: <tr>
1125: <td>
1126: <table class="LC_nested">
1127: <tr class="LC_info_row">';
1.386 raeburn 1128: if ($numheaders == 5) {
1.256 raeburn 1129: $output .= '
1130: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1131: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1132: </tr>';
1133: } else {
1134: $output .= '
1135: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1136: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1137: </tr>';
1138: }
1139: $rowtotal ++;
1.386 raeburn 1140: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1141: </table>
1142: </td>
1143: </tr>
1144: <tr>
1145: <td>
1146: <table class="LC_nested">
1147: <tr class="LC_info_row">';
1148: if ($numheaders == 5) {
1149: $output .= '
1150: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1151: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1152: </tr>';
1153: } else {
1154: $output .= '
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1157: </tr>';
1158: }
1159: $rowtotal ++;
1160: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1161: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1162: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1163: $rowtotal ++;
1164: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1165: </table>
1166: </td>
1167: </tr>
1168: <tr>
1169: <td>
1170: <table class="LC_nested">
1171: <tr class="LC_info_row">
1172: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1173: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1174: &textbookcourses_javascript($settings).
1175: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1176: </table>
1177: </td>
1178: </tr>
1179: <tr>
1180: <td>
1181: <table class="LC_nested">
1182: <tr class="LC_info_row">
1183: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1184: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1185: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">
1.306 raeburn 1193: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1194: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1195: </tr>'.
1196: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1197: } elsif ($action eq 'requestauthor') {
1198: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1199: $rowtotal ++;
1.122 jms 1200: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1201: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1202: </table>
1203: </td>
1204: </tr>
1205: <tr>
1206: <td>
1207: <table class="LC_nested">
1208: <tr class="LC_info_row">
1.306 raeburn 1209: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1210: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1211: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1212: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1213: </tr>'.
1.30 raeburn 1214: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1215: </table>
1216: </td>
1217: </tr>
1218: <tr>
1219: <td>
1220: <table class="LC_nested">
1221: <tr class="LC_info_row">
1.59 bisitz 1222: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1223: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1224: </tr>'.
1.30 raeburn 1225: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1226: $rowtotal += 2;
1.6 raeburn 1227: }
1.3 raeburn 1228: } else {
1.30 raeburn 1229: $output .= '
1.3 raeburn 1230: <tr>
1231: <td>
1232: <table class="LC_nested">
1.30 raeburn 1233: <tr class="LC_info_row">';
1.277 raeburn 1234: if ($action eq 'login') {
1.30 raeburn 1235: $output .= '
1.59 bisitz 1236: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1237: } elsif ($action eq 'serverstatuses') {
1238: $output .= '
1.306 raeburn 1239: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1240: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1241:
1.6 raeburn 1242: } else {
1.30 raeburn 1243: $output .= '
1.306 raeburn 1244: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1245: }
1.72 raeburn 1246: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1247: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1248: &mt($item->{'header'}->[0]->{'col2'});
1249: if ($action eq 'serverstatuses') {
1250: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1251: }
1.69 raeburn 1252: } else {
1.306 raeburn 1253: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1254: &mt($item->{'header'}->[0]->{'col2'});
1255: }
1256: $output .= '</td>';
1257: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1258: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1259: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1260: &mt($item->{'header'}->[0]->{'col3'});
1261: } else {
1.306 raeburn 1262: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1263: &mt($item->{'header'}->[0]->{'col3'});
1264: }
1.69 raeburn 1265: if ($action eq 'serverstatuses') {
1266: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1267: }
1268: $output .= '</td>';
1.6 raeburn 1269: }
1.150 raeburn 1270: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1271: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1272: &mt($item->{'header'}->[0]->{'col4'});
1273: }
1.69 raeburn 1274: $output .= '</tr>';
1.48 raeburn 1275: $rowtotal ++;
1.168 raeburn 1276: if ($action eq 'quotas') {
1.86 raeburn 1277: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1278: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1279: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.405 raeburn 1280: ($action eq 'ltitools') || ($action eq 'proctoring') ||
1281: ($action eq 'ipaccess')) {
1.230 raeburn 1282: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1283: }
1.3 raeburn 1284: }
1.30 raeburn 1285: $output .= '
1.3 raeburn 1286: </table>
1287: </td>
1288: </tr>
1.30 raeburn 1289: </table><br />';
1290: return ($output,$rowtotal);
1.1 raeburn 1291: }
1292:
1.3 raeburn 1293: sub print_login {
1.168 raeburn 1294: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1295: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1296: my %choices = &login_choices();
1.386 raeburn 1297: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1298: %lt = &login_file_options();
1299: $switchserver = &check_switchserver($dom,$confname);
1300: }
1.168 raeburn 1301: if ($caller eq 'service') {
1.149 raeburn 1302: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1303: my $choice = $choices{'disallowlogin'};
1304: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1305: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1306: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1307: '<th>'.$choices{'server'}.'</th>'.
1308: '<th>'.$choices{'serverpath'}.'</th>'.
1309: '<th>'.$choices{'custompath'}.'</th>'.
1310: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1311: my %disallowed;
1312: if (ref($settings) eq 'HASH') {
1313: if (ref($settings->{'loginvia'}) eq 'HASH') {
1314: %disallowed = %{$settings->{'loginvia'}};
1315: }
1316: }
1317: foreach my $lonhost (sort(keys(%servers))) {
1318: my $direct = 'selected="selected"';
1.128 raeburn 1319: if (ref($disallowed{$lonhost}) eq 'HASH') {
1320: if ($disallowed{$lonhost}{'server'} ne '') {
1321: $direct = '';
1322: }
1.110 raeburn 1323: }
1.115 raeburn 1324: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1325: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1326: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1327: '</option>';
1.184 raeburn 1328: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1329: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1330: my $selected = '';
1.128 raeburn 1331: if (ref($disallowed{$lonhost}) eq 'HASH') {
1332: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1333: $selected = 'selected="selected"';
1334: }
1.110 raeburn 1335: }
1336: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1337: $servers{$hostid}.'</option>';
1338: }
1.128 raeburn 1339: $datatable .= '</select></td>'.
1340: '<td><select name="'.$lonhost.'_serverpath">';
1341: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1342: my $pathname = $path;
1343: if ($path eq 'custom') {
1344: $pathname = &mt('Custom Path').' ->';
1345: }
1346: my $selected = '';
1347: if (ref($disallowed{$lonhost}) eq 'HASH') {
1348: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1349: $selected = 'selected="selected"';
1350: }
1351: } elsif ($path eq '') {
1352: $selected = 'selected="selected"';
1353: }
1354: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1355: }
1356: $datatable .= '</select></td>';
1357: my ($custom,$exempt);
1358: if (ref($disallowed{$lonhost}) eq 'HASH') {
1359: $custom = $disallowed{$lonhost}{'custompath'};
1360: $exempt = $disallowed{$lonhost}{'exempt'};
1361: }
1362: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1363: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1364: '</tr>';
1.110 raeburn 1365: }
1366: $datatable .= '</table></td></tr>';
1367: return $datatable;
1.168 raeburn 1368: } elsif ($caller eq 'page') {
1369: my %defaultchecked = (
1370: 'coursecatalog' => 'on',
1.188 raeburn 1371: 'helpdesk' => 'on',
1.168 raeburn 1372: 'adminmail' => 'off',
1373: 'newuser' => 'off',
1374: );
1.188 raeburn 1375: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1376: my (%checkedon,%checkedoff);
1.42 raeburn 1377: foreach my $item (@toggles) {
1.168 raeburn 1378: if ($defaultchecked{$item} eq 'on') {
1379: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1380: $checkedoff{$item} = ' ';
1.168 raeburn 1381: } elsif ($defaultchecked{$item} eq 'off') {
1382: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1383: $checkedon{$item} = ' ';
1384: }
1.1 raeburn 1385: }
1.168 raeburn 1386: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1387: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1388: my @logintext = ('textcol','bgcol');
1389: my @bgs = ('pgbg','mainbg','sidebg');
1390: my @links = ('link','alink','vlink');
1391: my %designhash = &Apache::loncommon::get_domainconf($dom);
1392: my %defaultdesign = %Apache::loncommon::defaultdesign;
1393: my (%is_custom,%designs);
1394: my %defaults = (
1395: font => $defaultdesign{'login.font'},
1396: );
1.6 raeburn 1397: foreach my $item (@images) {
1.168 raeburn 1398: $defaults{$item} = $defaultdesign{'login.'.$item};
1399: $defaults{'showlogo'}{$item} = 1;
1400: }
1401: foreach my $item (@bgs) {
1402: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1403: }
1.41 raeburn 1404: foreach my $item (@logintext) {
1.168 raeburn 1405: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1406: }
1.168 raeburn 1407: foreach my $item (@links) {
1408: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1409: }
1.168 raeburn 1410: if (ref($settings) eq 'HASH') {
1411: foreach my $item (@toggles) {
1412: if ($settings->{$item} eq '1') {
1413: $checkedon{$item} = ' checked="checked" ';
1414: $checkedoff{$item} = ' ';
1415: } elsif ($settings->{$item} eq '0') {
1416: $checkedoff{$item} = ' checked="checked" ';
1417: $checkedon{$item} = ' ';
1418: }
1419: }
1420: foreach my $item (@images) {
1421: if (defined($settings->{$item})) {
1422: $designs{$item} = $settings->{$item};
1423: $is_custom{$item} = 1;
1424: }
1425: if (defined($settings->{'showlogo'}{$item})) {
1426: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1427: }
1428: }
1.402 raeburn 1429: foreach my $item (@alttext) {
1430: if (ref($settings->{'alttext'}) eq 'HASH') {
1431: if ($settings->{'alttext'}->{$item} ne '') {
1432: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1433: }
1434: }
1435: }
1.168 raeburn 1436: foreach my $item (@logintext) {
1437: if ($settings->{$item} ne '') {
1438: $designs{'logintext'}{$item} = $settings->{$item};
1439: $is_custom{$item} = 1;
1440: }
1441: }
1442: if ($settings->{'font'} ne '') {
1443: $designs{'font'} = $settings->{'font'};
1444: $is_custom{'font'} = 1;
1445: }
1446: foreach my $item (@bgs) {
1447: if ($settings->{$item} ne '') {
1448: $designs{'bgs'}{$item} = $settings->{$item};
1449: $is_custom{$item} = 1;
1450: }
1451: }
1452: foreach my $item (@links) {
1453: if ($settings->{$item} ne '') {
1454: $designs{'links'}{$item} = $settings->{$item};
1455: $is_custom{$item} = 1;
1456: }
1457: }
1458: } else {
1459: if ($designhash{$dom.'.login.font'} ne '') {
1460: $designs{'font'} = $designhash{$dom.'.login.font'};
1461: $is_custom{'font'} = 1;
1462: }
1463: foreach my $item (@images) {
1464: if ($designhash{$dom.'.login.'.$item} ne '') {
1465: $designs{$item} = $designhash{$dom.'.login.'.$item};
1466: $is_custom{$item} = 1;
1467: }
1468: }
1469: foreach my $item (@bgs) {
1470: if ($designhash{$dom.'.login.'.$item} ne '') {
1471: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1472: $is_custom{$item} = 1;
1473: }
1.6 raeburn 1474: }
1.168 raeburn 1475: foreach my $item (@links) {
1476: if ($designhash{$dom.'.login.'.$item} ne '') {
1477: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1478: $is_custom{$item} = 1;
1479: }
1.6 raeburn 1480: }
1481: }
1.168 raeburn 1482: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1483: logo => 'Institution Logo',
1484: domlogo => 'Domain Logo',
1485: login => 'Login box');
1486: my $itemcount = 1;
1487: foreach my $item (@toggles) {
1488: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1489: $datatable .=
1490: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1491: '</td><td>'.
1492: '<span class="LC_nobreak"><label><input type="radio" name="'.
1493: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1494: '</label> <label><input type="radio" name="'.$item.'"'.
1495: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1496: '</tr>';
1497: $itemcount ++;
1.6 raeburn 1498: }
1.168 raeburn 1499: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1500: $datatable .= '</tr></table></td></tr>';
1501: } elsif ($caller eq 'help') {
1.386 raeburn 1502: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1503: my $itemcount = 1;
1504: $defaulturl = '/adm/loginproblems.html';
1505: $defaulttype = 'default';
1506: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1507: my @currlangs;
1508: if (ref($settings) eq 'HASH') {
1509: if (ref($settings->{'helpurl'}) eq 'HASH') {
1510: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1511: next if ($settings->{'helpurl'}{$key} eq '');
1512: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1513: $type{$key} = 'custom';
1514: unless ($key eq 'nolang') {
1515: push(@currlangs,$key);
1516: }
1517: }
1518: } elsif ($settings->{'helpurl'} ne '') {
1519: $type{'nolang'} = 'custom';
1520: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1521: }
1522: }
1.168 raeburn 1523: foreach my $lang ('nolang',sort(@currlangs)) {
1524: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1525: $datatable .= '<tr'.$css_class.'>';
1526: if ($url{$lang} eq '') {
1527: $url{$lang} = $defaulturl;
1528: }
1529: if ($type{$lang} eq '') {
1530: $type{$lang} = $defaulttype;
1531: }
1532: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1533: if ($lang eq 'nolang') {
1534: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1535: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1536: } else {
1537: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1538: $langchoices{$lang},
1539: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1540: }
1541: $datatable .= '</span></td>'."\n".
1542: '<td class="LC_left_item">';
1543: if ($type{$lang} eq 'custom') {
1544: $datatable .= '<span class="LC_nobreak"><label>'.
1545: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1546: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1547: } else {
1548: $datatable .= $lt{'upl'};
1549: }
1550: $datatable .='<br />';
1551: if ($switchserver) {
1552: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1553: } else {
1554: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1555: }
1.168 raeburn 1556: $datatable .= '</td></tr>';
1557: $itemcount ++;
1.6 raeburn 1558: }
1.168 raeburn 1559: my @addlangs;
1560: foreach my $lang (sort(keys(%langchoices))) {
1561: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1562: push(@addlangs,$lang);
1563: }
1564: if (@addlangs > 0) {
1565: my %toadd;
1566: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1567: $toadd{''} = &mt('Select');
1568: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1569: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1570: &mt('Add log-in help page for a specific language:').' '.
1571: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1572: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1573: if ($switchserver) {
1574: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1575: } else {
1576: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1577: }
1.168 raeburn 1578: $datatable .= '</td></tr>';
1.169 raeburn 1579: $itemcount ++;
1.6 raeburn 1580: }
1.169 raeburn 1581: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1582: } elsif ($caller eq 'headtag') {
1583: my %domservers = &Apache::lonnet::get_servers($dom);
1584: my $choice = $choices{'headtag'};
1585: $css_class = ' class="LC_odd_row"';
1586: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1587: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1588: '<th>'.$choices{'current'}.'</th>'.
1589: '<th>'.$choices{'action'}.'</th>'.
1590: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1591: my (%currurls,%currexempt);
1592: if (ref($settings) eq 'HASH') {
1593: if (ref($settings->{'headtag'}) eq 'HASH') {
1594: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1595: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1596: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1597: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1598: }
1599: }
1600: }
1601: }
1602: foreach my $lonhost (sort(keys(%domservers))) {
1603: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1604: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1605: if ($currurls{$lonhost}) {
1606: $datatable .= '<td class="LC_right_item"><a href="'.
1607: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1608: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1609: '">'.$lt{'curr'}.'</a></td>'.
1610: '<td><span class="LC_nobreak"><label>'.
1611: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1612: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1613: } else {
1614: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1615: }
1616: $datatable .='<br />';
1617: if ($switchserver) {
1618: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1619: } else {
1620: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1621: }
1.330 raeburn 1622: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1623: }
1624: $datatable .= '</table></td></tr>';
1.386 raeburn 1625: } elsif ($caller eq 'saml') {
1626: my %domservers = &Apache::lonnet::get_servers($dom);
1627: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1628: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1629: '<th>'.$choices{'samllanding'}.'</th>'.
1630: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1631: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1632: foreach my $lonhost (keys(%domservers)) {
1633: $samlurl{$lonhost} = '/adm/sso';
1634: $styleon{$lonhost} = 'display:none';
1635: $styleoff{$lonhost} = '';
1636: }
1.411 raeburn 1637: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1638: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1639: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1640: $saml{$lonhost} = 1;
1641: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1642: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1643: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1644: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1645: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1646: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1647: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1648: $styleon{$lonhost} = '';
1649: $styleoff{$lonhost} = 'display:none';
1650: } else {
1651: $styleon{$lonhost} = 'display:none';
1652: $styleoff{$lonhost} = '';
1653: }
1654: }
1655: }
1656: my $itemcount = 1;
1657: foreach my $lonhost (sort(keys(%domservers))) {
1658: my $samlon = ' ';
1659: my $samloff = ' checked="checked" ';
1660: if ($saml{$lonhost}) {
1661: $samlon = $samloff;
1662: $samloff = ' ';
1663: }
1.412 raeburn 1664: my $samlwinon = '';
1665: my $samlwinoff = ' checked="checked"';
1666: if ($samlwindow{$lonhost}) {
1667: $samlwinon = $samlwinoff;
1668: $samlwinoff = '';
1669: }
1.386 raeburn 1670: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1671: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1672: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1673: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1674: &mt('No').'</label>'.(' 'x2).
1675: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1676: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1677: &mt('Yes').'</label></span></td>'.
1678: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1679: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1680: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1681: '<th>'.&mt('Alt Text').'</th></tr>'.
1682: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1683: $samltext{$lonhost}.'" /></td><td>';
1684: if ($samlimg{$lonhost}) {
1685: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1686: '<span class="LC_nobreak"><label>'.
1687: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1688: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1689: } else {
1690: $datatable .= $lt{'upl'};
1691: }
1692: $datatable .='<br />';
1693: if ($switchserver) {
1694: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1695: } else {
1696: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1697: }
1698: $datatable .= '</td>'.
1.412 raeburn 1699: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1700: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1701: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1702: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1703: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1704: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1705: '<tr'.$css_class.'>'.
1706: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1707: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1708: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1709: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1710: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1711: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1712: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1713: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1714: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1715: '</table></td>'.
1716: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1717: $itemcount ++;
1718: }
1719: $datatable .= '</table></td></tr>';
1.1 raeburn 1720: }
1.6 raeburn 1721: return $datatable;
1722: }
1723:
1724: sub login_choices {
1725: my %choices =
1726: &Apache::lonlocal::texthash (
1.116 bisitz 1727: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1728: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1729: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1730: disallowlogin => "Login page requests redirected",
1731: hostid => "Server",
1.128 raeburn 1732: server => "Redirect to:",
1733: serverpath => "Path",
1734: custompath => "Custom",
1735: exempt => "Exempt IP(s)",
1.110 raeburn 1736: directlogin => "No redirect",
1737: newuser => "Link to create a user account",
1738: img => "Header",
1739: logo => "Main Logo",
1740: domlogo => "Domain Logo",
1741: login => "Log-in Header",
1742: textcol => "Text color",
1743: bgcol => "Box color",
1744: bgs => "Background colors",
1745: links => "Link colors",
1746: font => "Font color",
1747: pgbg => "Header",
1748: mainbg => "Page",
1749: sidebg => "Login box",
1750: link => "Link",
1751: alink => "Active link",
1752: vlink => "Visited link",
1.256 raeburn 1753: headtag => "Custom markup",
1754: action => "Action",
1755: current => "Current",
1.386 raeburn 1756: samllanding => "Dual login?",
1757: samloptions => "Options",
1.402 raeburn 1758: alttext => "Alt text",
1.6 raeburn 1759: );
1760: return %choices;
1761: }
1762:
1.386 raeburn 1763: sub login_file_options {
1764: return &Apache::lonlocal::texthash(
1765: del => 'Delete?',
1766: rep => 'Replace:',
1767: upl => 'Upload:',
1768: curr => 'View contents',
1769: default => 'Default',
1770: custom => 'Custom',
1771: none => 'None',
1772: );
1773: }
1774:
1.394 raeburn 1775: sub print_ipaccess {
1776: my ($dom,$settings,$rowtotal) = @_;
1777: my $css_class;
1778: my $itemcount = 0;
1779: my $datatable;
1780: my %ordered;
1781: if (ref($settings) eq 'HASH') {
1782: foreach my $item (keys(%{$settings})) {
1783: if (ref($settings->{$item}) eq 'HASH') {
1784: my $num = $settings->{$item}{'order'};
1785: if ($num eq '') {
1786: $num = scalar(keys(%{$settings}));
1787: }
1788: $ordered{$num} = $item;
1789: }
1790: }
1791: }
1792: my $maxnum = scalar(keys(%ordered));
1793: if (keys(%ordered)) {
1794: my @items = sort { $a <=> $b } keys(%ordered);
1795: for (my $i=0; $i<@items; $i++) {
1796: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1797: my $item = $ordered{$items[$i]};
1798: my ($name,$ipranges,%commblocks,%courses);
1799: if (ref($settings->{$item}) eq 'HASH') {
1800: $name = $settings->{$item}->{'name'};
1801: $ipranges = $settings->{$item}->{'ip'};
1802: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1803: %commblocks = %{$settings->{$item}->{'commblocks'}};
1804: }
1805: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1806: %courses = %{$settings->{$item}->{'courses'}};
1807: }
1808: }
1809: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1810: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1811: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1812: for (my $k=0; $k<=$maxnum; $k++) {
1813: my $vpos = $k+1;
1814: my $selstr;
1815: if ($k == $i) {
1816: $selstr = ' selected="selected" ';
1817: }
1818: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1819: }
1820: $datatable .= '</select>'.(' 'x2).
1821: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1822: &mt('Delete?').'</label></span></td>'.
1823: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1824: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1825: '</td></tr>';
1826: $itemcount ++;
1827: }
1828: }
1829: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1830: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1831: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1832: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1833: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1834: for (my $k=0; $k<$maxnum+1; $k++) {
1835: my $vpos = $k+1;
1836: my $selstr;
1837: if ($k == $maxnum) {
1838: $selstr = ' selected="selected" ';
1839: }
1840: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1841: }
1842: $datatable .= '</select> '."\n".
1843: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1844: '<td colspan="2">'.
1845: &ipaccess_options('add',$itemcount,$dom).
1846: '</td>'."\n".
1847: '</tr>'."\n";
1848: $$rowtotal ++;
1849: return $datatable;
1850: }
1851:
1852: sub ipaccess_options {
1853: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1854: my (%currblocks,%currcourses,$output);
1855: if (ref($blocksref) eq 'HASH') {
1856: %currblocks = %{$blocksref};
1857: }
1858: if (ref($coursesref) eq 'HASH') {
1859: %currcourses = %{$coursesref};
1860: }
1861: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1862: '<span class="LC_nobreak">'.&mt('Name').': '.
1863: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1864: '</span></fieldset>'.
1865: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1866: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1867: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1868: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1869: $ipranges.'</textarea></fieldset>'.
1870: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1871: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1872: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1873: '<table>';
1874: foreach my $cid (sort(keys(%currcourses))) {
1875: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1876: $output .= '<tr><td><span class="LC_nobreak">'.
1877: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1878: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1879: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1880: }
1881: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1882: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1883: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1884: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1885: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1886: '</span></td></tr></table>'."\n".
1887: '</fieldset>';
1888: return $output;
1889: }
1890:
1891: sub blocker_checkboxes {
1892: my ($num,$blocks) = @_;
1893: my ($typeorder,$types) = &commblocktype_text();
1894: my $numinrow = 6;
1895: my $output = '<table>';
1896: for (my $i=0; $i<@{$typeorder}; $i++) {
1897: my $block = $typeorder->[$i];
1898: my $blockstatus;
1899: if (ref($blocks) eq 'HASH') {
1900: if ($blocks->{$block} eq 'on') {
1901: $blockstatus = 'checked="checked"';
1902: }
1903: }
1904: my $rem = $i%($numinrow);
1905: if ($rem == 0) {
1906: if ($i > 0) {
1907: $output .= '</tr>';
1908: }
1909: $output .= '<tr>';
1910: }
1911: if ($i == scalar(@{$typeorder})-1) {
1912: my $colsleft = $numinrow-$rem;
1913: if ($colsleft > 1) {
1914: $output .= '<td colspan="'.$colsleft.'">';
1915: } else {
1916: $output .= '<td>';
1917: }
1918: } else {
1919: $output .= '<td>';
1920: }
1921: my $item = 'ipaccess_block_'.$num;
1922: if ($blockstatus) {
1923: $blockstatus = ' '.$blockstatus;
1924: }
1925: $output .= '<span class="LC_nobreak"><label>'."\n".
1926: '<input type="checkbox" name="'.$item.'"'.
1927: $blockstatus.' value="'.$block.'"'.' />'.
1928: $types->{$block}.'</label></span>'."\n".
1929: '<br /></td>';
1930: }
1931: $output .= '</tr></table>';
1932: return $output;
1933: }
1934:
1935: sub commblocktype_text {
1936: my %types = &Apache::lonlocal::texthash(
1937: 'com' => 'Messaging',
1938: 'chat' => 'Chat Room',
1939: 'boards' => 'Discussion',
1940: 'port' => 'Portfolio',
1941: 'groups' => 'Groups',
1942: 'blogs' => 'Blogs',
1943: 'about' => 'User Information',
1944: 'printout' => 'Printouts',
1945: 'passwd' => 'Change Password',
1946: 'grades' => 'Gradebook',
1.397 raeburn 1947: 'search' => 'Course search',
1948: 'wishlist' => 'Stored links',
1949: 'annotate' => 'Annotations',
1.394 raeburn 1950: );
1.397 raeburn 1951: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1952: return ($typeorder,\%types);
1953: }
1954:
1.6 raeburn 1955: sub print_rolecolors {
1.30 raeburn 1956: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1957: my %choices = &color_font_choices();
1958: my @bgs = ('pgbg','tabbg','sidebg');
1959: my @links = ('link','alink','vlink');
1960: my @images = ('img');
1961: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1962: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1963: my %defaultdesign = %Apache::loncommon::defaultdesign;
1964: my (%is_custom,%designs);
1.200 raeburn 1965: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1966: if (ref($settings) eq 'HASH') {
1967: if (ref($settings->{$role}) eq 'HASH') {
1968: if ($settings->{$role}->{'img'} ne '') {
1969: $designs{'img'} = $settings->{$role}->{'img'};
1970: $is_custom{'img'} = 1;
1971: }
1972: if ($settings->{$role}->{'font'} ne '') {
1973: $designs{'font'} = $settings->{$role}->{'font'};
1974: $is_custom{'font'} = 1;
1975: }
1.97 tempelho 1976: if ($settings->{$role}->{'fontmenu'} ne '') {
1977: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1978: $is_custom{'fontmenu'} = 1;
1979: }
1.6 raeburn 1980: foreach my $item (@bgs) {
1981: if ($settings->{$role}->{$item} ne '') {
1982: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1983: $is_custom{$item} = 1;
1984: }
1985: }
1986: foreach my $item (@links) {
1987: if ($settings->{$role}->{$item} ne '') {
1988: $designs{'links'}{$item} = $settings->{$role}->{$item};
1989: $is_custom{$item} = 1;
1990: }
1991: }
1992: }
1993: } else {
1994: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1995: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1996: $is_custom{'img'} = 1;
1997: }
1.97 tempelho 1998: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1999: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2000: $is_custom{'fontmenu'} = 1;
2001: }
1.6 raeburn 2002: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2003: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2004: $is_custom{'font'} = 1;
2005: }
2006: foreach my $item (@bgs) {
2007: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2008: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2009: $is_custom{$item} = 1;
2010:
2011: }
2012: }
2013: foreach my $item (@links) {
2014: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2015: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2016: $is_custom{$item} = 1;
2017: }
2018: }
2019: }
2020: my $itemcount = 1;
1.30 raeburn 2021: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2022: $datatable .= '</tr></table></td></tr>';
2023: return $datatable;
2024: }
2025:
1.200 raeburn 2026: sub role_defaults {
2027: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2028: my %defaults;
2029: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2030: return %defaults;
2031: }
2032: my %defaultdesign = %Apache::loncommon::defaultdesign;
2033: if ($role eq 'login') {
2034: %defaults = (
2035: font => $defaultdesign{$role.'.font'},
2036: );
2037: if (ref($logintext) eq 'ARRAY') {
2038: foreach my $item (@{$logintext}) {
2039: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2040: }
2041: }
2042: foreach my $item (@{$images}) {
2043: $defaults{'showlogo'}{$item} = 1;
2044: }
2045: } else {
2046: %defaults = (
2047: img => $defaultdesign{$role.'.img'},
2048: font => $defaultdesign{$role.'.font'},
2049: fontmenu => $defaultdesign{$role.'.fontmenu'},
2050: );
2051: }
2052: foreach my $item (@{$bgs}) {
2053: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2054: }
2055: foreach my $item (@{$links}) {
2056: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2057: }
2058: foreach my $item (@{$images}) {
2059: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2060: }
2061: return %defaults;
2062: }
2063:
1.6 raeburn 2064: sub display_color_options {
1.9 raeburn 2065: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2066: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2067: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2068: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2069: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2070: '<td>'.$choices->{'font'}.'</td>';
2071: if (!$is_custom->{'font'}) {
1.329 raeburn 2072: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2073: } else {
2074: $datatable .= '<td> </td>';
2075: }
1.174 foxr 2076: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2077:
1.8 raeburn 2078: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2079: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2080: ' value="'.$current_color.'" /> '.
1.329 raeburn 2081: ' </span></td></tr>';
1.107 raeburn 2082: unless ($role eq 'login') {
2083: $datatable .= '<tr'.$css_class.'>'.
2084: '<td>'.$choices->{'fontmenu'}.'</td>';
2085: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2086: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2087: } else {
2088: $datatable .= '<td> </td>';
2089: }
1.202 raeburn 2090: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2091: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2092: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2093: '<input class="colorchooser" type="text" size="10" name="'
2094: .$role.'_fontmenu"'.
2095: ' value="'.$current_color.'" /> '.
1.329 raeburn 2096: ' </span></td></tr>';
1.97 tempelho 2097: }
1.9 raeburn 2098: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2099: foreach my $img (@{$images}) {
1.18 albertel 2100: $itemcount ++;
1.6 raeburn 2101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2102: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2103: '<td>'.$choices->{$img};
1.402 raeburn 2104: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2105: if ($role eq 'login') {
2106: if ($img eq 'login') {
2107: $login_hdr_pick =
1.135 bisitz 2108: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2109: $logincolors =
2110: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2111: $designs,$defaults);
1.402 raeburn 2112: } else {
2113: if ($img ne 'domlogo') {
2114: $datatable.= &logo_display_options($img,$defaults,$designs);
2115: }
2116: if (ref($designs->{'alttext'}) eq 'HASH') {
2117: $alttext = $designs->{'alttext'}{$img};
2118: }
1.70 raeburn 2119: }
2120: }
2121: $datatable .= '</td>';
1.6 raeburn 2122: if ($designs->{$img} ne '') {
2123: $imgfile = $designs->{$img};
1.18 albertel 2124: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2125: } else {
2126: $imgfile = $defaults->{$img};
2127: }
2128: if ($imgfile) {
1.9 raeburn 2129: my ($showfile,$fullsize);
2130: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2131: my $urldir = $1;
2132: my $filename = $2;
2133: my @info = &Apache::lonnet::stat_file($designs->{$img});
2134: if (@info) {
2135: my $thumbfile = 'tn-'.$filename;
2136: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2137: if (@thumb) {
2138: $showfile = $urldir.'/'.$thumbfile;
2139: } else {
2140: $showfile = $imgfile;
2141: }
2142: } else {
2143: $showfile = '';
2144: }
2145: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2146: $showfile = $imgfile;
1.6 raeburn 2147: my $imgdir = $1;
2148: my $filename = $2;
1.159 raeburn 2149: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2150: $showfile = "/$imgdir/tn-".$filename;
2151: } else {
1.159 raeburn 2152: my $input = $londocroot.$imgfile;
2153: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2154: if (!-e $output) {
1.9 raeburn 2155: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2156: my ($fullwidth,$fullheight) = &check_dimensions($input);
2157: if ($fullwidth ne '' && $fullheight ne '') {
2158: if ($fullwidth > $width && $fullheight > $height) {
2159: my $size = $width.'x'.$height;
1.316 raeburn 2160: my @args = ('convert','-sample',$size,$input,$output);
2161: system({$args[0]} @args);
1.159 raeburn 2162: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2163: }
2164: }
1.6 raeburn 2165: }
2166: }
1.16 raeburn 2167: }
1.6 raeburn 2168: if ($showfile) {
1.40 raeburn 2169: if ($showfile =~ m{^/(adm|res)/}) {
2170: if ($showfile =~ m{^/res/}) {
2171: my $local_showfile =
2172: &Apache::lonnet::filelocation('',$showfile);
2173: &Apache::lonnet::repcopy($local_showfile);
2174: }
2175: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2176: }
2177: if ($imgfile) {
2178: if ($imgfile =~ m{^/(adm|res)/}) {
2179: if ($imgfile =~ m{^/res/}) {
2180: my $local_imgfile =
2181: &Apache::lonnet::filelocation('',$imgfile);
2182: &Apache::lonnet::repcopy($local_imgfile);
2183: }
2184: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2185: } else {
2186: $fullsize = $imgfile;
2187: }
2188: }
1.41 raeburn 2189: $datatable .= '<td>';
2190: if ($img eq 'login') {
1.135 bisitz 2191: $datatable .= $login_hdr_pick;
2192: }
1.41 raeburn 2193: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2194: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2195: } else {
1.201 raeburn 2196: $datatable .= '<td> </td><td class="LC_left_item">'.
2197: &mt('Upload:').'<br />';
1.6 raeburn 2198: }
2199: } else {
1.201 raeburn 2200: $datatable .= '<td> </td><td class="LC_left_item">'.
2201: &mt('Upload:').'<br />';
1.6 raeburn 2202: }
1.9 raeburn 2203: if ($switchserver) {
2204: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2205: } else {
1.135 bisitz 2206: if ($img ne 'login') { # suppress file selection for Log-in header
2207: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2208: }
1.9 raeburn 2209: }
1.402 raeburn 2210: if (($role eq 'login') && ($img ne 'login')) {
2211: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2212: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2213: '</label></span>';
2214: }
1.9 raeburn 2215: $datatable .= '</td></tr>';
1.6 raeburn 2216: }
2217: $itemcount ++;
2218: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2219: $datatable .= '<tr'.$css_class.'>'.
2220: '<td>'.$choices->{'bgs'}.'</td>';
2221: my $bgs_def;
2222: foreach my $item (@{$bgs}) {
2223: if (!$is_custom->{$item}) {
1.329 raeburn 2224: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2225: }
2226: }
2227: if ($bgs_def) {
1.8 raeburn 2228: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2229: } else {
2230: $datatable .= '<td> </td>';
2231: }
2232: $datatable .= '<td class="LC_right_item">'.
2233: '<table border="0"><tr>';
1.174 foxr 2234:
1.6 raeburn 2235: foreach my $item (@{$bgs}) {
1.306 raeburn 2236: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2237: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2238: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2239: $datatable .= ' ';
1.6 raeburn 2240: }
1.174 foxr 2241: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2242: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2243: }
2244: $datatable .= '</tr></table></td></tr>';
2245: $itemcount ++;
2246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2247: $datatable .= '<tr'.$css_class.'>'.
2248: '<td>'.$choices->{'links'}.'</td>';
2249: my $links_def;
2250: foreach my $item (@{$links}) {
2251: if (!$is_custom->{$item}) {
1.329 raeburn 2252: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2253: }
2254: }
2255: if ($links_def) {
1.8 raeburn 2256: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2257: } else {
2258: $datatable .= '<td> </td>';
2259: }
2260: $datatable .= '<td class="LC_right_item">'.
2261: '<table border="0"><tr>';
2262: foreach my $item (@{$links}) {
1.234 raeburn 2263: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2264: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2265: if ($designs->{'links'}{$item}) {
1.174 foxr 2266: $datatable.=' ';
1.6 raeburn 2267: }
1.174 foxr 2268: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2269: '" /></td>';
2270: }
1.30 raeburn 2271: $$rowtotal += $itemcount;
1.3 raeburn 2272: return $datatable;
2273: }
2274:
1.70 raeburn 2275: sub logo_display_options {
2276: my ($img,$defaults,$designs) = @_;
2277: my $checkedon;
2278: if (ref($defaults) eq 'HASH') {
2279: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2280: if ($defaults->{'showlogo'}{$img}) {
2281: $checkedon = 'checked="checked" ';
2282: }
2283: }
2284: }
2285: if (ref($designs) eq 'HASH') {
2286: if (ref($designs->{'showlogo'}) eq 'HASH') {
2287: if (defined($designs->{'showlogo'}{$img})) {
2288: if ($designs->{'showlogo'}{$img} == 0) {
2289: $checkedon = '';
2290: } elsif ($designs->{'showlogo'}{$img} == 1) {
2291: $checkedon = 'checked="checked" ';
2292: }
2293: }
2294: }
2295: }
2296: return '<br /><label> <input type="checkbox" name="'.
2297: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2298: &mt('show').'</label>'."\n";
2299: }
2300:
1.41 raeburn 2301: sub login_header_options {
1.135 bisitz 2302: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2303: my $output = '';
1.41 raeburn 2304: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2305: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2306: if (!$is_custom->{'textcol'}) {
2307: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2308: ' ';
2309: }
2310: if (!$is_custom->{'bgcol'}) {
2311: $output .= $choices->{'bgcol'}.': '.
2312: '<span id="css_'.$role.'_font" style="background-color: '.
2313: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2314: }
2315: $output .= '<br />';
2316: }
2317: $output .='<br />';
2318: return $output;
2319: }
2320:
2321: sub login_text_colors {
1.201 raeburn 2322: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2323: my $color_menu = '<table border="0"><tr>';
2324: foreach my $item (@{$logintext}) {
1.306 raeburn 2325: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2326: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2327: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2328: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2329: }
2330: $color_menu .= '</tr></table><br />';
2331: return $color_menu;
2332: }
2333:
2334: sub image_changes {
2335: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2336: my $output;
1.135 bisitz 2337: if ($img eq 'login') {
1.331 raeburn 2338: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2339: } elsif (!$is_custom) {
1.70 raeburn 2340: if ($img ne 'domlogo') {
1.331 raeburn 2341: $output = &mt('Default image:').'<br />';
1.41 raeburn 2342: } else {
1.331 raeburn 2343: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2344: }
2345: }
1.331 raeburn 2346: if ($img ne 'login') {
1.135 bisitz 2347: if ($img_import) {
2348: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2349: }
2350: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2351: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2352: if ($is_custom) {
2353: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2354: '<input type="checkbox" name="'.
2355: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2356: '</label> '.&mt('Replace:').'</span><br />';
2357: } else {
1.306 raeburn 2358: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2359: }
1.41 raeburn 2360: }
2361: return $output;
2362: }
2363:
1.3 raeburn 2364: sub print_quotas {
1.86 raeburn 2365: my ($dom,$settings,$rowtotal,$action) = @_;
2366: my $context;
2367: if ($action eq 'quotas') {
2368: $context = 'tools';
2369: } else {
2370: $context = $action;
2371: }
1.197 raeburn 2372: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2374: my $typecount = 0;
1.101 raeburn 2375: my ($css_class,%titles);
1.86 raeburn 2376: if ($context eq 'requestcourses') {
1.325 raeburn 2377: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2378: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2379: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2380: %titles = &courserequest_titles();
1.163 raeburn 2381: } elsif ($context eq 'requestauthor') {
2382: @usertools = ('author');
2383: @options = ('norequest','approval','automatic');
1.210 raeburn 2384: %titles = &authorrequest_titles();
1.86 raeburn 2385: } else {
1.413 ! raeburn 2386: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2387: %titles = &tool_titles();
1.86 raeburn 2388: }
1.26 raeburn 2389: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2390: foreach my $type (@{$types}) {
1.197 raeburn 2391: my ($currdefquota,$currauthorquota);
1.163 raeburn 2392: unless (($context eq 'requestcourses') ||
2393: ($context eq 'requestauthor')) {
1.86 raeburn 2394: if (ref($settings) eq 'HASH') {
2395: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2396: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2397: } else {
2398: $currdefquota = $settings->{$type};
2399: }
1.197 raeburn 2400: if (ref($settings->{authorquota}) eq 'HASH') {
2401: $currauthorquota = $settings->{authorquota}->{$type};
2402: }
1.78 raeburn 2403: }
1.72 raeburn 2404: }
1.3 raeburn 2405: if (defined($usertypes->{$type})) {
2406: $typecount ++;
2407: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2408: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2409: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2410: '<td class="LC_left_item">';
1.101 raeburn 2411: if ($context eq 'requestcourses') {
2412: $datatable .= '<table><tr>';
2413: }
2414: my %cell;
1.72 raeburn 2415: foreach my $item (@usertools) {
1.101 raeburn 2416: if ($context eq 'requestcourses') {
2417: my ($curroption,$currlimit);
2418: if (ref($settings) eq 'HASH') {
2419: if (ref($settings->{$item}) eq 'HASH') {
2420: $curroption = $settings->{$item}->{$type};
2421: if ($curroption =~ /^autolimit=(\d*)$/) {
2422: $currlimit = $1;
2423: }
2424: }
2425: }
2426: if (!$curroption) {
2427: $curroption = 'norequest';
2428: }
2429: $datatable .= '<th>'.$titles{$item}.'</th>';
2430: foreach my $option (@options) {
2431: my $val = $option;
2432: if ($option eq 'norequest') {
2433: $val = 0;
2434: }
2435: if ($option eq 'validate') {
2436: my $canvalidate = 0;
2437: if (ref($validations{$item}) eq 'HASH') {
2438: if ($validations{$item}{$type}) {
2439: $canvalidate = 1;
2440: }
2441: }
2442: next if (!$canvalidate);
2443: }
2444: my $checked = '';
2445: if ($option eq $curroption) {
2446: $checked = ' checked="checked"';
2447: } elsif ($option eq 'autolimit') {
2448: if ($curroption =~ /^autolimit/) {
2449: $checked = ' checked="checked"';
2450: }
2451: }
2452: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2453: '<input type="radio" name="crsreq_'.$item.
2454: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2455: $titles{$option}.'</label>';
1.101 raeburn 2456: if ($option eq 'autolimit') {
1.127 raeburn 2457: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2458: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2459: 'value="'.$currlimit.'" />';
1.101 raeburn 2460: }
1.127 raeburn 2461: $cell{$item} .= '</span> ';
1.103 raeburn 2462: if ($option eq 'autolimit') {
1.127 raeburn 2463: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2464: }
1.101 raeburn 2465: }
1.163 raeburn 2466: } elsif ($context eq 'requestauthor') {
2467: my $curroption;
2468: if (ref($settings) eq 'HASH') {
2469: $curroption = $settings->{$type};
2470: }
2471: if (!$curroption) {
2472: $curroption = 'norequest';
2473: }
2474: foreach my $option (@options) {
2475: my $val = $option;
2476: if ($option eq 'norequest') {
2477: $val = 0;
2478: }
2479: my $checked = '';
2480: if ($option eq $curroption) {
2481: $checked = ' checked="checked"';
2482: }
2483: $datatable .= '<span class="LC_nobreak"><label>'.
2484: '<input type="radio" name="authorreq_'.$type.
2485: '" value="'.$val.'"'.$checked.' />'.
2486: $titles{$option}.'</label></span> ';
2487: }
1.101 raeburn 2488: } else {
2489: my $checked = 'checked="checked" ';
1.413 ! raeburn 2490: if ($item eq 'timezone') {
! 2491: $checked = '';
! 2492: }
1.101 raeburn 2493: if (ref($settings) eq 'HASH') {
2494: if (ref($settings->{$item}) eq 'HASH') {
1.413 ! raeburn 2495: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2496: $checked = '';
2497: } elsif ($settings->{$item}->{$type} == 1) {
2498: $checked = 'checked="checked" ';
2499: }
1.78 raeburn 2500: }
1.72 raeburn 2501: }
1.101 raeburn 2502: $datatable .= '<span class="LC_nobreak"><label>'.
2503: '<input type="checkbox" name="'.$context.'_'.$item.
2504: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2505: '</label></span> ';
1.72 raeburn 2506: }
1.101 raeburn 2507: }
2508: if ($context eq 'requestcourses') {
2509: $datatable .= '</tr><tr>';
2510: foreach my $item (@usertools) {
1.106 raeburn 2511: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2512: }
2513: $datatable .= '</tr></table>';
1.72 raeburn 2514: }
1.86 raeburn 2515: $datatable .= '</td>';
1.163 raeburn 2516: unless (($context eq 'requestcourses') ||
2517: ($context eq 'requestauthor')) {
1.86 raeburn 2518: $datatable .=
1.197 raeburn 2519: '<td class="LC_right_item">'.
2520: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2521: '<input type="text" name="quota_'.$type.
1.72 raeburn 2522: '" value="'.$currdefquota.
1.197 raeburn 2523: '" size="5" /></span>'.(' ' x 2).
2524: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2525: '<input type="text" name="authorquota_'.$type.
2526: '" value="'.$currauthorquota.
2527: '" size="5" /></span></td>';
1.86 raeburn 2528: }
2529: $datatable .= '</tr>';
1.3 raeburn 2530: }
2531: }
2532: }
1.163 raeburn 2533: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2534: $defaultquota = '20';
1.197 raeburn 2535: $authorquota = '500';
1.86 raeburn 2536: if (ref($settings) eq 'HASH') {
2537: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2538: $defaultquota = $settings->{'defaultquota'}->{'default'};
2539: } elsif (defined($settings->{'default'})) {
2540: $defaultquota = $settings->{'default'};
2541: }
1.197 raeburn 2542: if (ref($settings->{'authorquota'}) eq 'HASH') {
2543: $authorquota = $settings->{'authorquota'}->{'default'};
2544: }
1.3 raeburn 2545: }
2546: }
2547: $typecount ++;
2548: $css_class = $typecount%2?' class="LC_odd_row"':'';
2549: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2550: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2551: '<td class="LC_left_item">';
1.101 raeburn 2552: if ($context eq 'requestcourses') {
2553: $datatable .= '<table><tr>';
2554: }
2555: my %defcell;
1.72 raeburn 2556: foreach my $item (@usertools) {
1.101 raeburn 2557: if ($context eq 'requestcourses') {
2558: my ($curroption,$currlimit);
2559: if (ref($settings) eq 'HASH') {
2560: if (ref($settings->{$item}) eq 'HASH') {
2561: $curroption = $settings->{$item}->{'default'};
2562: if ($curroption =~ /^autolimit=(\d*)$/) {
2563: $currlimit = $1;
2564: }
2565: }
2566: }
2567: if (!$curroption) {
2568: $curroption = 'norequest';
2569: }
2570: $datatable .= '<th>'.$titles{$item}.'</th>';
2571: foreach my $option (@options) {
2572: my $val = $option;
2573: if ($option eq 'norequest') {
2574: $val = 0;
2575: }
2576: if ($option eq 'validate') {
2577: my $canvalidate = 0;
2578: if (ref($validations{$item}) eq 'HASH') {
2579: if ($validations{$item}{'default'}) {
2580: $canvalidate = 1;
2581: }
2582: }
2583: next if (!$canvalidate);
2584: }
2585: my $checked = '';
2586: if ($option eq $curroption) {
2587: $checked = ' checked="checked"';
2588: } elsif ($option eq 'autolimit') {
2589: if ($curroption =~ /^autolimit/) {
2590: $checked = ' checked="checked"';
2591: }
2592: }
2593: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2594: '<input type="radio" name="crsreq_'.$item.
2595: '_default" value="'.$val.'"'.$checked.' />'.
2596: $titles{$option}.'</label>';
2597: if ($option eq 'autolimit') {
1.127 raeburn 2598: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2599: $item.'_limit_default" size="1" '.
2600: 'value="'.$currlimit.'" />';
2601: }
1.127 raeburn 2602: $defcell{$item} .= '</span> ';
1.104 raeburn 2603: if ($option eq 'autolimit') {
1.127 raeburn 2604: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2605: }
1.101 raeburn 2606: }
1.163 raeburn 2607: } elsif ($context eq 'requestauthor') {
2608: my $curroption;
2609: if (ref($settings) eq 'HASH') {
1.172 raeburn 2610: $curroption = $settings->{'default'};
1.163 raeburn 2611: }
2612: if (!$curroption) {
2613: $curroption = 'norequest';
2614: }
2615: foreach my $option (@options) {
2616: my $val = $option;
2617: if ($option eq 'norequest') {
2618: $val = 0;
2619: }
2620: my $checked = '';
2621: if ($option eq $curroption) {
2622: $checked = ' checked="checked"';
2623: }
2624: $datatable .= '<span class="LC_nobreak"><label>'.
2625: '<input type="radio" name="authorreq_default"'.
2626: ' value="'.$val.'"'.$checked.' />'.
2627: $titles{$option}.'</label></span> ';
2628: }
1.101 raeburn 2629: } else {
2630: my $checked = 'checked="checked" ';
2631: if (ref($settings) eq 'HASH') {
2632: if (ref($settings->{$item}) eq 'HASH') {
2633: if ($settings->{$item}->{'default'} == 0) {
2634: $checked = '';
2635: } elsif ($settings->{$item}->{'default'} == 1) {
2636: $checked = 'checked="checked" ';
2637: }
1.78 raeburn 2638: }
1.72 raeburn 2639: }
1.101 raeburn 2640: $datatable .= '<span class="LC_nobreak"><label>'.
2641: '<input type="checkbox" name="'.$context.'_'.$item.
2642: '" value="default" '.$checked.'/>'.$titles{$item}.
2643: '</label></span> ';
2644: }
2645: }
2646: if ($context eq 'requestcourses') {
2647: $datatable .= '</tr><tr>';
2648: foreach my $item (@usertools) {
1.106 raeburn 2649: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2650: }
1.101 raeburn 2651: $datatable .= '</tr></table>';
1.72 raeburn 2652: }
1.86 raeburn 2653: $datatable .= '</td>';
1.163 raeburn 2654: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2655: $datatable .= '<td class="LC_right_item">'.
2656: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2657: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2658: $defaultquota.'" size="5" /></span>'.(' ' x2).
2659: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2660: '<input type="text" name="authorquota" value="'.
2661: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2662: }
2663: $datatable .= '</tr>';
1.72 raeburn 2664: $typecount ++;
2665: $css_class = $typecount%2?' class="LC_odd_row"':'';
2666: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2667: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2668: if ($context eq 'requestcourses') {
1.109 raeburn 2669: $datatable .= &mt('(overrides affiliation, if set)').
2670: '</td>'.
2671: '<td class="LC_left_item">'.
2672: '<table><tr>';
1.101 raeburn 2673: } else {
1.109 raeburn 2674: $datatable .= &mt('(overrides affiliation, if checked)').
2675: '</td>'.
2676: '<td class="LC_left_item" colspan="2">'.
2677: '<br />';
1.101 raeburn 2678: }
2679: my %advcell;
1.72 raeburn 2680: foreach my $item (@usertools) {
1.101 raeburn 2681: if ($context eq 'requestcourses') {
2682: my ($curroption,$currlimit);
2683: if (ref($settings) eq 'HASH') {
2684: if (ref($settings->{$item}) eq 'HASH') {
2685: $curroption = $settings->{$item}->{'_LC_adv'};
2686: if ($curroption =~ /^autolimit=(\d*)$/) {
2687: $currlimit = $1;
2688: }
2689: }
2690: }
2691: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2692: my $checked = '';
2693: if ($curroption eq '') {
2694: $checked = ' checked="checked"';
2695: }
2696: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2697: '<input type="radio" name="crsreq_'.$item.
2698: '__LC_adv" value=""'.$checked.' />'.
2699: &mt('No override set').'</label></span> ';
1.101 raeburn 2700: foreach my $option (@options) {
2701: my $val = $option;
2702: if ($option eq 'norequest') {
2703: $val = 0;
2704: }
2705: if ($option eq 'validate') {
2706: my $canvalidate = 0;
2707: if (ref($validations{$item}) eq 'HASH') {
2708: if ($validations{$item}{'_LC_adv'}) {
2709: $canvalidate = 1;
2710: }
2711: }
2712: next if (!$canvalidate);
2713: }
2714: my $checked = '';
1.104 raeburn 2715: if ($val eq $curroption) {
1.101 raeburn 2716: $checked = ' checked="checked"';
2717: } elsif ($option eq 'autolimit') {
2718: if ($curroption =~ /^autolimit/) {
2719: $checked = ' checked="checked"';
2720: }
2721: }
2722: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2723: '<input type="radio" name="crsreq_'.$item.
2724: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2725: $titles{$option}.'</label>';
2726: if ($option eq 'autolimit') {
1.127 raeburn 2727: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2728: $item.'_limit__LC_adv" size="1" '.
2729: 'value="'.$currlimit.'" />';
2730: }
1.127 raeburn 2731: $advcell{$item} .= '</span> ';
1.104 raeburn 2732: if ($option eq 'autolimit') {
1.127 raeburn 2733: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2734: }
1.101 raeburn 2735: }
1.163 raeburn 2736: } elsif ($context eq 'requestauthor') {
2737: my $curroption;
2738: if (ref($settings) eq 'HASH') {
2739: $curroption = $settings->{'_LC_adv'};
2740: }
2741: my $checked = '';
2742: if ($curroption eq '') {
2743: $checked = ' checked="checked"';
2744: }
2745: $datatable .= '<span class="LC_nobreak"><label>'.
2746: '<input type="radio" name="authorreq__LC_adv"'.
2747: ' value=""'.$checked.' />'.
2748: &mt('No override set').'</label></span> ';
2749: foreach my $option (@options) {
2750: my $val = $option;
2751: if ($option eq 'norequest') {
2752: $val = 0;
2753: }
2754: my $checked = '';
2755: if ($val eq $curroption) {
2756: $checked = ' checked="checked"';
2757: }
2758: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2759: '<input type="radio" name="authorreq__LC_adv"'.
2760: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2761: $titles{$option}.'</label></span> ';
2762: }
1.101 raeburn 2763: } else {
2764: my $checked = 'checked="checked" ';
2765: if (ref($settings) eq 'HASH') {
2766: if (ref($settings->{$item}) eq 'HASH') {
2767: if ($settings->{$item}->{'_LC_adv'} == 0) {
2768: $checked = '';
2769: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2770: $checked = 'checked="checked" ';
2771: }
1.79 raeburn 2772: }
1.72 raeburn 2773: }
1.101 raeburn 2774: $datatable .= '<span class="LC_nobreak"><label>'.
2775: '<input type="checkbox" name="'.$context.'_'.$item.
2776: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2777: '</label></span> ';
2778: }
2779: }
2780: if ($context eq 'requestcourses') {
2781: $datatable .= '</tr><tr>';
2782: foreach my $item (@usertools) {
1.106 raeburn 2783: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2784: }
1.101 raeburn 2785: $datatable .= '</tr></table>';
1.72 raeburn 2786: }
1.98 raeburn 2787: $datatable .= '</td></tr>';
1.30 raeburn 2788: $$rowtotal += $typecount;
1.3 raeburn 2789: return $datatable;
2790: }
2791:
1.163 raeburn 2792: sub print_requestmail {
1.305 raeburn 2793: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2794: my ($now,$datatable,%currapp);
1.102 raeburn 2795: $now = time;
2796: if (ref($settings) eq 'HASH') {
2797: if (ref($settings->{'notify'}) eq 'HASH') {
2798: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2799: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2800: }
2801: }
2802: }
1.191 raeburn 2803: my $numinrow = 2;
1.224 raeburn 2804: my $css_class;
1.305 raeburn 2805: if ($$rowtotal%2) {
2806: $css_class = 'LC_odd_row';
2807: }
2808: if ($customcss) {
2809: $css_class .= " $customcss";
2810: }
2811: $css_class =~ s/^\s+//;
2812: if ($css_class) {
2813: $css_class = ' class="'.$css_class.'"';
2814: }
2815: if ($rowstyle) {
2816: $css_class .= ' style="'.$rowstyle.'"';
2817: }
1.163 raeburn 2818: my $text;
2819: if ($action eq 'requestcourses') {
2820: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2821: } elsif ($action eq 'requestauthor') {
2822: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2823: } else {
1.224 raeburn 2824: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2825: }
1.224 raeburn 2826: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2827: ' <td>'.$text.'</td>'.
1.102 raeburn 2828: ' <td class="LC_left_item">';
1.191 raeburn 2829: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2830: $action.'notifyapproval',%currapp);
1.191 raeburn 2831: if ($numdc > 0) {
2832: $datatable .= $table;
1.102 raeburn 2833: } else {
2834: $datatable .= &mt('There are no active Domain Coordinators');
2835: }
2836: $datatable .='</td></tr>';
2837: return $datatable;
2838: }
2839:
1.216 raeburn 2840: sub print_studentcode {
2841: my ($settings,$rowtotal) = @_;
2842: my $rownum = 0;
1.218 raeburn 2843: my ($output,%current);
1.325 raeburn 2844: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2845: if (ref($settings) eq 'HASH') {
2846: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2847: foreach my $type (@crstypes) {
2848: $current{$type} = $settings->{'uniquecode'}{$type};
2849: }
1.218 raeburn 2850: }
2851: }
2852: $output .= '<tr>'.
2853: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2854: '<td class="LC_left_item">';
2855: foreach my $type (@crstypes) {
2856: my $check = ' ';
2857: if ($current{$type}) {
2858: $check = ' checked="checked" ';
2859: }
2860: $output .= '<span class="LC_nobreak"><label>'.
2861: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2862: &mt($type).'</label></span>'.(' 'x2).' ';
2863: }
2864: $output .= '</td></tr>';
2865: $$rowtotal ++;
2866: return $output;
1.216 raeburn 2867: }
2868:
2869: sub print_textbookcourses {
1.242 raeburn 2870: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2871: my $rownum = 0;
2872: my $css_class;
2873: my $itemcount = 1;
2874: my $maxnum = 0;
2875: my $bookshash;
2876: if (ref($settings) eq 'HASH') {
1.242 raeburn 2877: $bookshash = $settings->{$type};
1.216 raeburn 2878: }
2879: my %ordered;
2880: if (ref($bookshash) eq 'HASH') {
2881: foreach my $item (keys(%{$bookshash})) {
2882: if (ref($bookshash->{$item}) eq 'HASH') {
2883: my $num = $bookshash->{$item}{'order'};
2884: $ordered{$num} = $item;
2885: }
2886: }
2887: }
2888: my $confname = $dom.'-domainconfig';
2889: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2890: my $maxnum = scalar(keys(%ordered));
2891: my $datatable;
1.216 raeburn 2892: if (keys(%ordered)) {
2893: my @items = sort { $a <=> $b } keys(%ordered);
2894: for (my $i=0; $i<@items; $i++) {
2895: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2896: my $key = $ordered{$items[$i]};
2897: my %coursehash=&Apache::lonnet::coursedescription($key);
2898: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2899: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2900: if (ref($bookshash->{$key}) eq 'HASH') {
2901: $subject = $bookshash->{$key}->{'subject'};
2902: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2903: if ($type eq 'textbooks') {
1.243 raeburn 2904: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2905: $author = $bookshash->{$key}->{'author'};
2906: $image = $bookshash->{$key}->{'image'};
2907: if ($image ne '') {
2908: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2909: my $imagethumb = "$path/tn-".$imagefile;
2910: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2911: }
1.216 raeburn 2912: }
2913: }
1.242 raeburn 2914: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2915: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2916: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2917: for (my $k=0; $k<=$maxnum; $k++) {
2918: my $vpos = $k+1;
2919: my $selstr;
2920: if ($k == $i) {
2921: $selstr = ' selected="selected" ';
2922: }
2923: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2924: }
2925: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2926: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2927: &mt('Delete?').'</label></span></td>'.
2928: '<td colspan="2">'.
1.242 raeburn 2929: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2930: (' 'x2).
1.242 raeburn 2931: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2932: if ($type eq 'textbooks') {
2933: $datatable .= (' 'x2).
1.243 raeburn 2934: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2935: (' 'x2).
1.242 raeburn 2936: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2937: (' 'x2).
2938: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2939: if ($image) {
1.267 raeburn 2940: $datatable .= $imgsrc.
1.242 raeburn 2941: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2942: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2943: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2944: }
2945: if ($switchserver) {
2946: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2947: } else {
2948: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2949: }
1.216 raeburn 2950: }
1.242 raeburn 2951: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2952: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2953: $coursetitle.'</span></td></tr>'."\n";
2954: $itemcount ++;
2955: }
2956: }
2957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2958: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2959: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2960: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2961: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2962: for (my $k=0; $k<$maxnum+1; $k++) {
2963: my $vpos = $k+1;
2964: my $selstr;
2965: if ($k == $maxnum) {
2966: $selstr = ' selected="selected" ';
2967: }
2968: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2969: }
2970: $datatable .= '</select> '."\n".
1.334 raeburn 2971: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2972: '<td colspan="2">'.
1.242 raeburn 2973: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2974: (' 'x2).
1.242 raeburn 2975: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2976: (' 'x2);
2977: if ($type eq 'textbooks') {
1.243 raeburn 2978: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2979: (' 'x2).
2980: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2981: (' 'x2).
2982: '<span class="LC_nobreak">'.&mt('Image:').' ';
2983: if ($switchserver) {
2984: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2985: } else {
2986: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2987: }
1.334 raeburn 2988: $datatable .= '</span>'."\n";
1.216 raeburn 2989: }
1.334 raeburn 2990: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2991: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2992: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2993: &Apache::loncommon::selectcourse_link
1.334 raeburn 2994: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2995: '</span></td>'."\n".
2996: '</tr>'."\n";
2997: $itemcount ++;
2998: return $datatable;
2999: }
3000:
1.217 raeburn 3001: sub textbookcourses_javascript {
1.242 raeburn 3002: my ($settings) = @_;
3003: return unless(ref($settings) eq 'HASH');
3004: my (%ordered,%total,%jstext);
3005: foreach my $type ('textbooks','templates') {
3006: $total{$type} = 0;
3007: if (ref($settings->{$type}) eq 'HASH') {
3008: foreach my $item (keys(%{$settings->{$type}})) {
3009: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3010: my $num = $settings->{$type}->{$item}{'order'};
3011: $ordered{$type}{$num} = $item;
3012: }
3013: }
3014: $total{$type} = scalar(keys(%{$settings->{$type}}));
3015: }
3016: my @jsarray = ();
3017: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3018: push(@jsarray,$ordered{$type}{$item});
3019: }
3020: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3021: }
3022: return <<"ENDSCRIPT";
3023: <script type="text/javascript">
3024: // <![CDATA[
1.242 raeburn 3025: function reorderBooks(form,item,caller) {
1.217 raeburn 3026: var changedVal;
1.242 raeburn 3027: $jstext{'textbooks'};
3028: $jstext{'templates'};
3029: var newpos;
3030: var maxh;
3031: if (caller == 'textbooks') {
3032: newpos = 'textbooks_addbook_pos';
3033: maxh = 1 + $total{'textbooks'};
3034: } else {
3035: newpos = 'templates_addbook_pos';
3036: maxh = 1 + $total{'templates'};
3037: }
1.217 raeburn 3038: var current = new Array;
3039: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3040: if (item == newpos) {
3041: changedVal = newitemVal;
3042: } else {
3043: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3044: current[newitemVal] = newpos;
3045: }
1.242 raeburn 3046: if (caller == 'textbooks') {
3047: for (var i=0; i<textbooks.length; i++) {
3048: var elementName = 'textbooks_'+textbooks[i];
3049: if (elementName != item) {
3050: if (form.elements[elementName]) {
3051: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3052: current[currVal] = elementName;
3053: }
3054: }
3055: }
3056: }
3057: if (caller == 'templates') {
3058: for (var i=0; i<templates.length; i++) {
3059: var elementName = 'templates_'+templates[i];
3060: if (elementName != item) {
3061: if (form.elements[elementName]) {
3062: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3063: current[currVal] = elementName;
3064: }
1.217 raeburn 3065: }
3066: }
3067: }
3068: var oldVal;
3069: for (var j=0; j<maxh; j++) {
3070: if (current[j] == undefined) {
3071: oldVal = j;
3072: }
3073: }
3074: if (oldVal < changedVal) {
3075: for (var k=oldVal+1; k<=changedVal ; k++) {
3076: var elementName = current[k];
3077: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3078: }
3079: } else {
3080: for (var k=changedVal; k<oldVal; k++) {
3081: var elementName = current[k];
3082: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3083: }
3084: }
3085: return;
3086: }
3087:
3088: // ]]>
3089: </script>
3090:
3091: ENDSCRIPT
3092: }
3093:
1.267 raeburn 3094: sub ltitools_javascript {
3095: my ($settings) = @_;
1.319 raeburn 3096: my $togglejs = <itools_toggle_js();
3097: unless (ref($settings) eq 'HASH') {
3098: return $togglejs;
3099: }
1.267 raeburn 3100: my (%ordered,$total,%jstext);
3101: $total = 0;
3102: foreach my $item (keys(%{$settings})) {
3103: if (ref($settings->{$item}) eq 'HASH') {
3104: my $num = $settings->{$item}{'order'};
3105: $ordered{$num} = $item;
3106: }
3107: }
3108: $total = scalar(keys(%{$settings}));
3109: my @jsarray = ();
3110: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3111: push(@jsarray,$ordered{$item});
3112: }
3113: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3114: return <<"ENDSCRIPT";
3115: <script type="text/javascript">
3116: // <![CDATA[
1.319 raeburn 3117: function reorderLTITools(form,item) {
1.267 raeburn 3118: var changedVal;
3119: $jstext
3120: var newpos = 'ltitools_add_pos';
3121: var maxh = 1 + $total;
3122: var current = new Array;
3123: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3124: if (item == newpos) {
3125: changedVal = newitemVal;
3126: } else {
3127: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3128: current[newitemVal] = newpos;
3129: }
3130: for (var i=0; i<ltitools.length; i++) {
3131: var elementName = 'ltitools_'+ltitools[i];
3132: if (elementName != item) {
3133: if (form.elements[elementName]) {
3134: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3135: current[currVal] = elementName;
3136: }
3137: }
3138: }
3139: var oldVal;
3140: for (var j=0; j<maxh; j++) {
3141: if (current[j] == undefined) {
3142: oldVal = j;
3143: }
3144: }
3145: if (oldVal < changedVal) {
3146: for (var k=oldVal+1; k<=changedVal ; k++) {
3147: var elementName = current[k];
3148: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3149: }
3150: } else {
3151: for (var k=changedVal; k<oldVal; k++) {
3152: var elementName = current[k];
3153: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3154: }
3155: }
3156: return;
3157: }
3158:
3159: // ]]>
3160: </script>
3161:
1.319 raeburn 3162: $togglejs
3163:
3164: ENDSCRIPT
3165: }
3166:
3167: sub ltitools_toggle_js {
3168: return <<"ENDSCRIPT";
3169: <script type="text/javascript">
3170: // <![CDATA[
3171:
3172: function toggleLTITools(form,setting,item) {
3173: var radioname = '';
3174: var divid = '';
3175: if ((setting == 'passback') || (setting == 'roster')) {
3176: radioname = 'ltitools_'+setting+'_'+item;
3177: divid = 'ltitools_'+setting+'time_'+item;
3178: var num = form.elements[radioname].length;
3179: if (num) {
3180: var setvis = '';
3181: for (var i=0; i<num; i++) {
3182: if (form.elements[radioname][i].checked) {
3183: if (form.elements[radioname][i].value == '1') {
3184: if (document.getElementById(divid)) {
3185: document.getElementById(divid).style.display = 'inline-block';
3186: }
3187: setvis = 1;
3188: }
3189: break;
3190: }
3191: }
3192: }
3193: if (!setvis) {
3194: if (document.getElementById(divid)) {
3195: document.getElementById(divid).style.display = 'none';
3196: }
3197: }
3198: }
1.324 raeburn 3199: if (setting == 'user') {
3200: divid = 'ltitools_'+setting+'_div_'+item;
3201: var checkid = 'ltitools_'+setting+'_field_'+item;
3202: if (document.getElementById(divid)) {
3203: if (document.getElementById(checkid)) {
3204: if (document.getElementById(checkid).checked) {
3205: document.getElementById(divid).style.display = 'inline-block';
3206: } else {
3207: document.getElementById(divid).style.display = 'none';
3208: }
3209: }
3210: }
3211: }
1.319 raeburn 3212: return;
3213: }
3214: // ]]>
3215: </script>
3216:
1.267 raeburn 3217: ENDSCRIPT
3218: }
3219:
1.381 raeburn 3220: sub wafproxy_javascript {
3221: my ($dom) = @_;
3222: return <<"ENDSCRIPT";
3223: <script type="text/javascript">
3224: // <![CDATA[
3225: function updateWAF() {
3226: if (document.getElementById('wafproxy_remoteip')) {
3227: var wafremote = 0;
3228: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3229: wafremote = 1;
3230: }
3231: var fields = new Array('header','trust');
3232: for (var i=0; i<fields.length; i++) {
3233: if (document.getElementById('wafproxy_'+fields[i])) {
3234: if (wafremote == 1) {
3235: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3236: }
3237: else {
3238: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3239: }
3240: }
3241: }
3242: if (document.getElementById('wafproxyranges_$dom')) {
3243: if (wafremote == 1) {
3244: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3245: } else {
3246: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3247: if (document.display.wafproxy_vpnaccess[i].checked) {
3248: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3249: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3250: }
3251: }
3252: }
3253: }
3254: }
3255: }
3256: return;
3257: }
3258:
3259: function checkWAF() {
3260: if (document.getElementById('wafproxy_remoteip')) {
3261: var wafvpn = 0;
3262: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3263: if (document.display.wafproxy_vpnaccess[i].checked) {
3264: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3265: wafvpn = 1;
3266: }
3267: break;
3268: }
3269: }
3270: var vpn = new Array('vpnint','vpnext');
3271: for (var i=0; i<vpn.length; i++) {
3272: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3273: if (wafvpn == 1) {
3274: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3275: }
3276: else {
3277: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3278: }
3279: }
3280: }
3281: if (document.getElementById('wafproxyranges_$dom')) {
3282: if (wafvpn == 1) {
3283: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3284: }
3285: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3286: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3287: }
3288: }
3289: }
3290: return;
3291: }
3292:
3293: function toggleWAF() {
3294: if (document.getElementById('wafproxy_table')) {
3295: var wafproxy = 0;
3296: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3297: if (document.display.wafproxy_${dom}[i].checked) {
3298: if (document.display.wafproxy_${dom}[i].value == 1) {
3299: wafproxy = 1;
3300: break;
3301: }
3302: }
3303: }
3304: if (wafproxy == 1) {
3305: document.getElementById('wafproxy_table').style.display='inline';
3306: }
3307: else {
3308: document.getElementById('wafproxy_table').style.display='none';
3309: }
3310: if (document.getElementById('wafproxyrow_${dom}')) {
3311: if (wafproxy == 1) {
3312: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3313: }
3314: else {
3315: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3316: }
3317: }
3318: if (document.getElementById('nowafproxyrow_$dom')) {
3319: if (wafproxy == 1) {
3320: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3321: }
3322: else {
3323: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3324: }
3325: }
3326: }
3327: return;
3328: }
3329: // ]]>
3330: </script>
3331:
3332: ENDSCRIPT
3333: }
3334:
1.372 raeburn 3335: sub proctoring_javascript {
3336: my ($settings) = @_;
3337: my (%ordered,$total,%jstext);
3338: $total = 0;
3339: if (ref($settings) eq 'HASH') {
3340: foreach my $item (keys(%{$settings})) {
3341: if (ref($settings->{$item}) eq 'HASH') {
3342: my $num = $settings->{$item}{'order'};
3343: $ordered{$num} = $item;
3344: }
3345: }
3346: $total = scalar(keys(%{$settings}));
3347: } else {
3348: %ordered = (
3349: 0 => 'proctorio',
3350: 1 => 'examity',
3351: );
3352: $total = 2;
3353: }
3354: my @jsarray = ();
3355: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3356: push(@jsarray,$ordered{$item});
3357: }
3358: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3359: return <<"ENDSCRIPT";
3360: <script type="text/javascript">
3361: // <![CDATA[
3362: function reorderProctoring(form,item) {
3363: var changedVal;
3364: $jstext
3365: var maxh = $total;
3366: var current = new Array;
3367: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3368: for (var i=0; i<proctors.length; i++) {
3369: var elementName = 'proctoring_pos_'+proctors[i];
3370: if (elementName != item) {
3371: if (form.elements[elementName]) {
3372: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3373: current[currVal] = elementName;
3374: }
3375: }
3376: }
3377: var oldVal;
3378: for (var j=0; j<maxh; j++) {
3379: if (current[j] == undefined) {
3380: oldVal = j;
3381: }
3382: }
3383: if (oldVal < changedVal) {
3384: for (var k=oldVal+1; k<=changedVal ; k++) {
3385: var elementName = current[k];
3386: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3387: }
3388: } else {
3389: for (var k=changedVal; k<oldVal; k++) {
3390: var elementName = current[k];
3391: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3392: }
3393: }
3394: return;
3395: }
3396:
3397: function toggleProctoring(form,item) {
3398: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3399: if (fieldsets.length) {
3400: var radioname = 'proctoring_available_'+item;
3401: var num = form.elements[radioname].length;
3402: if (num) {
3403: var setvis = '';
3404: for (var i=0; i<num; i++) {
3405: if (form.elements[radioname][i].checked) {
3406: if (form.elements[radioname][i].value == '1') {
3407: setvis = 1;
3408: break;
3409: }
3410: }
3411: }
3412: for (var j=0; j<fieldsets.length; j++) {
3413: if (setvis) {
3414: fieldsets[j].style.display = 'block';
3415: } else {
3416: fieldsets[j].style.display = 'none';
3417: }
3418: }
3419: }
3420: }
3421: return;
3422: }
3423:
3424: // ]]>
3425: </script>
3426:
3427: ENDSCRIPT
3428: }
3429:
3430:
1.320 raeburn 3431: sub lti_javascript {
1.405 raeburn 3432: my ($dom,$settings) = @_;
3433: my $togglejs = <i_toggle_js($dom);
1.320 raeburn 3434: unless (ref($settings) eq 'HASH') {
3435: return $togglejs;
3436: }
3437: my (%ordered,$total,%jstext);
1.390 raeburn 3438: $total = scalar(keys(%{$settings}));
1.320 raeburn 3439: foreach my $item (keys(%{$settings})) {
3440: if (ref($settings->{$item}) eq 'HASH') {
3441: my $num = $settings->{$item}{'order'};
1.390 raeburn 3442: if ($num eq '') {
3443: $num = $total - 1;
3444: }
1.320 raeburn 3445: $ordered{$num} = $item;
3446: }
3447: }
3448: my @jsarray = ();
3449: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3450: push(@jsarray,$ordered{$item});
3451: }
3452: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
1.406 raeburn 3453: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3454: return <<"ENDSCRIPT";
3455: <script type="text/javascript">
3456: // <![CDATA[
3457: function reorderLTI(form,item) {
3458: var changedVal;
3459: $jstext
3460: var newpos = 'lti_pos_add';
3461: var maxh = 1 + $total;
3462: var current = new Array;
3463: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3464: if (item == newpos) {
3465: changedVal = newitemVal;
3466: } else {
3467: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3468: current[newitemVal] = newpos;
3469: }
3470: for (var i=0; i<lti.length; i++) {
3471: var elementName = 'lti_pos_'+lti[i];
3472: if (elementName != item) {
3473: if (form.elements[elementName]) {
3474: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3475: current[currVal] = elementName;
3476: }
3477: }
3478: }
3479: var oldVal;
3480: for (var j=0; j<maxh; j++) {
3481: if (current[j] == undefined) {
3482: oldVal = j;
3483: }
3484: }
3485: if (oldVal < changedVal) {
3486: for (var k=oldVal+1; k<=changedVal ; k++) {
3487: var elementName = current[k];
3488: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3489: }
3490: } else {
3491: for (var k=changedVal; k<oldVal; k++) {
3492: var elementName = current[k];
3493: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3494: }
3495: }
3496: return;
3497: }
1.406 raeburn 3498:
3499: $linkprot_js
3500:
1.320 raeburn 3501: // ]]>
3502: </script>
3503:
3504: $togglejs
3505:
3506: ENDSCRIPT
3507: }
3508:
3509: sub lti_toggle_js {
1.405 raeburn 3510: my ($dom) = @_;
1.325 raeburn 3511: my %lcauthparmtext = &Apache::lonlocal::texthash (
3512: localauth => 'Local auth argument',
3513: krb => 'Kerberos domain',
3514: );
1.391 raeburn 3515: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3516: &js_escape(\$crsincalert);
1.405 raeburn 3517: my %servers = &Apache::lonnet::get_servers($dom,'library');
3518: my $primary = &Apache::lonnet::domain($dom,'primary');
3519: my $course_servers = "'".join("','",keys(%servers))."'";
3520:
1.320 raeburn 3521: return <<"ENDSCRIPT";
3522: <script type="text/javascript">
3523: // <![CDATA[
3524:
3525: function toggleLTI(form,setting,item) {
1.391 raeburn 3526: if ((setting == 'requser') || (setting == 'crsinc')) {
3527: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3528: var setvis = '';
3529: var radioname = 'lti_requser_'+item;
3530: var num = form.elements[radioname].length;
3531: if (num) {
3532: for (var i=0; i<num; i++) {
3533: if (form.elements[radioname][i].checked) {
3534: if (form.elements[radioname][i].value == '1') {
3535: setvis = 1;
3536: break;
3537: }
3538: }
3539: }
3540: }
3541: if (usrfieldsets.length) {
3542: for (var j=0; j<usrfieldsets.length; j++) {
3543: if (setvis) {
3544: usrfieldsets[j].style.display = 'block';
3545: } else {
3546: usrfieldsets[j].style.display = 'none';
3547: }
3548: }
3549: }
3550: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3551: if (crsfieldsets.length) {
3552: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3553: var num = form.elements[radioname].length;
3554: if (num) {
1.391 raeburn 3555: var crsvis = '';
1.345 raeburn 3556: for (var i=0; i<num; i++) {
3557: if (form.elements[radioname][i].checked) {
3558: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3559: if (setvis == '') {
3560: if (setting == 'crsinc'){
3561: alert("$crsincalert");
3562: form.elements[radioname][0].checked = true;
3563: }
3564: } else {
3565: crsvis = 1;
3566: }
3567: break;
1.345 raeburn 3568: }
3569: }
3570: }
1.391 raeburn 3571: setvis = crsvis;
3572: }
3573: for (var j=0; j<crsfieldsets.length; j++) {
3574: if (setvis) {
3575: crsfieldsets[j].style.display = 'block';
3576: } else {
3577: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3578: }
3579: }
3580: }
1.363 raeburn 3581: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3582: var radioname = '';
3583: var divid = '';
3584: if (setting == 'user') {
3585: radioname = 'lti_mapuser_'+item;
3586: divid = 'lti_userfield_'+item;
1.343 raeburn 3587: } else if (setting == 'crs') {
1.320 raeburn 3588: radioname = 'lti_mapcrs_'+item;
3589: divid = 'lti_crsfield_'+item;
1.363 raeburn 3590: } else if (setting == 'callback') {
3591: radioname = 'lti_callback_'+item;
3592: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3593: } else {
1.351 raeburn 3594: radioname = 'lti_passback_'+item;
1.337 raeburn 3595: divid = 'lti_passback_'+item;
1.320 raeburn 3596: }
3597: var num = form.elements[radioname].length;
3598: if (num) {
3599: var setvis = '';
3600: for (var i=0; i<num; i++) {
3601: if (form.elements[radioname][i].checked) {
1.363 raeburn 3602: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3603: if (form.elements[radioname][i].value == '1') {
3604: if (document.getElementById(divid)) {
3605: document.getElementById(divid).style.display = 'inline-block';
3606: }
3607: setvis = 1;
3608: break;
3609: }
3610: } else {
3611: if (form.elements[radioname][i].value == 'other') {
3612: if (document.getElementById(divid)) {
3613: document.getElementById(divid).style.display = 'inline-block';
3614: }
3615: setvis = 1;
3616: break;
1.320 raeburn 3617: }
3618: }
3619: }
3620: }
3621: if (!setvis) {
3622: if (document.getElementById(divid)) {
3623: document.getElementById(divid).style.display = 'none';
3624: }
3625: }
3626: }
3627: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3628: var numsec = form.elements['lti_crssec_'+item].length;
3629: if (numsec) {
3630: var setvis = '';
3631: for (var i=0; i<numsec; i++) {
3632: if (form.elements['lti_crssec_'+item][i].checked) {
3633: if (form.elements['lti_crssec_'+item][i].value == '1') {
3634: if (document.getElementById('lti_crssecfield_'+item)) {
3635: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3636: setvis = 1;
3637: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3638: if (numsrcsec) {
3639: var setsrcvis = '';
3640: for (var j=0; j<numsrcsec; j++) {
3641: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3642: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3643: if (document.getElementById('lti_secsrcfield_'+item)) {
3644: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3645: setsrcvis = 1;
3646: }
3647: }
3648: }
3649: }
3650: if (!setsrcvis) {
3651: if (document.getElementById('lti_secsrcfield_'+item)) {
3652: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3653: }
3654: }
3655: }
3656: }
3657: }
3658: }
3659: }
3660: if (!setvis) {
3661: if (document.getElementById('lti_crssecfield_'+item)) {
3662: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3663: }
3664: if (document.getElementById('lti_secsrcfield_'+item)) {
3665: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3666: }
3667: }
3668: }
1.325 raeburn 3669: } else if (setting == 'lcauth') {
3670: var numauth = form.elements['lti_lcauth_'+item].length;
3671: if (numauth) {
3672: for (var i=0; i<numauth; i++) {
3673: if (form.elements['lti_lcauth_'+item][i].checked) {
3674: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3675: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3676: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3677: } else {
3678: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3679: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3680: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3681: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3682: } else {
3683: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3684: }
3685: }
3686: }
3687: }
3688: }
3689: }
3690: }
1.326 raeburn 3691: } else if (setting == 'lcmenu') {
3692: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3693: var divid = 'lti_menufield_'+item;
3694: var setvis = '';
3695: for (var i=0; i<menus.length; i++) {
3696: var radioname = menus[i];
3697: var num = form.elements[radioname].length;
3698: if (num) {
3699: for (var j=0; j<num; j++) {
3700: if (form.elements[radioname][j].checked) {
3701: if (form.elements[radioname][j].value == '1') {
3702: if (document.getElementById(divid)) {
3703: document.getElementById(divid).style.display = 'inline-block';
3704: }
3705: setvis = 1;
3706: break;
3707: }
3708: }
3709: }
3710: }
3711: if (setvis == 1) {
3712: break;
3713: }
3714: }
3715: if (!setvis) {
3716: if (document.getElementById(divid)) {
3717: document.getElementById(divid).style.display = 'none';
3718: }
3719: }
1.320 raeburn 3720: }
3721: return;
3722: }
1.405 raeburn 3723:
3724: function toggleLTIEncKey(form) {
3725: var shownhosts = new Array();
3726: var hiddenhosts = new Array();
3727: var forcourse = new Array($course_servers);
3728: var fromdomain = '$primary';
3729: var crsradio = form.elements['ltisec_crslinkprot'];
3730: if (crsradio.length) {
3731: for (var i=0; i<crsradio.length; i++) {
3732: if (crsradio[i].checked) {
3733: if (crsradio[i].value == 1) {
3734: if (forcourse.length > 0) {
3735: for (var j=0; j<forcourse.length; j++) {
3736: if (!shownhosts.includes(forcourse[j])) {
3737: shownhosts.push(forcourse[j]);
3738: }
3739: }
3740: }
3741: } else {
3742: if (forcourse.length > 0) {
3743: for (var j=0; j<forcourse.length; j++) {
3744: if (!hiddenhosts.includes(forcourse[j])) {
3745: hiddenhosts.push(forcourse[j]);
3746: }
3747: }
3748: }
3749: }
3750: }
3751: }
3752: }
3753: var domradio = form.elements['ltisec_domlinkprot'];
3754: if (domradio.length) {
3755: for (var i=0; i<domradio.length; i++) {
3756: if (domradio[i].checked) {
3757: if (domradio[i].value == 1) {
3758: if (!shownhosts.includes(fromdomain)) {
3759: shownhosts.push(fromdomain);
3760: }
3761: } else {
3762: if (!hiddenhosts.includes(fromdomain)) {
3763: hiddenhosts.push(fromdomain);
3764: }
3765: }
3766: }
3767: }
3768: }
3769: var consumersradio = form.elements['ltisec_consumers'];
3770: if (consumersradio.length) {
3771: for (var i=0; i<consumersradio.length; i++) {
3772: if (consumersradio[i].checked) {
3773: if (consumersradio[i].value == 1) {
3774: if (!shownhosts.includes(fromdomain)) {
3775: shownhosts.push(fromdomain);
3776: }
3777: } else {
3778: if (!hiddenhosts.includes(fromdomain)) {
3779: hiddenhosts.push(fromdomain);
3780: }
3781: }
3782: }
3783: }
3784: }
3785: if (shownhosts.length > 0) {
3786: for (var i=0; i<shownhosts.length; i++) {
3787: if (document.getElementById('ltisec_info_'+shownhosts[i])) {
3788: document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
3789: }
3790: }
3791: if (document.getElementById('ltisec_noprivkey')) {
3792: document.getElementById('ltisec_noprivkey').style.display = 'none';
3793: }
3794: } else {
3795: if (document.getElementById('ltisec_noprivkey')) {
3796: document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
3797: }
3798: }
3799: if (hiddenhosts.length > 0) {
3800: for (var i=0; i<hiddenhosts.length; i++) {
3801: if (!shownhosts.includes(hiddenhosts[i])) {
3802: if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
3803: document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
3804: }
3805: }
3806: }
3807: }
3808: return;
3809: }
3810:
3811: function togglePrivKey(form,hostid) {
3812: var radioname = '';
3813: var currdivid = '';
3814: var newdivid = '';
3815: if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
3816: (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
3817: currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
3818: newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
3819: radioname = form.elements['ltisec_changeprivkey_'+hostid];
3820: if (radioname) {
3821: if (radioname.length > 0) {
3822: var setvis;
3823: for (var i=0; i<radioname.length; i++) {
3824: if (radioname[i].checked == true) {
3825: if (radioname[i].value == 1) {
3826: newdivid.style.display = 'inline-block';
3827: currdivid.style.display = 'none';
3828: setvis = 1;
3829: }
3830: break;
3831: }
3832: }
3833: if (!setvis) {
3834: newdivid.style.display = 'none';
3835: currdivid.style.display = 'inline-block';
3836: }
3837: }
3838: }
3839: }
3840: }
3841:
1.320 raeburn 3842: // ]]>
3843: </script>
3844:
3845: ENDSCRIPT
3846: }
3847:
1.385 raeburn 3848: sub autoupdate_javascript {
3849: return <<"ENDSCRIPT";
3850: <script type="text/javascript">
3851: // <![CDATA[
3852: function toggleLastActiveDays(form) {
3853: var radioname = 'lastactive';
3854: var divid = 'lastactive_div';
3855: var num = form.elements[radioname].length;
3856: if (num) {
3857: var setvis = '';
3858: for (var i=0; i<num; i++) {
3859: if (form.elements[radioname][i].checked) {
3860: if (form.elements[radioname][i].value == '1') {
3861: if (document.getElementById(divid)) {
3862: document.getElementById(divid).style.display = 'inline-block';
3863: }
3864: setvis = 1;
3865: }
3866: break;
3867: }
3868: }
3869: if (!setvis) {
3870: if (document.getElementById(divid)) {
3871: document.getElementById(divid).style.display = 'none';
3872: }
3873: }
3874: }
3875: return;
3876: }
3877: // ]]>
3878: </script>
3879:
3880: ENDSCRIPT
3881: }
3882:
1.399 raeburn 3883: sub autoenroll_javascript {
3884: return <<"ENDSCRIPT";
3885: <script type="text/javascript">
3886: // <![CDATA[
3887: function toggleFailsafe(form) {
3888: var radioname = 'autoenroll_failsafe';
3889: var divid = 'autoenroll_failsafe_div';
3890: var num = form.elements[radioname].length;
3891: if (num) {
3892: var setvis = '';
3893: for (var i=0; i<num; i++) {
3894: if (form.elements[radioname][i].checked) {
3895: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3896: if (document.getElementById(divid)) {
3897: document.getElementById(divid).style.display = 'inline-block';
3898: }
3899: setvis = 1;
3900: }
3901: break;
3902: }
3903: }
3904: if (!setvis) {
3905: if (document.getElementById(divid)) {
3906: document.getElementById(divid).style.display = 'none';
3907: }
3908: }
3909: }
3910: return;
3911: }
3912: // ]]>
3913: </script>
3914:
3915: ENDSCRIPT
3916: }
3917:
1.386 raeburn 3918: sub saml_javascript {
3919: return <<"ENDSCRIPT";
3920: <script type="text/javascript">
3921: // <![CDATA[
3922: function toggleSamlOptions(form,hostid) {
3923: var radioname = 'saml_'+hostid;
3924: var tablecellon = 'samloptionson_'+hostid;
3925: var tablecelloff = 'samloptionsoff_'+hostid;
3926: var num = form.elements[radioname].length;
3927: if (num) {
3928: var setvis = '';
3929: for (var i=0; i<num; i++) {
3930: if (form.elements[radioname][i].checked) {
3931: if (form.elements[radioname][i].value == '1') {
3932: if (document.getElementById(tablecellon)) {
3933: document.getElementById(tablecellon).style.display='';
3934: }
3935: if (document.getElementById(tablecelloff)) {
3936: document.getElementById(tablecelloff).style.display='none';
3937: }
3938: setvis = 1;
3939: }
3940: break;
3941: }
3942: }
3943: if (!setvis) {
3944: if (document.getElementById(tablecellon)) {
3945: document.getElementById(tablecellon).style.display='none';
3946: }
3947: if (document.getElementById(tablecelloff)) {
3948: document.getElementById(tablecelloff).style.display='';
3949: }
3950: }
3951: }
3952: return;
3953: }
3954: // ]]>
3955: </script>
3956:
3957: ENDSCRIPT
3958: }
3959:
1.394 raeburn 3960: sub ipaccess_javascript {
3961: my ($settings) = @_;
3962: my (%ordered,$total,%jstext);
3963: $total = 0;
3964: if (ref($settings) eq 'HASH') {
3965: foreach my $item (keys(%{$settings})) {
3966: if (ref($settings->{$item}) eq 'HASH') {
3967: my $num = $settings->{$item}{'order'};
3968: $ordered{$num} = $item;
3969: }
3970: }
3971: $total = scalar(keys(%{$settings}));
3972: }
3973: my @jsarray = ();
3974: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3975: push(@jsarray,$ordered{$item});
3976: }
3977: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3978: return <<"ENDSCRIPT";
3979: <script type="text/javascript">
3980: // <![CDATA[
3981: function reorderIPaccess(form,item) {
3982: var changedVal;
3983: $jstext
3984: var newpos = 'ipaccess_pos_add';
3985: var maxh = 1 + $total;
3986: var current = new Array;
3987: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3988: if (item == newpos) {
3989: changedVal = newitemVal;
3990: } else {
3991: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3992: current[newitemVal] = newpos;
3993: }
3994: for (var i=0; i<ipaccess.length; i++) {
3995: var elementName = 'ipaccess_pos_'+ipaccess[i];
3996: if (elementName != item) {
3997: if (form.elements[elementName]) {
3998: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3999: current[currVal] = elementName;
4000: }
4001: }
4002: }
4003: var oldVal;
4004: for (var j=0; j<maxh; j++) {
4005: if (current[j] == undefined) {
4006: oldVal = j;
4007: }
4008: }
4009: if (oldVal < changedVal) {
4010: for (var k=oldVal+1; k<=changedVal ; k++) {
4011: var elementName = current[k];
4012: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4013: }
4014: } else {
4015: for (var k=changedVal; k<oldVal; k++) {
4016: var elementName = current[k];
4017: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4018: }
4019: }
4020: return;
4021: }
4022: // ]]>
4023: </script>
4024:
4025: ENDSCRIPT
4026: }
4027:
1.3 raeburn 4028: sub print_autoenroll {
1.30 raeburn 4029: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 4030: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 4031: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
4032: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
4033: $failsafesty = 'none';
4034: %failsafechecked = (
4035: off => ' checked="checked"',
4036: );
1.3 raeburn 4037: if (ref($settings) eq 'HASH') {
4038: if (exists($settings->{'run'})) {
4039: if ($settings->{'run'} eq '0') {
4040: $runoff = ' checked="checked" ';
4041: $runon = ' ';
4042: } else {
4043: $runon = ' checked="checked" ';
4044: $runoff = ' ';
4045: }
4046: } else {
4047: if ($autorun) {
4048: $runon = ' checked="checked" ';
4049: $runoff = ' ';
4050: } else {
4051: $runoff = ' checked="checked" ';
4052: $runon = ' ';
4053: }
4054: }
1.129 raeburn 4055: if (exists($settings->{'co-owners'})) {
4056: if ($settings->{'co-owners'} eq '0') {
4057: $coownersoff = ' checked="checked" ';
4058: $coownerson = ' ';
4059: } else {
4060: $coownerson = ' checked="checked" ';
4061: $coownersoff = ' ';
4062: }
4063: } else {
4064: $coownersoff = ' checked="checked" ';
4065: $coownerson = ' ';
4066: }
1.3 raeburn 4067: if (exists($settings->{'sender_domain'})) {
4068: $defdom = $settings->{'sender_domain'};
4069: }
1.399 raeburn 4070: if (exists($settings->{'failsafe'})) {
4071: $failsafe = $settings->{'failsafe'};
4072: if ($failsafe eq 'zero') {
1.400 raeburn 4073: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4074: $failsafechecked{'off'} = '';
4075: $failsafesty = 'inline-block';
4076: } elsif ($failsafe eq 'any') {
4077: $failsafechecked{'any'} = ' checked="checked"';
4078: $failsafechecked{'off'} = '';
4079: }
4080: $autofailsafe = $settings->{'autofailsafe'};
4081: } elsif (exists($settings->{'autofailsafe'})) {
4082: $autofailsafe = $settings->{'autofailsafe'};
4083: if ($autofailsafe ne '') {
4084: $failsafechecked{'zero'} = ' checked="checked"';
4085: $failsafe = 'zero';
1.400 raeburn 4086: $failsafechecked{'off'} = '';
1.399 raeburn 4087: }
1.274 raeburn 4088: }
1.14 raeburn 4089: } else {
4090: if ($autorun) {
4091: $runon = ' checked="checked" ';
4092: $runoff = ' ';
4093: } else {
4094: $runoff = ' checked="checked" ';
4095: $runon = ' ';
4096: }
1.3 raeburn 4097: }
4098: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4099: my $notif_sender;
4100: if (ref($settings) eq 'HASH') {
4101: $notif_sender = $settings->{'sender_uname'};
4102: }
1.3 raeburn 4103: my $datatable='<tr class="LC_odd_row">'.
4104: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4105: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4106: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4107: $runon.' value="1" />'.&mt('Yes').'</label> '.
4108: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4109: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4110: '</tr><tr>'.
4111: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4112: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4113: &mt('username').': '.
4114: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4115: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4116: ': '.$domform.'</span></td></tr>'.
4117: '<tr class="LC_odd_row">'.
4118: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4119: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4120: '<input type="radio" name="autoassign_coowners"'.
4121: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4122: '<label><input type="radio" name="autoassign_coowners"'.
4123: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4124: '</tr><tr>'.
4125: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4126: '<td class="LC_left_item"><span class="LC_nobreak">'.
4127: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
4128: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
4129: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 4130: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4131: '<span class="LC_nobreak">'.
4132: &mt('Threshold for number of students in section to drop: [_1]',
4133: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4134: '</span></div></td></tr>';
1.274 raeburn 4135: $$rowtotal += 4;
1.3 raeburn 4136: return $datatable;
4137: }
4138:
4139: sub print_autoupdate {
1.30 raeburn 4140: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4141: my ($enable,$datatable);
1.3 raeburn 4142: if ($position eq 'top') {
1.385 raeburn 4143: my %choices = &Apache::lonlocal::texthash (
4144: run => 'Auto-update active?',
4145: classlists => 'Update information in classlists?',
4146: unexpired => 'Skip updates for users without active or future roles?',
4147: lastactive => 'Skip updates for inactive users?',
4148: );
4149: my $itemcount = 0;
1.3 raeburn 4150: my $updateon = ' ';
4151: my $updateoff = ' checked="checked" ';
4152: if (ref($settings) eq 'HASH') {
4153: if ($settings->{'run'} eq '1') {
4154: $updateon = $updateoff;
4155: $updateoff = ' ';
4156: }
4157: }
1.385 raeburn 4158: $enable = '<tr class="LC_odd_row">'.
4159: '<td>'.$choices{'run'}.'</td>'.
4160: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4161: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4162: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4163: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4164: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4165: '</tr>';
1.385 raeburn 4166: my @toggles = ('classlists','unexpired');
4167: my %defaultchecked = ('classlists' => 'off',
4168: 'unexpired' => 'off'
4169: );
4170: $$rowtotal ++;
4171: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4172: \%choices,$itemcount,'','','left','no');
4173: $datatable = $enable.$datatable;
4174: $$rowtotal += $itemcount;
4175: my $lastactiveon = ' ';
4176: my $lastactiveoff = ' checked="checked" ';
4177: my $lastactivestyle = 'none';
4178: my $lastactivedays;
4179: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4180: if (ref($settings) eq 'HASH') {
4181: if ($settings->{'lastactive'} =~ /^\d+$/) {
4182: $lastactiveon = $lastactiveoff;
4183: $lastactiveoff = ' ';
4184: $lastactivestyle = 'inline-block';
4185: $lastactivedays = $settings->{'lastactive'};
4186: }
4187: }
4188: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4189: $datatable .= '<tr'.$css_class.'>'.
4190: '<td>'.$choices{'lastactive'}.'</td>'.
4191: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4192: '<input type="radio" name="lastactive"'.
4193: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4194: ' <label>'.
4195: '<input type="radio" name="lastactive"'.
4196: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4197: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4198: ': '.&mt('inactive = no activity in last [_1] days',
4199: '<input type="text" size="5" name="lastactivedays" value="'.
4200: $lastactivedays.'" />').
4201: '</span></td>'.
4202: '</tr>';
4203: $$rowtotal ++;
1.131 raeburn 4204: } elsif ($position eq 'middle') {
4205: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4206: my $numinrow = 3;
4207: my $locknamesettings;
4208: $datatable .= &insttypes_row($settings,$types,$usertypes,
4209: $dom,$numinrow,$othertitle,
1.305 raeburn 4210: 'lockablenames',$rowtotal);
1.131 raeburn 4211: $$rowtotal ++;
1.3 raeburn 4212: } else {
1.44 raeburn 4213: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4214: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4215: 'permanentemail','id');
1.33 raeburn 4216: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4217: my $numrows = 0;
1.26 raeburn 4218: if (ref($types) eq 'ARRAY') {
4219: if (@{$types} > 0) {
4220: $datatable =
4221: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4222: \@fields,$types,\$numrows);
1.30 raeburn 4223: $$rowtotal += @{$types};
1.26 raeburn 4224: }
1.3 raeburn 4225: }
4226: $datatable .=
4227: &usertype_update_row($settings,{'default' => $othertitle},
4228: \%fieldtitles,\@fields,['default'],
4229: \$numrows);
1.30 raeburn 4230: $$rowtotal ++;
1.3 raeburn 4231: }
4232: return $datatable;
4233: }
4234:
1.125 raeburn 4235: sub print_autocreate {
4236: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4237: my (%createon,%createoff,%currhash);
1.125 raeburn 4238: my @types = ('xml','req');
4239: if (ref($settings) eq 'HASH') {
4240: foreach my $item (@types) {
4241: $createoff{$item} = ' checked="checked" ';
4242: $createon{$item} = ' ';
4243: if (exists($settings->{$item})) {
4244: if ($settings->{$item}) {
4245: $createon{$item} = ' checked="checked" ';
4246: $createoff{$item} = ' ';
4247: }
4248: }
4249: }
1.210 raeburn 4250: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4251: $currhash{$settings->{'xmldc'}} = 1;
4252: }
1.125 raeburn 4253: } else {
4254: foreach my $item (@types) {
4255: $createoff{$item} = ' checked="checked" ';
4256: $createon{$item} = ' ';
4257: }
4258: }
4259: $$rowtotal += 2;
1.191 raeburn 4260: my $numinrow = 2;
1.125 raeburn 4261: my $datatable='<tr class="LC_odd_row">'.
4262: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4263: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4264: '<input type="radio" name="autocreate_xml"'.
4265: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4266: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4267: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4268: '</td></tr><tr>'.
4269: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4270: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4271: '<input type="radio" name="autocreate_req"'.
4272: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4273: '<label><input type="radio" name="autocreate_req"'.
4274: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4275: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4276: 'autocreate_xmldc',%currhash);
1.247 raeburn 4277: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4278: if ($numdc > 1) {
1.247 raeburn 4279: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4280: '</td><td class="LC_left_item">';
1.125 raeburn 4281: } else {
1.247 raeburn 4282: $datatable .= &mt('Course creation processed as:').
4283: '</td><td class="LC_right_item">';
1.125 raeburn 4284: }
1.247 raeburn 4285: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4286: $$rowtotal += $rows;
1.125 raeburn 4287: return $datatable;
4288: }
4289:
1.23 raeburn 4290: sub print_directorysrch {
1.277 raeburn 4291: my ($position,$dom,$settings,$rowtotal) = @_;
4292: my $datatable;
4293: if ($position eq 'top') {
4294: my $instsrchon = ' ';
4295: my $instsrchoff = ' checked="checked" ';
4296: my ($exacton,$containson,$beginson);
4297: my $instlocalon = ' ';
4298: my $instlocaloff = ' checked="checked" ';
4299: if (ref($settings) eq 'HASH') {
4300: if ($settings->{'available'} eq '1') {
4301: $instsrchon = $instsrchoff;
4302: $instsrchoff = ' ';
4303: }
4304: if ($settings->{'localonly'} eq '1') {
4305: $instlocalon = $instlocaloff;
4306: $instlocaloff = ' ';
4307: }
4308: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4309: foreach my $type (@{$settings->{'searchtypes'}}) {
4310: if ($type eq 'exact') {
4311: $exacton = ' checked="checked" ';
4312: } elsif ($type eq 'contains') {
4313: $containson = ' checked="checked" ';
4314: } elsif ($type eq 'begins') {
4315: $beginson = ' checked="checked" ';
4316: }
4317: }
4318: } else {
4319: if ($settings->{'searchtypes'} eq 'exact') {
4320: $exacton = ' checked="checked" ';
4321: } elsif ($settings->{'searchtypes'} eq 'contains') {
4322: $containson = ' checked="checked" ';
4323: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4324: $exacton = ' checked="checked" ';
4325: $containson = ' checked="checked" ';
4326: }
4327: }
1.277 raeburn 4328: }
4329: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4330: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4331:
4332: my $numinrow = 4;
4333: my $cansrchrow = 0;
4334: $datatable='<tr class="LC_odd_row">'.
4335: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4336: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4337: '<input type="radio" name="dirsrch_available"'.
4338: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4339: '<label><input type="radio" name="dirsrch_available"'.
4340: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4341: '</tr><tr>'.
4342: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4343: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4344: '<input type="radio" name="dirsrch_instlocalonly"'.
4345: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4346: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4347: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4348: '</tr>';
4349: $$rowtotal += 2;
4350: if (ref($usertypes) eq 'HASH') {
4351: if (keys(%{$usertypes}) > 0) {
4352: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4353: $numinrow,$othertitle,'cansearch',
4354: $rowtotal);
1.277 raeburn 4355: $cansrchrow = 1;
1.25 raeburn 4356: }
1.23 raeburn 4357: }
1.277 raeburn 4358: if ($cansrchrow) {
4359: $$rowtotal ++;
4360: $datatable .= '<tr>';
4361: } else {
4362: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4363: }
1.277 raeburn 4364: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4365: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4366: foreach my $title (@{$titleorder}) {
4367: if (defined($searchtitles->{$title})) {
4368: my $check = ' ';
4369: if (ref($settings) eq 'HASH') {
4370: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4371: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4372: $check = ' checked="checked" ';
4373: }
1.39 raeburn 4374: }
1.25 raeburn 4375: }
1.277 raeburn 4376: $datatable .= '<td class="LC_left_item">'.
4377: '<span class="LC_nobreak"><label>'.
4378: '<input type="checkbox" name="searchby" '.
4379: 'value="'.$title.'"'.$check.'/>'.
4380: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4381: }
4382: }
1.277 raeburn 4383: $datatable .= '</tr></table></td></tr>';
4384: $$rowtotal ++;
4385: if ($cansrchrow) {
4386: $datatable .= '<tr class="LC_odd_row">';
4387: } else {
4388: $datatable .= '<tr>';
4389: }
4390: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4391: '<td class="LC_left_item" colspan="2">'.
4392: '<span class="LC_nobreak"><label>'.
4393: '<input type="checkbox" name="searchtypes" '.
4394: $exacton.' value="exact" />'.&mt('Exact match').
4395: '</label> '.
4396: '<label><input type="checkbox" name="searchtypes" '.
4397: $beginson.' value="begins" />'.&mt('Begins with').
4398: '</label> '.
4399: '<label><input type="checkbox" name="searchtypes" '.
4400: $containson.' value="contains" />'.&mt('Contains').
4401: '</label></span></td></tr>';
4402: $$rowtotal ++;
1.26 raeburn 4403: } else {
1.277 raeburn 4404: my $domsrchon = ' checked="checked" ';
4405: my $domsrchoff = ' ';
4406: my $domlocalon = ' ';
4407: my $domlocaloff = ' checked="checked" ';
4408: if (ref($settings) eq 'HASH') {
4409: if ($settings->{'lclocalonly'} eq '1') {
4410: $domlocalon = $domlocaloff;
4411: $domlocaloff = ' ';
4412: }
4413: if ($settings->{'lcavailable'} eq '0') {
4414: $domsrchoff = $domsrchon;
4415: $domsrchon = ' ';
4416: }
4417: }
4418: $datatable='<tr class="LC_odd_row">'.
4419: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4420: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4421: '<input type="radio" name="dirsrch_domavailable"'.
4422: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4423: '<label><input type="radio" name="dirsrch_domavailable"'.
4424: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4425: '</tr><tr>'.
4426: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4427: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4428: '<input type="radio" name="dirsrch_domlocalonly"'.
4429: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4430: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4431: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4432: '</tr>';
4433: $$rowtotal += 2;
1.26 raeburn 4434: }
1.25 raeburn 4435: return $datatable;
4436: }
4437:
1.28 raeburn 4438: sub print_contacts {
1.286 raeburn 4439: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4440: my $datatable;
4441: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4442: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4443: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4444: if ($position eq 'top') {
4445: if (ref($settings) eq 'HASH') {
4446: foreach my $item (@contacts) {
4447: if (exists($settings->{$item})) {
4448: $to{$item} = $settings->{$item};
4449: }
4450: }
4451: }
4452: } elsif ($position eq 'middle') {
4453: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4454: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4455: foreach my $type (@mailings) {
4456: $otheremails{$type} = '';
4457: }
1.340 raeburn 4458: } elsif ($position eq 'lower') {
4459: if (ref($settings) eq 'HASH') {
4460: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4461: %lonstatus = %{$settings->{'lonstatus'}};
4462: }
4463: }
1.286 raeburn 4464: } else {
4465: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4466: foreach my $type (@mailings) {
4467: $otheremails{$type} = '';
4468: }
1.286 raeburn 4469: $bccemails{'helpdeskmail'} = '';
4470: $bccemails{'otherdomsmail'} = '';
4471: $includestr{'helpdeskmail'} = '';
4472: $includestr{'otherdomsmail'} = '';
4473: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4474: }
1.28 raeburn 4475: if (ref($settings) eq 'HASH') {
1.340 raeburn 4476: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4477: foreach my $type (@mailings) {
4478: if (exists($settings->{$type})) {
4479: if (ref($settings->{$type}) eq 'HASH') {
4480: foreach my $item (@contacts) {
4481: if ($settings->{$type}{$item}) {
4482: $checked{$type}{$item} = ' checked="checked" ';
4483: }
4484: }
4485: $otheremails{$type} = $settings->{$type}{'others'};
4486: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4487: $bccemails{$type} = $settings->{$type}{'bcc'};
4488: if ($settings->{$type}{'include'} ne '') {
4489: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4490: $includestr{$type} = &unescape($includestr{$type});
4491: }
4492: }
4493: }
4494: } elsif ($type eq 'lonstatusmail') {
4495: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4496: }
1.28 raeburn 4497: }
4498: }
1.286 raeburn 4499: if ($position eq 'bottom') {
4500: foreach my $type (@mailings) {
4501: $bccemails{$type} = $settings->{$type}{'bcc'};
4502: if ($settings->{$type}{'include'} ne '') {
4503: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4504: $includestr{$type} = &unescape($includestr{$type});
4505: }
4506: }
4507: if (ref($settings->{'helpform'}) eq 'HASH') {
4508: if (ref($fields) eq 'ARRAY') {
4509: foreach my $field (@{$fields}) {
4510: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4511: }
1.286 raeburn 4512: }
4513: if (exists($settings->{'helpform'}{'maxsize'})) {
4514: $maxsize = $settings->{'helpform'}{'maxsize'};
4515: } else {
1.289 raeburn 4516: $maxsize = '1.0';
1.286 raeburn 4517: }
4518: } else {
4519: if (ref($fields) eq 'ARRAY') {
4520: foreach my $field (@{$fields}) {
4521: $currfield{$field} = 'yes';
1.134 raeburn 4522: }
1.28 raeburn 4523: }
1.286 raeburn 4524: $maxsize = '1.0';
1.28 raeburn 4525: }
4526: }
4527: } else {
1.286 raeburn 4528: if ($position eq 'top') {
4529: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4530: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4531: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4532: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4533: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4534: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4535: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4536: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4537: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4538: } elsif ($position eq 'bottom') {
4539: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4540: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4541: if (ref($fields) eq 'ARRAY') {
4542: foreach my $field (@{$fields}) {
4543: $currfield{$field} = 'yes';
4544: }
4545: }
4546: $maxsize = '1.0';
4547: }
1.28 raeburn 4548: }
4549: my ($titles,$short_titles) = &contact_titles();
4550: my $rownum = 0;
4551: my $css_class;
1.286 raeburn 4552: if ($position eq 'top') {
4553: foreach my $item (@contacts) {
4554: $css_class = $rownum%2?' class="LC_odd_row"':'';
4555: $datatable .= '<tr'.$css_class.'>'.
4556: '<td><span class="LC_nobreak">'.$titles->{$item}.
4557: '</span></td><td class="LC_right_item">'.
4558: '<input type="text" name="'.$item.'" value="'.
4559: $to{$item}.'" /></td></tr>';
4560: $rownum ++;
4561: }
1.315 raeburn 4562: } elsif ($position eq 'bottom') {
4563: $css_class = $rownum%2?' class="LC_odd_row"':'';
4564: $datatable .= '<tr'.$css_class.'>'.
4565: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4566: &mt('(e-mail, subject, and description always shown)').
4567: '</td><td class="LC_left_item">';
4568: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4569: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4570: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4571: foreach my $field (@{$fields}) {
4572: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4573: if (($field eq 'screenshot') || ($field eq 'cc')) {
4574: $datatable .= ' '.&mt('(logged-in users)');
4575: }
4576: $datatable .='</td><td>';
4577: my $clickaction;
4578: if ($field eq 'screenshot') {
4579: $clickaction = ' onclick="screenshotSize(this);"';
4580: }
4581: if (ref($possoptions->{$field}) eq 'ARRAY') {
4582: foreach my $option (@{$possoptions->{$field}}) {
4583: my $checked;
4584: if ($currfield{$field} eq $option) {
4585: $checked = ' checked="checked"';
4586: }
4587: $datatable .= '<span class="LC_nobreak"><label>'.
4588: '<input type="radio" name="helpform_'.$field.'" '.
4589: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4590: '</label></span>'.(' 'x2);
4591: }
4592: }
4593: if ($field eq 'screenshot') {
4594: my $display;
4595: if ($currfield{$field} eq 'no') {
4596: $display = ' style="display:none"';
4597: }
1.334 raeburn 4598: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4599: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4600: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4601: }
4602: $datatable .= '</td></tr>';
4603: }
4604: $datatable .= '</table>';
4605: }
4606: $datatable .= '</td></tr>'."\n";
4607: $rownum ++;
4608: }
1.340 raeburn 4609: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4610: foreach my $type (@mailings) {
4611: $css_class = $rownum%2?' class="LC_odd_row"':'';
4612: $datatable .= '<tr'.$css_class.'>'.
4613: '<td><span class="LC_nobreak">'.
4614: $titles->{$type}.': </span></td>'.
4615: '<td class="LC_left_item">';
4616: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4617: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4618: }
4619: $datatable .= '<span class="LC_nobreak">';
4620: foreach my $item (@contacts) {
4621: $datatable .= '<label>'.
4622: '<input type="checkbox" name="'.$type.'"'.
4623: $checked{$type}{$item}.
4624: ' value="'.$item.'" />'.$short_titles->{$item}.
4625: '</label> ';
4626: }
4627: $datatable .= '</span><br />'.&mt('Others').': '.
4628: '<input type="text" name="'.$type.'_others" '.
4629: 'value="'.$otheremails{$type}.'" />';
4630: my %locchecked;
4631: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4632: foreach my $loc ('s','b') {
4633: if ($includeloc{$type} eq $loc) {
4634: $locchecked{$loc} = ' checked="checked"';
4635: last;
4636: }
4637: }
4638: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4639: '<input type="text" name="'.$type.'_bcc" '.
4640: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4641: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4642: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4643: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4644: '<span class="LC_nobreak">'.&mt('Location:').' '.
4645: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4646: (' 'x2).
4647: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4648: '</span></fieldset>';
4649: }
4650: $datatable .= '</td></tr>'."\n";
4651: $rownum ++;
4652: }
1.28 raeburn 4653: }
1.286 raeburn 4654: if ($position eq 'middle') {
4655: my %choices;
1.340 raeburn 4656: my $corelink = &core_link_msu();
4657: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4658: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4659: $corelink);
4660: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4661: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4662: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4663: 'reportupdates' => 'on',
4664: 'reportstatus' => 'on');
1.286 raeburn 4665: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4666: \%choices,$rownum);
4667: $datatable .= $reports;
1.340 raeburn 4668: } elsif ($position eq 'lower') {
1.378 raeburn 4669: my (%current,%excluded,%weights);
1.340 raeburn 4670: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4671: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4672: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4673: } else {
1.378 raeburn 4674: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4675: }
4676: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4677: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4678: } else {
1.378 raeburn 4679: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4680: }
4681: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4682: foreach my $type ('E','W','N','U') {
1.340 raeburn 4683: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4684: $weights{$type} = $lonstatus{'weights'}{$type};
4685: } else {
4686: $weights{$type} = $defaults->{$type};
4687: }
4688: }
4689: } else {
1.341 raeburn 4690: foreach my $type ('E','W','N','U') {
1.340 raeburn 4691: $weights{$type} = $defaults->{$type};
4692: }
4693: }
4694: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4695: if (@{$lonstatus{'excluded'}} > 0) {
4696: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4697: }
4698: }
1.378 raeburn 4699: foreach my $item ('errorthreshold','errorsysmail') {
4700: $css_class = $rownum%2?' class="LC_odd_row"':'';
4701: $datatable .= '<tr'.$css_class.'>'.
4702: '<td class="LC_left_item"><span class="LC_nobreak">'.
4703: $titles->{$item}.
4704: '</span></td><td class="LC_left_item">'.
4705: '<input type="text" name="'.$item.'" value="'.
4706: $current{$item}.'" size="5" /></td></tr>';
4707: $rownum ++;
4708: }
1.340 raeburn 4709: $css_class = $rownum%2?' class="LC_odd_row"':'';
4710: $datatable .= '<tr'.$css_class.'>'.
4711: '<td class="LC_left_item">'.
4712: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4713: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4714: foreach my $type ('E','W','N','U') {
1.340 raeburn 4715: $datatable .= '<td>'.$names->{$type}.'<br />'.
4716: '<input type="text" name="errorweights_'.$type.'" value="'.
4717: $weights{$type}.'" size="5" /></td>';
4718: }
4719: $datatable .= '</tr></table></tr>';
4720: $rownum ++;
4721: $css_class = $rownum%2?' class="LC_odd_row"':'';
4722: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4723: $titles->{'errorexcluded'}.'</td>'.
4724: '<td class="LC_left_item"><table>';
4725: my $numinrow = 4;
4726: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4727: for (my $i=0; $i<@ids; $i++) {
4728: my $rem = $i%($numinrow);
4729: if ($rem == 0) {
4730: if ($i > 0) {
4731: $datatable .= '</tr>';
4732: }
4733: $datatable .= '<tr>';
4734: }
4735: my $check;
4736: if ($excluded{$ids[$i]}) {
4737: $check = ' checked="checked" ';
4738: }
4739: $datatable .= '<td class="LC_left_item">'.
4740: '<span class="LC_nobreak"><label>'.
4741: '<input type="checkbox" name="errorexcluded" '.
4742: 'value="'.$ids[$i].'"'.$check.' />'.
4743: $ids[$i].'</label></span></td>';
4744: }
4745: my $colsleft = $numinrow - @ids%($numinrow);
4746: if ($colsleft > 1 ) {
4747: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4748: ' </td>';
4749: } elsif ($colsleft == 1) {
4750: $datatable .= '<td class="LC_left_item"> </td>';
4751: }
4752: $datatable .= '</tr></table></td></tr>';
4753: $rownum ++;
1.286 raeburn 4754: } elsif ($position eq 'bottom') {
1.315 raeburn 4755: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4756: my (@posstypes,%usertypeshash);
4757: if (ref($types) eq 'ARRAY') {
4758: @posstypes = @{$types};
4759: }
4760: if (@posstypes) {
4761: if (ref($usertypes) eq 'HASH') {
4762: %usertypeshash = %{$usertypes};
4763: }
4764: my @overridden;
4765: my $numinrow = 4;
4766: if (ref($settings) eq 'HASH') {
4767: if (ref($settings->{'overrides'}) eq 'HASH') {
4768: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4769: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4770: push(@overridden,$key);
4771: foreach my $item (@contacts) {
4772: if ($settings->{'overrides'}{$key}{$item}) {
4773: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4774: }
4775: }
4776: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4777: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4778: $includeloc{'override_'.$key} = '';
4779: $includestr{'override_'.$key} = '';
4780: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4781: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4782: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4783: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4784: }
1.286 raeburn 4785: }
4786: }
4787: }
1.315 raeburn 4788: }
4789: my $customclass = 'LC_helpdesk_override';
4790: my $optionsprefix = 'LC_options_helpdesk_';
4791:
4792: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4793:
4794: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4795: $numinrow,$othertitle,'overrides',
4796: \$rownum,$onclicktypes,$customclass);
4797: $rownum ++;
4798: $usertypeshash{'default'} = $othertitle;
4799: foreach my $status (@posstypes) {
4800: my $css_class;
4801: if ($rownum%2) {
4802: $css_class = 'LC_odd_row ';
4803: }
4804: $css_class .= $customclass;
4805: my $rowid = $optionsprefix.$status;
4806: my $hidden = 1;
4807: my $currstyle = 'display:none';
4808: if (grep(/^\Q$status\E$/,@overridden)) {
4809: $currstyle = 'display:table-row';
4810: $hidden = 0;
4811: }
4812: my $key = 'override_'.$status;
4813: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4814: $includeloc{$key},$includestr{$key},$status,$rowid,
4815: $usertypeshash{$status},$css_class,$currstyle,
4816: \@contacts,$short_titles);
4817: unless ($hidden) {
4818: $rownum ++;
1.286 raeburn 4819: }
4820: }
1.134 raeburn 4821: }
1.28 raeburn 4822: }
1.30 raeburn 4823: $$rowtotal += $rownum;
1.28 raeburn 4824: return $datatable;
4825: }
4826:
1.340 raeburn 4827: sub core_link_msu {
4828: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4829: &mt('LON-CAPA core group - MSU'),600,500);
4830: }
4831:
1.315 raeburn 4832: sub overridden_helpdesk {
4833: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4834: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4835: my $class = 'LC_left_item';
4836: if ($css_class) {
4837: $css_class = ' class="'.$css_class.'"';
4838: }
4839: if ($rowid) {
4840: $rowid = ' id="'.$rowid.'"';
4841: }
4842: if ($rowstyle) {
4843: $rowstyle = ' style="'.$rowstyle.'"';
4844: }
4845: my ($output,$description);
4846: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4847: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4848: "<td>$description</td>\n".
4849: '<td class="'.$class.'" colspan="2">'.
4850: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4851: '<span class="LC_nobreak">';
4852: if (ref($contacts) eq 'ARRAY') {
4853: foreach my $item (@{$contacts}) {
4854: my $check;
4855: if (ref($checked) eq 'HASH') {
4856: $check = $checked->{$item};
4857: }
4858: my $title;
4859: if (ref($short_titles) eq 'HASH') {
4860: $title = $short_titles->{$item};
4861: }
4862: $output .= '<label>'.
4863: '<input type="checkbox" name="override_'.$type.'"'.$check.
4864: ' value="'.$item.'" />'.$title.'</label> ';
4865: }
4866: }
4867: $output .= '</span><br />'.&mt('Others').': '.
4868: '<input type="text" name="override_'.$type.'_others" '.
4869: 'value="'.$otheremails.'" />';
4870: my %locchecked;
4871: foreach my $loc ('s','b') {
4872: if ($includeloc eq $loc) {
4873: $locchecked{$loc} = ' checked="checked"';
4874: last;
4875: }
4876: }
4877: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4878: '<input type="text" name="override_'.$type.'_bcc" '.
4879: 'value="'.$bccemails.'" /></fieldset>'.
4880: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4881: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4882: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4883: '<span class="LC_nobreak">'.&mt('Location:').' '.
4884: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4885: (' 'x2).
4886: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4887: '</span></fieldset>'.
4888: '</td></tr>'."\n";
4889: return $output;
4890: }
4891:
1.286 raeburn 4892: sub contacts_javascript {
4893: return <<"ENDSCRIPT";
4894:
4895: <script type="text/javascript">
4896: // <![CDATA[
4897:
4898: function screenshotSize(field) {
4899: if (document.getElementById('help_screenshotsize')) {
4900: if (field.value == 'no') {
1.289 raeburn 4901: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4902: } else {
4903: document.getElementById('help_screenshotsize').style.display="";
4904: }
4905: }
4906: return;
4907: }
4908:
1.315 raeburn 4909: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4910: if (form.elements[checkbox].length != undefined) {
4911: var count = 0;
4912: if (docount) {
4913: for (var i=0; i<form.elements[checkbox].length; i++) {
4914: if (form.elements[checkbox][i].checked) {
4915: count ++;
4916: }
4917: }
4918: }
4919: for (var i=0; i<form.elements[checkbox].length; i++) {
4920: var type = form.elements[checkbox][i].value;
4921: if (document.getElementById(prefix+type)) {
4922: if (form.elements[checkbox][i].checked) {
4923: document.getElementById(prefix+type).style.display = 'table-row';
4924: if (count % 2 == 1) {
4925: document.getElementById(prefix+type).className = target+' LC_odd_row';
4926: } else {
4927: document.getElementById(prefix+type).className = target;
4928: }
4929: count ++;
4930: } else {
4931: document.getElementById(prefix+type).style.display = 'none';
4932: }
4933: }
4934: }
4935: }
4936: return;
4937: }
4938:
4939:
1.286 raeburn 4940: // ]]>
4941: </script>
4942:
4943: ENDSCRIPT
4944: }
4945:
1.118 jms 4946: sub print_helpsettings {
1.282 raeburn 4947: my ($position,$dom,$settings,$rowtotal) = @_;
4948: my $confname = $dom.'-domainconfig';
1.285 raeburn 4949: my $formname = 'display';
1.168 raeburn 4950: my ($datatable,$itemcount);
1.282 raeburn 4951: if ($position eq 'top') {
4952: $itemcount = 1;
4953: my (%choices,%defaultchecked,@toggles);
4954: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4955: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4956: &mt('LON-CAPA bug tracker'),600,500));
4957: %defaultchecked = ('submitbugs' => 'on');
4958: @toggles = ('submitbugs');
4959: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4960: \%choices,$itemcount);
4961: $$rowtotal ++;
4962: } else {
4963: my $css_class;
4964: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4965: my (%customroles,%ordered,%current);
1.301 raeburn 4966: if (ref($settings) eq 'HASH') {
4967: if (ref($settings->{'adhoc'}) eq 'HASH') {
4968: %current = %{$settings->{'adhoc'}};
4969: }
1.285 raeburn 4970: }
4971: my $count = 0;
4972: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4973: if ($key=~/^rolesdef\_(\w+)$/) {
4974: my $rolename = $1;
1.285 raeburn 4975: my (%privs,$order);
1.282 raeburn 4976: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4977: $customroles{$rolename} = \%privs;
1.285 raeburn 4978: if (ref($current{$rolename}) eq 'HASH') {
4979: $order = $current{$rolename}{'order'};
4980: }
4981: if ($order eq '') {
4982: $order = $count;
4983: }
4984: $ordered{$order} = $rolename;
4985: $count++;
4986: }
4987: }
4988: my $maxnum = scalar(keys(%ordered));
4989: my @roles_by_num = ();
4990: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4991: push(@roles_by_num,$item);
4992: }
4993: my $context = 'domprefs';
4994: my $crstype = 'Course';
4995: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4996: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4997: my ($numstatustypes,@jsarray);
4998: if (ref($types) eq 'ARRAY') {
4999: if (@{$types} > 0) {
5000: $numstatustypes = scalar(@{$types});
5001: push(@accesstypes,'status');
5002: @jsarray = ('bystatus');
1.282 raeburn 5003: }
5004: }
1.290 raeburn 5005: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 5006: if (keys(%domhelpdesk)) {
5007: push(@accesstypes,('inc','exc'));
5008: push(@jsarray,('notinc','notexc'));
5009: }
5010: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 5011: my $context = 'domprefs';
5012: my $crstype = 'Course';
1.285 raeburn 5013: my $prefix = 'helproles_';
5014: my $add_class = 'LC_hidden';
5015: foreach my $num (@roles_by_num) {
5016: my $role = $ordered{$num};
5017: my ($desc,$access,@statuses);
5018: if (ref($current{$role}) eq 'HASH') {
5019: $desc = $current{$role}{'desc'};
5020: $access = $current{$role}{'access'};
5021: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
5022: @statuses = @{$current{$role}{'insttypes'}};
5023: }
5024: }
5025: if ($desc eq '') {
5026: $desc = $role;
5027: }
5028: my $identifier = 'custhelp'.$num;
1.282 raeburn 5029: my %full=();
5030: my %levels= (
5031: course => {},
5032: domain => {},
5033: system => {},
5034: );
5035: my %levelscurrent=(
5036: course => {},
5037: domain => {},
5038: system => {},
5039: );
5040: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5041: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5042: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5043: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5044: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5045: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5046: for (my $k=0; $k<=$maxnum; $k++) {
5047: my $vpos = $k+1;
5048: my $selstr;
5049: if ($k == $num) {
5050: $selstr = ' selected="selected" ';
5051: }
5052: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5053: }
5054: $datatable .= '</select>'.(' 'x2).
5055: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5056: '</td>'.
5057: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5058: &mt('Name shown to users:').
5059: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5060: '</fieldset>'.
5061: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5062: $othertitle,$usertypes,$types,\%domhelpdesk).
5063: '<fieldset>'.
5064: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5065: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5066: \%levelscurrent,$identifier,
5067: 'LC_hidden',$prefix.$num.'_privs').
5068: '</fieldset></td>';
1.282 raeburn 5069: $itemcount ++;
5070: }
5071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5072: my $newcust = 'custhelp'.$count;
5073: my (%privs,%levelscurrent);
5074: my %full=();
5075: my %levels= (
5076: course => {},
5077: domain => {},
5078: system => {},
5079: );
5080: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5081: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5082: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5083: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5084: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5085: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5086: for (my $k=0; $k<$maxnum+1; $k++) {
5087: my $vpos = $k+1;
5088: my $selstr;
5089: if ($k == $maxnum) {
5090: $selstr = ' selected="selected" ';
5091: }
5092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5093: }
5094: $datatable .= '</select> '."\n".
1.282 raeburn 5095: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5096: '</label></span></td>'.
1.285 raeburn 5097: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5098: '<span class="LC_nobreak">'.
5099: &mt('Internal name:').
5100: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5101: '</span>'.(' 'x4).
5102: '<span class="LC_nobreak">'.
5103: &mt('Name shown to users:').
5104: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5105: '</span></fieldset>'.
5106: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5107: $usertypes,$types,\%domhelpdesk).
5108: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5109: &Apache::lonuserutils::custom_role_header($context,$crstype,
5110: \@templateroles,$newcust).
5111: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5112: \%levelscurrent,$newcust).
1.334 raeburn 5113: '</fieldset>'.
5114: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5115: '</td></tr>';
1.282 raeburn 5116: $count ++;
5117: $$rowtotal += $count;
5118: }
1.166 raeburn 5119: return $datatable;
1.121 raeburn 5120: }
5121:
1.285 raeburn 5122: sub adhocbutton {
5123: my ($prefix,$num,$field,$visibility) = @_;
5124: my %lt = &Apache::lonlocal::texthash(
5125: show => 'Show details',
5126: hide => 'Hide details',
5127: );
5128: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5129: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5130: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5131: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5132: }
5133:
5134: sub helpsettings_javascript {
5135: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5136: return unless(ref($roles_by_num) eq 'ARRAY');
5137: my %html_js_lt = &Apache::lonlocal::texthash(
5138: show => 'Show details',
5139: hide => 'Hide details',
5140: );
5141: &html_escape(\%html_js_lt);
5142: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5143: return <<"ENDSCRIPT";
5144: <script type="text/javascript">
5145: // <![CDATA[
5146:
5147: function reorderHelpRoles(form,item) {
5148: var changedVal;
5149: $jstext
5150: var newpos = 'helproles_${total}_pos';
5151: var maxh = 1 + $total;
5152: var current = new Array();
5153: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5154: if (item == newpos) {
5155: changedVal = newitemVal;
5156: } else {
5157: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5158: current[newitemVal] = newpos;
5159: }
5160: for (var i=0; i<helproles.length; i++) {
5161: var elementName = 'helproles_'+helproles[i]+'_pos';
5162: if (elementName != item) {
5163: if (form.elements[elementName]) {
5164: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5165: current[currVal] = elementName;
5166: }
5167: }
5168: }
5169: var oldVal;
5170: for (var j=0; j<maxh; j++) {
5171: if (current[j] == undefined) {
5172: oldVal = j;
5173: }
5174: }
5175: if (oldVal < changedVal) {
5176: for (var k=oldVal+1; k<=changedVal ; k++) {
5177: var elementName = current[k];
5178: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5179: }
5180: } else {
5181: for (var k=changedVal; k<oldVal; k++) {
5182: var elementName = current[k];
5183: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5184: }
5185: }
5186: return;
5187: }
5188:
5189: function helpdeskAccess(num) {
5190: var curraccess = null;
5191: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5192: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5193: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5194: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5195: }
5196: }
5197: }
5198: var shown = Array();
5199: var hidden = Array();
5200: if (curraccess == 'none') {
5201: hidden = Array('$hiddenstr');
5202: } else {
5203: if (curraccess == 'status') {
5204: shown = Array('bystatus');
5205: hidden = Array('notinc','notexc');
5206: } else {
5207: if (curraccess == 'exc') {
5208: shown = Array('notexc');
5209: hidden = Array('notinc','bystatus');
5210: }
5211: if (curraccess == 'inc') {
5212: shown = Array('notinc');
5213: hidden = Array('notexc','bystatus');
5214: }
1.293 raeburn 5215: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5216: hidden = Array('notinc','notexc','bystatus');
5217: }
5218: }
5219: }
5220: if (hidden.length > 0) {
5221: for (var i=0; i<hidden.length; i++) {
5222: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5223: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5224: }
5225: }
5226: }
5227: if (shown.length > 0) {
5228: for (var i=0; i<shown.length; i++) {
5229: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5230: if (shown[i] == 'privs') {
5231: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5232: } else {
5233: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5234: }
5235: }
5236: }
5237: }
5238: return;
5239: }
5240:
5241: function toggleHelpdeskItem(num,field) {
5242: if (document.getElementById('helproles_'+num+'_'+field)) {
5243: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5244: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5245: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5246: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5247: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5248: }
5249: } else {
5250: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5251: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5252: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5253: }
5254: }
5255: }
5256: return;
5257: }
5258:
5259: // ]]>
5260: </script>
5261:
5262: ENDSCRIPT
5263: }
5264:
5265: sub helpdeskroles_access {
5266: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5267: $usertypes,$types,$domhelpdesk) = @_;
5268: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5269: my %lt = &Apache::lonlocal::texthash(
5270: 'rou' => 'Role usage',
5271: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5272: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5273: 'dh' => 'All with domain helpdesk role',
5274: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5275: 'none' => 'None',
5276: 'status' => 'Determined based on institutional status',
5277: 'inc' => 'Include all, but exclude specific personnel',
5278: 'exc' => 'Exclude all, but include specific personnel',
5279: );
5280: my %usecheck = (
5281: all => ' checked="checked"',
5282: );
5283: my %displaydiv = (
5284: status => 'none',
5285: inc => 'none',
5286: exc => 'none',
5287: priv => 'block',
5288: );
5289: my $output;
5290: if (ref($current) eq 'HASH') {
5291: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5292: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5293: $usecheck{$current->{access}} = $usecheck{'all'};
5294: delete($usecheck{'all'});
5295: if ($current->{access} =~ /^(status|inc|exc)$/) {
5296: my $access = $1;
5297: $displaydiv{$access} = 'inline';
5298: } elsif ($current->{access} eq 'none') {
5299: $displaydiv{'priv'} = 'none';
5300: }
5301: }
5302: }
5303: }
5304: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5305: '<p>'.$lt{'whi'}.'</p>';
5306: foreach my $access (@{$accesstypes}) {
5307: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5308: ' onclick="helpdeskAccess('."'$num'".');" />'.
5309: $lt{$access}.'</label>';
5310: if ($access eq 'status') {
5311: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5312: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5313: $othertitle,$usertypes,$types).
5314: '</div>';
5315: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5316: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5317: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5318: '</div>';
5319: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5320: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5321: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5322: '</div>';
5323: }
5324: $output .= '</p>';
5325: }
5326: $output .= '</fieldset>';
5327: return $output;
5328: }
5329:
1.121 raeburn 5330: sub radiobutton_prefs {
1.192 raeburn 5331: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5332: $additional,$align,$firstval) = @_;
1.121 raeburn 5333: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5334: (ref($choices) eq 'HASH'));
5335:
1.170 raeburn 5336: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5337:
5338: foreach my $item (@{$toggles}) {
5339: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5340: $checkedon{$item} = ' checked="checked" ';
5341: $checkedoff{$item} = ' ';
1.121 raeburn 5342: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5343: $checkedoff{$item} = ' checked="checked" ';
5344: $checkedon{$item} = ' ';
5345: }
5346: }
5347: if (ref($settings) eq 'HASH') {
1.121 raeburn 5348: foreach my $item (@{$toggles}) {
1.118 jms 5349: if ($settings->{$item} eq '1') {
5350: $checkedon{$item} = ' checked="checked" ';
5351: $checkedoff{$item} = ' ';
5352: } elsif ($settings->{$item} eq '0') {
5353: $checkedoff{$item} = ' checked="checked" ';
5354: $checkedon{$item} = ' ';
5355: }
5356: }
1.121 raeburn 5357: }
1.192 raeburn 5358: if ($onclick) {
5359: $onclick = ' onclick="'.$onclick.'"';
5360: }
1.121 raeburn 5361: foreach my $item (@{$toggles}) {
1.118 jms 5362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5363: $datatable .=
1.306 raeburn 5364: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5365: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5366: '</span></td>';
5367: if ($align eq 'left') {
5368: $datatable .= '<td class="LC_left_item">';
5369: } else {
5370: $datatable .= '<td class="LC_right_item">';
5371: }
1.385 raeburn 5372: $datatable .= '<span class="LC_nobreak">';
5373: if ($firstval eq 'no') {
5374: $datatable .=
5375: '<label><input type="radio" name="'.
5376: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5377: '</label> <label><input type="radio" name="'.$item.'" '.
5378: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5379: } else {
5380: $datatable .=
5381: '<label><input type="radio" name="'.
5382: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5383: '</label> <label><input type="radio" name="'.$item.'" '.
5384: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5385: }
5386: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5387: $itemcount ++;
1.121 raeburn 5388: }
5389: return ($datatable,$itemcount);
5390: }
5391:
1.267 raeburn 5392: sub print_ltitools {
5393: my ($dom,$settings,$rowtotal) = @_;
5394: my $rownum = 0;
5395: my $css_class;
5396: my $itemcount = 1;
5397: my $maxnum = 0;
5398: my %ordered;
5399: if (ref($settings) eq 'HASH') {
5400: foreach my $item (keys(%{$settings})) {
5401: if (ref($settings->{$item}) eq 'HASH') {
5402: my $num = $settings->{$item}{'order'};
5403: $ordered{$num} = $item;
5404: }
5405: }
5406: }
5407: my $confname = $dom.'-domainconfig';
5408: my $switchserver = &check_switchserver($dom,$confname);
5409: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5410: my $datatable;
1.267 raeburn 5411: my %lt = <itools_names();
5412: my @courseroles = ('cc','in','ta','ep','st');
5413: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 5414: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 5415: if (keys(%ordered)) {
5416: my @items = sort { $a <=> $b } keys(%ordered);
5417: for (my $i=0; $i<@items; $i++) {
5418: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5419: my $item = $ordered{$items[$i]};
1.323 raeburn 5420: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 5421: if (ref($settings->{$item}) eq 'HASH') {
5422: $title = $settings->{$item}->{'title'};
5423: $url = $settings->{$item}->{'url'};
5424: $key = $settings->{$item}->{'key'};
5425: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 5426: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 5427: my $image = $settings->{$item}->{'image'};
5428: if ($image ne '') {
5429: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
5430: }
1.323 raeburn 5431: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
5432: $sigsel{'HMAC-256'} = ' selected="selected"';
5433: } else {
5434: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
5435: }
1.267 raeburn 5436: }
1.319 raeburn 5437: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 5438: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5439: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
5440: for (my $k=0; $k<=$maxnum; $k++) {
5441: my $vpos = $k+1;
5442: my $selstr;
5443: if ($k == $i) {
5444: $selstr = ' selected="selected" ';
5445: }
5446: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5447: }
5448: $datatable .= '</select>'.(' 'x2).
5449: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
5450: &mt('Delete?').'</label></span></td>'.
5451: '<td colspan="2">'.
5452: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5453: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 5454: (' 'x2).
5455: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
5456: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5457: (' 'x2).
5458: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
5459: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5460: (' 'x2).
5461: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
5462: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
5463: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 5464: '<br /><br />'.
1.323 raeburn 5465: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 5466: ' value="'.$url.'" /></span>'.
5467: (' 'x2).
1.319 raeburn 5468: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 5469: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
5470: (' 'x2).
1.322 raeburn 5471: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
5472: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
5473: (' 'x2).
1.267 raeburn 5474: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5475: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
5476: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5477: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
5478: '</fieldset>'.
5479: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5480: '<span class="LC_nobreak">'.&mt('Display target:');
5481: my %currdisp;
5482: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
5483: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
5484: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 5485: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
5486: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 5487: } else {
5488: $currdisp{'iframe'} = ' checked="checked"';
5489: }
5490: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
5491: $currdisp{'width'} = $1;
5492: }
5493: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
5494: $currdisp{'height'} = $1;
5495: }
1.296 raeburn 5496: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
5497: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 5498: } else {
5499: $currdisp{'iframe'} = ' checked="checked"';
5500: }
1.298 raeburn 5501: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5502: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
5503: $lt{$disp}.'</label>'.(' 'x2);
5504: }
5505: $datatable .= (' 'x4);
5506: foreach my $dimen ('width','height') {
5507: $datatable .= '<label>'.$lt{$dimen}.' '.
5508: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
5509: (' 'x2);
5510: }
1.334 raeburn 5511: $datatable .= '</span><br />'.
1.296 raeburn 5512: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5513: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 5514: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5515: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5516: '</textarea></div><div style=""></div><br />';
1.319 raeburn 5517: my %units = (
5518: 'passback' => 'days',
5519: 'roster' => 'seconds',
5520: );
1.267 raeburn 5521: foreach my $extra ('passback','roster') {
1.319 raeburn 5522: my $validsty = 'none';
5523: my $currvalid;
1.267 raeburn 5524: my $checkedon = '';
5525: my $checkedoff = ' checked="checked"';
5526: if ($settings->{$item}->{$extra}) {
5527: $checkedon = $checkedoff;
5528: $checkedoff = '';
1.319 raeburn 5529: $validsty = 'inline-block';
5530: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
5531: $currvalid = $settings->{$item}->{$extra.'valid'};
5532: }
5533: }
5534: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
5535: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5536: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
5537: &mt('No').'</label>'.(' 'x2).
5538: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
5539: &mt('Yes').'</label></span></div>'.
5540: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
5541: '<span class="LC_nobreak">'.
5542: &mt("at least [_1] $units{$extra} after launch",
5543: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
5544: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5545: }
1.319 raeburn 5546: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 5547: if ($imgsrc) {
5548: $datatable .= $imgsrc.
5549: '<label><input type="checkbox" name="ltitools_image_del"'.
5550: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5551: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5552: } else {
5553: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5554: }
5555: if ($switchserver) {
5556: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5557: } else {
5558: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5559: }
5560: $datatable .= '</span></fieldset>';
1.324 raeburn 5561: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5562: if (ref($settings->{$item}) eq 'HASH') {
5563: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5564: %checkedfields = %{$settings->{$item}->{'fields'}};
5565: }
1.324 raeburn 5566: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5567: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5568: %rolemaps = %{$settings->{$item}->{'roles'}};
5569: $checkedfields{'roles'} = 1;
5570: }
5571: }
5572: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5573: '<span class="LC_nobreak">';
1.324 raeburn 5574: my $userfieldstyle = 'display:none;';
5575: my $seluserdom = '';
5576: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5577: foreach my $field (@fields) {
1.324 raeburn 5578: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5579: if ($checkedfields{$field}) {
5580: $checked = ' checked="checked"';
5581: }
1.324 raeburn 5582: if ($field eq 'user') {
5583: $id = ' id="ltitools_user_field_'.$i.'"';
5584: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5585: if ($checked) {
5586: $userfieldstyle = 'display:inline-block';
5587: if ($userincdom) {
5588: $seluserdom = $unseluserdom;
5589: $unseluserdom = '';
5590: }
5591: }
5592: } else {
5593: $spacer = (' ' x2);
5594: }
1.267 raeburn 5595: $datatable .= '<label>'.
1.324 raeburn 5596: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5597: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5598: }
1.324 raeburn 5599: $datatable .= '</span>';
5600: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5601: '<span class="LC_nobreak"> : '.
5602: '<select name="ltitools_userincdom_'.$i.'">'.
5603: '<option value="">'.&mt('Select').'</option>'.
5604: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5605: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5606: '</select></span></div>';
5607: $datatable .= '</fieldset>'.
1.267 raeburn 5608: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5609: foreach my $role (@courseroles) {
5610: my ($selected,$selectnone);
5611: if (!$rolemaps{$role}) {
5612: $selectnone = ' selected="selected"';
5613: }
1.306 raeburn 5614: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5615: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5616: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5617: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5618: foreach my $ltirole (@ltiroles) {
5619: unless ($selectnone) {
5620: if ($rolemaps{$role} eq $ltirole) {
5621: $selected = ' selected="selected"';
5622: } else {
5623: $selected = '';
5624: }
5625: }
5626: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5627: }
5628: $datatable .= '</select></td>';
5629: }
1.273 raeburn 5630: $datatable .= '</tr></table></fieldset>';
5631: my %courseconfig;
5632: if (ref($settings->{$item}) eq 'HASH') {
5633: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5634: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5635: }
5636: }
5637: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5638: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5639: my $checked;
5640: if ($courseconfig{$item}) {
5641: $checked = ' checked="checked"';
5642: }
5643: $datatable .= '<label>'.
5644: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5645: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5646: }
5647: $datatable .= '</span></fieldset>'.
1.267 raeburn 5648: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5649: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5650: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5651: my %custom = %{$settings->{$item}->{'custom'}};
5652: if (keys(%custom) > 0) {
5653: foreach my $key (sort(keys(%custom))) {
5654: $datatable .= '<tr><td><span class="LC_nobreak">'.
5655: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5656: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5657: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5658: ' value="'.$custom{$key}.'" /></td></tr>';
5659: }
5660: }
5661: }
5662: $datatable .= '<tr><td><span class="LC_nobreak">'.
5663: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5664: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5665: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5666: $datatable .= '</table></fieldset></td></tr>'."\n";
5667: $itemcount ++;
5668: }
5669: }
5670: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5671: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5672: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5673: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5674: '<select name="ltitools_add_pos"'.$chgstr.'>';
5675: for (my $k=0; $k<$maxnum+1; $k++) {
5676: my $vpos = $k+1;
5677: my $selstr;
5678: if ($k == $maxnum) {
5679: $selstr = ' selected="selected" ';
5680: }
5681: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5682: }
5683: $datatable .= '</select> '."\n".
1.334 raeburn 5684: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5685: '<td colspan="2">'.
5686: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5687: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5688: (' 'x2).
5689: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5690: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5691: (' 'x2).
5692: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5693: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5694: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5695: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5696: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5697: '<br />'.
1.323 raeburn 5698: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5699: (' 'x2).
5700: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5701: (' 'x2).
1.322 raeburn 5702: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5703: (' 'x2).
1.267 raeburn 5704: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5705: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
5706: '</fieldset>'.
5707: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5708: '<span class="LC_nobreak">'.&mt('Display target:');
5709: my %defaultdisp;
5710: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5711: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5712: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5713: $lt{$disp}.'</label>'.(' 'x2);
5714: }
5715: $datatable .= (' 'x4);
5716: foreach my $dimen ('width','height') {
5717: $datatable .= '<label>'.$lt{$dimen}.' '.
5718: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5719: (' 'x2);
5720: }
1.334 raeburn 5721: $datatable .= '</span><br />'.
1.296 raeburn 5722: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5723: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5724: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5725: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5726: '</div><div style=""></div><br />';
1.319 raeburn 5727: my %units = (
5728: 'passback' => 'days',
5729: 'roster' => 'seconds',
5730: );
5731: my %defaulttimes = (
5732: 'passback' => '7',
1.322 raeburn 5733: 'roster' => '300',
1.319 raeburn 5734: );
1.267 raeburn 5735: foreach my $extra ('passback','roster') {
1.319 raeburn 5736: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5737: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5738: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5739: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5740: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5741: &mt('Yes').'</label></span></div>'.
5742: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5743: '<span class="LC_nobreak">'.
5744: &mt("at least [_1] $units{$extra} after launch",
5745: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5746: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5747: }
1.319 raeburn 5748: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5749: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5750: if ($switchserver) {
5751: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5752: } else {
5753: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5754: }
5755: $datatable .= '</span></fieldset>'.
5756: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5757: '<span class="LC_nobreak">';
5758: foreach my $field (@fields) {
1.324 raeburn 5759: my ($id,$onclick,$spacer);
5760: if ($field eq 'user') {
5761: $id = ' id="ltitools_user_field_add"';
5762: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5763: } else {
5764: $spacer = (' ' x2);
5765: }
1.267 raeburn 5766: $datatable .= '<label>'.
1.324 raeburn 5767: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5768: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5769: }
1.324 raeburn 5770: $datatable .= '</span>'.
5771: '<div style="display:none;" id="ltitools_user_div_add">'.
5772: '<span class="LC_nobreak"> : '.
5773: '<select name="ltitools_userincdom_add">'.
5774: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5775: '<option value="0">'.&mt('username').'</option>'.
5776: '<option value="1">'.&mt('username:domain').'</option>'.
5777: '</select></span></div></fieldset>';
5778: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5779: foreach my $role (@courseroles) {
5780: my ($checked,$checkednone);
1.306 raeburn 5781: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5782: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5783: '<select name="ltitools_add_roles_'.$role.'">'.
5784: '<option value="" selected="selected">'.&mt('Select').'</option>';
5785: foreach my $ltirole (@ltiroles) {
5786: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5787: }
5788: $datatable .= '</select></td>';
5789: }
5790: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5791: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5792: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5793: $datatable .= '<label>'.
5794: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5795: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5796: }
5797: $datatable .= '</span></fieldset>'.
1.267 raeburn 5798: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5799: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5800: '<tr><td><span class="LC_nobreak">'.
5801: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5802: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5803: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5804: '</table></fieldset>'."\n".
1.267 raeburn 5805: '</td>'."\n".
5806: '</tr>'."\n";
5807: $itemcount ++;
5808: return $datatable;
5809: }
5810:
5811: sub ltitools_names {
5812: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5813: 'title' => 'Title',
5814: 'version' => 'Version',
5815: 'msgtype' => 'Message Type',
1.323 raeburn 5816: 'sigmethod' => 'Signature Method',
1.296 raeburn 5817: 'url' => 'URL',
5818: 'key' => 'Key',
1.322 raeburn 5819: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5820: 'secret' => 'Secret',
5821: 'icon' => 'Icon',
1.324 raeburn 5822: 'user' => 'User',
1.296 raeburn 5823: 'fullname' => 'Full Name',
5824: 'firstname' => 'First Name',
5825: 'lastname' => 'Last Name',
5826: 'email' => 'E-mail',
5827: 'roles' => 'Role',
1.298 raeburn 5828: 'window' => 'Window',
5829: 'tab' => 'Tab',
1.296 raeburn 5830: 'iframe' => 'iFrame',
5831: 'height' => 'Height',
5832: 'width' => 'Width',
5833: 'linktext' => 'Default Link Text',
5834: 'explanation' => 'Default Explanation',
5835: 'passback' => 'Tool can return grades:',
5836: 'roster' => 'Tool can retrieve roster:',
5837: 'crstarget' => 'Display target',
5838: 'crslabel' => 'Course label',
5839: 'crstitle' => 'Course title',
5840: 'crslinktext' => 'Link Text',
5841: 'crsexplanation' => 'Explanation',
1.318 raeburn 5842: 'crsappend' => 'Provider URL',
1.267 raeburn 5843: );
5844: return %lt;
5845: }
5846:
1.372 raeburn 5847: sub print_proctoring {
5848: my ($dom,$settings,$rowtotal) = @_;
5849: my $itemcount = 1;
5850: my (%ordered,%providernames,%current,%currentdef);
5851: my $confname = $dom.'-domainconfig';
5852: my $switchserver = &check_switchserver($dom,$confname);
5853: if (ref($settings) eq 'HASH') {
5854: foreach my $item (keys(%{$settings})) {
5855: if (ref($settings->{$item}) eq 'HASH') {
5856: my $num = $settings->{$item}{'order'};
5857: $ordered{$num} = $item;
5858: }
5859: }
5860: } else {
5861: %ordered = (
5862: 1 => 'proctorio',
5863: 2 => 'examity',
5864: );
5865: }
5866: %providernames = &proctoring_providernames();
5867: my $maxnum = scalar(keys(%ordered));
5868: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5869: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5870: if (ref($requref) eq 'HASH') {
5871: %requserfields = %{$requref};
5872: }
5873: if (ref($opturef) eq 'HASH') {
5874: %optuserfields = %{$opturef};
5875: }
5876: if (ref($defref) eq 'HASH') {
5877: %defaults = %{$defref};
5878: }
5879: if (ref($extref) eq 'HASH') {
5880: %extended = %{$extref};
5881: }
5882: if (ref($crsref) eq 'HASH') {
5883: %crsconf = %{$crsref};
5884: }
5885: if (ref($rolesref) eq 'ARRAY') {
5886: @courseroles = @{$rolesref};
5887: }
5888: if (ref($ltiref) eq 'ARRAY') {
5889: @ltiroles = @{$ltiref};
5890: }
5891: my $datatable;
5892: my $css_class;
5893: if (keys(%ordered)) {
5894: my @items = sort { $a <=> $b } keys(%ordered);
5895: for (my $i=0; $i<@items; $i++) {
5896: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5897: my $provider = $ordered{$items[$i]};
5898: my $optionsty = 'none';
5899: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5900: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5901: if (ref($settings) eq 'HASH') {
5902: if (ref($settings->{$provider}) eq 'HASH') {
5903: %current = %{$settings->{$provider}};
5904: if ($current{'available'}) {
5905: $optionsty = 'block';
5906: $available = 1;
5907: }
5908: if ($current{'lifetime'} =~ /^\d+$/) {
5909: $lifetime = $current{'lifetime'};
5910: }
5911: if ($current{'version'} =~ /^\d+\.\d+$/) {
5912: $version = $current{'version'};
5913: }
5914: if ($current{'image'} ne '') {
5915: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5916: }
5917: if (ref($current{'fields'}) eq 'ARRAY') {
5918: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5919: }
5920: $userincdom = $current{'incdom'};
5921: if (ref($current{'roles'}) eq 'HASH') {
5922: %rolemaps = %{$current{'roles'}};
5923: $checkedfields{'roles'} = 1;
5924: }
5925: if (ref($current{'defaults'}) eq 'ARRAY') {
5926: foreach my $val (@{$current{'defaults'}}) {
5927: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5928: $inuse{$val} = 1;
5929: } else {
5930: foreach my $poss (keys(%{$extended{$provider}})) {
5931: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5932: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5933: $inuse{$poss} = $val;
5934: last;
5935: }
5936: }
5937: }
5938: }
5939: }
5940: } elsif (ref($current{'defaults'}) eq 'HASH') {
5941: foreach my $key (keys(%{$current{'defaults'}})) {
5942: my $currval = $current{'defaults'}{$key};
5943: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5944: $inuse{$key} = 1;
5945: } else {
5946: my $match;
5947: foreach my $poss (keys(%{$extended{$provider}})) {
5948: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5949: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5950: $inuse{$poss} = $key;
5951: last;
5952: }
5953: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5954: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5955: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5956: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5957: $currentdef{$inner} = $currval;
5958: $match = 1;
5959: last;
5960: }
5961: } elsif ($inner eq $key) {
5962: $currentdef{$key} = $currval;
5963: $match = 1;
5964: last;
5965: }
5966: }
5967: }
5968: last if ($match);
5969: }
5970: }
5971: }
5972: }
5973: if (ref($current{'crsconf'}) eq 'ARRAY') {
5974: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5975: }
5976: }
5977: }
5978: my %lt = &proctoring_titles($provider);
5979: my %fieldtitles = &proctoring_fieldtitles($provider);
5980: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5981: my %checkedavailable = (
5982: yes => '',
5983: no => ' checked="checked"',
5984: );
5985: if ($available) {
5986: $checkedavailable{'yes'} = $checkedavailable{'no'};
5987: $checkedavailable{'no'} = '';
5988: }
5989: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5990: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5991: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5992: for (my $k=0; $k<$maxnum; $k++) {
5993: my $vpos = $k+1;
5994: my $selstr;
5995: if ($k == $i) {
5996: $selstr = ' selected="selected" ';
5997: }
5998: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5999: }
6000: if ($version eq '') {
6001: if ($provider eq 'proctorio') {
6002: $version = '1.0';
6003: } elsif ($provider eq 'examity') {
6004: $version = '1.1';
6005: }
6006: }
6007: if ($lifetime eq '') {
6008: $lifetime = '300';
6009: }
6010: $datatable .=
6011: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
6012: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
6013: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
6014: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
6015: '</td>'.
6016: '<td colspan="2">'.
6017: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
6018: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
6019: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
6020: (' 'x2).
6021: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
6022: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6023: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6024: (' 'x2).
6025: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
6026: '<br />'.
6027: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
6028: '<br />'.
6029: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
6030: (' 'x2).
6031: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
6032: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
6033: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6034: if ($imgsrc) {
6035: $datatable .= $imgsrc.
6036: '<label><input type="checkbox" name="proctoring_image_del"'.
6037: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
6038: '<span class="LC_nobreak"> '.&mt('Replace:');
6039: }
6040: $datatable .= ' ';
6041: if ($switchserver) {
6042: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6043: } else {
6044: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
6045: }
6046: unless ($imgsrc) {
6047: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
6048: }
6049: $datatable .= '</fieldset>'."\n";
6050: if (ref($requserfields{$provider}) eq 'ARRAY') {
6051: if (@{$requserfields{$provider}} > 0) {
6052: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
6053: foreach my $field (@{$requserfields{$provider}}) {
6054: $datatable .= '<span class="LC_nobreak">'.
6055: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
6056: $lt{$field}.'</label>';
6057: if ($field eq 'user') {
6058: my $seluserdom = '';
6059: my $unseluserdom = ' selected="selected"';
6060: if ($userincdom) {
6061: $seluserdom = $unseluserdom;
6062: $unseluserdom = '';
6063: }
6064: $datatable .= ': '.
6065: '<select name="proctoring_userincdom_'.$provider.'">'.
6066: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
6067: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
6068: '</select> ';
6069: } else {
6070: $datatable .= ' ';
6071: if ($field eq 'roles') {
6072: $showroles = 1;
6073: }
6074: }
6075: $datatable .= '</span> ';
6076: }
6077: }
6078: $datatable .= '</fieldset>'."\n";
6079: }
6080: if (ref($optuserfields{$provider}) eq 'ARRAY') {
6081: if (@{$optuserfields{$provider}} > 0) {
6082: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
6083: foreach my $field (@{$optuserfields{$provider}}) {
6084: my $checked;
6085: if ($checkedfields{$field}) {
6086: $checked = ' checked="checked"';
6087: }
6088: $datatable .= '<span class="LC_nobreak">'.
6089: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
6090: }
6091: $datatable .= '</fieldset>'."\n";
6092: }
6093: }
6094: if (ref($defaults{$provider}) eq 'ARRAY') {
6095: if (@{$defaults{$provider}}) {
6096: my (%options,@selectboxes);
6097: if (ref($extended{$provider}) eq 'HASH') {
6098: %options = %{$extended{$provider}};
6099: }
6100: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
6101: my ($rem,$numinrow,$dropdowns);
6102: if ($provider eq 'proctorio') {
6103: $datatable .= '<table>';
6104: $numinrow = 4;
6105: }
6106: my $i = 0;
6107: foreach my $field (@{$defaults{$provider}}) {
6108: my $checked;
6109: if ($inuse{$field}) {
6110: $checked = ' checked="checked"';
6111: }
6112: if ($provider eq 'examity') {
6113: if ($field eq 'display') {
6114: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
6115: foreach my $option ('iframe','tab','window') {
6116: my $checkdisp;
6117: if ($currentdef{'target'} eq $option) {
6118: $checkdisp = ' checked="checked"';
6119: }
6120: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
6121: $fieldtitles{$option}.'</label>'.(' 'x2);
6122: }
6123: $datatable .= (' 'x4);
6124: foreach my $dimen ('width','height') {
6125: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
6126: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
6127: 'value="'.$currentdef{$dimen}.'" /></label>'.
6128: (' 'x2);
6129: }
6130: $datatable .= '</span><br />'.
6131: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
6132: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
6133: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
6134: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
6135: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
6136: $currentdef{'explanation'}.
6137: '</textarea></div><div style=""></div><br />';
6138: }
6139: } else {
6140: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
6141: my ($output,$selnone);
6142: unless ($checked) {
6143: $selnone = ' selected="selected"';
6144: }
6145: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
6146: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
6147: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
6148: foreach my $option (@{$options{$field}}) {
6149: my $sel;
6150: if ($inuse{$field} eq $option) {
6151: $sel = ' selected="selected"';
6152: }
6153: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
6154: }
6155: $output .= '</select></span>';
6156: push(@selectboxes,$output);
6157: } else {
6158: $rem = $i%($numinrow);
6159: if ($rem == 0) {
6160: if ($i > 0) {
6161: $datatable .= '</tr>';
6162: }
6163: $datatable .= '<tr>';
6164: }
6165: $datatable .= '<td class="LC_left_item">'.
6166: '<span class="LC_nobreak">'.
6167: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
6168: $fieldtitles{$field}.'</label></span></td>';
6169: $i++;
6170: }
6171: }
6172: }
6173: if ($provider eq 'proctorio') {
6174: if ($numinrow) {
6175: $rem = $i%$numinrow;
6176: }
6177: my $colsleft = $numinrow - $rem;
6178: if ($colsleft > 1) {
6179: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6180: } else {
6181: $datatable .= '<td class="LC_left_item">';
6182: }
6183: $datatable .= ' '.
6184: '</td></tr></table>';
6185: if (@selectboxes) {
6186: $datatable .= '<hr /><table>';
6187: $numinrow = 2;
6188: for (my $i=0; $i<@selectboxes; $i++) {
6189: $rem = $i%($numinrow);
6190: if ($rem == 0) {
6191: if ($i > 0) {
6192: $datatable .= '</tr>';
6193: }
6194: $datatable .= '<tr>';
6195: }
6196: $datatable .= '<td class="LC_left_item">'.
6197: $selectboxes[$i].'</td>';
6198: }
6199: if ($numinrow) {
6200: $rem = $i%$numinrow;
6201: }
6202: $colsleft = $numinrow - $rem;
6203: if ($colsleft > 1) {
6204: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6205: } else {
6206: $datatable .= '<td class="LC_left_item">';
6207: }
6208: $datatable .= ' '.
6209: '</td></tr></table>';
6210: }
6211: }
6212: $datatable .= '</fieldset>';
6213: }
6214: if (ref($crsconf{$provider}) eq 'ARRAY') {
6215: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6216: '<legend>'.&mt('Configurable in course').'</legend>';
6217: my ($rem,$numinrow);
6218: if ($provider eq 'proctorio') {
6219: $datatable .= '<table>';
6220: $numinrow = 4;
6221: }
6222: my $i = 0;
6223: foreach my $item (@{$crsconf{$provider}}) {
6224: my $name;
6225: if ($provider eq 'examity') {
6226: $name = $lt{'crs'.$item};
6227: } elsif ($provider eq 'proctorio') {
6228: $name = $fieldtitles{$item};
6229: $rem = $i%($numinrow);
6230: if ($rem == 0) {
6231: if ($i > 0) {
6232: $datatable .= '</tr>';
6233: }
6234: $datatable .= '<tr>';
6235: }
6236: $datatable .= '<td class="LC_left_item>';
6237: }
6238: my $checked;
6239: if ($crsconfig{$item}) {
6240: $checked = ' checked="checked"';
6241: }
6242: $datatable .= '<span class="LC_nobreak"><label>'.
6243: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
6244: $name.'</label></span>';
6245: if ($provider eq 'examity') {
6246: $datatable .= ' ';
6247: }
6248: $datatable .= "\n";
6249: $i++;
6250: }
6251: if ($provider eq 'proctorio') {
6252: if ($numinrow) {
6253: $rem = $i%$numinrow;
6254: }
6255: my $colsleft = $numinrow - $rem;
6256: if ($colsleft > 1) {
6257: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6258: } else {
6259: $datatable .= '<td class="LC_left_item">';
6260: }
6261: $datatable .= ' '.
6262: '</td></tr></table>';
6263: }
6264: $datatable .= '</fieldset>';
6265: }
6266: if ($showroles) {
6267: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6268: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
6269: foreach my $role (@courseroles) {
6270: my ($selected,$selectnone);
6271: if (!$rolemaps{$role}) {
6272: $selectnone = ' selected="selected"';
6273: }
6274: $datatable .= '<td style="text-align: center">'.
6275: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6276: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
6277: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6278: foreach my $ltirole (@ltiroles) {
6279: unless ($selectnone) {
6280: if ($rolemaps{$role} eq $ltirole) {
6281: $selected = ' selected="selected"';
6282: } else {
6283: $selected = '';
6284: }
6285: }
6286: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6287: }
6288: $datatable .= '</select></td>';
6289: }
6290: $datatable .= '</tr></table></fieldset>'.
6291: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6292: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6293: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6294: '<tr><td></td><td>lms</td>'.
6295: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6296: ' value="Loncapa" disabled="disabled"/></td></tr>';
6297: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6298: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6299: my %custom = %{$settings->{$provider}->{'custom'}};
6300: if (keys(%custom) > 0) {
6301: foreach my $key (sort(keys(%custom))) {
6302: next if ($key eq 'lms');
6303: $datatable .= '<tr><td><span class="LC_nobreak">'.
6304: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6305: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6306: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6307: ' value="'.$custom{$key}.'" /></td></tr>';
6308: }
6309: }
6310: }
6311: $datatable .= '<tr><td><span class="LC_nobreak">'.
6312: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6313: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6314: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6315: '</table></fieldset></td></tr>'."\n";
6316: }
6317: $datatable .= '</td></tr>';
6318: }
6319: $itemcount ++;
6320: }
6321: }
6322: return $datatable;
6323: }
6324:
6325: sub proctoring_data {
6326: my $requserfields = {
6327: proctorio => ['user'],
6328: examity => ['roles','user'],
6329: };
6330: my $optuserfields = {
6331: proctorio => ['fullname'],
6332: examity => ['fullname','firstname','lastname','email'],
6333: };
6334: my $defaults = {
6335: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6336: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6337: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6338: 'closetabs','onescreen','print','downloads','cache','rightclick',
6339: 'reentry','calculator','whiteboard'],
6340: examity => ['display'],
6341: };
6342: my $extended = {
6343: proctorio => {
6344: verifyid => ['verifyidauto','verifyidlive'],
6345: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6346: tabslinks => ['notabs','linksonly'],
6347: reentry => ['noreentry','agentreentry'],
6348: calculator => ['calculatorbasic','calculatorsci'],
6349: },
6350: examity => {
6351: display => {
6352: target => ['iframe','tab','window'],
6353: width => '',
6354: height => '',
6355: linktext => '',
6356: explanation => '',
6357: },
6358: },
6359: };
6360: my $crsconf = {
6361: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6362: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6363: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6364: 'closetabs','onescreen','print','downloads','cache','rightclick',
6365: 'reentry','calculator','whiteboard'],
6366: examity => ['label','title','target','linktext','explanation','append'],
6367: };
6368: my $courseroles = ['cc','in','ta','ep','st'];
6369: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6370: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6371: }
6372:
6373: sub proctoring_titles {
6374: my ($item) = @_;
6375: my (%common_lt,%custom_lt);
6376: %common_lt = &Apache::lonlocal::texthash (
6377: 'avai' => 'Available?',
6378: 'base' => 'Basic Settings',
6379: 'requ' => 'User data required to be sent on launch',
6380: 'optu' => 'User data optionally sent on launch',
6381: 'udsl' => 'User data sent on launch',
6382: 'defa' => 'Defaults for items configurable in course',
6383: 'sigmethod' => 'Signature Method',
6384: 'key' => 'Key',
6385: 'lifetime' => 'Nonce lifetime (s)',
6386: 'secret' => 'Secret',
6387: 'icon' => 'Icon',
6388: 'fullname' => 'Full Name',
6389: 'visible' => 'Visible input',
6390: 'username' => 'username',
6391: 'user' => 'User',
6392: );
6393: if ($item eq 'proctorio') {
6394: %custom_lt = &Apache::lonlocal::texthash (
6395: 'version' => 'OAuth version',
6396: 'url' => 'API URL',
6397: 'uname:dom' => 'username-domain',
6398: );
6399: } elsif ($item eq 'examity') {
6400: %custom_lt = &Apache::lonlocal::texthash (
6401: 'version' => 'LTI Version',
6402: 'url' => 'URL',
6403: 'uname:dom' => 'username:domain',
6404: 'msgtype' => 'Message Type',
6405: 'firstname' => 'First Name',
6406: 'lastname' => 'Last Name',
6407: 'email' => 'E-mail',
6408: 'roles' => 'Role',
6409: 'crstarget' => 'Display target',
6410: 'crslabel' => 'Course label',
6411: 'crstitle' => 'Course title',
6412: 'crslinktext' => 'Link Text',
6413: 'crsexplanation' => 'Explanation',
6414: 'crsappend' => 'Provider URL',
6415: );
6416: }
6417: my %lt = (%common_lt,%custom_lt);
6418: return %lt;
6419: }
6420:
6421: sub proctoring_fieldtitles {
6422: my ($item) = @_;
6423: if ($item eq 'proctorio') {
6424: return &Apache::lonlocal::texthash (
6425: 'recordvideo' => 'Record video',
6426: 'recordaudio' => 'Record audio',
6427: 'recordscreen' => 'Record screen',
6428: 'recordwebtraffic' => 'Record web traffic',
6429: 'recordroomstart' => 'Record room scan',
6430: 'verifyvideo' => 'Verify webcam',
6431: 'verifyaudio' => 'Verify microphone',
6432: 'verifydesktop' => 'Verify desktop recording',
6433: 'verifyid' => 'Photo ID verification',
6434: 'verifysignature' => 'Require signature',
6435: 'fullscreen' => 'Fullscreen',
6436: 'clipboard' => 'Disable copy/paste',
6437: 'tabslinks' => 'New tabs/windows',
6438: 'closetabs' => 'Close other tabs',
6439: 'onescreen' => 'Limit to single screen',
6440: 'print' => 'Disable Printing',
6441: 'downloads' => 'Disable Downloads',
6442: 'cache' => 'Empty cache after exam',
6443: 'rightclick' => 'Disable right click',
6444: 'reentry' => 'Re-entry to exam',
6445: 'calculator' => 'Onscreen calculator',
6446: 'whiteboard' => 'Onscreen whiteboard',
6447: 'verifyidauto' => 'Automated verification',
6448: 'verifyidlive' => 'Live agent verification',
6449: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6450: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6451: 'fullscreensever' => 'Forced, navigation away ends exam',
6452: 'notabs' => 'Disaallowed',
6453: 'linksonly' => 'Allowed from links in exam',
6454: 'noreentry' => 'Disallowed',
6455: 'agentreentry' => 'Agent required for re-entry',
6456: 'calculatorbasic' => 'Basic',
6457: 'calculatorsci' => 'Scientific',
6458: );
6459: } elsif ($item eq 'examity') {
6460: return &Apache::lonlocal::texthash (
6461: 'target' => 'Display target',
6462: 'window' => 'Window',
6463: 'tab' => 'Tab',
6464: 'iframe' => 'iFrame',
6465: 'height' => 'Height (pixels)',
6466: 'width' => 'Width (pixels)',
6467: 'linktext' => 'Default Link Text',
6468: 'explanation' => 'Default Explanation',
6469: 'append' => 'Provider URL',
6470: );
6471: }
6472: }
6473:
6474: sub proctoring_providernames {
6475: return (
6476: proctorio => 'Proctorio',
6477: examity => 'Examity',
6478: );
6479: }
6480:
1.320 raeburn 6481: sub print_lti {
1.405 raeburn 6482: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6483: my $itemcount = 1;
1.405 raeburn 6484: my ($datatable,$css_class);
6485: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6486: if (ref($settings) eq 'HASH') {
1.405 raeburn 6487: if ($position eq 'top') {
6488: if (exists($settings->{'encrypt'})) {
6489: if (ref($settings->{'encrypt'}) eq 'HASH') {
6490: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6491: if ($key eq 'consumers') {
6492: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6493: } else {
6494: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6495: }
6496: }
6497: }
6498: }
6499: if (exists($settings->{'private'})) {
6500: if (ref($settings->{'private'}) eq 'HASH') {
6501: if (ref($settings->{'private'}) eq 'HASH') {
6502: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6503: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6504: }
6505: }
6506: }
6507: }
6508: } elsif ($position eq 'middle') {
6509: if (exists($settings->{'rules'})) {
6510: if (ref($settings->{'rules'}) eq 'HASH') {
6511: %rules = %{$settings->{'rules'}};
6512: }
6513: }
6514: } elsif ($position eq 'lower') {
6515: if (exists($settings->{'linkprot'})) {
6516: if (ref($settings->{'linkprot'}) eq 'HASH') {
6517: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6518: if ($linkprot{'lock'}) {
6519: delete($linkprot{'lock'});
6520: }
1.405 raeburn 6521: }
6522: }
6523: } else {
6524: foreach my $key ('encrypt','private','rules','linkprot') {
6525: if (exists($settings->{$key})) {
6526: delete($settings->{$key});
1.390 raeburn 6527: }
1.320 raeburn 6528: }
6529: }
6530: }
1.405 raeburn 6531: if ($position eq 'top') {
6532: my @ids=&Apache::lonnet::current_machine_ids();
6533: my %servers = &Apache::lonnet::get_servers($dom,'library');
6534: my $primary = &Apache::lonnet::domain($dom,'primary');
6535: my ($extra,$numshown);
6536: foreach my $hostid (sort(keys(%servers))) {
6537: my ($showextra,$divsty,$switch);
6538: if ($hostid eq $primary) {
6539: if (($encrypt{'ltisec_consumers'}) || ($encrypt{'ltisec_domlinkprot'})) {
6540: $showextra = 1;
6541: }
6542: }
6543: if ($encrypt{'ltisec_crslinkprot'}) {
6544: $showextra = 1;
6545: }
6546: unless (grep(/^\Q$hostid\E$/,@ids)) {
6547: $switch = 1;
6548: }
6549: if ($showextra) {
6550: $numshown ++;
6551: $divsty = 'display:inline-block';
6552: } else {
6553: $divsty = 'display:none';
6554: }
6555: $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
6556: '<legend>'.$hostid.'</legend>';
6557: if ($switch) {
6558: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
6559: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
6560: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6561: if (exists($privkeys{$hostid})) {
6562: $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
6563: '<span class="LC_nobreak">'.
6564: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6565: '<span class="LC_nobreak">'.&mt('Change?').
6566: '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
6567: (' 'x2).
6568: '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
6569: '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
6570: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
6571: '</span></div>';
6572: } else {
6573: $extra .= '<span class="LC_nobreak">'.
6574: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
6575: '</span>'."\n";
6576: }
6577: } elsif (exists($privkeys{$hostid})) {
6578: $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
6579: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6580: '<span class="LC_nobreak">'.&mt('Change?').
6581: '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
6582: (' 'x2).
6583: '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
6584: '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
6585: '<span class="LC_nobreak">'.&mt('New Key').':'.
6586: '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
6587: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
6588: '</span></div>';
6589: } else {
6590: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
6591: '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
6592: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
6593: }
6594: $extra .= '</fieldset>';
6595: }
6596: my %choices = &Apache::lonlocal::texthash (
6597: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
6598: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
6599: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
6600: );
6601: my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
6602: my %defaultchecked = (
6603: 'ltisec_crslinkprot' => 'off',
6604: 'ltisec_domlinkprot' => 'off',
6605: 'ltisec_consumers' => 'off',
6606: );
6607: my ($onclick,$itemcount);
6608: $onclick = 'javascript:toggleLTIEncKey(this.form);';
6609: ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
6610: \%choices,$itemcount,$onclick,'','left','no');
6611:
6612: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6613: my $noprivkeysty = 'display:inline-block';
6614: if ($numshown) {
6615: $noprivkeysty = 'display:none';
6616: }
6617: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
6618: '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
6619: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
6620: $extra.
6621: '</td></tr>';
6622: $itemcount ++;
6623: $$rowtotal += $itemcount;
6624: } elsif ($position eq 'middle') {
6625: $datatable = &password_rules('secrets',\$itemcount,\%rules);
1.406 raeburn 6626: $$rowtotal += $itemcount;
1.405 raeburn 6627: } elsif ($position eq 'lower') {
1.406 raeburn 6628: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.405 raeburn 6629: } else {
6630: my $maxnum = 0;
6631: my %ordered;
6632: if (ref($settings) eq 'HASH') {
6633: foreach my $item (keys(%{$settings})) {
6634: if (ref($settings->{$item}) eq 'HASH') {
6635: my $num = $settings->{$item}{'order'};
6636: if ($num eq '') {
6637: $num = scalar(keys(%{$settings}));
6638: }
6639: $ordered{$num} = $item;
6640: }
1.352 raeburn 6641: }
1.405 raeburn 6642: }
6643: $maxnum = scalar(keys(%ordered));
6644: my %lt = <i_names();
6645: if (keys(%ordered)) {
6646: my @items = sort { $a <=> $b } keys(%ordered);
6647: for (my $i=0; $i<@items; $i++) {
6648: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6649: my $item = $ordered{$items[$i]};
6650: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
6651: if (ref($settings->{$item}) eq 'HASH') {
6652: $key = $settings->{$item}->{'key'};
6653: $secret = $settings->{$item}->{'secret'};
6654: $lifetime = $settings->{$item}->{'lifetime'};
6655: $consumer = $settings->{$item}->{'consumer'};
6656: $requser = $settings->{$item}->{'requser'};
6657: $crsinc = $settings->{$item}->{'crsinc'};
6658: $current = $settings->{$item};
6659: }
6660: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6661: my %checkedrequser = (
6662: yes => ' checked="checked"',
6663: no => '',
6664: );
6665: if (!$requser) {
6666: $checkedrequser{'no'} = $checkedrequser{'yes'};
6667: $checkedrequser{'yes'} = '';
6668: }
6669: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6670: my %checkedcrsinc = (
1.391 raeburn 6671: yes => ' checked="checked"',
6672: no => '',
1.405 raeburn 6673: );
6674: if (!$crsinc) {
6675: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6676: $checkedcrsinc{'yes'} = '';
6677: }
6678: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6679: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6680: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6681: for (my $k=0; $k<=$maxnum; $k++) {
6682: my $vpos = $k+1;
6683: my $selstr;
6684: if ($k == $i) {
6685: $selstr = ' selected="selected" ';
6686: }
6687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6688: }
1.405 raeburn 6689: $datatable .= '</select>'.(' 'x2).
6690: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6691: &mt('Delete?').'</label></span></td>'.
6692: '<td colspan="2">'.
6693: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6694: '<span class="LC_nobreak">'.$lt{'consumer'}.
6695: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6696: (' 'x2).
6697: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6698: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6699: (' 'x2).
6700: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
6701: 'value="'.$lifetime.'" size="3" /></span>'.
6702: (' 'x2).
6703: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6704: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6705: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6706: '<br /><br />'.
6707: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6708: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6709: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6710: (' 'x4).
6711: '<span class="LC_nobreak">'.$lt{'key'}.
6712: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6713: (' 'x2).
6714: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6715: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6716: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
6717: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6718: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6719: $itemcount ++;
1.320 raeburn 6720: }
6721: }
1.405 raeburn 6722: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6723: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6724: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6725: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6726: '<select name="lti_pos_add"'.$chgstr.'>';
6727: for (my $k=0; $k<$maxnum+1; $k++) {
6728: my $vpos = $k+1;
6729: my $selstr;
6730: if ($k == $maxnum) {
6731: $selstr = ' selected="selected" ';
6732: }
6733: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6734: }
1.405 raeburn 6735: $datatable .= '</select> '."\n".
6736: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6737: '<td colspan="2">'.
6738: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6739: '<span class="LC_nobreak">'.$lt{'consumer'}.
6740: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6741: (' 'x2).
6742: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6743: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6744: (' 'x2).
6745: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6746: (' 'x2).
6747: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6748: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6749: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6750: '<br /><br />'.
6751: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6752: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6753: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6754: (' 'x4).
6755: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6756: (' 'x2).
6757: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6758: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
6759: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6760: '</td>'."\n".
6761: '</tr>'."\n";
6762: $itemcount ++;
1.320 raeburn 6763: }
1.405 raeburn 6764: $$rowtotal += $itemcount;
6765: return $datatable;
1.320 raeburn 6766: }
6767:
6768: sub lti_names {
6769: my %lt = &Apache::lonlocal::texthash(
6770: 'version' => 'LTI Version',
6771: 'url' => 'URL',
6772: 'key' => 'Key',
1.322 raeburn 6773: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6774: 'consumer' => 'Consumer',
1.320 raeburn 6775: 'secret' => 'Secret',
1.345 raeburn 6776: 'requser' => "User's identity sent",
1.391 raeburn 6777: 'crsinc' => "Course's identity sent",
1.320 raeburn 6778: 'email' => 'Email address',
6779: 'sourcedid' => 'User ID',
6780: 'other' => 'Other',
6781: 'passback' => 'Can return grades to Consumer:',
6782: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6783: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6784: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6785: );
6786: return %lt;
6787: }
6788:
6789: sub lti_options {
1.325 raeburn 6790: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6791: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6792: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6793: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6794: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6795: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6796: $checked{'mapcrstype'} = {};
6797: $checked{'makeuser'} = {};
6798: $checked{'selfenroll'} = {};
6799: $checked{'crssec'} = {};
6800: $checked{'crssecsrc'} = {};
1.325 raeburn 6801: $checked{'lcauth'} = {};
1.326 raeburn 6802: $checked{'menuitem'} = {};
1.325 raeburn 6803: if ($num eq 'add') {
6804: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6805: }
1.320 raeburn 6806: my $userfieldsty = 'none';
6807: my $crsfieldsty = 'none';
6808: my $crssecfieldsty = 'none';
6809: my $secsrcfieldsty = 'none';
1.363 raeburn 6810: my $callbacksty = 'none';
1.337 raeburn 6811: my $passbacksty = 'none';
1.345 raeburn 6812: my $optionsty = 'block';
1.391 raeburn 6813: my $crssty = 'block';
1.325 raeburn 6814: my $lcauthparm;
6815: my $lcauthparmstyle = 'display:none';
6816: my $lcauthparmtext;
1.326 raeburn 6817: my $menusty;
1.325 raeburn 6818: my $numinrow = 4;
1.326 raeburn 6819: my %menutitles = <imenu_titles();
1.320 raeburn 6820:
6821: if (ref($current) eq 'HASH') {
1.345 raeburn 6822: if (!$current->{'requser'}) {
6823: $optionsty = 'none';
1.391 raeburn 6824: $crssty = 'none';
6825: } elsif (!$current->{'crsinc'}) {
6826: $crssty = 'none';
1.345 raeburn 6827: }
1.320 raeburn 6828: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6829: $checked{'mapuser'}{'sourcedid'} = '';
6830: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6831: $checked{'mapuser'}{'email'} = ' checked="checked"';
6832: } else {
6833: $checked{'mapuser'}{'other'} = ' checked="checked"';
6834: $userfield = $current->{'mapuser'};
6835: $userfieldsty = 'inline-block';
6836: }
6837: }
6838: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6839: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6840: if ($current->{'mapcrs'} eq 'context_id') {
6841: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6842: } else {
6843: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6844: $cidfield = $current->{'mapcrs'};
6845: $crsfieldsty = 'inline-block';
6846: }
6847: }
6848: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6849: foreach my $type (@{$current->{'mapcrstype'}}) {
6850: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6851: }
6852: }
1.392 raeburn 6853: if (!$current->{'storecrs'}) {
6854: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6855: $checked{'storecrs'}{'Y'} = '';
6856: }
1.345 raeburn 6857: if ($current->{'makecrs'}) {
1.320 raeburn 6858: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6859: }
1.320 raeburn 6860: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6861: foreach my $role (@{$current->{'makeuser'}}) {
6862: $checked{'makeuser'}{$role} = ' checked="checked"';
6863: }
6864: }
1.325 raeburn 6865: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6866: $checked{'lcauth'}{$1} = ' checked="checked"';
6867: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6868: $lcauthparm = $current->{'lcauthparm'};
6869: $lcauthparmstyle = 'display:table-row';
6870: if ($current->{'lcauth'} eq 'localauth') {
6871: $lcauthparmtext = &mt('Local auth argument');
6872: } else {
6873: $lcauthparmtext = &mt('Kerberos domain');
6874: }
6875: }
6876: }
1.320 raeburn 6877: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6878: foreach my $role (@{$current->{'selfenroll'}}) {
6879: $checked{'selfenroll'}{$role} = ' checked="checked"';
6880: }
6881: }
6882: if (ref($current->{'maproles'}) eq 'HASH') {
6883: %rolemaps = %{$current->{'maproles'}};
6884: }
6885: if ($current->{'section'} ne '') {
6886: $checked{'crssec'}{'Y'} = ' checked="checked"';
6887: $crssecfieldsty = 'inline-block';
6888: if ($current->{'section'} eq 'course_section_sourcedid') {
6889: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6890: } else {
6891: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6892: $crssecsrc = $current->{'section'};
6893: $secsrcfieldsty = 'inline-block';
6894: }
6895: } else {
6896: $checked{'crssec'}{'N'} = ' checked="checked"';
6897: }
1.363 raeburn 6898: if ($current->{'callback'} ne '') {
6899: $callback = $current->{'callback'};
6900: $checked{'callback'}{'Y'} = ' checked="checked"';
6901: $callbacksty = 'inline-block';
6902: } else {
6903: $checked{'callback'}{'N'} = ' checked="checked"';
6904: }
1.326 raeburn 6905: if ($current->{'topmenu'}) {
6906: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6907: } else {
6908: $checked{'topmenu'}{'N'} = ' checked="checked"';
6909: }
6910: if ($current->{'inlinemenu'}) {
6911: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6912: } else {
6913: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6914: }
6915: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6916: $menusty = 'inline-block';
6917: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6918: foreach my $item (@{$current->{'lcmenu'}}) {
6919: if (exists($menutitles{$item})) {
6920: $checked{'menuitem'}{$item} = ' checked="checked"';
6921: }
6922: }
6923: }
6924: } else {
6925: $menusty = 'none';
6926: }
1.320 raeburn 6927: } else {
6928: $checked{'makecrs'}{'N'} = ' checked="checked"';
6929: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6930: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6931: $checked{'topmenu'}{'N'} = ' checked="checked"';
6932: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6933: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6934: $menusty = 'inline-block';
1.320 raeburn 6935: }
1.325 raeburn 6936: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6937: my %coursetypetitles = &Apache::lonlocal::texthash (
6938: official => 'Official',
6939: unofficial => 'Unofficial',
6940: community => 'Community',
6941: textbook => 'Textbook',
6942: placement => 'Placement Test',
1.325 raeburn 6943: lti => 'LTI Provider',
1.320 raeburn 6944: );
1.325 raeburn 6945: my @authtypes = ('internal','krb4','krb5','localauth');
6946: my %shortauth = (
6947: internal => 'int',
6948: krb4 => 'krb4',
6949: krb5 => 'krb5',
6950: localauth => 'loc'
6951: );
6952: my %authnames = &authtype_names();
1.320 raeburn 6953: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6954: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6955: my @courseroles = ('cc','in','ta','ep','st');
6956: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6957: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6958: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6959: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6960: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6961: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6962: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6963: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6964: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6965: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6966: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6967: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6968: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6969: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6970: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6971: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6972: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6973: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6974: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6975: foreach my $option ('sourcedid','email','other') {
6976: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6977: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6978: ($option eq 'other' ? '' : (' 'x2) );
6979: }
6980: $output .= '</span></div>'.
6981: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6982: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6983: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6984: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6985: foreach my $ltirole (@ltiroles) {
6986: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6987: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6988: }
6989: $output .= '</fieldset>'.
1.391 raeburn 6990: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6991: '<table>'.
6992: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6993: '</table>'.
6994: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6995: '<td class="LC_left_item">';
6996: foreach my $auth ('lti',@authtypes) {
6997: my $authtext;
6998: if ($auth eq 'lti') {
6999: $authtext = &mt('None');
7000: } else {
7001: $authtext = $authnames{$shortauth{$auth}};
7002: }
7003: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
7004: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
7005: $authtext.'</label></span> ';
7006: }
7007: $output .= '</td></tr>'.
7008: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
7009: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
7010: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
7011: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
7012: '</table></fieldset>'.
1.391 raeburn 7013: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
7014: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
7015: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
7016: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
7017: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
7018: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
7019: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
7020: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7021: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
7022: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
7023: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
7024: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
7025: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
7026: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7027: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
7028: '<span class="LC_nobreak">'.&mt('Menu items').': ';
7029: foreach my $type ('fullname','coursetitle','role','logout','grades') {
7030: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
7031: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
7032: (' 'x2);
7033: }
7034: $output .= '</span></div></fieldset>'.
7035: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 7036: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7037: &mt('Unique course identifier').': ';
7038: foreach my $option ('course_offering_sourcedid','context_id','other') {
7039: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
7040: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
7041: ($option eq 'other' ? '' : (' 'x2) );
7042: }
1.334 raeburn 7043: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 7044: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
7045: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
7046: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
7047: foreach my $type (@coursetypes) {
7048: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
7049: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
7050: (' 'x2);
7051: }
1.392 raeburn 7052: $output .= '</span><br /><br />'.
7053: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
7054: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
7055: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
7056: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
7057: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
7058: '</fieldset>'.
1.391 raeburn 7059: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
7060: foreach my $ltirole (@lticourseroles) {
7061: my ($selected,$selectnone);
7062: if ($rolemaps{$ltirole} eq '') {
7063: $selectnone = ' selected="selected"';
7064: }
7065: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
7066: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
7067: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
7068: foreach my $role (@courseroles) {
7069: unless ($selectnone) {
7070: if ($rolemaps{$ltirole} eq $role) {
7071: $selected = ' selected="selected"';
7072: } else {
7073: $selected = '';
7074: }
7075: }
7076: $output .= '<option value="'.$role.'"'.$selected.'>'.
7077: &Apache::lonnet::plaintext($role,'Course').
7078: '</option>';
7079: }
7080: $output .= '</select></td>';
7081: }
7082: $output .= '</tr></table></fieldset>'.
7083: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 7084: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
7085: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
7086: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
7087: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
7088: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
7089: '</fieldset>'.
1.391 raeburn 7090: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 7091: foreach my $lticrsrole (@lticourseroles) {
7092: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
7093: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
7094: }
7095: $output .= '</fieldset>'.
1.391 raeburn 7096: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 7097: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
7098: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
7099: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
7100: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 7101: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 7102: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
7103: '<span class="LC_nobreak">'.&mt('From').':<label>'.
7104: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
7105: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
7106: &mt('Standard field').'</label>'.(' 'x2).
7107: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
7108: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 7109: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 7110: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 7111: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
7112: my ($pb1p1chk,$pb1p0chk,$onclickpb);
7113: foreach my $extra ('roster','passback') {
1.320 raeburn 7114: my $checkedon = '';
7115: my $checkedoff = ' checked="checked"';
1.337 raeburn 7116: if ($extra eq 'passback') {
7117: $pb1p1chk = ' checked="checked"';
7118: $pb1p0chk = '';
7119: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
7120: } else {
7121: $onclickpb = '';
7122: }
1.320 raeburn 7123: if (ref($current) eq 'HASH') {
7124: if (($current->{$extra})) {
7125: $checkedon = $checkedoff;
7126: $checkedoff = '';
1.337 raeburn 7127: if ($extra eq 'passback') {
7128: $passbacksty = 'inline-block';
7129: }
7130: if ($current->{'passbackformat'} eq '1.0') {
7131: $pb1p0chk = ' checked="checked"';
7132: $pb1p1chk = '';
7133: }
1.320 raeburn 7134: }
7135: }
7136: $output .= $lt{$extra}.' '.
1.337 raeburn 7137: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 7138: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 7139: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 7140: &mt('Yes').'</label><br />';
7141: }
1.337 raeburn 7142: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
7143: '<span class="LC_nobreak">'.&mt('Grade format').
7144: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
7145: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7146: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 7147: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 7148: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 7149: $output .= '</span></div></fieldset>';
1.320 raeburn 7150: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
7151: #
7152: # $output .= '</fieldset>'.
7153: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
7154: return $output;
7155: }
7156:
1.326 raeburn 7157: sub ltimenu_titles {
7158: return &Apache::lonlocal::texthash(
7159: fullname => 'Full name',
7160: coursetitle => 'Course title',
7161: role => 'Role',
7162: logout => 'Logout',
7163: grades => 'Grades',
7164: );
7165: }
7166:
1.405 raeburn 7167: sub check_switchserver {
7168: my ($home) = @_;
7169: my $switchserver;
7170: if ($home ne '') {
7171: my $allowed;
7172: my @ids=&Apache::lonnet::current_machine_ids();
7173: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7174: if (!$allowed) {
7175: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7176: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
7177: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
7178: }
7179: }
7180: return $switchserver;
7181: }
7182:
1.121 raeburn 7183: sub print_coursedefaults {
1.139 raeburn 7184: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 7185: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 7186: my $itemcount = 1;
1.192 raeburn 7187: my %choices = &Apache::lonlocal::texthash (
7188: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 7189: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 7190: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
7191: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 7192: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
7193: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 7194: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 7195: texengine => 'Default method to display mathematics',
1.257 raeburn 7196: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 7197: canclone => "People who may clone a course (besides course's owner and coordinators)",
7198: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 7199: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.192 raeburn 7200: );
1.198 raeburn 7201: my %staticdefaults = (
7202: anonsurvey_threshold => 10,
7203: uploadquota => 500,
1.257 raeburn 7204: postsubmit => 60,
1.276 raeburn 7205: mysqltables => 172800,
1.198 raeburn 7206: );
1.139 raeburn 7207: if ($position eq 'top') {
1.257 raeburn 7208: %defaultchecked = (
7209: 'canuse_pdfforms' => 'off',
7210: 'uselcmath' => 'on',
7211: 'usejsme' => 'on',
1.398 raeburn 7212: 'inline_chem' => 'on',
1.289 raeburn 7213: 'canclone' => 'none',
1.257 raeburn 7214: );
1.398 raeburn 7215: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 7216: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 7217: if (ref($settings) eq 'HASH') {
7218: if ($settings->{'texengine'}) {
7219: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
7220: $deftex = $settings->{'texengine'};
7221: }
7222: }
7223: }
7224: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7225: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
7226: '<span class="LC_nobreak">'.$choices{'texengine'}.
7227: '</span></td><td class="LC_right_item">'.
7228: '<select name="texengine">'."\n";
7229: my %texoptions = (
7230: MathJax => 'MathJax',
7231: mimetex => &mt('Convert to Images'),
7232: tth => &mt('TeX to HTML'),
7233: );
7234: foreach my $renderer ('MathJax','mimetex','tth') {
7235: my $selected = '';
7236: if ($renderer eq $deftex) {
7237: $selected = ' selected="selected"';
7238: }
7239: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
7240: }
7241: $mathdisp .= '</select></td></tr>'."\n";
7242: $itemcount ++;
1.139 raeburn 7243: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 7244: \%choices,$itemcount);
1.314 raeburn 7245: $datatable = $mathdisp.$datatable;
1.264 raeburn 7246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7247: $datatable .=
1.306 raeburn 7248: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 7249: '<span class="LC_nobreak">'.$choices{'canclone'}.
7250: '</span></td><td class="LC_left_item">';
7251: my $currcanclone = 'none';
7252: my $onclick;
7253: my @cloneoptions = ('none','domain');
1.380 raeburn 7254: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 7255: none => 'No additional course requesters',
7256: domain => "Any course requester in course's domain",
7257: instcode => 'Course requests for official courses ...',
7258: );
7259: my (%codedefaults,@code_order,@posscodes);
7260: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
7261: \@code_order) eq 'ok') {
7262: if (@code_order > 0) {
7263: push(@cloneoptions,'instcode');
7264: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
7265: }
7266: }
7267: if (ref($settings) eq 'HASH') {
7268: if ($settings->{'canclone'}) {
7269: if (ref($settings->{'canclone'}) eq 'HASH') {
7270: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
7271: if (@code_order > 0) {
7272: $currcanclone = 'instcode';
7273: @posscodes = @{$settings->{'canclone'}{'instcode'}};
7274: }
7275: }
7276: } elsif ($settings->{'canclone'} eq 'domain') {
7277: $currcanclone = $settings->{'canclone'};
7278: }
7279: }
1.289 raeburn 7280: }
1.264 raeburn 7281: foreach my $option (@cloneoptions) {
7282: my ($checked,$additional);
7283: if ($currcanclone eq $option) {
7284: $checked = ' checked="checked"';
7285: }
7286: if ($option eq 'instcode') {
7287: if (@code_order) {
7288: my $show = 'none';
7289: if ($checked) {
7290: $show = 'block';
7291: }
1.317 raeburn 7292: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7293: &mt('Institutional codes for new and cloned course have identical:').
7294: '<br />';
7295: foreach my $item (@code_order) {
7296: my $codechk;
7297: if ($checked) {
7298: if (grep(/^\Q$item\E$/,@posscodes)) {
7299: $codechk = ' checked="checked"';
7300: }
7301: }
7302: $additional .= '<label>'.
7303: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7304: $item.'</label>';
7305: }
7306: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7307: }
7308: }
7309: $datatable .=
7310: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7311: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7312: '</label> '.$additional.'</span><br />';
7313: }
7314: $datatable .= '</td>'.
7315: '</tr>';
7316: $itemcount ++;
1.139 raeburn 7317: } else {
7318: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 7319: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 7320: my $currusecredits = 0;
1.257 raeburn 7321: my $postsubmitclient = 1;
1.405 raeburn 7322: my $ltiauth = 0;
1.271 raeburn 7323: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7324: if (ref($settings) eq 'HASH') {
1.404 raeburn 7325: if ($settings->{'ltiauth'}) {
7326: $ltiauth = 1;
1.405 raeburn 7327: }
1.139 raeburn 7328: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7329: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7330: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7331: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7332: }
7333: }
1.192 raeburn 7334: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7335: foreach my $type (@types) {
7336: next if ($type eq 'community');
7337: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7338: if ($defcredits{$type} ne '') {
7339: $currusecredits = 1;
7340: }
7341: }
7342: }
7343: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7344: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7345: $postsubmitclient = 0;
7346: foreach my $type (@types) {
7347: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7348: }
7349: } else {
7350: foreach my $type (@types) {
7351: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7352: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7353: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7354: } else {
7355: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7356: }
7357: } else {
7358: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7359: }
7360: }
7361: }
7362: } else {
7363: foreach my $type (@types) {
7364: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7365: }
7366: }
1.276 raeburn 7367: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7368: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7369: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7370: }
7371: } else {
7372: foreach my $type (@types) {
7373: $currmysql{$type} = $staticdefaults{'mysqltables'};
7374: }
7375: }
1.258 raeburn 7376: } else {
7377: foreach my $type (@types) {
7378: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7379: }
1.139 raeburn 7380: }
7381: if (!$currdefresponder) {
1.198 raeburn 7382: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7383: } elsif ($currdefresponder < 1) {
7384: $currdefresponder = 1;
7385: }
1.198 raeburn 7386: foreach my $type (@types) {
7387: if ($curruploadquota{$type} eq '') {
7388: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7389: }
7390: }
1.139 raeburn 7391: $datatable .=
1.192 raeburn 7392: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7393: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7394: '</span></td>'.
7395: '<td class="LC_right_item"><span class="LC_nobreak">'.
7396: '<input type="text" name="anonsurvey_threshold"'.
7397: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7398: '</td></tr>'."\n";
7399: $itemcount ++;
7400: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7401: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7402: $choices{'uploadquota'}.
7403: '</span></td>'.
1.306 raeburn 7404: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7405: '<table><tr>';
1.198 raeburn 7406: foreach my $type (@types) {
1.306 raeburn 7407: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7408: '<input type="text" name="uploadquota_'.$type.'"'.
7409: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7410: }
7411: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7412: $itemcount ++;
1.236 raeburn 7413: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7414: my $display = 'none';
1.192 raeburn 7415: if ($currusecredits) {
7416: $display = 'block';
7417: }
7418: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7419: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7420: foreach my $type (@types) {
7421: next if ($type eq 'community');
1.306 raeburn 7422: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7423: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7424: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7425: }
7426: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7427: %defaultchecked = ('coursecredits' => 'off');
7428: @toggles = ('coursecredits');
7429: my $current = {
7430: 'coursecredits' => $currusecredits,
7431: };
7432: (my $table,$itemcount) =
7433: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7434: \%choices,$itemcount,$onclick,$additional,'left');
7435: $datatable .= $table;
7436: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7437: my $display = 'none';
7438: if ($postsubmitclient) {
7439: $display = 'block';
7440: }
7441: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7442: &mt('Number of seconds submit is disabled').'<br />'.
7443: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7444: '<table><tr>';
1.257 raeburn 7445: foreach my $type (@types) {
1.306 raeburn 7446: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7447: '<input type="text" name="'.$type.'_timeout" value="'.
7448: $deftimeout{$type}.'" size="5" /></td>';
7449: }
7450: $additional .= '</tr></table></div>'."\n";
7451: %defaultchecked = ('postsubmit' => 'on');
7452: @toggles = ('postsubmit');
1.280 raeburn 7453: $current = {
7454: 'postsubmit' => $postsubmitclient,
7455: };
1.257 raeburn 7456: ($table,$itemcount) =
7457: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7458: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7459: $datatable .= $table;
1.276 raeburn 7460: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7461: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7462: $choices{'mysqltables'}.
7463: '</span></td>'.
1.306 raeburn 7464: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7465: '<table><tr>';
7466: foreach my $type (@types) {
1.306 raeburn 7467: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7468: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7469: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7470: }
7471: $datatable .= '</tr></table></td></tr>'."\n";
7472: $itemcount ++;
1.404 raeburn 7473: %defaultchecked = ('ltiauth' => 'off');
7474: @toggles = ('ltiauth');
7475: $current = {
7476: 'ltiauth' => $ltiauth,
7477: };
7478: ($table,$itemcount) =
7479: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7480: \%choices,$itemcount,undef,undef,'left');
7481: $datatable .= $table;
7482: $itemcount ++;
1.139 raeburn 7483: }
1.192 raeburn 7484: $$rowtotal += $itemcount;
1.121 raeburn 7485: return $datatable;
1.118 jms 7486: }
7487:
1.231 raeburn 7488: sub print_selfenrollment {
7489: my ($position,$dom,$settings,$rowtotal) = @_;
7490: my ($css_class,$datatable);
7491: my $itemcount = 1;
1.271 raeburn 7492: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7493: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7494: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7495: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7496: my @rows;
7497: my $key;
7498: if ($position eq 'top') {
7499: $key = 'admin';
7500: if (ref($rowsref) eq 'ARRAY') {
7501: @rows = @{$rowsref};
7502: }
7503: } elsif ($position eq 'middle') {
7504: $key = 'default';
7505: @rows = ('types','registered','approval','limit');
7506: }
7507: foreach my $row (@rows) {
7508: if (defined($titlesref->{$row})) {
7509: $itemcount ++;
7510: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7511: $datatable .= '<tr'.$css_class.'>'.
7512: '<td>'.$titlesref->{$row}.'</td>'.
7513: '<td class="LC_left_item">'.
7514: '<table><tr>';
7515: my (%current,%currentcap);
7516: if (ref($settings) eq 'HASH') {
7517: if (ref($settings->{$key}) eq 'HASH') {
7518: foreach my $type (@types) {
7519: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7520: $current{$type} = $settings->{$key}->{$type}->{$row};
7521: }
7522: if (($row eq 'limit') && ($key eq 'default')) {
7523: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7524: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7525: }
7526: }
7527: }
7528: }
7529: }
7530: my %roles = (
7531: '0' => &Apache::lonnet::plaintext('dc'),
7532: );
7533:
7534: foreach my $type (@types) {
7535: unless (($row eq 'registered') && ($key eq 'default')) {
7536: $datatable .= '<th>'.&mt($type).'</th>';
7537: }
7538: }
7539: unless (($row eq 'registered') && ($key eq 'default')) {
7540: $datatable .= '</tr><tr>';
7541: }
7542: foreach my $type (@types) {
7543: if ($type eq 'community') {
7544: $roles{'1'} = &mt('Community personnel');
7545: } else {
7546: $roles{'1'} = &mt('Course personnel');
7547: }
7548: $datatable .= '<td style="vertical-align: top">';
7549: if ($position eq 'top') {
7550: my %checked;
7551: if ($current{$type} eq '0') {
7552: $checked{'0'} = ' checked="checked"';
7553: } else {
7554: $checked{'1'} = ' checked="checked"';
7555: }
7556: foreach my $role ('1','0') {
7557: $datatable .= '<span class="LC_nobreak"><label>'.
7558: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7559: 'value="'.$role.'"'.$checked{$role}.' />'.
7560: $roles{$role}.'</label></span> ';
7561: }
7562: } else {
7563: if ($row eq 'types') {
7564: my %checked;
7565: if ($current{$type} =~ /^(all|dom)$/) {
7566: $checked{$1} = ' checked="checked"';
7567: } else {
7568: $checked{''} = ' checked="checked"';
7569: }
7570: foreach my $val ('','dom','all') {
7571: $datatable .= '<span class="LC_nobreak"><label>'.
7572: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7573: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7574: }
7575: } elsif ($row eq 'registered') {
7576: my %checked;
7577: if ($current{$type} eq '1') {
7578: $checked{'1'} = ' checked="checked"';
7579: } else {
7580: $checked{'0'} = ' checked="checked"';
7581: }
7582: foreach my $val ('0','1') {
7583: $datatable .= '<span class="LC_nobreak"><label>'.
7584: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7585: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7586: }
7587: } elsif ($row eq 'approval') {
7588: my %checked;
7589: if ($current{$type} =~ /^([12])$/) {
7590: $checked{$1} = ' checked="checked"';
7591: } else {
7592: $checked{'0'} = ' checked="checked"';
7593: }
7594: for my $val (0..2) {
7595: $datatable .= '<span class="LC_nobreak"><label>'.
7596: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7597: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7598: }
7599: } elsif ($row eq 'limit') {
7600: my %checked;
7601: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7602: $checked{$1} = ' checked="checked"';
7603: } else {
7604: $checked{'none'} = ' checked="checked"';
7605: }
7606: my $cap;
7607: if ($currentcap{$type} =~ /^\d+$/) {
7608: $cap = $currentcap{$type};
7609: }
7610: foreach my $val ('none','allstudents','selfenrolled') {
7611: $datatable .= '<span class="LC_nobreak"><label>'.
7612: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7613: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7614: }
7615: $datatable .= '<br />'.
7616: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7617: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7618: '</span>';
7619: }
7620: }
7621: $datatable .= '</td>';
7622: }
7623: $datatable .= '</tr>';
7624: }
7625: $datatable .= '</table></td></tr>';
7626: }
7627: } elsif ($position eq 'bottom') {
1.235 raeburn 7628: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7629: }
7630: $$rowtotal += $itemcount;
7631: return $datatable;
7632: }
7633:
7634: sub print_validation_rows {
7635: my ($caller,$dom,$settings,$rowtotal) = @_;
7636: my ($itemsref,$namesref,$fieldsref);
7637: if ($caller eq 'selfenroll') {
7638: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7639: } elsif ($caller eq 'requestcourses') {
7640: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7641: }
7642: my %currvalidation;
7643: if (ref($settings) eq 'HASH') {
7644: if (ref($settings->{'validation'}) eq 'HASH') {
7645: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7646: }
1.235 raeburn 7647: }
7648: my $datatable;
7649: my $itemcount = 0;
7650: foreach my $item (@{$itemsref}) {
7651: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7652: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7653: $namesref->{$item}.
7654: '</span></td>'.
7655: '<td class="LC_left_item">';
7656: if (($item eq 'url') || ($item eq 'button')) {
7657: $datatable .= '<span class="LC_nobreak">'.
7658: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7659: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7660: } elsif ($item eq 'fields') {
7661: my @currfields;
7662: if (ref($currvalidation{$item}) eq 'ARRAY') {
7663: @currfields = @{$currvalidation{$item}};
7664: }
7665: foreach my $field (@{$fieldsref}) {
7666: my $check = '';
7667: if (grep(/^\Q$field\E$/,@currfields)) {
7668: $check = ' checked="checked"';
7669: }
7670: $datatable .= '<span class="LC_nobreak"><label>'.
7671: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7672: ' value="'.$field.'"'.$check.' />'.$field.
7673: '</label></span> ';
7674: }
7675: } elsif ($item eq 'markup') {
1.334 raeburn 7676: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7677: $currvalidation{$item}.
1.231 raeburn 7678: '</textarea>';
1.235 raeburn 7679: }
7680: $datatable .= '</td></tr>'."\n";
7681: if (ref($rowtotal)) {
1.231 raeburn 7682: $itemcount ++;
7683: }
7684: }
1.235 raeburn 7685: if ($caller eq 'requestcourses') {
7686: my %currhash;
1.248 raeburn 7687: if (ref($settings) eq 'HASH') {
7688: if (ref($settings->{'validation'}) eq 'HASH') {
7689: if ($settings->{'validation'}{'dc'} ne '') {
7690: $currhash{$settings->{'validation'}{'dc'}} = 1;
7691: }
1.235 raeburn 7692: }
7693: }
7694: my $numinrow = 2;
7695: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7696: 'validationdc',%currhash);
1.247 raeburn 7697: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7698: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7699: if ($numdc > 1) {
1.247 raeburn 7700: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7701: } else {
1.247 raeburn 7702: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7703: }
1.247 raeburn 7704: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7705: $itemcount ++;
7706: }
7707: if (ref($rowtotal)) {
7708: $$rowtotal += $itemcount;
7709: }
1.231 raeburn 7710: return $datatable;
7711: }
7712:
1.357 raeburn 7713: sub print_privacy {
7714: my ($position,$dom,$settings,$rowtotal) = @_;
7715: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7716: my $itemcount = 0;
7717: unless ($position eq 'top') {
7718: @items = ('domain','author','course','community');
7719: %names = &Apache::lonlocal::texthash (
7720: domain => 'Assigned domain role(s)',
7721: author => 'Assigned co-author role(s)',
7722: course => 'Assigned course role(s)',
7723: community => 'Assigned community role',
7724: );
7725: $numinrow = 4;
7726: ($othertitle,$usertypes,$types) =
7727: &Apache::loncommon::sorted_inst_types($dom);
7728: }
7729: if (($position eq 'top') || ($position eq 'middle')) {
7730: my (%by_ip,%by_location,@intdoms,@instdoms);
7731: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7732: if ($position eq 'top') {
7733: my %curr;
7734: my @options = ('none','user','domain','auto');
7735: my %titles = &Apache::lonlocal::texthash (
7736: none => 'Not allowed',
7737: user => 'User authorizes',
7738: domain => 'DC authorizes',
7739: auto => 'Unrestricted',
7740: instdom => 'Other domain shares institution/provider',
7741: extdom => 'Other domain has different institution/provider',
7742: );
7743: my %names = &Apache::lonlocal::texthash (
7744: domain => 'Domain role',
7745: author => 'Co-author role',
7746: course => 'Course role',
7747: community => 'Community role',
7748: );
7749: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7750: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7751: foreach my $domtype ('instdom','extdom') {
7752: my (%checked,$skip);
7753: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7754: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7755: '<td class="LC_left_item">';
7756: if ($domtype eq 'instdom') {
7757: unless (@instdoms > 1) {
7758: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7759: $skip = 1;
7760: }
7761: } elsif ($domtype eq 'extdom') {
7762: if (keys(%by_location) == 0) {
7763: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7764: $skip = 1;
7765: }
7766: }
7767: unless ($skip) {
7768: foreach my $roletype ('domain','author','course','community') {
7769: $checked{'auto'} = ' checked="checked"';
7770: if (ref($settings) eq 'HASH') {
7771: if (ref($settings->{approval}) eq 'HASH') {
7772: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7773: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7774: $checked{$1} = ' checked="checked"';
7775: $checked{'auto'} = '';
7776: }
7777: }
7778: }
7779: }
7780: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7781: foreach my $option (@options) {
7782: $datatable .= '<span class="LC_nobreak"><label>'.
7783: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7784: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7785: '</label></span> ';
7786: }
7787: $datatable .= '</fieldset>';
7788: }
7789: }
7790: $datatable .= '</td></tr>';
7791: $itemcount ++;
7792: }
7793: } elsif ($position eq 'middle') {
7794: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7795: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7796: foreach my $item (@{$types}) {
7797: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7798: $numinrow,$itemcount,'','','','','',
7799: '',$usertypes->{$item});
7800: $itemcount ++;
7801: }
7802: }
7803: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7804: $numinrow,$itemcount,'','','','','',
7805: '',$othertitle);
7806: $itemcount ++;
7807: } else {
1.360 raeburn 7808: my (@insttypes,%insttitles);
7809: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7810: @insttypes = @{$types};
7811: %insttitles = %{$usertypes};
7812: }
7813: foreach my $item (@insttypes,'default') {
7814: my $title;
7815: if ($item eq 'default') {
7816: $title = $othertitle;
7817: } else {
7818: $title = $insttitles{$item};
7819: }
7820: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7821: $datatable .= '<tr'.$css_class.'>'.
7822: '<td class="LC_left_item">'.$title.'</td>'.
7823: '<td class="LC_left_item">'.
7824: &mt('Nothing to set here, as there are no other domains').
7825: '</td></tr>';
7826: $itemcount ++;
7827: }
1.357 raeburn 7828: }
7829: }
7830: } else {
7831: my $prefix;
7832: if ($position eq 'lower') {
7833: $prefix = 'priv';
7834: } else {
7835: $prefix = 'unpriv';
7836: }
7837: foreach my $item (@items) {
7838: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7839: $numinrow,$itemcount,'','','','','',
7840: '',$names{$item});
7841: $itemcount ++;
7842: }
7843: }
7844: if (ref($rowtotal)) {
7845: $$rowtotal += $itemcount;
7846: }
7847: return $datatable;
7848: }
7849:
1.354 raeburn 7850: sub print_passwords {
7851: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7852: my ($datatable,$css_class);
7853: my $itemcount = 0;
7854: my %titles = &Apache::lonlocal::texthash (
7855: captcha => '"Forgot Password" CAPTCHA validation',
7856: link => 'Reset link expiration (hours)',
7857: case => 'Case-sensitive usernames/e-mail',
7858: prelink => 'Information required (form 1)',
7859: postlink => 'Information required (form 2)',
7860: emailsrc => 'LON-CAPA e-mail address type(s)',
7861: customtext => 'Domain specific text (HTML)',
7862: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7863: intauth_check => 'Check bcrypt cost if authenticated',
7864: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7865: permanent => 'Permanent e-mail address',
7866: critical => 'Critical notification address',
7867: notify => 'Notification address',
7868: min => 'Minimum password length',
7869: max => 'Maximum password length',
7870: chars => 'Required characters',
7871: expire => 'Password expiration (days)',
1.356 raeburn 7872: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7873: );
7874: if ($position eq 'top') {
7875: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7876: my $shownlinklife = 2;
7877: my $prelink = 'both';
7878: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7879: if (ref($settings) eq 'HASH') {
7880: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7881: $shownlinklife = $settings->{resetlink};
7882: }
7883: if (ref($settings->{resetcase}) eq 'ARRAY') {
7884: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7885: }
7886: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7887: $prelink = $settings->{resetprelink};
7888: }
7889: if (ref($settings->{resetpostlink}) eq 'HASH') {
7890: %postlink = %{$settings->{resetpostlink}};
7891: }
7892: if (ref($settings->{resetemail}) eq 'ARRAY') {
7893: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7894: }
7895: if ($settings->{resetremove}) {
7896: $nostdtext = 1;
7897: }
7898: if ($settings->{resetcustom}) {
7899: $customurl = $settings->{resetcustom};
7900: }
7901: } else {
7902: if (ref($types) eq 'ARRAY') {
7903: foreach my $item (@{$types}) {
7904: $casesens{$item} = 1;
7905: $postlink{$item} = ['username','email'];
7906: }
7907: }
7908: $casesens{'default'} = 1;
7909: $postlink{'default'} = ['username','email'];
7910: $prelink = 'both';
7911: %emailsrc = (
7912: permanent => 1,
7913: critical => 1,
7914: notify => 1,
7915: );
7916: }
7917: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7918: $itemcount ++;
7919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7920: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7921: '<td class="LC_left_item">'.
7922: '<input type="textbox" value="'.$shownlinklife.'" '.
7923: 'name="passwords_link" size="3" /></td></tr>';
7924: $itemcount ++;
7925: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7926: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7927: '<td class="LC_left_item">';
7928: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7929: foreach my $item (@{$types}) {
7930: my $checkedcase;
7931: if ($casesens{$item}) {
7932: $checkedcase = ' checked="checked"';
7933: }
7934: $datatable .= '<span class="LC_nobreak"><label>'.
7935: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7936: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7937: '</span> ';
1.354 raeburn 7938: }
7939: }
7940: my $checkedcase;
7941: if ($casesens{'default'}) {
7942: $checkedcase = ' checked="checked"';
7943: }
7944: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7945: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7946: $othertitle.'</label></span></td>';
7947: $itemcount ++;
7948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7949: my %checkedpre = (
7950: both => ' checked="checked"',
7951: either => '',
7952: );
7953: if ($prelink eq 'either') {
7954: $checkedpre{either} = ' checked="checked"';
7955: $checkedpre{both} = '';
7956: }
7957: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7958: '<td class="LC_left_item"><span class="LC_nobreak">'.
7959: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7960: &mt('Both username and e-mail address').'</label></span> '.
7961: '<span class="LC_nobreak"><label>'.
7962: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7963: &mt('Either username or e-mail address').'</label></span></td></tr>';
7964: $itemcount ++;
7965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7966: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7967: '<td class="LC_left_item">';
7968: my %postlinked;
7969: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7970: foreach my $item (@{$types}) {
7971: undef(%postlinked);
7972: $datatable .= '<fieldset style="display: inline-block;">'.
7973: '<legend>'.$usertypes->{$item}.'</legend>';
7974: if (ref($postlink{$item}) eq 'ARRAY') {
7975: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7976: }
7977: foreach my $field ('email','username') {
7978: my $checked;
7979: if ($postlinked{$field}) {
7980: $checked = ' checked="checked"';
7981: }
7982: $datatable .= '<span class="LC_nobreak"><label>'.
7983: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7984: $field.'"'.$checked.' />'.$field.'</label>'.
7985: '<span> ';
7986: }
7987: $datatable .= '</fieldset>';
7988: }
7989: }
7990: if (ref($postlink{'default'}) eq 'ARRAY') {
7991: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7992: }
7993: $datatable .= '<fieldset style="display: inline-block;">'.
7994: '<legend>'.$othertitle.'</legend>';
7995: foreach my $field ('email','username') {
7996: my $checked;
7997: if ($postlinked{$field}) {
7998: $checked = ' checked="checked"';
7999: }
8000: $datatable .= '<span class="LC_nobreak"><label>'.
8001: '<input type="checkbox" name="passwords_postlink_default" value="'.
8002: $field.'"'.$checked.' />'.$field.'</label>'.
8003: '<span> ';
8004: }
8005: $datatable .= '</fieldset></td></tr>';
8006: $itemcount ++;
8007: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8008: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8009: '<td class="LC_left_item">';
8010: foreach my $type ('permanent','critical','notify') {
8011: my $checkedemail;
8012: if ($emailsrc{$type}) {
8013: $checkedemail = ' checked="checked"';
8014: }
8015: $datatable .= '<span class="LC_nobreak"><label>'.
8016: '<input type="checkbox" name="passwords_emailsrc" value="'.
8017: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8018: '<span> ';
8019: }
8020: $datatable .= '</td></tr>';
8021: $itemcount ++;
8022: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8023: my $switchserver = &check_switchserver($dom,$confname);
8024: my ($showstd,$noshowstd);
8025: if ($nostdtext) {
8026: $noshowstd = ' checked="checked"';
8027: } else {
8028: $showstd = ' checked="checked"';
8029: }
8030: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8031: '<td class="LC_left_item"><span class="LC_nobreak">'.
8032: &mt('Retain standard text:').
8033: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8034: &mt('Yes').'</label>'.' '.
8035: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8036: &mt('No').'</label></span><br />'.
8037: '<span class="LC_fontsize_small">'.
8038: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8039: &mt('Include custom text:');
8040: if ($customurl) {
1.369 raeburn 8041: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8042: undef,undef,undef,undef,'background-color:#ffffff');
8043: $datatable .= '<span class="LC_nobreak"> '.$link.
8044: '<label><input type="checkbox" name="passwords_custom_del"'.
8045: ' value="1" />'.&mt('Delete?').'</label></span>'.
8046: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8047: }
8048: if ($switchserver) {
8049: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8050: } else {
8051: $datatable .='<span class="LC_nobreak"> '.
8052: '<input type="file" name="passwords_customfile" /></span>';
8053: }
8054: $datatable .= '</td></tr>';
8055: } elsif ($position eq 'middle') {
8056: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8057: my @items = ('intauth_cost','intauth_check','intauth_switch');
8058: my %defaults;
8059: if (ref($domconf{'defaults'}) eq 'HASH') {
8060: %defaults = %{$domconf{'defaults'}};
8061: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8062: $defaults{'intauth_cost'} = 10;
8063: }
8064: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8065: $defaults{'intauth_check'} = 0;
8066: }
8067: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8068: $defaults{'intauth_switch'} = 0;
8069: }
8070: } else {
8071: %defaults = (
8072: 'intauth_cost' => 10,
8073: 'intauth_check' => 0,
8074: 'intauth_switch' => 0,
8075: );
8076: }
8077: foreach my $item (@items) {
8078: if ($itemcount%2) {
8079: $css_class = '';
8080: } else {
8081: $css_class = ' class="LC_odd_row" ';
8082: }
8083: $datatable .= '<tr'.$css_class.'>'.
8084: '<td><span class="LC_nobreak">'.$titles{$item}.
8085: '</span></td><td class="LC_left_item" colspan="3">';
8086: if ($item eq 'intauth_switch') {
8087: my @options = (0,1,2);
8088: my %optiondesc = &Apache::lonlocal::texthash (
8089: 0 => 'No',
8090: 1 => 'Yes',
8091: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8092: );
8093: $datatable .= '<table width="100%">';
8094: foreach my $option (@options) {
8095: my $checked = ' ';
8096: if ($defaults{$item} eq $option) {
8097: $checked = ' checked="checked"';
8098: }
8099: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8100: '<label><input type="radio" name="'.$item.
8101: '" value="'.$option.'"'.$checked.' />'.
8102: $optiondesc{$option}.'</label></span></td></tr>';
8103: }
8104: $datatable .= '</table>';
8105: } elsif ($item eq 'intauth_check') {
8106: my @options = (0,1,2);
8107: my %optiondesc = &Apache::lonlocal::texthash (
8108: 0 => 'No',
8109: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8110: 2 => 'Yes, disallow login if stored cost is less than domain default',
8111: );
8112: $datatable .= '<table width="100%">';
8113: foreach my $option (@options) {
8114: my $checked = ' ';
8115: my $onclick;
8116: if ($defaults{$item} eq $option) {
8117: $checked = ' checked="checked"';
8118: }
8119: if ($option == 2) {
8120: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8121: }
8122: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8123: '<label><input type="radio" name="'.$item.
8124: '" value="'.$option.'"'.$checked.$onclick.' />'.
8125: $optiondesc{$option}.'</label></span></td></tr>';
8126: }
8127: $datatable .= '</table>';
8128: } else {
8129: $datatable .= '<input type="text" name="'.$item.'" value="'.
8130: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8131: }
8132: $datatable .= '</td></tr>';
8133: $itemcount ++;
8134: }
8135: } elsif ($position eq 'lower') {
1.405 raeburn 8136: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8137: } else {
1.359 raeburn 8138: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8139: my %ownerchg = (
8140: by => {},
8141: for => {},
8142: );
8143: my %ownertitles = &Apache::lonlocal::texthash (
8144: by => 'Course owner status(es) allowed',
8145: for => 'Student status(es) allowed',
8146: );
1.354 raeburn 8147: if (ref($settings) eq 'HASH') {
1.359 raeburn 8148: if (ref($settings->{crsownerchg}) eq 'HASH') {
8149: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8150: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8151: }
8152: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8153: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8154: }
1.354 raeburn 8155: }
8156: }
8157: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8158: $datatable .= '<tr '.$css_class.'>'.
8159: '<td>'.
8160: &mt('Requirements').'<ul>'.
1.359 raeburn 8161: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8162: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8163: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8164: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8165: '</ul>'.
8166: '</td>'.
1.359 raeburn 8167: '<td class="LC_left_item">';
8168: foreach my $item ('by','for') {
8169: $datatable .= '<fieldset style="display: inline-block;">'.
8170: '<legend>'.$ownertitles{$item}.'</legend>';
8171: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8172: foreach my $type (@{$types}) {
8173: my $checked;
8174: if ($ownerchg{$item}{$type}) {
8175: $checked = ' checked="checked"';
8176: }
8177: $datatable .= '<span class="LC_nobreak"><label>'.
8178: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8179: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8180: '</span> ';
1.359 raeburn 8181: }
8182: }
8183: my $checked;
8184: if ($ownerchg{$item}{'default'}) {
8185: $checked = ' checked="checked"';
8186: }
8187: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8188: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8189: $othertitle.'</label></span></fieldset>';
8190: }
8191: $datatable .= '</td></tr>';
1.354 raeburn 8192: }
8193: return $datatable;
8194: }
8195:
1.405 raeburn 8196: sub password_rules {
8197: my ($prefix,$itemcountref,$settings) = @_;
8198: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8199: my %titles;
8200: if ($prefix eq 'passwords') {
8201: %titles = &Apache::lonlocal::texthash (
8202: min => 'Minimum password length',
8203: max => 'Maximum password length',
8204: chars => 'Required characters',
8205: );
8206: } elsif ($prefix eq 'secrets') {
8207: %titles = &Apache::lonlocal::texthash (
8208: min => 'Minimum secret length',
8209: max => 'Maximum secret length',
8210: chars => 'Required characters',
8211: );
8212: }
8213: $min = $Apache::lonnet::passwdmin;
8214: my $datatable;
8215: my $itemcount;
8216: if (ref($itemcountref)) {
8217: $itemcount = $$itemcountref;
8218: }
8219: if (ref($settings) eq 'HASH') {
8220: if ($settings->{min}) {
8221: $min = $settings->{min};
8222: }
8223: if ($settings->{max}) {
8224: $max = $settings->{max};
8225: }
8226: if (ref($settings->{chars}) eq 'ARRAY') {
8227: map { $chars{$_} = 1; } (@{$settings->{chars}});
8228: }
8229: if ($prefix eq 'passwords') {
8230: if ($settings->{expire}) {
8231: $expire = $settings->{expire};
8232: }
8233: if ($settings->{numsaved}) {
8234: $numsaved = $settings->{numsaved};
8235: }
8236: }
8237: }
8238: my %rulenames = &Apache::lonlocal::texthash(
8239: uc => 'At least one upper case letter',
8240: lc => 'At least one lower case letter',
8241: num => 'At least one number',
8242: spec => 'At least one non-alphanumeric',
8243: );
8244: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8245: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8246: '<td class="LC_left_item"><span class="LC_nobreak">'.
8247: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8248: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8249: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8250: '</span></td></tr>';
8251: $itemcount ++;
8252: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8253: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8254: '<td class="LC_left_item"><span class="LC_nobreak">'.
8255: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8256: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8257: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8258: '</span></td></tr>';
8259: $itemcount ++;
8260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8261: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8262: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8263: '</span></td>';
8264: my $numinrow = 2;
8265: my @possrules = ('uc','lc','num','spec');
8266: $datatable .= '<td class="LC_left_item"><table>';
8267: for (my $i=0; $i<@possrules; $i++) {
8268: my ($rem,$checked);
8269: if ($chars{$possrules[$i]}) {
8270: $checked = ' checked="checked"';
8271: }
8272: $rem = $i%($numinrow);
8273: if ($rem == 0) {
8274: if ($i > 0) {
8275: $datatable .= '</tr>';
8276: }
8277: $datatable .= '<tr>';
8278: }
8279: $datatable .= '<td><span class="LC_nobreak"><label>'.
8280: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8281: $rulenames{$possrules[$i]}.'</label></span></td>';
8282: }
8283: my $rem = @possrules%($numinrow);
8284: my $colsleft = $numinrow - $rem;
8285: if ($colsleft > 1 ) {
8286: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8287: ' </td>';
8288: } elsif ($colsleft == 1) {
8289: $datatable .= '<td class="LC_left_item"> </td>';
8290: }
8291: $datatable .='</table></td></tr>';
8292: $itemcount ++;
8293: if ($prefix eq 'passwords') {
8294: $titles{'expire'} = &mt('Password expiration (days)');
8295: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8297: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8298: '<td class="LC_left_item"><span class="LC_nobreak">'.
8299: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8300: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8301: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8302: '</span></td></tr>';
8303: $itemcount ++;
8304: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8305: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8306: '<td class="LC_left_item"><span class="LC_nobreak">'.
8307: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8308: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8309: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8310: '</span></td></tr>';
8311: $itemcount ++;
8312: }
8313: if (ref($itemcountref)) {
8314: $$itemcountref += $itemcount;
8315: }
8316: return $datatable;
8317: }
8318:
1.373 raeburn 8319: sub print_wafproxy {
8320: my ($position,$dom,$settings,$rowtotal) = @_;
8321: my $css_class;
8322: my $itemcount = 0;
8323: my $datatable;
8324: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8325: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8326: my %lt = &wafproxy_titles();
1.373 raeburn 8327: foreach my $server (sort(keys(%servers))) {
8328: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8329: next if ($serverhome eq '');
1.373 raeburn 8330: my $serverdom;
8331: if ($serverhome ne $server) {
8332: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8333: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8334: $othercontrol{$server} = $serverdom;
8335: }
1.373 raeburn 8336: } else {
8337: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8338: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8339: if ($serverdom ne $dom) {
8340: $othercontrol{$server} = $serverdom;
8341: } else {
8342: $setdom = 1;
8343: if (ref($settings) eq 'HASH') {
8344: if (ref($settings->{'alias'}) eq 'HASH') {
8345: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8346: if ($aliases{$dom} ne '') {
8347: $showdom = 1;
8348: }
1.373 raeburn 8349: }
1.388 raeburn 8350: if (ref($settings->{'saml'}) eq 'HASH') {
8351: $saml{$dom} = $settings->{'saml'};
8352: }
1.373 raeburn 8353: }
8354: }
8355: }
8356: }
1.381 raeburn 8357: if ($setdom) {
8358: %{$values{$dom}} = ();
8359: if (ref($settings) eq 'HASH') {
8360: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8361: $values{$dom}{$item} = $settings->{$item};
8362: }
8363: }
8364: }
1.373 raeburn 8365: if (keys(%othercontrol)) {
8366: %otherdoms = reverse(%othercontrol);
8367: foreach my $domain (keys(%otherdoms)) {
8368: %{$values{$domain}} = ();
8369: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8370: if (ref($config{'wafproxy'}) eq 'HASH') {
8371: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 8372: if (exists($config{'wafproxy'}{'saml'})) {
8373: $saml{$domain} = $config{'wafproxy'}{'saml'};
8374: }
1.383 raeburn 8375: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8376: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8377: }
8378: }
8379: }
8380: }
8381: if ($position eq 'top') {
8382: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8383: my %aliasinfo;
1.373 raeburn 8384: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8385: $itemcount ++;
8386: my $dom_in_effect;
8387: my $aliasrows = '<tr>'.
1.383 raeburn 8388: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8389: &mt('Hostname').': '.
8390: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8391: if ($othercontrol{$server}) {
1.381 raeburn 8392: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8393: my ($current,$forsaml);
1.383 raeburn 8394: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8395: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8396: }
1.388 raeburn 8397: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8398: if ($saml{$dom_in_effect}{$server}) {
8399: $forsaml = 1;
8400: }
8401: }
1.383 raeburn 8402: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8403: &mt('Alias').': ';
1.373 raeburn 8404: if ($current) {
1.381 raeburn 8405: $aliasrows .= $current;
1.388 raeburn 8406: if ($forsaml) {
1.396 raeburn 8407: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8408: }
1.373 raeburn 8409: } else {
1.383 raeburn 8410: $aliasrows .= &mt('None');
1.373 raeburn 8411: }
1.383 raeburn 8412: $aliasrows .= ' <span class="LC_small">('.
8413: &mt('controlled by domain: [_1]',
8414: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8415: } else {
1.381 raeburn 8416: $dom_in_effect = $dom;
1.388 raeburn 8417: my ($current,$samlon,$samloff);
8418: $samloff = ' checked="checked"';
1.373 raeburn 8419: if (ref($aliases{$dom}) eq 'HASH') {
8420: if ($aliases{$dom}{$server}) {
8421: $current = $aliases{$dom}{$server};
8422: }
8423: }
1.388 raeburn 8424: if (ref($saml{$dom}) eq 'HASH') {
8425: if ($saml{$dom}{$server}) {
8426: $samlon = $samloff;
8427: undef($samloff);
8428: }
8429: }
1.383 raeburn 8430: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8431: &mt('Alias').': '.
1.381 raeburn 8432: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8433: 'value="'.$current.'" size="30" />'.
8434: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8435: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8436: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
8437: &mt('No').'</label> <label>'.
8438: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8439: &mt('Yes').'</label></span>'.
8440: '</td>';
1.381 raeburn 8441: }
8442: $aliasrows .= '</tr>';
8443: $aliasinfo{$dom_in_effect} .= $aliasrows;
8444: }
8445: if ($aliasinfo{$dom}) {
8446: my ($onclick,$wafon,$wafoff,$showtable);
8447: $onclick = ' onclick="javascript:toggleWAF();"';
8448: $wafoff = ' checked="checked"';
8449: $showtable = ' style="display:none";';
8450: if ($showdom) {
8451: $wafon = $wafoff;
8452: $wafoff = '';
8453: $showtable = ' style="display:inline;"';
8454: }
8455: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8456: $datatable = '<tr'.$css_class.'>'.
8457: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8458: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8459: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8460: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8461: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8462: &mt('No').'</label></span></td>'.
8463: '<td class="LC_left_item">'.
8464: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8465: '</table></td></tr>';
8466: $itemcount++;
8467: }
1.383 raeburn 8468: if (keys(%otherdoms)) {
8469: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8470: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8471: $datatable .= '<tr'.$css_class.'>'.
8472: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8473: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8474: '</table></td></tr>';
1.381 raeburn 8475: $itemcount++;
1.373 raeburn 8476: }
8477: }
8478: } else {
1.383 raeburn 8479: my %ip_methods = &remoteip_methods();
1.373 raeburn 8480: if ($setdom) {
8481: $itemcount ++;
8482: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8483: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8484: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8485: $wafstyle = ' style="display:none;"';
8486: $nowafstyle = ' style="display:table-row;"';
8487: $currwafdisplay = ' style="display: none"';
8488: $wafrangestyle = ' style="display: none"';
8489: $curr_remotip = 'n';
1.382 raeburn 8490: $ssltossl = ' checked="checked"';
1.381 raeburn 8491: if ($showdom) {
8492: $wafstyle = ' style="display:table-row;"';
8493: $nowafstyle = ' style="display:none;"';
8494: if (keys(%{$values{$dom}})) {
8495: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8496: $curr_remotip = $values{$dom}{remoteip};
8497: }
8498: if ($curr_remotip eq 'h') {
8499: $currwafdisplay = ' style="display:table-row"';
8500: $wafrangestyle = ' style="display:inline-block;"';
8501: }
1.382 raeburn 8502: if ($values{$dom}{'sslopt'}) {
8503: $alltossl = ' checked="checked"';
8504: $ssltossl = '';
8505: }
1.381 raeburn 8506: }
8507: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8508: $vpndircheck = ' checked="checked"';
8509: $currwafvpn = ' style="display:table-row;"';
8510: $wafrangestyle = ' style="display:inline-block;"';
8511: } else {
8512: $vpnaliascheck = ' checked="checked"';
8513: $currwafvpn = ' style="display:none;"';
8514: }
8515: }
8516: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8517: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8518: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8519: '</tr>'.
8520: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8521: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8522: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8523: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8524: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8525: '<td class="LC_left_item"><table>'.
8526: '<tr>'.
8527: '<td valign="top">'.$lt{'remoteip'}.': '.
8528: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8529: foreach my $option ('m','h','n') {
8530: my $sel;
8531: if ($option eq $curr_remotip) {
8532: $sel = ' selected="selected"';
8533: }
8534: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8535: $ip_methods{$option}.'</option>';
8536: }
8537: $datatable .= '</select></td></tr>'."\n".
8538: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8539: $lt{'ipheader'}.': '.
8540: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8541: 'name="wafproxy_ipheader" />'.
8542: '</td></tr>'."\n".
8543: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8544: $lt{'trusted'}.':<br />'.
1.381 raeburn 8545: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8546: $values{$dom}{'trusted'}.'</textarea>'.
8547: '</td></tr>'."\n".
8548: '<tr><td><hr /></td></tr>'."\n".
8549: '<tr>'.
8550: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8551: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8552: $lt{'vpndirect'}.'</label>'.(' 'x2).
8553: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8554: $lt{'vpnaliased'}.'</label></span></td></tr>';
8555: foreach my $item ('vpnint','vpnext') {
8556: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8557: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8558: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8559: $values{$dom}{$item}.'</textarea>'.
8560: '</td></tr>'."\n";
1.373 raeburn 8561: }
1.382 raeburn 8562: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8563: '<tr>'.
8564: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8565: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8566: $lt{'alltossl'}.'</label>'.(' 'x2).
8567: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8568: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8569: '</table></td></tr>';
1.373 raeburn 8570: }
8571: if (keys(%otherdoms)) {
8572: foreach my $domain (sort(keys(%otherdoms))) {
8573: $itemcount ++;
8574: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8575: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8576: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8577: '<td class="LC_left_item"><table>';
1.382 raeburn 8578: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8579: my $showval = &mt('None');
1.382 raeburn 8580: if ($item eq 'ssl') {
8581: $showval = $lt{'ssltossl'};
8582: }
1.373 raeburn 8583: if ($values{$domain}{$item}) {
1.381 raeburn 8584: $showval = $values{$domain}{$item};
1.382 raeburn 8585: if ($item eq 'ssl') {
8586: $showval = $lt{'alltossl'};
1.383 raeburn 8587: } elsif ($item eq 'remoteip') {
8588: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8589: }
1.373 raeburn 8590: }
8591: $datatable .= '<tr>'.
8592: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8593: }
1.381 raeburn 8594: $datatable .= '</table></td></tr>';
1.373 raeburn 8595: }
8596: }
8597: }
8598: $$rowtotal += $itemcount;
8599: return $datatable;
8600: }
8601:
8602: sub wafproxy_titles {
8603: return &Apache::lonlocal::texthash(
1.381 raeburn 8604: remoteip => "Method for determining user's IP",
8605: ipheader => 'Request header containing remote IP',
8606: trusted => 'Trusted IP range(s)',
8607: vpnaccess => 'Access from institutional VPN',
8608: vpndirect => 'via regular hostname (no WAF)',
8609: vpnaliased => 'via aliased hostname (WAF)',
8610: vpnint => 'Internal IP Range(s) for VPN sessions',
8611: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8612: sslopt => 'Forwarding http/https',
1.381 raeburn 8613: alltossl => 'WAF forwards both http and https requests to https',
8614: ssltossl => 'WAF forwards http requests to http and https to https',
8615: );
8616: }
8617:
8618: sub remoteip_methods {
8619: return &Apache::lonlocal::texthash(
8620: m => 'Use Apache mod_remoteip',
8621: h => 'Use headers parsed by LON-CAPA',
8622: n => 'Not in use',
1.373 raeburn 8623: );
8624: }
8625:
1.137 raeburn 8626: sub print_usersessions {
8627: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8628: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8629: my (%by_ip,%by_location,@intdoms,@instdoms);
8630: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8631:
8632: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8633: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8634: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8635: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8636: if ($position eq 'top') {
1.152 raeburn 8637: if (keys(%serverhomes) > 1) {
1.145 raeburn 8638: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8639: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8640: if (ref($settings) eq 'HASH') {
8641: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8642: $curroffloadnow = $settings->{'offloadnow'};
8643: }
1.371 raeburn 8644: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8645: $curroffloadoth = $settings->{'offloadoth'};
8646: }
1.261 raeburn 8647: }
1.371 raeburn 8648: my $other_insts = scalar(keys(%by_location));
8649: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8650: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8651: } else {
1.140 raeburn 8652: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8653: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8654: '</td></tr>';
1.140 raeburn 8655: }
1.137 raeburn 8656: } else {
1.279 raeburn 8657: my %titles = &usersession_titles();
8658: my ($prefix,@types);
8659: if ($position eq 'bottom') {
8660: $prefix = 'remote';
8661: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8662: } else {
1.279 raeburn 8663: $prefix = 'hosted';
8664: @types = ('excludedomain','includedomain');
8665: }
8666: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8667: }
8668: $$rowtotal += $itemcount;
8669: return $datatable;
8670: }
8671:
8672: sub rules_by_location {
8673: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8674: my ($datatable,$itemcount,$css_class);
8675: if (keys(%{$by_location}) == 0) {
8676: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8677: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8678: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8679: '</td></tr>';
8680: $itemcount = 1;
8681: } else {
8682: $itemcount = 0;
8683: my $numinrow = 5;
8684: my (%current,%checkedon,%checkedoff);
8685: my @locations = sort(keys(%{$by_location}));
8686: foreach my $type (@{$types}) {
8687: $checkedon{$type} = '';
8688: $checkedoff{$type} = ' checked="checked"';
8689: }
8690: if (ref($settings) eq 'HASH') {
8691: if (ref($settings->{$prefix}) eq 'HASH') {
8692: foreach my $key (keys(%{$settings->{$prefix}})) {
8693: $current{$key} = $settings->{$prefix}{$key};
8694: if ($key eq 'version') {
8695: if ($current{$key} ne '') {
1.145 raeburn 8696: $checkedon{$key} = ' checked="checked"';
8697: $checkedoff{$key} = '';
8698: }
1.279 raeburn 8699: } elsif (ref($current{$key}) eq 'ARRAY') {
8700: $checkedon{$key} = ' checked="checked"';
8701: $checkedoff{$key} = '';
1.137 raeburn 8702: }
8703: }
8704: }
1.279 raeburn 8705: }
8706: foreach my $type (@{$types}) {
8707: next if ($type ne 'version' && !@locations);
8708: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8709: $datatable .= '<tr'.$css_class.'>
8710: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8711: <span class="LC_nobreak">
8712: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8713: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8714: if ($type eq 'version') {
8715: my @lcversions = &Apache::lonnet::all_loncaparevs();
8716: my $selector = '<select name="'.$prefix.'_version">';
8717: foreach my $version (@lcversions) {
8718: my $selected = '';
8719: if ($current{'version'} eq $version) {
8720: $selected = ' selected="selected"';
1.145 raeburn 8721: }
1.279 raeburn 8722: $selector .= ' <option value="'.$version.'"'.
8723: $selected.'>'.$version.'</option>';
8724: }
8725: $selector .= '</select> ';
8726: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8727: } else {
8728: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8729: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8730: ' />'.(' 'x2).
8731: '<input type="button" value="'.&mt('uncheck all').'" '.
8732: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8733: "\n".
8734: '</div><div><table>';
8735: my $rem;
8736: for (my $i=0; $i<@locations; $i++) {
8737: my ($showloc,$value,$checkedtype);
8738: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8739: my $ip = $by_location->{$locations[$i]}->[0];
8740: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8741: $value = join(':',@{$by_ip->{$ip}});
8742: $showloc = join(', ',@{$by_ip->{$ip}});
8743: if (ref($current{$type}) eq 'ARRAY') {
8744: foreach my $loc (@{$by_ip->{$ip}}) {
8745: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8746: $checkedtype = ' checked="checked"';
8747: last;
1.145 raeburn 8748: }
1.138 raeburn 8749: }
8750: }
8751: }
1.137 raeburn 8752: }
1.279 raeburn 8753: $rem = $i%($numinrow);
8754: if ($rem == 0) {
8755: if ($i > 0) {
8756: $datatable .= '</tr>';
8757: }
8758: $datatable .= '<tr>';
8759: }
8760: $datatable .= '<td class="LC_left_item">'.
8761: '<span class="LC_nobreak"><label>'.
8762: '<input type="checkbox" name="'.$prefix.'_'.$type.
8763: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8764: '</label></span></td>';
8765: }
8766: $rem = @locations%($numinrow);
8767: my $colsleft = $numinrow - $rem;
8768: if ($colsleft > 1 ) {
8769: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8770: ' </td>';
8771: } elsif ($colsleft == 1) {
8772: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8773: }
1.279 raeburn 8774: $datatable .= '</tr></table>';
1.137 raeburn 8775: }
1.279 raeburn 8776: $datatable .= '</td></tr>';
8777: $itemcount ++;
1.137 raeburn 8778: }
8779: }
1.279 raeburn 8780: return ($datatable,$itemcount);
1.137 raeburn 8781: }
8782:
1.275 raeburn 8783: sub print_ssl {
8784: my ($position,$dom,$settings,$rowtotal) = @_;
8785: my ($css_class,$datatable);
8786: my $itemcount = 1;
8787: if ($position eq 'top') {
1.281 raeburn 8788: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8789: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8790: my $same_institution;
8791: if ($intdom ne '') {
8792: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8793: if (ref($internet_names) eq 'ARRAY') {
8794: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8795: $same_institution = 1;
8796: }
8797: }
8798: }
1.275 raeburn 8799: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8800: $datatable = '<tr'.$css_class.'><td colspan="2">';
8801: if ($same_institution) {
8802: my %domservers = &Apache::lonnet::get_servers($dom);
8803: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8804: } else {
8805: $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.");
8806: }
8807: $datatable .= '</td></tr>';
1.275 raeburn 8808: $itemcount ++;
8809: } else {
8810: my %titles = &ssl_titles();
8811: my (%by_ip,%by_location,@intdoms,@instdoms);
8812: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8813: my @alldoms = &Apache::lonnet::all_domains();
8814: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8815: my @domservers = &Apache::lonnet::get_servers($dom);
8816: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8817: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8818: if (($position eq 'connto') || ($position eq 'connfrom')) {
8819: my $legacy;
8820: unless (ref($settings) eq 'HASH') {
8821: my $name;
8822: if ($position eq 'connto') {
8823: $name = 'loncAllowInsecure';
8824: } else {
8825: $name = 'londAllowInsecure';
8826: }
8827: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8828: my @ids=&Apache::lonnet::current_machine_ids();
8829: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8830: my %what = (
8831: $name => 1,
8832: );
8833: my ($result,$returnhash) =
8834: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8835: if ($result eq 'ok') {
8836: if (ref($returnhash) eq 'HASH') {
8837: $legacy = $returnhash->{$name};
8838: }
8839: }
8840: } else {
8841: $legacy = $Apache::lonnet::perlvar{$name};
8842: }
8843: }
1.275 raeburn 8844: foreach my $type ('dom','intdom','other') {
8845: my %checked;
8846: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8847: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8848: '<td class="LC_right_item">';
8849: my $skip;
8850: if ($type eq 'dom') {
8851: unless (keys(%servers) > 1) {
8852: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8853: $skip = 1;
8854: }
8855: }
8856: if ($type eq 'intdom') {
8857: unless (@instdoms > 1) {
8858: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8859: $skip = 1;
8860: }
8861: } elsif ($type eq 'other') {
8862: if (keys(%by_location) == 0) {
8863: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8864: $skip = 1;
8865: }
8866: }
8867: unless ($skip) {
8868: $checked{'yes'} = ' checked="checked"';
8869: if (ref($settings) eq 'HASH') {
1.293 raeburn 8870: if (ref($settings->{$position}) eq 'HASH') {
8871: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8872: $checked{$1} = $checked{'yes'};
8873: delete($checked{'yes'});
8874: }
8875: }
1.293 raeburn 8876: } else {
8877: if ($legacy == 0) {
8878: $checked{'req'} = $checked{'yes'};
8879: delete($checked{'yes'});
8880: }
1.275 raeburn 8881: }
8882: foreach my $option ('no','yes','req') {
8883: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8884: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8885: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8886: '</label></span>'.(' 'x2);
8887: }
8888: }
8889: $datatable .= '</td></tr>';
8890: $itemcount ++;
8891: }
8892: } else {
8893: my $prefix = 'replication';
8894: my @types = ('certreq','nocertreq');
1.279 raeburn 8895: if (keys(%by_location) == 0) {
8896: $datatable .= '<tr'.$css_class.'><td>'.
8897: &mt('Nothing to set here, as there are no other institutions').
8898: '</td></tr>';
8899: $itemcount ++;
1.275 raeburn 8900: } else {
1.279 raeburn 8901: ($datatable,$itemcount) =
8902: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8903: }
8904: }
8905: }
8906: $$rowtotal += $itemcount;
8907: return $datatable;
8908: }
8909:
8910: sub ssl_titles {
8911: return &Apache::lonlocal::texthash (
8912: dom => 'LON-CAPA servers/VMs from same domain',
8913: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8914: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8915: connto => 'Connections to other servers',
8916: connfrom => 'Connections from other servers',
1.275 raeburn 8917: replication => 'Replicating content to other institutions',
8918: certreq => 'Client certificate required, but specific domains exempt',
8919: nocertreq => 'No client certificate required, except for specific domains',
8920: no => 'SSL not used',
8921: yes => 'SSL Optional (used if available)',
8922: req => 'SSL Required',
8923: );
1.279 raeburn 8924: }
8925:
8926: sub print_trust {
8927: my ($prefix,$dom,$settings,$rowtotal) = @_;
8928: my ($css_class,$datatable,%checked,%choices);
8929: my (%by_ip,%by_location,@intdoms,@instdoms);
8930: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8931: my $itemcount = 1;
8932: my %titles = &trust_titles();
8933: my @types = ('exc','inc');
8934: if ($prefix eq 'top') {
8935: $prefix = 'content';
8936: } elsif ($prefix eq 'bottom') {
8937: $prefix = 'msg';
8938: }
8939: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8940: $$rowtotal += $itemcount;
8941: return $datatable;
8942: }
8943:
8944: sub trust_titles {
8945: return &Apache::lonlocal::texthash(
8946: content => "Access to this domain's content by others",
8947: shared => "Access to other domain's content by this domain",
8948: enroll => "Enrollment in this domain's courses by others",
8949: othcoau => "Co-author roles in this domain for others",
8950: coaurem => "Co-author roles for this domain's users elsewhere",
8951: domroles => "Domain roles in this domain assignable to others",
8952: catalog => "Course Catalog for this domain displayed elsewhere",
8953: reqcrs => "Requests for creation of courses in this domain by others",
8954: msg => "Users in other domains can send messages to this domain",
8955: exc => "Allow all, but exclude specific domains",
8956: inc => "Deny all, but include specific domains",
8957: );
1.275 raeburn 8958: }
8959:
1.138 raeburn 8960: sub build_location_hashes {
1.275 raeburn 8961: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8962: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8963: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8964: my %iphost = &Apache::lonnet::get_iphost();
8965: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8966: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8967: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8968: foreach my $id (@{$iphost{$primary_ip}}) {
8969: my $intdom = &Apache::lonnet::internet_dom($id);
8970: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8971: push(@{$intdoms},$intdom);
8972: }
8973: }
8974: }
8975: foreach my $ip (keys(%iphost)) {
8976: if (ref($iphost{$ip}) eq 'ARRAY') {
8977: foreach my $id (@{$iphost{$ip}}) {
8978: my $location = &Apache::lonnet::internet_dom($id);
8979: if ($location) {
1.275 raeburn 8980: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8981: my $dom = &Apache::lonnet::host_domain($id);
8982: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8983: push(@{$instdoms},$dom);
8984: }
8985: next;
8986: }
1.138 raeburn 8987: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8988: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8989: push(@{$by_ip->{$ip}},$location);
8990: }
8991: } else {
8992: $by_ip->{$ip} = [$location];
8993: }
8994: }
8995: }
8996: }
8997: }
8998: foreach my $ip (sort(keys(%{$by_ip}))) {
8999: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9000: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9001: my $first = $by_ip->{$ip}->[0];
9002: if (ref($by_location->{$first}) eq 'ARRAY') {
9003: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9004: push(@{$by_location->{$first}},$ip);
9005: }
9006: } else {
9007: $by_location->{$first} = [$ip];
9008: }
9009: }
9010: }
9011: return;
9012: }
9013:
1.145 raeburn 9014: sub current_offloads_to {
9015: my ($dom,$settings,$servers) = @_;
9016: my (%spareid,%otherdomconfigs);
1.152 raeburn 9017: if (ref($servers) eq 'HASH') {
1.145 raeburn 9018: foreach my $lonhost (sort(keys(%{$servers}))) {
9019: my $gotspares;
1.152 raeburn 9020: if (ref($settings) eq 'HASH') {
9021: if (ref($settings->{'spares'}) eq 'HASH') {
9022: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9023: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9024: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9025: $gotspares = 1;
9026: }
1.145 raeburn 9027: }
9028: }
9029: unless ($gotspares) {
9030: my $gotspares;
9031: my $serverhomeID =
9032: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9033: my $serverhomedom =
9034: &Apache::lonnet::host_domain($serverhomeID);
9035: if ($serverhomedom ne $dom) {
9036: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9037: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9038: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9039: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9040: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9041: $gotspares = 1;
9042: }
9043: }
9044: } else {
9045: $otherdomconfigs{$serverhomedom} =
9046: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9047: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9048: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9049: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9050: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9051: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9052: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9053: $gotspares = 1;
9054: }
9055: }
9056: }
9057: }
9058: }
9059: }
9060: }
9061: unless ($gotspares) {
9062: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9063: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9064: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9065: } else {
9066: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9067: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9068: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9069: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9070: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9071: } else {
1.150 raeburn 9072: my %what = (
9073: spareid => 1,
9074: );
9075: my ($result,$returnhash) =
9076: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9077: if ($result eq 'ok') {
9078: if (ref($returnhash) eq 'HASH') {
9079: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9080: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9081: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9082: }
9083: }
1.145 raeburn 9084: }
9085: }
9086: }
9087: }
9088: }
9089: }
9090: return %spareid;
9091: }
9092:
9093: sub spares_row {
1.371 raeburn 9094: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9095: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9096: my $css_class;
9097: my $numinrow = 4;
9098: my $itemcount = 1;
9099: my $datatable;
1.152 raeburn 9100: my %typetitles = &sparestype_titles();
9101: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9102: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9103: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9104: my ($othercontrol,$serverdom);
9105: if ($serverhome ne $server) {
9106: $serverdom = &Apache::lonnet::host_domain($serverhome);
9107: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9108: } else {
9109: $serverdom = &Apache::lonnet::host_domain($server);
9110: if ($serverdom ne $dom) {
9111: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9112: }
9113: }
9114: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9115: my ($checkednow,$checkedoth);
1.261 raeburn 9116: if (ref($curroffloadnow) eq 'HASH') {
9117: if ($curroffloadnow->{$server}) {
9118: $checkednow = ' checked="checked"';
9119: }
9120: }
1.371 raeburn 9121: if (ref($curroffloadoth) eq 'HASH') {
9122: if ($curroffloadoth->{$server}) {
9123: $checkedoth = ' checked="checked"';
9124: }
9125: }
1.145 raeburn 9126: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9127: $datatable .= '<tr'.$css_class.'>
9128: <td rowspan="2">
1.183 bisitz 9129: <span class="LC_nobreak">'.
9130: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9131: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9132: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9133: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9134: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9135: "\n";
1.371 raeburn 9136: if ($other_insts) {
9137: $datatable .= '<br />'.
9138: '<span class="LC_nobreak">'."\n".
9139: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9140: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9141: "\n";
9142: }
1.145 raeburn 9143: my (%current,%canselect);
1.152 raeburn 9144: my @choices =
9145: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9146: foreach my $type ('primary','default') {
9147: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9148: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9149: my @spares = @{$spareid->{$server}{$type}};
9150: if (@spares > 0) {
1.152 raeburn 9151: if ($othercontrol) {
9152: $current{$type} = join(', ',@spares);
9153: } else {
9154: $current{$type} .= '<table>';
9155: my $numspares = scalar(@spares);
9156: for (my $i=0; $i<@spares; $i++) {
9157: my $rem = $i%($numinrow);
9158: if ($rem == 0) {
9159: if ($i > 0) {
9160: $current{$type} .= '</tr>';
9161: }
9162: $current{$type} .= '<tr>';
1.145 raeburn 9163: }
1.152 raeburn 9164: $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'".');" /> '.
9165: $spareid->{$server}{$type}[$i].
9166: '</label></td>'."\n";
9167: }
9168: my $rem = @spares%($numinrow);
9169: my $colsleft = $numinrow - $rem;
9170: if ($colsleft > 1 ) {
9171: $current{$type} .= '<td colspan="'.$colsleft.
9172: '" class="LC_left_item">'.
9173: ' </td>';
9174: } elsif ($colsleft == 1) {
9175: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9176: }
1.152 raeburn 9177: $current{$type} .= '</tr></table>';
1.150 raeburn 9178: }
1.145 raeburn 9179: }
9180: }
9181: if ($current{$type} eq '') {
9182: $current{$type} = &mt('None specified');
9183: }
1.152 raeburn 9184: if ($othercontrol) {
9185: if ($type eq 'primary') {
9186: $canselect{$type} = $othercontrol;
9187: }
9188: } else {
9189: $canselect{$type} =
9190: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9191: '<select name="newspare_'.$type.'_'.$server.'" '.
9192: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9193: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9194: if (@choices > 0) {
9195: foreach my $lonhost (@choices) {
9196: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9197: }
9198: }
9199: $canselect{$type} .= '</select>'."\n";
9200: }
9201: } else {
9202: $current{$type} = &mt('Could not be determined');
9203: if ($type eq 'primary') {
9204: $canselect{$type} = $othercontrol;
9205: }
1.145 raeburn 9206: }
1.152 raeburn 9207: if ($type eq 'default') {
9208: $datatable .= '<tr'.$css_class.'>';
9209: }
9210: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9211: '<td>'.$current{$type}.'</td>'."\n".
9212: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9213: }
9214: $itemcount ++;
9215: }
9216: }
9217: $$rowtotal += $itemcount;
9218: return $datatable;
9219: }
9220:
1.152 raeburn 9221: sub possible_newspares {
9222: my ($server,$currspares,$serverhomes,$altids) = @_;
9223: my $serverhostname = &Apache::lonnet::hostname($server);
9224: my %excluded;
9225: if ($serverhostname ne '') {
9226: %excluded = (
9227: $serverhostname => 1,
9228: );
9229: }
9230: if (ref($currspares) eq 'HASH') {
9231: foreach my $type (keys(%{$currspares})) {
9232: if (ref($currspares->{$type}) eq 'ARRAY') {
9233: if (@{$currspares->{$type}} > 0) {
9234: foreach my $curr (@{$currspares->{$type}}) {
9235: my $hostname = &Apache::lonnet::hostname($curr);
9236: $excluded{$hostname} = 1;
9237: }
9238: }
9239: }
9240: }
9241: }
9242: my @choices;
9243: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9244: if (keys(%{$serverhomes}) > 1) {
9245: foreach my $name (sort(keys(%{$serverhomes}))) {
9246: unless ($excluded{$name}) {
9247: if (exists($altids->{$serverhomes->{$name}})) {
9248: push(@choices,$altids->{$serverhomes->{$name}});
9249: } else {
9250: push(@choices,$serverhomes->{$name});
1.145 raeburn 9251: }
9252: }
9253: }
9254: }
9255: }
1.152 raeburn 9256: return sort(@choices);
1.145 raeburn 9257: }
9258:
1.150 raeburn 9259: sub print_loadbalancing {
9260: my ($dom,$settings,$rowtotal) = @_;
9261: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9262: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9263: my $numinrow = 1;
9264: my $datatable;
9265: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9266: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9267: if (ref($settings) eq 'HASH') {
9268: %existing = %{$settings};
9269: }
9270: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9271: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9272: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9273: } else {
9274: return;
9275: }
9276: my ($othertitle,$usertypes,$types) =
9277: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9278: my $rownum = 8;
1.150 raeburn 9279: if (ref($types) eq 'ARRAY') {
9280: $rownum += scalar(@{$types});
9281: }
1.171 raeburn 9282: my @css_class = ('LC_odd_row','LC_even_row');
9283: my $balnum = 0;
9284: my $islast;
9285: my (@toshow,$disabledtext);
9286: if (keys(%currbalancer) > 0) {
9287: @toshow = sort(keys(%currbalancer));
9288: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9289: push(@toshow,'');
9290: }
9291: } else {
9292: @toshow = ('');
9293: $disabledtext = &mt('No existing load balancer');
9294: }
9295: foreach my $lonhost (@toshow) {
9296: if ($balnum == scalar(@toshow)-1) {
9297: $islast = 1;
9298: } else {
9299: $islast = 0;
9300: }
9301: my $cssidx = $balnum%2;
9302: my $targets_div_style = 'display: none';
9303: my $disabled_div_style = 'display: block';
9304: my $homedom_div_style = 'display: none';
9305: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9306: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9307: '<p>';
9308: if ($lonhost eq '') {
1.210 raeburn 9309: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9310: if (keys(%currbalancer) > 0) {
9311: $datatable .= &mt('Add balancer:');
9312: } else {
9313: $datatable .= &mt('Enable balancer:');
9314: }
9315: $datatable .= ' '.
9316: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9317: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9318: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9319: '<option value="" selected="selected">'.&mt('None').
9320: '</option>'."\n";
9321: foreach my $server (sort(keys(%servers))) {
9322: next if ($currbalancer{$server});
9323: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9324: }
1.210 raeburn 9325: $datatable .=
1.171 raeburn 9326: '</select>'."\n".
9327: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9328: } else {
9329: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9330: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9331: &mt('Stop balancing').'</label>'.
9332: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9333: $targets_div_style = 'display: block';
9334: $disabled_div_style = 'display: none';
9335: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9336: $homedom_div_style = 'display: block';
9337: }
9338: }
1.306 raeburn 9339: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9340: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9341: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9342: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9343: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9344: my @sparestypes = ('primary','default');
9345: my %typetitles = &sparestype_titles();
1.284 raeburn 9346: my %hostherechecked = (
9347: no => ' checked="checked"',
9348: );
1.342 raeburn 9349: my %balcookiechecked = (
9350: no => ' checked="checked"',
9351: );
1.171 raeburn 9352: foreach my $sparetype (@sparestypes) {
9353: my $targettable;
9354: for (my $i=0; $i<$numspares; $i++) {
9355: my $checked;
9356: if (ref($currtargets{$lonhost}) eq 'HASH') {
9357: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9358: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9359: $checked = ' checked="checked"';
9360: }
9361: }
9362: }
9363: my ($chkboxval,$disabled);
9364: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9365: $chkboxval = $spares[$i];
9366: }
9367: if (exists($currbalancer{$spares[$i]})) {
9368: $disabled = ' disabled="disabled"';
9369: }
1.210 raeburn 9370: $targettable .=
1.253 raeburn 9371: '<td><span class="LC_nobreak"><label>'.
9372: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9373: $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 9374: '</span></label></span></td>';
1.171 raeburn 9375: my $rem = $i%($numinrow);
9376: if ($rem == 0) {
9377: if (($i > 0) && ($i < $numspares-1)) {
9378: $targettable .= '</tr>';
9379: }
9380: if ($i < $numspares-1) {
9381: $targettable .= '<tr>';
1.150 raeburn 9382: }
9383: }
9384: }
1.171 raeburn 9385: if ($targettable ne '') {
9386: my $rem = $numspares%($numinrow);
9387: my $colsleft = $numinrow - $rem;
9388: if ($colsleft > 1 ) {
9389: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9390: ' </td>';
9391: } elsif ($colsleft == 1) {
9392: $targettable .= '<td class="LC_left_item"> </td>';
9393: }
9394: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9395: '<table><tr>'.$targettable.'</tr></table><br />';
9396: }
1.284 raeburn 9397: $hostherechecked{$sparetype} = '';
9398: if (ref($currtargets{$lonhost}) eq 'HASH') {
9399: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9400: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9401: $hostherechecked{$sparetype} = ' checked="checked"';
9402: $hostherechecked{'no'} = '';
9403: }
9404: }
9405: }
9406: }
1.342 raeburn 9407: if ($currcookies{$lonhost}) {
9408: %balcookiechecked = (
9409: yes => ' checked="checked"',
9410: );
9411: }
1.284 raeburn 9412: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9413: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9414: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9415: foreach my $sparetype (@sparestypes) {
9416: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9417: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9418: '</i></label><br />';
1.171 raeburn 9419: }
1.342 raeburn 9420: $datatable .= &mt('Use balancer cookie').'<br />'.
9421: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9422: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9423: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9424: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9425: '</div></td></tr>'.
1.171 raeburn 9426: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9427: $othertitle,$usertypes,$types,\%servers,
9428: \%currbalancer,$lonhost,
9429: $targets_div_style,$homedom_div_style,
9430: $css_class[$cssidx],$balnum,$islast);
9431: $$rowtotal += $rownum;
9432: $balnum ++;
9433: }
9434: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9435: return $datatable;
9436: }
9437:
9438: sub get_loadbalancers_config {
1.342 raeburn 9439: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9440: return unless ((ref($servers) eq 'HASH') &&
9441: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9442: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9443: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9444: if (keys(%{$existing}) > 0) {
9445: my $oldlonhost;
9446: foreach my $key (sort(keys(%{$existing}))) {
9447: if ($key eq 'lonhost') {
9448: $oldlonhost = $existing->{'lonhost'};
9449: $currbalancer->{$oldlonhost} = 1;
9450: } elsif ($key eq 'targets') {
9451: if ($oldlonhost) {
9452: $currtargets->{$oldlonhost} = $existing->{'targets'};
9453: }
9454: } elsif ($key eq 'rules') {
9455: if ($oldlonhost) {
9456: $currrules->{$oldlonhost} = $existing->{'rules'};
9457: }
9458: } elsif (ref($existing->{$key}) eq 'HASH') {
9459: $currbalancer->{$key} = 1;
9460: $currtargets->{$key} = $existing->{$key}{'targets'};
9461: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9462: if ($existing->{$key}{'cookie'}) {
9463: $currcookies->{$key} = 1;
9464: }
1.150 raeburn 9465: }
9466: }
1.171 raeburn 9467: } else {
9468: my ($balancerref,$targetsref) =
9469: &Apache::lonnet::get_lonbalancer_config($servers);
9470: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9471: foreach my $server (sort(keys(%{$balancerref}))) {
9472: $currbalancer->{$server} = 1;
9473: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9474: }
9475: }
9476: }
1.171 raeburn 9477: return;
1.150 raeburn 9478: }
9479:
9480: sub loadbalancing_rules {
9481: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9482: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9483: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9484: my $output;
1.171 raeburn 9485: my $num = 0;
1.210 raeburn 9486: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9487: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9488: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9489: foreach my $type (@{$alltypes}) {
1.171 raeburn 9490: $num ++;
1.150 raeburn 9491: my $current;
9492: if (ref($currrules) eq 'HASH') {
9493: $current = $currrules->{$type};
9494: }
1.253 raeburn 9495: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9496: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9497: $current = '';
9498: }
9499: }
9500: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9501: $servers,$currbalancer,$lonhost,$dom,
9502: $targets_div_style,$homedom_div_style,
9503: $css_class,$balnum,$num,$islast);
1.150 raeburn 9504: }
9505: }
9506: return $output;
9507: }
9508:
9509: sub loadbalancing_titles {
9510: my ($dom,$intdom,$usertypes,$types) = @_;
9511: my %othertypes = (
9512: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9513: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9514: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9515: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9516: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9517: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9518: );
1.209 raeburn 9519: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9520: my @available;
1.150 raeburn 9521: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9522: @available = @{$types};
1.150 raeburn 9523: }
1.302 raeburn 9524: unless (grep(/^default$/,@available)) {
9525: push(@available,'default');
9526: }
9527: unshift(@alltypes,@available);
1.150 raeburn 9528: my %titles;
9529: foreach my $type (@alltypes) {
9530: if ($type =~ /^_LC_/) {
9531: $titles{$type} = $othertypes{$type};
9532: } elsif ($type eq 'default') {
9533: $titles{$type} = &mt('All users from [_1]',$dom);
9534: if (ref($types) eq 'ARRAY') {
9535: if (@{$types} > 0) {
9536: $titles{$type} = &mt('Other users from [_1]',$dom);
9537: }
9538: }
9539: } elsif (ref($usertypes) eq 'HASH') {
9540: $titles{$type} = $usertypes->{$type};
9541: }
9542: }
9543: return (\@alltypes,\%othertypes,\%titles);
9544: }
9545:
9546: sub loadbalance_rule_row {
1.171 raeburn 9547: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9548: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9549: my @rulenames;
1.150 raeburn 9550: my %ruletitles = &offloadtype_text();
1.209 raeburn 9551: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9552: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9553: } else {
1.209 raeburn 9554: @rulenames = ('default','homeserver');
9555: if ($type eq '_LC_external') {
9556: push(@rulenames,'externalbalancer');
9557: } else {
9558: push(@rulenames,'specific');
9559: }
9560: push(@rulenames,'none');
1.150 raeburn 9561: }
9562: my $style = $targets_div_style;
1.253 raeburn 9563: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9564: $style = $homedom_div_style;
9565: }
1.171 raeburn 9566: my $space;
9567: if ($islast && $num == 1) {
1.317 raeburn 9568: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9569: }
1.210 raeburn 9570: my $output =
1.306 raeburn 9571: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9572: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9573: '<td valaign="top">'.$space.
9574: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9575: for (my $i=0; $i<@rulenames; $i++) {
9576: my $rule = $rulenames[$i];
9577: my ($checked,$extra);
9578: if ($rulenames[$i] eq 'default') {
9579: $rule = '';
9580: }
9581: if ($rulenames[$i] eq 'specific') {
9582: if (ref($servers) eq 'HASH') {
9583: my $default;
9584: if (($current ne '') && (exists($servers->{$current}))) {
9585: $checked = ' checked="checked"';
9586: }
9587: unless ($checked) {
9588: $default = ' selected="selected"';
9589: }
1.210 raeburn 9590: $extra =
1.171 raeburn 9591: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9592: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9593: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9594: '<option value=""'.$default.'></option>'."\n";
9595: foreach my $server (sort(keys(%{$servers}))) {
9596: if (ref($currbalancer) eq 'HASH') {
9597: next if (exists($currbalancer->{$server}));
9598: }
1.150 raeburn 9599: my $selected;
1.171 raeburn 9600: if ($server eq $current) {
1.150 raeburn 9601: $selected = ' selected="selected"';
9602: }
1.171 raeburn 9603: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9604: }
9605: $extra .= '</select>';
9606: }
9607: } elsif ($rule eq $current) {
9608: $checked = ' checked="checked"';
9609: }
9610: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9611: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9612: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9613: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9614: ')"'.$checked.' /> ';
9615: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9616: $output .= $ruletitles{'particular'};
9617: } else {
9618: $output .= $ruletitles{$rulenames[$i]};
9619: }
9620: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9621: }
9622: $output .= '</div></td></tr>'."\n";
9623: return $output;
9624: }
9625:
9626: sub offloadtype_text {
9627: my %ruletitles = &Apache::lonlocal::texthash (
9628: 'default' => 'Offloads to default destinations',
9629: 'homeserver' => "Offloads to user's home server",
9630: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9631: 'specific' => 'Offloads to specific server',
1.161 raeburn 9632: 'none' => 'No offload',
1.209 raeburn 9633: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9634: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9635: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9636: );
9637: return %ruletitles;
9638: }
9639:
9640: sub sparestype_titles {
9641: my %typestitles = &Apache::lonlocal::texthash (
9642: 'primary' => 'primary',
9643: 'default' => 'default',
9644: );
9645: return %typestitles;
9646: }
9647:
1.28 raeburn 9648: sub contact_titles {
9649: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9650: 'supportemail' => 'Support E-mail address',
9651: 'adminemail' => 'Default Server Admin E-mail address',
9652: 'errormail' => 'Error reports to be e-mailed to',
9653: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9654: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9655: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9656: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9657: 'requestsmail' => 'E-mail from course requests requiring approval',
9658: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9659: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9660: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9661: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9662: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9663: 'errorweights' => 'Weights used to compute error count',
9664: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9665: );
9666: my %short_titles = &Apache::lonlocal::texthash (
9667: adminemail => 'Admin E-mail address',
9668: supportemail => 'Support E-mail',
9669: );
9670: return (\%titles,\%short_titles);
9671: }
9672:
1.286 raeburn 9673: sub helpform_fields {
9674: my %titles = &Apache::lonlocal::texthash (
9675: 'username' => 'Name',
9676: 'user' => 'Username/domain',
9677: 'phone' => 'Phone',
9678: 'cc' => 'Cc e-mail',
9679: 'course' => 'Course Details',
9680: 'section' => 'Sections',
1.289 raeburn 9681: 'screenshot' => 'File upload',
1.286 raeburn 9682: );
9683: my @fields = ('username','phone','user','course','section','cc','screenshot');
9684: my %possoptions = (
9685: username => ['yes','no','req'],
1.289 raeburn 9686: phone => ['yes','no','req'],
1.286 raeburn 9687: user => ['yes','no'],
1.289 raeburn 9688: cc => ['yes','no'],
1.286 raeburn 9689: course => ['yes','no'],
9690: section => ['yes','no'],
9691: screenshot => ['yes','no'],
9692: );
9693: my %fieldoptions = &Apache::lonlocal::texthash (
9694: 'yes' => 'Optional',
9695: 'req' => 'Required',
9696: 'no' => "Not shown",
9697: );
9698: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9699: }
9700:
1.72 raeburn 9701: sub tool_titles {
9702: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9703: aboutme => 'Personal web page',
1.86 raeburn 9704: blog => 'Blog',
1.162 raeburn 9705: webdav => 'WebDAV',
1.86 raeburn 9706: portfolio => 'Portfolio',
1.413 ! raeburn 9707: timezone => 'Can set time zone',
1.88 bisitz 9708: official => 'Official courses (with institutional codes)',
9709: unofficial => 'Unofficial courses',
1.98 raeburn 9710: community => 'Communities',
1.216 raeburn 9711: textbook => 'Textbook courses',
1.271 raeburn 9712: placement => 'Placement tests',
1.86 raeburn 9713: );
1.72 raeburn 9714: return %titles;
9715: }
9716:
1.101 raeburn 9717: sub courserequest_titles {
9718: my %titles = &Apache::lonlocal::texthash (
9719: official => 'Official',
9720: unofficial => 'Unofficial',
9721: community => 'Communities',
1.216 raeburn 9722: textbook => 'Textbook',
1.271 raeburn 9723: placement => 'Placement tests',
1.325 raeburn 9724: lti => 'LTI Provider',
1.101 raeburn 9725: norequest => 'Not allowed',
1.325 raeburn 9726: approval => 'Approval by DC',
1.101 raeburn 9727: validate => 'With validation',
9728: autolimit => 'Numerical limit',
1.103 raeburn 9729: unlimited => '(blank for unlimited)',
1.101 raeburn 9730: );
9731: return %titles;
9732: }
9733:
1.163 raeburn 9734: sub authorrequest_titles {
9735: my %titles = &Apache::lonlocal::texthash (
9736: norequest => 'Not allowed',
9737: approval => 'Approval by Dom. Coord.',
9738: automatic => 'Automatic approval',
9739: );
9740: return %titles;
1.210 raeburn 9741: }
1.163 raeburn 9742:
1.101 raeburn 9743: sub courserequest_conditions {
9744: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9745: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9746: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9747: );
9748: return %conditions;
9749: }
9750:
9751:
1.27 raeburn 9752: sub print_usercreation {
1.30 raeburn 9753: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9754: my $numinrow = 4;
1.28 raeburn 9755: my $datatable;
9756: if ($position eq 'top') {
1.30 raeburn 9757: $$rowtotal ++;
1.34 raeburn 9758: my $rowcount = 0;
1.32 raeburn 9759: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9760: if (ref($rules) eq 'HASH') {
9761: if (keys(%{$rules}) > 0) {
1.32 raeburn 9762: $datatable .= &user_formats_row('username',$settings,$rules,
9763: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9764: $$rowtotal ++;
1.32 raeburn 9765: $rowcount ++;
9766: }
9767: }
9768: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9769: if (ref($idrules) eq 'HASH') {
9770: if (keys(%{$idrules}) > 0) {
9771: $datatable .= &user_formats_row('id',$settings,$idrules,
9772: $idruleorder,$numinrow,$rowcount);
9773: $$rowtotal ++;
9774: $rowcount ++;
1.28 raeburn 9775: }
9776: }
1.39 raeburn 9777: if ($rowcount == 0) {
9778: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9779: $$rowtotal ++;
9780: $rowcount ++;
9781: }
1.34 raeburn 9782: } elsif ($position eq 'middle') {
1.224 raeburn 9783: my @creators = ('author','course','requestcrs');
1.37 raeburn 9784: my ($rules,$ruleorder) =
9785: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9786: my %lt = &usercreation_types();
9787: my %checked;
9788: if (ref($settings) eq 'HASH') {
9789: if (ref($settings->{'cancreate'}) eq 'HASH') {
9790: foreach my $item (@creators) {
9791: $checked{$item} = $settings->{'cancreate'}{$item};
9792: }
9793: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9794: foreach my $item (@creators) {
9795: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9796: $checked{$item} = 'none';
9797: }
9798: }
9799: }
9800: }
9801: my $rownum = 0;
9802: foreach my $item (@creators) {
9803: $rownum ++;
1.224 raeburn 9804: if ($checked{$item} eq '') {
9805: $checked{$item} = 'any';
1.34 raeburn 9806: }
9807: my $css_class;
9808: if ($rownum%2) {
9809: $css_class = '';
9810: } else {
9811: $css_class = ' class="LC_odd_row" ';
9812: }
9813: $datatable .= '<tr'.$css_class.'>'.
9814: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9815: '</span></td><td style="text-align: right">';
1.224 raeburn 9816: my @options = ('any');
9817: if (ref($rules) eq 'HASH') {
9818: if (keys(%{$rules}) > 0) {
9819: push(@options,('official','unofficial'));
1.37 raeburn 9820: }
9821: }
1.224 raeburn 9822: push(@options,'none');
1.37 raeburn 9823: foreach my $option (@options) {
1.50 raeburn 9824: my $type = 'radio';
1.34 raeburn 9825: my $check = ' ';
1.224 raeburn 9826: if ($checked{$item} eq $option) {
9827: $check = ' checked="checked" ';
1.34 raeburn 9828: }
9829: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9830: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9831: $item.'" value="'.$option.'"'.$check.'/> '.
9832: $lt{$option}.'</label> </span>';
9833: }
9834: $datatable .= '</td></tr>';
9835: }
1.28 raeburn 9836: } else {
9837: my @contexts = ('author','course','domain');
1.325 raeburn 9838: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9839: my %checked;
9840: if (ref($settings) eq 'HASH') {
9841: if (ref($settings->{'authtypes'}) eq 'HASH') {
9842: foreach my $item (@contexts) {
9843: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9844: foreach my $auth (@authtypes) {
9845: if ($settings->{'authtypes'}{$item}{$auth}) {
9846: $checked{$item}{$auth} = ' checked="checked" ';
9847: }
9848: }
9849: }
9850: }
1.27 raeburn 9851: }
1.35 raeburn 9852: } else {
9853: foreach my $item (@contexts) {
1.36 raeburn 9854: foreach my $auth (@authtypes) {
1.35 raeburn 9855: $checked{$item}{$auth} = ' checked="checked" ';
9856: }
9857: }
1.27 raeburn 9858: }
1.28 raeburn 9859: my %title = &context_names();
9860: my %authname = &authtype_names();
9861: my $rownum = 0;
9862: my $css_class;
9863: foreach my $item (@contexts) {
9864: if ($rownum%2) {
9865: $css_class = '';
9866: } else {
9867: $css_class = ' class="LC_odd_row" ';
9868: }
1.30 raeburn 9869: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9870: '<td>'.$title{$item}.
9871: '</td><td class="LC_left_item">'.
9872: '<span class="LC_nobreak">';
9873: foreach my $auth (@authtypes) {
9874: $datatable .= '<label>'.
9875: '<input type="checkbox" name="'.$item.'_auth" '.
9876: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9877: $authname{$auth}.'</label> ';
9878: }
9879: $datatable .= '</span></td></tr>';
9880: $rownum ++;
1.27 raeburn 9881: }
1.30 raeburn 9882: $$rowtotal += $rownum;
1.27 raeburn 9883: }
9884: return $datatable;
9885: }
9886:
1.224 raeburn 9887: sub print_selfcreation {
9888: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9889: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9890: $emaildomain,$datatable);
1.224 raeburn 9891: if (ref($settings) eq 'HASH') {
9892: if (ref($settings->{'cancreate'}) eq 'HASH') {
9893: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9894: if (ref($createsettings) eq 'HASH') {
9895: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9896: @selfcreate = @{$createsettings->{'selfcreate'}};
9897: } elsif ($createsettings->{'selfcreate'} ne '') {
9898: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9899: @selfcreate = ('email','login','sso');
9900: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9901: @selfcreate = ($createsettings->{'selfcreate'});
9902: }
9903: }
9904: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9905: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9906: }
1.305 raeburn 9907: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9908: $emailoptions = $createsettings->{'emailoptions'};
9909: }
1.303 raeburn 9910: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9911: $emailverified = $createsettings->{'emailverified'};
9912: }
9913: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9914: $emaildomain = $createsettings->{'emaildomain'};
9915: }
1.224 raeburn 9916: }
9917: }
9918: }
9919: my %radiohash;
9920: my $numinrow = 4;
9921: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9922: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9923: if ($position eq 'top') {
9924: my %choices = &Apache::lonlocal::texthash (
9925: cancreate_login => 'Institutional Login',
9926: cancreate_sso => 'Institutional Single Sign On',
9927: );
9928: my @toggles = sort(keys(%choices));
9929: my %defaultchecked = (
9930: 'cancreate_login' => 'off',
9931: 'cancreate_sso' => 'off',
9932: );
1.228 raeburn 9933: my ($onclick,$itemcount);
1.224 raeburn 9934: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9935: \%choices,$itemcount,$onclick);
1.228 raeburn 9936: $$rowtotal += $itemcount;
9937:
1.224 raeburn 9938: if (ref($usertypes) eq 'HASH') {
9939: if (keys(%{$usertypes}) > 0) {
9940: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9941: $dom,$numinrow,$othertitle,
1.305 raeburn 9942: 'statustocreate',$rowtotal);
1.224 raeburn 9943: $$rowtotal ++;
9944: }
9945: }
1.240 raeburn 9946: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9947: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9948: $fieldtitles{'inststatus'} = &mt('Institutional status');
9949: my $rem;
9950: my $numperrow = 2;
9951: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9952: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9953: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9954: '<td class="LC_left_item">'."\n".
1.334 raeburn 9955: '<table>'."\n";
1.240 raeburn 9956: for (my $i=0; $i<@fields; $i++) {
9957: $rem = $i%($numperrow);
9958: if ($rem == 0) {
9959: if ($i > 0) {
9960: $datatable .= '</tr>';
9961: }
9962: $datatable .= '<tr>';
9963: }
9964: my $currval;
1.248 raeburn 9965: if (ref($createsettings) eq 'HASH') {
9966: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9967: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9968: }
1.240 raeburn 9969: }
9970: $datatable .= '<td class="LC_left_item">'.
9971: '<span class="LC_nobreak">'.
9972: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9973: 'value="'.$currval.'" size="10" /> '.
9974: $fieldtitles{$fields[$i]}.'</span></td>';
9975: }
9976: my $colsleft = $numperrow - $rem;
9977: if ($colsleft > 1 ) {
9978: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9979: ' </td>';
9980: } elsif ($colsleft == 1) {
9981: $datatable .= '<td class="LC_left_item"> </td>';
9982: }
9983: $datatable .= '</tr></table></td></tr>';
9984: $$rowtotal ++;
1.224 raeburn 9985: } elsif ($position eq 'middle') {
9986: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9987: my @posstypes;
1.224 raeburn 9988: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9989: @posstypes = @{$types};
9990: }
9991: unless (grep(/^default$/,@posstypes)) {
9992: push(@posstypes,'default');
9993: }
9994: my %usertypeshash;
9995: if (ref($usertypes) eq 'HASH') {
9996: %usertypeshash = %{$usertypes};
9997: }
9998: $usertypeshash{'default'} = $othertitle;
9999: foreach my $status (@posstypes) {
10000: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10001: $numinrow,$$rowtotal,\%usertypeshash);
10002: $$rowtotal ++;
1.224 raeburn 10003: }
10004: } else {
1.236 raeburn 10005: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10006: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10007: );
10008: my @toggles = sort(keys(%choices));
10009: my %defaultchecked = (
10010: 'cancreate_email' => 'off',
10011: );
1.305 raeburn 10012: my $customclass = 'LC_selfcreate_email';
10013: my $classprefix = 'LC_canmodify_emailusername_';
10014: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10015: my $display = 'none';
1.305 raeburn 10016: my $rowstyle = 'display:none';
1.236 raeburn 10017: if (grep(/^\Qemail\E$/,@selfcreate)) {
10018: $display = 'block';
1.305 raeburn 10019: $rowstyle = 'display:table-row';
1.236 raeburn 10020: }
1.305 raeburn 10021: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10022: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10023: \%choices,$$rowtotal,$onclick);
10024: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10025: $rowstyle);
10026: $$rowtotal ++;
10027: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10028: $rowstyle);
10029: $$rowtotal ++;
10030: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10031: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10032: my ($emailrules,$emailruleorder) =
10033: &Apache::lonnet::inst_userrules($dom,'email');
10034: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10035: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10036: if (ref($types) eq 'ARRAY') {
10037: @posstypes = @{$types};
10038: }
10039: if (@posstypes) {
10040: unless (grep(/^default$/,@posstypes)) {
10041: push(@posstypes,'default');
1.302 raeburn 10042: }
10043: if (ref($usertypes) eq 'HASH') {
10044: %usertypeshash = %{$usertypes};
10045: }
1.305 raeburn 10046: my $currassign;
10047: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10048: $currassign = {
10049: selfassign => $domdefaults{'inststatusguest'},
10050: };
10051: @ordered = @{$domdefaults{'inststatusguest'}};
10052: } else {
10053: $currassign = { selfassign => [] };
10054: }
10055: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10056: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10057: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10058: $numinrow,$othertitle,'selfassign',
10059: $rowtotal,$onclicktypes,$customclass,
10060: $rowstyle);
10061: $$rowtotal ++;
1.302 raeburn 10062: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10063: foreach my $status (@posstypes) {
10064: my $css_class;
10065: if ($$rowtotal%2) {
10066: $css_class = 'LC_odd_row ';
10067: }
10068: $css_class .= $customclass;
10069: my $rowid = $optionsprefix.$status;
10070: my $hidden = 1;
10071: my $currstyle = 'display:none';
10072: if (grep(/^\Q$status\E$/,@ordered)) {
10073: $currstyle = $rowstyle;
10074: $hidden = 0;
10075: }
10076: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10077: $emailrules,$emailruleorder,$settings,$status,$rowid,
10078: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10079: unless ($hidden) {
10080: $$rowtotal ++;
10081: }
1.224 raeburn 10082: }
1.302 raeburn 10083: } else {
1.305 raeburn 10084: my $css_class;
10085: if ($$rowtotal%2) {
10086: $css_class = 'LC_odd_row ';
10087: }
10088: $css_class .= $customclass;
1.302 raeburn 10089: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10090: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10091: $emailrules,$emailruleorder,$settings,'default','',
10092: $othertitle,$css_class,$rowstyle,$intdom);
10093: $$rowtotal ++;
1.224 raeburn 10094: }
10095: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10096: $numinrow = 1;
1.305 raeburn 10097: if (@posstypes) {
10098: foreach my $status (@posstypes) {
10099: my $rowid = $classprefix.$status;
10100: my $datarowstyle = 'display:none';
10101: if (grep(/^\Q$status\E$/,@ordered)) {
10102: $datarowstyle = $rowstyle;
10103: }
10104: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10105: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10106: $infotitles,$rowid,$customclass,$datarowstyle);
10107: unless ($datarowstyle eq 'display:none') {
10108: $$rowtotal ++;
10109: }
1.224 raeburn 10110: }
1.305 raeburn 10111: } else {
10112: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10113: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10114: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10115: }
10116: }
10117: return $datatable;
10118: }
10119:
1.305 raeburn 10120: sub selfcreate_javascript {
10121: return <<"ENDSCRIPT";
10122:
10123: <script type="text/javascript">
10124: // <![CDATA[
10125:
10126: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10127: var x = document.getElementsByClassName(target);
10128: var insttypes = 0;
10129: var insttypeRegExp = new RegExp(prefix);
10130: if ((x.length != undefined) && (x.length > 0)) {
10131: if (form.elements[radio].length != undefined) {
10132: for (var i=0; i<form.elements[radio].length; i++) {
10133: if (form.elements[radio][i].checked) {
10134: if (form.elements[radio][i].value == 1) {
10135: for (var j=0; j<x.length; j++) {
10136: if (x[j].id == 'undefined') {
10137: x[j].style.display = 'table-row';
10138: } else if (insttypeRegExp.test(x[j].id)) {
10139: insttypes ++;
10140: } else {
10141: x[j].style.display = 'table-row';
10142: }
10143: }
10144: } else {
10145: for (var j=0; j<x.length; j++) {
10146: x[j].style.display = 'none';
10147: }
1.236 raeburn 10148: }
1.305 raeburn 10149: break;
10150: }
10151: }
10152: if (insttypes > 0) {
10153: toggleDataRow(form,checkbox,target,altprefix);
10154: toggleDataRow(form,checkbox,target,prefix,1);
10155: }
10156: }
10157: }
10158: return;
10159: }
10160:
10161: function toggleDataRow(form,checkbox,target,prefix,docount) {
10162: if (form.elements[checkbox].length != undefined) {
10163: var count = 0;
10164: if (docount) {
10165: for (var i=0; i<form.elements[checkbox].length; i++) {
10166: if (form.elements[checkbox][i].checked) {
10167: count ++;
1.236 raeburn 10168: }
1.305 raeburn 10169: }
10170: }
10171: for (var i=0; i<form.elements[checkbox].length; i++) {
10172: var type = form.elements[checkbox][i].value;
10173: if (document.getElementById(prefix+type)) {
10174: if (form.elements[checkbox][i].checked) {
10175: document.getElementById(prefix+type).style.display = 'table-row';
10176: if (count % 2 == 1) {
10177: document.getElementById(prefix+type).className = target+' LC_odd_row';
10178: } else {
10179: document.getElementById(prefix+type).className = target;
1.236 raeburn 10180: }
1.305 raeburn 10181: count ++;
1.236 raeburn 10182: } else {
1.305 raeburn 10183: document.getElementById(prefix+type).style.display = 'none';
10184: }
10185: }
10186: }
10187: }
10188: return;
10189: }
10190:
10191: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10192: var caller = radio+'_'+status;
10193: if (form.elements[caller].length != undefined) {
10194: for (var i=0; i<form.elements[caller].length; i++) {
10195: if (form.elements[caller][i].checked) {
10196: if (document.getElementById(altprefix+'_inst_'+status)) {
10197: var curr = form.elements[caller][i].value;
10198: if (prefix) {
10199: document.getElementById(prefix+'_'+status).style.display = 'none';
10200: }
10201: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10202: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10203: if (curr == 'custom') {
10204: if (prefix) {
10205: document.getElementById(prefix+'_'+status).style.display = 'inline';
10206: }
10207: } else if (curr == 'inst') {
10208: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10209: } else if (curr == 'noninst') {
10210: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10211: }
1.305 raeburn 10212: break;
1.236 raeburn 10213: }
10214: }
10215: }
10216: }
10217: }
10218:
1.305 raeburn 10219: // ]]>
10220: </script>
10221:
10222: ENDSCRIPT
10223: }
10224:
10225: sub noninst_users {
10226: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
10227: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
10228: my $class = 'LC_left_item';
10229: if ($css_class) {
10230: $css_class = ' class="'.$css_class.'"';
10231: }
10232: if ($rowid) {
10233: $rowid = ' id="'.$rowid.'"';
10234: }
10235: if ($rowstyle) {
10236: $rowstyle = ' style="'.$rowstyle.'"';
10237: }
10238: my ($output,$description);
10239: if ($type eq 'default') {
10240: $description = &mt('Requests for: [_1]',$typetitle);
10241: } else {
10242: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10243: }
10244: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
10245: "<td>$description</td>\n".
10246: '<td class="'.$class.'" colspan="2">'.
10247: '<table><tr>';
10248: my %headers = &Apache::lonlocal::texthash(
10249: approve => 'Processing',
10250: email => 'E-mail',
10251: username => 'Username',
10252: );
10253: foreach my $item ('approve','email','username') {
10254: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10255: }
1.305 raeburn 10256: $output .= '</tr><tr>';
10257: foreach my $item ('approve','email','username') {
1.306 raeburn 10258: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10259: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10260: if ($item eq 'approve') {
10261: %choices = &Apache::lonlocal::texthash (
10262: automatic => 'Automatically approved',
10263: approval => 'Queued for approval',
10264: );
10265: @options = ('automatic','approval');
10266: $hashref = $processing;
10267: $defoption = 'automatic';
10268: $name = 'cancreate_emailprocess_'.$type;
10269: } elsif ($item eq 'email') {
10270: %choices = &Apache::lonlocal::texthash (
10271: any => 'Any e-mail',
10272: inst => 'Institutional only',
10273: noninst => 'Non-institutional only',
10274: custom => 'Custom restrictions',
10275: );
10276: @options = ('any','inst','noninst');
10277: my $showcustom;
10278: if (ref($emailrules) eq 'HASH') {
10279: if (keys(%{$emailrules}) > 0) {
10280: push(@options,'custom');
10281: $showcustom = 'cancreate_emailrule';
10282: if (ref($settings) eq 'HASH') {
10283: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10284: foreach my $rule (@{$settings->{'email_rule'}}) {
10285: if (exists($emailrules->{$rule})) {
10286: $hascustom ++;
10287: }
10288: }
10289: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10290: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10291: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10292: if (exists($emailrules->{$rule})) {
10293: $hascustom ++;
10294: }
10295: }
10296: }
10297: }
10298: }
10299: }
10300: }
10301: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10302: "'cancreate_emaildomain','$type'".');"';
10303: $hashref = $emailoptions;
10304: $defoption = 'any';
10305: $name = 'cancreate_emailoptions_'.$type;
10306: } elsif ($item eq 'username') {
10307: %choices = &Apache::lonlocal::texthash (
10308: all => 'Same as e-mail',
10309: first => 'Omit @domain',
10310: free => 'Free to choose',
10311: );
10312: @options = ('all','first','free');
10313: $hashref = $emailverified;
10314: $defoption = 'all';
10315: $name = 'cancreate_usernameoptions_'.$type;
10316: }
10317: foreach my $option (@options) {
10318: my $checked;
10319: if (ref($hashref) eq 'HASH') {
10320: if ($type eq '') {
10321: if (!exists($hashref->{'default'})) {
10322: if ($option eq $defoption) {
10323: $checked = ' checked="checked"';
10324: }
10325: } else {
10326: if ($hashref->{'default'} eq $option) {
10327: $checked = ' checked="checked"';
10328: }
1.303 raeburn 10329: }
10330: } else {
1.305 raeburn 10331: if (!exists($hashref->{$type})) {
10332: if ($option eq $defoption) {
10333: $checked = ' checked="checked"';
10334: }
10335: } else {
10336: if ($hashref->{$type} eq $option) {
10337: $checked = ' checked="checked"';
10338: }
1.303 raeburn 10339: }
10340: }
1.305 raeburn 10341: } elsif (($item eq 'email') && ($hascustom)) {
10342: if ($option eq 'custom') {
10343: $checked = ' checked="checked"';
10344: }
10345: } elsif ($option eq $defoption) {
10346: $checked = ' checked="checked"';
10347: }
10348: $output .= '<span class="LC_nobreak"><label>'.
10349: '<input type="radio" name="'.$name.'"'.
10350: $checked.' value="'.$option.'"'.$onclick.' />'.
10351: $choices{$option}.'</label></span><br />';
10352: if ($item eq 'email') {
10353: if ($option eq 'custom') {
10354: my $id = 'cancreate_emailrule_'.$type;
10355: my $display = 'none';
10356: if ($checked) {
10357: $display = 'inline';
1.303 raeburn 10358: }
1.305 raeburn 10359: my $numinrow = 2;
10360: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10361: '<legend>'.&mt('Disallow').'</legend><table>'.
10362: &user_formats_row('email',$settings,$emailrules,
10363: $emailruleorder,$numinrow,'',$type);
10364: '</table></fieldset>';
10365: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10366: my %text = &Apache::lonlocal::texthash (
10367: inst => 'must end:',
10368: noninst => 'cannot end:',
10369: );
10370: my $value;
10371: if (ref($emaildomain) eq 'HASH') {
10372: if (ref($emaildomain->{$type}) eq 'HASH') {
10373: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10374: }
10375: }
1.305 raeburn 10376: if ($value eq '') {
10377: $value = '@'.$intdom;
10378: }
10379: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10380: my $display = 'none';
10381: if ($checked) {
10382: $display = 'inline';
10383: }
10384: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10385: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10386: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10387: '</div>';
1.303 raeburn 10388: }
10389: }
10390: }
1.305 raeburn 10391: $output .= '</td>'."\n";
1.303 raeburn 10392: }
1.305 raeburn 10393: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10394: return $output;
10395: }
10396:
1.165 raeburn 10397: sub captcha_choice {
1.305 raeburn 10398: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10399: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10400: $vertext,$currver);
1.165 raeburn 10401: my %lt = &captcha_phrases();
10402: $keyentry = 'hidden';
1.354 raeburn 10403: my $colspan=2;
1.165 raeburn 10404: if ($context eq 'cancreate') {
1.224 raeburn 10405: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10406: } elsif ($context eq 'login') {
10407: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10408: } elsif ($context eq 'passwords') {
10409: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10410: $colspan=1;
1.165 raeburn 10411: }
10412: if (ref($settings) eq 'HASH') {
10413: if ($settings->{'captcha'}) {
10414: $checked{$settings->{'captcha'}} = ' checked="checked"';
10415: } else {
10416: $checked{'original'} = ' checked="checked"';
10417: }
10418: if ($settings->{'captcha'} eq 'recaptcha') {
10419: $pubtext = $lt{'pub'};
10420: $privtext = $lt{'priv'};
10421: $keyentry = 'text';
1.269 raeburn 10422: $vertext = $lt{'ver'};
10423: $currver = $settings->{'recaptchaversion'};
10424: if ($currver ne '2') {
10425: $currver = 1;
10426: }
1.165 raeburn 10427: }
10428: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10429: $currpub = $settings->{'recaptchakeys'}{'public'};
10430: $currpriv = $settings->{'recaptchakeys'}{'private'};
10431: }
10432: } else {
10433: $checked{'original'} = ' checked="checked"';
10434: }
1.305 raeburn 10435: my $css_class;
10436: if ($itemcount%2) {
10437: $css_class = 'LC_odd_row';
10438: }
10439: if ($customcss) {
10440: $css_class .= " $customcss";
10441: }
10442: $css_class =~ s/^\s+//;
10443: if ($css_class) {
10444: $css_class = ' class="'.$css_class.'"';
10445: }
10446: if ($rowstyle) {
10447: $css_class .= ' style="'.$rowstyle.'"';
10448: }
1.169 raeburn 10449: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10450: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10451: '<table><tr><td>'."\n";
10452: foreach my $option ('original','recaptcha','notused') {
10453: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10454: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10455: $lt{$option}.'</label></span>';
10456: unless ($option eq 'notused') {
10457: $output .= (' 'x2)."\n";
10458: }
10459: }
10460: #
10461: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10462: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10463: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10464: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10465: #
1.165 raeburn 10466: $output .= '</td></tr>'."\n".
1.305 raeburn 10467: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10468: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10469: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10470: $currpub.'" size="40" /></span><br />'."\n".
10471: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10472: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10473: $currpriv.'" size="40" /></span><br />'.
10474: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10475: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10476: $currver.'" size="3" /></span><br />'.
10477: '</td></tr></table>'."\n".
1.165 raeburn 10478: '</td></tr>';
10479: return $output;
10480: }
10481:
1.32 raeburn 10482: sub user_formats_row {
1.305 raeburn 10483: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10484: my $output;
10485: my %text = (
10486: 'username' => 'new usernames',
10487: 'id' => 'IDs',
10488: );
1.409 raeburn 10489: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10490: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10491: $output = '<tr '.$css_class.'>'.
10492: '<td><span class="LC_nobreak">'.
10493: &mt("Format rules to check for $text{$type}: ").
10494: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10495: }
1.27 raeburn 10496: my $rem;
10497: if (ref($ruleorder) eq 'ARRAY') {
10498: for (my $i=0; $i<@{$ruleorder}; $i++) {
10499: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10500: my $rem = $i%($numinrow);
10501: if ($rem == 0) {
10502: if ($i > 0) {
10503: $output .= '</tr>';
10504: }
10505: $output .= '<tr>';
10506: }
10507: my $check = ' ';
1.39 raeburn 10508: if (ref($settings) eq 'HASH') {
10509: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10510: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10511: $check = ' checked="checked" ';
10512: }
1.305 raeburn 10513: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10514: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10515: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10516: $check = ' checked="checked" ';
10517: }
10518: }
1.27 raeburn 10519: }
10520: }
1.305 raeburn 10521: my $name = $type.'_rule';
10522: if ($type eq 'email') {
10523: $name .= '_'.$status;
10524: }
1.27 raeburn 10525: $output .= '<td class="LC_left_item">'.
10526: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10527: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10528: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10529: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10530: }
10531: }
10532: $rem = @{$ruleorder}%($numinrow);
10533: }
1.305 raeburn 10534: my $colsleft;
10535: if ($rem) {
10536: $colsleft = $numinrow - $rem;
10537: }
1.27 raeburn 10538: if ($colsleft > 1 ) {
10539: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10540: ' </td>';
10541: } elsif ($colsleft == 1) {
10542: $output .= '<td class="LC_left_item"> </td>';
10543: }
1.409 raeburn 10544: $output .= '</tr>';
10545: unless (($type eq 'email') || ($type eq 'unamemap')) {
10546: $output .= '</table></td></tr>';
1.305 raeburn 10547: }
1.27 raeburn 10548: return $output;
10549: }
10550:
1.34 raeburn 10551: sub usercreation_types {
10552: my %lt = &Apache::lonlocal::texthash (
10553: author => 'When adding a co-author',
10554: course => 'When adding a user to a course',
1.100 raeburn 10555: requestcrs => 'When requesting a course',
1.34 raeburn 10556: any => 'Any',
10557: official => 'Institutional only ',
10558: unofficial => 'Non-institutional only',
10559: none => 'None',
10560: );
10561: return %lt;
1.48 raeburn 10562: }
1.34 raeburn 10563:
1.224 raeburn 10564: sub selfcreation_types {
10565: my %lt = &Apache::lonlocal::texthash (
10566: selfcreate => 'User creates own account',
10567: any => 'Any',
10568: official => 'Institutional only ',
10569: unofficial => 'Non-institutional only',
10570: email => 'E-mail address',
10571: login => 'Institutional Login',
10572: sso => 'SSO',
10573: );
10574: }
10575:
1.28 raeburn 10576: sub authtype_names {
10577: my %lt = &Apache::lonlocal::texthash(
10578: int => 'Internal',
10579: krb4 => 'Kerberos 4',
10580: krb5 => 'Kerberos 5',
10581: loc => 'Local',
1.325 raeburn 10582: lti => 'LTI',
1.28 raeburn 10583: );
10584: return %lt;
10585: }
10586:
10587: sub context_names {
10588: my %context_title = &Apache::lonlocal::texthash(
10589: author => 'Creating users when an Author',
10590: course => 'Creating users when in a course',
10591: domain => 'Creating users when a Domain Coordinator',
10592: );
10593: return %context_title;
10594: }
10595:
1.33 raeburn 10596: sub print_usermodification {
10597: my ($position,$dom,$settings,$rowtotal) = @_;
10598: my $numinrow = 4;
10599: my ($context,$datatable,$rowcount);
10600: if ($position eq 'top') {
10601: $rowcount = 0;
10602: $context = 'author';
10603: foreach my $role ('ca','aa') {
10604: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10605: $numinrow,$rowcount);
10606: $$rowtotal ++;
10607: $rowcount ++;
10608: }
1.230 raeburn 10609: } elsif ($position eq 'bottom') {
1.33 raeburn 10610: $context = 'course';
10611: $rowcount = 0;
10612: foreach my $role ('st','ep','ta','in','cr') {
10613: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10614: $numinrow,$rowcount);
10615: $$rowtotal ++;
10616: $rowcount ++;
10617: }
10618: }
10619: return $datatable;
10620: }
10621:
1.43 raeburn 10622: sub print_defaults {
1.236 raeburn 10623: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10624: my $rownum = 0;
1.294 raeburn 10625: my ($datatable,$css_class,$titles);
10626: unless ($position eq 'bottom') {
10627: $titles = &defaults_titles($dom);
10628: }
1.236 raeburn 10629: if ($position eq 'top') {
10630: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10631: 'datelocale_def','portal_def');
10632: my %defaults;
10633: if (ref($settings) eq 'HASH') {
10634: %defaults = %{$settings};
1.43 raeburn 10635: } else {
1.236 raeburn 10636: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10637: foreach my $item (@items) {
10638: $defaults{$item} = $domdefaults{$item};
10639: }
1.43 raeburn 10640: }
1.236 raeburn 10641: foreach my $item (@items) {
10642: if ($rownum%2) {
10643: $css_class = '';
10644: } else {
10645: $css_class = ' class="LC_odd_row" ';
10646: }
10647: $datatable .= '<tr'.$css_class.'>'.
10648: '<td><span class="LC_nobreak">'.$titles->{$item}.
10649: '</span></td><td class="LC_right_item" colspan="3">';
10650: if ($item eq 'auth_def') {
1.325 raeburn 10651: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10652: my %shortauth = (
10653: internal => 'int',
10654: krb4 => 'krb4',
10655: krb5 => 'krb5',
1.325 raeburn 10656: localauth => 'loc',
10657: lti => 'lti',
1.236 raeburn 10658: );
10659: my %authnames = &authtype_names();
10660: foreach my $auth (@authtypes) {
10661: my $checked = ' ';
10662: if ($defaults{$item} eq $auth) {
10663: $checked = ' checked="checked" ';
10664: }
10665: $datatable .= '<label><input type="radio" name="'.$item.
10666: '" value="'.$auth.'"'.$checked.'/>'.
10667: $authnames{$shortauth{$auth}}.'</label> ';
10668: }
10669: } elsif ($item eq 'timezone_def') {
10670: my $includeempty = 1;
10671: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10672: } elsif ($item eq 'datelocale_def') {
10673: my $includeempty = 1;
10674: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10675: } elsif ($item eq 'lang_def') {
1.263 raeburn 10676: my $includeempty = 1;
10677: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 10678: } else {
10679: my $size;
10680: if ($item eq 'portal_def') {
10681: $size = ' size="25"';
10682: }
10683: $datatable .= '<input type="text" name="'.$item.'" value="'.
10684: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 10685: }
1.236 raeburn 10686: $datatable .= '</td></tr>';
10687: $rownum ++;
10688: }
1.409 raeburn 10689: } elsif ($position eq 'middle') {
1.294 raeburn 10690: my %defaults;
10691: if (ref($settings) eq 'HASH') {
1.354 raeburn 10692: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10693: my $maxnum = @{$settings->{'inststatusorder'}};
10694: for (my $i=0; $i<$maxnum; $i++) {
10695: $css_class = $rownum%2?' class="LC_odd_row"':'';
10696: my $item = $settings->{'inststatusorder'}->[$i];
10697: my $title = $settings->{'inststatustypes'}->{$item};
10698: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10699: $datatable .= '<tr'.$css_class.'>'.
10700: '<td><span class="LC_nobreak">'.
10701: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10702: for (my $k=0; $k<=$maxnum; $k++) {
10703: my $vpos = $k+1;
10704: my $selstr;
10705: if ($k == $i) {
10706: $selstr = ' selected="selected" ';
10707: }
10708: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10709: }
10710: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10711: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10712: &mt('delete').'</span></td>'.
1.380 raeburn 10713: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10714: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10715: '</span></td></tr>';
10716: }
10717: $css_class = $rownum%2?' class="LC_odd_row"':'';
10718: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10719: $datatable .= '<tr '.$css_class.'>'.
10720: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10721: for (my $k=0; $k<=$maxnum; $k++) {
10722: my $vpos = $k+1;
10723: my $selstr;
10724: if ($k == $maxnum) {
10725: $selstr = ' selected="selected" ';
10726: }
10727: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10728: }
10729: $datatable .= '</select> '.&mt('Internal ID:').
10730: '<input type="text" size="10" name="addinststatus" value="" />'.
10731: ' '.&mt('(new)').
10732: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10733: &mt('Name displayed').':'.
1.354 raeburn 10734: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10735: '</tr>'."\n";
10736: $rownum ++;
1.294 raeburn 10737: }
1.354 raeburn 10738: }
1.409 raeburn 10739: } else {
10740: my ($unamemaprules,$ruleorder) =
10741: &Apache::lonnet::inst_userrules($dom,'unamemap');
10742: $css_class = $rownum%2?' class="LC_odd_row"':'';
10743: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10744: my $numinrow = 2;
10745: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10746: &user_formats_row('unamemap',$settings,$unamemaprules,
10747: $ruleorder,$numinrow).
10748: '</table></td></tr>';
10749: }
10750: if ($datatable eq '') {
10751: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10752: &mt('No rules set for domain in customized localenroll.pm').
10753: '</td></tr>';
10754: }
1.354 raeburn 10755: }
10756: $$rowtotal += $rownum;
1.43 raeburn 10757: return $datatable;
10758: }
10759:
1.168 raeburn 10760: sub get_languages_hash {
10761: my %langchoices;
10762: foreach my $id (&Apache::loncommon::languageids()) {
10763: my $code = &Apache::loncommon::supportedlanguagecode($id);
10764: if ($code ne '') {
10765: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10766: }
10767: }
10768: return %langchoices;
10769: }
10770:
1.43 raeburn 10771: sub defaults_titles {
1.141 raeburn 10772: my ($dom) = @_;
1.43 raeburn 10773: my %titles = &Apache::lonlocal::texthash (
10774: 'auth_def' => 'Default authentication type',
10775: 'auth_arg_def' => 'Default authentication argument',
10776: 'lang_def' => 'Default language',
1.54 raeburn 10777: 'timezone_def' => 'Default timezone',
1.68 raeburn 10778: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10779: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 10780: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10781: 'intauth_check' => 'Check bcrypt cost if authenticated',
10782: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10783: );
1.141 raeburn 10784: if ($dom) {
10785: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10786: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10787: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10788: $protocol = 'http' if ($protocol ne 'https');
10789: if ($uint_dom) {
10790: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10791: $uint_dom);
10792: }
10793: }
1.43 raeburn 10794: return (\%titles);
10795: }
10796:
1.346 raeburn 10797: sub print_scantron {
10798: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10799: if ($position eq 'top') {
10800: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10801: } else {
10802: return &print_scantronconfig($dom,$settings,\$rowtotal);
10803: }
10804: }
10805:
10806: sub scantron_javascript {
10807: return <<"ENDSCRIPT";
10808:
10809: <script type="text/javascript">
10810: // <![CDATA[
10811:
10812: function toggleScantron(form) {
1.347 raeburn 10813: var csvfieldset = new Array();
1.346 raeburn 10814: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10815: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10816: }
10817: if (document.getElementById('scantroncsv_options')) {
10818: csvfieldset.push(document.getElementById('scantroncsv_options'));
10819: }
10820: if (csvfieldset.length) {
1.346 raeburn 10821: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10822: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10823: if (scantroncsv.checked) {
1.347 raeburn 10824: for (var i=0; i<csvfieldset.length; i++) {
10825: csvfieldset[i].style.display = 'block';
10826: }
1.346 raeburn 10827: } else {
1.347 raeburn 10828: for (var i=0; i<csvfieldset.length; i++) {
10829: csvfieldset[i].style.display = 'none';
10830: }
1.346 raeburn 10831: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10832: if (csvselects.length) {
10833: for (var j=0; j<csvselects.length; j++) {
10834: csvselects[j].selectedIndex = 0;
10835: }
10836: }
10837: }
10838: }
10839: }
10840: return;
10841: }
10842: // ]]>
10843: </script>
10844:
10845: ENDSCRIPT
10846:
10847: }
10848:
1.46 raeburn 10849: sub print_scantronformat {
10850: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10851: my $itemcount = 1;
1.60 raeburn 10852: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10853: %confhash);
1.46 raeburn 10854: my $switchserver = &check_switchserver($dom,$confname);
10855: my %lt = &Apache::lonlocal::texthash (
1.95 www 10856: default => 'Default bubblesheet format file error',
10857: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10858: );
10859: my %scantronfiles = (
10860: default => 'default.tab',
10861: custom => 'custom.tab',
10862: );
10863: foreach my $key (keys(%scantronfiles)) {
10864: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10865: .$scantronfiles{$key};
10866: }
10867: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10868: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10869: if (!$switchserver) {
10870: my $servadm = $r->dir_config('lonAdmEMail');
10871: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10872: if ($configuserok eq 'ok') {
10873: if ($author_ok eq 'ok') {
10874: my %legacyfile = (
1.346 raeburn 10875: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10876: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10877: );
10878: my %md5chk;
10879: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10880: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10881: chomp($md5chk{$type});
1.46 raeburn 10882: }
10883: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10884: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10885: ($scantronurls{$type},my $error) =
1.46 raeburn 10886: &legacy_scantronformat($r,$dom,$confname,
10887: $type,$legacyfile{$type},
10888: $scantronurls{$type},
10889: $scantronfiles{$type});
1.60 raeburn 10890: if ($error ne '') {
10891: $error{$type} = $error;
10892: }
10893: }
10894: if (keys(%error) == 0) {
10895: $is_custom = 1;
1.346 raeburn 10896: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10897: $scantronurls{'custom'};
1.346 raeburn 10898: my $putresult =
1.60 raeburn 10899: &Apache::lonnet::put_dom('configuration',
10900: \%confhash,$dom);
10901: if ($putresult ne 'ok') {
1.346 raeburn 10902: $error{'custom'} =
1.60 raeburn 10903: '<span class="LC_error">'.
10904: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10905: }
1.46 raeburn 10906: }
10907: } else {
1.60 raeburn 10908: ($scantronurls{'default'},my $error) =
1.46 raeburn 10909: &legacy_scantronformat($r,$dom,$confname,
10910: 'default',$legacyfile{'default'},
10911: $scantronurls{'default'},
10912: $scantronfiles{'default'});
1.60 raeburn 10913: if ($error eq '') {
10914: $confhash{'scantron'}{'scantronformat'} = '';
10915: my $putresult =
10916: &Apache::lonnet::put_dom('configuration',
10917: \%confhash,$dom);
10918: if ($putresult ne 'ok') {
10919: $error{'default'} =
10920: '<span class="LC_error">'.
10921: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10922: }
10923: } else {
10924: $error{'default'} = $error;
10925: }
1.46 raeburn 10926: }
10927: }
10928: }
10929: } else {
1.95 www 10930: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10931: }
10932: }
10933: if (ref($settings) eq 'HASH') {
10934: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10935: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10936: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10937: $scantronurl = '';
10938: } else {
10939: $scantronurl = $settings->{'scantronformat'};
10940: }
10941: $is_custom = 1;
10942: } else {
10943: $scantronurl = $scantronurls{'default'};
10944: }
10945: } else {
1.60 raeburn 10946: if ($is_custom) {
10947: $scantronurl = $scantronurls{'custom'};
10948: } else {
10949: $scantronurl = $scantronurls{'default'};
10950: }
1.46 raeburn 10951: }
10952: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10953: $datatable .= '<tr'.$css_class.'>';
10954: if (!$is_custom) {
1.65 raeburn 10955: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10956: '<span class="LC_nobreak">';
1.46 raeburn 10957: if ($scantronurl) {
1.199 raeburn 10958: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10959: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10960: } else {
10961: $datatable = &mt('File unavailable for display');
10962: }
1.65 raeburn 10963: $datatable .= '</span></td>';
1.60 raeburn 10964: if (keys(%error) == 0) {
1.306 raeburn 10965: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10966: if (!$switchserver) {
10967: $datatable .= &mt('Upload:').'<br />';
10968: }
10969: } else {
10970: my $errorstr;
10971: foreach my $key (sort(keys(%error))) {
10972: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10973: }
10974: $datatable .= '<td>'.$errorstr;
10975: }
1.46 raeburn 10976: } else {
10977: if (keys(%error) > 0) {
10978: my $errorstr;
10979: foreach my $key (sort(keys(%error))) {
10980: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10981: }
1.60 raeburn 10982: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10983: } elsif ($scantronurl) {
1.199 raeburn 10984: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10985: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10986: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10987: $link.
10988: '<label><input type="checkbox" name="scantronformat_del"'.
10989: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10990: '<td><span class="LC_nobreak"> '.
10991: &mt('Replace:').'</span><br />';
1.46 raeburn 10992: }
10993: }
10994: if (keys(%error) == 0) {
10995: if ($switchserver) {
10996: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10997: } else {
1.65 raeburn 10998: $datatable .='<span class="LC_nobreak"> '.
10999: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11000: }
11001: }
11002: $datatable .= '</td></tr>';
11003: $$rowtotal ++;
11004: return $datatable;
11005: }
11006:
11007: sub legacy_scantronformat {
11008: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11009: my ($url,$error);
11010: my @statinfo = &Apache::lonnet::stat_file($newurl);
11011: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
11012: (my $result,$url) =
11013: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
11014: '','',$newfile);
11015: if ($result ne 'ok') {
1.130 raeburn 11016: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11017: }
11018: }
11019: return ($url,$error);
11020: }
1.43 raeburn 11021:
1.346 raeburn 11022: sub print_scantronconfig {
11023: my ($dom,$settings,$rowtotal) = @_;
11024: my $itemcount = 2;
11025: my $is_checked = ' checked="checked"';
1.347 raeburn 11026: my %optionson = (
11027: hdr => ' checked="checked"',
11028: pad => ' checked="checked"',
11029: rem => ' checked="checked"',
11030: );
11031: my %optionsoff = (
11032: hdr => '',
11033: pad => '',
11034: rem => '',
11035: );
1.346 raeburn 11036: my $currcsvsty = 'none';
1.347 raeburn 11037: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11038: my @fields = &scantroncsv_fields();
11039: my %titles = &scantronconfig_titles();
11040: if (ref($settings) eq 'HASH') {
11041: if (ref($settings->{config}) eq 'HASH') {
11042: if ($settings->{config}->{dat}) {
11043: $checked{'dat'} = $is_checked;
11044: }
11045: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11046: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11047: %csvfields = %{$settings->{config}->{csv}->{fields}};
11048: if (keys(%csvfields) > 0) {
11049: $checked{'csv'} = $is_checked;
11050: $currcsvsty = 'block';
11051: }
11052: }
11053: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11054: %csvoptions = %{$settings->{config}->{csv}->{options}};
11055: foreach my $option (keys(%optionson)) {
11056: unless ($csvoptions{$option}) {
11057: $optionsoff{$option} = $optionson{$option};
11058: $optionson{$option} = '';
11059: }
11060: }
1.346 raeburn 11061: }
11062: }
11063: } else {
11064: $checked{'dat'} = $is_checked;
11065: }
11066: } else {
11067: $checked{'dat'} = $is_checked;
11068: }
11069: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11070: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11071: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11072: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11073: foreach my $item ('dat','csv') {
11074: my $id;
11075: if ($item eq 'csv') {
11076: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11077: }
1.346 raeburn 11078: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11079: $titles{$item}.'</label>'.(' 'x3);
11080: if ($item eq 'csv') {
11081: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11082: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11083: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11084: foreach my $col (@fields) {
11085: my $selnone;
11086: if ($csvfields{$col} eq '') {
11087: $selnone = ' selected="selected"';
11088: }
11089: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11090: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11091: '<option value=""'.$selnone.'></option>';
11092: for (my $i=0; $i<20; $i++) {
11093: my $shown = $i+1;
11094: my $sel;
11095: unless ($selnone) {
11096: if (exists($csvfields{$col})) {
11097: if ($csvfields{$col} == $i) {
11098: $sel = ' selected="selected"';
11099: }
11100: }
11101: }
11102: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11103: }
11104: $datatable .= '</select></td></tr>';
11105: }
1.347 raeburn 11106: $datatable .= '</table></fieldset>'.
11107: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11108: '<legend>'.&mt('CSV Options').'</legend>';
11109: foreach my $option ('hdr','pad','rem') {
11110: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11111: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11112: &mt('Yes').'</label>'.(' 'x2)."\n".
11113: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11114: }
11115: $datatable .= '</fieldset>';
1.346 raeburn 11116: $itemcount ++;
11117: }
11118: }
11119: $datatable .= '</td></tr>';
11120: $$rowtotal ++;
11121: return $datatable;
11122: }
11123:
11124: sub scantronconfig_titles {
11125: return &Apache::lonlocal::texthash(
11126: dat => 'Standard format (.dat)',
11127: csv => 'Comma separated values (.csv)',
1.347 raeburn 11128: hdr => 'Remove first line in file (contains column titles)',
11129: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11130: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11131: CODE => 'CODE',
11132: ID => 'Student ID',
11133: PaperID => 'Paper ID',
11134: FirstName => 'First Name',
11135: LastName => 'Last Name',
11136: FirstQuestion => 'First Question Response',
11137: Section => 'Section',
11138: );
11139: }
11140:
11141: sub scantroncsv_fields {
11142: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11143: }
11144:
1.49 raeburn 11145: sub print_coursecategories {
1.57 raeburn 11146: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11147: my $datatable;
11148: if ($position eq 'top') {
1.238 raeburn 11149: my (%checked);
11150: my @catitems = ('unauth','auth');
11151: my @cattypes = ('std','domonly','codesrch','none');
11152: $checked{'unauth'} = 'std';
11153: $checked{'auth'} = 'std';
11154: if (ref($settings) eq 'HASH') {
11155: foreach my $type (@cattypes) {
11156: if ($type eq $settings->{'unauth'}) {
11157: $checked{'unauth'} = $type;
11158: }
11159: if ($type eq $settings->{'auth'}) {
11160: $checked{'auth'} = $type;
11161: }
11162: }
11163: }
11164: my %lt = &Apache::lonlocal::texthash (
11165: unauth => 'Catalog type for unauthenticated users',
11166: auth => 'Catalog type for authenticated users',
11167: none => 'No catalog',
11168: std => 'Standard catalog',
11169: domonly => 'Domain-only catalog',
11170: codesrch => "Code search form",
11171: );
11172: my $itemcount = 0;
11173: foreach my $item (@catitems) {
11174: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11175: $datatable .= '<tr '.$css_class.'>'.
11176: '<td>'.$lt{$item}.'</td>'.
11177: '<td class="LC_right_item"><span class="LC_nobreak">';
11178: foreach my $type (@cattypes) {
11179: my $ischecked;
11180: if ($checked{$item} eq $type) {
11181: $ischecked=' checked="checked"';
11182: }
11183: $datatable .= '<label>'.
11184: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11185: ' />'.$lt{$type}.'</label> ';
11186: }
1.327 raeburn 11187: $datatable .= '</span></td></tr>';
1.238 raeburn 11188: $itemcount ++;
11189: }
11190: $$rowtotal += $itemcount;
11191: } elsif ($position eq 'middle') {
1.57 raeburn 11192: my $toggle_cats_crs = ' ';
11193: my $toggle_cats_dom = ' checked="checked" ';
11194: my $can_cat_crs = ' ';
11195: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11196: my $toggle_catscomm_comm = ' ';
11197: my $toggle_catscomm_dom = ' checked="checked" ';
11198: my $can_catcomm_comm = ' ';
11199: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11200: my $toggle_catsplace_place = ' ';
11201: my $toggle_catsplace_dom = ' checked="checked" ';
11202: my $can_catplace_place = ' ';
11203: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11204:
1.57 raeburn 11205: if (ref($settings) eq 'HASH') {
11206: if ($settings->{'togglecats'} eq 'crs') {
11207: $toggle_cats_crs = $toggle_cats_dom;
11208: $toggle_cats_dom = ' ';
11209: }
11210: if ($settings->{'categorize'} eq 'crs') {
11211: $can_cat_crs = $can_cat_dom;
11212: $can_cat_dom = ' ';
11213: }
1.120 raeburn 11214: if ($settings->{'togglecatscomm'} eq 'comm') {
11215: $toggle_catscomm_comm = $toggle_catscomm_dom;
11216: $toggle_catscomm_dom = ' ';
11217: }
11218: if ($settings->{'categorizecomm'} eq 'comm') {
11219: $can_catcomm_comm = $can_catcomm_dom;
11220: $can_catcomm_dom = ' ';
11221: }
1.272 raeburn 11222: if ($settings->{'togglecatsplace'} eq 'place') {
11223: $toggle_catsplace_place = $toggle_catsplace_dom;
11224: $toggle_catsplace_dom = ' ';
11225: }
11226: if ($settings->{'categorizeplace'} eq 'place') {
11227: $can_catplace_place = $can_catplace_dom;
11228: $can_catplace_dom = ' ';
11229: }
1.57 raeburn 11230: }
11231: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11232: togglecats => 'Show/Hide a course in catalog',
11233: togglecatscomm => 'Show/Hide a community in catalog',
11234: togglecatsplace => 'Show/Hide a placement test in catalog',
11235: categorize => 'Assign a category to a course',
11236: categorizecomm => 'Assign a category to a community',
11237: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11238: );
11239: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11240: dom => 'Set in Domain',
11241: crs => 'Set in Course',
11242: comm => 'Set in Community',
11243: place => 'Set in Placement Test',
1.57 raeburn 11244: );
11245: $datatable = '<tr class="LC_odd_row">'.
11246: '<td>'.$title{'togglecats'}.'</td>'.
11247: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11248: '<input type="radio" name="togglecats"'.
11249: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11250: '<label><input type="radio" name="togglecats"'.
11251: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11252: '</tr><tr>'.
11253: '<td>'.$title{'categorize'}.'</td>'.
11254: '<td class="LC_right_item"><span class="LC_nobreak">'.
11255: '<label><input type="radio" name="categorize"'.
11256: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11257: '<label><input type="radio" name="categorize"'.
11258: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11259: '</tr><tr class="LC_odd_row">'.
11260: '<td>'.$title{'togglecatscomm'}.'</td>'.
11261: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11262: '<input type="radio" name="togglecatscomm"'.
11263: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11264: '<label><input type="radio" name="togglecatscomm"'.
11265: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11266: '</tr><tr>'.
11267: '<td>'.$title{'categorizecomm'}.'</td>'.
11268: '<td class="LC_right_item"><span class="LC_nobreak">'.
11269: '<label><input type="radio" name="categorizecomm"'.
11270: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11271: '<label><input type="radio" name="categorizecomm"'.
11272: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11273: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11274: '<td>'.$title{'togglecatsplace'}.'</td>'.
11275: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11276: '<input type="radio" name="togglecatsplace"'.
11277: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11278: '<label><input type="radio" name="togglecatscomm"'.
11279: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11280: '</tr><tr>'.
11281: '<td>'.$title{'categorizeplace'}.'</td>'.
11282: '<td class="LC_right_item"><span class="LC_nobreak">'.
11283: '<label><input type="radio" name="categorizeplace"'.
11284: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11285: '<label><input type="radio" name="categorizeplace"'.
11286: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11287: '</tr>';
1.272 raeburn 11288: $$rowtotal += 6;
1.57 raeburn 11289: } else {
11290: my $css_class;
11291: my $itemcount = 1;
11292: my $cathash;
11293: if (ref($settings) eq 'HASH') {
11294: $cathash = $settings->{'cats'};
11295: }
11296: if (ref($cathash) eq 'HASH') {
11297: my (@cats,@trails,%allitems,%idx,@jsarray);
11298: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11299: \%allitems,\%idx,\@jsarray);
11300: my $maxdepth = scalar(@cats);
11301: my $colattrib = '';
11302: if ($maxdepth > 2) {
11303: $colattrib = ' colspan="2" ';
11304: }
11305: my @path;
11306: if (@cats > 0) {
11307: if (ref($cats[0]) eq 'ARRAY') {
11308: my $numtop = @{$cats[0]};
11309: my $maxnum = $numtop;
1.120 raeburn 11310: my %default_names = (
11311: instcode => &mt('Official courses'),
11312: communities => &mt('Communities'),
1.272 raeburn 11313: placement => &mt('Placement Tests'),
1.120 raeburn 11314: );
11315:
11316: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11317: ($cathash->{'instcode::0'} eq '') ||
11318: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11319: ($cathash->{'communities::0'} eq '') ||
11320: (!grep(/^placement$/,@{$cats[0]})) ||
11321: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11322: $maxnum ++;
11323: }
11324: my $lastidx;
11325: for (my $i=0; $i<$numtop; $i++) {
11326: my $parent = $cats[0][$i];
11327: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11328: my $item = &escape($parent).'::0';
11329: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11330: $lastidx = $idx{$item};
11331: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11332: .'<select name="'.$item.'"'.$chgstr.'>';
11333: for (my $k=0; $k<=$maxnum; $k++) {
11334: my $vpos = $k+1;
11335: my $selstr;
11336: if ($k == $i) {
11337: $selstr = ' selected="selected" ';
11338: }
11339: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11340: }
1.214 raeburn 11341: $datatable .= '</select></span></td><td>';
1.272 raeburn 11342: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11343: $datatable .= '<span class="LC_nobreak">'
11344: .$default_names{$parent}.'</span>';
11345: if ($parent eq 'instcode') {
11346: $datatable .= '<br /><span class="LC_nobreak">('
11347: .&mt('with institutional codes')
11348: .')</span></td><td'.$colattrib.'>';
11349: } else {
11350: $datatable .= '<table><tr><td>';
11351: }
11352: $datatable .= '<span class="LC_nobreak">'
11353: .'<label><input type="radio" name="'
11354: .$parent.'" value="1" checked="checked" />'
11355: .&mt('Display').'</label>';
11356: if ($parent eq 'instcode') {
11357: $datatable .= ' ';
11358: } else {
11359: $datatable .= '</span></td></tr><tr><td>'
11360: .'<span class="LC_nobreak">';
11361: }
11362: $datatable .= '<label><input type="radio" name="'
11363: .$parent.'" value="0" />'
11364: .&mt('Do not display').'</label></span>';
1.272 raeburn 11365: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11366: $datatable .= '</td></tr></table>';
11367: }
11368: $datatable .= '</td>';
1.57 raeburn 11369: } else {
11370: $datatable .= $parent
1.214 raeburn 11371: .' <span class="LC_nobreak"><label>'
11372: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11373: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11374: }
11375: my $depth = 1;
11376: push(@path,$parent);
11377: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11378: pop(@path);
11379: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11380: $itemcount ++;
11381: }
1.48 raeburn 11382: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11383: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11384: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11385: for (my $k=0; $k<=$maxnum; $k++) {
11386: my $vpos = $k+1;
11387: my $selstr;
1.57 raeburn 11388: if ($k == $numtop) {
1.48 raeburn 11389: $selstr = ' selected="selected" ';
11390: }
11391: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11392: }
1.59 bisitz 11393: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11394: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11395: .'</tr>'."\n";
1.48 raeburn 11396: $itemcount ++;
1.272 raeburn 11397: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11398: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11399: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11400: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11401: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11402: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11403: for (my $k=0; $k<=$maxnum; $k++) {
11404: my $vpos = $k+1;
11405: my $selstr;
11406: if ($k == $maxnum) {
11407: $selstr = ' selected="selected" ';
11408: }
11409: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11410: }
1.120 raeburn 11411: $datatable .= '</select></span></td>'.
11412: '<td><span class="LC_nobreak">'.
11413: $default_names{$default}.'</span>';
11414: if ($default eq 'instcode') {
11415: $datatable .= '<br /><span class="LC_nobreak">('
11416: .&mt('with institutional codes').')</span>';
11417: }
11418: $datatable .= '</td>'
11419: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11420: .&mt('Display').'</label> '
11421: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11422: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11423: }
11424: }
11425: }
1.57 raeburn 11426: } else {
11427: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11428: }
11429: } else {
1.327 raeburn 11430: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11431: .&initialize_categories($itemcount);
1.48 raeburn 11432: }
1.57 raeburn 11433: $$rowtotal += $itemcount;
1.48 raeburn 11434: }
11435: return $datatable;
11436: }
11437:
1.69 raeburn 11438: sub print_serverstatuses {
11439: my ($dom,$settings,$rowtotal) = @_;
11440: my $datatable;
11441: my @pages = &serverstatus_pages();
11442: my (%namedaccess,%machineaccess);
11443: foreach my $type (@pages) {
11444: $namedaccess{$type} = '';
11445: $machineaccess{$type}= '';
11446: }
11447: if (ref($settings) eq 'HASH') {
11448: foreach my $type (@pages) {
11449: if (exists($settings->{$type})) {
11450: if (ref($settings->{$type}) eq 'HASH') {
11451: foreach my $key (keys(%{$settings->{$type}})) {
11452: if ($key eq 'namedusers') {
11453: $namedaccess{$type} = $settings->{$type}->{$key};
11454: } elsif ($key eq 'machines') {
11455: $machineaccess{$type} = $settings->{$type}->{$key};
11456: }
11457: }
11458: }
11459: }
11460: }
11461: }
1.81 raeburn 11462: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11463: my $rownum = 0;
11464: my $css_class;
11465: foreach my $type (@pages) {
11466: $rownum ++;
11467: $css_class = $rownum%2?' class="LC_odd_row"':'';
11468: $datatable .= '<tr'.$css_class.'>'.
11469: '<td><span class="LC_nobreak">'.
11470: $titles->{$type}.'</span></td>'.
11471: '<td class="LC_left_item">'.
11472: '<input type="text" name="'.$type.'_namedusers" '.
11473: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11474: '<td class="LC_right_item">'.
11475: '<span class="LC_nobreak">'.
11476: '<input type="text" name="'.$type.'_machines" '.
11477: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11478: '</span></td></tr>'."\n";
1.69 raeburn 11479: }
11480: $$rowtotal += $rownum;
11481: return $datatable;
11482: }
11483:
11484: sub serverstatus_pages {
11485: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11486: 'checksums','clusterstatus','certstatus','metadata_keywords',
11487: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11488: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11489: }
11490:
1.236 raeburn 11491: sub defaults_javascript {
11492: my ($settings) = @_;
1.354 raeburn 11493: return unless (ref($settings) eq 'HASH');
1.236 raeburn 11494: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11495: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11496: if ($maxnum eq '') {
11497: $maxnum = 0;
11498: }
11499: $maxnum ++;
1.249 raeburn 11500: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11501: return <<"ENDSCRIPT";
11502: <script type="text/javascript">
11503: // <![CDATA[
11504: function reorderTypes(form,caller) {
11505: var changedVal;
11506: $jstext
11507: var newpos = 'addinststatus_pos';
11508: var current = new Array;
11509: var maxh = $maxnum;
11510: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11511: var oldVal;
11512: if (caller == newpos) {
11513: changedVal = newitemVal;
11514: } else {
11515: var curritem = 'inststatus_pos_'+caller;
11516: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11517: current[newitemVal] = newpos;
11518: }
11519: for (var i=0; i<inststatuses.length; i++) {
11520: if (inststatuses[i] != caller) {
11521: var elementName = 'inststatus_pos_'+inststatuses[i];
11522: if (form.elements[elementName]) {
11523: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11524: current[currVal] = elementName;
11525: }
11526: }
11527: }
11528: for (var j=0; j<maxh; j++) {
11529: if (current[j] == undefined) {
11530: oldVal = j;
11531: }
11532: }
11533: if (oldVal < changedVal) {
11534: for (var k=oldVal+1; k<=changedVal ; k++) {
11535: var elementName = current[k];
11536: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11537: }
11538: } else {
11539: for (var k=changedVal; k<oldVal; k++) {
11540: var elementName = current[k];
11541: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11542: }
11543: }
11544: return;
11545: }
11546:
11547: // ]]>
11548: </script>
11549:
11550: ENDSCRIPT
11551: }
1.354 raeburn 11552: return;
11553: }
11554:
11555: sub passwords_javascript {
1.405 raeburn 11556: my ($prefix) = @_;
11557: my %intalert;
11558: if ($prefix eq 'passwords') {
11559: %intalert = &Apache::lonlocal::texthash (
11560: 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.',
11561: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11562: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11563: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11564: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11565: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11566: );
11567: } elsif ($prefix eq 'secrets') {
11568: %intalert = &Apache::lonlocal::texthash (
11569: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11570: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11571: );
11572: }
1.365 raeburn 11573: &js_escape(\%intalert);
11574: my $defmin = $Apache::lonnet::passwdmin;
1.405 raeburn 11575: my $intauthjs;
11576: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11577:
11578: function warnIntAuth(field) {
11579: if (field.name == 'intauth_check') {
11580: if (field.value == '2') {
1.365 raeburn 11581: alert('$intalert{authcheck}');
1.354 raeburn 11582: }
11583: }
11584: if (field.name == 'intauth_cost') {
11585: field.value.replace(/\s/g,'');
11586: if (field.value != '') {
11587: var regexdigit=/^\\d+\$/;
11588: if (!regexdigit.test(field.value)) {
1.365 raeburn 11589: alert('$intalert{authcost}');
11590: }
11591: }
11592: }
11593: return;
11594: }
11595:
1.405 raeburn 11596: ENDSCRIPT
11597:
11598: }
11599:
11600: $intauthjs .= <<"ENDSCRIPT";
11601:
11602: function warnInt$prefix(field) {
1.365 raeburn 11603: field.value.replace(/^\s+/,'');
11604: field.value.replace(/\s+\$/,'');
11605: var regexdigit=/^\\d+\$/;
1.408 raeburn 11606: if (field.name == '${prefix}_min') {
1.365 raeburn 11607: if (field.value == '') {
11608: alert('$intalert{passmin}');
11609: field.value = '$defmin';
11610: } else {
11611: if (!regexdigit.test(field.value)) {
11612: alert('$intalert{passmin}');
11613: field.value = '$defmin';
11614: }
1.366 raeburn 11615: var minval = parseInt(field.value,10);
1.365 raeburn 11616: if (minval < $defmin) {
11617: alert('$intalert{passmin}');
11618: field.value = '$defmin';
11619: }
11620: }
11621: } else {
11622: if (field.value == '0') {
11623: field.value = '';
11624: }
11625: if (field.value != '') {
1.408 raeburn 11626: if (field.name == '${prefix}_expire') {
1.365 raeburn 11627: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11628: if (!regexpposnum.test(field.value)) {
11629: alert('$intalert{passexp}');
11630: field.value = '';
11631: } else {
11632: var expval = parseFloat(field.value);
11633: if (expval == 0) {
11634: alert('$intalert{passexp}');
11635: field.value = '';
11636: }
11637: }
11638: } else {
11639: if (!regexdigit.test(field.value)) {
1.408 raeburn 11640: if (field.name == '${prefix}_max') {
1.365 raeburn 11641: alert('$intalert{passmax}');
11642: } else {
1.408 raeburn 11643: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11644: alert('$intalert{passnum}');
11645: }
11646: }
1.370 raeburn 11647: field.value = '';
1.365 raeburn 11648: }
1.354 raeburn 11649: }
11650: }
11651: }
11652: return;
11653: }
11654:
11655: ENDSCRIPT
11656: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11657: }
11658:
1.49 raeburn 11659: sub coursecategories_javascript {
11660: my ($settings) = @_;
1.57 raeburn 11661: my ($output,$jstext,$cathash);
1.49 raeburn 11662: if (ref($settings) eq 'HASH') {
1.57 raeburn 11663: $cathash = $settings->{'cats'};
11664: }
11665: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11666: my (@cats,@jsarray,%idx);
1.57 raeburn 11667: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11668: if (@jsarray > 0) {
11669: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11670: for (my $i=0; $i<@jsarray; $i++) {
11671: if (ref($jsarray[$i]) eq 'ARRAY') {
11672: my $catstr = join('","',@{$jsarray[$i]});
11673: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11674: }
11675: }
11676: }
11677: } else {
11678: $jstext = ' var categories = Array(1);'."\n".
11679: ' categories[0] = Array("instcode_pos");'."\n";
11680: }
1.237 bisitz 11681: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11682: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11683: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11684: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11685: &js_escape(\$instcode_reserved);
11686: &js_escape(\$communities_reserved);
1.272 raeburn 11687: &js_escape(\$placement_reserved);
1.265 damieng 11688: &js_escape(\$choose_again);
1.49 raeburn 11689: $output = <<"ENDSCRIPT";
11690: <script type="text/javascript">
1.109 raeburn 11691: // <![CDATA[
1.49 raeburn 11692: function reorderCats(form,parent,item,idx) {
11693: var changedVal;
11694: $jstext
11695: var newpos = 'addcategory_pos';
11696: if (parent == '') {
11697: var has_instcode = 0;
11698: var maxtop = categories[idx].length;
11699: for (var j=0; j<maxtop; j++) {
11700: if (categories[idx][j] == 'instcode::0') {
11701: has_instcode == 1;
11702: }
11703: }
11704: if (has_instcode == 0) {
11705: categories[idx][maxtop] = 'instcode_pos';
11706: }
11707: } else {
11708: newpos += '_'+parent;
11709: }
11710: var maxh = 1 + categories[idx].length;
11711: var current = new Array;
11712: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11713: if (item == newpos) {
11714: changedVal = newitemVal;
11715: } else {
11716: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11717: current[newitemVal] = newpos;
11718: }
11719: for (var i=0; i<categories[idx].length; i++) {
11720: var elementName = categories[idx][i];
11721: if (elementName != item) {
11722: if (form.elements[elementName]) {
11723: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11724: current[currVal] = elementName;
11725: }
11726: }
11727: }
11728: var oldVal;
11729: for (var j=0; j<maxh; j++) {
11730: if (current[j] == undefined) {
11731: oldVal = j;
11732: }
11733: }
11734: if (oldVal < changedVal) {
11735: for (var k=oldVal+1; k<=changedVal ; k++) {
11736: var elementName = current[k];
11737: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11738: }
11739: } else {
11740: for (var k=changedVal; k<oldVal; k++) {
11741: var elementName = current[k];
11742: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11743: }
11744: }
11745: return;
11746: }
1.120 raeburn 11747:
11748: function categoryCheck(form) {
11749: if (form.elements['addcategory_name'].value == 'instcode') {
11750: alert('$instcode_reserved\\n$choose_again');
11751: return false;
11752: }
11753: if (form.elements['addcategory_name'].value == 'communities') {
11754: alert('$communities_reserved\\n$choose_again');
11755: return false;
11756: }
1.272 raeburn 11757: if (form.elements['addcategory_name'].value == 'placement') {
11758: alert('$placement_reserved\\n$choose_again');
11759: return false;
11760: }
1.120 raeburn 11761: return true;
11762: }
11763:
1.109 raeburn 11764: // ]]>
1.49 raeburn 11765: </script>
11766:
11767: ENDSCRIPT
11768: return $output;
11769: }
11770:
1.48 raeburn 11771: sub initialize_categories {
11772: my ($itemcount) = @_;
1.120 raeburn 11773: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11774: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11775: instcode => 'Official courses (with institutional codes)',
11776: communities => 'Communities',
1.272 raeburn 11777: placement => 'Placement Tests',
1.120 raeburn 11778: );
1.328 raeburn 11779: my %selnum = (
11780: instcode => '0',
11781: communities => '1',
11782: placement => '2',
11783: );
11784: my %selected;
1.272 raeburn 11785: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11786: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11787: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11788: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11789: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11790: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11791: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11792: .'<option value="0"'.$selected{'0'}.'>1</option>'
11793: .'<option value="1"'.$selected{'1'}.'>2</option>'
11794: .'<option value="2"'.$selected{'2'}.'>3</option>'
11795: .'<option value="3">4</option></select> '
1.120 raeburn 11796: .$default_names{$default}
11797: .'</span></td><td><span class="LC_nobreak">'
11798: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11799: .&mt('Display').'</label> <label>'
11800: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11801: .'</label></span></td></tr>';
1.120 raeburn 11802: $itemcount ++;
11803: }
1.48 raeburn 11804: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11805: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11806: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11807: .'<select name="addcategory_pos"'.$chgstr.'>'
11808: .'<option value="0">1</option>'
11809: .'<option value="1">2</option>'
1.328 raeburn 11810: .'<option value="2">3</option>'
11811: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11812: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11813: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11814: .'</td></tr>';
1.48 raeburn 11815: return $datatable;
11816: }
11817:
11818: sub build_category_rows {
1.49 raeburn 11819: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11820: my ($text,$name,$item,$chgstr);
1.48 raeburn 11821: if (ref($cats) eq 'ARRAY') {
11822: my $maxdepth = scalar(@{$cats});
11823: if (ref($cats->[$depth]) eq 'HASH') {
11824: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11825: my $numchildren = @{$cats->[$depth]{$parent}};
11826: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11827: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11828: my ($idxnum,$parent_name,$parent_item);
11829: my $higher = $depth - 1;
11830: if ($higher == 0) {
11831: $parent_name = &escape($parent).'::'.$higher;
11832: } else {
11833: if (ref($path) eq 'ARRAY') {
11834: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11835: }
11836: }
11837: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11838: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11839: if ($j < $numchildren) {
1.48 raeburn 11840: $name = $cats->[$depth]{$parent}[$j];
11841: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11842: $idxnum = $idx->{$item};
11843: } else {
11844: $name = $parent_name;
11845: $item = $parent_item;
1.48 raeburn 11846: }
1.49 raeburn 11847: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11848: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11849: for (my $i=0; $i<=$numchildren; $i++) {
11850: my $vpos = $i+1;
11851: my $selstr;
11852: if ($j == $i) {
11853: $selstr = ' selected="selected" ';
11854: }
11855: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11856: }
11857: $text .= '</select> ';
11858: if ($j < $numchildren) {
11859: my $deeper = $depth+1;
11860: $text .= $name.' '
11861: .'<label><input type="checkbox" name="deletecategory" value="'
11862: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11863: if(ref($path) eq 'ARRAY') {
11864: push(@{$path},$name);
1.49 raeburn 11865: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11866: pop(@{$path});
11867: }
11868: } else {
1.330 raeburn 11869: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11870: if ($j == $numchildren) {
11871: $text .= $name;
11872: } else {
11873: $text .= $item;
11874: }
11875: $text .= '" value="" />';
11876: }
11877: $text .= '</td></tr>';
11878: }
11879: $text .= '</table></td>';
11880: } else {
11881: my $higher = $depth-1;
11882: if ($higher == 0) {
11883: $name = &escape($parent).'::'.$higher;
11884: } else {
11885: if (ref($path) eq 'ARRAY') {
11886: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11887: }
11888: }
11889: my $colspan;
11890: if ($parent ne 'instcode') {
11891: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11892: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11893: }
11894: }
11895: }
11896: }
11897: return $text;
11898: }
11899:
1.33 raeburn 11900: sub modifiable_userdata_row {
1.305 raeburn 11901: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11902: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11903: my ($role,$rolename,$statustype);
11904: $role = $item;
1.224 raeburn 11905: if ($context eq 'cancreate') {
1.305 raeburn 11906: if ($item =~ /^(emailusername)_(.+)$/) {
11907: $role = $1;
11908: $statustype = $2;
1.228 raeburn 11909: if (ref($usertypes) eq 'HASH') {
11910: if ($usertypes->{$statustype}) {
11911: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11912: } else {
11913: $rolename = &mt('Data provided by user');
11914: }
11915: }
1.224 raeburn 11916: }
11917: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11918: if (ref($usertypes) eq 'HASH') {
11919: $rolename = $usertypes->{$role};
11920: } else {
11921: $rolename = $role;
11922: }
1.325 raeburn 11923: } elsif ($context eq 'lti') {
11924: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11925: } elsif ($context eq 'privacy') {
11926: $rolename = $itemdesc;
1.33 raeburn 11927: } else {
1.63 raeburn 11928: if ($role eq 'cr') {
11929: $rolename = &mt('Custom role');
11930: } else {
11931: $rolename = &Apache::lonnet::plaintext($role);
11932: }
1.33 raeburn 11933: }
1.224 raeburn 11934: my (@fields,%fieldtitles);
11935: if (ref($fieldsref) eq 'ARRAY') {
11936: @fields = @{$fieldsref};
11937: } else {
11938: @fields = ('lastname','firstname','middlename','generation',
11939: 'permanentemail','id');
11940: }
11941: if ((ref($titlesref) eq 'HASH')) {
11942: %fieldtitles = %{$titlesref};
11943: } else {
11944: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11945: }
1.33 raeburn 11946: my $output;
1.305 raeburn 11947: my $css_class;
11948: if ($rowcount%2) {
11949: $css_class = 'LC_odd_row';
11950: }
11951: if ($customcss) {
11952: $css_class .= " $customcss";
11953: }
11954: $css_class =~ s/^\s+//;
11955: if ($css_class) {
11956: $css_class = ' class="'.$css_class.'"';
11957: }
11958: if ($rowstyle) {
11959: $css_class .= ' style="'.$rowstyle.'"';
11960: }
11961: if ($rowid) {
11962: $rowid = ' id="'.$rowid.'"';
11963: }
11964: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11965: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11966: '<td class="LC_left_item" colspan="2"><table>';
11967: my $rem;
11968: my %checks;
1.325 raeburn 11969: my %current;
1.33 raeburn 11970: if (ref($settings) eq 'HASH') {
1.325 raeburn 11971: my $hashref;
11972: if ($context eq 'lti') {
11973: if (ref($settings) eq 'HASH') {
11974: $hashref = $settings->{'instdata'};
11975: }
1.357 raeburn 11976: } elsif ($context eq 'privacy') {
11977: my ($key,$inner) = split(/_/,$role);
11978: if (ref($settings) eq 'HASH') {
11979: if (ref($settings->{$key}) eq 'HASH') {
11980: $hashref = $settings->{$key}->{$inner};
11981: }
11982: }
1.325 raeburn 11983: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11984: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11985: $hashref = $settings->{'lti_instdata'};
11986: }
11987: if ($role eq 'emailusername') {
11988: if ($statustype) {
11989: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11990: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11991: }
1.325 raeburn 11992: }
11993: }
11994: }
11995: if (ref($hashref) eq 'HASH') {
11996: foreach my $field (@fields) {
11997: if ($hashref->{$field}) {
11998: if ($role eq 'emailusername') {
11999: $checks{$field} = $hashref->{$field};
12000: } else {
12001: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12002: }
12003: }
12004: }
12005: }
12006: }
1.305 raeburn 12007:
12008: my $total = scalar(@fields);
12009: for (my $i=0; $i<$total; $i++) {
12010: $rem = $i%($numinrow);
1.33 raeburn 12011: if ($rem == 0) {
12012: if ($i > 0) {
12013: $output .= '</tr>';
12014: }
12015: $output .= '<tr>';
12016: }
12017: my $check = ' ';
1.228 raeburn 12018: unless ($role eq 'emailusername') {
12019: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12020: $check = $checks{$fields[$i]};
1.357 raeburn 12021: } elsif ($context eq 'privacy') {
12022: if ($role =~ /^priv_(domain|course)$/) {
12023: if (ref($settings) ne 'HASH') {
12024: $check = ' checked="checked" ';
12025: }
12026: } elsif ($role =~ /^priv_(author|community)$/) {
12027: if (ref($settings) ne 'HASH') {
12028: unless ($fields[$i] eq 'id') {
12029: $check = ' checked="checked" ';
12030: }
12031: }
12032: } elsif ($role =~ /^(unpriv|othdom)_/) {
12033: if (ref($settings) ne 'HASH') {
12034: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12035: $check = ' checked="checked" ';
12036: }
12037: }
12038: }
1.325 raeburn 12039: } elsif ($context ne 'lti') {
1.228 raeburn 12040: if ($role eq 'st') {
12041: if (ref($settings) ne 'HASH') {
12042: $check = ' checked="checked" ';
12043: }
1.33 raeburn 12044: }
12045: }
12046: }
12047: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12048: '<span class="LC_nobreak">';
1.325 raeburn 12049: my $prefix = 'canmodify';
1.228 raeburn 12050: if ($role eq 'emailusername') {
12051: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12052: $checks{$fields[$i]} = 'omit';
12053: }
12054: foreach my $option ('required','optional','omit') {
12055: my $checked='';
12056: if ($checks{$fields[$i]} eq $option) {
12057: $checked='checked="checked" ';
12058: }
12059: $output .= '<label>'.
1.325 raeburn 12060: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12061: &mt($option).'</label>'.(' ' x2);
12062: }
12063: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12064: } else {
1.325 raeburn 12065: if ($context eq 'lti') {
12066: $prefix = 'lti';
1.357 raeburn 12067: } elsif ($context eq 'privacy') {
12068: $prefix = 'privacy';
1.325 raeburn 12069: }
1.228 raeburn 12070: $output .= '<label>'.
1.325 raeburn 12071: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12072: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12073: '</label>';
12074: }
12075: $output .= '</span></td>';
1.33 raeburn 12076: }
1.305 raeburn 12077: $rem = $total%$numinrow;
12078: my $colsleft;
12079: if ($rem) {
12080: $colsleft = $numinrow - $rem;
12081: }
12082: if ($colsleft > 1) {
1.33 raeburn 12083: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12084: ' </td>';
12085: } elsif ($colsleft == 1) {
12086: $output .= '<td class="LC_left_item"> </td>';
12087: }
12088: $output .= '</tr></table></td></tr>';
12089: return $output;
12090: }
1.28 raeburn 12091:
1.93 raeburn 12092: sub insttypes_row {
1.305 raeburn 12093: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12094: $customcss,$rowstyle) = @_;
1.93 raeburn 12095: my %lt = &Apache::lonlocal::texthash (
12096: cansearch => 'Users allowed to search',
12097: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 12098: lockablenames => 'User preference to lock name',
1.305 raeburn 12099: selfassign => 'Self-reportable affiliations',
1.315 raeburn 12100: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 12101: );
12102: my $showdom;
12103: if ($context eq 'cansearch') {
12104: $showdom = ' ('.$dom.')';
12105: }
1.165 raeburn 12106: my $class = 'LC_left_item';
12107: if ($context eq 'statustocreate') {
12108: $class = 'LC_right_item';
12109: }
1.305 raeburn 12110: my $css_class;
12111: if ($$rowtotal%2) {
12112: $css_class = 'LC_odd_row';
12113: }
12114: if ($customcss) {
12115: $css_class .= ' '.$customcss;
12116: }
12117: $css_class =~ s/^\s+//;
12118: if ($css_class) {
12119: $css_class = ' class="'.$css_class.'"';
12120: }
12121: if ($rowstyle) {
12122: $css_class .= ' style="'.$rowstyle.'"';
12123: }
12124: if ($onclick) {
12125: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12126: }
12127: my $output = '<tr'.$css_class.'>'.
12128: '<td>'.$lt{$context}.$showdom.
12129: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12130: my $rem;
12131: if (ref($types) eq 'ARRAY') {
12132: for (my $i=0; $i<@{$types}; $i++) {
12133: if (defined($usertypes->{$types->[$i]})) {
12134: my $rem = $i%($numinrow);
12135: if ($rem == 0) {
12136: if ($i > 0) {
12137: $output .= '</tr>';
12138: }
12139: $output .= '<tr>';
1.23 raeburn 12140: }
1.26 raeburn 12141: my $check = ' ';
1.99 raeburn 12142: if (ref($settings) eq 'HASH') {
12143: if (ref($settings->{$context}) eq 'ARRAY') {
12144: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12145: $check = ' checked="checked" ';
12146: }
1.315 raeburn 12147: } elsif (ref($settings->{$context}) eq 'HASH') {
12148: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12149: $check = ' checked="checked" ';
12150: }
1.99 raeburn 12151: } elsif ($context eq 'statustocreate') {
1.26 raeburn 12152: $check = ' checked="checked" ';
12153: }
1.23 raeburn 12154: }
1.26 raeburn 12155: $output .= '<td class="LC_left_item">'.
12156: '<span class="LC_nobreak"><label>'.
1.93 raeburn 12157: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 12158: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 12159: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12160: }
12161: }
1.26 raeburn 12162: $rem = @{$types}%($numinrow);
1.23 raeburn 12163: }
12164: my $colsleft = $numinrow - $rem;
1.315 raeburn 12165: if ($context eq 'overrides') {
12166: if ($colsleft > 1) {
12167: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12168: } else {
12169: $output .= '<td class="LC_left_item">';
12170: }
12171: $output .= ' ';
1.23 raeburn 12172: } else {
1.334 raeburn 12173: if ($rem == 0) {
1.315 raeburn 12174: $output .= '<tr>';
12175: }
12176: if ($colsleft > 1) {
12177: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12178: } else {
12179: $output .= '<td class="LC_left_item">';
12180: }
12181: my $defcheck = ' ';
12182: if (ref($settings) eq 'HASH') {
12183: if (ref($settings->{$context}) eq 'ARRAY') {
12184: if (grep(/^default$/,@{$settings->{$context}})) {
12185: $defcheck = ' checked="checked" ';
12186: }
12187: } elsif ($context eq 'statustocreate') {
1.99 raeburn 12188: $defcheck = ' checked="checked" ';
12189: }
1.26 raeburn 12190: }
1.315 raeburn 12191: $output .= '<span class="LC_nobreak"><label>'.
12192: '<input type="checkbox" name="'.$context.'" '.
12193: 'value="default"'.$defcheck.$onclick.' />'.
12194: $othertitle.'</label></span>';
1.23 raeburn 12195: }
1.315 raeburn 12196: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12197: return $output;
1.23 raeburn 12198: }
12199:
12200: sub sorted_searchtitles {
12201: my %searchtitles = &Apache::lonlocal::texthash(
12202: 'uname' => 'username',
12203: 'lastname' => 'last name',
12204: 'lastfirst' => 'last name, first name',
12205: );
12206: my @titleorder = ('uname','lastname','lastfirst');
12207: return (\%searchtitles,\@titleorder);
12208: }
12209:
1.25 raeburn 12210: sub sorted_searchtypes {
12211: my %srchtypes_desc = (
12212: exact => 'is exact match',
12213: contains => 'contains ..',
12214: begins => 'begins with ..',
12215: );
12216: my @srchtypeorder = ('exact','begins','contains');
12217: return (\%srchtypes_desc,\@srchtypeorder);
12218: }
12219:
1.3 raeburn 12220: sub usertype_update_row {
12221: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12222: my $datatable;
12223: my $numinrow = 4;
12224: foreach my $type (@{$types}) {
12225: if (defined($usertypes->{$type})) {
12226: $$rownums ++;
12227: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12228: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12229: '</td><td class="LC_left_item"><table>';
12230: for (my $i=0; $i<@{$fields}; $i++) {
12231: my $rem = $i%($numinrow);
12232: if ($rem == 0) {
12233: if ($i > 0) {
12234: $datatable .= '</tr>';
12235: }
12236: $datatable .= '<tr>';
12237: }
12238: my $check = ' ';
1.39 raeburn 12239: if (ref($settings) eq 'HASH') {
12240: if (ref($settings->{'fields'}) eq 'HASH') {
12241: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12242: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12243: $check = ' checked="checked" ';
12244: }
1.3 raeburn 12245: }
12246: }
12247: }
12248:
12249: if ($i == @{$fields}-1) {
12250: my $colsleft = $numinrow - $rem;
12251: if ($colsleft > 1) {
12252: $datatable .= '<td colspan="'.$colsleft.'">';
12253: } else {
12254: $datatable .= '<td>';
12255: }
12256: } else {
12257: $datatable .= '<td>';
12258: }
1.8 raeburn 12259: $datatable .= '<span class="LC_nobreak"><label>'.
12260: '<input type="checkbox" name="updateable_'.$type.
12261: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12262: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12263: }
12264: $datatable .= '</tr></table></td></tr>';
12265: }
12266: }
12267: return $datatable;
1.1 raeburn 12268: }
12269:
12270: sub modify_login {
1.205 raeburn 12271: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12272: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12273: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12274: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12275: %title = ( coursecatalog => 'Display course catalog',
12276: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12277: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12278: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12279: loginheader => 'Log-in box header',
12280: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12281: @offon = ('off','on');
1.112 raeburn 12282: if (ref($domconfig{login}) eq 'HASH') {
12283: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12284: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12285: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12286: }
12287: }
1.386 raeburn 12288: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12289: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12290: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12291: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12292: $saml{$lonhost} = 1;
12293: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12294: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12295: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12296: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12297: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12298: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12299: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12300: }
12301: }
12302: }
1.112 raeburn 12303: }
1.9 raeburn 12304: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12305: \%domconfig,\%loginhash);
1.188 raeburn 12306: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12307: foreach my $item (@toggles) {
12308: $loginhash{login}{$item} = $env{'form.'.$item};
12309: }
1.41 raeburn 12310: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12311: if (ref($colchanges{'login'}) eq 'HASH') {
12312: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12313: \%loginhash);
12314: }
1.110 raeburn 12315:
1.149 raeburn 12316: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12317: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12318: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12319: if (keys(%servers) > 1) {
12320: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12321: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12322: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12323: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12324: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12325: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12326: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12327: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12328: $changes{'loginvia'}{$lonhost} = 1;
12329: } else {
12330: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12331: $changes{'loginvia'}{$lonhost} = 1;
12332: }
12333: } else {
12334: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12335: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12336: $changes{'loginvia'}{$lonhost} = 1;
12337: }
12338: }
12339: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12340: foreach my $item (@loginvia_attribs) {
12341: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12342: }
12343: } else {
12344: foreach my $item (@loginvia_attribs) {
12345: my $new = $env{'form.'.$lonhost.'_'.$item};
12346: if (($item eq 'serverpath') && ($new eq 'custom')) {
12347: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12348: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12349: $new = '/';
12350: }
12351: }
12352: if (($item eq 'custompath') &&
12353: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12354: $new = '';
12355: }
12356: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12357: $changes{'loginvia'}{$lonhost} = 1;
12358: }
12359: if ($item eq 'exempt') {
1.256 raeburn 12360: $new = &check_exempt_addresses($new);
1.128 raeburn 12361: }
12362: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12363: }
12364: }
1.112 raeburn 12365: } else {
1.128 raeburn 12366: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12367: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12368: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12369: foreach my $item (@loginvia_attribs) {
12370: my $new = $env{'form.'.$lonhost.'_'.$item};
12371: if (($item eq 'serverpath') && ($new eq 'custom')) {
12372: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12373: $new = '/';
12374: }
12375: }
12376: if (($item eq 'custompath') &&
12377: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12378: $new = '';
12379: }
12380: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12381: }
1.110 raeburn 12382: }
12383: }
12384: }
12385: }
1.119 raeburn 12386:
1.168 raeburn 12387: my $servadm = $r->dir_config('lonAdmEMail');
12388: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12389: if (ref($domconfig{'login'}) eq 'HASH') {
12390: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12391: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12392: if ($lang eq 'nolang') {
12393: push(@currlangs,$lang);
12394: } elsif (defined($langchoices{$lang})) {
12395: push(@currlangs,$lang);
12396: } else {
12397: next;
12398: }
12399: }
12400: }
12401: }
12402: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12403: if (@currlangs > 0) {
12404: foreach my $lang (@currlangs) {
12405: if (grep(/^\Q$lang\E$/,@delurls)) {
12406: $changes{'helpurl'}{$lang} = 1;
12407: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12408: $changes{'helpurl'}{$lang} = 1;
12409: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12410: push(@newlangs,$lang);
12411: } else {
12412: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12413: }
12414: }
12415: }
12416: unless (grep(/^nolang$/,@currlangs)) {
12417: if ($env{'form.loginhelpurl_nolang.filename'}) {
12418: $changes{'helpurl'}{'nolang'} = 1;
12419: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12420: push(@newlangs,'nolang');
12421: }
12422: }
12423: if ($env{'form.loginhelpurl_add_lang'}) {
12424: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12425: ($env{'form.loginhelpurl_add_file.filename'})) {
12426: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12427: $addedfile = $env{'form.loginhelpurl_add_lang'};
12428: }
12429: }
12430: if ((@newlangs > 0) || ($addedfile)) {
12431: my $error;
12432: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12433: if ($configuserok eq 'ok') {
12434: if ($switchserver) {
12435: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12436: } elsif ($author_ok eq 'ok') {
12437: my @allnew = @newlangs;
12438: if ($addedfile ne '') {
12439: push(@allnew,$addedfile);
12440: }
12441: foreach my $lang (@allnew) {
12442: my $formelem = 'loginhelpurl_'.$lang;
12443: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12444: $formelem = 'loginhelpurl_add_file';
12445: }
12446: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12447: "help/$lang",'','',$newfile{$lang});
12448: if ($result eq 'ok') {
12449: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12450: $changes{'helpurl'}{$lang} = 1;
12451: } else {
12452: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12453: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12454: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12455: (!grep(/^\Q$lang\E$/,@delurls))) {
12456: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12457: }
12458: }
12459: }
12460: } else {
12461: $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);
12462: }
12463: } else {
12464: $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);
12465: }
12466: if ($error) {
12467: &Apache::lonnet::logthis($error);
12468: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12469: }
12470: }
1.256 raeburn 12471:
12472: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12473: if (ref($domconfig{'login'}) eq 'HASH') {
12474: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12475: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12476: if ($domservers{$lonhost}) {
12477: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12478: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12479: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12480: }
12481: }
12482: }
12483: }
12484: }
12485: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12486: foreach my $lonhost (sort(keys(%domservers))) {
12487: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12488: $changes{'headtag'}{$lonhost} = 1;
12489: } else {
12490: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12491: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12492: }
12493: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12494: push(@newhosts,$lonhost);
12495: } elsif ($currheadtagurls{$lonhost}) {
12496: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12497: if ($currexempt{$lonhost}) {
1.289 raeburn 12498: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12499: $changes{'headtag'}{$lonhost} = 1;
12500: }
12501: } elsif ($possexempt{$lonhost}) {
12502: $changes{'headtag'}{$lonhost} = 1;
12503: }
12504: if ($possexempt{$lonhost}) {
12505: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12506: }
12507: }
12508: }
12509: }
12510: if (@newhosts) {
12511: my $error;
12512: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12513: if ($configuserok eq 'ok') {
12514: if ($switchserver) {
12515: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12516: } elsif ($author_ok eq 'ok') {
12517: foreach my $lonhost (@newhosts) {
12518: my $formelem = 'loginheadtag_'.$lonhost;
12519: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12520: "login/headtag/$lonhost",'','',
12521: $env{'form.loginheadtag_'.$lonhost.'.filename'});
12522: if ($result eq 'ok') {
12523: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12524: $changes{'headtag'}{$lonhost} = 1;
12525: if ($possexempt{$lonhost}) {
12526: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12527: }
12528: } else {
12529: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12530: $newheadtagurls{$lonhost},$result);
12531: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12532: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12533: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12534: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12535: }
12536: }
12537: }
12538: } else {
12539: $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);
12540: }
12541: } else {
12542: $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);
12543: }
12544: if ($error) {
12545: &Apache::lonnet::logthis($error);
12546: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12547: }
12548: }
1.386 raeburn 12549: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12550: my @newsamlimgs;
12551: foreach my $lonhost (keys(%domservers)) {
12552: if ($env{'form.saml_'.$lonhost}) {
12553: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12554: push(@newsamlimgs,$lonhost);
12555: }
1.412 raeburn 12556: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12557: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12558: }
12559: if ($saml{$lonhost}) {
1.412 raeburn 12560: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12561: $env{'form.saml_window_'.$lonhost} = '';
12562: }
1.386 raeburn 12563: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12564: #FIXME Need to obsolete published image
12565: delete($currsaml{$lonhost}{'img'});
12566: $changes{'saml'}{$lonhost} = 1;
12567: }
12568: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12569: $changes{'saml'}{$lonhost} = 1;
12570: }
12571: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12572: $changes{'saml'}{$lonhost} = 1;
12573: }
12574: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12575: $changes{'saml'}{$lonhost} = 1;
12576: }
12577: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12578: $changes{'saml'}{$lonhost} = 1;
12579: }
1.412 raeburn 12580: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12581: $changes{'saml'}{$lonhost} = 1;
12582: }
1.386 raeburn 12583: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12584: $changes{'saml'}{$lonhost} = 1;
12585: }
12586: } else {
12587: $changes{'saml'}{$lonhost} = 1;
12588: }
1.412 raeburn 12589: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12590: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12591: }
12592: } else {
1.389 raeburn 12593: if ($saml{$lonhost}) {
12594: $changes{'saml'}{$lonhost} = 1;
12595: delete($currsaml{$lonhost});
12596: }
1.386 raeburn 12597: }
12598: }
12599: foreach my $posshost (keys(%currsaml)) {
12600: unless (exists($domservers{$posshost})) {
12601: delete($currsaml{$posshost});
12602: }
12603: }
12604: %{$loginhash{'login'}{'saml'}} = %currsaml;
12605: if (@newsamlimgs) {
12606: my $error;
12607: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12608: if ($configuserok eq 'ok') {
12609: if ($switchserver) {
12610: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12611: } elsif ($author_ok eq 'ok') {
12612: foreach my $lonhost (@newsamlimgs) {
12613: my $formelem = 'saml_img_'.$lonhost;
12614: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12615: "login/saml/$lonhost",'','',
12616: $env{'form.saml_img_'.$lonhost.'.filename'});
12617: if ($result eq 'ok') {
12618: $currsaml{$lonhost}{'img'} = $imgurl;
12619: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12620: $changes{'saml'}{$lonhost} = 1;
12621: } else {
12622: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12623: $lonhost,$result);
12624: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12625: }
12626: }
12627: } else {
12628: $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);
12629: }
12630: } else {
12631: $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);
12632: }
12633: if ($error) {
12634: &Apache::lonnet::logthis($error);
12635: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12636: }
12637: }
1.169 raeburn 12638: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12639:
12640: my $defaulthelpfile = '/adm/loginproblems.html';
12641: my $defaulttext = &mt('Default in use');
12642:
1.1 raeburn 12643: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12644: $dom);
12645: if ($putresult eq 'ok') {
1.188 raeburn 12646: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12647: my %defaultchecked = (
12648: 'coursecatalog' => 'on',
1.188 raeburn 12649: 'helpdesk' => 'on',
1.42 raeburn 12650: 'adminmail' => 'off',
1.43 raeburn 12651: 'newuser' => 'off',
1.42 raeburn 12652: );
1.55 raeburn 12653: if (ref($domconfig{'login'}) eq 'HASH') {
12654: foreach my $item (@toggles) {
12655: if ($defaultchecked{$item} eq 'on') {
12656: if (($domconfig{'login'}{$item} eq '0') &&
12657: ($env{'form.'.$item} eq '1')) {
12658: $changes{$item} = 1;
12659: } elsif (($domconfig{'login'}{$item} eq '' ||
12660: $domconfig{'login'}{$item} eq '1') &&
12661: ($env{'form.'.$item} eq '0')) {
12662: $changes{$item} = 1;
12663: }
12664: } elsif ($defaultchecked{$item} eq 'off') {
12665: if (($domconfig{'login'}{$item} eq '1') &&
12666: ($env{'form.'.$item} eq '0')) {
12667: $changes{$item} = 1;
12668: } elsif (($domconfig{'login'}{$item} eq '' ||
12669: $domconfig{'login'}{$item} eq '0') &&
12670: ($env{'form.'.$item} eq '1')) {
12671: $changes{$item} = 1;
12672: }
1.42 raeburn 12673: }
12674: }
1.41 raeburn 12675: }
1.6 raeburn 12676: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12677: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12678: if (exists($changes{'saml'})) {
12679: my $hostid_in_use;
12680: my @hosts = &Apache::lonnet::current_machine_ids();
12681: if (@hosts > 1) {
12682: foreach my $hostid (@hosts) {
12683: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12684: $hostid_in_use = $hostid;
12685: last;
12686: }
12687: }
12688: } else {
12689: $hostid_in_use = $r->dir_config('lonHostID');
12690: }
12691: if (($hostid_in_use) &&
12692: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12693: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12694: }
12695: if (ref($lastactref) eq 'HASH') {
12696: if (ref($changes{'saml'}) eq 'HASH') {
12697: my %updates;
12698: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12699: $lastactref->{'samllanding'} = \%updates;
12700: }
12701: }
12702: }
1.212 raeburn 12703: if (ref($lastactref) eq 'HASH') {
12704: $lastactref->{'domainconfig'} = 1;
12705: }
1.1 raeburn 12706: $resulttext = &mt('Changes made:').'<ul>';
12707: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12708: if ($item eq 'loginvia') {
1.112 raeburn 12709: if (ref($changes{$item}) eq 'HASH') {
12710: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12711: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12712: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12713: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12714: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12715: $protocol = 'http' if ($protocol ne 'https');
12716: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12717:
12718: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12719: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12720: } else {
12721: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12722: }
12723: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12724: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12725: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12726: }
12727: $resulttext .= '</li>';
12728: } else {
12729: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12730: }
1.112 raeburn 12731: } else {
1.128 raeburn 12732: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12733: }
12734: }
1.128 raeburn 12735: $resulttext .= '</ul></li>';
1.112 raeburn 12736: }
1.168 raeburn 12737: } elsif ($item eq 'helpurl') {
12738: if (ref($changes{$item}) eq 'HASH') {
12739: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12740: if (grep(/^\Q$lang\E$/,@delurls)) {
12741: my ($chg,$link);
12742: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12743: if ($lang eq 'nolang') {
12744: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12745: } else {
12746: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12747: }
12748: $resulttext .= '<li>'.$chg.'</li>';
12749: } else {
12750: my $chg;
12751: if ($lang eq 'nolang') {
12752: $chg = &mt('custom log-in help file for no preferred language');
12753: } else {
12754: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12755: }
12756: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12757: $loginhash{'login'}{'helpurl'}{$lang}.
12758: '?inhibitmenu=yes',$chg,600,500).
12759: '</li>';
12760: }
12761: }
12762: }
1.256 raeburn 12763: } elsif ($item eq 'headtag') {
12764: if (ref($changes{$item}) eq 'HASH') {
12765: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12766: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12767: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12768: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12769: $resulttext .= '<li><a href="'.
12770: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12771: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12772: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12773: if ($possexempt{$lonhost}) {
12774: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12775: } else {
12776: $resulttext .= &mt('included for any client IP');
12777: }
12778: $resulttext .= '</li>';
12779: }
12780: }
12781: }
1.386 raeburn 12782: } elsif ($item eq 'saml') {
12783: if (ref($changes{$item}) eq 'HASH') {
12784: my %notlt = (
12785: text => 'Text for log-in by SSO',
12786: img => 'SSO button image',
12787: alt => 'Alt text for button image',
12788: url => 'SSO URL',
12789: title => 'Tooltip for SSO link',
1.412 raeburn 12790: window => 'Pop-up window if iframe',
1.386 raeburn 12791: notsso => 'Text for non-SSO log-in',
12792: );
12793: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12794: if (ref($currsaml{$lonhost}) eq 'HASH') {
12795: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12796: '<ul>';
1.412 raeburn 12797: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12798: if ($currsaml{$lonhost}{$key} eq '') {
12799: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12800: } else {
12801: my $value = "'$currsaml{$lonhost}{$key}'";
12802: if ($key eq 'img') {
12803: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12804: } elsif ($key eq 'window') {
12805: $value = 'On';
1.386 raeburn 12806: }
12807: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12808: $value).'</li>';
12809: }
12810: }
12811: $resulttext .= '</ul></li>';
12812: } else {
12813: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12814: }
12815: }
12816: }
1.169 raeburn 12817: } elsif ($item eq 'captcha') {
12818: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12819: my $chgtxt;
1.169 raeburn 12820: if ($loginhash{'login'}{$item} eq 'notused') {
12821: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12822: } else {
12823: my %captchas = &captcha_phrases();
12824: if ($captchas{$loginhash{'login'}{$item}}) {
12825: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12826: } else {
12827: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12828: }
12829: }
12830: $resulttext .= '<li>'.$chgtxt.'</li>';
12831: }
12832: } elsif ($item eq 'recaptchakeys') {
12833: if (ref($loginhash{'login'}) eq 'HASH') {
12834: my ($privkey,$pubkey);
12835: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12836: $pubkey = $loginhash{'login'}{$item}{'public'};
12837: $privkey = $loginhash{'login'}{$item}{'private'};
12838: }
12839: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12840: if (!$pubkey) {
12841: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12842: } else {
12843: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12844: }
12845: if (!$privkey) {
12846: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12847: } else {
1.251 raeburn 12848: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12849: }
12850: $chgtxt .= '</ul>';
12851: $resulttext .= '<li>'.$chgtxt.'</li>';
12852: }
1.269 raeburn 12853: } elsif ($item eq 'recaptchaversion') {
12854: if (ref($loginhash{'login'}) eq 'HASH') {
12855: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12856: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12857: '</li>';
12858: }
12859: }
1.41 raeburn 12860: } else {
12861: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12862: }
1.1 raeburn 12863: }
1.6 raeburn 12864: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12865: } else {
12866: $resulttext = &mt('No changes made to log-in page settings');
12867: }
12868: } else {
1.11 albertel 12869: $resulttext = '<span class="LC_error">'.
12870: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12871: }
1.6 raeburn 12872: if ($errors) {
1.9 raeburn 12873: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12874: $errors.'</ul>';
12875: }
12876: return $resulttext;
12877: }
12878:
1.256 raeburn 12879: sub check_exempt_addresses {
12880: my ($iplist) = @_;
12881: $iplist =~ s/^\s+//;
12882: $iplist =~ s/\s+$//;
12883: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12884: my (@okips,$new);
12885: foreach my $ip (@poss_ips) {
12886: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12887: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12888: push(@okips,$ip);
12889: }
12890: }
12891: }
12892: if (@okips > 0) {
12893: $new = join(',',@okips);
12894: } else {
12895: $new = '';
12896: }
12897: return $new;
12898: }
12899:
1.6 raeburn 12900: sub color_font_choices {
12901: my %choices =
12902: &Apache::lonlocal::texthash (
12903: img => "Header",
12904: bgs => "Background colors",
12905: links => "Link colors",
1.55 raeburn 12906: images => "Images",
1.6 raeburn 12907: font => "Font color",
1.201 raeburn 12908: fontmenu => "Font menu",
1.76 raeburn 12909: pgbg => "Page",
1.6 raeburn 12910: tabbg => "Header",
12911: sidebg => "Border",
12912: link => "Link",
12913: alink => "Active link",
12914: vlink => "Visited link",
12915: );
12916: return %choices;
12917: }
12918:
1.394 raeburn 12919: sub modify_ipaccess {
12920: my ($dom,$lastactref,%domconfig) = @_;
12921: my (@allpos,%changes,%confhash,$errors,$resulttext);
12922: my (@items,%deletions,%itemids,@warnings);
12923: my ($typeorder,$types) = &commblocktype_text();
12924: if ($env{'form.ipaccess_add'}) {
12925: my $name = $env{'form.ipaccess_name_add'};
12926: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12927: if ($newid) {
12928: $itemids{'add'} = $newid;
12929: push(@items,'add');
12930: $changes{$newid} = 1;
12931: } else {
12932: $error = &mt('Failed to acquire unique ID for new IP access control item');
12933: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12934: }
12935: }
12936: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12937: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12938: if (@todelete) {
12939: map { $deletions{$_} = 1; } @todelete;
12940: }
12941: my $maxnum = $env{'form.ipaccess_maxnum'};
12942: for (my $i=0; $i<$maxnum; $i++) {
12943: my $itemid = $env{'form.ipaccess_id_'.$i};
12944: $itemid =~ s/\D+//g;
12945: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12946: if ($deletions{$itemid}) {
12947: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12948: } else {
12949: push(@items,$i);
12950: $itemids{$i} = $itemid;
12951: }
12952: }
12953: }
12954: }
12955: foreach my $idx (@items) {
12956: my $itemid = $itemids{$idx};
12957: next unless ($itemid);
12958: my %current;
12959: unless ($idx eq 'add') {
12960: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12961: %current = %{$domconfig{'ipaccess'}{$itemid}};
12962: }
12963: }
12964: my $position = $env{'form.ipaccess_pos_'.$itemid};
12965: $position =~ s/\D+//g;
12966: if ($position ne '') {
12967: $allpos[$position] = $itemid;
12968: }
12969: my $name = $env{'form.ipaccess_name_'.$idx};
12970: $name =~ s/^\s+|\s+$//g;
12971: $confhash{$itemid}{'name'} = $name;
12972: my $possrange = $env{'form.ipaccess_range_'.$idx};
12973: $possrange =~ s/^\s+|\s+$//g;
12974: unless ($possrange eq '') {
12975: $possrange =~ s/[\r\n]+/\s/g;
12976: $possrange =~ s/\s*-\s*/-/g;
12977: $possrange =~ s/\s+/,/g;
12978: $possrange =~ s/,+/,/g;
12979: if ($possrange ne '') {
12980: my (@ok,$count);
12981: $count = 0;
12982: foreach my $poss (split(/\,/,$possrange)) {
12983: $count ++;
12984: $poss = &validate_ip_pattern($poss);
12985: if ($poss ne '') {
12986: push(@ok,$poss);
12987: }
12988: }
12989: my $diff = $count - scalar(@ok);
12990: if ($diff) {
12991: $errors .= '<li><span class="LC_error">'.
12992: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
12993: $diff,$name).
12994: '</span></li>';
12995: }
12996: if (@ok) {
12997: my @cidr_list;
12998: foreach my $item (@ok) {
12999: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13000: }
13001: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13002: }
13003: }
13004: }
13005: foreach my $field ('name','ip') {
13006: unless (($idx eq 'add') || ($changes{$itemid})) {
13007: if ($current{$field} ne $confhash{$itemid}{$field}) {
13008: $changes{$itemid} = 1;
13009: last;
13010: }
13011: }
13012: }
13013: $confhash{$itemid}{'commblocks'} = {};
13014:
13015: my %commblocks;
13016: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
13017: foreach my $type (@{$typeorder}) {
13018: if ($commblocks{$type}) {
13019: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13020: }
13021: unless (($idx eq 'add') || ($changes{$itemid})) {
13022: if (ref($current{'commblocks'}) eq 'HASH') {
13023: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13024: $changes{$itemid} = 1;
13025: }
13026: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13027: $changes{$itemid} = 1;
13028: }
13029: }
13030: }
13031: $confhash{$itemid}{'courses'} = {};
13032: my %crsdeletions;
13033: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13034: if (@delcrs) {
13035: map { $crsdeletions{$_} = 1; } @delcrs;
13036: }
13037: if (ref($current{'courses'}) eq 'HASH') {
13038: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13039: if ($crsdeletions{$cid}) {
13040: $changes{$itemid} = 1;
13041: } else {
13042: $confhash{$itemid}{'courses'}{$cid} = 1;
13043: }
13044: }
13045: }
13046: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13047: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
13048: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
13049: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13050: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13051: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13052: $errors .= '<li><span class="LC_error">'.
13053: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13054: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13055: '</span></li>';
13056: } else {
13057: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13058: $changes{$itemid} = 1;
13059: }
13060: }
13061: }
13062: if (@allpos > 0) {
13063: my $idx = 0;
13064: foreach my $itemid (@allpos) {
13065: if ($itemid ne '') {
13066: $confhash{$itemid}{'order'} = $idx;
13067: unless ($changes{$itemid}) {
13068: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13069: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13070: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13071: $changes{$itemid} = 1;
13072: }
13073: }
13074: }
13075: }
13076: $idx ++;
13077: }
13078: }
13079: }
13080: if (keys(%changes)) {
13081: my %defaultshash = (
13082: ipaccess => \%confhash,
13083: );
13084: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13085: $dom);
13086: if ($putresult eq 'ok') {
13087: my $cachetime = 1800;
13088: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13089: if (ref($lastactref) eq 'HASH') {
13090: $lastactref->{'ipaccess'} = 1;
13091: }
13092: $resulttext = &mt('Changes made:').'<ul>';
13093: my %bynum;
13094: foreach my $itemid (sort(keys(%changes))) {
13095: if (ref($confhash{$itemid}) eq 'HASH') {
13096: my $position = $confhash{$itemid}{'order'};
13097: if ($position =~ /^\d+$/) {
13098: $bynum{$position} = $itemid;
13099: }
13100: }
13101: }
13102: if (keys(%deletions)) {
13103: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13104: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13105: }
13106: }
13107: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13108: my $itemid = $bynum{$pos};
13109: if (ref($confhash{$itemid}) eq 'HASH') {
13110: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13111: my $position = $pos + 1;
13112: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13113: if ($confhash{$itemid}{'ip'} eq '') {
13114: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13115: } else {
13116: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13117: }
13118: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13119: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13120: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13121: '</li>';
13122: } else {
13123: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13124: }
13125: if (keys(%{$confhash{$itemid}{'courses'}})) {
13126: my @courses;
13127: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
13128: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
13129: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13130: }
13131: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13132: join('</li><li>',@courses).'</li></ul>';
13133: } else {
13134: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13135: }
1.395 raeburn 13136: $resulttext .= '</ul></li>';
1.394 raeburn 13137: }
13138: }
1.395 raeburn 13139: $resulttext .= '</ul>';
1.394 raeburn 13140: } else {
13141: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13142: }
13143: } else {
13144: $resulttext = &mt('No changes made');
13145: }
13146: if ($errors) {
13147: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13148: $errors.'</ul></p>';
13149: }
13150: return $resulttext;
13151: }
13152:
13153: sub get_ipaccess_id {
13154: my ($domain,$location) = @_;
13155: # get lock on ipaccess db
13156: my $lockhash = {
13157: lock => $env{'user.name'}.
13158: ':'.$env{'user.domain'},
13159: };
13160: my $tries = 0;
13161: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13162: my ($id,$error);
13163:
13164: while (($gotlock ne 'ok') && ($tries<10)) {
13165: $tries ++;
13166: sleep (0.1);
13167: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13168: }
13169: if ($gotlock eq 'ok') {
13170: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13171: if ($currids{'lock'}) {
13172: delete($currids{'lock'});
13173: if (keys(%currids)) {
13174: my @curr = sort { $a <=> $b } keys(%currids);
13175: if ($curr[-1] =~ /^\d+$/) {
13176: $id = 1 + $curr[-1];
13177: }
13178: } else {
13179: $id = 1;
13180: }
13181: if ($id) {
13182: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13183: $error = 'nostore';
13184: }
13185: } else {
13186: $error = 'nonumber';
13187: }
13188: }
13189: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13190: } else {
13191: $error = 'nolock';
13192: }
13193: return ($id,$error);
13194: }
13195:
1.6 raeburn 13196: sub modify_rolecolors {
1.205 raeburn 13197: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13198: my ($resulttext,%rolehash);
13199: $rolehash{'rolecolors'} = {};
1.55 raeburn 13200: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13201: if ($domconfig{'rolecolors'} eq '') {
13202: $domconfig{'rolecolors'} = {};
13203: }
13204: }
1.9 raeburn 13205: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13206: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13207: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13208: $dom);
13209: if ($putresult eq 'ok') {
13210: if (keys(%changes) > 0) {
1.41 raeburn 13211: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13212: if (ref($lastactref) eq 'HASH') {
13213: $lastactref->{'domainconfig'} = 1;
13214: }
1.6 raeburn 13215: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13216: $rolehash{'rolecolors'});
13217: } else {
13218: $resulttext = &mt('No changes made to default color schemes');
13219: }
13220: } else {
1.11 albertel 13221: $resulttext = '<span class="LC_error">'.
13222: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13223: }
13224: if ($errors) {
13225: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13226: $errors.'</ul>';
13227: }
13228: return $resulttext;
13229: }
13230:
13231: sub modify_colors {
1.9 raeburn 13232: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13233: my (%changes,%choices);
1.51 raeburn 13234: my @bgs;
1.6 raeburn 13235: my @links = ('link','alink','vlink');
1.41 raeburn 13236: my @logintext;
1.6 raeburn 13237: my @images;
13238: my $servadm = $r->dir_config('lonAdmEMail');
13239: my $errors;
1.200 raeburn 13240: my %defaults;
1.6 raeburn 13241: foreach my $role (@{$roles}) {
13242: if ($role eq 'login') {
1.12 raeburn 13243: %choices = &login_choices();
1.41 raeburn 13244: @logintext = ('textcol','bgcol');
1.12 raeburn 13245: } else {
13246: %choices = &color_font_choices();
13247: }
13248: if ($role eq 'login') {
1.41 raeburn 13249: @images = ('img','logo','domlogo','login');
1.51 raeburn 13250: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13251: } else {
13252: @images = ('img');
1.200 raeburn 13253: @bgs = ('pgbg','tabbg','sidebg');
13254: }
13255: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13256: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13257: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13258: }
13259: if ($role eq 'login') {
13260: foreach my $item (@logintext) {
1.234 raeburn 13261: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13262: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13263: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13264: }
13265: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13266: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13267: }
13268: }
13269: } else {
1.234 raeburn 13270: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13271: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13272: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13273: }
13274: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13275: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13276: }
1.6 raeburn 13277: }
1.200 raeburn 13278: foreach my $item (@bgs) {
1.234 raeburn 13279: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13280: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13281: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13282: }
13283: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13284: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13285: }
13286: }
13287: foreach my $item (@links) {
1.234 raeburn 13288: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13289: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13290: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13291: }
13292: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13293: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13294: }
1.6 raeburn 13295: }
1.46 raeburn 13296: my ($configuserok,$author_ok,$switchserver) =
13297: &config_check($dom,$confname,$servadm);
1.9 raeburn 13298: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13299: if (ref($domconfig->{$role}) ne 'HASH') {
13300: $domconfig->{$role} = {};
13301: }
1.8 raeburn 13302: foreach my $img (@images) {
1.402 raeburn 13303: if ($role eq 'login') {
13304: if (($img eq 'img') || ($img eq 'logo')) {
13305: if (defined($env{'form.login_showlogo_'.$img})) {
13306: $confhash->{$role}{'showlogo'}{$img} = 1;
13307: } else {
13308: $confhash->{$role}{'showlogo'}{$img} = 0;
13309: }
13310: }
13311: if ($env{'form.login_alt_'.$img} ne '') {
13312: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13313: }
1.402 raeburn 13314: }
1.18 albertel 13315: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13316: && !defined($domconfig->{$role}{$img})
13317: && !$env{'form.'.$role.'_del_'.$img}
13318: && $env{'form.'.$role.'_import_'.$img}) {
13319: # import the old configured image from the .tab setting
13320: # if they haven't provided a new one
13321: $domconfig->{$role}{$img} =
13322: $env{'form.'.$role.'_import_'.$img};
13323: }
1.6 raeburn 13324: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13325: my $error;
1.6 raeburn 13326: if ($configuserok eq 'ok') {
1.9 raeburn 13327: if ($switchserver) {
1.12 raeburn 13328: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13329: } else {
13330: if ($author_ok eq 'ok') {
13331: my ($result,$logourl) =
13332: &publishlogo($r,'upload',$role.'_'.$img,
13333: $dom,$confname,$img,$width,$height);
13334: if ($result eq 'ok') {
13335: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13336: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 13337: } else {
1.12 raeburn 13338: $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 13339: }
13340: } else {
1.46 raeburn 13341: $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 13342: }
13343: }
13344: } else {
1.46 raeburn 13345: $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 13346: }
13347: if ($error) {
1.8 raeburn 13348: &Apache::lonnet::logthis($error);
1.11 albertel 13349: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13350: }
13351: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13352: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13353: my $error;
13354: if ($configuserok eq 'ok') {
13355: # is confname an author?
13356: if ($switchserver eq '') {
13357: if ($author_ok eq 'ok') {
13358: my ($result,$logourl) =
13359: &publishlogo($r,'copy',$domconfig->{$role}{$img},
13360: $dom,$confname,$img,$width,$height);
13361: if ($result eq 'ok') {
13362: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13363: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 13364: }
13365: }
13366: }
13367: }
1.6 raeburn 13368: }
13369: }
13370: }
13371: if (ref($domconfig) eq 'HASH') {
13372: if (ref($domconfig->{$role}) eq 'HASH') {
13373: foreach my $img (@images) {
13374: if ($domconfig->{$role}{$img} ne '') {
13375: if ($env{'form.'.$role.'_del_'.$img}) {
13376: $confhash->{$role}{$img} = '';
1.12 raeburn 13377: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13378: } else {
1.9 raeburn 13379: if ($confhash->{$role}{$img} eq '') {
13380: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13381: }
1.6 raeburn 13382: }
13383: } else {
13384: if ($env{'form.'.$role.'_del_'.$img}) {
13385: $confhash->{$role}{$img} = '';
1.12 raeburn 13386: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13387: }
13388: }
1.402 raeburn 13389: if ($role eq 'login') {
13390: if (($img eq 'logo') || ($img eq 'img')) {
13391: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13392: if ($confhash->{$role}{'showlogo'}{$img} ne
13393: $domconfig->{$role}{'showlogo'}{$img}) {
13394: $changes{$role}{'showlogo'}{$img} = 1;
13395: }
13396: } else {
13397: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13398: $changes{$role}{'showlogo'}{$img} = 1;
13399: }
1.70 raeburn 13400: }
1.402 raeburn 13401: }
13402: if ($img ne 'login') {
13403: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13404: if ($confhash->{$role}{'alttext'}{$img} ne
13405: $domconfig->{$role}{'alttext'}{$img}) {
13406: $changes{$role}{'alttext'}{$img} = 1;
13407: }
13408: } else {
13409: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13410: $changes{$role}{'alttext'}{$img} = 1;
13411: }
1.70 raeburn 13412: }
13413: }
13414: }
13415: }
1.6 raeburn 13416: if ($domconfig->{$role}{'font'} ne '') {
13417: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13418: $changes{$role}{'font'} = 1;
13419: }
13420: } else {
13421: if ($confhash->{$role}{'font'}) {
13422: $changes{$role}{'font'} = 1;
13423: }
13424: }
1.107 raeburn 13425: if ($role ne 'login') {
13426: if ($domconfig->{$role}{'fontmenu'} ne '') {
13427: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13428: $changes{$role}{'fontmenu'} = 1;
13429: }
13430: } else {
13431: if ($confhash->{$role}{'fontmenu'}) {
13432: $changes{$role}{'fontmenu'} = 1;
13433: }
1.97 tempelho 13434: }
13435: }
1.6 raeburn 13436: foreach my $item (@bgs) {
13437: if ($domconfig->{$role}{$item} ne '') {
13438: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13439: $changes{$role}{'bgs'}{$item} = 1;
13440: }
13441: } else {
13442: if ($confhash->{$role}{$item}) {
13443: $changes{$role}{'bgs'}{$item} = 1;
13444: }
13445: }
13446: }
13447: foreach my $item (@links) {
13448: if ($domconfig->{$role}{$item} ne '') {
13449: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13450: $changes{$role}{'links'}{$item} = 1;
13451: }
13452: } else {
13453: if ($confhash->{$role}{$item}) {
13454: $changes{$role}{'links'}{$item} = 1;
13455: }
13456: }
13457: }
1.41 raeburn 13458: foreach my $item (@logintext) {
13459: if ($domconfig->{$role}{$item} ne '') {
13460: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13461: $changes{$role}{'logintext'}{$item} = 1;
13462: }
13463: } else {
13464: if ($confhash->{$role}{$item}) {
13465: $changes{$role}{'logintext'}{$item} = 1;
13466: }
13467: }
13468: }
1.6 raeburn 13469: } else {
13470: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13471: \@logintext,$confhash,\%changes);
1.6 raeburn 13472: }
13473: } else {
13474: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13475: \@logintext,$confhash,\%changes);
1.6 raeburn 13476: }
13477: }
13478: return ($errors,%changes);
13479: }
13480:
1.46 raeburn 13481: sub config_check {
13482: my ($dom,$confname,$servadm) = @_;
13483: my ($configuserok,$author_ok,$switchserver,%currroles);
13484: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13485: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13486: $confname,$servadm);
13487: if ($configuserok eq 'ok') {
13488: $switchserver = &check_switchserver($dom,$confname);
13489: if ($switchserver eq '') {
13490: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13491: }
13492: }
13493: return ($configuserok,$author_ok,$switchserver);
13494: }
13495:
1.6 raeburn 13496: sub default_change_checker {
1.41 raeburn 13497: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13498: foreach my $item (@{$links}) {
13499: if ($confhash->{$role}{$item}) {
13500: $changes->{$role}{'links'}{$item} = 1;
13501: }
13502: }
13503: foreach my $item (@{$bgs}) {
13504: if ($confhash->{$role}{$item}) {
13505: $changes->{$role}{'bgs'}{$item} = 1;
13506: }
13507: }
1.41 raeburn 13508: foreach my $item (@{$logintext}) {
13509: if ($confhash->{$role}{$item}) {
13510: $changes->{$role}{'logintext'}{$item} = 1;
13511: }
13512: }
1.6 raeburn 13513: foreach my $img (@{$images}) {
13514: if ($env{'form.'.$role.'_del_'.$img}) {
13515: $confhash->{$role}{$img} = '';
1.12 raeburn 13516: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13517: }
1.70 raeburn 13518: if ($role eq 'login') {
13519: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13520: $changes->{$role}{'showlogo'}{$img} = 1;
13521: }
1.402 raeburn 13522: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13523: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13524: $changes->{$role}{'alttext'}{$img} = 1;
13525: }
13526: }
1.70 raeburn 13527: }
1.6 raeburn 13528: }
13529: if ($confhash->{$role}{'font'}) {
13530: $changes->{$role}{'font'} = 1;
13531: }
1.48 raeburn 13532: }
1.6 raeburn 13533:
13534: sub display_colorchgs {
13535: my ($dom,$changes,$roles,$confhash) = @_;
13536: my (%choices,$resulttext);
13537: if (!grep(/^login$/,@{$roles})) {
13538: $resulttext = &mt('Changes made:').'<br />';
13539: }
13540: foreach my $role (@{$roles}) {
13541: if ($role eq 'login') {
13542: %choices = &login_choices();
13543: } else {
13544: %choices = &color_font_choices();
13545: }
13546: if (ref($changes->{$role}) eq 'HASH') {
13547: if ($role ne 'login') {
13548: $resulttext .= '<h4>'.&mt($role).'</h4>';
13549: }
13550: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13551: if ($role ne 'login') {
13552: $resulttext .= '<ul>';
13553: }
13554: if (ref($changes->{$role}{$key}) eq 'HASH') {
13555: if ($role ne 'login') {
13556: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13557: }
13558: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13559: if (($role eq 'login') && ($key eq 'showlogo')) {
13560: if ($confhash->{$role}{$key}{$item}) {
13561: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13562: } else {
13563: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13564: }
1.402 raeburn 13565: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13566: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13567: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13568: $confhash->{$role}{$key}{$item}).'</li>';
13569: } else {
13570: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13571: }
1.70 raeburn 13572: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13573: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13574: } else {
1.12 raeburn 13575: my $newitem = $confhash->{$role}{$item};
13576: if ($key eq 'images') {
1.306 raeburn 13577: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13578: }
13579: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13580: }
13581: }
13582: if ($role ne 'login') {
13583: $resulttext .= '</ul></li>';
13584: }
13585: } else {
13586: if ($confhash->{$role}{$key} eq '') {
13587: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13588: } else {
13589: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13590: }
13591: }
13592: if ($role ne 'login') {
13593: $resulttext .= '</ul>';
13594: }
13595: }
13596: }
13597: }
1.3 raeburn 13598: return $resulttext;
1.1 raeburn 13599: }
13600:
1.9 raeburn 13601: sub thumb_dimensions {
13602: return ('200','50');
13603: }
13604:
1.16 raeburn 13605: sub check_dimensions {
13606: my ($inputfile) = @_;
13607: my ($fullwidth,$fullheight);
13608: if ($inputfile =~ m|^[/\w.\-]+$|) {
13609: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13610: my $imageinfo = <PIPE>;
13611: if (!close(PIPE)) {
13612: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13613: }
13614: chomp($imageinfo);
13615: my ($fullsize) =
1.21 raeburn 13616: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13617: if ($fullsize) {
13618: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13619: }
13620: }
13621: }
13622: return ($fullwidth,$fullheight);
13623: }
13624:
1.9 raeburn 13625: sub check_configuser {
13626: my ($uhome,$dom,$confname,$servadm) = @_;
13627: my ($configuserok,%currroles);
13628: if ($uhome eq 'no_host') {
13629: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13630: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13631: $configuserok =
13632: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13633: $configpass,'','','','','',undef,$servadm);
13634: } else {
13635: $configuserok = 'ok';
13636: %currroles =
13637: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13638: }
13639: return ($configuserok,%currroles);
13640: }
13641:
13642: sub check_authorstatus {
13643: my ($dom,$confname,%currroles) = @_;
13644: my $author_ok;
1.40 raeburn 13645: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13646: my $start = time;
13647: my $end = 0;
13648: $author_ok =
13649: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13650: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13651: } else {
13652: $author_ok = 'ok';
13653: }
13654: return $author_ok;
13655: }
13656:
13657: sub publishlogo {
1.46 raeburn 13658: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 13659: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 13660: if ($action eq 'upload') {
13661: $fname=$env{'form.'.$formname.'.filename'};
13662: chop($env{'form.'.$formname});
13663: } else {
13664: ($fname) = ($formname =~ /([^\/]+)$/);
13665: }
1.46 raeburn 13666: if ($savefileas ne '') {
13667: $fname = $savefileas;
13668: }
1.9 raeburn 13669: $fname=&Apache::lonnet::clean_filename($fname);
13670: # See if there is anything left
13671: unless ($fname) { return ('error: no uploaded file'); }
13672: $fname="$subdir/$fname";
1.210 raeburn 13673: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 13674: my $filepath="$docroot/priv";
13675: my $relpath = "$dom/$confname";
1.9 raeburn 13676: my ($fnamepath,$file,$fetchthumb);
13677: $file=$fname;
13678: if ($fname=~m|/|) {
13679: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
13680: }
1.164 raeburn 13681: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 13682: my $count;
1.164 raeburn 13683: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 13684: $filepath.="/$parts[$count]";
13685: if ((-e $filepath)!=1) {
13686: mkdir($filepath,02770);
13687: }
13688: }
13689: # Check for bad extension and disallow upload
13690: if ($file=~/\.(\w+)$/ &&
13691: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
13692: $output =
1.207 bisitz 13693: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 13694: } elsif ($file=~/\.(\w+)$/ &&
13695: !defined(&Apache::loncommon::fileembstyle($1))) {
13696: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
13697: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 13698: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 13699: } elsif (-d "$filepath/$file") {
1.195 bisitz 13700: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 13701: } else {
13702: my $source = $filepath.'/'.$file;
13703: my $logfile;
1.316 raeburn 13704: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 13705: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 13706: }
13707: print $logfile
13708: "\n================= Publish ".localtime()." ================\n".
13709: $env{'user.name'}.':'.$env{'user.domain'}."\n";
13710: # Save the file
1.316 raeburn 13711: if (!open(FH,">",$source)) {
1.9 raeburn 13712: &Apache::lonnet::logthis('Failed to create '.$source);
13713: return (&mt('Failed to create file'));
13714: }
13715: if ($action eq 'upload') {
13716: if (!print FH ($env{'form.'.$formname})) {
13717: &Apache::lonnet::logthis('Failed to write to '.$source);
13718: return (&mt('Failed to write file'));
13719: }
13720: } else {
13721: my $original = &Apache::lonnet::filelocation('',$formname);
13722: if(!copy($original,$source)) {
13723: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
13724: return (&mt('Failed to write file'));
13725: }
13726: }
13727: close(FH);
13728: chmod(0660, $source); # Permissions to rw-rw---.
13729:
13730: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
13731: my $copyfile=$targetdir.'/'.$file;
13732:
13733: my @parts=split(/\//,$targetdir);
13734: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
13735: for (my $count=5;$count<=$#parts;$count++) {
13736: $path.="/$parts[$count]";
13737: if (!-e $path) {
13738: print $logfile "\nCreating directory ".$path;
13739: mkdir($path,02770);
13740: }
13741: }
13742: my $versionresult;
13743: if (-e $copyfile) {
13744: $versionresult = &logo_versioning($targetdir,$file,$logfile);
13745: } else {
13746: $versionresult = 'ok';
13747: }
13748: if ($versionresult eq 'ok') {
13749: if (copy($source,$copyfile)) {
13750: print $logfile "\nCopied original source to ".$copyfile."\n";
13751: $output = 'ok';
13752: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 13753: push(@{$modified_urls},[$copyfile,$source]);
13754: my $metaoutput =
13755: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
13756: unless ($registered_cleanup) {
13757: my $handlers = $r->get_handlers('PerlCleanupHandler');
13758: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13759: $registered_cleanup=1;
13760: }
1.9 raeburn 13761: } else {
13762: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
13763: $output = &mt('Failed to copy file to RES space').", $!";
13764: }
13765: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
13766: my $inputfile = $filepath.'/'.$file;
13767: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 13768: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
13769: if ($fullwidth ne '' && $fullheight ne '') {
13770: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
13771: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 13772: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
13773: system({$args[0]} @args);
1.16 raeburn 13774: chmod(0660, $filepath.'/tn-'.$file);
13775: if (-e $outfile) {
13776: my $copyfile=$targetdir.'/tn-'.$file;
13777: if (copy($outfile,$copyfile)) {
13778: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 13779: my $thumb_metaoutput =
13780: &write_metadata($dom,$confname,$formname,
13781: $targetdir,'tn-'.$file,$logfile);
13782: push(@{$modified_urls},[$copyfile,$outfile]);
13783: unless ($registered_cleanup) {
13784: my $handlers = $r->get_handlers('PerlCleanupHandler');
13785: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13786: $registered_cleanup=1;
13787: }
1.267 raeburn 13788: $madethumb = 1;
1.16 raeburn 13789: } else {
13790: print $logfile "\nUnable to write ".$copyfile.
13791: ':'.$!."\n";
13792: }
13793: }
1.9 raeburn 13794: }
13795: }
13796: }
13797: } else {
13798: $output = $versionresult;
13799: }
13800: }
1.267 raeburn 13801: return ($output,$logourl,$madethumb);
1.9 raeburn 13802: }
13803:
13804: sub logo_versioning {
13805: my ($targetdir,$file,$logfile) = @_;
13806: my $target = $targetdir.'/'.$file;
13807: my ($maxversion,$fn,$extn,$output);
13808: $maxversion = 0;
13809: if ($file =~ /^(.+)\.(\w+)$/) {
13810: $fn=$1;
13811: $extn=$2;
13812: }
13813: opendir(DIR,$targetdir);
13814: while (my $filename=readdir(DIR)) {
13815: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
13816: $maxversion=($1>$maxversion)?$1:$maxversion;
13817: }
13818: }
13819: $maxversion++;
13820: print $logfile "\nCreating old version ".$maxversion."\n";
13821: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
13822: if (copy($target,$copyfile)) {
13823: print $logfile "Copied old target to ".$copyfile."\n";
13824: $copyfile=$copyfile.'.meta';
13825: if (copy($target.'.meta',$copyfile)) {
13826: print $logfile "Copied old target metadata to ".$copyfile."\n";
13827: $output = 'ok';
13828: } else {
13829: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
13830: $output = &mt('Failed to copy old meta').", $!, ";
13831: }
13832: } else {
13833: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
13834: $output = &mt('Failed to copy old target').", $!, ";
13835: }
13836: return $output;
13837: }
13838:
13839: sub write_metadata {
13840: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
13841: my (%metadatafields,%metadatakeys,$output);
13842: $metadatafields{'title'}=$formname;
13843: $metadatafields{'creationdate'}=time;
13844: $metadatafields{'lastrevisiondate'}=time;
13845: $metadatafields{'copyright'}='public';
13846: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
13847: $env{'user.domain'};
13848: $metadatafields{'authorspace'}=$confname.':'.$dom;
13849: $metadatafields{'domain'}=$dom;
13850: {
13851: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
13852: my $mfh;
1.316 raeburn 13853: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 13854: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 13855: unless ($_=~/\./) {
13856: my $unikey=$_;
13857: $unikey=~/^([A-Za-z]+)/;
13858: my $tag=$1;
13859: $tag=~tr/A-Z/a-z/;
13860: print $mfh "\n\<$tag";
13861: foreach (split(/\,/,$metadatakeys{$unikey})) {
13862: my $value=$metadatafields{$unikey.'.'.$_};
13863: $value=~s/\"/\'\'/g;
13864: print $mfh ' '.$_.'="'.$value.'"';
13865: }
13866: print $mfh '>'.
13867: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
13868: .'</'.$tag.'>';
13869: }
13870: }
13871: $output = 'ok';
13872: print $logfile "\nWrote metadata";
13873: close($mfh);
13874: } else {
13875: print $logfile "\nFailed to open metadata file";
1.9 raeburn 13876: $output = &mt('Could not write metadata');
13877: }
13878: }
1.155 raeburn 13879: return $output;
13880: }
13881:
13882: sub notifysubscribed {
13883: foreach my $targetsource (@{$modified_urls}){
13884: next unless (ref($targetsource) eq 'ARRAY');
13885: my ($target,$source)=@{$targetsource};
13886: if ($source ne '') {
1.316 raeburn 13887: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13888: print $logfh "\nCleanup phase: Notifications\n";
13889: my @subscribed=&subscribed_hosts($target);
13890: foreach my $subhost (@subscribed) {
13891: print $logfh "\nNotifying host ".$subhost.':';
13892: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13893: print $logfh $reply;
13894: }
13895: my @subscribedmeta=&subscribed_hosts("$target.meta");
13896: foreach my $subhost (@subscribedmeta) {
13897: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13898: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13899: $subhost);
13900: print $logfh $reply;
13901: }
13902: print $logfh "\n============ Done ============\n";
1.160 raeburn 13903: close($logfh);
1.155 raeburn 13904: }
13905: }
13906: }
13907: return OK;
13908: }
13909:
13910: sub subscribed_hosts {
13911: my ($target) = @_;
13912: my @subscribed;
1.316 raeburn 13913: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13914: while (my $subline=<$fh>) {
13915: if ($subline =~ /^($match_lonid):/) {
13916: my $host = $1;
13917: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13918: unless (grep(/^\Q$host\E$/,@subscribed)) {
13919: push(@subscribed,$host);
13920: }
13921: }
13922: }
13923: }
13924: }
13925: return @subscribed;
1.9 raeburn 13926: }
13927:
13928: sub check_switchserver {
13929: my ($dom,$confname) = @_;
13930: my ($allowed,$switchserver);
13931: my $home = &Apache::lonnet::homeserver($confname,$dom);
13932: if ($home eq 'no_host') {
13933: $home = &Apache::lonnet::domain($dom,'primary');
13934: }
13935: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 13936: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
13937: if (!$allowed) {
1.180 raeburn 13938: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 13939: }
13940: return $switchserver;
13941: }
13942:
1.1 raeburn 13943: sub modify_quotas {
1.216 raeburn 13944: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 13945: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 13946: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 13947: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
13948: $validationfieldsref);
1.86 raeburn 13949: if ($action eq 'quotas') {
13950: $context = 'tools';
1.163 raeburn 13951: } else {
1.86 raeburn 13952: $context = $action;
13953: }
13954: if ($context eq 'requestcourses') {
1.325 raeburn 13955: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 13956: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 13957: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
13958: %titles = &courserequest_titles();
13959: $toolregexp = join('|',@usertools);
13960: %conditions = &courserequest_conditions();
1.216 raeburn 13961: $confname = $dom.'-domainconfig';
13962: my $servadm = $r->dir_config('lonAdmEMail');
13963: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 13964: ($validationitemsref,$validationnamesref,$validationfieldsref) =
13965: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 13966: } elsif ($context eq 'requestauthor') {
13967: @usertools = ('author');
13968: %titles = &authorrequest_titles();
1.86 raeburn 13969: } else {
1.413 ! raeburn 13970: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 13971: %titles = &tool_titles();
1.86 raeburn 13972: }
1.212 raeburn 13973: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 13974: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13975: foreach my $key (keys(%env)) {
1.101 raeburn 13976: if ($context eq 'requestcourses') {
13977: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
13978: my $item = $1;
13979: my $type = $2;
13980: if ($type =~ /^limit_(.+)/) {
13981: $limithash{$item}{$1} = $env{$key};
13982: } else {
13983: $confhash{$item}{$type} = $env{$key};
13984: }
13985: }
1.163 raeburn 13986: } elsif ($context eq 'requestauthor') {
13987: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
13988: $confhash{$1} = $env{$key};
13989: }
1.101 raeburn 13990: } else {
1.86 raeburn 13991: if ($key =~ /^form\.quota_(.+)$/) {
13992: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 13993: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
13994: $confhash{'authorquota'}{$1} = $env{$key};
13995: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 13996: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
13997: }
1.72 raeburn 13998: }
13999: }
1.163 raeburn 14000: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14001: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14002: @approvalnotify = sort(@approvalnotify);
14003: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14004: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14005: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14006: foreach my $type (@hasuniquecode) {
14007: if (grep(/^\Q$type\E$/,@crstypes)) {
14008: $confhash{'uniquecode'}{$type} = 1;
14009: }
1.216 raeburn 14010: }
1.242 raeburn 14011: my (%newbook,%allpos);
1.216 raeburn 14012: if ($context eq 'requestcourses') {
1.242 raeburn 14013: foreach my $type ('textbooks','templates') {
14014: @{$allpos{$type}} = ();
14015: my $invalid;
14016: if ($type eq 'textbooks') {
14017: $invalid = &mt('Invalid LON-CAPA course for textbook');
14018: } else {
14019: $invalid = &mt('Invalid LON-CAPA course for template');
14020: }
14021: if ($env{'form.'.$type.'_addbook'}) {
14022: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14023: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14024: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14025: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14026: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14027: } else {
14028: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14029: my $position = $env{'form.'.$type.'_addbook_pos'};
14030: $position =~ s/\D+//g;
14031: if ($position ne '') {
14032: $allpos{$type}[$position] = $newbook{$type};
14033: }
1.216 raeburn 14034: }
1.242 raeburn 14035: } else {
14036: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14037: }
14038: }
1.242 raeburn 14039: }
1.216 raeburn 14040: }
1.102 raeburn 14041: if (ref($domconfig{$action}) eq 'HASH') {
14042: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14043: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14044: $changes{'notify'}{'approval'} = 1;
14045: }
14046: } else {
1.144 raeburn 14047: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14048: $changes{'notify'}{'approval'} = 1;
14049: }
14050: }
1.218 raeburn 14051: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14052: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14053: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14054: unless ($confhash{'uniquecode'}{$crstype}) {
14055: $changes{'uniquecode'} = 1;
14056: }
14057: }
14058: unless ($changes{'uniquecode'}) {
14059: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14060: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14061: $changes{'uniquecode'} = 1;
14062: }
14063: }
14064: }
14065: } else {
14066: $changes{'uniquecode'} = 1;
14067: }
14068: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14069: $changes{'uniquecode'} = 1;
1.216 raeburn 14070: }
14071: if ($context eq 'requestcourses') {
1.242 raeburn 14072: foreach my $type ('textbooks','templates') {
14073: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14074: my %deletions;
14075: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14076: if (@todelete) {
14077: map { $deletions{$_} = 1; } @todelete;
14078: }
14079: my %imgdeletions;
14080: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14081: if (@todeleteimages) {
14082: map { $imgdeletions{$_} = 1; } @todeleteimages;
14083: }
14084: my $maxnum = $env{'form.'.$type.'_maxnum'};
14085: for (my $i=0; $i<=$maxnum; $i++) {
14086: my $itemid = $env{'form.'.$type.'_id_'.$i};
14087: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14088: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14089: if ($deletions{$key}) {
14090: if ($domconfig{$action}{$type}{$key}{'image'}) {
14091: #FIXME need to obsolete item in RES space
14092: }
14093: next;
14094: } else {
14095: my $newpos = $env{'form.'.$itemid};
14096: $newpos =~ s/\D+//g;
1.243 raeburn 14097: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14098: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14099: ($type eq 'templates'));
1.242 raeburn 14100: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14101: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14102: $changes{$type}{$key} = 1;
14103: }
14104: }
14105: $allpos{$type}[$newpos] = $key;
14106: }
14107: if ($imgdeletions{$key}) {
14108: $changes{$type}{$key} = 1;
1.216 raeburn 14109: #FIXME need to obsolete item in RES space
1.242 raeburn 14110: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14111: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14112: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14113: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14114: } else {
14115: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14116: $cdom,$cnum,$type,$configuserok,
14117: $switchserver,$author_ok);
14118: if ($imgurl) {
14119: $confhash{$type}{$key}{'image'} = $imgurl;
14120: $changes{$type}{$key} = 1;
14121: }
14122: if ($error) {
14123: &Apache::lonnet::logthis($error);
14124: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14125: }
14126: }
1.242 raeburn 14127: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14128: $confhash{$type}{$key}{'image'} =
14129: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14130: }
14131: }
14132: }
14133: }
14134: }
14135: }
1.102 raeburn 14136: } else {
1.144 raeburn 14137: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14138: $changes{'notify'}{'approval'} = 1;
14139: }
1.218 raeburn 14140: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14141: $changes{'uniquecode'} = 1;
14142: }
14143: }
14144: if ($context eq 'requestcourses') {
1.242 raeburn 14145: foreach my $type ('textbooks','templates') {
14146: if ($newbook{$type}) {
14147: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14148: foreach my $item ('subject','title','publisher','author') {
14149: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14150: ($type eq 'template'));
1.242 raeburn 14151: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14152: if ($env{'form.'.$type.'_addbook_'.$item}) {
14153: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14154: }
14155: }
14156: if ($type eq 'textbooks') {
14157: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14158: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14159: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14160: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14161: } else {
14162: my ($imageurl,$error) =
14163: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14164: $configuserok,$switchserver,$author_ok);
14165: if ($imageurl) {
14166: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14167: }
14168: if ($error) {
14169: &Apache::lonnet::logthis($error);
14170: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14171: }
1.242 raeburn 14172: }
14173: }
1.216 raeburn 14174: }
14175: }
1.242 raeburn 14176: if (@{$allpos{$type}} > 0) {
14177: my $idx = 0;
14178: foreach my $item (@{$allpos{$type}}) {
14179: if ($item ne '') {
14180: $confhash{$type}{$item}{'order'} = $idx;
14181: if (ref($domconfig{$action}) eq 'HASH') {
14182: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14183: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14184: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14185: $changes{$type}{$item} = 1;
14186: }
1.216 raeburn 14187: }
14188: }
14189: }
1.242 raeburn 14190: $idx ++;
1.216 raeburn 14191: }
14192: }
14193: }
14194: }
1.235 raeburn 14195: if (ref($validationitemsref) eq 'ARRAY') {
14196: foreach my $item (@{$validationitemsref}) {
14197: if ($item eq 'fields') {
14198: my @changed;
14199: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14200: if (@{$confhash{'validation'}{$item}} > 0) {
14201: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14202: }
1.266 raeburn 14203: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14204: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14205: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14206: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14207: $domconfig{'requestcourses'}{'validation'}{$item});
14208: } else {
14209: @changed = @{$confhash{'validation'}{$item}};
14210: }
1.235 raeburn 14211: } else {
14212: @changed = @{$confhash{'validation'}{$item}};
14213: }
14214: } else {
14215: @changed = @{$confhash{'validation'}{$item}};
14216: }
14217: if (@changed) {
14218: if ($confhash{'validation'}{$item}) {
14219: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14220: } else {
14221: $changes{'validation'}{$item} = &mt('None');
14222: }
14223: }
14224: } else {
14225: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14226: if ($item eq 'markup') {
14227: if ($env{'form.requestcourses_validation_'.$item}) {
14228: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14229: }
14230: }
1.266 raeburn 14231: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14232: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14233: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14234: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14235: }
14236: } else {
14237: if ($confhash{'validation'}{$item} ne '') {
14238: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14239: }
1.235 raeburn 14240: }
14241: } else {
14242: if ($confhash{'validation'}{$item} ne '') {
14243: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14244: }
14245: }
14246: }
14247: }
14248: }
14249: if ($env{'form.validationdc'}) {
14250: my $newval = $env{'form.validationdc'};
1.285 raeburn 14251: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14252: if (exists($domcoords{$newval})) {
14253: $confhash{'validation'}{'dc'} = $newval;
14254: }
14255: }
14256: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14257: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14258: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14259: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14260: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14261: if ($confhash{'validation'}{'dc'} eq '') {
14262: $changes{'validation'}{'dc'} = &mt('None');
14263: } else {
14264: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14265: }
1.235 raeburn 14266: }
1.266 raeburn 14267: } elsif ($confhash{'validation'}{'dc'} ne '') {
14268: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14269: }
14270: } elsif ($confhash{'validation'}{'dc'} ne '') {
14271: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14272: }
14273: } elsif ($confhash{'validation'}{'dc'} ne '') {
14274: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14275: }
1.266 raeburn 14276: } else {
14277: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14278: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14279: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14280: $changes{'validation'}{'dc'} = &mt('None');
14281: }
14282: }
1.235 raeburn 14283: }
14284: }
1.102 raeburn 14285: }
14286: } else {
1.86 raeburn 14287: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 14288: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 14289: }
1.72 raeburn 14290: foreach my $item (@usertools) {
14291: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14292: my $unset;
1.101 raeburn 14293: if ($context eq 'requestcourses') {
1.104 raeburn 14294: $unset = '0';
14295: if ($type eq '_LC_adv') {
14296: $unset = '';
14297: }
1.101 raeburn 14298: if ($confhash{$item}{$type} eq 'autolimit') {
14299: $confhash{$item}{$type} .= '=';
14300: unless ($limithash{$item}{$type} =~ /\D/) {
14301: $confhash{$item}{$type} .= $limithash{$item}{$type};
14302: }
14303: }
1.163 raeburn 14304: } elsif ($context eq 'requestauthor') {
14305: $unset = '0';
14306: if ($type eq '_LC_adv') {
14307: $unset = '';
14308: }
1.72 raeburn 14309: } else {
1.101 raeburn 14310: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14311: $confhash{$item}{$type} = 1;
14312: } else {
14313: $confhash{$item}{$type} = 0;
14314: }
1.72 raeburn 14315: }
1.86 raeburn 14316: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14317: if ($action eq 'requestauthor') {
14318: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14319: $changes{$type} = 1;
14320: }
14321: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14322: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14323: $changes{$item}{$type} = 1;
14324: }
14325: } else {
14326: if ($context eq 'requestcourses') {
1.104 raeburn 14327: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14328: $changes{$item}{$type} = 1;
14329: }
14330: } else {
14331: if (!$confhash{$item}{$type}) {
14332: $changes{$item}{$type} = 1;
14333: }
14334: }
14335: }
14336: } else {
14337: if ($context eq 'requestcourses') {
1.104 raeburn 14338: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14339: $changes{$item}{$type} = 1;
14340: }
1.163 raeburn 14341: } elsif ($context eq 'requestauthor') {
14342: if ($confhash{$type} ne $unset) {
14343: $changes{$type} = 1;
14344: }
1.72 raeburn 14345: } else {
14346: if (!$confhash{$item}{$type}) {
14347: $changes{$item}{$type} = 1;
14348: }
14349: }
14350: }
1.1 raeburn 14351: }
14352: }
1.163 raeburn 14353: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14354: if (ref($domconfig{'quotas'}) eq 'HASH') {
14355: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14356: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14357: if (exists($confhash{'defaultquota'}{$key})) {
14358: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14359: $changes{'defaultquota'}{$key} = 1;
14360: }
14361: } else {
14362: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14363: }
14364: }
1.86 raeburn 14365: } else {
14366: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14367: if (exists($confhash{'defaultquota'}{$key})) {
14368: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14369: $changes{'defaultquota'}{$key} = 1;
14370: }
14371: } else {
14372: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14373: }
1.1 raeburn 14374: }
14375: }
1.197 raeburn 14376: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
14377: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
14378: if (exists($confhash{'authorquota'}{$key})) {
14379: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
14380: $changes{'authorquota'}{$key} = 1;
14381: }
14382: } else {
14383: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
14384: }
14385: }
14386: }
1.1 raeburn 14387: }
1.86 raeburn 14388: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14389: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14390: if (ref($domconfig{'quotas'}) eq 'HASH') {
14391: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14392: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14393: $changes{'defaultquota'}{$key} = 1;
14394: }
14395: } else {
14396: if (!exists($domconfig{'quotas'}{$key})) {
14397: $changes{'defaultquota'}{$key} = 1;
14398: }
1.72 raeburn 14399: }
14400: } else {
1.86 raeburn 14401: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14402: }
1.1 raeburn 14403: }
14404: }
1.197 raeburn 14405: if (ref($confhash{'authorquota'}) eq 'HASH') {
14406: foreach my $key (keys(%{$confhash{'authorquota'}})) {
14407: if (ref($domconfig{'quotas'}) eq 'HASH') {
14408: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
14409: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
14410: $changes{'authorquota'}{$key} = 1;
14411: }
14412: } else {
14413: $changes{'authorquota'}{$key} = 1;
14414: }
14415: } else {
14416: $changes{'authorquota'}{$key} = 1;
14417: }
14418: }
14419: }
1.1 raeburn 14420: }
1.72 raeburn 14421:
1.163 raeburn 14422: if ($context eq 'requestauthor') {
14423: $domdefaults{'requestauthor'} = \%confhash;
14424: } else {
14425: foreach my $key (keys(%confhash)) {
1.242 raeburn 14426: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14427: $domdefaults{$key} = $confhash{$key};
14428: }
1.163 raeburn 14429: }
1.72 raeburn 14430: }
1.163 raeburn 14431:
1.1 raeburn 14432: my %quotahash = (
1.86 raeburn 14433: $action => { %confhash }
1.1 raeburn 14434: );
14435: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14436: $dom);
14437: if ($putresult eq 'ok') {
14438: if (keys(%changes) > 0) {
1.72 raeburn 14439: my $cachetime = 24*60*60;
14440: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14441: if (ref($lastactref) eq 'HASH') {
14442: $lastactref->{'domdefaults'} = 1;
14443: }
1.1 raeburn 14444: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14445: unless (($context eq 'requestcourses') ||
1.163 raeburn 14446: ($context eq 'requestauthor')) {
1.86 raeburn 14447: if (ref($changes{'defaultquota'}) eq 'HASH') {
14448: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14449: foreach my $type (@{$types},'default') {
14450: if (defined($changes{'defaultquota'}{$type})) {
14451: my $typetitle = $usertypes->{$type};
14452: if ($type eq 'default') {
14453: $typetitle = $othertitle;
14454: }
1.213 raeburn 14455: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14456: }
14457: }
1.86 raeburn 14458: $resulttext .= '</ul></li>';
1.72 raeburn 14459: }
1.197 raeburn 14460: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 14461: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 14462: foreach my $type (@{$types},'default') {
14463: if (defined($changes{'authorquota'}{$type})) {
14464: my $typetitle = $usertypes->{$type};
14465: if ($type eq 'default') {
14466: $typetitle = $othertitle;
14467: }
1.213 raeburn 14468: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 14469: }
14470: }
14471: $resulttext .= '</ul></li>';
14472: }
1.72 raeburn 14473: }
1.80 raeburn 14474: my %newenv;
1.72 raeburn 14475: foreach my $item (@usertools) {
1.163 raeburn 14476: my (%haschgs,%inconf);
14477: if ($context eq 'requestauthor') {
14478: %haschgs = %changes;
1.210 raeburn 14479: %inconf = %confhash;
1.163 raeburn 14480: } else {
14481: if (ref($changes{$item}) eq 'HASH') {
14482: %haschgs = %{$changes{$item}};
14483: }
14484: if (ref($confhash{$item}) eq 'HASH') {
14485: %inconf = %{$confhash{$item}};
14486: }
14487: }
14488: if (keys(%haschgs) > 0) {
1.80 raeburn 14489: my $newacc =
14490: &Apache::lonnet::usertools_access($env{'user.name'},
14491: $env{'user.domain'},
1.86 raeburn 14492: $item,'reload',$context);
1.210 raeburn 14493: if (($context eq 'requestcourses') ||
1.163 raeburn 14494: ($context eq 'requestauthor')) {
1.108 raeburn 14495: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14496: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14497: }
14498: } else {
14499: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14500: $newenv{'environment.availabletools.'.$item} = $newacc;
14501: }
1.80 raeburn 14502: }
1.163 raeburn 14503: unless ($context eq 'requestauthor') {
14504: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14505: }
1.72 raeburn 14506: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14507: if ($haschgs{$type}) {
1.72 raeburn 14508: my $typetitle = $usertypes->{$type};
14509: if ($type eq 'default') {
14510: $typetitle = $othertitle;
14511: } elsif ($type eq '_LC_adv') {
14512: $typetitle = 'LON-CAPA Advanced Users';
14513: }
1.163 raeburn 14514: if ($inconf{$type}) {
1.101 raeburn 14515: if ($context eq 'requestcourses') {
14516: my $cond;
1.163 raeburn 14517: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14518: if ($1 eq '') {
14519: $cond = &mt('(Automatic processing of any request).');
14520: } else {
14521: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14522: }
14523: } else {
1.163 raeburn 14524: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14525: }
14526: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14527: } elsif ($context eq 'requestauthor') {
14528: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14529: $titles{$inconf{$type}},$typetitle);
14530:
1.101 raeburn 14531: } else {
14532: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14533: }
1.72 raeburn 14534: } else {
1.104 raeburn 14535: if ($type eq '_LC_adv') {
1.163 raeburn 14536: if ($inconf{$type} eq '0') {
1.104 raeburn 14537: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14538: } else {
14539: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14540: }
14541: } else {
14542: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14543: }
1.72 raeburn 14544: }
14545: }
1.26 raeburn 14546: }
1.163 raeburn 14547: unless ($context eq 'requestauthor') {
14548: $resulttext .= '</ul></li>';
14549: }
1.26 raeburn 14550: }
1.1 raeburn 14551: }
1.163 raeburn 14552: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14553: if (ref($changes{'notify'}) eq 'HASH') {
14554: if ($changes{'notify'}{'approval'}) {
14555: if (ref($confhash{'notify'}) eq 'HASH') {
14556: if ($confhash{'notify'}{'approval'}) {
14557: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14558: } else {
1.163 raeburn 14559: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14560: }
14561: }
14562: }
14563: }
14564: }
1.216 raeburn 14565: if ($action eq 'requestcourses') {
14566: my @offon = ('off','on');
14567: if ($changes{'uniquecode'}) {
1.218 raeburn 14568: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14569: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14570: $resulttext .= '<li>'.
14571: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14572: '</li>';
14573: } else {
14574: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14575: '</li>';
14576: }
1.216 raeburn 14577: }
1.242 raeburn 14578: foreach my $type ('textbooks','templates') {
14579: if (ref($changes{$type}) eq 'HASH') {
14580: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14581: foreach my $key (sort(keys(%{$changes{$type}}))) {
14582: my %coursehash = &Apache::lonnet::coursedescription($key);
14583: my $coursetitle = $coursehash{'description'};
14584: my $position = $confhash{$type}{$key}{'order'} + 1;
14585: $resulttext .= '<li>';
1.243 raeburn 14586: foreach my $item ('subject','title','publisher','author') {
14587: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14588: ($type eq 'templates'));
1.242 raeburn 14589: my $name = $item.':';
14590: $name =~ s/^(\w)/\U$1/;
14591: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14592: }
14593: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14594: if ($type eq 'textbooks') {
14595: if ($confhash{$type}{$key}{'image'}) {
14596: $resulttext .= ' '.&mt('Image: [_1]',
14597: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14598: ' alt="Textbook cover" />').'<br />';
14599: }
14600: }
14601: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14602: }
1.242 raeburn 14603: $resulttext .= '</ul></li>';
1.216 raeburn 14604: }
14605: }
1.235 raeburn 14606: if (ref($changes{'validation'}) eq 'HASH') {
14607: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14608: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14609: foreach my $item (@{$validationitemsref}) {
14610: if (exists($changes{'validation'}{$item})) {
14611: if ($item eq 'markup') {
14612: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14613: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14614: } else {
14615: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14616: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14617: }
14618: }
14619: }
14620: if (exists($changes{'validation'}{'dc'})) {
14621: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14622: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14623: }
14624: }
14625: }
1.216 raeburn 14626: }
1.1 raeburn 14627: $resulttext .= '</ul>';
1.80 raeburn 14628: if (keys(%newenv)) {
14629: &Apache::lonnet::appenv(\%newenv);
14630: }
1.1 raeburn 14631: } else {
1.86 raeburn 14632: if ($context eq 'requestcourses') {
14633: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14634: } elsif ($context eq 'requestauthor') {
14635: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14636: } else {
1.90 weissno 14637: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14638: }
1.1 raeburn 14639: }
14640: } else {
1.11 albertel 14641: $resulttext = '<span class="LC_error">'.
14642: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14643: }
1.216 raeburn 14644: if ($errors) {
14645: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14646: '<ul>'.$errors.'</ul></p>';
14647: }
1.3 raeburn 14648: return $resulttext;
1.1 raeburn 14649: }
14650:
1.216 raeburn 14651: sub process_textbook_image {
1.242 raeburn 14652: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14653: my $filename = $env{'form.'.$caller.'.filename'};
14654: my ($error,$url);
14655: my ($width,$height) = (50,50);
14656: if ($configuserok eq 'ok') {
14657: if ($switchserver) {
14658: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14659: $switchserver);
14660: } elsif ($author_ok eq 'ok') {
14661: my ($result,$imageurl) =
14662: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 14663: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 14664: if ($result eq 'ok') {
14665: $url = $imageurl;
14666: } else {
14667: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14668: }
14669: } else {
14670: $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);
14671: }
14672: } else {
14673: $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);
14674: }
14675: return ($url,$error);
14676: }
14677:
1.267 raeburn 14678: sub modify_ltitools {
14679: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14680: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 14681: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 14682: my $confname = $dom.'-domainconfig';
14683: my $servadm = $r->dir_config('lonAdmEMail');
14684: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14685: my (%posslti,%possfield);
14686: my @courseroles = ('cc','in','ta','ep','st');
14687: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
14688: map { $posslti{$_} = 1; } @ltiroles;
14689: my @allfields = ('fullname','firstname','lastname','email','user','roles');
14690: map { $possfield{$_} = 1; } @allfields;
14691: my %lt = <itools_names();
14692: if ($env{'form.ltitools_add'}) {
14693: my $title = $env{'form.ltitools_add_title'};
14694: $title =~ s/(`)/'/g;
14695: ($newid,my $error) = &get_ltitools_id($dom,$title);
14696: if ($newid) {
14697: my $position = $env{'form.ltitools_add_pos'};
14698: $position =~ s/\D+//g;
14699: if ($position ne '') {
14700: $allpos[$position] = $newid;
14701: }
14702: $changes{$newid} = 1;
1.322 raeburn 14703: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 14704: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 14705: if ($item eq 'lifetime') {
14706: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
14707: }
1.267 raeburn 14708: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 14709: if (($item eq 'key') || ($item eq 'secret')) {
14710: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14711: } else {
14712: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14713: }
1.267 raeburn 14714: }
14715: }
14716: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
14717: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
14718: }
14719: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
14720: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
14721: }
1.323 raeburn 14722: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
14723: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
14724: } else {
14725: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
14726: }
1.296 raeburn 14727: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 14728: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
14729: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 14730: if (($item eq 'width') || ($item eq 'height')) {
14731: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
14732: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14733: }
14734: } else {
14735: if ($env{'form.ltitools_add_'.$item} ne '') {
14736: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14737: }
1.267 raeburn 14738: }
14739: }
14740: if ($env{'form.ltitools_add_target'} eq 'window') {
14741: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 14742: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
14743: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 14744: } else {
14745: $confhash{$newid}{'display'}{'target'} = 'iframe';
14746: }
14747: foreach my $item ('passback','roster') {
1.319 raeburn 14748: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 14749: $confhash{$newid}{$item} = 1;
1.319 raeburn 14750: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
14751: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
14752: $lifetime =~ s/^\s+|\s+$//g;
14753: if ($lifetime =~ /^\d+\.?\d*$/) {
14754: $confhash{$newid}{$item.'valid'} = $lifetime;
14755: }
14756: }
1.267 raeburn 14757: }
14758: }
14759: if ($env{'form.ltitools_add_image.filename'} ne '') {
14760: my ($imageurl,$error) =
1.307 raeburn 14761: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 14762: $configuserok,$switchserver,$author_ok);
14763: if ($imageurl) {
14764: $confhash{$newid}{'image'} = $imageurl;
14765: }
14766: if ($error) {
14767: &Apache::lonnet::logthis($error);
14768: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14769: }
14770: }
14771: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
14772: foreach my $field (@fields) {
14773: if ($possfield{$field}) {
14774: if ($field eq 'roles') {
14775: foreach my $role (@courseroles) {
14776: my $choice = $env{'form.ltitools_add_roles_'.$role};
14777: if (($choice ne '') && ($posslti{$choice})) {
14778: $confhash{$newid}{'roles'}{$role} = $choice;
14779: if ($role eq 'cc') {
14780: $confhash{$newid}{'roles'}{'co'} = $choice;
14781: }
14782: }
14783: }
14784: } else {
14785: $confhash{$newid}{'fields'}{$field} = 1;
14786: }
14787: }
14788: }
1.324 raeburn 14789: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
14790: if ($confhash{$newid}{'fields'}{'user'}) {
14791: if ($env{'form.ltitools_userincdom_add'}) {
14792: $confhash{$newid}{'incdom'} = 1;
14793: }
14794: }
14795: }
1.273 raeburn 14796: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
14797: foreach my $item (@courseconfig) {
14798: $confhash{$newid}{'crsconf'}{$item} = 1;
14799: }
1.267 raeburn 14800: if ($env{'form.ltitools_add_custom'}) {
14801: my $name = $env{'form.ltitools_add_custom_name'};
14802: my $value = $env{'form.ltitools_add_custom_value'};
14803: $value =~ s/(`)/'/g;
14804: $name =~ s/(`)/'/g;
14805: $confhash{$newid}{'custom'}{$name} = $value;
14806: }
14807: } else {
14808: my $error = &mt('Failed to acquire unique ID for new external tool');
14809: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14810: }
14811: }
14812: if (ref($domconfig{$action}) eq 'HASH') {
14813: my %deletions;
14814: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
14815: if (@todelete) {
14816: map { $deletions{$_} = 1; } @todelete;
14817: }
14818: my %customadds;
14819: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
14820: if (@newcustom) {
14821: map { $customadds{$_} = 1; } @newcustom;
14822: }
14823: my %imgdeletions;
14824: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
14825: if (@todeleteimages) {
14826: map { $imgdeletions{$_} = 1; } @todeleteimages;
14827: }
14828: my $maxnum = $env{'form.ltitools_maxnum'};
14829: for (my $i=0; $i<=$maxnum; $i++) {
14830: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 14831: $itemid =~ s/\D+//g;
1.267 raeburn 14832: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14833: if ($deletions{$itemid}) {
14834: if ($domconfig{$action}{$itemid}{'image'}) {
14835: #FIXME need to obsolete item in RES space
14836: }
14837: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
14838: next;
14839: } else {
14840: my $newpos = $env{'form.ltitools_'.$itemid};
14841: $newpos =~ s/\D+//g;
1.322 raeburn 14842: foreach my $item ('title','url','lifetime') {
1.267 raeburn 14843: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14844: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14845: $changes{$itemid} = 1;
14846: }
14847: }
1.297 raeburn 14848: foreach my $item ('key','secret') {
14849: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14850: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
14851: $changes{$itemid} = 1;
14852: }
14853: }
1.267 raeburn 14854: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
14855: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
14856: }
14857: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
14858: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
14859: }
1.323 raeburn 14860: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
14861: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
14862: } else {
14863: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
14864: }
14865: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
14866: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
14867: $changes{$itemid} = 1;
14868: }
14869: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
14870: $changes{$itemid} = 1;
14871: }
1.267 raeburn 14872: foreach my $size ('width','height') {
14873: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
14874: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
14875: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
14876: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
14877: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14878: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
14879: $changes{$itemid} = 1;
14880: }
14881: } else {
14882: $changes{$itemid} = 1;
14883: }
1.296 raeburn 14884: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14885: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
14886: $changes{$itemid} = 1;
14887: }
14888: }
14889: }
14890: foreach my $item ('linktext','explanation') {
14891: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
14892: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
14893: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
14894: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14895: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14896: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
14897: $changes{$itemid} = 1;
14898: }
14899: } else {
14900: $changes{$itemid} = 1;
14901: }
14902: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14903: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
14904: $changes{$itemid} = 1;
14905: }
1.267 raeburn 14906: }
14907: }
14908: if ($env{'form.ltitools_target_'.$i} eq 'window') {
14909: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 14910: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
14911: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 14912: } else {
14913: $confhash{$itemid}{'display'}{'target'} = 'iframe';
14914: }
14915: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14916: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
14917: $changes{$itemid} = 1;
14918: }
14919: } else {
14920: $changes{$itemid} = 1;
14921: }
14922: foreach my $extra ('passback','roster') {
14923: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
14924: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 14925: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 14926: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 14927: $lifetime =~ s/^\s+|\s+$//g;
14928: if ($lifetime =~ /^\d+\.?\d*$/) {
14929: $confhash{$itemid}{$extra.'valid'} = $lifetime;
14930: }
14931: }
1.267 raeburn 14932: }
14933: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
14934: $changes{$itemid} = 1;
14935: }
1.319 raeburn 14936: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
14937: $changes{$itemid} = 1;
14938: }
1.267 raeburn 14939: }
1.273 raeburn 14940: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 14941: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 14942: if (grep(/^\Q$item\E$/,@courseconfig)) {
14943: $confhash{$itemid}{'crsconf'}{$item} = 1;
14944: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
14945: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
14946: $changes{$itemid} = 1;
14947: }
14948: } else {
14949: $changes{$itemid} = 1;
14950: }
14951: }
14952: }
1.267 raeburn 14953: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
14954: foreach my $field (@fields) {
14955: if ($possfield{$field}) {
14956: if ($field eq 'roles') {
14957: foreach my $role (@courseroles) {
14958: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
14959: if (($choice ne '') && ($posslti{$choice})) {
14960: $confhash{$itemid}{'roles'}{$role} = $choice;
14961: if ($role eq 'cc') {
14962: $confhash{$itemid}{'roles'}{'co'} = $choice;
14963: }
14964: }
14965: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
14966: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
14967: $changes{$itemid} = 1;
14968: }
14969: } elsif ($confhash{$itemid}{'roles'}{$role}) {
14970: $changes{$itemid} = 1;
14971: }
14972: }
14973: } else {
14974: $confhash{$itemid}{'fields'}{$field} = 1;
14975: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
14976: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
14977: $changes{$itemid} = 1;
14978: }
14979: } else {
14980: $changes{$itemid} = 1;
14981: }
14982: }
14983: }
14984: }
1.324 raeburn 14985: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14986: if ($confhash{$itemid}{'fields'}{'user'}) {
14987: if ($env{'form.ltitools_userincdom_'.$i}) {
14988: $confhash{$itemid}{'incdom'} = 1;
14989: }
14990: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
14991: $changes{$itemid} = 1;
14992: }
14993: }
14994: }
1.267 raeburn 14995: $allpos[$newpos] = $itemid;
14996: }
14997: if ($imgdeletions{$itemid}) {
14998: $changes{$itemid} = 1;
14999: #FIXME need to obsolete item in RES space
15000: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
15001: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
15002: $itemid,$configuserok,$switchserver,
15003: $author_ok);
15004: if ($imgurl) {
15005: $confhash{$itemid}{'image'} = $imgurl;
15006: $changes{$itemid} = 1;
15007: }
15008: if ($error) {
15009: &Apache::lonnet::logthis($error);
15010: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15011: }
15012: } elsif ($domconfig{$action}{$itemid}{'image'}) {
15013: $confhash{$itemid}{'image'} =
15014: $domconfig{$action}{$itemid}{'image'};
15015: }
15016: if ($customadds{$i}) {
15017: my $name = $env{'form.ltitools_custom_name_'.$i};
15018: $name =~ s/(`)/'/g;
15019: $name =~ s/^\s+//;
15020: $name =~ s/\s+$//;
15021: my $value = $env{'form.ltitools_custom_value_'.$i};
15022: $value =~ s/(`)/'/g;
15023: $value =~ s/^\s+//;
15024: $value =~ s/\s+$//;
15025: if ($name ne '') {
15026: $confhash{$itemid}{'custom'}{$name} = $value;
15027: $changes{$itemid} = 1;
15028: }
15029: }
15030: my %customdels;
15031: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
15032: if (@customdeletions) {
15033: $changes{$itemid} = 1;
15034: }
15035: map { $customdels{$_} = 1; } @customdeletions;
15036: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
15037: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
15038: unless ($customdels{$key}) {
15039: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
15040: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
15041: }
15042: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
15043: $changes{$itemid} = 1;
15044: }
15045: }
15046: }
15047: }
15048: unless ($changes{$itemid}) {
15049: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
15050: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
15051: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
15052: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
15053: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
15054: $changes{$itemid} = 1;
15055: last;
15056: }
15057: }
15058: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
15059: $changes{$itemid} = 1;
15060: }
15061: }
15062: last if ($changes{$itemid});
15063: }
15064: }
15065: }
15066: }
15067: }
15068: if (@allpos > 0) {
15069: my $idx = 0;
15070: foreach my $itemid (@allpos) {
15071: if ($itemid ne '') {
15072: $confhash{$itemid}{'order'} = $idx;
15073: if (ref($domconfig{$action}) eq 'HASH') {
15074: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15075: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15076: $changes{$itemid} = 1;
15077: }
15078: }
15079: }
15080: $idx ++;
15081: }
15082: }
15083: }
15084: my %ltitoolshash = (
15085: $action => { %confhash }
15086: );
15087: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
15088: $dom);
15089: if ($putresult eq 'ok') {
1.297 raeburn 15090: my %ltienchash = (
15091: $action => { %encconfig }
15092: );
1.384 raeburn 15093: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 15094: if (keys(%changes) > 0) {
15095: my $cachetime = 24*60*60;
1.297 raeburn 15096: my %ltiall = %confhash;
15097: foreach my $id (keys(%ltiall)) {
15098: if (ref($encconfig{$id}) eq 'HASH') {
15099: foreach my $item ('key','secret') {
15100: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15101: }
15102: }
15103: }
15104: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 15105: if (ref($lastactref) eq 'HASH') {
15106: $lastactref->{'ltitools'} = 1;
15107: }
15108: $resulttext = &mt('Changes made:').'<ul>';
15109: my %bynum;
15110: foreach my $itemid (sort(keys(%changes))) {
15111: my $position = $confhash{$itemid}{'order'};
15112: $bynum{$position} = $itemid;
15113: }
15114: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15115: my $itemid = $bynum{$pos};
15116: if (ref($confhash{$itemid}) ne 'HASH') {
15117: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15118: } else {
15119: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
15120: if ($confhash{$itemid}{'image'}) {
15121: $resulttext .= ' '.
15122: '<img src="'.$confhash{$itemid}{'image'}.'"'.
15123: ' alt="'.&mt('Tool Provider icon').'" />';
15124: }
15125: $resulttext .= '</li><ul>';
15126: my $position = $pos + 1;
15127: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 15128: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 15129: if ($confhash{$itemid}{$item} ne '') {
15130: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15131: }
15132: }
1.297 raeburn 15133: if ($encconfig{$itemid}{'key'} ne '') {
15134: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15135: }
15136: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 15137: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 15138: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 15139: $resulttext .= ('*'x$num).'</li>';
15140: }
1.273 raeburn 15141: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 15142: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 15143: my $numconfig = 0;
15144: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
15145: foreach my $item (@possconfig) {
15146: if ($confhash{$itemid}{'crsconf'}{$item}) {
15147: $numconfig ++;
1.296 raeburn 15148: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 15149: }
15150: }
15151: }
15152: if (!$numconfig) {
1.372 raeburn 15153: $resulttext .= ' '.&mt('None');
1.273 raeburn 15154: }
15155: $resulttext .= '</li>';
1.267 raeburn 15156: foreach my $item ('passback','roster') {
15157: $resulttext .= '<li>'.$lt{$item}.' ';
15158: if ($confhash{$itemid}{$item}) {
15159: $resulttext .= &mt('Yes');
1.319 raeburn 15160: if ($confhash{$itemid}{$item.'valid'}) {
15161: if ($item eq 'passback') {
15162: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
15163: $confhash{$itemid}{$item.'valid'});
15164: } else {
15165: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
15166: $confhash{$itemid}{$item.'valid'});
15167: }
15168: }
1.267 raeburn 15169: } else {
15170: $resulttext .= &mt('No');
15171: }
15172: $resulttext .= '</li>';
15173: }
15174: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
15175: my $displaylist;
15176: if ($confhash{$itemid}{'display'}{'target'}) {
15177: $displaylist = &mt('Display target').': '.
15178: $confhash{$itemid}{'display'}{'target'}.',';
15179: }
15180: foreach my $size ('width','height') {
15181: if ($confhash{$itemid}{'display'}{$size}) {
15182: $displaylist .= (' 'x2).$lt{$size}.': '.
15183: $confhash{$itemid}{'display'}{$size}.',';
15184: }
15185: }
15186: if ($displaylist) {
15187: $displaylist =~ s/,$//;
15188: $resulttext .= '<li>'.$displaylist.'</li>';
15189: }
1.296 raeburn 15190: foreach my $item ('linktext','explanation') {
15191: if ($confhash{$itemid}{'display'}{$item}) {
15192: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
15193: }
15194: }
15195: }
1.267 raeburn 15196: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
15197: my $fieldlist;
15198: foreach my $field (@allfields) {
15199: if ($confhash{$itemid}{'fields'}{$field}) {
15200: $fieldlist .= (' 'x2).$lt{$field}.',';
15201: }
15202: }
15203: if ($fieldlist) {
15204: $fieldlist =~ s/,$//;
1.324 raeburn 15205: if ($confhash{$itemid}{'fields'}{'user'}) {
15206: if ($confhash{$itemid}{'incdom'}) {
15207: $fieldlist .= ' ('.&mt('username:domain').')';
15208: } else {
15209: $fieldlist .= ' ('.&mt('username').')';
15210: }
15211: }
1.267 raeburn 15212: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
15213: }
15214: }
15215: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
15216: my $rolemaps;
15217: foreach my $role (@courseroles) {
15218: if ($confhash{$itemid}{'roles'}{$role}) {
15219: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15220: $confhash{$itemid}{'roles'}{$role}.',';
15221: }
15222: }
15223: if ($rolemaps) {
15224: $rolemaps =~ s/,$//;
15225: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15226: }
15227: }
15228: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
15229: my $customlist;
15230: if (keys(%{$confhash{$itemid}{'custom'}})) {
15231: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
15232: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
15233: }
15234: }
15235: if ($customlist) {
1.317 raeburn 15236: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 15237: }
15238: }
15239: $resulttext .= '</ul></li>';
15240: }
15241: }
15242: $resulttext .= '</ul>';
15243: } else {
15244: $resulttext = &mt('No changes made.');
15245: }
15246: } else {
15247: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15248: }
15249: if ($errors) {
15250: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15251: $errors.'</ul>';
15252: }
15253: return $resulttext;
15254: }
15255:
15256: sub process_ltitools_image {
15257: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
15258: my $filename = $env{'form.'.$caller.'.filename'};
15259: my ($error,$url);
15260: my ($width,$height) = (21,21);
15261: if ($configuserok eq 'ok') {
15262: if ($switchserver) {
15263: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
15264: $switchserver);
15265: } elsif ($author_ok eq 'ok') {
15266: my ($result,$imageurl,$madethumb) =
15267: &publishlogo($r,'upload',$caller,$dom,$confname,
15268: "ltitools/$itemid/icon",$width,$height);
15269: if ($result eq 'ok') {
15270: if ($madethumb) {
15271: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15272: my $imagethumb = "$path/tn-".$imagefile;
15273: $url = $imagethumb;
15274: } else {
15275: $url = $imageurl;
15276: }
15277: } else {
15278: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15279: }
15280: } else {
15281: $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);
15282: }
15283: } else {
15284: $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);
15285: }
15286: return ($url,$error);
15287: }
15288:
15289: sub get_ltitools_id {
15290: my ($cdom,$title) = @_;
15291: # get lock on ltitools db
15292: my $lockhash = {
15293: lock => $env{'user.name'}.
15294: ':'.$env{'user.domain'},
15295: };
15296: my $tries = 0;
15297: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
15298: my ($id,$error);
15299:
15300: while (($gotlock ne 'ok') && ($tries<10)) {
15301: $tries ++;
15302: sleep (0.1);
15303: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
15304: }
15305: if ($gotlock eq 'ok') {
15306: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
15307: if ($currids{'lock'}) {
15308: delete($currids{'lock'});
15309: if (keys(%currids)) {
15310: my @curr = sort { $a <=> $b } keys(%currids);
15311: if ($curr[-1] =~ /^\d+$/) {
15312: $id = 1 + $curr[-1];
15313: }
15314: } else {
15315: $id = 1;
15316: }
15317: if ($id) {
15318: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
15319: $error = 'nostore';
15320: }
15321: } else {
15322: $error = 'nonumber';
15323: }
15324: }
15325: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
15326: } else {
15327: $error = 'nolock';
15328: }
15329: return ($id,$error);
15330: }
15331:
1.372 raeburn 15332: sub modify_proctoring {
15333: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15334: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15335: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15336: my $confname = $dom.'-domainconfig';
15337: my $servadm = $r->dir_config('lonAdmEMail');
15338: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15339: my %providernames = &proctoring_providernames();
15340: my $maxnum = scalar(keys(%providernames));
15341:
15342: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15343: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15344: if (ref($requref) eq 'HASH') {
15345: %requserfields = %{$requref};
15346: }
15347: if (ref($opturef) eq 'HASH') {
15348: %optuserfields = %{$opturef};
15349: }
15350: if (ref($defref) eq 'HASH') {
15351: %defaults = %{$defref};
15352: }
15353: if (ref($extref) eq 'HASH') {
15354: %extended = %{$extref};
15355: }
15356: if (ref($crsref) eq 'HASH') {
15357: %crsconf = %{$crsref};
15358: }
15359: if (ref($rolesref) eq 'ARRAY') {
15360: @courseroles = @{$rolesref};
15361: }
15362: if (ref($ltiref) eq 'ARRAY') {
15363: @ltiroles = @{$ltiref};
15364: }
15365:
15366: if (ref($domconfig{$action}) eq 'HASH') {
15367: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15368: if (@todeleteimages) {
15369: map { $imgdeletions{$_} = 1; } @todeleteimages;
15370: }
15371: }
15372: my %customadds;
15373: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15374: if (@newcustom) {
15375: map { $customadds{$_} = 1; } @newcustom;
15376: }
15377: foreach my $provider (sort(keys(%providernames))) {
15378: $confhash{$provider} = {};
15379: my $pos = $env{'form.proctoring_pos_'.$provider};
15380: $pos =~ s/\D+//g;
15381: $allpos[$pos] = $provider;
15382: my (%current,%currentenc);
15383: my $showroles = 0;
15384: if (ref($domconfig{$action}) eq 'HASH') {
15385: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15386: %current = %{$domconfig{$action}{$provider}};
15387: foreach my $item ('key','secret') {
15388: $currentenc{$item} = $current{$item};
15389: delete($current{$item});
15390: }
15391: }
15392: }
15393: if ($env{'form.proctoring_available_'.$provider}) {
15394: $confhash{$provider}{'available'} = 1;
15395: unless ($current{'available'}) {
15396: $changes{$provider} = 1;
15397: }
15398: } else {
15399: %{$confhash{$provider}} = %current;
15400: %{$encconfhash{$provider}} = %currentenc;
15401: $confhash{$provider}{'available'} = 0;
15402: if ($current{'available'}) {
15403: $changes{$provider} = 1;
15404: }
15405: }
15406: if ($confhash{$provider}{'available'}) {
15407: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15408: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15409: if ($field eq 'lifetime') {
15410: if ($possval =~ /^\d+$/) {
15411: $confhash{$provider}{$field} = $possval;
15412: }
15413: } elsif ($field eq 'version') {
15414: if ($possval =~ /^\d+\.\d+$/) {
15415: $confhash{$provider}{$field} = $possval;
15416: }
15417: } elsif ($field eq 'sigmethod') {
15418: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15419: $confhash{$provider}{$field} = $possval;
15420: }
15421: } elsif ($field eq 'url') {
15422: $confhash{$provider}{$field} = $possval;
15423: } elsif (($field eq 'key') || ($field eq 'secret')) {
15424: $encconfhash{$provider}{$field} = $possval;
15425: unless ($currentenc{$field} eq $possval) {
15426: $changes{$provider} = 1;
15427: }
15428: }
15429: unless (($field eq 'key') || ($field eq 'secret')) {
15430: unless ($current{$field} eq $confhash{$provider}{$field}) {
15431: $changes{$provider} = 1;
15432: }
15433: }
15434: }
15435: if ($imgdeletions{$provider}) {
15436: $changes{$provider} = 1;
15437: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15438: my ($imageurl,$error) =
15439: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15440: $configuserok,$switchserver,$author_ok);
15441: if ($imageurl) {
15442: $confhash{$provider}{'image'} = $imageurl;
15443: $changes{$provider} = 1;
15444: }
15445: if ($error) {
15446: &Apache::lonnet::logthis($error);
15447: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15448: }
15449: } elsif (exists($current{'image'})) {
15450: $confhash{$provider}{'image'} = $current{'image'};
15451: }
15452: if (ref($requserfields{$provider}) eq 'ARRAY') {
15453: if (@{$requserfields{$provider}} > 0) {
15454: if (grep(/^user$/,@{$requserfields{$provider}})) {
15455: if ($env{'form.proctoring_userincdom_'.$provider}) {
15456: $confhash{$provider}{'incdom'} = 1;
15457: }
15458: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15459: $changes{$provider} = 1;
15460: }
15461: }
15462: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15463: $showroles = 1;
15464: }
15465: }
15466: }
15467: $confhash{$provider}{'fields'} = [];
15468: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15469: if (@{$optuserfields{$provider}} > 0) {
15470: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15471: foreach my $field (@{$optuserfields{$provider}}) {
15472: if (grep(/^\Q$field\E$/,@optfields)) {
15473: push(@{$confhash{$provider}{'fields'}},$field);
15474: }
15475: }
15476: }
15477: if (ref($current{'fields'}) eq 'ARRAY') {
15478: unless ($changes{$provider}) {
15479: my @new = sort(@{$confhash{$provider}{'fields'}});
15480: my @old = sort(@{$current{'fields'}});
15481: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15482: if (@diffs) {
15483: $changes{$provider} = 1;
15484: }
15485: }
15486: } elsif (@{$confhash{$provider}{'fields'}}) {
15487: $changes{$provider} = 1;
15488: }
15489: }
15490: if (ref($defaults{$provider}) eq 'ARRAY') {
15491: if (@{$defaults{$provider}} > 0) {
15492: my %options;
15493: if (ref($extended{$provider}) eq 'HASH') {
15494: %options = %{$extended{$provider}};
15495: }
15496: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15497: foreach my $field (@{$defaults{$provider}}) {
15498: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15499: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15500: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15501: push(@{$confhash{$provider}{'defaults'}},$poss);
15502: }
15503: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15504: foreach my $inner (keys(%{$options{$field}})) {
15505: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15506: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15507: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15508: $confhash{$provider}{'defaults'}{$inner} = $poss;
15509: }
15510: } else {
15511: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15512: }
15513: }
15514: } else {
15515: if (grep(/^\Q$field\E$/,@checked)) {
15516: push(@{$confhash{$provider}{'defaults'}},$field);
15517: }
15518: }
15519: }
15520: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15521: if (ref($current{'defaults'}) eq 'ARRAY') {
15522: unless ($changes{$provider}) {
15523: my @new = sort(@{$confhash{$provider}{'defaults'}});
15524: my @old = sort(@{$current{'defaults'}});
15525: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15526: if (@diffs) {
15527: $changes{$provider} = 1;
15528: }
15529: }
15530: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15531: if (@{$current{'defaults'}}) {
15532: $changes{$provider} = 1;
15533: }
15534: }
15535: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15536: if (ref($current{'defaults'}) eq 'HASH') {
15537: unless ($changes{$provider}) {
15538: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15539: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15540: $changes{$provider} = 1;
15541: last;
15542: }
15543: }
15544: }
15545: unless ($changes{$provider}) {
15546: foreach my $key (keys(%{$current{'defaults'}})) {
15547: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15548: $changes{$provider} = 1;
15549: last;
15550: }
15551: }
15552: }
15553: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15554: $changes{$provider} = 1;
15555: }
15556: }
15557: }
15558: }
15559: if (ref($crsconf{$provider}) eq 'ARRAY') {
15560: if (@{$crsconf{$provider}} > 0) {
15561: $confhash{$provider}{'crsconf'} = [];
15562: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15563: foreach my $crsfield (@{$crsconf{$provider}}) {
15564: if (grep(/^\Q$crsfield\E$/,@checked)) {
15565: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15566: }
15567: }
15568: if (ref($current{'crsconf'}) eq 'ARRAY') {
15569: unless ($changes{$provider}) {
15570: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15571: my @old = sort(@{$current{'crsconf'}});
15572: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15573: if (@diffs) {
15574: $changes{$provider} = 1;
15575: }
15576: }
15577: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15578: $changes{$provider} = 1;
15579: }
15580: }
15581: }
15582: if ($showroles) {
15583: $confhash{$provider}{'roles'} = {};
15584: foreach my $role (@courseroles) {
15585: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15586: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15587: $confhash{$provider}{'roles'}{$role} = $poss;
15588: }
15589: }
15590: unless ($changes{$provider}) {
15591: if (ref($current{'roles'}) eq 'HASH') {
15592: foreach my $role (keys(%{$current{'roles'}})) {
15593: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15594: $changes{$provider} = 1;
15595: last
15596: }
15597: }
15598: unless ($changes{$provider}) {
15599: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15600: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15601: $changes{$provider} = 1;
15602: last;
15603: }
15604: }
15605: }
15606: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15607: $changes{$provider} = 1;
15608: }
15609: }
15610: }
15611: if (ref($current{'custom'}) eq 'HASH') {
15612: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15613: foreach my $key (keys(%{$current{'custom'}})) {
15614: if (grep(/^\Q$key\E$/,@customdels)) {
15615: $changes{$provider} = 1;
15616: } else {
15617: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15618: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15619: $changes{$provider} = 1;
15620: }
15621: }
15622: }
15623: }
15624: if ($customadds{$provider}) {
15625: my $name = $env{'form.proctoring_custom_name_'.$provider};
15626: $name =~ s/(`)/'/g;
15627: $name =~ s/^\s+//;
15628: $name =~ s/\s+$//;
15629: my $value = $env{'form.proctoring_custom_value_'.$provider};
15630: $value =~ s/(`)/'/g;
15631: $value =~ s/^\s+//;
15632: $value =~ s/\s+$//;
15633: if ($name ne '') {
15634: $confhash{$provider}{'custom'}{$name} = $value;
15635: $changes{$provider} = 1;
15636: }
15637: }
15638: }
15639: }
15640: if (@allpos > 0) {
15641: my $idx = 0;
15642: foreach my $provider (@allpos) {
15643: if ($provider ne '') {
15644: $confhash{$provider}{'order'} = $idx;
15645: unless ($changes{$provider}) {
15646: if (ref($domconfig{$action}) eq 'HASH') {
15647: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15648: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15649: $changes{$provider} = 1;
15650: }
15651: }
15652: }
15653: }
15654: $idx ++;
15655: }
15656: }
15657: }
15658: my %proc_hash = (
15659: $action => { %confhash }
15660: );
15661: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15662: $dom);
15663: if ($putresult eq 'ok') {
15664: my %proc_enchash = (
15665: $action => { %encconfhash }
15666: );
1.384 raeburn 15667: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15668: if (keys(%changes) > 0) {
15669: my $cachetime = 24*60*60;
15670: my %procall = %confhash;
15671: foreach my $provider (keys(%procall)) {
15672: if (ref($encconfhash{$provider}) eq 'HASH') {
15673: foreach my $key ('key','secret') {
15674: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15675: }
15676: }
15677: }
15678: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15679: if (ref($lastactref) eq 'HASH') {
15680: $lastactref->{'proctoring'} = 1;
15681: }
15682: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15683: my %bynum;
15684: foreach my $provider (sort(keys(%changes))) {
15685: my $position = $confhash{$provider}{'order'};
15686: $bynum{$position} = $provider;
15687: }
15688: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15689: my $provider = $bynum{$pos};
15690: my %lt = &proctoring_titles($provider);
15691: my %fieldtitles = &proctoring_fieldtitles($provider);
15692: if (!$confhash{$provider}{'available'}) {
15693: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15694: } else {
15695: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15696: if ($confhash{$provider}{'image'}) {
15697: $resulttext .= ' '.
15698: '<img src="'.$confhash{$provider}{'image'}.'"'.
15699: ' alt="'.&mt('Proctoring icon').'" />';
15700: }
15701: $resulttext .= '<ul>';
15702: my $position = $pos + 1;
15703: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15704: foreach my $key ('version','sigmethod','url','lifetime') {
15705: if ($confhash{$provider}{$key} ne '') {
15706: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15707: }
15708: }
15709: if ($encconfhash{$provider}{'key'} ne '') {
15710: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15711: }
15712: if ($encconfhash{$provider}{'secret'} ne '') {
15713: $resulttext .= '<li>'.$lt{'secret'}.': ';
15714: my $num = length($encconfhash{$provider}{'secret'});
15715: $resulttext .= ('*'x$num).'</li>';
15716: }
15717: my (@fields,$showroles);
15718: if (ref($requserfields{$provider}) eq 'ARRAY') {
15719: push(@fields,@{$requserfields{$provider}});
15720: }
15721: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15722: push(@fields,@{$confhash{$provider}{'fields'}});
15723: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15724: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15725: }
15726: if (@fields) {
15727: if (grep(/^roles$/,@fields)) {
15728: $showroles = 1;
15729: }
15730: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15731: join('", "', map { $lt{$_}; } @fields).'"</li>';
15732: }
15733: if (ref($requserfields{$provider}) eq 'ARRAY') {
15734: if (grep(/^user$/,@{$requserfields{$provider}})) {
15735: if ($confhash{$provider}{'incdom'}) {
15736: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15737: } else {
15738: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15739: }
15740: }
15741: }
15742: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15743: if (@{$confhash{$provider}{'defaults'}} > 0) {
15744: $resulttext .= '<li>'.$lt{'defa'};
15745: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15746: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15747: }
15748: $resulttext =~ s/,$//;
15749: $resulttext .= '</li>';
15750: }
15751: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15752: if (keys(%{$confhash{$provider}{'defaults'}})) {
15753: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15754: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15755: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15756: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15757: }
15758: }
15759: $resulttext .= '</ul></li>';
15760: }
15761: }
15762: if (ref($crsconf{$provider}) eq 'ARRAY') {
15763: if (@{$crsconf{$provider}} > 0) {
15764: $resulttext .= '<li>'.&mt('Configurable in course:');
15765: my $numconfig = 0;
15766: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15767: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15768: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15769: $numconfig ++;
15770: if ($provider eq 'examity') {
15771: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15772: } else {
15773: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15774: }
15775: }
15776: $resulttext =~ s/,$//;
15777: }
15778: }
15779: if (!$numconfig) {
15780: $resulttext .= ' '.&mt('None');
15781: }
15782: $resulttext .= '</li>';
15783: }
15784: }
15785: if ($showroles) {
15786: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15787: my $rolemaps;
15788: foreach my $role (@courseroles) {
15789: if ($confhash{$provider}{'roles'}{$role}) {
15790: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15791: $confhash{$provider}{'roles'}{$role}.',';
15792: }
15793: }
15794: if ($rolemaps) {
15795: $rolemaps =~ s/,$//;
15796: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15797: }
15798: }
15799: }
15800: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15801: my $customlist;
15802: if (keys(%{$confhash{$provider}{'custom'}})) {
15803: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15804: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15805: }
15806: $customlist =~ s/,$//;
15807: }
15808: if ($customlist) {
15809: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15810: }
15811: }
15812: $resulttext .= '</ul></li>';
15813: }
15814: }
15815: $resulttext .= '</ul>';
15816: } else {
15817: $resulttext = &mt('No changes made.');
15818: }
15819: } else {
15820: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15821: }
15822: if ($errors) {
15823: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15824: $errors.'</ul>';
15825: }
15826: return $resulttext;
15827: }
15828:
15829: sub process_proctoring_image {
15830: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15831: my $filename = $env{'form.'.$caller.'.filename'};
15832: my ($error,$url);
15833: my ($width,$height) = (21,21);
15834: if ($configuserok eq 'ok') {
15835: if ($switchserver) {
15836: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15837: $switchserver);
15838: } elsif ($author_ok eq 'ok') {
15839: my ($result,$imageurl,$madethumb) =
15840: &publishlogo($r,'upload',$caller,$dom,$confname,
15841: "proctoring/$provider/icon",$width,$height);
15842: if ($result eq 'ok') {
15843: if ($madethumb) {
15844: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15845: my $imagethumb = "$path/tn-".$imagefile;
15846: $url = $imagethumb;
15847: } else {
15848: $url = $imageurl;
15849: }
15850: } else {
15851: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15852: }
15853: } else {
15854: $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);
15855: }
15856: } else {
15857: $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);
15858: }
15859: return ($url,$error);
15860: }
15861:
1.320 raeburn 15862: sub modify_lti {
15863: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15864: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15865: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
15866: my (%posslti,%posslticrs,%posscrstype);
15867: my @courseroles = ('cc','in','ta','ep','st');
15868: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15869: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15870: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15871: my %coursetypetitles = &Apache::lonlocal::texthash (
15872: official => 'Official',
15873: unofficial => 'Unofficial',
15874: community => 'Community',
15875: textbook => 'Textbook',
15876: placement => 'Placement Test',
1.392 raeburn 15877: lti => 'LTI Provider',
1.320 raeburn 15878: );
1.325 raeburn 15879: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15880: my %lt = <i_names();
15881: map { $posslti{$_} = 1; } @ltiroles;
15882: map { $posslticrs{$_} = 1; } @lticourseroles;
15883: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15884:
1.326 raeburn 15885: my %menutitles = <imenu_titles();
15886:
1.406 raeburn 15887: my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
1.405 raeburn 15888: $newltisec{'private'}{'keys'} = [];
15889: $newltisec{'encrypt'} = {};
15890: $newltisec{'rules'} = {};
1.406 raeburn 15891: $newltisec{'linkprot'} = {};
1.405 raeburn 15892: if (ref($domconfig{'ltisec'}) eq 'HASH') {
15893: %currltisec = %{$domconfig{'ltisec'}};
1.406 raeburn 15894: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15895: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
15896: unless ($id =~ /^\d+$/) {
15897: delete($currltisec{'linkprot'}{$id});
15898: }
15899: }
15900: }
1.405 raeburn 15901: if (ref($currltisec{'private'}) eq 'HASH') {
15902: if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
15903: $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
15904: map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
15905: }
15906: }
15907: }
15908: foreach my $item ('crs','dom','consumers') {
15909: my $formelement;
15910: if ($item eq 'consumers') {
15911: $formelement = 'form.ltisec_'.$item;
15912: } else {
15913: $formelement = 'form.ltisec_'.$item.'linkprot';
15914: }
15915: if ($env{$formelement}) {
15916: $newltisec{'encrypt'}{$item} = 1;
15917: if (ref($currltisec{'encrypt'}) eq 'HASH') {
15918: unless ($currltisec{'encrypt'}{$item}) {
15919: $secchanges{'encrypt'} = 1;
15920: }
15921: } else {
15922: $secchanges{'encrypt'} = 1;
15923: }
15924: } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
15925: if ($currltisec{'encrypt'}{$item}) {
15926: $secchanges{'encrypt'} = 1;
15927: }
15928: }
15929: }
15930: unless (exists($currltisec{'rules'})) {
15931: $currltisec{'rules'} = {};
15932: }
15933: &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
15934:
15935: my @ids=&Apache::lonnet::current_machine_ids();
15936: my %servers = &Apache::lonnet::get_servers($dom,'library');
15937:
15938: foreach my $hostid (keys(%servers)) {
15939: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15940: my $newkey;
15941: my $keyitem = 'form.ltisec_privkey_'.$hostid;
15942: if (exists($env{$keyitem})) {
15943: $env{$keyitem} =~ s/(`)/'/g;
15944: if ($keyset{$hostid}) {
15945: if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
15946: if ($env{$keyitem} ne '') {
15947: $secchanges{'private'} = 1;
15948: $newkeyset{$hostid} = $env{$keyitem};
15949: }
15950: }
15951: } elsif ($env{$keyitem} ne '') {
15952: unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
15953: push(@{$newltisec{'private'}{'keys'}},$hostid);
15954: }
15955: $secchanges{'private'} = 1;
15956: $newkeyset{$hostid} = $env{$keyitem};
15957: }
15958: }
15959: }
15960: }
15961:
1.406 raeburn 15962: my (%linkprotchg,$linkprotoutput,$is_home);
15963: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15964: \%linkprotchg,'domain');
15965: my $home = &Apache::lonnet::domain($dom,'primary');
15966: unless (($home eq 'no_host') || ($home eq '')) {
15967: my @ids=&Apache::lonnet::current_machine_ids();
15968: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15969: }
15970:
15971: if (keys(%linkprotchg)) {
15972: $secchanges{'linkprot'} = 1;
15973: my %oldlinkprot;
15974: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15975: %oldlinkprot = %{$currltisec{'linkprot'}};
15976: }
15977: foreach my $id (keys(%linkprotchg)) {
15978: if (ref($linkprotchg{$id}) eq 'HASH') {
15979: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15980: if (($inner eq 'secret') || ($inner eq 'key')) {
15981: if ($is_home) {
15982: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15983: }
15984: }
15985: }
15986: } else {
15987: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15988: }
15989: }
15990: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15991: if (keys(%linkprotchg)) {
15992: %{$newltisec{'linkprot'}} = %linkprotchg;
15993: }
15994: }
15995: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15996: foreach my $id (%{$currltisec{'linkprot'}}) {
15997: next if ($id !~ /^\d+$/);
15998: unless (exists($linkprotchg{$id})) {
15999: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
16000: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
16001: if (($inner eq 'secret') || ($inner eq 'key')) {
16002: if ($is_home) {
16003: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
16004: }
16005: } else {
16006: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
16007: }
16008: }
16009: } else {
16010: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
16011: }
16012: }
16013: }
16014: }
16015: if ($proterror) {
16016: $errors .= '<li>'.$proterror.'</li>';
16017: }
1.320 raeburn 16018: my (@items,%deletions,%itemids);
16019: if ($env{'form.lti_add'}) {
16020: my $consumer = $env{'form.lti_consumer_add'};
16021: $consumer =~ s/(`)/'/g;
16022: ($newid,my $error) = &get_lti_id($dom,$consumer);
16023: if ($newid) {
16024: $itemids{'add'} = $newid;
16025: push(@items,'add');
16026: $changes{$newid} = 1;
16027: } else {
16028: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
16029: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16030: }
16031: }
16032: if (ref($domconfig{$action}) eq 'HASH') {
16033: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
16034: if (@todelete) {
16035: map { $deletions{$_} = 1; } @todelete;
16036: }
16037: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 16038: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 16039: my $itemid = $env{'form.lti_id_'.$i};
16040: $itemid =~ s/\D+//g;
16041: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16042: if ($deletions{$itemid}) {
16043: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16044: } else {
1.390 raeburn 16045: push(@items,$i);
16046: $itemids{$i} = $itemid;
1.320 raeburn 16047: }
16048: }
16049: }
16050: }
16051: foreach my $idx (@items) {
16052: my $itemid = $itemids{$idx};
16053: next unless ($itemid);
1.390 raeburn 16054: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16055: $position =~ s/\D+//g;
16056: if ($position ne '') {
16057: $allpos[$position] = $itemid;
16058: }
1.391 raeburn 16059: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 16060: my $formitem = 'form.lti_'.$item.'_'.$idx;
16061: $env{$formitem} =~ s/(`)/'/g;
16062: if ($item eq 'lifetime') {
16063: $env{$formitem} =~ s/[^\d.]//g;
16064: }
16065: if ($env{$formitem} ne '') {
16066: if (($item eq 'key') || ($item eq 'secret')) {
16067: $encconfig{$itemid}{$item} = $env{$formitem};
16068: } else {
16069: $confhash{$itemid}{$item} = $env{$formitem};
16070: unless (($idx eq 'add') || ($changes{$itemid})) {
16071: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
16072: $changes{$itemid} = 1;
16073: }
16074: }
16075: }
16076: }
16077: }
16078: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16079: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16080: }
1.345 raeburn 16081: if ($confhash{$itemid}{'requser'}) {
16082: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16083: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16084: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16085: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16086: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16087: my $mapuser = $env{'form.lti_customuser_'.$idx};
16088: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16089: $mapuser =~ s/^\s+|\s+$//g;
16090: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16091: }
16092: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16093: my @makeuser;
16094: foreach my $ltirole (sort(@possmakeuser)) {
16095: if ($posslti{$ltirole}) {
16096: push(@makeuser,$ltirole);
16097: }
16098: }
16099: $confhash{$itemid}{'makeuser'} = \@makeuser;
16100: if (@makeuser) {
16101: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16102: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16103: $confhash{$itemid}{'lcauth'} = $lcauth;
16104: if ($lcauth ne 'internal') {
16105: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16106: $lcauthparm =~ s/^(\s+|\s+)$//g;
16107: $lcauthparm =~ s/`//g;
16108: if ($lcauthparm ne '') {
16109: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16110: }
16111: }
16112: } else {
16113: $confhash{$itemid}{'lcauth'} = 'lti';
16114: }
1.320 raeburn 16115: }
1.345 raeburn 16116: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16117: if (@possinstdata) {
16118: foreach my $field (@possinstdata) {
16119: if (exists($fieldtitles{$field})) {
16120: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16121: }
16122: }
16123: }
1.363 raeburn 16124: if ($env{'form.lti_callback_'.$idx}) {
16125: if ($env{'form.lti_callbackparam_'.$idx}) {
16126: my $callback = $env{'form.lti_callbackparam_'.$idx};
16127: $callback =~ s/^\s+|\s+$//g;
16128: $confhash{$itemid}{'callback'} = $callback;
16129: }
16130: }
1.391 raeburn 16131: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16132: if ($env{'form.lti_'.$field.'_'.$idx}) {
16133: $confhash{$itemid}{$field} = 1;
16134: }
1.320 raeburn 16135: }
1.345 raeburn 16136: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16137: $confhash{$itemid}{lcmenu} = [];
16138: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16139: foreach my $field (@possmenu) {
16140: if (exists($menutitles{$field})) {
16141: if ($field eq 'grades') {
16142: next unless ($env{'form.lti_inlinemenu_'.$idx});
16143: }
16144: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16145: }
16146: }
16147: }
1.391 raeburn 16148: if ($confhash{$itemid}{'crsinc'}) {
16149: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16150: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16151: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16152: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16153: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16154: $mapcrs =~ s/(`)/'/g;
16155: $mapcrs =~ s/^\s+|\s+$//g;
16156: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16157: }
16158: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16159: my @crstypes;
16160: foreach my $type (sort(@posstypes)) {
16161: if ($posscrstype{$type}) {
16162: push(@crstypes,$type);
16163: }
16164: }
16165: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16166: if ($env{'form.lti_storecrs_'.$idx}) {
16167: $confhash{$itemid}{'storecrs'} = 1;
16168: }
1.391 raeburn 16169: if ($env{'form.lti_makecrs_'.$idx}) {
16170: $confhash{$itemid}{'makecrs'} = 1;
16171: }
16172: foreach my $ltirole (@lticourseroles) {
16173: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16174: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16175: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16176: }
16177: }
16178: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16179: my @selfenroll;
16180: foreach my $type (sort(@possenroll)) {
16181: if ($posslticrs{$type}) {
16182: push(@selfenroll,$type);
16183: }
16184: }
16185: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16186: if ($env{'form.lti_crssec_'.$idx}) {
16187: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16188: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16189: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16190: my $section = $env{'form.lti_customsection_'.$idx};
16191: $section =~ s/(`)/'/g;
16192: $section =~ s/^\s+|\s+$//g;
16193: if ($section ne '') {
16194: $confhash{$itemid}{'section'} = $section;
16195: }
16196: }
16197: }
16198: foreach my $field ('passback','roster') {
16199: if ($env{'form.lti_'.$field.'_'.$idx}) {
16200: $confhash{$itemid}{$field} = 1;
16201: }
16202: }
16203: if ($env{'form.lti_passback_'.$idx}) {
16204: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16205: $confhash{$itemid}{'passbackformat'} = '1.0';
16206: } else {
16207: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16208: }
16209: }
1.391 raeburn 16210: }
16211: unless (($idx eq 'add') || ($changes{$itemid})) {
16212: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16213: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 16214: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16215: $changes{$itemid} = 1;
16216: }
1.345 raeburn 16217: }
16218: unless ($changes{$itemid}) {
1.391 raeburn 16219: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
16220: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16221: $changes{$itemid} = 1;
16222: }
16223: }
1.345 raeburn 16224: }
1.391 raeburn 16225: foreach my $field ('mapcrstype','selfenroll') {
16226: unless ($changes{$itemid}) {
16227: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
16228: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16229: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
16230: $confhash{$itemid}{$field});
16231: if (@diffs) {
16232: $changes{$itemid} = 1;
16233: }
16234: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
16235: $changes{$itemid} = 1;
16236: }
16237: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16238: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16239: $changes{$itemid} = 1;
16240: }
16241: }
1.391 raeburn 16242: }
16243: }
16244: unless ($changes{$itemid}) {
16245: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
16246: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16247: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
16248: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
16249: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16250: $changes{$itemid} = 1;
16251: last;
16252: }
16253: }
1.391 raeburn 16254: unless ($changes{$itemid}) {
16255: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16256: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
16257: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
16258: $changes{$itemid} = 1;
16259: last;
16260: }
16261: }
16262: }
16263: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
16264: $changes{$itemid} = 1;
1.345 raeburn 16265: }
1.391 raeburn 16266: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16267: unless ($changes{$itemid}) {
16268: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16269: $changes{$itemid} = 1;
16270: }
16271: }
16272: }
16273: }
16274: }
16275: unless ($changes{$itemid}) {
16276: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
16277: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16278: $changes{$itemid} = 1;
1.320 raeburn 16279: }
1.391 raeburn 16280: }
16281: unless ($changes{$itemid}) {
16282: foreach my $field ('makeuser','lcmenu') {
16283: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
16284: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16285: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
16286: $confhash{$itemid}{$field});
16287: if (@diffs) {
16288: $changes{$itemid} = 1;
16289: }
16290: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
16291: $changes{$itemid} = 1;
16292: }
16293: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16294: if (@{$confhash{$itemid}{$field}} > 0) {
16295: $changes{$itemid} = 1;
16296: }
1.345 raeburn 16297: }
1.320 raeburn 16298: }
16299: }
16300: }
16301: }
16302: }
16303: }
16304: if (@allpos > 0) {
16305: my $idx = 0;
16306: foreach my $itemid (@allpos) {
16307: if ($itemid ne '') {
16308: $confhash{$itemid}{'order'} = $idx;
16309: if (ref($domconfig{$action}) eq 'HASH') {
16310: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16311: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16312: $changes{$itemid} = 1;
16313: }
16314: }
16315: }
16316: $idx ++;
16317: }
16318: }
16319: }
16320: my %ltihash = (
1.405 raeburn 16321: $action => { %confhash }
16322: );
1.406 raeburn 16323: my %ltienchash = (
16324: $action => { %encconfig }
16325: );
1.405 raeburn 16326: if (keys(%secchanges)) {
16327: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16328: if ($secchanges{'linkprot'}) {
16329: if ($is_home) {
16330: $ltienchash{'linkprot'} = \%newltienc;
16331: }
16332: }
1.405 raeburn 16333: }
16334: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16335: if ($putresult eq 'ok') {
1.405 raeburn 16336: my %keystore;
16337: if (keys(%secchanges)) {
16338: if ($secchanges{'private'}) {
16339: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
16340: foreach my $hostid (keys(%newkeyset)) {
16341: my $storehash = {
16342: key => $newkeyset{$hostid},
16343: who => $env{'user.name'}.':'.$env{'user.domain'},
16344: };
16345: $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
16346: $dom,$hostid);
16347: }
16348: }
1.407 raeburn 16349: if (ref($lastactref) eq 'HASH') {
16350: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
16351: $lastactref->{'domdefaults'} = 1;
16352: }
16353: }
1.405 raeburn 16354: }
1.384 raeburn 16355: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16356: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16357: return &mt('No changes made.');
16358: }
16359: $resulttext = &mt('Changes made:').'<ul>';
16360: if (keys(%secchanges) > 0) {
16361: foreach my $item (keys(%secchanges)) {
16362: if ($item eq 'encrypt') {
16363: my %encrypted = (
16364: crs => {
16365: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
16366: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
16367: },
16368: dom => {
16369: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
16370: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
16371: },
16372: consumers => {
16373: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
16374: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
16375: },
16376: );
16377: foreach my $type ('crs','dom','consumers') {
16378: my $shown = $encrypted{$type}{'off'};
16379: if (ref($newltisec{$item}) eq 'HASH') {
16380: if ($newltisec{$item}{$type}) {
16381: $shown = $encrypted{$type}{'on'};
16382: }
16383: }
16384: $resulttext .= '<li>'.$shown.'</li>';
16385: }
16386: } elsif ($item eq 'rules') {
16387: my %titles = &Apache::lonlocal::texthash(
16388: min => 'Minimum password length',
16389: max => 'Maximum password length',
16390: chars => 'Required characters',
16391: );
16392: foreach my $rule ('min','max') {
16393: if ($newltisec{rules}{$rule} eq '') {
16394: if ($rule eq 'min') {
16395: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
16396: ' '.&mt('Default of [_1] will be used',
16397: $Apache::lonnet::passwdmin).'</li>';
16398: } else {
16399: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
16400: }
16401: } else {
16402: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
16403: }
16404: }
16405: if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
16406: if (@{$newltisec{'rules'}{'chars'}} > 0) {
16407: my %rulenames = &Apache::lonlocal::texthash(
16408: uc => 'At least one upper case letter',
16409: lc => 'At least one lower case letter',
16410: num => 'At least one number',
16411: spec => 'At least one non-alphanumeric',
16412: );
16413: my $needed = '<ul><li>'.
16414: join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
16415: '</li></ul>';
16416: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16417: } else {
16418: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16419: }
16420: } else {
16421: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16422: }
16423: } elsif ($item eq 'private') {
16424: if (keys(%newkeyset)) {
16425: foreach my $hostid (sort(keys(%newkeyset))) {
16426: if ($keystore{$hostid} eq 'ok') {
16427: $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
16428: }
16429: }
16430: }
1.406 raeburn 16431: } elsif ($item eq 'linkprot') {
16432: $resulttext .= $linkprotoutput;
1.405 raeburn 16433: }
16434: }
16435: }
1.320 raeburn 16436: if (keys(%changes) > 0) {
16437: my $cachetime = 24*60*60;
16438: my %ltiall = %confhash;
16439: foreach my $id (keys(%ltiall)) {
16440: if (ref($encconfig{$id}) eq 'HASH') {
16441: foreach my $item ('key','secret') {
16442: $ltiall{$id}{$item} = $encconfig{$id}{$item};
16443: }
16444: }
16445: }
16446: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
16447: if (ref($lastactref) eq 'HASH') {
16448: $lastactref->{'lti'} = 1;
16449: }
16450: my %bynum;
16451: foreach my $itemid (sort(keys(%changes))) {
16452: my $position = $confhash{$itemid}{'order'};
16453: $bynum{$position} = $itemid;
16454: }
16455: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16456: my $itemid = $bynum{$pos};
16457: if (ref($confhash{$itemid}) ne 'HASH') {
16458: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16459: } else {
1.390 raeburn 16460: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16461: my $position = $pos + 1;
16462: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16463: foreach my $item ('version','lifetime') {
16464: if ($confhash{$itemid}{$item} ne '') {
16465: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16466: }
16467: }
16468: if ($encconfig{$itemid}{'key'} ne '') {
16469: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
16470: }
16471: if ($encconfig{$itemid}{'secret'} ne '') {
16472: $resulttext .= '<li>'.$lt{'secret'}.': ';
16473: my $num = length($encconfig{$itemid}{'secret'});
16474: $resulttext .= ('*'x$num).'</li>';
16475: }
1.345 raeburn 16476: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16477: if ($confhash{$itemid}{'callback'}) {
16478: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16479: } else {
1.392 raeburn 16480: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16481: }
1.345 raeburn 16482: if ($confhash{$itemid}{'mapuser'}) {
16483: my $shownmapuser;
16484: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16485: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16486: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16487: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16488: } else {
16489: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16490: }
1.345 raeburn 16491: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16492: }
1.345 raeburn 16493: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16494: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16495: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16496: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16497: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16498: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16499: } else {
16500: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16501: $confhash{$itemid}{'lcauth'});
16502: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16503: $resulttext .= '; '.&mt('a randomly generated password will be created');
16504: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16505: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16506: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16507: }
16508: } else {
16509: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16510: }
16511: }
16512: $resulttext .= '</li>';
16513: } else {
16514: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16515: }
1.320 raeburn 16516: }
1.345 raeburn 16517: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16518: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16519: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16520: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16521: } else {
1.345 raeburn 16522: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16523: }
1.320 raeburn 16524: }
1.391 raeburn 16525: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16526: $resulttext .= '<li>'.$lt{$item}.': ';
16527: if ($confhash{$itemid}{$item}) {
16528: $resulttext .= &mt('Yes');
16529: } else {
16530: $resulttext .= &mt('No');
1.337 raeburn 16531: }
1.345 raeburn 16532: $resulttext .= '</li>';
1.320 raeburn 16533: }
1.345 raeburn 16534: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16535: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16536: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16537: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16538: } else {
16539: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16540: }
16541: }
16542: if ($confhash{$itemid}{'crsinc'}) {
16543: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16544: my $rolemaps;
16545: foreach my $role (@ltiroles) {
16546: if ($confhash{$itemid}{'maproles'}{$role}) {
16547: $rolemaps .= (' 'x2).$role.'='.
16548: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16549: 'Course').',';
16550: }
16551: }
16552: if ($rolemaps) {
16553: $rolemaps =~ s/,$//;
16554: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16555: }
16556: }
16557: if ($confhash{$itemid}{'mapcrs'}) {
16558: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16559: }
16560: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16561: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16562: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16563: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16564: '</li>';
16565: } else {
16566: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16567: }
16568: }
1.392 raeburn 16569: if ($confhash{$itemid}{'storecrs'}) {
16570: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16571: }
1.391 raeburn 16572: if ($confhash{$itemid}{'makecrs'}) {
16573: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16574: } else {
16575: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16576: }
16577: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16578: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16579: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16580: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16581: '</li>';
16582: } else {
16583: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16584: }
16585: }
16586: if ($confhash{$itemid}{'section'}) {
16587: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16588: $resulttext .= '<li>'.&mt('User section from standard field:').
16589: ' (course_section_sourcedid)'.'</li>';
16590: } else {
16591: $resulttext .= '<li>'.&mt('User section from:').' '.
16592: $confhash{$itemid}{'section'}.'</li>';
16593: }
1.345 raeburn 16594: } else {
1.391 raeburn 16595: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16596: }
16597: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16598: $resulttext .= '<li>'.$lt{$item}.': ';
16599: if ($confhash{$itemid}{$item}) {
16600: $resulttext .= &mt('Yes');
16601: if ($item eq 'passback') {
16602: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16603: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16604: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16605: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16606: }
16607: }
16608: } else {
16609: $resulttext .= &mt('No');
16610: }
16611: $resulttext .= '</li>';
16612: }
16613: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16614: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16615: $resulttext .= '<li>'.&mt('Menu items:').' '.
16616: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16617: } else {
16618: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16619: }
1.345 raeburn 16620: }
1.326 raeburn 16621: }
16622: }
1.320 raeburn 16623: $resulttext .= '</ul></li>';
16624: }
16625: }
16626: }
1.405 raeburn 16627: $resulttext .= '</ul>';
1.320 raeburn 16628: } else {
16629: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16630: }
16631: if ($errors) {
16632: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16633: $errors.'</ul>';
16634: }
16635: return $resulttext;
16636: }
16637:
16638: sub get_lti_id {
16639: my ($domain,$consumer) = @_;
16640: # get lock on lti db
16641: my $lockhash = {
16642: lock => $env{'user.name'}.
16643: ':'.$env{'user.domain'},
16644: };
16645: my $tries = 0;
16646: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16647: my ($id,$error);
16648:
16649: while (($gotlock ne 'ok') && ($tries<10)) {
16650: $tries ++;
16651: sleep (0.1);
16652: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16653: }
16654: if ($gotlock eq 'ok') {
16655: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16656: if ($currids{'lock'}) {
16657: delete($currids{'lock'});
16658: if (keys(%currids)) {
16659: my @curr = sort { $a <=> $b } keys(%currids);
16660: if ($curr[-1] =~ /^\d+$/) {
16661: $id = 1 + $curr[-1];
16662: }
16663: } else {
16664: $id = 1;
16665: }
16666: if ($id) {
16667: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16668: $error = 'nostore';
16669: }
16670: } else {
16671: $error = 'nonumber';
16672: }
16673: }
16674: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16675: } else {
16676: $error = 'nolock';
16677: }
16678: return ($id,$error);
16679: }
16680:
1.3 raeburn 16681: sub modify_autoenroll {
1.205 raeburn 16682: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16683: my ($resulttext,%changes);
16684: my %currautoenroll;
16685: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16686: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16687: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16688: }
16689: }
16690: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16691: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16692: sender => 'Sender for notification messages',
1.274 raeburn 16693: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16694: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16695: my @offon = ('off','on');
1.17 raeburn 16696: my $sender_uname = $env{'form.sender_uname'};
16697: my $sender_domain = $env{'form.sender_domain'};
16698: if ($sender_domain eq '') {
16699: $sender_uname = '';
16700: } elsif ($sender_uname eq '') {
16701: $sender_domain = '';
16702: }
1.129 raeburn 16703: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16704: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16705: $autofailsafe =~ s{^\s+|\s+$}{}g;
16706: if ($autofailsafe =~ /\D/) {
16707: undef($autofailsafe);
16708: }
1.274 raeburn 16709: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16710: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16711: $failsafe = 'off';
1.400 raeburn 16712: undef($autofailsafe);
1.274 raeburn 16713: }
1.1 raeburn 16714: my %autoenrollhash = (
1.129 raeburn 16715: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16716: 'sender_uname' => $sender_uname,
16717: 'sender_domain' => $sender_domain,
16718: 'co-owners' => $coowners,
1.399 raeburn 16719: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16720: 'failsafe' => $failsafe,
1.1 raeburn 16721: }
16722: );
1.4 raeburn 16723: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16724: $dom);
1.1 raeburn 16725: if ($putresult eq 'ok') {
16726: if (exists($currautoenroll{'run'})) {
16727: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16728: $changes{'run'} = 1;
16729: }
16730: } elsif ($autorun) {
16731: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16732: $changes{'run'} = 1;
1.1 raeburn 16733: }
16734: }
1.17 raeburn 16735: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16736: $changes{'sender'} = 1;
16737: }
1.17 raeburn 16738: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16739: $changes{'sender'} = 1;
16740: }
1.129 raeburn 16741: if ($currautoenroll{'co-owners'} ne '') {
16742: if ($currautoenroll{'co-owners'} ne $coowners) {
16743: $changes{'coowners'} = 1;
16744: }
16745: } elsif ($coowners) {
16746: $changes{'coowners'} = 1;
1.274 raeburn 16747: }
1.399 raeburn 16748: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16749: $changes{'autofailsafe'} = 1;
16750: }
1.399 raeburn 16751: if ($currautoenroll{'failsafe'} ne $failsafe) {
16752: $changes{'failsafe'} = 1;
16753: }
1.1 raeburn 16754: if (keys(%changes) > 0) {
16755: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16756: if ($changes{'run'}) {
1.1 raeburn 16757: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16758: }
16759: if ($changes{'sender'}) {
1.17 raeburn 16760: if ($sender_uname eq '' || $sender_domain eq '') {
16761: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16762: } else {
16763: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16764: }
1.1 raeburn 16765: }
1.129 raeburn 16766: if ($changes{'coowners'}) {
16767: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16768: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16769: if (ref($lastactref) eq 'HASH') {
16770: $lastactref->{'domainconfig'} = 1;
16771: }
1.129 raeburn 16772: }
1.274 raeburn 16773: if ($changes{'autofailsafe'}) {
1.399 raeburn 16774: if ($autofailsafe ne '') {
16775: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16776: } else {
1.399 raeburn 16777: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16778: }
1.399 raeburn 16779: }
16780: if ($changes{'failsafe'}) {
16781: if ($failsafe eq 'off') {
16782: unless ($changes{'autofailsafe'}) {
16783: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16784: }
16785: } elsif ($failsafe eq 'zero') {
16786: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16787: } else {
16788: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16789: }
16790: }
16791: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16792: &Apache::lonnet::get_domain_defaults($dom,1);
16793: if (ref($lastactref) eq 'HASH') {
16794: $lastactref->{'domdefaults'} = 1;
16795: }
16796: }
1.1 raeburn 16797: $resulttext .= '</ul>';
16798: } else {
16799: $resulttext = &mt('No changes made to auto-enrollment settings');
16800: }
16801: } else {
1.11 albertel 16802: $resulttext = '<span class="LC_error">'.
16803: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16804: }
1.3 raeburn 16805: return $resulttext;
1.1 raeburn 16806: }
16807:
16808: sub modify_autoupdate {
1.3 raeburn 16809: my ($dom,%domconfig) = @_;
1.1 raeburn 16810: my ($resulttext,%currautoupdate,%fields,%changes);
16811: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16812: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16813: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16814: }
16815: }
16816: my @offon = ('off','on');
16817: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16818: run => 'Auto-update:',
16819: classlists => 'Updates to user information in classlists?',
16820: unexpired => 'Skip updates for users without active or future roles?',
16821: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16822: );
1.44 raeburn 16823: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16824: my %fieldtitles = &Apache::lonlocal::texthash (
16825: id => 'Student/Employee ID',
1.20 raeburn 16826: permanentemail => 'E-mail address',
1.1 raeburn 16827: lastname => 'Last Name',
16828: firstname => 'First Name',
16829: middlename => 'Middle Name',
1.132 raeburn 16830: generation => 'Generation',
1.1 raeburn 16831: );
1.142 raeburn 16832: $othertitle = &mt('All users');
1.1 raeburn 16833: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16834: $othertitle = &mt('Other users');
1.1 raeburn 16835: }
16836: foreach my $key (keys(%env)) {
16837: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16838: my ($usertype,$item) = ($1,$2);
16839: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16840: if ($usertype eq 'default') {
16841: push(@{$fields{$1}},$2);
16842: } elsif (ref($types) eq 'ARRAY') {
16843: if (grep(/^\Q$usertype\E$/,@{$types})) {
16844: push(@{$fields{$1}},$2);
16845: }
16846: }
16847: }
1.1 raeburn 16848: }
16849: }
1.131 raeburn 16850: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16851: @lockablenames = sort(@lockablenames);
16852: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16853: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16854: if (@changed) {
16855: $changes{'lockablenames'} = 1;
16856: }
16857: } else {
16858: if (@lockablenames) {
16859: $changes{'lockablenames'} = 1;
16860: }
16861: }
1.1 raeburn 16862: my %updatehash = (
16863: autoupdate => { run => $env{'form.autoupdate_run'},
16864: classlists => $env{'form.classlists'},
1.385 raeburn 16865: unexpired => $env{'form.unexpired'},
1.1 raeburn 16866: fields => {%fields},
1.131 raeburn 16867: lockablenames => \@lockablenames,
1.1 raeburn 16868: }
16869: );
1.385 raeburn 16870: my $lastactivedays;
16871: if ($env{'form.lastactive'}) {
16872: $lastactivedays = $env{'form.lastactivedays'};
16873: $lastactivedays =~ s/^\s+|\s+$//g;
16874: unless ($lastactivedays =~ /^\d+$/) {
16875: undef($lastactivedays);
16876: $env{'form.lastactive'} = 0;
16877: }
16878: }
16879: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16880: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16881: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16882: if (exists($updatehash{autoupdate}{$key})) {
16883: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16884: $changes{$key} = 1;
16885: }
16886: }
16887: } elsif ($key eq 'fields') {
16888: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16889: foreach my $item (@{$types},'default') {
1.1 raeburn 16890: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16891: my $change = 0;
16892: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16893: if (!exists($fields{$item})) {
16894: $change = 1;
1.132 raeburn 16895: last;
1.1 raeburn 16896: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16897: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16898: $change = 1;
1.132 raeburn 16899: last;
1.1 raeburn 16900: }
16901: }
16902: }
16903: if ($change) {
16904: push(@{$changes{$key}},$item);
16905: }
1.26 raeburn 16906: }
1.1 raeburn 16907: }
16908: }
1.131 raeburn 16909: } elsif ($key eq 'lockablenames') {
16910: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16911: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16912: if (@changed) {
16913: $changes{'lockablenames'} = 1;
16914: }
16915: } else {
16916: if (@lockablenames) {
16917: $changes{'lockablenames'} = 1;
16918: }
16919: }
16920: }
16921: }
16922: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16923: if (@lockablenames) {
16924: $changes{'lockablenames'} = 1;
1.1 raeburn 16925: }
16926: }
1.385 raeburn 16927: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16928: if ($updatehash{'autoupdate'}{'unexpired'}) {
16929: $changes{'unexpired'} = 1;
16930: }
16931: }
16932: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16933: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16934: $changes{'lastactive'} = 1;
16935: }
16936: }
1.26 raeburn 16937: foreach my $item (@{$types},'default') {
16938: if (defined($fields{$item})) {
16939: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16940: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16941: my $change = 0;
16942: if (ref($fields{$item}) eq 'ARRAY') {
16943: foreach my $type (@{$fields{$item}}) {
16944: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16945: $change = 1;
16946: last;
16947: }
16948: }
16949: }
16950: if ($change) {
16951: push(@{$changes{'fields'}},$item);
16952: }
16953: } else {
1.26 raeburn 16954: push(@{$changes{'fields'}},$item);
16955: }
16956: } else {
16957: push(@{$changes{'fields'}},$item);
1.1 raeburn 16958: }
16959: }
16960: }
16961: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16962: $dom);
16963: if ($putresult eq 'ok') {
16964: if (keys(%changes) > 0) {
16965: $resulttext = &mt('Changes made:').'<ul>';
16966: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16967: if ($key eq 'lockablenames') {
16968: $resulttext .= '<li>';
16969: if (@lockablenames) {
16970: $usertypes->{'default'} = $othertitle;
16971: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16972: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16973: } else {
16974: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16975: }
16976: $resulttext .= '</li>';
16977: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16978: foreach my $item (@{$changes{$key}}) {
16979: my @newvalues;
16980: foreach my $type (@{$fields{$item}}) {
16981: push(@newvalues,$fieldtitles{$type});
16982: }
1.3 raeburn 16983: my $newvaluestr;
16984: if (@newvalues > 0) {
16985: $newvaluestr = join(', ',@newvalues);
16986: } else {
16987: $newvaluestr = &mt('none');
1.6 raeburn 16988: }
1.1 raeburn 16989: if ($item eq 'default') {
1.26 raeburn 16990: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16991: } else {
1.26 raeburn 16992: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16993: }
16994: }
16995: } else {
16996: my $newvalue;
16997: if ($key eq 'run') {
16998: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16999: } elsif ($key eq 'lastactive') {
17000: $newvalue = $offon[$env{'form.lastactive'}];
17001: unless ($lastactivedays eq '') {
17002: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
17003: }
1.1 raeburn 17004: } else {
17005: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 17006: }
1.1 raeburn 17007: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
17008: }
17009: }
17010: $resulttext .= '</ul>';
17011: } else {
1.3 raeburn 17012: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 17013: }
17014: } else {
1.11 albertel 17015: $resulttext = '<span class="LC_error">'.
17016: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17017: }
1.3 raeburn 17018: return $resulttext;
1.1 raeburn 17019: }
17020:
1.125 raeburn 17021: sub modify_autocreate {
17022: my ($dom,%domconfig) = @_;
17023: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17024: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17025: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17026: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17027: }
17028: }
17029: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17030: req => 'Auto-creation of validated requests for official courses',
17031: xmldc => 'Identity of course creator of courses from XML files',
17032: );
17033: my @types = ('xml','req');
17034: foreach my $item (@types) {
17035: $newvals{$item} = $env{'form.autocreate_'.$item};
17036: $newvals{$item} =~ s/\D//g;
17037: $newvals{$item} = 0 if ($newvals{$item} eq '');
17038: }
17039: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17040: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17041: unless (exists($domcoords{$newvals{'xmldc'}})) {
17042: $newvals{'xmldc'} = '';
17043: }
17044: %autocreatehash = (
17045: autocreate => { xml => $newvals{'xml'},
17046: req => $newvals{'req'},
17047: }
17048: );
17049: if ($newvals{'xmldc'} ne '') {
17050: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17051: }
17052: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17053: $dom);
17054: if ($putresult eq 'ok') {
17055: my @items = @types;
17056: if ($newvals{'xml'}) {
17057: push(@items,'xmldc');
17058: }
17059: foreach my $item (@items) {
17060: if (exists($currautocreate{$item})) {
17061: if ($currautocreate{$item} ne $newvals{$item}) {
17062: $changes{$item} = 1;
17063: }
17064: } elsif ($newvals{$item}) {
17065: $changes{$item} = 1;
17066: }
17067: }
17068: if (keys(%changes) > 0) {
17069: my @offon = ('off','on');
17070: $resulttext = &mt('Changes made:').'<ul>';
17071: foreach my $item (@types) {
17072: if ($changes{$item}) {
17073: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17074: $resulttext .= '<li>'.
17075: &mt("$title{$item} set to [_1]$newtxt [_2]",
17076: '<b>','</b>').
17077: '</li>';
1.125 raeburn 17078: }
17079: }
17080: if ($changes{'xmldc'}) {
17081: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17082: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17083: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17084: }
17085: $resulttext .= '</ul>';
17086: } else {
17087: $resulttext = &mt('No changes made to auto-creation settings');
17088: }
17089: } else {
17090: $resulttext = '<span class="LC_error">'.
17091: &mt('An error occurred: [_1]',$putresult).'</span>';
17092: }
17093: return $resulttext;
17094: }
17095:
1.23 raeburn 17096: sub modify_directorysrch {
1.295 raeburn 17097: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17098: my ($resulttext,%changes);
17099: my %currdirsrch;
17100: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17101: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17102: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17103: }
17104: }
1.277 raeburn 17105: my %title = ( available => 'Institutional directory search available',
17106: localonly => 'Other domains can search institution',
17107: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17108: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17109: searchby => 'Search types',
17110: searchtypes => 'Search latitude');
17111: my @offon = ('off','on');
1.24 raeburn 17112: my @otherdoms = ('Yes','No');
1.23 raeburn 17113:
1.25 raeburn 17114: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17115: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17116: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17117:
1.44 raeburn 17118: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17119: if (keys(%{$usertypes}) == 0) {
17120: @cansearch = ('default');
17121: } else {
17122: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17123: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17124: if (!grep(/^\Q$type\E$/,@cansearch)) {
17125: push(@{$changes{'cansearch'}},$type);
17126: }
1.23 raeburn 17127: }
1.26 raeburn 17128: foreach my $type (@cansearch) {
17129: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17130: push(@{$changes{'cansearch'}},$type);
17131: }
1.23 raeburn 17132: }
1.26 raeburn 17133: } else {
17134: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17135: }
17136: }
17137:
17138: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17139: foreach my $by (@{$currdirsrch{'searchby'}}) {
17140: if (!grep(/^\Q$by\E$/,@searchby)) {
17141: push(@{$changes{'searchby'}},$by);
17142: }
17143: }
17144: foreach my $by (@searchby) {
17145: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17146: push(@{$changes{'searchby'}},$by);
17147: }
17148: }
17149: } else {
17150: push(@{$changes{'searchby'}},@searchby);
17151: }
1.25 raeburn 17152:
17153: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17154: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17155: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17156: push(@{$changes{'searchtypes'}},$type);
17157: }
17158: }
17159: foreach my $type (@searchtypes) {
17160: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17161: push(@{$changes{'searchtypes'}},$type);
17162: }
17163: }
17164: } else {
17165: if (exists($currdirsrch{'searchtypes'})) {
17166: foreach my $type (@searchtypes) {
17167: if ($type ne $currdirsrch{'searchtypes'}) {
17168: push(@{$changes{'searchtypes'}},$type);
17169: }
17170: }
17171: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17172: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17173: }
17174: } else {
17175: push(@{$changes{'searchtypes'}},@searchtypes);
17176: }
17177: }
17178:
1.23 raeburn 17179: my %dirsrch_hash = (
17180: directorysrch => { available => $env{'form.dirsrch_available'},
17181: cansearch => \@cansearch,
1.277 raeburn 17182: localonly => $env{'form.dirsrch_instlocalonly'},
17183: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17184: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17185: searchby => \@searchby,
1.25 raeburn 17186: searchtypes => \@searchtypes,
1.23 raeburn 17187: }
17188: );
17189: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17190: $dom);
17191: if ($putresult eq 'ok') {
17192: if (exists($currdirsrch{'available'})) {
17193: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17194: $changes{'available'} = 1;
17195: }
17196: } else {
17197: if ($env{'form.dirsrch_available'} eq '1') {
17198: $changes{'available'} = 1;
17199: }
17200: }
1.277 raeburn 17201: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17202: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17203: $changes{'lcavailable'} = 1;
17204: }
1.277 raeburn 17205: } else {
17206: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17207: $changes{'lcavailable'} = 1;
17208: }
17209: }
1.24 raeburn 17210: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17211: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17212: $changes{'localonly'} = 1;
17213: }
1.24 raeburn 17214: } else {
1.277 raeburn 17215: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17216: $changes{'localonly'} = 1;
17217: }
17218: }
1.277 raeburn 17219: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17220: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17221: $changes{'lclocalonly'} = 1;
17222: }
1.277 raeburn 17223: } else {
17224: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17225: $changes{'lclocalonly'} = 1;
17226: }
17227: }
1.23 raeburn 17228: if (keys(%changes) > 0) {
17229: $resulttext = &mt('Changes made:').'<ul>';
17230: if ($changes{'available'}) {
17231: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17232: }
1.277 raeburn 17233: if ($changes{'lcavailable'}) {
17234: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17235: }
1.24 raeburn 17236: if ($changes{'localonly'}) {
1.277 raeburn 17237: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17238: }
1.277 raeburn 17239: if ($changes{'lclocalonly'}) {
17240: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17241: }
1.23 raeburn 17242: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17243: my $chgtext;
1.26 raeburn 17244: if (ref($usertypes) eq 'HASH') {
17245: if (keys(%{$usertypes}) > 0) {
17246: foreach my $type (@{$types}) {
17247: if (grep(/^\Q$type\E$/,@cansearch)) {
17248: $chgtext .= $usertypes->{$type}.'; ';
17249: }
17250: }
17251: if (grep(/^default$/,@cansearch)) {
17252: $chgtext .= $othertitle;
17253: } else {
17254: $chgtext =~ s/\; $//;
17255: }
1.210 raeburn 17256: $resulttext .=
1.178 raeburn 17257: '<li>'.
17258: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17259: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17260: '</li>';
1.23 raeburn 17261: }
17262: }
17263: }
17264: if (ref($changes{'searchby'}) eq 'ARRAY') {
17265: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17266: my $chgtext;
17267: foreach my $type (@{$titleorder}) {
17268: if (grep(/^\Q$type\E$/,@searchby)) {
17269: if (defined($searchtitles->{$type})) {
17270: $chgtext .= $searchtitles->{$type}.'; ';
17271: }
17272: }
17273: }
17274: $chgtext =~ s/\; $//;
17275: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17276: }
1.25 raeburn 17277: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17278: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17279: my $chgtext;
17280: foreach my $type (@{$srchtypeorder}) {
17281: if (grep(/^\Q$type\E$/,@searchtypes)) {
17282: if (defined($srchtypes_desc->{$type})) {
17283: $chgtext .= $srchtypes_desc->{$type}.'; ';
17284: }
17285: }
17286: }
17287: $chgtext =~ s/\; $//;
1.178 raeburn 17288: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17289: }
17290: $resulttext .= '</ul>';
1.295 raeburn 17291: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17292: if (ref($lastactref) eq 'HASH') {
17293: $lastactref->{'directorysrch'} = 1;
17294: }
1.23 raeburn 17295: } else {
1.277 raeburn 17296: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17297: }
17298: } else {
17299: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17300: &mt('An error occurred: [_1]',$putresult).'</span>';
17301: }
17302: return $resulttext;
17303: }
17304:
1.28 raeburn 17305: sub modify_contacts {
1.205 raeburn 17306: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17307: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17308: if (ref($domconfig{'contacts'}) eq 'HASH') {
17309: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17310: $currsetting{$key} = $domconfig{'contacts'}{$key};
17311: }
17312: }
1.286 raeburn 17313: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17314: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17315: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17316: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17317: my @toggles = ('reporterrors','reportupdates','reportstatus');
17318: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17319: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17320: foreach my $type (@mailings) {
17321: @{$newsetting{$type}} =
17322: &Apache::loncommon::get_env_multiple('form.'.$type);
17323: foreach my $item (@contacts) {
17324: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17325: $contacts_hash{contacts}{$type}{$item} = 1;
17326: } else {
17327: $contacts_hash{contacts}{$type}{$item} = 0;
17328: }
1.289 raeburn 17329: }
1.28 raeburn 17330: $others{$type} = $env{'form.'.$type.'_others'};
17331: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17332: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17333: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17334: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17335: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17336: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17337: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17338: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17339: }
1.134 raeburn 17340: }
1.28 raeburn 17341: }
17342: foreach my $item (@contacts) {
17343: $to{$item} = $env{'form.'.$item};
17344: $contacts_hash{'contacts'}{$item} = $to{$item};
17345: }
1.203 raeburn 17346: foreach my $item (@toggles) {
17347: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17348: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17349: }
17350: }
1.340 raeburn 17351: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17352: foreach my $item (@lonstatus) {
17353: if ($item eq 'excluded') {
17354: my (%serverhomes,@excluded);
17355: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17356: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17357: if (@possexcluded) {
17358: foreach my $id (sort(@possexcluded)) {
17359: if ($serverhomes{$id}) {
17360: push(@excluded,$id);
17361: }
17362: }
17363: }
17364: if (@excluded) {
17365: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17366: }
17367: } elsif ($item eq 'weights') {
1.377 raeburn 17368: foreach my $type ('E','W','N','U') {
1.340 raeburn 17369: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17370: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17371: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17372: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17373: $env{'form.error'.$item.'_'.$type};
17374: }
17375: }
17376: }
17377: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17378: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17379: if ($env{'form.error'.$item} =~ /^\d+$/) {
17380: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17381: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17382: }
17383: }
17384: }
17385: }
1.286 raeburn 17386: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17387: foreach my $field (@{$fields}) {
17388: if (ref($possoptions->{$field}) eq 'ARRAY') {
17389: my $value = $env{'form.helpform_'.$field};
17390: $value =~ s/^\s+|\s+$//g;
17391: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17392: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17393: if ($field eq 'screenshot') {
17394: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17395: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17396: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17397: }
17398: }
17399: }
17400: }
17401: }
17402: }
1.315 raeburn 17403: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17404: my (@statuses,%usertypeshash,@overrides);
17405: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17406: @statuses = @{$types};
17407: if (ref($usertypes) eq 'HASH') {
17408: %usertypeshash = %{$usertypes};
17409: }
17410: }
17411: if (@statuses) {
17412: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17413: foreach my $type (@possoverrides) {
17414: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17415: push(@overrides,$type);
17416: }
17417: }
17418: if (@overrides) {
17419: foreach my $type (@overrides) {
17420: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17421: foreach my $item (@contacts) {
17422: if (grep(/^\Q$item\E$/,@standard)) {
17423: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17424: $newsetting{'override_'.$type}{$item} = 1;
17425: } else {
17426: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17427: $newsetting{'override_'.$type}{$item} = 0;
17428: }
17429: }
17430: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17431: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17432: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17433: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17434: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17435: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17436: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17437: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17438: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17439: }
17440: }
17441: }
17442: }
1.28 raeburn 17443: if (keys(%currsetting) > 0) {
17444: foreach my $item (@contacts) {
17445: if ($to{$item} ne $currsetting{$item}) {
17446: $changes{$item} = 1;
17447: }
17448: }
17449: foreach my $type (@mailings) {
17450: foreach my $item (@contacts) {
17451: if (ref($currsetting{$type}) eq 'HASH') {
17452: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17453: push(@{$changes{$type}},$item);
17454: }
17455: } else {
17456: push(@{$changes{$type}},@{$newsetting{$type}});
17457: }
17458: }
17459: if ($others{$type} ne $currsetting{$type}{'others'}) {
17460: push(@{$changes{$type}},'others');
17461: }
1.289 raeburn 17462: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17463: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17464: push(@{$changes{$type}},'bcc');
17465: }
1.286 raeburn 17466: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17467: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17468: push(@{$changes{$type}},'include');
17469: }
17470: }
17471: }
17472: if (ref($fields) eq 'ARRAY') {
17473: if (ref($currsetting{'helpform'}) eq 'HASH') {
17474: foreach my $field (@{$fields}) {
17475: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17476: push(@{$changes{'helpform'}},$field);
17477: }
17478: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17479: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17480: push(@{$changes{'helpform'}},'maxsize');
17481: }
17482: }
17483: }
17484: } else {
17485: foreach my $field (@{$fields}) {
17486: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17487: push(@{$changes{'helpform'}},$field);
17488: }
17489: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17490: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17491: push(@{$changes{'helpform'}},'maxsize');
17492: }
17493: }
17494: }
1.134 raeburn 17495: }
1.28 raeburn 17496: }
1.315 raeburn 17497: if (@statuses) {
17498: if (ref($currsetting{'overrides'}) eq 'HASH') {
17499: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17500: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17501: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17502: foreach my $item (@contacts,'bcc','others','include') {
17503: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
17504: push(@{$changes{'overrides'}},$key);
17505: last;
17506: }
17507: }
17508: } else {
17509: push(@{$changes{'overrides'}},$key);
17510: }
17511: }
17512: }
17513: foreach my $key (@overrides) {
17514: unless (exists($currsetting{'overrides'}{$key})) {
17515: push(@{$changes{'overrides'}},$key);
17516: }
17517: }
17518: } else {
17519: foreach my $key (@overrides) {
17520: push(@{$changes{'overrides'}},$key);
17521: }
17522: }
17523: }
1.340 raeburn 17524: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17525: foreach my $key ('excluded','weights','threshold','sysmail') {
17526: if ($key eq 'excluded') {
17527: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17528: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17529: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17530: (@{$currsetting{'lonstatus'}{$key}})) {
17531: my @diffs =
17532: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17533: $currsetting{'lonstatus'}{$key});
17534: if (@diffs) {
17535: push(@{$changes{'lonstatus'}},$key);
17536: }
17537: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17538: push(@{$changes{'lonstatus'}},$key);
17539: }
17540: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17541: (@{$currsetting{'lonstatus'}{$key}})) {
17542: push(@{$changes{'lonstatus'}},$key);
17543: }
17544: } elsif ($key eq 'weights') {
17545: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17546: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17547: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17548: foreach my $type ('E','W','N','U') {
1.340 raeburn 17549: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17550: $currsetting{'lonstatus'}{$key}{$type}) {
17551: push(@{$changes{'lonstatus'}},$key);
17552: last;
17553: }
17554: }
17555: } else {
1.341 raeburn 17556: foreach my $type ('E','W','N','U') {
1.340 raeburn 17557: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17558: push(@{$changes{'lonstatus'}},$key);
17559: last;
17560: }
17561: }
17562: }
17563: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17564: foreach my $type ('E','W','N','U') {
1.340 raeburn 17565: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17566: push(@{$changes{'lonstatus'}},$key);
17567: last;
17568: }
17569: }
17570: }
17571: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17572: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17573: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17574: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17575: push(@{$changes{'lonstatus'}},$key);
17576: }
17577: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17578: push(@{$changes{'lonstatus'}},$key);
17579: }
17580: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17581: push(@{$changes{'lonstatus'}},$key);
17582: }
17583: }
17584: }
17585: } else {
17586: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17587: foreach my $key ('excluded','weights','threshold','sysmail') {
17588: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17589: push(@{$changes{'lonstatus'}},$key);
17590: }
17591: }
17592: }
17593: }
1.28 raeburn 17594: } else {
17595: my %default;
17596: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17597: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17598: $default{'errormail'} = 'adminemail';
17599: $default{'packagesmail'} = 'adminemail';
17600: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17601: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17602: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17603: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17604: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17605: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17606: foreach my $item (@contacts) {
17607: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17608: $changes{$item} = 1;
1.203 raeburn 17609: }
1.28 raeburn 17610: }
17611: foreach my $type (@mailings) {
17612: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17613: push(@{$changes{$type}},@{$newsetting{$type}});
17614: }
17615: if ($others{$type} ne '') {
17616: push(@{$changes{$type}},'others');
1.134 raeburn 17617: }
1.286 raeburn 17618: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17619: if ($bcc{$type} ne '') {
17620: push(@{$changes{$type}},'bcc');
17621: }
1.286 raeburn 17622: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17623: push(@{$changes{$type}},'include');
17624: }
1.134 raeburn 17625: }
1.28 raeburn 17626: }
1.286 raeburn 17627: if (ref($fields) eq 'ARRAY') {
17628: foreach my $field (@{$fields}) {
17629: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17630: push(@{$changes{'helpform'}},$field);
17631: }
17632: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17633: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17634: push(@{$changes{'helpform'}},'maxsize');
17635: }
17636: }
17637: }
1.289 raeburn 17638: }
1.340 raeburn 17639: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17640: foreach my $key ('excluded','weights','threshold','sysmail') {
17641: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17642: push(@{$changes{'lonstatus'}},$key);
17643: }
17644: }
17645: }
1.28 raeburn 17646: }
1.203 raeburn 17647: foreach my $item (@toggles) {
17648: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17649: $changes{$item} = 1;
17650: } elsif ((!$env{'form.'.$item}) &&
17651: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17652: $changes{$item} = 1;
17653: }
17654: }
1.28 raeburn 17655: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17656: $dom);
17657: if ($putresult eq 'ok') {
17658: if (keys(%changes) > 0) {
1.205 raeburn 17659: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17660: if (ref($lastactref) eq 'HASH') {
17661: $lastactref->{'domainconfig'} = 1;
17662: }
1.28 raeburn 17663: my ($titles,$short_titles) = &contact_titles();
17664: $resulttext = &mt('Changes made:').'<ul>';
17665: foreach my $item (@contacts) {
17666: if ($changes{$item}) {
17667: $resulttext .= '<li>'.$titles->{$item}.
17668: &mt(' set to: ').
17669: '<span class="LC_cusr_emph">'.
17670: $to{$item}.'</span></li>';
17671: }
17672: }
17673: foreach my $type (@mailings) {
17674: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17675: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17676: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17677: } else {
17678: $resulttext .= '<li>'.$titles->{$type}.': ';
17679: }
1.28 raeburn 17680: my @text;
17681: foreach my $item (@{$newsetting{$type}}) {
17682: push(@text,$short_titles->{$item});
17683: }
17684: if ($others{$type} ne '') {
17685: push(@text,$others{$type});
17686: }
1.286 raeburn 17687: if (@text) {
17688: $resulttext .= '<span class="LC_cusr_emph">'.
17689: join(', ',@text).'</span>';
17690: }
17691: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17692: if ($bcc{$type} ne '') {
1.286 raeburn 17693: my $bcctext;
17694: if (@text) {
1.289 raeburn 17695: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17696: } else {
17697: $bcctext = '(Bcc)';
17698: }
17699: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17700: } elsif (!@text) {
17701: $resulttext .= &mt('No one');
17702: }
1.289 raeburn 17703: if ($includestr{$type} ne '') {
1.286 raeburn 17704: if ($includeloc{$type} eq 'b') {
17705: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17706: } elsif ($includeloc{$type} eq 's') {
17707: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17708: }
1.134 raeburn 17709: }
1.286 raeburn 17710: } elsif (!@text) {
17711: $resulttext .= &mt('No recipients');
1.134 raeburn 17712: }
17713: $resulttext .= '</li>';
1.28 raeburn 17714: }
17715: }
1.315 raeburn 17716: if (ref($changes{'overrides'}) eq 'ARRAY') {
17717: my @deletions;
17718: foreach my $type (@{$changes{'overrides'}}) {
17719: if ($usertypeshash{$type}) {
17720: if (grep(/^\Q$type\E/,@overrides)) {
17721: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17722: $usertypeshash{$type}).'<ul><li>';
17723: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17724: my @text;
17725: foreach my $item (@contacts) {
17726: if ($newsetting{'override_'.$type}{$item}) {
17727: push(@text,$short_titles->{$item});
17728: }
17729: }
17730: if ($newsetting{'override_'.$type}{'others'} ne '') {
17731: push(@text,$newsetting{'override_'.$type}{'others'});
17732: }
17733:
17734: if (@text) {
17735: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17736: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17737: }
17738: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17739: my $bcctext;
17740: if (@text) {
17741: $bcctext = ' '.&mt('with Bcc to');
17742: } else {
17743: $bcctext = '(Bcc)';
17744: }
17745: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17746: } elsif (!@text) {
17747: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17748: }
17749: $resulttext .= '</li>';
17750: if ($newsetting{'override_'.$type}{'include'} ne '') {
17751: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17752: if ($loc eq 'b') {
17753: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17754: } elsif ($loc eq 's') {
17755: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17756: }
17757: }
17758: }
17759: $resulttext .= '</li></ul></li>';
17760: } else {
17761: push(@deletions,$usertypeshash{$type});
17762: }
17763: }
17764: }
17765: if (@deletions) {
17766: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17767: join(', ',@deletions)).'</li>';
17768: }
17769: }
1.203 raeburn 17770: my @offon = ('off','on');
1.340 raeburn 17771: my $corelink = &core_link_msu();
1.203 raeburn 17772: if ($changes{'reporterrors'}) {
17773: $resulttext .= '<li>'.
17774: &mt('E-mail error reports to [_1] set to "'.
17775: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17776: $corelink).
1.203 raeburn 17777: '</li>';
17778: }
17779: if ($changes{'reportupdates'}) {
17780: $resulttext .= '<li>'.
17781: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17782: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17783: $corelink).
1.203 raeburn 17784: '</li>';
17785: }
1.340 raeburn 17786: if ($changes{'reportstatus'}) {
17787: $resulttext .= '<li>'.
17788: &mt('E-mail status if errors above threshold to [_1] set to "'.
17789: $offon[$env{'form.reportstatus'}].'".',
17790: $corelink).
17791: '</li>';
17792: }
17793: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17794: $resulttext .= '<li>'.
17795: &mt('Nightly status check e-mail settings').':<ul>';
17796: my (%defval,%use_def,%shown);
17797: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17798: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17799: $defval{'weights'} =
1.341 raeburn 17800: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17801: $defval{'excluded'} = &mt('None');
17802: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17803: foreach my $item ('threshold','sysmail','weights','excluded') {
17804: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17805: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17806: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17807: } elsif ($item eq 'weights') {
17808: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17809: foreach my $type ('E','W','N','U') {
1.340 raeburn 17810: $shown{$item} .= $lonstatus_names->{$type}.'=';
17811: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17812: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17813: } else {
17814: $shown{$item} .= $lonstatus_defs->{$type};
17815: }
17816: $shown{$item} .= ', ';
17817: }
17818: $shown{$item} =~ s/, $//;
17819: } else {
17820: $shown{$item} = $defval{$item};
17821: }
17822: } elsif ($item eq 'excluded') {
17823: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17824: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17825: } else {
17826: $shown{$item} = $defval{$item};
17827: }
17828: }
17829: } else {
17830: $shown{$item} = $defval{$item};
17831: }
17832: }
17833: } else {
17834: foreach my $item ('threshold','weights','excluded','sysmail') {
17835: $shown{$item} = $defval{$item};
17836: }
17837: }
17838: foreach my $item ('threshold','weights','excluded','sysmail') {
17839: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17840: $shown{$item}).'</li>';
17841: }
17842: $resulttext .= '</ul></li>';
17843: }
1.286 raeburn 17844: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17845: my (@optional,@required,@unused,$maxsizechg);
17846: foreach my $field (@{$changes{'helpform'}}) {
17847: if ($field eq 'maxsize') {
17848: $maxsizechg = 1;
17849: next;
17850: }
17851: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17852: push(@optional,$field);
1.286 raeburn 17853: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17854: push(@unused,$field);
17855: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17856: push(@required,$field);
1.286 raeburn 17857: }
17858: }
17859: if (@optional) {
17860: $resulttext .= '<li>'.
17861: &mt('Help form fields changed to "Optional": [_1].',
17862: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17863: '</li>';
17864: }
17865: if (@required) {
17866: $resulttext .= '<li>'.
17867: &mt('Help form fields changed to "Required": [_1].',
17868: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17869: '</li>';
17870: }
17871: if (@unused) {
17872: $resulttext .= '<li>'.
17873: &mt('Help form fields changed to "Not shown": [_1].',
17874: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17875: '</li>';
17876: }
17877: if ($maxsizechg) {
17878: $resulttext .= '<li>'.
17879: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17880: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17881: '</li>';
17882: }
17883: }
1.28 raeburn 17884: $resulttext .= '</ul>';
17885: } else {
1.288 raeburn 17886: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17887: }
17888: } else {
17889: $resulttext = '<span class="LC_error">'.
17890: &mt('An error occurred: [_1].',$putresult).'</span>';
17891: }
17892: return $resulttext;
17893: }
17894:
1.357 raeburn 17895: sub modify_privacy {
17896: my ($dom,%domconfig) = @_;
17897: my ($resulttext,%current,%changes);
17898: if (ref($domconfig{'privacy'}) eq 'HASH') {
17899: %current = %{$domconfig{'privacy'}};
17900: }
17901: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17902: my @items = ('domain','author','course','community');
17903: my %names = &Apache::lonlocal::texthash (
17904: domain => 'Assigned domain role(s)',
17905: author => 'Assigned co-author role(s)',
17906: course => 'Assigned course role(s)',
17907: community => 'Assigned community role',
17908: );
17909: my %roles = &Apache::lonlocal::texthash (
17910: domain => 'Domain role',
17911: author => 'Co-author role',
17912: course => 'Course role',
17913: community => 'Community role',
17914: );
17915: my %titles = &Apache::lonlocal::texthash (
17916: approval => 'Approval for role in different domain',
17917: othdom => 'User information available in other domain',
17918: priv => 'Information viewable by privileged user in same domain',
17919: unpriv => 'Information viewable by unprivileged user in same domain',
17920: instdom => 'Other domain shares institution/provider',
17921: extdom => 'Other domain has different institution/provider',
17922: none => 'Not allowed',
17923: user => 'User authorizes',
17924: domain => 'Domain Coordinator authorizes',
17925: auto => 'Unrestricted',
17926: );
17927: my %fieldnames = &Apache::lonlocal::texthash (
17928: id => 'Student/Employee ID',
17929: permanentemail => 'E-mail address',
17930: lastname => 'Last Name',
17931: firstname => 'First Name',
17932: middlename => 'Middle Name',
17933: generation => 'Generation',
17934: );
17935: my ($othertitle,$usertypes,$types) =
17936: &Apache::loncommon::sorted_inst_types($dom);
17937: my (%by_ip,%by_location,@intdoms,@instdoms);
17938: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17939:
17940: my %privacyhash = (
17941: 'approval' => {
17942: instdom => {},
17943: extdom => {},
17944: },
17945: 'othdom' => {},
17946: 'priv' => {},
17947: 'unpriv' => {},
17948: );
17949: foreach my $item (@items) {
17950: if (@instdoms > 1) {
17951: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
17952: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17953: }
17954: if (ref($current{'approval'}) eq 'HASH') {
17955: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17956: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17957: $changes{'approval'} = 1;
17958: }
17959: }
17960: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17961: $changes{'approval'} = 1;
17962: }
17963: }
17964: if (keys(%by_location) > 0) {
17965: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17966: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17967: }
17968: if (ref($current{'approval'}) eq 'HASH') {
17969: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17970: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17971: $changes{'approval'} = 1;
17972: }
17973: }
17974: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17975: $changes{'approval'} = 1;
17976: }
17977: }
17978: foreach my $status ('priv','unpriv') {
17979: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17980: my @newvalues;
17981: foreach my $field (@possibles) {
17982: if (grep(/^\Q$field\E$/,@fields)) {
17983: $privacyhash{$status}{$item}{$field} = 1;
17984: push(@newvalues,$field);
17985: }
17986: }
17987: @newvalues = sort(@newvalues);
17988: if (ref($current{$status}) eq 'HASH') {
17989: if (ref($current{$status}{$item}) eq 'HASH') {
17990: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17991: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17992: if (@diffs > 0) {
17993: $changes{$status} = 1;
17994: }
17995: }
17996: } else {
17997: my @stdfields;
17998: foreach my $field (@fields) {
17999: if ($field eq 'id') {
18000: next if ($status eq 'unpriv');
18001: next if (($status eq 'priv') && ($item eq 'community'));
18002: }
18003: push(@stdfields,$field);
18004: }
18005: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18006: if (@diffs > 0) {
18007: $changes{$status} = 1;
18008: }
18009: }
18010: }
18011: }
18012: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
18013: my @statuses;
18014: if (ref($types) eq 'ARRAY') {
18015: @statuses = @{$types};
18016: }
18017: foreach my $type (@statuses,'default') {
18018: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18019: my @newvalues;
18020: foreach my $field (sort(@possfields)) {
18021: if (grep(/^\Q$field\E$/,@fields)) {
18022: $privacyhash{'othdom'}{$type}{$field} = 1;
18023: push(@newvalues,$field);
18024: }
18025: }
18026: @newvalues = sort(@newvalues);
18027: if (ref($current{'othdom'}) eq 'HASH') {
18028: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18029: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18030: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18031: if (@diffs > 0) {
18032: $changes{'othdom'} = 1;
18033: }
18034: }
18035: } else {
18036: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18037: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18038: if (@diffs > 0) {
18039: $changes{'othdom'} = 1;
18040: }
18041: }
18042: }
18043: }
18044: my %confighash = (
18045: privacy => \%privacyhash,
18046: );
18047: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18048: if ($putresult eq 'ok') {
18049: if (keys(%changes) > 0) {
18050: $resulttext = &mt('Changes made: ').'<ul>';
18051: foreach my $key ('approval','othdom','priv','unpriv') {
18052: if ($changes{$key}) {
18053: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18054: if ($key eq 'approval') {
18055: if (keys(%{$privacyhash{$key}{instdom}})) {
18056: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18057: foreach my $item (@items) {
18058: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18059: }
18060: $resulttext .= '</ul></li>';
18061: }
18062: if (keys(%{$privacyhash{$key}{extdom}})) {
18063: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18064: foreach my $item (@items) {
18065: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18066: }
18067: $resulttext .= '</ul></li>';
18068: }
18069: } elsif ($key eq 'othdom') {
18070: my @statuses;
18071: if (ref($types) eq 'ARRAY') {
18072: @statuses = @{$types};
18073: }
18074: if (ref($privacyhash{$key}) eq 'HASH') {
18075: foreach my $status (@statuses,'default') {
18076: if ($status eq 'default') {
18077: $resulttext .= '<li>'.$othertitle.': ';
18078: } elsif (ref($usertypes) eq 'HASH') {
18079: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18080: } else {
18081: next;
18082: }
18083: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18084: if (keys(%{$privacyhash{$key}{$status}})) {
18085: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18086: } else {
18087: $resulttext .= &mt('none');
18088: }
18089: }
18090: $resulttext .= '</li>';
18091: }
18092: }
18093: } else {
18094: foreach my $item (@items) {
18095: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18096: $resulttext .= '<li>'.$names{$item}.': ';
18097: if (keys(%{$privacyhash{$key}{$item}})) {
18098: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18099: } else {
18100: $resulttext .= &mt('none');
18101: }
18102: $resulttext .= '</li>';
18103: }
18104: }
18105: }
18106: $resulttext .= '</ul></li>';
18107: }
18108: }
18109: } else {
18110: $resulttext = &mt('No changes made to user information settings');
18111: }
18112: } else {
18113: $resulttext = '<span class="LC_error">'.
18114: &mt('An error occurred: [_1]',$putresult).'</span>';
18115: }
18116: return $resulttext;
18117: }
18118:
1.354 raeburn 18119: sub modify_passwords {
18120: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18121: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18122: $updatedefaults,$updateconf);
1.354 raeburn 18123: my $customfn = 'resetpw.html';
18124: if (ref($domconfig{'passwords'}) eq 'HASH') {
18125: %current = %{$domconfig{'passwords'}};
18126: }
18127: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18128: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18129: if (ref($types) eq 'ARRAY') {
18130: @oktypes = @{$types};
18131: }
18132: push(@oktypes,'default');
18133:
18134: my %titles = &Apache::lonlocal::texthash (
18135: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18136: intauth_check => 'Check bcrypt cost if authenticated',
18137: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18138: permanent => 'Permanent e-mail address',
18139: critical => 'Critical notification address',
18140: notify => 'Notification address',
18141: min => 'Minimum password length',
18142: max => 'Maximum password length',
18143: chars => 'Required characters',
18144: expire => 'Password expiration (days)',
1.356 raeburn 18145: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18146: reset => 'Resetting Forgotten Password',
18147: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18148: rules => 'Rules for LON-CAPA Passwords',
18149: crsownerchg => 'Course Owner Changing Student Passwords',
18150: username => 'Username',
18151: email => 'E-mail address',
18152: );
18153:
18154: #
18155: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18156: #
18157: my (%curr_defaults,%save_defaults);
18158: if (ref($domconfig{'defaults'}) eq 'HASH') {
18159: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18160: if ($key =~ /^intauth_(cost|check|switch)$/) {
18161: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18162: } else {
18163: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18164: }
18165: }
18166: }
18167: my %staticdefaults = (
18168: 'resetlink' => 2,
18169: 'resetcase' => \@oktypes,
18170: 'resetprelink' => 'both',
18171: 'resetemail' => ['critical','notify','permanent'],
18172: 'intauth_cost' => 10,
18173: 'intauth_check' => 0,
18174: 'intauth_switch' => 0,
18175: );
1.365 raeburn 18176: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18177: foreach my $type (@oktypes) {
18178: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18179: }
18180: my $linklife = $env{'form.passwords_link'};
18181: $linklife =~ s/^\s+|\s+$//g;
18182: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18183: $newvalues{'resetlink'} = $linklife;
18184: if ($current{'resetlink'}) {
18185: if ($current{'resetlink'} ne $linklife) {
18186: $changes{'reset'} = 1;
18187: }
1.368 raeburn 18188: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18189: if ($staticdefaults{'resetlink'} ne $linklife) {
18190: $changes{'reset'} = 1;
18191: }
18192: }
18193: } elsif ($current{'resetlink'}) {
18194: $changes{'reset'} = 1;
18195: }
18196: my @casesens;
18197: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18198: foreach my $case (sort(@posscase)) {
18199: if (grep(/^\Q$case\E$/,@oktypes)) {
18200: push(@casesens,$case);
18201: }
18202: }
18203: $newvalues{'resetcase'} = \@casesens;
18204: if (ref($current{'resetcase'}) eq 'ARRAY') {
18205: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18206: if (@diffs > 0) {
18207: $changes{'reset'} = 1;
18208: }
1.368 raeburn 18209: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18210: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18211: if (@diffs > 0) {
18212: $changes{'reset'} = 1;
18213: }
18214: }
18215: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18216: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18217: if (exists($current{'resetprelink'})) {
18218: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18219: $changes{'reset'} = 1;
18220: }
1.368 raeburn 18221: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18222: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18223: $changes{'reset'} = 1;
18224: }
18225: }
18226: } elsif ($current{'resetprelink'}) {
18227: $changes{'reset'} = 1;
18228: }
18229: foreach my $type (@oktypes) {
18230: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18231: my @postlink;
18232: foreach my $item (sort(@possplink)) {
18233: if ($item =~ /^(email|username)$/) {
18234: push(@postlink,$item);
18235: }
18236: }
18237: $newvalues{'resetpostlink'}{$type} = \@postlink;
18238: unless ($changes{'reset'}) {
18239: if (ref($current{'resetpostlink'}) eq 'HASH') {
18240: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18241: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18242: if (@diffs > 0) {
18243: $changes{'reset'} = 1;
18244: }
18245: } else {
18246: $changes{'reset'} = 1;
18247: }
1.368 raeburn 18248: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18249: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18250: if (@diffs > 0) {
18251: $changes{'reset'} = 1;
18252: }
18253: }
18254: }
18255: }
18256: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18257: my @resetemail;
18258: foreach my $item (sort(@possemailsrc)) {
18259: if ($item =~ /^(permanent|critical|notify)$/) {
18260: push(@resetemail,$item);
18261: }
18262: }
18263: $newvalues{'resetemail'} = \@resetemail;
18264: unless ($changes{'reset'}) {
18265: if (ref($current{'resetemail'}) eq 'ARRAY') {
18266: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18267: if (@diffs > 0) {
18268: $changes{'reset'} = 1;
18269: }
1.368 raeburn 18270: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18271: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18272: if (@diffs > 0) {
18273: $changes{'reset'} = 1;
18274: }
18275: }
18276: }
18277: if ($env{'form.passwords_stdtext'} == 0) {
18278: $newvalues{'resetremove'} = 1;
18279: unless ($current{'resetremove'}) {
18280: $changes{'reset'} = 1;
18281: }
18282: } elsif ($current{'resetremove'}) {
18283: $changes{'reset'} = 1;
18284: }
18285: if ($env{'form.passwords_customfile.filename'} ne '') {
18286: my $servadm = $r->dir_config('lonAdmEMail');
18287: my ($configuserok,$author_ok,$switchserver) =
18288: &config_check($dom,$confname,$servadm);
18289: my $error;
18290: if ($configuserok eq 'ok') {
18291: if ($switchserver) {
18292: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18293: } else {
18294: if ($author_ok eq 'ok') {
18295: my ($result,$customurl) =
18296: &publishlogo($r,'upload','passwords_customfile',$dom,
18297: $confname,'customtext/resetpw','','',$customfn);
18298: if ($result eq 'ok') {
18299: $newvalues{'resetcustom'} = $customurl;
18300: $changes{'reset'} = 1;
18301: } else {
18302: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18303: }
18304: } else {
18305: $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);
18306: }
18307: }
18308: } else {
18309: $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);
18310: }
18311: if ($error) {
18312: &Apache::lonnet::logthis($error);
18313: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18314: }
18315: } elsif ($current{'resetcustom'}) {
18316: if ($env{'form.passwords_custom_del'}) {
18317: $changes{'reset'} = 1;
18318: } else {
18319: $newvalues{'resetcustom'} = $current{'resetcustom'};
18320: }
18321: }
18322: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18323: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18324: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18325: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18326: $changes{'intauth'} = 1;
18327: }
18328: } else {
18329: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18330: }
18331: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18332: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18333: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18334: $changes{'intauth'} = 1;
18335: }
18336: } else {
18337: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18338: }
18339: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18340: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18341: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18342: $changes{'intauth'} = 1;
18343: }
18344: } else {
18345: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18346: }
18347: foreach my $item ('cost','check','switch') {
18348: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18349: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18350: $updatedefaults = 1;
18351: }
18352: }
1.405 raeburn 18353: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18354: my %crsownerchg = (
18355: by => [],
18356: for => [],
18357: );
18358: foreach my $item ('by','for') {
18359: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18360: foreach my $type (sort(@posstypes)) {
18361: if (grep(/^\Q$type\E$/,@oktypes)) {
18362: push(@{$crsownerchg{$item}},$type);
18363: }
18364: }
18365: }
18366: $newvalues{'crsownerchg'} = \%crsownerchg;
18367: if (ref($current{'crsownerchg'}) eq 'HASH') {
18368: foreach my $item ('by','for') {
18369: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18370: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18371: if (@diffs > 0) {
18372: $changes{'crsownerchg'} = 1;
18373: last;
18374: }
18375: }
18376: }
1.368 raeburn 18377: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18378: foreach my $item ('by','for') {
18379: if (@{$crsownerchg{$item}} > 0) {
18380: $changes{'crsownerchg'} = 1;
18381: last;
18382: }
1.354 raeburn 18383: }
18384: }
18385:
18386: my %confighash = (
18387: defaults => \%save_defaults,
18388: passwords => \%newvalues,
18389: );
18390: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18391:
18392: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18393: if ($putresult eq 'ok') {
18394: if (keys(%changes) > 0) {
18395: $resulttext = &mt('Changes made: ').'<ul>';
18396: foreach my $key ('reset','intauth','rules','crsownerchg') {
18397: if ($changes{$key}) {
1.355 raeburn 18398: unless ($key eq 'intauth') {
18399: $updateconf = 1;
18400: }
1.354 raeburn 18401: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18402: if ($key eq 'reset') {
18403: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18404: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18405: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18406: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18407: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18408: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18409: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18410: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18411: }
1.354 raeburn 18412: } else {
18413: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18414: }
18415: if ($confighash{'passwords'}{'resetlink'}) {
18416: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18417: } else {
18418: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18419: &mt('Will default to 2 hours').'</li>';
18420: }
18421: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18422: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18423: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18424: } else {
18425: my $casesens;
18426: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18427: if ($type eq 'default') {
18428: $casesens .= $othertitle.', ';
18429: } elsif ($usertypes->{$type} ne '') {
18430: $casesens .= $usertypes->{$type}.', ';
18431: }
18432: }
18433: $casesens =~ s/\Q, \E$//;
18434: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18435: }
18436: } else {
18437: $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>';
18438: }
18439: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18440: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18441: } else {
18442: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18443: }
18444: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18445: my $output;
18446: if (ref($types) eq 'ARRAY') {
18447: foreach my $type (@{$types}) {
18448: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18449: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18450: $output .= $usertypes->{$type}.' -- '.&mt('none');
18451: } else {
18452: $output .= $usertypes->{$type}.' -- '.
18453: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18454: }
18455: }
18456: }
18457: }
18458: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18459: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18460: $output .= $othertitle.' -- '.&mt('none');
18461: } else {
18462: $output .= $othertitle.' -- '.
18463: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18464: }
18465: }
18466: if ($output) {
18467: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18468: } else {
18469: $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>';
18470: }
18471: } else {
18472: $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>';
18473: }
18474: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18475: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18476: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18477: } else {
18478: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18479: }
18480: } else {
1.379 raeburn 18481: $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 18482: }
18483: if ($confighash{'passwords'}{'resetremove'}) {
18484: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18485: } else {
18486: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18487: }
18488: if ($confighash{'passwords'}{'resetcustom'}) {
18489: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18490: &mt('custom text'),600,500,undef,undef,
18491: undef,undef,'background-color:#ffffff');
18492: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18493: } else {
18494: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18495: }
18496: } elsif ($key eq 'intauth') {
18497: foreach my $item ('cost','switch','check') {
18498: my $value = $save_defaults{$key.'_'.$item};
18499: if ($item eq 'switch') {
18500: my %optiondesc = &Apache::lonlocal::texthash (
18501: 0 => 'No',
18502: 1 => 'Yes',
18503: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18504: );
18505: if ($value =~ /^(0|1|2)$/) {
18506: $value = $optiondesc{$value};
18507: } else {
18508: $value = &mt('none -- defaults to No');
18509: }
18510: } elsif ($item eq 'check') {
18511: my %optiondesc = &Apache::lonlocal::texthash (
18512: 0 => 'No',
18513: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18514: 2 => 'Yes, disallow login if stored cost is less than domain default',
18515: );
18516: if ($value =~ /^(0|1|2)$/) {
18517: $value = $optiondesc{$value};
18518: } else {
18519: $value = &mt('none -- defaults to No');
18520: }
18521: }
18522: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18523: }
18524: } elsif ($key eq 'rules') {
1.356 raeburn 18525: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18526: if ($confighash{'passwords'}{$rule} eq '') {
18527: if ($rule eq 'min') {
1.356 raeburn 18528: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18529: ' '.&mt('Default of [_1] will be used',
18530: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18531: } else {
18532: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18533: }
18534: } else {
18535: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18536: }
18537: }
1.370 raeburn 18538: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18539: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18540: my %rulenames = &Apache::lonlocal::texthash(
18541: uc => 'At least one upper case letter',
18542: lc => 'At least one lower case letter',
18543: num => 'At least one number',
18544: spec => 'At least one non-alphanumeric',
18545: );
18546: my $needed = '<ul><li>'.
18547: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
18548: '</li></ul>';
18549: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18550: } else {
18551: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18552: }
18553: } else {
18554: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18555: }
1.354 raeburn 18556: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18557: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18558: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18559: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18560: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18561: } else {
18562: my %crsownerstr;
18563: foreach my $item ('by','for') {
18564: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18565: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18566: if ($type eq 'default') {
18567: $crsownerstr{$item} .= $othertitle.', ';
18568: } elsif ($usertypes->{$type} ne '') {
18569: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18570: }
18571: }
18572: $crsownerstr{$item} =~ s/\Q, \E$//;
18573: }
18574: }
18575: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18576: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18577: }
1.354 raeburn 18578: } else {
1.359 raeburn 18579: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18580: }
18581: }
18582: $resulttext .= '</ul></li>';
18583: }
18584: }
18585: $resulttext .= '</ul>';
18586: } else {
18587: $resulttext = &mt('No changes made to password settings');
18588: }
1.355 raeburn 18589: my $cachetime = 24*60*60;
1.354 raeburn 18590: if ($updatedefaults) {
18591: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18592: if (ref($lastactref) eq 'HASH') {
18593: $lastactref->{'domdefaults'} = 1;
18594: }
18595: }
1.355 raeburn 18596: if ($updateconf) {
18597: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18598: if (ref($lastactref) eq 'HASH') {
18599: $lastactref->{'passwdconf'} = 1;
18600: }
18601: }
1.354 raeburn 18602: } else {
18603: $resulttext = '<span class="LC_error">'.
18604: &mt('An error occurred: [_1]',$putresult).'</span>';
18605: }
18606: if ($errors) {
18607: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18608: $errors.'</ul></p>';
18609: }
18610: return $resulttext;
18611: }
18612:
1.405 raeburn 18613: sub password_rule_changes {
18614: my ($prefix,$newvalues,$current,$changes) = @_;
18615: return unless ((ref($newvalues) eq 'HASH') &&
18616: (ref($current) eq 'HASH') &&
18617: (ref($changes) eq 'HASH'));
18618: my (@rules,%staticdefaults);
18619: if ($prefix eq 'passwords') {
18620: @rules = ('min','max','expire','numsaved');
18621: } elsif ($prefix eq 'secrets') {
18622: @rules = ('min','max');
18623: }
18624: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18625: foreach my $rule (@rules) {
18626: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18627: my $ruleok;
18628: if ($rule eq 'expire') {
18629: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18630: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18631: $ruleok = 1;
18632: }
18633: } elsif ($rule eq 'min') {
18634: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18635: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18636: $ruleok = 1;
18637: }
18638: }
18639: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18640: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18641: $ruleok = 1;
18642: }
18643: if ($ruleok) {
18644: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18645: if (exists($current->{$rule})) {
18646: if ($newvalues->{$rule} ne $current->{$rule}) {
18647: $changes->{'rules'} = 1;
18648: }
18649: } elsif ($rule eq 'min') {
18650: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18651: $changes->{'rules'} = 1;
18652: }
18653: } else {
18654: $changes->{'rules'} = 1;
18655: }
18656: } elsif (exists($current->{$rule})) {
18657: $changes->{'rules'} = 1;
18658: }
18659: }
18660: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18661: my @chars;
18662: foreach my $item (sort(@posschars)) {
18663: if ($item =~ /^(uc|lc|num|spec)$/) {
18664: push(@chars,$item);
18665: }
18666: }
18667: $newvalues->{'chars'} = \@chars;
18668: unless ($changes->{'rules'}) {
18669: if (ref($current->{'chars'}) eq 'ARRAY') {
18670: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18671: if (@diffs > 0) {
18672: $changes->{'rules'} = 1;
18673: }
18674: } else {
18675: if (@chars > 0) {
18676: $changes->{'rules'} = 1;
18677: }
18678: }
18679: }
18680: return;
18681: }
18682:
1.28 raeburn 18683: sub modify_usercreation {
1.27 raeburn 18684: my ($dom,%domconfig) = @_;
1.224 raeburn 18685: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18686: my $warningmsg;
1.27 raeburn 18687: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18688: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18689: if ($key eq 'cancreate') {
18690: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18691: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18692: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18693: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18694: } else {
1.224 raeburn 18695: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18696: }
18697: }
18698: }
18699: } elsif ($key eq 'email_rule') {
18700: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18701: } else {
18702: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18703: }
1.27 raeburn 18704: }
18705: }
18706: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18707: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18708: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18709: foreach my $item(@contexts) {
1.224 raeburn 18710: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18711: }
1.34 raeburn 18712: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18713: foreach my $item (@contexts) {
1.224 raeburn 18714: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18715: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18716: }
1.27 raeburn 18717: }
1.34 raeburn 18718: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18719: foreach my $item (@contexts) {
1.43 raeburn 18720: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18721: if ($cancreate{$item} ne 'any') {
18722: push(@{$changes{'cancreate'}},$item);
18723: }
18724: } else {
18725: if ($cancreate{$item} ne 'none') {
18726: push(@{$changes{'cancreate'}},$item);
18727: }
1.27 raeburn 18728: }
18729: }
18730: } else {
1.43 raeburn 18731: foreach my $item (@contexts) {
1.34 raeburn 18732: push(@{$changes{'cancreate'}},$item);
18733: }
1.27 raeburn 18734: }
1.34 raeburn 18735:
1.27 raeburn 18736: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18737: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18738: if (!grep(/^\Q$type\E$/,@username_rule)) {
18739: push(@{$changes{'username_rule'}},$type);
18740: }
18741: }
18742: foreach my $type (@username_rule) {
18743: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18744: push(@{$changes{'username_rule'}},$type);
18745: }
18746: }
18747: } else {
18748: push(@{$changes{'username_rule'}},@username_rule);
18749: }
18750:
1.32 raeburn 18751: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18752: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18753: if (!grep(/^\Q$type\E$/,@id_rule)) {
18754: push(@{$changes{'id_rule'}},$type);
18755: }
18756: }
18757: foreach my $type (@id_rule) {
18758: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18759: push(@{$changes{'id_rule'}},$type);
18760: }
18761: }
18762: } else {
18763: push(@{$changes{'id_rule'}},@id_rule);
18764: }
18765:
1.43 raeburn 18766: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18767: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18768: my %authhash;
1.43 raeburn 18769: foreach my $item (@authen_contexts) {
1.28 raeburn 18770: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18771: foreach my $auth (@authtypes) {
18772: if (grep(/^\Q$auth\E$/,@authallowed)) {
18773: $authhash{$item}{$auth} = 1;
18774: } else {
18775: $authhash{$item}{$auth} = 0;
18776: }
18777: }
18778: }
18779: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18780: foreach my $item (@authen_contexts) {
1.28 raeburn 18781: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18782: foreach my $auth (@authtypes) {
18783: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18784: push(@{$changes{'authtypes'}},$item);
18785: last;
18786: }
18787: }
18788: }
18789: }
18790: } else {
1.43 raeburn 18791: foreach my $item (@authen_contexts) {
1.28 raeburn 18792: push(@{$changes{'authtypes'}},$item);
18793: }
18794: }
18795:
1.224 raeburn 18796: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18797: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18798: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18799: $save_usercreate{'id_rule'} = \@id_rule;
18800: $save_usercreate{'username_rule'} = \@username_rule,
18801: $save_usercreate{'authtypes'} = \%authhash;
18802:
1.27 raeburn 18803: my %usercreation_hash = (
1.224 raeburn 18804: usercreation => \%save_usercreate,
18805: );
1.27 raeburn 18806:
18807: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18808: $dom);
1.50 raeburn 18809:
1.224 raeburn 18810: if ($putresult eq 'ok') {
18811: if (keys(%changes) > 0) {
18812: $resulttext = &mt('Changes made:').'<ul>';
18813: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18814: my %lt = &usercreation_types();
18815: foreach my $type (@{$changes{'cancreate'}}) {
18816: my $chgtext = $lt{$type}.', ';
18817: if ($cancreate{$type} eq 'none') {
18818: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18819: } elsif ($cancreate{$type} eq 'any') {
18820: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18821: } elsif ($cancreate{$type} eq 'official') {
18822: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18823: } elsif ($cancreate{$type} eq 'unofficial') {
18824: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18825: }
18826: $resulttext .= '<li>'.$chgtext.'</li>';
18827: }
18828: }
18829: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18830: my ($rules,$ruleorder) =
18831: &Apache::lonnet::inst_userrules($dom,'username');
18832: my $chgtext = '<ul>';
18833: foreach my $type (@username_rule) {
18834: if (ref($rules->{$type}) eq 'HASH') {
18835: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18836: }
18837: }
18838: $chgtext .= '</ul>';
18839: if (@username_rule > 0) {
18840: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18841: } else {
18842: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18843: }
18844: }
18845: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18846: my ($idrules,$idruleorder) =
18847: &Apache::lonnet::inst_userrules($dom,'id');
18848: my $chgtext = '<ul>';
18849: foreach my $type (@id_rule) {
18850: if (ref($idrules->{$type}) eq 'HASH') {
18851: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18852: }
18853: }
18854: $chgtext .= '</ul>';
18855: if (@id_rule > 0) {
18856: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18857: } else {
18858: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18859: }
18860: }
18861: my %authname = &authtype_names();
18862: my %context_title = &context_names();
18863: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18864: my $chgtext = '<ul>';
18865: foreach my $type (@{$changes{'authtypes'}}) {
18866: my @allowed;
18867: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18868: foreach my $auth (@authtypes) {
18869: if ($authhash{$type}{$auth}) {
18870: push(@allowed,$authname{$auth});
18871: }
18872: }
18873: if (@allowed > 0) {
18874: $chgtext .= join(', ',@allowed).'</li>';
18875: } else {
18876: $chgtext .= &mt('none').'</li>';
18877: }
18878: }
18879: $chgtext .= '</ul>';
18880: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18881: $resulttext .= '</li>';
18882: }
18883: $resulttext .= '</ul>';
18884: } else {
18885: $resulttext = &mt('No changes made to user creation settings');
18886: }
18887: } else {
18888: $resulttext = '<span class="LC_error">'.
18889: &mt('An error occurred: [_1]',$putresult).'</span>';
18890: }
18891: if ($warningmsg ne '') {
18892: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18893: }
18894: return $resulttext;
18895: }
18896:
18897: sub modify_selfcreation {
1.305 raeburn 18898: my ($dom,$lastactref,%domconfig) = @_;
18899: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18900: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18901: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18902: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18903: if (ref($typesref) eq 'ARRAY') {
18904: @types = @{$typesref};
18905: }
18906: if (ref($usertypesref) eq 'HASH') {
18907: %usertypes = %{$usertypesref};
1.228 raeburn 18908: }
1.303 raeburn 18909: $usertypes{'default'} = $othertitle;
1.224 raeburn 18910: #
18911: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18912: #
18913: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18914: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18915: if ($key eq 'cancreate') {
18916: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18917: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18918: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18919: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18920: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18921: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18922: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18923: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18924: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18925: } else {
18926: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18927: }
18928: }
18929: }
18930: } elsif ($key eq 'email_rule') {
18931: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18932: } else {
18933: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18934: }
18935: }
18936: }
18937: #
18938: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18939: #
18940: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18941: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18942: if ($key eq 'selfcreate') {
18943: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18944: } else {
18945: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18946: }
18947: }
18948: }
1.305 raeburn 18949: #
18950: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18951: #
18952: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18953: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18954: if ($key eq 'inststatusguest') {
18955: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18956: } else {
18957: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18958: }
18959: }
18960: }
1.224 raeburn 18961:
18962: my @contexts = ('selfcreate');
18963: @{$cancreate{'selfcreate'}} = ();
18964: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18965: if (@types) {
18966: @{$cancreate{'statustocreate'}} = ();
18967: }
1.236 raeburn 18968: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18969: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18970: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18971: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18972: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18973: my %selfcreatetypes = (
18974: sso => 'users authenticated by institutional single sign on',
18975: login => 'users authenticated by institutional log-in',
1.303 raeburn 18976: email => 'users verified by e-mail',
1.50 raeburn 18977: );
1.224 raeburn 18978: #
18979: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18980: # is permitted.
18981: #
1.305 raeburn 18982: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18983:
1.305 raeburn 18984: my (@statuses,%email_rule);
1.228 raeburn 18985: foreach my $item ('login','sso','email') {
1.224 raeburn 18986: if ($item eq 'email') {
1.236 raeburn 18987: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18988: if (@types) {
18989: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18990: foreach my $status (@poss_statuses) {
18991: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18992: push(@statuses,$status);
18993: }
18994: }
18995: $save_inststatus{'inststatusguest'} = \@statuses;
18996: } else {
18997: push(@statuses,'default');
18998: }
18999: if (@statuses) {
19000: my %curr_rule;
19001: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19002: foreach my $type (@statuses) {
19003: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19004: }
1.305 raeburn 19005: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19006: foreach my $type (@statuses) {
19007: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19008: }
19009: }
19010: push(@{$cancreate{'selfcreate'}},'email');
19011: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19012: my %curremaildom;
19013: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19014: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19015: }
19016: foreach my $type (@statuses) {
19017: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19018: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19019: }
19020: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19021: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19022: }
19023: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19024: #
19025: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19026: #
19027: my $chosen = $1;
19028: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19029: my $emaildom;
19030: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
19031: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
19032: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19033: if (ref($curremaildom{$type}) eq 'HASH') {
19034: if (exists($curremaildom{$type}{$chosen})) {
19035: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19036: push(@{$changes{'cancreate'}},'emaildomain');
19037: }
19038: } elsif ($emaildom ne '') {
19039: push(@{$changes{'cancreate'}},'emaildomain');
19040: }
19041: } elsif ($emaildom ne '') {
19042: push(@{$changes{'cancreate'}},'emaildomain');
19043: }
19044: }
19045: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19046: } elsif ($chosen eq 'custom') {
19047: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19048: $email_rule{$type} = [];
19049: if (ref($emailrules) eq 'HASH') {
19050: foreach my $rule (@possemail_rules) {
19051: if (exists($emailrules->{$rule})) {
19052: push(@{$email_rule{$type}},$rule);
19053: }
19054: }
19055: }
19056: if (@{$email_rule{$type}}) {
19057: $cancreate{'emailoptions'}{$type} = 'custom';
19058: if (ref($curr_rule{$type}) eq 'ARRAY') {
19059: if (@{$curr_rule{$type}} > 0) {
19060: foreach my $rule (@{$curr_rule{$type}}) {
19061: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19062: push(@{$changes{'email_rule'}},$type);
19063: }
19064: }
19065: }
19066: foreach my $type (@{$email_rule{$type}}) {
19067: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19068: push(@{$changes{'email_rule'}},$type);
19069: }
19070: }
19071: } else {
19072: push(@{$changes{'email_rule'}},$type);
19073: }
19074: }
19075: } else {
19076: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19077: }
19078: }
19079: }
19080: if (@types) {
19081: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19082: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19083: if (@changed) {
19084: push(@{$changes{'inststatus'}},'inststatusguest');
19085: }
19086: } else {
19087: push(@{$changes{'inststatus'}},'inststatusguest');
19088: }
19089: }
19090: } else {
19091: delete($env{'form.cancreate_email'});
19092: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19093: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19094: push(@{$changes{'inststatus'}},'inststatusguest');
19095: }
19096: }
19097: }
19098: } else {
19099: $save_inststatus{'inststatusguest'} = [];
19100: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19101: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19102: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19103: }
19104: }
1.224 raeburn 19105: }
19106: } else {
19107: if ($env{'form.cancreate_'.$item}) {
19108: push(@{$cancreate{'selfcreate'}},$item);
19109: }
19110: }
19111: }
1.305 raeburn 19112: my (%userinfo,%savecaptcha);
1.224 raeburn 19113: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19114: #
1.228 raeburn 19115: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19116: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19117: #
1.236 raeburn 19118:
1.244 raeburn 19119: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19120: push(@contexts,'emailusername');
1.305 raeburn 19121: if (@statuses) {
19122: foreach my $type (@statuses) {
1.228 raeburn 19123: if (ref($infofields) eq 'ARRAY') {
19124: foreach my $field (@{$infofields}) {
19125: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19126: $cancreate{'emailusername'}{$type}{$field} = $1;
19127: }
19128: }
1.224 raeburn 19129: }
19130: }
19131: }
19132: #
19133: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19134: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19135: #
19136:
19137: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19138: @approvalnotify = sort(@approvalnotify);
19139: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19140: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19141: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19142: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19143: push(@{$changes{'cancreate'}},'notify');
19144: }
19145: } else {
19146: if ($cancreate{'notify'}{'approval'}) {
19147: push(@{$changes{'cancreate'}},'notify');
19148: }
19149: }
19150: } elsif ($cancreate{'notify'}{'approval'}) {
19151: push(@{$changes{'cancreate'}},'notify');
19152: }
19153:
19154: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19155: }
19156: #
1.236 raeburn 19157: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19158: # institutional log-in.
19159: #
19160: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19161: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19162: ($domdefaults{'auth_def'} eq 'localauth'))) {
19163: $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.').' '.
19164: &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.');
19165: }
19166: }
19167: my @fields = ('lastname','firstname','middlename','generation',
19168: 'permanentemail','id');
1.240 raeburn 19169: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19170: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19171: #
19172: # Where usernames may created for institutional log-in and/or institutional single sign on:
19173: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19174: # may self-create accounts
19175: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19176: # which the user may supply, if institutional data is unavailable.
19177: #
19178: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19179: if (@types) {
1.305 raeburn 19180: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19181: push(@contexts,'statustocreate');
1.303 raeburn 19182: foreach my $type (@types) {
1.224 raeburn 19183: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19184: foreach my $field (@fields) {
19185: if (grep(/^\Q$field\E$/,@modifiable)) {
19186: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19187: } else {
19188: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19189: }
19190: }
19191: }
19192: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19193: foreach my $type (@types) {
1.224 raeburn 19194: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19195: foreach my $field (@fields) {
19196: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19197: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19198: push(@{$changes{'selfcreate'}},$type);
19199: last;
19200: }
19201: }
19202: }
19203: }
19204: } else {
1.303 raeburn 19205: foreach my $type (@types) {
1.224 raeburn 19206: push(@{$changes{'selfcreate'}},$type);
19207: }
19208: }
19209: }
1.240 raeburn 19210: foreach my $field (@shibfields) {
19211: if ($env{'form.shibenv_'.$field} ne '') {
19212: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19213: }
19214: }
19215: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19216: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19217: foreach my $field (@shibfields) {
19218: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19219: push(@{$changes{'cancreate'}},'shibenv');
19220: }
19221: }
19222: } else {
19223: foreach my $field (@shibfields) {
19224: if ($env{'form.shibenv_'.$field}) {
19225: push(@{$changes{'cancreate'}},'shibenv');
19226: last;
19227: }
19228: }
19229: }
19230: }
1.224 raeburn 19231: }
19232: foreach my $item (@contexts) {
19233: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19234: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19235: if (ref($cancreate{$item}) eq 'ARRAY') {
19236: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19237: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19238: push(@{$changes{'cancreate'}},$item);
19239: }
19240: }
19241: }
19242: }
19243: if (ref($cancreate{$item}) eq 'ARRAY') {
19244: foreach my $type (@{$cancreate{$item}}) {
19245: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19246: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19247: push(@{$changes{'cancreate'}},$item);
19248: }
19249: }
19250: }
19251: }
19252: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19253: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19254: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19255: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19256: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19257: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19258: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19259: push(@{$changes{'cancreate'}},$item);
19260: }
19261: }
19262: }
1.305 raeburn 19263: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19264: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19265: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19266: push(@{$changes{'cancreate'}},$item);
19267: }
1.224 raeburn 19268: }
19269: }
19270: }
1.305 raeburn 19271: foreach my $type (keys(%{$cancreate{$item}})) {
19272: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19273: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19274: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19275: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19276: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19277: push(@{$changes{'cancreate'}},$item);
19278: }
19279: }
19280: } else {
19281: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19282: push(@{$changes{'cancreate'}},$item);
19283: }
19284: }
19285: }
1.305 raeburn 19286: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19287: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19288: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19289: push(@{$changes{'cancreate'}},$item);
19290: }
1.224 raeburn 19291: }
19292: }
19293: }
19294: }
19295: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19296: if (ref($cancreate{$item}) eq 'ARRAY') {
19297: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19298: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19299: push(@{$changes{'cancreate'}},$item);
19300: }
19301: }
1.305 raeburn 19302: }
19303: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19304: if (ref($cancreate{$item}) eq 'HASH') {
19305: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19306: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19307: }
19308: }
19309: } elsif ($item eq 'emailusername') {
1.228 raeburn 19310: if (ref($cancreate{$item}) eq 'HASH') {
19311: foreach my $type (keys(%{$cancreate{$item}})) {
19312: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19313: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19314: if ($cancreate{$item}{$type}{$field}) {
19315: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19316: push(@{$changes{'cancreate'}},$item);
19317: }
19318: last;
19319: }
19320: }
19321: }
19322: }
1.224 raeburn 19323: }
19324: }
19325: }
19326: #
19327: # Populate %save_usercreate hash with updates to self-creation configuration.
19328: #
19329: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19330: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19331: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19332: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19333: if (ref($cancreate{'notify'}) eq 'HASH') {
19334: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19335: }
1.236 raeburn 19336: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19337: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19338: }
1.303 raeburn 19339: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19340: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19341: }
1.305 raeburn 19342: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19343: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19344: }
1.303 raeburn 19345: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19346: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19347: }
1.224 raeburn 19348: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19349: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19350: }
1.240 raeburn 19351: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19352: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19353: }
1.224 raeburn 19354: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19355: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19356:
19357: my %userconfig_hash = (
19358: usercreation => \%save_usercreate,
19359: usermodification => \%save_usermodify,
1.305 raeburn 19360: inststatus => \%save_inststatus,
1.224 raeburn 19361: );
1.305 raeburn 19362:
1.224 raeburn 19363: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19364: $dom);
19365: #
1.305 raeburn 19366: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19367: #
1.27 raeburn 19368: if ($putresult eq 'ok') {
19369: if (keys(%changes) > 0) {
19370: $resulttext = &mt('Changes made:').'<ul>';
19371: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19372: my %lt = &selfcreation_types();
1.34 raeburn 19373: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19374: my $chgtext = '';
1.45 raeburn 19375: if ($type eq 'selfcreate') {
1.50 raeburn 19376: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19377: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19378: } else {
1.224 raeburn 19379: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19380: '<ul>';
1.50 raeburn 19381: foreach my $case (@{$cancreate{$type}}) {
19382: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19383: }
19384: $chgtext .= '</ul>';
1.100 raeburn 19385: if (ref($cancreate{$type}) eq 'ARRAY') {
19386: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19387: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19388: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19389: $chgtext .= '<span class="LC_warning">'.
19390: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19391: '</span><br />';
19392: }
19393: }
19394: }
19395: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19396: if (!@statuses) {
19397: $chgtext .= '<span class="LC_warning">'.
19398: &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.").
19399: '</span><br />';
1.303 raeburn 19400:
1.100 raeburn 19401: }
19402: }
19403: }
1.43 raeburn 19404: }
1.240 raeburn 19405: } elsif ($type eq 'shibenv') {
19406: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19407: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19408: } else {
19409: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19410: '<ul>';
19411: foreach my $field (@shibfields) {
19412: next if ($cancreate{$type}{$field} eq '');
19413: if ($field eq 'inststatus') {
19414: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19415: } else {
19416: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19417: }
19418: }
19419: $chgtext .= '</ul>';
1.303 raeburn 19420: }
1.93 raeburn 19421: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19422: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19423: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19424: if (@{$cancreate{'selfcreate'}} > 0) {
19425: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19426: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19427: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19428: $chgtext .= '<br />'.
19429: '<span class="LC_warning">'.
19430: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19431: '</span>';
19432: }
1.303 raeburn 19433: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19434: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19435: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19436: } else {
19437: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19438: }
19439: $chgtext .= '<ul>';
19440: foreach my $case (@{$cancreate{$type}}) {
19441: if ($case eq 'default') {
19442: $chgtext .= '<li>'.$othertitle.'</li>';
19443: } else {
1.303 raeburn 19444: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19445: }
19446: }
1.100 raeburn 19447: $chgtext .= '</ul>';
19448: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19449: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19450: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19451: '</span>';
1.100 raeburn 19452: }
19453: }
19454: } else {
19455: if (@{$cancreate{$type}} == 0) {
19456: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19457: } else {
19458: $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 19459: }
19460: }
1.303 raeburn 19461: $chgtext .= '<br />';
1.93 raeburn 19462: }
1.236 raeburn 19463: } elsif ($type eq 'selfcreateprocessing') {
19464: my %choices = &Apache::lonlocal::texthash (
19465: automatic => 'Automatic approval',
19466: approval => 'Queued for approval',
19467: );
1.305 raeburn 19468: if (@types) {
19469: if (@statuses) {
1.303 raeburn 19470: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19471: '<ul>';
1.305 raeburn 19472: foreach my $status (@statuses) {
19473: if ($status eq 'default') {
19474: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19475: } else {
1.305 raeburn 19476: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19477: }
19478: }
19479: $chgtext .= '</ul>';
19480: }
19481: } else {
19482: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19483: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19484: }
19485: } elsif ($type eq 'emailverified') {
19486: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19487: all => 'Same as e-mail',
19488: first => 'Omit @domain',
19489: free => 'Free to choose',
1.303 raeburn 19490: );
1.305 raeburn 19491: if (@types) {
19492: if (@statuses) {
1.303 raeburn 19493: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19494: '<ul>';
1.305 raeburn 19495: foreach my $status (@statuses) {
1.362 raeburn 19496: if ($status eq 'default') {
1.305 raeburn 19497: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19498: } else {
1.305 raeburn 19499: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19500: }
19501: }
19502: $chgtext .= '</ul>';
19503: }
19504: } else {
1.305 raeburn 19505: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19506: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19507: }
1.305 raeburn 19508: } elsif ($type eq 'emailoptions') {
19509: my %options = &Apache::lonlocal::texthash (
19510: any => 'Any e-mail',
19511: inst => 'Institutional only',
19512: noninst => 'Non-institutional only',
19513: custom => 'Custom restrictions',
19514: );
19515: if (@types) {
19516: if (@statuses) {
19517: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19518: '<ul>';
19519: foreach my $status (@statuses) {
19520: if ($type eq 'default') {
19521: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19522: } else {
19523: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19524: }
19525: }
1.305 raeburn 19526: $chgtext .= '</ul>';
19527: }
19528: } else {
19529: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19530: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19531: } else {
19532: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19533: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19534: }
1.305 raeburn 19535: }
19536: } elsif ($type eq 'emaildomain') {
19537: my $output;
19538: if (@statuses) {
19539: foreach my $type (@statuses) {
19540: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19541: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19542: if ($type eq 'default') {
19543: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19544: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19545: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19546: } else {
19547: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19548: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19549: }
1.303 raeburn 19550: } else {
1.305 raeburn 19551: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19552: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19553: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19554: } else {
19555: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
19556: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19557: }
1.303 raeburn 19558: }
1.305 raeburn 19559: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19560: if ($type eq 'default') {
19561: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19562: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19563: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19564: } else {
19565: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19566: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19567: }
1.303 raeburn 19568: } else {
1.305 raeburn 19569: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19570: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19571: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19572: } else {
19573: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
19574: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19575: }
1.303 raeburn 19576: }
19577: }
19578: }
19579: }
1.305 raeburn 19580: }
19581: if ($output ne '') {
19582: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19583: '<ul>'.$output.'</ul>';
1.236 raeburn 19584: }
1.165 raeburn 19585: } elsif ($type eq 'captcha') {
1.224 raeburn 19586: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19587: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19588: } else {
19589: my %captchas = &captcha_phrases();
1.224 raeburn 19590: if ($captchas{$savecaptcha{$type}}) {
19591: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19592: } else {
1.210 raeburn 19593: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19594: }
19595: }
19596: } elsif ($type eq 'recaptchakeys') {
19597: my ($privkey,$pubkey);
1.224 raeburn 19598: if (ref($savecaptcha{$type}) eq 'HASH') {
19599: $pubkey = $savecaptcha{$type}{'public'};
19600: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19601: }
19602: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19603: if (!$pubkey) {
19604: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19605: } else {
19606: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19607: }
19608: if (!$privkey) {
19609: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19610: } else {
19611: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19612: }
19613: $chgtext .= '</ul>';
1.269 raeburn 19614: } elsif ($type eq 'recaptchaversion') {
19615: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19616: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19617: }
1.224 raeburn 19618: } elsif ($type eq 'emailusername') {
19619: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19620: if (@statuses) {
19621: foreach my $type (@statuses) {
1.228 raeburn 19622: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19623: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19624: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19625: '<ul>';
19626: foreach my $field (@{$infofields}) {
19627: if ($cancreate{'emailusername'}{$type}{$field}) {
19628: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19629: }
19630: }
1.245 raeburn 19631: $chgtext .= '</ul>';
19632: } else {
1.303 raeburn 19633: $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 19634: }
19635: } else {
1.303 raeburn 19636: $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 19637: }
19638: }
19639: }
19640: }
19641: } elsif ($type eq 'notify') {
1.303 raeburn 19642: my $numapprove = 0;
1.224 raeburn 19643: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19644: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19645: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19646: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19647: $numapprove ++;
1.224 raeburn 19648: }
19649: }
1.43 raeburn 19650: }
1.303 raeburn 19651: unless ($numapprove) {
19652: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19653: }
1.34 raeburn 19654: }
1.224 raeburn 19655: if ($chgtext) {
19656: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19657: }
19658: }
19659: }
1.305 raeburn 19660: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19661: my ($emailrules,$emailruleorder) =
19662: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19663: foreach my $type (@{$changes{'email_rule'}}) {
19664: if (ref($email_rule{$type}) eq 'ARRAY') {
19665: my $chgtext = '<ul>';
19666: foreach my $rule (@{$email_rule{$type}}) {
19667: if (ref($emailrules->{$rule}) eq 'HASH') {
19668: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19669: }
19670: }
19671: $chgtext .= '</ul>';
1.310 raeburn 19672: my $typename;
1.305 raeburn 19673: if (@types) {
19674: if ($type eq 'default') {
19675: $typename = $othertitle;
19676: } else {
19677: $typename = $usertypes{$type};
19678: }
19679: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19680: }
19681: if (@{$email_rule{$type}} > 0) {
19682: $resulttext .= '<li>'.
19683: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19684: $usertypes{$type}).
19685: $chgtext.
19686: '</li>';
19687: } else {
19688: $resulttext .= '<li>'.
1.310 raeburn 19689: &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 19690: '</li>'.
1.310 raeburn 19691: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19692: }
1.43 raeburn 19693: }
19694: }
1.305 raeburn 19695: }
19696: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19697: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19698: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19699: my $chgtext = '<ul>';
19700: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19701: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19702: }
19703: $chgtext .= '</ul>';
19704: $resulttext .= '<li>'.
19705: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19706: $chgtext.
19707: '</li>';
19708: } else {
19709: $resulttext .= '<li>'.
19710: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19711: '</li>';
19712: }
1.43 raeburn 19713: }
19714: }
1.224 raeburn 19715: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19716: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19717: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19718: foreach my $type (@{$changes{'selfcreate'}}) {
19719: my $typename = $type;
1.303 raeburn 19720: if (keys(%usertypes) > 0) {
19721: if ($usertypes{$type} ne '') {
19722: $typename = $usertypes{$type};
1.224 raeburn 19723: }
19724: }
19725: my @modifiable;
19726: $resulttext .= '<li>'.
19727: &mt('Self-creation of account by users with status: [_1]',
19728: '<span class="LC_cusr_emph">'.$typename.'</span>').
19729: ' - '.&mt('modifiable fields (if institutional data blank): ');
19730: foreach my $field (@fields) {
19731: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19732: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19733: }
19734: }
1.224 raeburn 19735: if (@modifiable > 0) {
19736: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19737: } else {
1.224 raeburn 19738: $resulttext .= &mt('none');
1.43 raeburn 19739: }
1.224 raeburn 19740: $resulttext .= '</li>';
1.28 raeburn 19741: }
1.224 raeburn 19742: $resulttext .= '</ul></li>';
1.28 raeburn 19743: }
1.27 raeburn 19744: $resulttext .= '</ul>';
1.305 raeburn 19745: my $cachetime = 24*60*60;
19746: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19747: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19748: if (ref($lastactref) eq 'HASH') {
19749: $lastactref->{'domdefaults'} = 1;
19750: }
1.27 raeburn 19751: } else {
1.224 raeburn 19752: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19753: }
19754: } else {
19755: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19756: &mt('An error occurred: [_1]',$putresult).'</span>';
19757: }
1.43 raeburn 19758: if ($warningmsg ne '') {
19759: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19760: }
1.23 raeburn 19761: return $resulttext;
19762: }
19763:
1.165 raeburn 19764: sub process_captcha {
1.369 raeburn 19765: my ($container,$changes,$newsettings,$currsettings) = @_;
19766: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19767: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19768: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19769: $newsettings->{'captcha'} = 'original';
19770: }
1.369 raeburn 19771: my %current;
19772: if (ref($currsettings) eq 'HASH') {
19773: %current = %{$currsettings};
19774: }
19775: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19776: if ($container eq 'cancreate') {
1.169 raeburn 19777: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19778: push(@{$changes->{'cancreate'}},'captcha');
19779: } elsif (!defined($changes->{'cancreate'})) {
19780: $changes->{'cancreate'} = ['captcha'];
19781: }
1.368 raeburn 19782: } elsif ($container eq 'passwords') {
19783: $changes->{'reset'} = 1;
1.169 raeburn 19784: } else {
19785: $changes->{'captcha'} = 1;
1.165 raeburn 19786: }
19787: }
1.269 raeburn 19788: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19789: if ($newsettings->{'captcha'} eq 'recaptcha') {
19790: $newpub = $env{'form.'.$container.'_recaptchapub'};
19791: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19792: $newpub =~ s/[^\w\-]//g;
19793: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19794: $newsettings->{'recaptchakeys'} = {
19795: public => $newpub,
19796: private => $newpriv,
19797: };
1.269 raeburn 19798: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19799: $newversion =~ s/\D//g;
19800: if ($newversion ne '2') {
19801: $newversion = 1;
19802: }
19803: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19804: }
1.369 raeburn 19805: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19806: $currpub = $current{'recaptchakeys'}{'public'};
19807: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19808: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19809: $newsettings->{'recaptchakeys'} = {
19810: public => '',
19811: private => '',
19812: }
19813: }
1.165 raeburn 19814: }
1.369 raeburn 19815: if ($current{'captcha'} eq 'recaptcha') {
19816: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19817: if ($currversion ne '2') {
19818: $currversion = 1;
19819: }
19820: }
19821: if ($currversion ne $newversion) {
19822: if ($container eq 'cancreate') {
19823: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19824: push(@{$changes->{'cancreate'}},'recaptchaversion');
19825: } elsif (!defined($changes->{'cancreate'})) {
19826: $changes->{'cancreate'} = ['recaptchaversion'];
19827: }
1.368 raeburn 19828: } elsif ($container eq 'passwords') {
19829: $changes->{'reset'} = 1;
1.269 raeburn 19830: } else {
19831: $changes->{'recaptchaversion'} = 1;
19832: }
19833: }
1.165 raeburn 19834: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19835: if ($container eq 'cancreate') {
19836: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19837: push(@{$changes->{'cancreate'}},'recaptchakeys');
19838: } elsif (!defined($changes->{'cancreate'})) {
19839: $changes->{'cancreate'} = ['recaptchakeys'];
19840: }
1.368 raeburn 19841: } elsif ($container eq 'passwords') {
19842: $changes->{'reset'} = 1;
1.169 raeburn 19843: } else {
1.210 raeburn 19844: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19845: }
19846: }
19847: return;
19848: }
19849:
1.33 raeburn 19850: sub modify_usermodification {
19851: my ($dom,%domconfig) = @_;
1.224 raeburn 19852: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19853: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19854: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19855: if ($key eq 'selfcreate') {
19856: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19857: } else {
19858: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19859: }
1.33 raeburn 19860: }
19861: }
1.224 raeburn 19862: my @contexts = ('author','course');
1.33 raeburn 19863: my %context_title = (
19864: author => 'In author context',
19865: course => 'In course context',
19866: );
19867: my @fields = ('lastname','firstname','middlename','generation',
19868: 'permanentemail','id');
19869: my %roles = (
19870: author => ['ca','aa'],
19871: course => ['st','ep','ta','in','cr'],
19872: );
19873: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19874: foreach my $context (@contexts) {
19875: foreach my $role (@{$roles{$context}}) {
19876: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19877: foreach my $item (@fields) {
19878: if (grep(/^\Q$item\E$/,@modifiable)) {
19879: $modifyhash{$context}{$role}{$item} = 1;
19880: } else {
19881: $modifyhash{$context}{$role}{$item} = 0;
19882: }
19883: }
19884: }
19885: if (ref($curr_usermodification{$context}) eq 'HASH') {
19886: foreach my $role (@{$roles{$context}}) {
19887: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19888: foreach my $field (@fields) {
19889: if ($modifyhash{$context}{$role}{$field} ne
19890: $curr_usermodification{$context}{$role}{$field}) {
19891: push(@{$changes{$context}},$role);
19892: last;
19893: }
19894: }
19895: }
19896: }
19897: } else {
19898: foreach my $context (@contexts) {
19899: foreach my $role (@{$roles{$context}}) {
19900: push(@{$changes{$context}},$role);
19901: }
19902: }
19903: }
19904: }
19905: my %usermodification_hash = (
19906: usermodification => \%modifyhash,
19907: );
19908: my $putresult = &Apache::lonnet::put_dom('configuration',
19909: \%usermodification_hash,$dom);
19910: if ($putresult eq 'ok') {
19911: if (keys(%changes) > 0) {
19912: $resulttext = &mt('Changes made: ').'<ul>';
19913: foreach my $context (@contexts) {
19914: if (ref($changes{$context}) eq 'ARRAY') {
19915: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19916: if (ref($changes{$context}) eq 'ARRAY') {
19917: foreach my $role (@{$changes{$context}}) {
19918: my $rolename;
1.224 raeburn 19919: if ($role eq 'cr') {
19920: $rolename = &mt('Custom');
1.33 raeburn 19921: } else {
1.224 raeburn 19922: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19923: }
19924: my @modifiable;
1.224 raeburn 19925: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19926: foreach my $field (@fields) {
19927: if ($modifyhash{$context}{$role}{$field}) {
19928: push(@modifiable,$fieldtitles{$field});
19929: }
19930: }
19931: if (@modifiable > 0) {
19932: $resulttext .= join(', ',@modifiable);
19933: } else {
19934: $resulttext .= &mt('none');
19935: }
19936: $resulttext .= '</li>';
19937: }
19938: $resulttext .= '</ul></li>';
19939: }
19940: }
19941: }
19942: $resulttext .= '</ul>';
19943: } else {
19944: $resulttext = &mt('No changes made to user modification settings');
19945: }
19946: } else {
19947: $resulttext = '<span class="LC_error">'.
19948: &mt('An error occurred: [_1]',$putresult).'</span>';
19949: }
19950: return $resulttext;
19951: }
19952:
1.43 raeburn 19953: sub modify_defaults {
1.212 raeburn 19954: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19955: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19956: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19957: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19958: 'portal_def');
1.325 raeburn 19959: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19960: foreach my $item (@items) {
19961: $newvalues{$item} = $env{'form.'.$item};
19962: if ($item eq 'auth_def') {
19963: if ($newvalues{$item} ne '') {
19964: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19965: push(@errors,$item);
19966: }
19967: }
19968: } elsif ($item eq 'lang_def') {
19969: if ($newvalues{$item} ne '') {
19970: if ($newvalues{$item} =~ /^(\w+)/) {
19971: my $langcode = $1;
1.103 raeburn 19972: if ($langcode ne 'x_chef') {
19973: if (code2language($langcode) eq '') {
19974: push(@errors,$item);
19975: }
1.43 raeburn 19976: }
19977: } else {
19978: push(@errors,$item);
19979: }
19980: }
1.54 raeburn 19981: } elsif ($item eq 'timezone_def') {
19982: if ($newvalues{$item} ne '') {
1.62 raeburn 19983: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19984: push(@errors,$item);
19985: }
19986: }
1.68 raeburn 19987: } elsif ($item eq 'datelocale_def') {
19988: if ($newvalues{$item} ne '') {
19989: my @datelocale_ids = DateTime::Locale->ids();
19990: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19991: push(@errors,$item);
19992: }
19993: }
1.141 raeburn 19994: } elsif ($item eq 'portal_def') {
19995: if ($newvalues{$item} ne '') {
19996: unless ($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])\/?$/) {
19997: push(@errors,$item);
19998: }
19999: }
1.43 raeburn 20000: }
20001: if (grep(/^\Q$item\E$/,@errors)) {
20002: $newvalues{$item} = $domdefaults{$item};
20003: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20004: $changes{$item} = 1;
20005: }
1.72 raeburn 20006: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20007: }
1.354 raeburn 20008: my %staticdefaults = (
20009: 'intauth_cost' => 10,
20010: 'intauth_check' => 0,
20011: 'intauth_switch' => 0,
20012: );
20013: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20014: if (exists($domdefaults{$item})) {
20015: $newvalues{$item} = $domdefaults{$item};
20016: } else {
20017: $newvalues{$item} = $staticdefaults{$item};
20018: }
20019: }
1.409 raeburn 20020: my ($unamemaprules,$ruleorder);
20021: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20022: if (@possunamemaprules) {
20023: ($unamemaprules,$ruleorder) =
20024: &Apache::lonnet::inst_userrules($dom,'unamemap');
20025: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20026: if (@{$ruleorder} > 0) {
20027: my %possrules;
20028: map { $possrules{$_} = 1; } @possunamemaprules;
20029: foreach my $rule (@{$ruleorder}) {
20030: if ($possrules{$rule}) {
20031: push(@{$newvalues{'unamemap_rule'}},$rule);
20032: }
20033: }
20034: }
20035: }
20036: }
20037: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20038: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20039: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20040: $newvalues{'unamemap_rule'});
20041: if (@rulediffs) {
20042: $changes{'unamemap_rule'} = 1;
20043: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20044: }
20045: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20046: $changes{'unamemap_rule'} = 1;
20047: delete($domdefaults{'unamemap_rule'});
20048: }
20049: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20050: if (@{$newvalues{'unamemap_rule'}} > 0) {
20051: $changes{'unamemap_rule'} = 1;
20052: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20053: }
20054: }
1.43 raeburn 20055: my %defaults_hash = (
1.72 raeburn 20056: defaults => \%newvalues,
20057: );
1.43 raeburn 20058: my $title = &defaults_titles();
1.236 raeburn 20059:
20060: my $currinststatus;
20061: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20062: $currinststatus = $domconfig{'inststatus'};
20063: } else {
20064: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20065: $currinststatus = {
20066: inststatustypes => $usertypes,
20067: inststatusorder => $types,
20068: inststatusguest => [],
20069: };
20070: }
20071: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20072: my @allpos;
20073: my %alltypes;
1.305 raeburn 20074: my @inststatusguest;
20075: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20076: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20077: unless (grep(/^\Q$type\E$/,@todelete)) {
20078: push(@inststatusguest,$type);
20079: }
20080: }
20081: }
20082: my ($currtitles,$currorder);
1.236 raeburn 20083: if (ref($currinststatus) eq 'HASH') {
20084: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20085: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20086: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20087: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20088: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20089: }
20090: }
20091: unless (grep(/^\Q$type\E$/,@todelete)) {
20092: my $position = $env{'form.inststatus_pos_'.$type};
20093: $position =~ s/\D+//g;
20094: $allpos[$position] = $type;
20095: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20096: $alltypes{$type} =~ s/`//g;
20097: }
20098: }
20099: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20100: $currtitles =~ s/,$//;
20101: }
20102: }
20103: if ($env{'form.addinststatus'}) {
20104: my $newtype = $env{'form.addinststatus'};
20105: $newtype =~ s/\W//g;
20106: unless (exists($alltypes{$newtype})) {
20107: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20108: $alltypes{$newtype} =~ s/`//g;
20109: my $position = $env{'form.addinststatus_pos'};
20110: $position =~ s/\D+//g;
20111: if ($position ne '') {
20112: $allpos[$position] = $newtype;
20113: }
20114: }
20115: }
1.305 raeburn 20116: my @orderedstatus;
1.236 raeburn 20117: foreach my $type (@allpos) {
20118: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20119: push(@orderedstatus,$type);
20120: }
20121: }
20122: foreach my $type (keys(%alltypes)) {
20123: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20124: delete($alltypes{$type});
20125: }
20126: }
20127: $defaults_hash{'inststatus'} = {
20128: inststatustypes => \%alltypes,
20129: inststatusorder => \@orderedstatus,
1.305 raeburn 20130: inststatusguest => \@inststatusguest,
1.236 raeburn 20131: };
20132: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20133: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20134: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20135: }
20136: }
20137: if ($currorder ne join(',',@orderedstatus)) {
20138: $changes{'inststatus'}{'inststatusorder'} = 1;
20139: }
20140: my $newtitles;
20141: foreach my $item (@orderedstatus) {
20142: $newtitles .= $alltypes{$item}.',';
20143: }
20144: $newtitles =~ s/,$//;
20145: if ($currtitles ne $newtitles) {
20146: $changes{'inststatus'}{'inststatustypes'} = 1;
20147: }
1.43 raeburn 20148: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20149: $dom);
20150: if ($putresult eq 'ok') {
20151: if (keys(%changes) > 0) {
20152: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20153: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20154: 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";
20155: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20156: if ($item eq 'inststatus') {
20157: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20158: if (@orderedstatus) {
1.236 raeburn 20159: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20160: foreach my $type (@orderedstatus) {
20161: $resulttext .= $alltypes{$type}.', ';
20162: }
20163: $resulttext =~ s/, $//;
20164: $resulttext .= '</li>';
1.305 raeburn 20165: } else {
20166: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20167: }
20168: }
1.409 raeburn 20169: } elsif ($item eq 'unamemap_rule') {
20170: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20171: my @rulenames;
20172: if (ref($unamemaprules) eq 'HASH') {
20173: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20174: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20175: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20176: }
20177: }
20178: }
20179: if (@rulenames) {
20180: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20181: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20182: '</li>';
20183: } else {
20184: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20185: }
20186: } else {
20187: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20188: }
1.236 raeburn 20189: } else {
20190: my $value = $env{'form.'.$item};
20191: if ($value eq '') {
20192: $value = &mt('none');
20193: } elsif ($item eq 'auth_def') {
20194: my %authnames = &authtype_names();
20195: my %shortauth = (
20196: internal => 'int',
20197: krb4 => 'krb4',
20198: krb5 => 'krb5',
20199: localauth => 'loc',
1.325 raeburn 20200: lti => 'lti',
1.236 raeburn 20201: );
20202: $value = $authnames{$shortauth{$value}};
20203: }
20204: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
20205: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 20206: }
20207: }
20208: $resulttext .= '</ul>';
20209: $mailmsgtext .= "\n";
20210: my $cachetime = 24*60*60;
1.72 raeburn 20211: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20212: if (ref($lastactref) eq 'HASH') {
20213: $lastactref->{'domdefaults'} = 1;
20214: }
1.68 raeburn 20215: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20216: my $notify = 1;
20217: if (ref($domconfig{'contacts'}) eq 'HASH') {
20218: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20219: $notify = 0;
20220: }
20221: }
20222: if ($notify) {
20223: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20224: "LON-CAPA Domain Settings Change - $dom",
20225: $mailmsgtext);
20226: }
1.54 raeburn 20227: }
1.43 raeburn 20228: } else {
1.54 raeburn 20229: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20230: }
20231: } else {
20232: $resulttext = '<span class="LC_error">'.
20233: &mt('An error occurred: [_1]',$putresult).'</span>';
20234: }
20235: if (@errors > 0) {
20236: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20237: foreach my $item (@errors) {
20238: $resulttext .= ' "'.$title->{$item}.'",';
20239: }
20240: $resulttext =~ s/,$//;
20241: }
20242: return $resulttext;
20243: }
20244:
1.46 raeburn 20245: sub modify_scantron {
1.205 raeburn 20246: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20247: my ($resulttext,%confhash,%changes,$errors);
20248: my $custom = 'custom.tab';
20249: my $default = 'default.tab';
20250: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20251: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20252: &config_check($dom,$confname,$servadm);
20253: if ($env{'form.scantronformat.filename'} ne '') {
20254: my $error;
20255: if ($configuserok eq 'ok') {
20256: if ($switchserver) {
1.130 raeburn 20257: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20258: } else {
20259: if ($author_ok eq 'ok') {
20260: my ($result,$scantronurl) =
20261: &publishlogo($r,'upload','scantronformat',$dom,
20262: $confname,'scantron','','',$custom);
20263: if ($result eq 'ok') {
20264: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20265: $changes{'scantronformat'} = 1;
1.46 raeburn 20266: } else {
20267: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20268: }
20269: } else {
20270: $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);
20271: }
20272: }
20273: } else {
20274: $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);
20275: }
20276: if ($error) {
20277: &Apache::lonnet::logthis($error);
20278: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20279: }
20280: }
1.48 raeburn 20281: if (ref($domconfig{'scantron'}) eq 'HASH') {
20282: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20283: if ($env{'form.scantronformat_del'}) {
20284: $confhash{'scantron'}{'scantronformat'} = '';
20285: $changes{'scantronformat'} = 1;
1.347 raeburn 20286: } else {
20287: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20288: }
20289: }
20290: }
1.347 raeburn 20291: my @options = ('hdr','pad','rem');
1.346 raeburn 20292: my @fields = &scantroncsv_fields();
20293: my %titles = &scantronconfig_titles();
1.347 raeburn 20294: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20295: my ($newdat,$currdat,%newcol,%currcol);
20296: if (grep(/^dat$/,@formats)) {
20297: $confhash{'scantron'}{config}{dat} = 1;
20298: $newdat = 1;
20299: } else {
20300: $newdat = 0;
20301: }
20302: if (grep(/^csv$/,@formats)) {
20303: my %bynum;
20304: foreach my $field (@fields) {
20305: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20306: my $posscol = $1;
20307: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20308: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20309: $bynum{$posscol} = $field;
20310: $newcol{$field} = $posscol;
20311: }
20312: }
20313: }
1.347 raeburn 20314: if (keys(%newcol)) {
20315: foreach my $option (@options) {
20316: if ($env{'form.scantroncsv_'.$option}) {
20317: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20318: }
20319: }
20320: }
1.346 raeburn 20321: }
20322: $currdat = 1;
20323: if (ref($domconfig{'scantron'}) eq 'HASH') {
20324: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20325: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20326: $currdat = 0;
20327: }
20328: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20329: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20330: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20331: }
1.346 raeburn 20332: }
20333: }
20334: }
20335: if ($currdat != $newdat) {
20336: $changes{'config'} = 1;
20337: } else {
20338: foreach my $field (@fields) {
20339: if ($currcol{$field} ne '') {
20340: if ($currcol{$field} ne $newcol{$field}) {
20341: $changes{'config'} = 1;
20342: last;
1.347 raeburn 20343: }
1.346 raeburn 20344: } elsif ($newcol{$field} ne '') {
20345: $changes{'config'} = 1;
20346: last;
20347: }
20348: }
20349: }
1.46 raeburn 20350: if (keys(%confhash) > 0) {
20351: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20352: $dom);
20353: if ($putresult eq 'ok') {
20354: if (keys(%changes) > 0) {
1.48 raeburn 20355: if (ref($confhash{'scantron'}) eq 'HASH') {
20356: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20357: if ($changes{'scantronformat'}) {
20358: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20359: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20360: } else {
20361: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20362: }
20363: }
1.347 raeburn 20364: if ($changes{'config'}) {
1.346 raeburn 20365: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20366: if ($confhash{'scantron'}{'config'}{'dat'}) {
20367: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20368: }
20369: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20370: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20371: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20372: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20373: foreach my $field (@fields) {
20374: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20375: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20376: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20377: }
20378: }
20379: $resulttext .= '</ul></li>';
20380: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20381: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20382: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20383: foreach my $option (@options) {
20384: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20385: $resulttext .= '<li>'.$titles{$option}.'</li>';
20386: }
20387: }
20388: $resulttext .= '</ul></li>';
20389: }
1.346 raeburn 20390: }
20391: }
20392: }
20393: }
20394: } else {
20395: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20396: }
1.46 raeburn 20397: }
1.48 raeburn 20398: $resulttext .= '</ul>';
20399: } else {
1.130 raeburn 20400: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20401: }
20402: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20403: if (ref($lastactref) eq 'HASH') {
20404: $lastactref->{'domainconfig'} = 1;
20405: }
1.46 raeburn 20406: } else {
1.346 raeburn 20407: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20408: }
20409: } else {
20410: $resulttext = '<span class="LC_error">'.
20411: &mt('An error occurred: [_1]',$putresult).'</span>';
20412: }
20413: } else {
1.130 raeburn 20414: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20415: }
20416: if ($errors) {
1.353 raeburn 20417: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20418: $errors.'</ul></p>';
1.46 raeburn 20419: }
20420: return $resulttext;
20421: }
20422:
1.48 raeburn 20423: sub modify_coursecategories {
1.239 raeburn 20424: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20425: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20426: $cathash);
1.48 raeburn 20427: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20428: my @catitems = ('unauth','auth');
20429: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20430: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20431: $cathash = $domconfig{'coursecategories'}{'cats'};
20432: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20433: $changes{'togglecats'} = 1;
20434: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20435: }
20436: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20437: $changes{'categorize'} = 1;
20438: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20439: }
1.120 raeburn 20440: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20441: $changes{'togglecatscomm'} = 1;
20442: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20443: }
20444: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20445: $changes{'categorizecomm'} = 1;
20446: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20447:
20448: }
20449: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20450: $changes{'togglecatsplace'} = 1;
20451: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20452: }
20453: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20454: $changes{'categorizeplace'} = 1;
20455: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20456: }
1.238 raeburn 20457: foreach my $item (@catitems) {
20458: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20459: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20460: $changes{$item} = 1;
20461: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20462: }
20463: }
20464: }
1.57 raeburn 20465: } else {
20466: $changes{'togglecats'} = 1;
20467: $changes{'categorize'} = 1;
1.124 raeburn 20468: $changes{'togglecatscomm'} = 1;
20469: $changes{'categorizecomm'} = 1;
1.272 raeburn 20470: $changes{'togglecatsplace'} = 1;
20471: $changes{'categorizeplace'} = 1;
1.87 raeburn 20472: $domconfig{'coursecategories'} = {
20473: togglecats => $env{'form.togglecats'},
20474: categorize => $env{'form.categorize'},
1.124 raeburn 20475: togglecatscomm => $env{'form.togglecatscomm'},
20476: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20477: togglecatsplace => $env{'form.togglecatsplace'},
20478: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20479: };
1.238 raeburn 20480: foreach my $item (@catitems) {
20481: if ($env{'form.coursecat_'.$item} ne 'std') {
20482: $changes{$item} = 1;
20483: }
20484: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20485: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20486: }
20487: }
1.57 raeburn 20488: }
20489: if (ref($cathash) eq 'HASH') {
20490: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20491: push (@deletecategory,'instcode::0');
20492: }
1.120 raeburn 20493: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20494: push(@deletecategory,'communities::0');
20495: }
1.272 raeburn 20496: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20497: push(@deletecategory,'placement::0');
20498: }
1.48 raeburn 20499: }
1.57 raeburn 20500: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20501: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20502: if (@deletecategory > 0) {
20503: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20504: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20505: foreach my $item (@deletecategory) {
1.57 raeburn 20506: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20507: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20508: $deletions{$item} = 1;
1.57 raeburn 20509: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20510: }
20511: }
20512: }
1.57 raeburn 20513: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20514: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20515: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20516: $reorderings{$item} = 1;
1.57 raeburn 20517: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20518: }
20519: if ($env{'form.addcategory_name_'.$item} ne '') {
20520: my $newcat = $env{'form.addcategory_name_'.$item};
20521: my $newdepth = $depth+1;
20522: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20523: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20524: $adds{$newitem} = 1;
20525: }
20526: if ($env{'form.subcat_'.$item} ne '') {
20527: my $newcat = $env{'form.subcat_'.$item};
20528: my $newdepth = $depth+1;
20529: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20530: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20531: $adds{$newitem} = 1;
20532: }
20533: }
20534: }
20535: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20536: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20537: my $newitem = 'instcode::0';
1.57 raeburn 20538: if ($cathash->{$newitem} eq '') {
20539: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20540: $adds{$newitem} = 1;
20541: }
20542: } else {
20543: my $newitem = 'instcode::0';
1.57 raeburn 20544: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20545: $adds{$newitem} = 1;
20546: }
20547: }
1.120 raeburn 20548: if ($env{'form.communities'} eq '1') {
20549: if (ref($cathash) eq 'HASH') {
20550: my $newitem = 'communities::0';
20551: if ($cathash->{$newitem} eq '') {
20552: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20553: $adds{$newitem} = 1;
20554: }
20555: } else {
20556: my $newitem = 'communities::0';
20557: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20558: $adds{$newitem} = 1;
20559: }
20560: }
1.272 raeburn 20561: if ($env{'form.placement'} eq '1') {
20562: if (ref($cathash) eq 'HASH') {
20563: my $newitem = 'placement::0';
20564: if ($cathash->{$newitem} eq '') {
20565: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20566: $adds{$newitem} = 1;
20567: }
20568: } else {
20569: my $newitem = 'placement::0';
20570: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20571: $adds{$newitem} = 1;
20572: }
20573: }
1.48 raeburn 20574: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20575: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20576: ($env{'form.addcategory_name'} ne 'communities') &&
20577: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20578: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20579: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20580: $adds{$newitem} = 1;
20581: }
1.48 raeburn 20582: }
1.57 raeburn 20583: my $putresult;
1.48 raeburn 20584: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20585: if (keys(%deletions) > 0) {
20586: foreach my $key (keys(%deletions)) {
20587: if ($predelallitems{$key} ne '') {
20588: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20589: }
20590: }
20591: }
20592: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20593: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20594: if (ref($chkcats[0]) eq 'ARRAY') {
20595: my $depth = 0;
20596: my $chg = 0;
20597: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20598: my $name = $chkcats[0][$i];
20599: my $item;
20600: if ($name eq '') {
20601: $chg ++;
20602: } else {
20603: $item = &escape($name).'::0';
20604: if ($chg) {
1.57 raeburn 20605: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20606: }
20607: $depth ++;
1.57 raeburn 20608: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20609: $depth --;
20610: }
20611: }
20612: }
1.57 raeburn 20613: }
20614: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20615: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20616: if ($putresult eq 'ok') {
1.57 raeburn 20617: my %title = (
1.120 raeburn 20618: togglecats => 'Show/Hide a course in catalog',
20619: categorize => 'Assign a category to a course',
20620: togglecatscomm => 'Show/Hide a community in catalog',
20621: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20622: );
20623: my %level = (
1.120 raeburn 20624: dom => 'set in Domain ("Modify Course/Community")',
20625: crs => 'set in Course ("Course Configuration")',
20626: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20627: none => 'No catalog',
20628: std => 'Standard catalog',
20629: domonly => 'Domain-only catalog',
20630: codesrch => 'Code search form',
1.57 raeburn 20631: );
1.48 raeburn 20632: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20633: if ($changes{'togglecats'}) {
20634: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20635: }
20636: if ($changes{'categorize'}) {
20637: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20638: }
1.120 raeburn 20639: if ($changes{'togglecatscomm'}) {
20640: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20641: }
20642: if ($changes{'categorizecomm'}) {
20643: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20644: }
1.238 raeburn 20645: if ($changes{'unauth'}) {
20646: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20647: }
20648: if ($changes{'auth'}) {
20649: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20650: }
1.57 raeburn 20651: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20652: my $cathash;
20653: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20654: $cathash = $domconfig{'coursecategories'}{'cats'};
20655: } else {
20656: $cathash = {};
20657: }
20658: my (@cats,@trails,%allitems);
20659: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20660: if (keys(%deletions) > 0) {
20661: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20662: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20663: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20664: }
20665: $resulttext .= '</ul></li>';
20666: }
20667: if (keys(%reorderings) > 0) {
20668: my %sort_by_trail;
20669: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20670: foreach my $key (keys(%reorderings)) {
20671: if ($allitems{$key} ne '') {
20672: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20673: }
1.48 raeburn 20674: }
1.57 raeburn 20675: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20676: $resulttext .= '<li>'.$trails[$trail].'</li>';
20677: }
20678: $resulttext .= '</ul></li>';
1.48 raeburn 20679: }
1.57 raeburn 20680: if (keys(%adds) > 0) {
20681: my %sort_by_trail;
20682: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20683: foreach my $key (keys(%adds)) {
20684: if ($allitems{$key} ne '') {
20685: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20686: }
20687: }
20688: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20689: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20690: }
1.57 raeburn 20691: $resulttext .= '</ul></li>';
1.48 raeburn 20692: }
1.364 raeburn 20693: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20694: if (ref($lastactref) eq 'HASH') {
20695: $lastactref->{'cats'} = 1;
20696: }
1.48 raeburn 20697: }
20698: $resulttext .= '</ul>';
1.239 raeburn 20699: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20700: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20701: if ($changes{'auth'}) {
20702: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20703: }
20704: if ($changes{'unauth'}) {
20705: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20706: }
20707: my $cachetime = 24*60*60;
20708: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20709: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20710: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20711: }
20712: }
1.48 raeburn 20713: } else {
20714: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20715: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20716: }
20717: } else {
1.120 raeburn 20718: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20719: }
20720: return $resulttext;
20721: }
20722:
1.69 raeburn 20723: sub modify_serverstatuses {
20724: my ($dom,%domconfig) = @_;
20725: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20726: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20727: %currserverstatus = %{$domconfig{'serverstatuses'}};
20728: }
20729: my @pages = &serverstatus_pages();
20730: foreach my $type (@pages) {
20731: $newserverstatus{$type}{'namedusers'} = '';
20732: $newserverstatus{$type}{'machines'} = '';
20733: if (defined($env{'form.'.$type.'_namedusers'})) {
20734: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20735: my @okusers;
20736: foreach my $user (@users) {
20737: my ($uname,$udom) = split(/:/,$user);
20738: if (($udom =~ /^$match_domain$/) &&
20739: (&Apache::lonnet::domain($udom)) &&
20740: ($uname =~ /^$match_username$/)) {
20741: if (!grep(/^\Q$user\E/,@okusers)) {
20742: push(@okusers,$user);
20743: }
20744: }
20745: }
20746: if (@okusers > 0) {
20747: @okusers = sort(@okusers);
20748: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20749: }
20750: }
20751: if (defined($env{'form.'.$type.'_machines'})) {
20752: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20753: my @okmachines;
20754: foreach my $ip (@machines) {
20755: my @parts = split(/\./,$ip);
20756: next if (@parts < 4);
20757: my $badip = 0;
20758: for (my $i=0; $i<4; $i++) {
20759: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20760: $badip = 1;
20761: last;
20762: }
20763: }
20764: if (!$badip) {
20765: push(@okmachines,$ip);
20766: }
20767: }
20768: @okmachines = sort(@okmachines);
20769: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20770: }
20771: }
20772: my %serverstatushash = (
20773: serverstatuses => \%newserverstatus,
20774: );
20775: foreach my $type (@pages) {
1.83 raeburn 20776: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20777: my (@current,@new);
1.83 raeburn 20778: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20779: if ($currserverstatus{$type}{$setting} ne '') {
20780: @current = split(/,/,$currserverstatus{$type}{$setting});
20781: }
20782: }
20783: if ($newserverstatus{$type}{$setting} ne '') {
20784: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20785: }
20786: if (@current > 0) {
20787: if (@new > 0) {
20788: foreach my $item (@current) {
20789: if (!grep(/^\Q$item\E$/,@new)) {
20790: $changes{$type}{$setting} = 1;
1.82 raeburn 20791: last;
20792: }
20793: }
1.84 raeburn 20794: foreach my $item (@new) {
20795: if (!grep(/^\Q$item\E$/,@current)) {
20796: $changes{$type}{$setting} = 1;
20797: last;
1.82 raeburn 20798: }
20799: }
20800: } else {
1.83 raeburn 20801: $changes{$type}{$setting} = 1;
1.69 raeburn 20802: }
1.83 raeburn 20803: } elsif (@new > 0) {
20804: $changes{$type}{$setting} = 1;
1.69 raeburn 20805: }
20806: }
20807: }
20808: if (keys(%changes) > 0) {
1.81 raeburn 20809: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20810: my $putresult = &Apache::lonnet::put_dom('configuration',
20811: \%serverstatushash,$dom);
20812: if ($putresult eq 'ok') {
20813: $resulttext .= &mt('Changes made:').'<ul>';
20814: foreach my $type (@pages) {
1.84 raeburn 20815: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20816: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20817: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20818: if ($newserverstatus{$type}{'namedusers'} eq '') {
20819: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20820: } else {
20821: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20822: }
1.84 raeburn 20823: }
20824: if ($changes{$type}{'machines'}) {
1.69 raeburn 20825: if ($newserverstatus{$type}{'machines'} eq '') {
20826: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20827: } else {
20828: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20829: }
20830:
20831: }
20832: $resulttext .= '</ul></li>';
20833: }
20834: }
20835: $resulttext .= '</ul>';
20836: } else {
20837: $resulttext = '<span class="LC_error">'.
20838: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20839:
20840: }
20841: } else {
20842: $resulttext = &mt('No changes made to access to server status pages');
20843: }
20844: return $resulttext;
20845: }
20846:
1.118 jms 20847: sub modify_helpsettings {
1.285 raeburn 20848: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20849: my ($resulttext,$errors,%changes,%helphash);
20850: my %defaultchecked = ('submitbugs' => 'on');
20851: my @offon = ('off','on');
1.118 jms 20852: my @toggles = ('submitbugs');
1.285 raeburn 20853: my %current = ('submitbugs' => '',
20854: 'adhoc' => {},
20855: );
1.118 jms 20856: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20857: %current = %{$domconfig{'helpsettings'}};
20858: }
1.285 raeburn 20859: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20860: foreach my $item (@toggles) {
20861: if ($defaultchecked{$item} eq 'on') {
20862: if ($current{$item} eq '') {
20863: if ($env{'form.'.$item} eq '0') {
20864: $changes{$item} = 1;
20865: }
20866: } elsif ($current{$item} ne $env{'form.'.$item}) {
20867: $changes{$item} = 1;
20868: }
20869: } elsif ($defaultchecked{$item} eq 'off') {
20870: if ($current{$item} eq '') {
20871: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20872: $changes{$item} = 1;
20873: }
1.282 raeburn 20874: } elsif ($current{$item} ne $env{'form.'.$item}) {
20875: $changes{$item} = 1;
20876: }
20877: }
20878: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20879: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20880: }
20881: }
1.285 raeburn 20882: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20883: my $confname = $dom.'-domainconfig';
20884: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20885: my (@allpos,%newsettings,%changedprivs,$newrole);
20886: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20887: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20888: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20889: my %lt = &Apache::lonlocal::texthash(
20890: s => 'system',
20891: d => 'domain',
20892: order => 'Display order',
20893: access => 'Role usage',
1.291 raeburn 20894: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20895: dh => 'All with domain helpdesk role',
20896: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20897: none => 'None',
20898: status => 'Determined based on institutional status',
20899: inc => 'Include all, but exclude specific personnel',
20900: exc => 'Exclude all, but include specific personnel',
20901: );
20902: for (my $num=0; $num<=$maxnum; $num++) {
20903: my ($prefix,$identifier,$rolename,%curr);
20904: if ($num == $maxnum) {
20905: next unless ($env{'form.newcusthelp'} == $maxnum);
20906: $identifier = 'custhelp'.$num;
20907: $prefix = 'helproles_'.$num;
20908: $rolename = $env{'form.custhelpname'.$num};
20909: $rolename=~s/[^A-Za-z0-9]//gs;
20910: next if ($rolename eq '');
20911: next if (exists($existing{'rolesdef_'.$rolename}));
20912: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20913: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20914: $newprivs{'c'},$confname,$dom);
20915: if ($result ne 'ok') {
20916: $errors .= '<li><span class="LC_error">'.
20917: &mt('An error occurred storing the new custom role: [_1]',
20918: $result).'</span></li>';
20919: next;
20920: } else {
20921: $changedprivs{$rolename} = \%newprivs;
20922: $newrole = $rolename;
20923: }
20924: } else {
20925: $prefix = 'helproles_'.$num;
20926: $rolename = $env{'form.'.$prefix};
20927: next if ($rolename eq '');
20928: next unless (exists($existing{'rolesdef_'.$rolename}));
20929: $identifier = 'custhelp'.$num;
20930: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20931: my %currprivs;
1.289 raeburn 20932: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20933: split(/\_/,$existing{'rolesdef_'.$rolename});
20934: foreach my $level ('c','d','s') {
20935: if ($newprivs{$level} ne $currprivs{$level}) {
20936: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20937: $newprivs{'c'},$confname,$dom);
20938: if ($result ne 'ok') {
20939: $errors .= '<li><span class="LC_error">'.
20940: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20941: $rolename,$result).'</span></li>';
20942: } else {
20943: $changedprivs{$rolename} = \%newprivs;
20944: }
20945: last;
20946: }
20947: }
20948: if (ref($current{'adhoc'}) eq 'HASH') {
20949: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20950: %curr = %{$current{'adhoc'}{$rolename}};
20951: }
20952: }
20953: }
20954: my $newpos = $env{'form.'.$prefix.'_pos'};
20955: $newpos =~ s/\D+//g;
20956: $allpos[$newpos] = $rolename;
20957: my $newdesc = $env{'form.'.$prefix.'_desc'};
20958: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20959: if ($curr{'desc'}) {
20960: if ($curr{'desc'} ne $newdesc) {
20961: $changes{'customrole'}{$rolename}{'desc'} = 1;
20962: $newsettings{$rolename}{'desc'} = $newdesc;
20963: }
20964: } elsif ($newdesc ne '') {
20965: $changes{'customrole'}{$rolename}{'desc'} = 1;
20966: $newsettings{$rolename}{'desc'} = $newdesc;
20967: }
20968: my $access = $env{'form.'.$prefix.'_access'};
20969: if (grep(/^\Q$access\E$/,@accesstypes)) {
20970: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20971: if ($access eq 'status') {
20972: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20973: if (scalar(@statuses) == 0) {
1.289 raeburn 20974: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20975: } else {
20976: my (@shownstatus,$numtypes);
20977: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20978: if (ref($types) eq 'ARRAY') {
20979: $numtypes = scalar(@{$types});
20980: foreach my $type (sort(@statuses)) {
20981: if ($type eq 'default') {
20982: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20983: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20984: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20985: push(@shownstatus,$usertypes->{$type});
20986: }
20987: }
20988: }
20989: if (grep(/^default$/,@statuses)) {
20990: push(@shownstatus,$othertitle);
20991: }
20992: if (scalar(@shownstatus) == 1+$numtypes) {
20993: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20994: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20995: } else {
20996: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20997: if (ref($curr{'status'}) eq 'ARRAY') {
20998: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20999: if (@diffs) {
21000: $changes{'customrole'}{$rolename}{$access} = 1;
21001: }
21002: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21003: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21004: }
1.166 raeburn 21005: }
21006: }
1.285 raeburn 21007: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21008: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21009: my @newspecstaff;
21010: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21011: foreach my $person (sort(@personnel)) {
21012: if ($domhelpdesk{$person}) {
21013: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21014: }
21015: }
21016: if (ref($curr{$access}) eq 'ARRAY') {
21017: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21018: if (@diffs) {
21019: $changes{'customrole'}{$rolename}{$access} = 1;
21020: }
21021: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21022: $changes{'customrole'}{$rolename}{$access} = 1;
21023: }
21024: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21025: my ($uname,$udom) = split(/:/,$person);
21026: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21027: }
21028: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21029: }
1.285 raeburn 21030: } else {
21031: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21032: }
21033: unless ($curr{'access'} eq $access) {
21034: $changes{'customrole'}{$rolename}{'access'} = 1;
21035: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21036: }
21037: }
1.285 raeburn 21038: if (@allpos > 0) {
21039: my $idx = 0;
21040: foreach my $rolename (@allpos) {
21041: if ($rolename ne '') {
21042: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21043: if (ref($current{'adhoc'}) eq 'HASH') {
21044: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21045: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21046: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21047: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21048: }
21049: }
1.282 raeburn 21050: }
1.285 raeburn 21051: $idx ++;
1.166 raeburn 21052: }
21053: }
1.118 jms 21054: }
1.123 jms 21055: my $putresult;
21056: if (keys(%changes) > 0) {
1.166 raeburn 21057: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21058: if ($putresult eq 'ok') {
1.285 raeburn 21059: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21060: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21061: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21062: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21063: }
21064: }
21065: my $cachetime = 24*60*60;
21066: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21067: if (ref($lastactref) eq 'HASH') {
21068: $lastactref->{'domdefaults'} = 1;
21069: }
21070: } else {
21071: $errors .= '<li><span class="LC_error">'.
21072: &mt('An error occurred storing the settings: [_1]',
21073: $putresult).'</span></li>';
21074: }
21075: }
21076: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21077: $resulttext = &mt('Changes made:').'<ul>';
21078: my (%shownprivs,@levelorder);
21079: @levelorder = ('c','d','s');
21080: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21081: foreach my $item (sort(keys(%changes))) {
21082: if ($item eq 'submitbugs') {
21083: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21084: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21085: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21086: } elsif ($item eq 'customrole') {
21087: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21088: my @keyorder = ('order','desc','access','status','exc','inc');
21089: my %keytext = &Apache::lonlocal::texthash(
21090: order => 'Order',
21091: desc => 'Role description',
21092: access => 'Role usage',
1.300 droeschl 21093: status => 'Allowed institutional types',
1.285 raeburn 21094: exc => 'Allowed personnel',
21095: inc => 'Disallowed personnel',
21096: );
1.282 raeburn 21097: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21098: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21099: if ($role eq $newrole) {
21100: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21101: $role).'<ul>';
21102: } else {
21103: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21104: $role).'<ul>';
21105: }
21106: foreach my $key (@keyorder) {
21107: if ($changes{'customrole'}{$role}{$key}) {
21108: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21109: $keytext{$key},$newsettings{$role}{$key}).
21110: '</li>';
21111: }
21112: }
21113: if (ref($changedprivs{$role}) eq 'HASH') {
21114: $shownprivs{$role} = 1;
21115: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21116: foreach my $level (@levelorder) {
21117: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21118: next if ($item eq '');
21119: my ($priv) = split(/\&/,$item,2);
21120: if (&Apache::lonnet::plaintext($priv)) {
21121: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21122: unless ($level eq 'c') {
21123: $resulttext .= ' ('.$lt{$level}.')';
21124: }
21125: $resulttext .= '</li>';
21126: }
21127: }
21128: }
21129: $resulttext .= '</ul>';
21130: }
21131: $resulttext .= '</ul></li>';
21132: }
21133: }
21134: }
21135: }
21136: }
21137: }
21138: if (keys(%changedprivs)) {
21139: foreach my $role (sort(keys(%changedprivs))) {
21140: unless ($shownprivs{$role}) {
21141: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21142: $role).'<ul>'.
21143: '<li>'.&mt('Privileges set to :').'<ul>';
21144: foreach my $level (@levelorder) {
21145: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21146: next if ($item eq '');
21147: my ($priv) = split(/\&/,$item,2);
21148: if (&Apache::lonnet::plaintext($priv)) {
21149: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21150: unless ($level eq 'c') {
21151: $resulttext .= ' ('.$lt{$level}.')';
21152: }
21153: $resulttext .= '</li>';
21154: }
1.282 raeburn 21155: }
21156: }
1.285 raeburn 21157: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21158: }
21159: }
21160: }
1.285 raeburn 21161: $resulttext .= '</ul>';
21162: } else {
21163: $resulttext = &mt('No changes made to help settings');
1.118 jms 21164: }
21165: if ($errors) {
1.168 raeburn 21166: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21167: $errors.'</ul>';
1.118 jms 21168: }
21169: return $resulttext;
21170: }
21171:
1.121 raeburn 21172: sub modify_coursedefaults {
1.212 raeburn 21173: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21174: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21175: my %defaultchecked = (
21176: 'canuse_pdfforms' => 'off',
21177: 'uselcmath' => 'on',
1.398 raeburn 21178: 'usejsme' => 'on',
21179: 'inline_chem' => 'on',
1.404 raeburn 21180: 'ltiauth' => 'off',
1.257 raeburn 21181: );
1.404 raeburn 21182: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21183: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21184: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
21185: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
21186: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 21187: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21188: my %staticdefaults = (
21189: anonsurvey_threshold => 10,
21190: uploadquota => 500,
1.257 raeburn 21191: postsubmit => 60,
1.276 raeburn 21192: mysqltables => 172800,
1.198 raeburn 21193: );
1.314 raeburn 21194: my %texoptions = (
21195: MathJax => 'MathJax',
21196: mimetex => &mt('Convert to Images'),
21197: tth => &mt('TeX to HTML'),
21198: );
1.121 raeburn 21199: $defaultshash{'coursedefaults'} = {};
21200:
21201: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21202: if ($domconfig{'coursedefaults'} eq '') {
21203: $domconfig{'coursedefaults'} = {};
21204: }
21205: }
21206:
21207: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21208: foreach my $item (@toggles) {
21209: if ($defaultchecked{$item} eq 'on') {
21210: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21211: ($env{'form.'.$item} eq '0')) {
21212: $changes{$item} = 1;
1.192 raeburn 21213: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21214: $changes{$item} = 1;
21215: }
21216: } elsif ($defaultchecked{$item} eq 'off') {
21217: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21218: ($env{'form.'.$item} eq '1')) {
21219: $changes{$item} = 1;
21220: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21221: $changes{$item} = 1;
21222: }
21223: }
21224: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21225: }
1.198 raeburn 21226: foreach my $item (@numbers) {
21227: my ($currdef,$newdef);
1.208 raeburn 21228: $newdef = $env{'form.'.$item};
1.198 raeburn 21229: if ($item eq 'anonsurvey_threshold') {
21230: $currdef = $domconfig{'coursedefaults'}{$item};
21231: $newdef =~ s/\D//g;
21232: if ($newdef eq '' || $newdef < 1) {
21233: $newdef = 1;
21234: }
21235: $defaultshash{'coursedefaults'}{$item} = $newdef;
21236: } else {
1.276 raeburn 21237: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
21238: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21239: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21240: }
21241: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21242: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21243: }
21244: if ($currdef ne $newdef) {
21245: if ($item eq 'anonsurvey_threshold') {
21246: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21247: $changes{$item} = 1;
21248: }
1.276 raeburn 21249: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 21250: my $setting = $1;
1.276 raeburn 21251: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21252: $changes{$setting} = 1;
1.198 raeburn 21253: }
21254: }
1.139 raeburn 21255: }
21256: }
1.314 raeburn 21257: my $texengine;
21258: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21259: $texengine = $env{'form.texengine'};
1.349 raeburn 21260: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21261: if ($currdef eq '') {
21262: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21263: $changes{'texengine'} = 1;
21264: }
1.349 raeburn 21265: } elsif ($currdef ne $texengine) {
1.314 raeburn 21266: $changes{'texengine'} = 1;
21267: }
21268: }
21269: if ($texengine ne '') {
21270: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21271: }
1.264 raeburn 21272: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21273: my @currclonecode;
21274: if (ref($currclone) eq 'HASH') {
21275: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21276: @currclonecode = @{$currclone->{'instcode'}};
21277: }
21278: }
21279: my $newclone;
1.289 raeburn 21280: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21281: $newclone = $env{'form.canclone'};
21282: }
21283: if ($newclone eq 'instcode') {
21284: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21285: my (%codedefaults,@code_order,@clonecode);
21286: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21287: \@code_order);
21288: foreach my $item (@code_order) {
21289: if (grep(/^\Q$item\E$/,@newcodes)) {
21290: push(@clonecode,$item);
21291: }
21292: }
21293: if (@clonecode) {
21294: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21295: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21296: if (@diffs) {
21297: $changes{'canclone'} = 1;
21298: }
21299: } else {
21300: $newclone eq '';
21301: }
21302: } elsif ($newclone ne '') {
1.289 raeburn 21303: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21304: }
1.264 raeburn 21305: if ($newclone ne $currclone) {
21306: $changes{'canclone'} = 1;
21307: }
1.257 raeburn 21308: my %credits;
21309: foreach my $type (@types) {
21310: unless ($type eq 'community') {
21311: $credits{$type} = $env{'form.'.$type.'_credits'};
21312: $credits{$type} =~ s/[^\d.]+//g;
21313: }
21314: }
21315: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21316: ($env{'form.coursecredits'} eq '1')) {
21317: $changes{'coursecredits'} = 1;
21318: foreach my $type (keys(%credits)) {
21319: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21320: }
21321: } else {
1.289 raeburn 21322: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21323: foreach my $type (@types) {
21324: unless ($type eq 'community') {
1.289 raeburn 21325: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21326: $changes{'coursecredits'} = 1;
21327: }
21328: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21329: }
21330: }
21331: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21332: foreach my $type (@types) {
21333: unless ($type eq 'community') {
21334: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21335: $changes{'coursecredits'} = 1;
21336: last;
21337: }
21338: }
21339: }
21340: }
21341: }
21342: if ($env{'form.postsubmit'} eq '1') {
21343: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21344: my %currtimeout;
21345: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21346: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21347: $changes{'postsubmit'} = 1;
21348: }
21349: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21350: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21351: }
21352: } else {
21353: $changes{'postsubmit'} = 1;
21354: }
21355: foreach my $type (@types) {
21356: my $timeout = $env{'form.'.$type.'_timeout'};
21357: $timeout =~ s/\D//g;
21358: if ($timeout == $staticdefaults{'postsubmit'}) {
21359: $timeout = '';
21360: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21361: $timeout = '0';
21362: }
21363: unless ($timeout eq '') {
21364: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21365: }
21366: if (exists($currtimeout{$type})) {
21367: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21368: $changes{'postsubmit'} = 1;
1.257 raeburn 21369: }
21370: } elsif ($timeout ne '') {
21371: $changes{'postsubmit'} = 1;
21372: }
21373: }
21374: } else {
21375: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21376: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21377: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21378: $changes{'postsubmit'} = 1;
21379: }
21380: } else {
21381: $changes{'postsubmit'} = 1;
21382: }
1.192 raeburn 21383: }
1.121 raeburn 21384: }
21385: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21386: $dom);
21387: if ($putresult eq 'ok') {
21388: if (keys(%changes) > 0) {
1.213 raeburn 21389: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21390: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21391: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21392: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.404 raeburn 21393: ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
21394: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.257 raeburn 21395: if ($changes{$item}) {
21396: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21397: }
1.289 raeburn 21398: }
1.192 raeburn 21399: if ($changes{'coursecredits'}) {
21400: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21401: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21402: $domdefaults{$type.'credits'} =
21403: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21404: }
21405: }
21406: }
21407: if ($changes{'postsubmit'}) {
21408: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21409: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21410: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21411: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21412: $domdefaults{$type.'postsubtimeout'} =
21413: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21414: }
21415: }
1.192 raeburn 21416: }
21417: }
1.198 raeburn 21418: if ($changes{'uploadquota'}) {
21419: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21420: foreach my $type (@types) {
21421: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21422: }
21423: }
21424: }
1.264 raeburn 21425: if ($changes{'canclone'}) {
21426: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21427: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21428: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21429: if (@clonecodes) {
21430: $domdefaults{'canclone'} = join('+',@clonecodes);
21431: }
21432: }
21433: } else {
21434: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21435: }
21436: }
1.121 raeburn 21437: my $cachetime = 24*60*60;
21438: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21439: if (ref($lastactref) eq 'HASH') {
21440: $lastactref->{'domdefaults'} = 1;
21441: }
1.121 raeburn 21442: }
21443: $resulttext = &mt('Changes made:').'<ul>';
21444: foreach my $item (sort(keys(%changes))) {
21445: if ($item eq 'canuse_pdfforms') {
21446: if ($env{'form.'.$item} eq '1') {
21447: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21448: } else {
21449: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21450: }
1.257 raeburn 21451: } elsif ($item eq 'uselcmath') {
21452: if ($env{'form.'.$item} eq '1') {
21453: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21454: } else {
21455: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21456: }
21457: } elsif ($item eq 'usejsme') {
21458: if ($env{'form.'.$item} eq '1') {
21459: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21460: } else {
1.289 raeburn 21461: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21462: }
1.398 raeburn 21463: } elsif ($item eq 'inline_chem') {
21464: if ($env{'form.'.$item} eq '1') {
21465: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21466: } else {
21467: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21468: }
1.314 raeburn 21469: } elsif ($item eq 'texengine') {
21470: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21471: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21472: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21473: }
1.139 raeburn 21474: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21475: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21476: } elsif ($item eq 'uploadquota') {
21477: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21478: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21479: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21480: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21481: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21482: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21483: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21484: '</ul>'.
21485: '</li>';
21486: } else {
21487: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21488: }
1.276 raeburn 21489: } elsif ($item eq 'mysqltables') {
21490: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21491: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21492: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21493: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21494: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21495: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21496: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21497: '</ul>'.
21498: '</li>';
21499: } else {
21500: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21501: }
1.257 raeburn 21502: } elsif ($item eq 'postsubmit') {
21503: if ($domdefaults{'postsubmit'} eq 'off') {
21504: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21505: } else {
21506: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21507: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21508: $resulttext .= &mt('durations:').'<ul>';
21509: foreach my $type (@types) {
21510: $resulttext .= '<li>';
21511: my $timeout;
21512: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21513: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21514: }
21515: my $display;
21516: if ($timeout eq '0') {
21517: $display = &mt('unlimited');
21518: } elsif ($timeout eq '') {
21519: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21520: } else {
21521: $display = &mt('[quant,_1,second]',$timeout);
21522: }
21523: if ($type eq 'community') {
21524: $resulttext .= &mt('Communities');
21525: } elsif ($type eq 'official') {
21526: $resulttext .= &mt('Official courses');
21527: } elsif ($type eq 'unofficial') {
21528: $resulttext .= &mt('Unofficial courses');
21529: } elsif ($type eq 'textbook') {
21530: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21531: } elsif ($type eq 'placement') {
21532: $resulttext .= &mt('Placement tests');
1.257 raeburn 21533: }
21534: $resulttext .= ' -- '.$display.'</li>';
21535: }
21536: $resulttext .= '</ul>';
21537: }
1.289 raeburn 21538: $resulttext .= '</li>';
1.257 raeburn 21539: }
1.192 raeburn 21540: } elsif ($item eq 'coursecredits') {
21541: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21542: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21543: ($domdefaults{'unofficialcredits'} eq '') &&
21544: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21545: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21546: } else {
21547: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21548: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21549: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21550: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21551: '</ul>'.
21552: '</li>';
21553: }
21554: } else {
21555: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21556: }
1.264 raeburn 21557: } elsif ($item eq 'canclone') {
21558: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21559: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21560: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21561: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21562: }
21563: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21564: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21565: } else {
1.289 raeburn 21566: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21567: }
1.404 raeburn 21568: } elsif ($item eq 'ltiauth') {
21569: if ($env{'form.'.$item} eq '1') {
21570: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21571: } else {
21572: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21573: }
1.140 raeburn 21574: }
1.121 raeburn 21575: }
21576: $resulttext .= '</ul>';
21577: } else {
21578: $resulttext = &mt('No changes made to course defaults');
21579: }
21580: } else {
21581: $resulttext = '<span class="LC_error">'.
21582: &mt('An error occurred: [_1]',$putresult).'</span>';
21583: }
21584: return $resulttext;
21585: }
21586:
1.231 raeburn 21587: sub modify_selfenrollment {
21588: my ($dom,$lastactref,%domconfig) = @_;
21589: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21590: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21591: my %titles = &tool_titles();
1.232 raeburn 21592: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21593: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21594: $ordered{'default'} = ['types','registered','approval','limit'];
21595:
21596: my (%roles,%shown,%toplevel);
21597: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21598:
21599: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21600: if ($domconfig{'selfenrollment'} eq '') {
21601: $domconfig{'selfenrollment'} = {};
21602: }
21603: }
21604: %toplevel = (
21605: admin => 'Configuration Rights',
21606: default => 'Default settings',
21607: validation => 'Validation of self-enrollment requests',
21608: );
1.233 raeburn 21609: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21610:
21611: if (ref($ordered{'admin'}) eq 'ARRAY') {
21612: foreach my $item (@{$ordered{'admin'}}) {
21613: foreach my $type (@types) {
21614: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21615: $selfenrollhash{'admin'}{$type}{$item} = 1;
21616: } else {
21617: $selfenrollhash{'admin'}{$type}{$item} = 0;
21618: }
21619: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21620: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21621: if ($selfenrollhash{'admin'}{$type}{$item} ne
21622: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21623: push(@{$changes{'admin'}{$type}},$item);
21624: }
21625: } else {
21626: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21627: push(@{$changes{'admin'}{$type}},$item);
21628: }
21629: }
21630: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21631: push(@{$changes{'admin'}{$type}},$item);
21632: }
21633: }
21634: }
21635: }
21636:
21637: foreach my $item (@{$ordered{'default'}}) {
21638: foreach my $type (@types) {
21639: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21640: if ($item eq 'types') {
21641: unless (($value eq 'all') || ($value eq 'dom')) {
21642: $value = '';
21643: }
21644: } elsif ($item eq 'registered') {
21645: unless ($value eq '1') {
21646: $value = 0;
21647: }
21648: } elsif ($item eq 'approval') {
21649: unless ($value =~ /^[012]$/) {
21650: $value = 0;
21651: }
21652: } else {
21653: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21654: $value = 'none';
21655: }
21656: }
21657: $selfenrollhash{'default'}{$type}{$item} = $value;
21658: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21659: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21660: if ($selfenrollhash{'default'}{$type}{$item} ne
21661: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21662: push(@{$changes{'default'}{$type}},$item);
21663: }
21664: } else {
21665: push(@{$changes{'default'}{$type}},$item);
21666: }
21667: } else {
21668: push(@{$changes{'default'}{$type}},$item);
21669: }
21670: if ($item eq 'limit') {
21671: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21672: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21673: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21674: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21675: }
21676: } else {
21677: $selfenrollhash{'default'}{$type}{'cap'} = '';
21678: }
21679: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21680: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21681: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21682: push(@{$changes{'default'}{$type}},'cap');
21683: }
21684: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21685: push(@{$changes{'default'}{$type}},'cap');
21686: }
21687: }
21688: }
21689: }
21690:
21691: foreach my $item (@{$itemsref}) {
21692: if ($item eq 'fields') {
21693: my @changed;
21694: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21695: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21696: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21697: }
21698: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21699: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21700: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21701: $domconfig{'selfenrollment'}{'validation'}{$item});
21702: } else {
21703: @changed = @{$selfenrollhash{'validation'}{$item}};
21704: }
21705: } else {
21706: @changed = @{$selfenrollhash{'validation'}{$item}};
21707: }
21708: if (@changed) {
21709: if ($selfenrollhash{'validation'}{$item}) {
21710: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21711: } else {
21712: $changes{'validation'}{$item} = &mt('None');
21713: }
21714: }
21715: } else {
21716: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21717: if ($item eq 'markup') {
21718: if ($env{'form.selfenroll_validation_'.$item}) {
21719: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21720: }
21721: }
21722: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21723: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21724: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21725: }
21726: }
21727: }
21728: }
21729:
21730: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21731: $dom);
21732: if ($putresult eq 'ok') {
21733: if (keys(%changes) > 0) {
21734: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21735: $resulttext = &mt('Changes made:').'<ul>';
21736: foreach my $key ('admin','default','validation') {
21737: if (ref($changes{$key}) eq 'HASH') {
21738: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21739: if ($key eq 'validation') {
21740: foreach my $item (@{$itemsref}) {
21741: if (exists($changes{$key}{$item})) {
21742: if ($item eq 'markup') {
21743: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21744: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21745: } else {
21746: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21747: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21748: }
21749: }
21750: }
21751: } else {
21752: foreach my $type (@types) {
21753: if ($type eq 'community') {
21754: $roles{'1'} = &mt('Community personnel');
21755: } else {
21756: $roles{'1'} = &mt('Course personnel');
21757: }
21758: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21759: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21760: if ($key eq 'admin') {
21761: my @mgrdc = ();
21762: if (ref($ordered{$key}) eq 'ARRAY') {
21763: foreach my $item (@{$ordered{'admin'}}) {
21764: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21765: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21766: push(@mgrdc,$item);
21767: }
21768: }
21769: }
21770: if (@mgrdc) {
21771: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21772: } else {
21773: delete($domdefaults{$type.'selfenrolladmdc'});
21774: }
21775: }
21776: } else {
21777: if (ref($ordered{$key}) eq 'ARRAY') {
21778: foreach my $item (@{$ordered{$key}}) {
21779: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21780: $domdefaults{$type.'selfenroll'.$item} =
21781: $selfenrollhash{$key}{$type}{$item};
21782: }
21783: }
21784: }
21785: }
21786: }
1.231 raeburn 21787: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21788: foreach my $item (@{$ordered{$key}}) {
21789: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21790: $resulttext .= '<li>';
21791: if ($key eq 'admin') {
21792: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21793: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21794: } else {
21795: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21796: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21797: }
21798: $resulttext .= '</li>';
21799: }
21800: }
21801: $resulttext .= '</ul></li>';
21802: }
21803: }
21804: $resulttext .= '</ul></li>';
21805: }
21806: }
1.305 raeburn 21807: }
21808: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21809: my $cachetime = 24*60*60;
21810: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21811: if (ref($lastactref) eq 'HASH') {
21812: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21813: }
1.231 raeburn 21814: }
21815: $resulttext .= '</ul>';
21816: } else {
21817: $resulttext = &mt('No changes made to self-enrollment settings');
21818: }
21819: } else {
21820: $resulttext = '<span class="LC_error">'.
21821: &mt('An error occurred: [_1]',$putresult).'</span>';
21822: }
21823: return $resulttext;
21824: }
21825:
1.373 raeburn 21826: sub modify_wafproxy {
21827: my ($dom,$action,$lastactref,%domconfig) = @_;
21828: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21829: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21830: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21831: foreach my $server (sort(keys(%servers))) {
21832: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21833: if ($serverhome eq $server) {
21834: my $serverdom = &Apache::lonnet::host_domain($server);
21835: if ($serverdom eq $dom) {
21836: $canset{$server} = 1;
21837: }
21838: }
21839: }
1.381 raeburn 21840: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21841: %{$values{$dom}} = ();
21842: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21843: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21844: }
1.388 raeburn 21845: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21846: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21847: }
1.382 raeburn 21848: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21849: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21850: }
21851: }
1.373 raeburn 21852: my $output;
21853: if (keys(%canset)) {
21854: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21855: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21856: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21857: if ($env{'form.wafproxy_'.$dom}) {
21858: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21859: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21860: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21861: $changes{'alias'} = 1;
21862: }
1.388 raeburn 21863: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21864: $wafproxy{'saml'}{$key} = 1;
21865: }
21866: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21867: $changes{'saml'} = 1;
21868: }
1.381 raeburn 21869: } else {
21870: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21871: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21872: if ($curralias{$key}) {
21873: $changes{'alias'} = 1;
21874: }
1.388 raeburn 21875: if ($currsaml{$key}) {
21876: $changes{'saml'} = 1;
21877: }
1.373 raeburn 21878: }
21879: if ($wafproxy{'alias'}{$key} eq '') {
21880: if ($curralias{$key}) {
21881: $expirecache{$key} = 1;
21882: }
21883: delete($wafproxy{'alias'}{$key});
21884: }
1.388 raeburn 21885: if ($wafproxy{'saml'}{$key} eq '') {
21886: if ($currsaml{$key}) {
21887: $expiresaml{$key} = 1;
21888: }
21889: delete($wafproxy{'saml'}{$key});
21890: }
1.373 raeburn 21891: }
21892: unless (keys(%{$wafproxy{'alias'}})) {
21893: delete($wafproxy{'alias'});
21894: }
1.388 raeburn 21895: unless (keys(%{$wafproxy{'saml'}})) {
21896: delete($wafproxy{'saml'});
21897: }
21898: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21899: my %warn = (
21900: trusted => 'trusted IP range(s)',
1.381 raeburn 21901: vpnint => 'internal IP range(s) for VPN sessions(s)',
21902: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21903: );
1.382 raeburn 21904: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21905: my $possible = $env{'form.wafproxy_'.$item};
21906: $possible =~ s/^\s+|\s+$//g;
21907: if ($possible ne '') {
1.381 raeburn 21908: if ($item eq 'remoteip') {
21909: if ($possible =~ /^[mhn]$/) {
21910: $wafproxy{$item} = $possible;
21911: }
21912: } elsif ($item eq 'ipheader') {
21913: if ($wafproxy{'remoteip'} eq 'h') {
21914: $wafproxy{$item} = $possible;
21915: }
1.382 raeburn 21916: } elsif ($item eq 'sslopt') {
21917: if ($possible =~ /^0|1$/) {
21918: $wafproxy{$item} = $possible;
21919: }
1.373 raeburn 21920: } else {
21921: my (@ok,$count);
1.381 raeburn 21922: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21923: unless ($env{'form.wafproxy_vpnaccess'}) {
21924: $possible = '';
21925: }
21926: } elsif ($item eq 'trusted') {
21927: unless ($wafproxy{'remoteip'} eq 'h') {
21928: $possible = '';
21929: }
21930: }
21931: unless ($possible eq '') {
21932: $possible =~ s/[\r\n]+/\s/g;
21933: $possible =~ s/\s*-\s*/-/g;
21934: $possible =~ s/\s+/,/g;
1.393 raeburn 21935: $possible =~ s/,+/,/g;
1.381 raeburn 21936: }
1.373 raeburn 21937: $count = 0;
1.381 raeburn 21938: if ($possible ne '') {
1.373 raeburn 21939: foreach my $poss (split(/\,/,$possible)) {
21940: $count ++;
1.393 raeburn 21941: $poss = &validate_ip_pattern($poss);
21942: if ($poss ne '') {
1.373 raeburn 21943: push(@ok,$poss);
21944: }
21945: }
21946: my $diff = $count - scalar(@ok);
21947: if ($diff) {
21948: push(@warnings,'<li>'.
21949: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21950: $diff,$warn{$item}).
21951: '</li>');
21952: }
1.393 raeburn 21953: if (@ok) {
21954: my @cidr_list;
21955: foreach my $item (@ok) {
21956: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21957: }
21958: $wafproxy{$item} = join(',',@cidr_list);
21959: }
1.373 raeburn 21960: }
21961: }
1.381 raeburn 21962: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21963: $changes{$item} = 1;
21964: }
1.381 raeburn 21965: } elsif ($currvalue{$item}) {
21966: $changes{$item} = 1;
21967: }
21968: }
21969: } else {
21970: if (keys(%curralias)) {
21971: $changes{'alias'} = 1;
1.388 raeburn 21972: }
21973: if (keys(%currsaml)) {
21974: $changes{'saml'} = 1;
1.381 raeburn 21975: }
21976: if (keys(%currvalue)) {
21977: foreach my $key (keys(%currvalue)) {
21978: $changes{$key} = 1;
1.373 raeburn 21979: }
21980: }
21981: }
21982: if (keys(%changes)) {
21983: my %defaultshash = (
21984: wafproxy => \%wafproxy,
21985: );
21986: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21987: $dom);
21988: if ($putresult eq 'ok') {
21989: my $cachetime = 24*60*60;
21990: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21991: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21992: if ($changes{$item}) {
21993: unless ($updatedomdefs) {
21994: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21995: $updatedomdefs = 1;
21996: }
21997: if ($wafproxy{$item}) {
21998: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21999: } elsif (exists($domdefaults{'waf_'.$item})) {
22000: delete($domdefaults{'waf_'.$item});
22001: }
22002: }
22003: }
22004: if ($updatedomdefs) {
22005: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22006: if (ref($lastactref) eq 'HASH') {
22007: $lastactref->{'domdefaults'} = 1;
22008: }
22009: }
22010: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22011: my %updates = %expirecache;
22012: foreach my $key (keys(%expirecache)) {
22013: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22014: }
22015: if (ref($wafproxy{'alias'}) eq 'HASH') {
22016: my $cachetime = 24*60*60;
22017: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22018: $updates{$key} = 1;
22019: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22020: $cachetime);
22021: }
22022: }
22023: if (ref($lastactref) eq 'HASH') {
22024: $lastactref->{'proxyalias'} = \%updates;
22025: }
22026: }
1.388 raeburn 22027: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22028: my %samlupdates = %expiresaml;
22029: foreach my $key (keys(%expiresaml)) {
22030: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22031: }
22032: if (ref($wafproxy{'saml'}) eq 'HASH') {
22033: my $cachetime = 24*60*60;
22034: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22035: $samlupdates{$key} = 1;
22036: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22037: $cachetime);
22038: }
22039: }
22040: if (ref($lastactref) eq 'HASH') {
22041: $lastactref->{'proxysaml'} = \%samlupdates;
22042: }
22043: }
1.373 raeburn 22044: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22045: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22046: if ($changes{$item}) {
22047: if ($item eq 'alias') {
22048: my $numaliased = 0;
22049: if (ref($wafproxy{'alias'}) eq 'HASH') {
22050: my $shown;
22051: if (keys(%{$wafproxy{'alias'}})) {
22052: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22053: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22054: &Apache::lonnet::hostname($server),
22055: $wafproxy{'alias'}{$server}).'</li>';
22056: $numaliased ++;
22057: }
22058: if ($numaliased) {
22059: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22060: '<ul>'.$shown.'</ul>').'</li>';
22061: }
22062: }
22063: }
22064: unless ($numaliased) {
22065: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22066: }
1.388 raeburn 22067: } elsif ($item eq 'saml') {
22068: my $shown;
22069: if (ref($wafproxy{'saml'}) eq 'HASH') {
22070: if (keys(%{$wafproxy{'saml'}})) {
22071: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22072: }
22073: }
22074: if ($shown) {
1.396 raeburn 22075: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22076: $shown).'</li>';
22077: } else {
1.396 raeburn 22078: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22079: }
1.373 raeburn 22080: } else {
1.381 raeburn 22081: if ($item eq 'remoteip') {
22082: my %ip_methods = &remoteip_methods();
22083: if ($wafproxy{$item} =~ /^[mh]$/) {
22084: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22085: $ip_methods{$wafproxy{$item}}).'</li>';
22086: } else {
22087: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22088: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22089: '</li>';
22090: } else {
22091: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22092: }
22093: }
22094: } elsif ($item eq 'ipheader') {
1.373 raeburn 22095: if ($wafproxy{$item}) {
1.381 raeburn 22096: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22097: $wafproxy{$item}).'</li>';
22098: } else {
1.381 raeburn 22099: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22100: }
22101: } elsif ($item eq 'trusted') {
22102: if ($wafproxy{$item}) {
1.381 raeburn 22103: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22104: $wafproxy{$item}).'</li>';
22105: } else {
22106: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22107: }
1.381 raeburn 22108: } elsif ($item eq 'vpnint') {
22109: if ($wafproxy{$item}) {
22110: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22111: $wafproxy{$item}).'</li>';
22112: } else {
22113: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22114: }
22115: } elsif ($item eq 'vpnext') {
1.373 raeburn 22116: if ($wafproxy{$item}) {
1.381 raeburn 22117: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22118: $wafproxy{$item}).'</li>';
22119: } else {
1.381 raeburn 22120: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22121: }
1.382 raeburn 22122: } elsif ($item eq 'sslopt') {
22123: if ($wafproxy{$item}) {
22124: $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>';
22125: } else {
22126: $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>';
22127: }
1.373 raeburn 22128: }
22129: }
22130: }
22131: }
22132: } else {
22133: $output = '<span class="LC_error">'.
22134: &mt('An error occurred: [_1]',$putresult).'</span>';
22135: }
22136: } elsif (keys(%canset)) {
22137: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22138: }
22139: if (@warnings) {
22140: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22141: join("\n",@warnings).'</ul>';
22142: }
22143: return $output;
22144: }
22145:
22146: sub validate_ip_pattern {
22147: my ($pattern) = @_;
22148: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22149: my ($start,$end) = ($1,$2);
22150: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22151: if (($start !~ m{/}) && ($end !~ m{/})) {
22152: return $start.'-'.$end;
22153: }
22154: }
22155: } elsif ($pattern ne '') {
22156: $pattern = &Net::CIDR::cidrvalidate($pattern);
22157: if ($pattern ne '') {
22158: return $pattern;
1.373 raeburn 22159: }
22160: }
1.393 raeburn 22161: return;
1.373 raeburn 22162: }
22163:
1.137 raeburn 22164: sub modify_usersessions {
1.212 raeburn 22165: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22166: my @hostingtypes = ('version','excludedomain','includedomain');
22167: my @offloadtypes = ('primary','default');
22168: my %types = (
22169: remote => \@hostingtypes,
22170: hosted => \@hostingtypes,
22171: spares => \@offloadtypes,
22172: );
22173: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22174: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22175: my (%by_ip,%by_location,@intdoms,@instdoms);
22176: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22177: my @locations = sort(keys(%by_location));
1.137 raeburn 22178: my (%defaultshash,%changes);
22179: foreach my $prefix (@prefixes) {
22180: $defaultshash{'usersessions'}{$prefix} = {};
22181: }
1.212 raeburn 22182: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22183: my $resulttext;
1.138 raeburn 22184: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22185: foreach my $prefix (@prefixes) {
1.145 raeburn 22186: next if ($prefix eq 'spares');
22187: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22188: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22189: if ($type eq 'version') {
22190: my $value = $env{'form.'.$prefix.'_'.$type};
22191: my $okvalue;
22192: if ($value ne '') {
22193: if (grep(/^\Q$value\E$/,@lcversions)) {
22194: $okvalue = $value;
22195: }
22196: }
22197: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22198: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22199: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22200: if ($inuse == 0) {
22201: $changes{$prefix}{$type} = 1;
22202: } else {
22203: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22204: $changes{$prefix}{$type} = 1;
22205: }
22206: if ($okvalue ne '') {
22207: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22208: }
22209: }
22210: } else {
22211: if (($inuse == 1) && ($okvalue ne '')) {
22212: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22213: $changes{$prefix}{$type} = 1;
22214: }
22215: }
22216: } else {
22217: if (($inuse == 1) && ($okvalue ne '')) {
22218: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22219: $changes{$prefix}{$type} = 1;
22220: }
22221: }
22222: } else {
22223: if (($inuse == 1) && ($okvalue ne '')) {
22224: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22225: $changes{$prefix}{$type} = 1;
22226: }
22227: }
22228: } else {
22229: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22230: my @okvals;
22231: foreach my $val (@vals) {
1.138 raeburn 22232: if ($val =~ /:/) {
22233: my @items = split(/:/,$val);
22234: foreach my $item (@items) {
22235: if (ref($by_location{$item}) eq 'ARRAY') {
22236: push(@okvals,$item);
22237: }
22238: }
22239: } else {
22240: if (ref($by_location{$val}) eq 'ARRAY') {
22241: push(@okvals,$val);
22242: }
1.137 raeburn 22243: }
22244: }
22245: @okvals = sort(@okvals);
22246: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22247: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22248: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22249: if ($inuse == 0) {
22250: $changes{$prefix}{$type} = 1;
22251: } else {
22252: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22253: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22254: if (@changed > 0) {
22255: $changes{$prefix}{$type} = 1;
22256: }
22257: }
22258: } else {
22259: if ($inuse == 1) {
22260: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22261: $changes{$prefix}{$type} = 1;
22262: }
22263: }
22264: } else {
22265: if ($inuse == 1) {
22266: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22267: $changes{$prefix}{$type} = 1;
22268: }
22269: }
22270: } else {
22271: if ($inuse == 1) {
22272: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22273: $changes{$prefix}{$type} = 1;
22274: }
22275: }
22276: }
22277: }
22278: }
1.145 raeburn 22279:
22280: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22281: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22282: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22283: my $savespares;
22284:
22285: foreach my $lonhost (sort(keys(%servers))) {
22286: my $serverhomeID =
22287: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22288: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22289: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22290: my %spareschg;
22291: foreach my $type (@{$types{'spares'}}) {
22292: my @okspares;
22293: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22294: foreach my $server (@checked) {
1.152 raeburn 22295: if (&Apache::lonnet::hostname($server) ne '') {
22296: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22297: unless (grep(/^\Q$server\E$/,@okspares)) {
22298: push(@okspares,$server);
22299: }
1.145 raeburn 22300: }
22301: }
22302: }
22303: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22304: my $newspare;
1.152 raeburn 22305: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22306: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22307: $newspare = $new;
22308: }
22309: }
1.152 raeburn 22310: my @spares;
22311: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22312: @spares = sort(@okspares,$newspare);
22313: } else {
22314: @spares = sort(@okspares);
22315: }
22316: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22317: if (ref($spareid{$lonhost}) eq 'HASH') {
22318: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22319: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22320: if (@diffs > 0) {
22321: $spareschg{$type} = 1;
22322: }
22323: }
22324: }
22325: }
22326: if (keys(%spareschg) > 0) {
22327: $changes{'spares'}{$lonhost} = \%spareschg;
22328: }
22329: }
1.261 raeburn 22330: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22331: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22332: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22333: my @okoffload;
22334: if (@offloadnow) {
22335: foreach my $server (@offloadnow) {
22336: if (&Apache::lonnet::hostname($server) ne '') {
22337: unless (grep(/^\Q$server\E$/,@okoffload)) {
22338: push(@okoffload,$server);
22339: }
22340: }
22341: }
22342: if (@okoffload) {
22343: foreach my $lonhost (@okoffload) {
22344: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22345: }
22346: }
22347: }
1.371 raeburn 22348: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22349: my @okoffloadoth;
22350: if (@offloadoth) {
22351: foreach my $server (@offloadoth) {
22352: if (&Apache::lonnet::hostname($server) ne '') {
22353: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22354: push(@okoffloadoth,$server);
22355: }
22356: }
22357: }
22358: if (@okoffloadoth) {
22359: foreach my $lonhost (@okoffloadoth) {
22360: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22361: }
22362: }
22363: }
1.145 raeburn 22364: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22365: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22366: if (ref($changes{'spares'}) eq 'HASH') {
22367: if (keys(%{$changes{'spares'}}) > 0) {
22368: $savespares = 1;
22369: }
22370: }
22371: } else {
22372: $savespares = 1;
22373: }
1.371 raeburn 22374: foreach my $offload ('offloadnow','offloadoth') {
22375: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22376: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22377: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22378: $changes{$offload} = 1;
22379: last;
22380: }
1.261 raeburn 22381: }
1.371 raeburn 22382: unless ($changes{$offload}) {
22383: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22384: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22385: $changes{$offload} = 1;
22386: last;
22387: }
1.261 raeburn 22388: }
22389: }
1.371 raeburn 22390: } else {
22391: if (($offload eq 'offloadnow') && (@okoffload)) {
22392: $changes{'offloadnow'} = 1;
22393: }
22394: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22395: $changes{'offloadoth'} = 1;
22396: }
22397: }
22398: }
22399: } else {
22400: if (@okoffload) {
1.261 raeburn 22401: $changes{'offloadnow'} = 1;
22402: }
1.371 raeburn 22403: if (@okoffloadoth) {
22404: $changes{'offloadoth'} = 1;
22405: }
1.145 raeburn 22406: }
1.147 raeburn 22407: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22408: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22409: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22410: $dom);
22411: if ($putresult eq 'ok') {
22412: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22413: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22414: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22415: }
22416: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22417: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22418: }
1.261 raeburn 22419: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22420: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22421: }
1.371 raeburn 22422: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22423: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22424: }
1.137 raeburn 22425: }
22426: my $cachetime = 24*60*60;
22427: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22428: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22429: if (ref($lastactref) eq 'HASH') {
22430: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22431: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22432: }
1.147 raeburn 22433: if (keys(%changes) > 0) {
22434: my %lt = &usersession_titles();
22435: $resulttext = &mt('Changes made:').'<ul>';
22436: foreach my $prefix (@prefixes) {
22437: if (ref($changes{$prefix}) eq 'HASH') {
22438: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22439: if ($prefix eq 'spares') {
22440: if (ref($changes{$prefix}) eq 'HASH') {
22441: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22442: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22443: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22444: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22445: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22446: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22447: foreach my $type (@{$types{$prefix}}) {
22448: if ($changes{$prefix}{$lonhost}{$type}) {
22449: my $offloadto = &mt('None');
22450: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22451: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22452: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22453: }
1.145 raeburn 22454: }
1.147 raeburn 22455: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22456: }
1.137 raeburn 22457: }
22458: }
1.147 raeburn 22459: $resulttext .= '</li>';
1.137 raeburn 22460: }
22461: }
1.147 raeburn 22462: } else {
22463: foreach my $type (@{$types{$prefix}}) {
22464: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22465: my ($newvalue,$notinuse);
1.147 raeburn 22466: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22467: if (ref($defaultshash{'usersessions'}{$prefix})) {
22468: if ($type eq 'version') {
22469: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22470: } else {
22471: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22472: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22473: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22474: }
22475: } else {
22476: $notinuse = 1;
1.147 raeburn 22477: }
1.145 raeburn 22478: }
22479: }
22480: }
1.147 raeburn 22481: if ($newvalue eq '') {
22482: if ($type eq 'version') {
22483: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22484: } elsif ($notinuse) {
22485: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22486: } else {
22487: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22488: }
1.145 raeburn 22489: } else {
1.147 raeburn 22490: if ($type eq 'version') {
1.344 raeburn 22491: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22492: }
22493: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22494: }
1.137 raeburn 22495: }
22496: }
22497: }
1.147 raeburn 22498: $resulttext .= '</ul>';
1.137 raeburn 22499: }
22500: }
1.261 raeburn 22501: if ($changes{'offloadnow'}) {
22502: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22503: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22504: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22505: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22506: $resulttext .= '<li>'.$lonhost.'</li>';
22507: }
22508: $resulttext .= '</ul>';
22509: } else {
1.371 raeburn 22510: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22511: }
22512: } else {
22513: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22514: }
22515: }
22516: if ($changes{'offloadoth'}) {
22517: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22518: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22519: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22520: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22521: $resulttext .= '<li>'.$lonhost.'</li>';
22522: }
22523: $resulttext .= '</ul>';
22524: } else {
22525: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22526: }
22527: } else {
1.371 raeburn 22528: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22529: }
22530: }
1.147 raeburn 22531: $resulttext .= '</ul>';
22532: } else {
22533: $resulttext = $nochgmsg;
1.137 raeburn 22534: }
22535: } else {
22536: $resulttext = '<span class="LC_error">'.
22537: &mt('An error occurred: [_1]',$putresult).'</span>';
22538: }
22539: } else {
1.147 raeburn 22540: $resulttext = $nochgmsg;
1.137 raeburn 22541: }
22542: return $resulttext;
22543: }
22544:
1.275 raeburn 22545: sub modify_ssl {
22546: my ($dom,$lastactref,%domconfig) = @_;
22547: my (%by_ip,%by_location,@intdoms,@instdoms);
22548: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22549: my @locations = sort(keys(%by_location));
22550: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22551: my (%defaultshash,%changes);
22552: my $action = 'ssl';
1.293 raeburn 22553: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22554: foreach my $prefix (@prefixes) {
22555: $defaultshash{$action}{$prefix} = {};
22556: }
22557: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22558: my $resulttext;
22559: my %iphost = &Apache::lonnet::get_iphost();
22560: my @reptypes = ('certreq','nocertreq');
22561: my @connecttypes = ('dom','intdom','other');
22562: my %types = (
1.293 raeburn 22563: connto => \@connecttypes,
22564: connfrom => \@connecttypes,
22565: replication => \@reptypes,
1.275 raeburn 22566: );
22567: foreach my $prefix (sort(keys(%types))) {
22568: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22569: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22570: my $value = 'yes';
22571: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22572: $value = $env{'form.'.$prefix.'_'.$type};
22573: }
1.335 raeburn 22574: if (ref($domconfig{$action}) eq 'HASH') {
22575: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22576: if ($domconfig{$action}{$prefix}{$type} ne '') {
22577: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22578: $changes{$prefix}{$type} = 1;
22579: }
22580: $defaultshash{$action}{$prefix}{$type} = $value;
22581: } else {
22582: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22583: $changes{$prefix}{$type} = 1;
22584: }
22585: } else {
22586: $defaultshash{$action}{$prefix}{$type} = $value;
22587: $changes{$prefix}{$type} = 1;
22588: }
22589: } else {
22590: $defaultshash{$action}{$prefix}{$type} = $value;
22591: $changes{$prefix}{$type} = 1;
22592: }
22593: if (($type eq 'dom') && (keys(%servers) == 1)) {
22594: delete($changes{$prefix}{$type});
22595: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22596: delete($changes{$prefix}{$type});
22597: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22598: delete($changes{$prefix}{$type});
22599: }
22600: } elsif ($prefix eq 'replication') {
22601: if (@locations > 0) {
22602: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22603: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22604: my @okvals;
22605: foreach my $val (@vals) {
22606: if ($val =~ /:/) {
22607: my @items = split(/:/,$val);
22608: foreach my $item (@items) {
22609: if (ref($by_location{$item}) eq 'ARRAY') {
22610: push(@okvals,$item);
22611: }
22612: }
22613: } else {
22614: if (ref($by_location{$val}) eq 'ARRAY') {
22615: push(@okvals,$val);
22616: }
22617: }
22618: }
22619: @okvals = sort(@okvals);
22620: if (ref($domconfig{$action}) eq 'HASH') {
22621: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22622: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22623: if ($inuse == 0) {
22624: $changes{$prefix}{$type} = 1;
22625: } else {
22626: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22627: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22628: if (@changed > 0) {
22629: $changes{$prefix}{$type} = 1;
22630: }
22631: }
22632: } else {
22633: if ($inuse == 1) {
22634: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22635: $changes{$prefix}{$type} = 1;
22636: }
22637: }
22638: } else {
22639: if ($inuse == 1) {
22640: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22641: $changes{$prefix}{$type} = 1;
22642: }
22643: }
22644: } else {
22645: if ($inuse == 1) {
22646: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22647: $changes{$prefix}{$type} = 1;
22648: }
22649: }
22650: }
22651: }
22652: }
22653: }
1.336 raeburn 22654: if (keys(%changes)) {
22655: foreach my $prefix (keys(%changes)) {
22656: if (ref($changes{$prefix}) eq 'HASH') {
22657: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22658: delete($changes{$prefix});
22659: }
22660: } else {
22661: delete($changes{$prefix});
22662: }
22663: }
22664: }
1.275 raeburn 22665: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22666: if (keys(%changes) > 0) {
22667: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22668: $dom);
22669: if ($putresult eq 'ok') {
22670: if (ref($defaultshash{$action}) eq 'HASH') {
22671: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22672: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22673: }
1.293 raeburn 22674: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22675: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22676: }
22677: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22678: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22679: }
22680: }
22681: my $cachetime = 24*60*60;
22682: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22683: if (ref($lastactref) eq 'HASH') {
22684: $lastactref->{'domdefaults'} = 1;
22685: }
22686: if (keys(%changes) > 0) {
22687: my %titles = &ssl_titles();
22688: $resulttext = &mt('Changes made:').'<ul>';
22689: foreach my $prefix (@prefixes) {
22690: if (ref($changes{$prefix}) eq 'HASH') {
22691: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22692: foreach my $type (@{$types{$prefix}}) {
22693: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22694: my ($newvalue,$notinuse);
1.275 raeburn 22695: if (ref($defaultshash{$action}) eq 'HASH') {
22696: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22697: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22698: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22699: } else {
22700: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22701: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22702: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22703: }
22704: } else {
22705: $notinuse = 1;
1.275 raeburn 22706: }
22707: }
22708: }
1.344 raeburn 22709: if ($notinuse) {
22710: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22711: } elsif ($newvalue eq '') {
1.275 raeburn 22712: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22713: } else {
22714: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22715: }
22716: }
22717: }
22718: }
22719: $resulttext .= '</ul>';
22720: }
22721: }
22722: } else {
22723: $resulttext = $nochgmsg;
22724: }
22725: } else {
22726: $resulttext = '<span class="LC_error">'.
22727: &mt('An error occurred: [_1]',$putresult).'</span>';
22728: }
22729: } else {
22730: $resulttext = $nochgmsg;
22731: }
22732: return $resulttext;
22733: }
22734:
1.279 raeburn 22735: sub modify_trust {
22736: my ($dom,$lastactref,%domconfig) = @_;
22737: my (%by_ip,%by_location,@intdoms,@instdoms);
22738: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22739: my @locations = sort(keys(%by_location));
22740: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22741: my @types = ('exc','inc');
22742: my (%defaultshash,%changes);
22743: foreach my $prefix (@prefixes) {
22744: $defaultshash{'trust'}{$prefix} = {};
22745: }
22746: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22747: my $resulttext;
22748: foreach my $prefix (@prefixes) {
22749: foreach my $type (@types) {
22750: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22751: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22752: my @okvals;
22753: foreach my $val (@vals) {
22754: if ($val =~ /:/) {
22755: my @items = split(/:/,$val);
22756: foreach my $item (@items) {
22757: if (ref($by_location{$item}) eq 'ARRAY') {
22758: push(@okvals,$item);
22759: }
22760: }
22761: } else {
22762: if (ref($by_location{$val}) eq 'ARRAY') {
22763: push(@okvals,$val);
22764: }
22765: }
22766: }
22767: @okvals = sort(@okvals);
22768: if (ref($domconfig{'trust'}) eq 'HASH') {
22769: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22770: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22771: if ($inuse == 0) {
22772: $changes{$prefix}{$type} = 1;
22773: } else {
22774: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22775: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22776: if (@changed > 0) {
22777: $changes{$prefix}{$type} = 1;
22778: }
22779: }
22780: } else {
22781: if ($inuse == 1) {
22782: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22783: $changes{$prefix}{$type} = 1;
22784: }
22785: }
22786: } else {
22787: if ($inuse == 1) {
22788: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22789: $changes{$prefix}{$type} = 1;
22790: }
22791: }
22792: } else {
22793: if ($inuse == 1) {
22794: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22795: $changes{$prefix}{$type} = 1;
22796: }
22797: }
22798: }
22799: }
22800: my $nochgmsg = &mt('No changes made to trust settings.');
22801: if (keys(%changes) > 0) {
22802: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22803: $dom);
22804: if ($putresult eq 'ok') {
22805: if (ref($defaultshash{'trust'}) eq 'HASH') {
22806: foreach my $prefix (@prefixes) {
22807: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22808: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22809: }
22810: }
22811: }
22812: my $cachetime = 24*60*60;
22813: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22814: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22815: if (ref($lastactref) eq 'HASH') {
22816: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22817: $lastactref->{'trust'} = 1;
1.279 raeburn 22818: }
22819: if (keys(%changes) > 0) {
22820: my %lt = &trust_titles();
22821: $resulttext = &mt('Changes made:').'<ul>';
22822: foreach my $prefix (@prefixes) {
22823: if (ref($changes{$prefix}) eq 'HASH') {
22824: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22825: foreach my $type (@types) {
22826: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22827: my ($newvalue,$notinuse);
1.279 raeburn 22828: if (ref($defaultshash{'trust'}) eq 'HASH') {
22829: if (ref($defaultshash{'trust'}{$prefix})) {
22830: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22831: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22832: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22833: }
1.344 raeburn 22834: } else {
22835: $notinuse = 1;
1.279 raeburn 22836: }
22837: }
22838: }
1.344 raeburn 22839: if ($notinuse) {
22840: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22841: } elsif ($newvalue eq '') {
1.279 raeburn 22842: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22843: } else {
22844: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22845: }
22846: }
22847: }
22848: $resulttext .= '</ul>';
22849: }
22850: }
22851: $resulttext .= '</ul>';
22852: } else {
22853: $resulttext = $nochgmsg;
22854: }
22855: } else {
22856: $resulttext = '<span class="LC_error">'.
22857: &mt('An error occurred: [_1]',$putresult).'</span>';
22858: }
22859: } else {
22860: $resulttext = $nochgmsg;
22861: }
22862: return $resulttext;
22863: }
22864:
1.150 raeburn 22865: sub modify_loadbalancing {
22866: my ($dom,%domconfig) = @_;
22867: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22868: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22869: my ($othertitle,$usertypes,$types) =
22870: &Apache::loncommon::sorted_inst_types($dom);
22871: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22872: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22873: my @sparestypes = ('primary','default');
22874: my %typetitles = &sparestype_titles();
22875: my $resulttext;
1.342 raeburn 22876: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22877: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22878: %existing = %{$domconfig{'loadbalancing'}};
22879: }
22880: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22881: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22882: my ($saveloadbalancing,%defaultshash,%changes);
22883: my ($alltypes,$othertypes,$titles) =
22884: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22885: my %ruletitles = &offloadtype_text();
22886: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22887: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22888: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22889: if ($balancer eq '') {
22890: next;
22891: }
1.210 raeburn 22892: if (!exists($servers{$balancer})) {
1.171 raeburn 22893: if (exists($currbalancer{$balancer})) {
22894: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22895: }
1.171 raeburn 22896: next;
22897: }
22898: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22899: push(@{$changes{'delete'}},$balancer);
22900: next;
22901: }
22902: if (!exists($currbalancer{$balancer})) {
22903: push(@{$changes{'add'}},$balancer);
22904: }
22905: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22906: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22907: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22908: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22909: $saveloadbalancing = 1;
22910: }
22911: foreach my $sparetype (@sparestypes) {
22912: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22913: my @offloadto;
22914: foreach my $target (@targets) {
22915: if (($servers{$target}) && ($target ne $balancer)) {
22916: if ($sparetype eq 'default') {
22917: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22918: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22919: }
22920: }
1.171 raeburn 22921: unless(grep(/^\Q$target\E$/,@offloadto)) {
22922: push(@offloadto,$target);
22923: }
1.150 raeburn 22924: }
22925: }
1.284 raeburn 22926: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22927: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22928: push(@offloadto,$balancer);
22929: }
22930: }
22931: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22932: }
1.342 raeburn 22933: if ($env{'form.loadbalancing_cookie_'.$i}) {
22934: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
22935: if (exists($currbalancer{$balancer})) {
22936: unless ($currcookies{$balancer}) {
22937: $changes{'curr'}{$balancer}{'cookie'} = 1;
22938: }
22939: }
22940: } elsif (exists($currbalancer{$balancer})) {
22941: if ($currcookies{$balancer}) {
22942: $changes{'curr'}{$balancer}{'cookie'} = 1;
22943: }
22944: }
1.171 raeburn 22945: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22946: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22947: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22948: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22949: if (@targetdiffs > 0) {
1.171 raeburn 22950: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22951: }
1.171 raeburn 22952: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22953: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22954: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22955: }
22956: }
22957: }
22958: } else {
1.171 raeburn 22959: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22960: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22961: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22962: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22963: $changes{'curr'}{$balancer}{'targets'} = 1;
22964: }
1.150 raeburn 22965: }
22966: }
1.210 raeburn 22967: }
1.150 raeburn 22968: }
22969: my $ishomedom;
1.171 raeburn 22970: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22971: $ishomedom = 1;
1.150 raeburn 22972: }
22973: if (ref($alltypes) eq 'ARRAY') {
22974: foreach my $type (@{$alltypes}) {
22975: my $rule;
1.210 raeburn 22976: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22977: (!$ishomedom)) {
1.171 raeburn 22978: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22979: }
22980: if ($rule eq 'specific') {
1.255 raeburn 22981: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22982: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22983: $rule = $specifiedhost;
22984: }
1.150 raeburn 22985: }
1.171 raeburn 22986: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22987: if (ref($currrules{$balancer}) eq 'HASH') {
22988: if ($rule ne $currrules{$balancer}{$type}) {
22989: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22990: }
22991: } elsif ($rule ne '') {
1.171 raeburn 22992: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22993: }
22994: }
22995: }
1.171 raeburn 22996: }
22997: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22998: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22999: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23000: $defaultshash{'loadbalancing'} = {};
23001: }
23002: my $putresult = &Apache::lonnet::put_dom('configuration',
23003: \%defaultshash,$dom);
23004: if ($putresult eq 'ok') {
23005: if (keys(%changes) > 0) {
1.252 raeburn 23006: my %toupdate;
1.171 raeburn 23007: if (ref($changes{'delete'}) eq 'ARRAY') {
23008: foreach my $balancer (sort(@{$changes{'delete'}})) {
23009: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23010: $toupdate{$balancer} = 1;
1.150 raeburn 23011: }
1.171 raeburn 23012: }
23013: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23014: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23015: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23016: $toupdate{$balancer} = 1;
1.171 raeburn 23017: }
23018: }
23019: if (ref($changes{'curr'}) eq 'HASH') {
23020: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23021: $toupdate{$balancer} = 1;
1.171 raeburn 23022: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23023: if ($changes{'curr'}{$balancer}{'targets'}) {
23024: my %offloadstr;
23025: foreach my $sparetype (@sparestypes) {
23026: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23027: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23028: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23029: }
23030: }
1.150 raeburn 23031: }
1.171 raeburn 23032: if (keys(%offloadstr) == 0) {
23033: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23034: } else {
1.171 raeburn 23035: my $showoffload;
23036: foreach my $sparetype (@sparestypes) {
23037: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23038: if (defined($offloadstr{$sparetype})) {
23039: $showoffload .= $offloadstr{$sparetype};
23040: } else {
23041: $showoffload .= &mt('None');
23042: }
23043: $showoffload .= (' 'x3);
23044: }
23045: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23046: }
23047: }
23048: }
1.171 raeburn 23049: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23050: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23051: foreach my $type (@{$alltypes}) {
23052: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23053: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23054: my $balancetext;
23055: if ($rule eq '') {
23056: $balancetext = $ruletitles{'default'};
1.209 raeburn 23057: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23058: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23059: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23060: foreach my $sparetype (@sparestypes) {
23061: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23062: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23063: }
23064: }
1.253 raeburn 23065: foreach my $item (@{$alltypes}) {
23066: next if ($item =~ /^_LC_ipchange/);
23067: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23068: if ($hasrule eq 'homeserver') {
23069: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23070: } else {
23071: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23072: if ($servers{$hasrule}) {
23073: $toupdate{$hasrule} = 1;
23074: }
23075: }
23076: }
23077: }
1.254 raeburn 23078: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23079: $balancetext = $ruletitles{$rule};
23080: } else {
23081: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23082: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23083: if ($receiver) {
23084: $toupdate{$receiver};
23085: }
23086: }
23087: } else {
23088: $balancetext = $ruletitles{$rule};
1.252 raeburn 23089: }
1.171 raeburn 23090: } else {
23091: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23092: }
1.210 raeburn 23093: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23094: }
23095: }
23096: }
23097: }
1.342 raeburn 23098: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23099: if ($currcookies{$balancer}) {
23100: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23101: $balancer).'</li>';
23102: } else {
23103: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23104: $balancer).'</li>';
23105: }
1.342 raeburn 23106: }
1.375 raeburn 23107: }
23108: }
23109: if (keys(%toupdate)) {
23110: my %thismachine;
23111: my $updatedhere;
23112: my $cachetime = 60*60*24;
23113: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23114: foreach my $lonhost (keys(%toupdate)) {
23115: if ($thismachine{$lonhost}) {
23116: unless ($updatedhere) {
23117: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23118: $defaultshash{'loadbalancing'},
23119: $cachetime);
23120: $updatedhere = 1;
1.252 raeburn 23121: }
1.375 raeburn 23122: } else {
23123: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23124: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23125: }
1.150 raeburn 23126: }
1.171 raeburn 23127: }
23128: if ($resulttext ne '') {
23129: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23130: } else {
23131: $resulttext = $nochgmsg;
23132: }
23133: } else {
1.171 raeburn 23134: $resulttext = $nochgmsg;
1.150 raeburn 23135: }
23136: } else {
1.171 raeburn 23137: $resulttext = '<span class="LC_error">'.
23138: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23139: }
23140: } else {
1.171 raeburn 23141: $resulttext = $nochgmsg;
1.150 raeburn 23142: }
23143: return $resulttext;
23144: }
23145:
1.48 raeburn 23146: sub recurse_check {
23147: my ($chkcats,$categories,$depth,$name) = @_;
23148: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23149: my $chg = 0;
23150: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23151: my $category = $chkcats->[$depth]{$name}[$j];
23152: my $item;
23153: if ($category eq '') {
23154: $chg ++;
23155: } else {
23156: my $deeper = $depth + 1;
23157: $item = &escape($category).':'.&escape($name).':'.$depth;
23158: if ($chg) {
23159: $categories->{$item} -= $chg;
23160: }
23161: &recurse_check($chkcats,$categories,$deeper,$category);
23162: $deeper --;
23163: }
23164: }
23165: }
23166: return;
23167: }
23168:
23169: sub recurse_cat_deletes {
23170: my ($item,$coursecategories,$deletions) = @_;
23171: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23172: my $subdepth = $depth + 1;
23173: if (ref($coursecategories) eq 'HASH') {
23174: foreach my $subitem (keys(%{$coursecategories})) {
23175: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23176: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23177: delete($coursecategories->{$subitem});
23178: $deletions->{$subitem} = 1;
23179: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23180: }
1.48 raeburn 23181: }
23182: }
23183: return;
23184: }
23185:
1.125 raeburn 23186: sub active_dc_picker {
1.191 raeburn 23187: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23188: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23189: my @domcoord = keys(%domcoords);
23190: if (keys(%currhash)) {
23191: foreach my $dc (keys(%currhash)) {
23192: unless (exists($domcoords{$dc})) {
23193: push(@domcoord,$dc);
23194: }
23195: }
23196: }
23197: @domcoord = sort(@domcoord);
1.210 raeburn 23198: my $numdcs = scalar(@domcoord);
1.191 raeburn 23199: my $rows = 0;
23200: my $table;
1.125 raeburn 23201: if ($numdcs > 1) {
1.191 raeburn 23202: $table = '<table>';
23203: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23204: my $rem = $i%($numinrow);
23205: if ($rem == 0) {
23206: if ($i > 0) {
1.191 raeburn 23207: $table .= '</tr>';
1.125 raeburn 23208: }
1.191 raeburn 23209: $table .= '<tr>';
23210: $rows ++;
1.125 raeburn 23211: }
1.191 raeburn 23212: my $check = '';
23213: if ($inputtype eq 'radio') {
23214: if (keys(%currhash) == 0) {
23215: if (!$i) {
23216: $check = ' checked="checked"';
23217: }
23218: } elsif (exists($currhash{$domcoord[$i]})) {
23219: $check = ' checked="checked"';
23220: }
23221: } else {
23222: if (exists($currhash{$domcoord[$i]})) {
23223: $check = ' checked="checked"';
1.125 raeburn 23224: }
23225: }
1.191 raeburn 23226: if ($i == @domcoord - 1) {
1.125 raeburn 23227: my $colsleft = $numinrow - $rem;
23228: if ($colsleft > 1) {
1.191 raeburn 23229: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23230: } else {
1.191 raeburn 23231: $table .= '<td class="LC_left_item">';
1.125 raeburn 23232: }
23233: } else {
1.191 raeburn 23234: $table .= '<td class="LC_left_item">';
23235: }
23236: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23237: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23238: $table .= '<span class="LC_nobreak"><label>'.
23239: '<input type="'.$inputtype.'" name="'.$name.'"'.
23240: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23241: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23242: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23243: }
1.219 raeburn 23244: $table .= '</label></span></td>';
1.191 raeburn 23245: }
23246: $table .= '</tr></table>';
23247: } elsif ($numdcs == 1) {
1.219 raeburn 23248: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23249: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23250: if ($inputtype eq 'radio') {
1.247 raeburn 23251: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23252: if ($user ne $dcname.':'.$dcdom) {
23253: $table .= ' ('.$dcname.':'.$dcdom.')';
23254: }
1.191 raeburn 23255: } else {
23256: my $check;
23257: if (exists($currhash{$domcoord[0]})) {
23258: $check = ' checked="checked"';
1.125 raeburn 23259: }
1.247 raeburn 23260: $table = '<span class="LC_nobreak"><label>'.
23261: '<input type="checkbox" name="'.$name.'" '.
23262: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23263: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23264: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23265: }
1.220 raeburn 23266: $table .= '</label></span>';
1.191 raeburn 23267: $rows ++;
1.125 raeburn 23268: }
23269: }
1.191 raeburn 23270: return ($numdcs,$table,$rows);
1.125 raeburn 23271: }
23272:
1.137 raeburn 23273: sub usersession_titles {
23274: return &Apache::lonlocal::texthash(
23275: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23276: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23277: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23278: version => 'LON-CAPA version requirement',
1.138 raeburn 23279: excludedomain => 'Allow all, but exclude specific domains',
23280: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23281: primary => 'Primary (checked first)',
1.154 raeburn 23282: default => 'Default',
1.137 raeburn 23283: );
23284: }
23285:
1.152 raeburn 23286: sub id_for_thisdom {
23287: my (%servers) = @_;
23288: my %altids;
23289: foreach my $server (keys(%servers)) {
23290: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23291: if ($serverhome ne $server) {
23292: $altids{$serverhome} = $server;
23293: }
23294: }
23295: return %altids;
23296: }
23297:
1.150 raeburn 23298: sub count_servers {
23299: my ($currbalancer,%servers) = @_;
23300: my (@spares,$numspares);
23301: foreach my $lonhost (sort(keys(%servers))) {
23302: next if ($currbalancer eq $lonhost);
23303: push(@spares,$lonhost);
23304: }
23305: if ($currbalancer) {
23306: $numspares = scalar(@spares);
23307: } else {
23308: $numspares = scalar(@spares) - 1;
23309: }
23310: return ($numspares,@spares);
23311: }
23312:
23313: sub lonbalance_targets_js {
1.171 raeburn 23314: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23315: my $select = &mt('Select');
23316: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23317: if (ref($servers) eq 'HASH') {
23318: $alltargets = join("','",sort(keys(%{$servers})));
23319: my @homedoms;
23320: foreach my $server (sort(keys(%{$servers}))) {
23321: if (&Apache::lonnet::host_domain($server) eq $dom) {
23322: push(@homedoms,'1');
23323: } else {
23324: push(@homedoms,'0');
23325: }
23326: }
23327: $allishome = join("','",@homedoms);
23328: }
23329: if (ref($types) eq 'ARRAY') {
23330: if (@{$types} > 0) {
23331: @alltypes = @{$types};
23332: }
23333: }
23334: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23335: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23336: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23337: if (ref($settings) eq 'HASH') {
23338: %existing = %{$settings};
23339: }
23340: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23341: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23342: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23343: return <<"END";
23344:
23345: <script type="text/javascript">
23346: // <![CDATA[
23347:
1.171 raeburn 23348: currBalancers = new Array('$balancers');
23349:
23350: function toggleTargets(balnum) {
23351: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23352: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23353: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23354: var prevbalancer = prevhostitem.value;
23355: var baltotal = document.getElementById('loadbalancing_total').value;
23356: prevhostitem.value = balancer;
23357: if (prevbalancer != '') {
23358: var prevIdx = currBalancers.indexOf(prevbalancer);
23359: if (prevIdx != -1) {
23360: currBalancers.splice(prevIdx,1);
23361: }
23362: }
1.150 raeburn 23363: if (balancer == '') {
1.171 raeburn 23364: hideSpares(balnum);
1.150 raeburn 23365: } else {
1.171 raeburn 23366: var currIdx = currBalancers.indexOf(balancer);
23367: if (currIdx == -1) {
23368: currBalancers.push(balancer);
23369: }
1.150 raeburn 23370: var homedoms = new Array('$allishome');
1.171 raeburn 23371: var ishomedom = homedoms[lonhostitem.selectedIndex];
23372: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23373: }
1.171 raeburn 23374: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23375: return;
23376: }
23377:
1.171 raeburn 23378: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23379: var alltargets = new Array('$alltargets');
23380: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23381: var offloadtypes = new Array('primary','default');
23382:
1.171 raeburn 23383: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23384: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23385:
1.151 raeburn 23386: for (var i=0; i<offloadtypes.length; i++) {
23387: var count = 0;
23388: for (var j=0; j<alltargets.length; j++) {
23389: if (alltargets[j] != balancer) {
1.171 raeburn 23390: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23391: item.value = alltargets[j];
23392: item.style.textAlign='left';
23393: item.style.textFace='normal';
23394: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23395: if (currBalancers.indexOf(alltargets[j]) == -1) {
23396: item.disabled = '';
23397: } else {
23398: item.disabled = 'disabled';
23399: item.checked = false;
23400: }
1.151 raeburn 23401: count ++;
23402: }
1.150 raeburn 23403: }
23404: }
1.151 raeburn 23405: for (var k=0; k<insttypes.length; k++) {
23406: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23407: if (ishomedom == 1) {
1.171 raeburn 23408: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23409: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23410: } else {
1.171 raeburn 23411: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23412: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23413: }
23414: } else {
1.171 raeburn 23415: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23416: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23417: }
1.151 raeburn 23418: if ((insttypes[k] != '_LC_external') &&
23419: ((insttypes[k] != '_LC_internetdom') ||
23420: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23421: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23422: item.options.length = 0;
23423: item.options[0] = new Option("","",true,true);
1.210 raeburn 23424: var idx = 0;
1.151 raeburn 23425: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23426: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23427: idx ++;
23428: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23429: }
23430: }
23431: }
23432: }
23433: return;
23434: }
23435:
1.171 raeburn 23436: function hideSpares(balnum) {
1.150 raeburn 23437: var alltargets = new Array('$alltargets');
23438: var insttypes = new Array('$allinsttypes');
23439: var offloadtypes = new Array('primary','default');
23440:
1.171 raeburn 23441: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23442: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23443:
23444: var total = alltargets.length - 1;
23445: for (var i=0; i<offloadtypes; i++) {
23446: for (var j=0; j<total; j++) {
1.171 raeburn 23447: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23448: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23449: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23450: }
1.150 raeburn 23451: }
23452: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23453: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23454: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23455: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23456: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23457: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23458: }
23459: }
23460: return;
23461: }
23462:
1.171 raeburn 23463: function checkOffloads(item,balnum,type) {
1.150 raeburn 23464: var alltargets = new Array('$alltargets');
23465: var offloadtypes = new Array('primary','default');
23466: if (item.checked) {
23467: var total = alltargets.length - 1;
23468: var other;
23469: if (type == offloadtypes[0]) {
1.151 raeburn 23470: other = offloadtypes[1];
1.150 raeburn 23471: } else {
1.151 raeburn 23472: other = offloadtypes[0];
1.150 raeburn 23473: }
23474: for (var i=0; i<total; i++) {
1.171 raeburn 23475: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23476: if (server == item.value) {
1.171 raeburn 23477: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23478: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23479: }
23480: }
23481: }
23482: }
23483: return;
23484: }
23485:
1.171 raeburn 23486: function singleServerToggle(balnum,type) {
23487: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23488: if (offloadtoSelIdx == 0) {
1.171 raeburn 23489: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23490: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23491:
23492: } else {
1.171 raeburn 23493: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23494: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23495: }
23496: return;
23497: }
23498:
1.171 raeburn 23499: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23500: if (type == '_LC_external') {
1.171 raeburn 23501: return;
1.150 raeburn 23502: }
1.171 raeburn 23503: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23504: for (var i=0; i<typesRules.length; i++) {
23505: if (formname.elements[typesRules[i]].checked) {
23506: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23507: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23508: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23509: } else {
1.171 raeburn 23510: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23511: }
23512: }
23513: }
23514: return;
23515: }
23516:
23517: function balancerDeleteChange(balnum) {
23518: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23519: var baltotal = document.getElementById('loadbalancing_total').value;
23520: var addtarget;
23521: var removetarget;
23522: var action = 'delete';
23523: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23524: var lonhost = hostitem.value;
23525: var currIdx = currBalancers.indexOf(lonhost);
23526: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23527: if (currIdx != -1) {
23528: currBalancers.splice(currIdx,1);
23529: }
23530: addtarget = lonhost;
23531: } else {
23532: if (currIdx == -1) {
23533: currBalancers.push(lonhost);
23534: }
23535: removetarget = lonhost;
23536: action = 'undelete';
23537: }
23538: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23539: }
23540: return;
23541: }
23542:
23543: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23544: if (baltotal > 1) {
23545: var offloadtypes = new Array('primary','default');
23546: var alltargets = new Array('$alltargets');
23547: var insttypes = new Array('$allinsttypes');
23548: for (var i=0; i<baltotal; i++) {
23549: if (i != balnum) {
23550: for (var j=0; j<offloadtypes.length; j++) {
23551: var total = alltargets.length - 1;
23552: for (var k=0; k<total; k++) {
23553: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23554: var server = serveritem.value;
23555: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23556: if (server == addtarget) {
23557: serveritem.disabled = '';
23558: }
23559: }
23560: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23561: if (server == removetarget) {
23562: serveritem.disabled = 'disabled';
23563: serveritem.checked = false;
23564: }
23565: }
23566: }
23567: }
23568: for (var j=0; j<insttypes.length; j++) {
23569: if (insttypes[j] != '_LC_external') {
23570: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23571: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23572: var currSel = singleserver.selectedIndex;
23573: var currVal = singleserver.options[currSel].value;
23574: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23575: var numoptions = singleserver.options.length;
23576: var needsnew = 1;
23577: for (var k=0; k<numoptions; k++) {
23578: if (singleserver.options[k] == addtarget) {
23579: needsnew = 0;
23580: break;
23581: }
23582: }
23583: if (needsnew == 1) {
23584: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23585: }
23586: }
23587: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23588: singleserver.options.length = 0;
23589: if ((currVal) && (currVal != removetarget)) {
23590: singleserver.options[0] = new Option("","",false,false);
23591: } else {
23592: singleserver.options[0] = new Option("","",true,true);
23593: }
23594: var idx = 0;
23595: for (var m=0; m<alltargets.length; m++) {
23596: if (currBalancers.indexOf(alltargets[m]) == -1) {
23597: idx ++;
23598: if (currVal == alltargets[m]) {
23599: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23600: } else {
23601: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23602: }
23603: }
23604: }
23605: }
23606: }
23607: }
23608: }
1.150 raeburn 23609: }
23610: }
23611: }
23612: return;
23613: }
23614:
1.152 raeburn 23615: // ]]>
23616: </script>
23617:
23618: END
23619: }
23620:
1.372 raeburn 23621:
1.152 raeburn 23622: sub new_spares_js {
23623: my @sparestypes = ('primary','default');
23624: my $types = join("','",@sparestypes);
23625: my $select = &mt('Select');
23626: return <<"END";
23627:
23628: <script type="text/javascript">
23629: // <![CDATA[
23630:
23631: function updateNewSpares(formname,lonhost) {
23632: var types = new Array('$types');
23633: var include = new Array();
23634: var exclude = new Array();
23635: for (var i=0; i<types.length; i++) {
23636: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23637: for (var j=0; j<spareboxes.length; j++) {
23638: if (formname.elements[spareboxes[j]].checked) {
23639: exclude.push(formname.elements[spareboxes[j]].value);
23640: } else {
23641: include.push(formname.elements[spareboxes[j]].value);
23642: }
23643: }
23644: }
23645: for (var i=0; i<types.length; i++) {
23646: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23647: var selIdx = newSpare.selectedIndex;
23648: var currnew = newSpare.options[selIdx].value;
23649: var okSpares = new Array();
23650: for (var j=0; j<newSpare.options.length; j++) {
23651: var possible = newSpare.options[j].value;
23652: if (possible != '') {
23653: if (exclude.indexOf(possible) == -1) {
23654: okSpares.push(possible);
23655: } else {
23656: if (currnew == possible) {
23657: selIdx = 0;
23658: }
23659: }
23660: }
23661: }
23662: for (var k=0; k<include.length; k++) {
23663: if (okSpares.indexOf(include[k]) == -1) {
23664: okSpares.push(include[k]);
23665: }
23666: }
23667: okSpares.sort();
23668: newSpare.options.length = 0;
23669: if (selIdx == 0) {
23670: newSpare.options[0] = new Option("$select","",true,true);
23671: } else {
23672: newSpare.options[0] = new Option("$select","",false,false);
23673: }
23674: for (var m=0; m<okSpares.length; m++) {
23675: var idx = m+1;
23676: var selThis = 0;
23677: if (selIdx != 0) {
23678: if (okSpares[m] == currnew) {
23679: selThis = 1;
23680: }
23681: }
23682: if (selThis == 1) {
23683: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23684: } else {
23685: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23686: }
23687: }
23688: }
23689: return;
23690: }
23691:
23692: function checkNewSpares(lonhost,type) {
23693: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23694: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23695: if (chosen != '') {
1.152 raeburn 23696: var othertype;
23697: var othernewSpare;
23698: if (type == 'primary') {
23699: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23700: }
23701: if (type == 'default') {
23702: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23703: }
23704: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23705: othernewSpare.selectedIndex = 0;
23706: }
23707: }
23708: return;
23709: }
23710:
23711: // ]]>
23712: </script>
23713:
23714: END
23715:
23716: }
23717:
23718: sub common_domprefs_js {
23719: return <<"END";
23720:
23721: <script type="text/javascript">
23722: // <![CDATA[
23723:
1.150 raeburn 23724: function getIndicesByName(formname,item) {
1.152 raeburn 23725: var group = new Array();
1.150 raeburn 23726: for (var i=0;i<formname.elements.length;i++) {
23727: if (formname.elements[i].name == item) {
1.152 raeburn 23728: group.push(formname.elements[i].id);
1.150 raeburn 23729: }
23730: }
1.152 raeburn 23731: return group;
1.150 raeburn 23732: }
23733:
23734: // ]]>
23735: </script>
23736:
23737: END
1.152 raeburn 23738:
1.150 raeburn 23739: }
23740:
1.165 raeburn 23741: sub recaptcha_js {
23742: my %lt = &captcha_phrases();
23743: return <<"END";
23744:
23745: <script type="text/javascript">
23746: // <![CDATA[
23747:
23748: function updateCaptcha(caller,context) {
23749: var privitem;
23750: var pubitem;
23751: var privtext;
23752: var pubtext;
1.269 raeburn 23753: var versionitem;
23754: var versiontext;
1.165 raeburn 23755: if (document.getElementById(context+'_recaptchapub')) {
23756: pubitem = document.getElementById(context+'_recaptchapub');
23757: } else {
23758: return;
23759: }
23760: if (document.getElementById(context+'_recaptchapriv')) {
23761: privitem = document.getElementById(context+'_recaptchapriv');
23762: } else {
23763: return;
23764: }
23765: if (document.getElementById(context+'_recaptchapubtxt')) {
23766: pubtext = document.getElementById(context+'_recaptchapubtxt');
23767: } else {
23768: return;
23769: }
23770: if (document.getElementById(context+'_recaptchaprivtxt')) {
23771: privtext = document.getElementById(context+'_recaptchaprivtxt');
23772: } else {
23773: return;
23774: }
1.269 raeburn 23775: if (document.getElementById(context+'_recaptchaversion')) {
23776: versionitem = document.getElementById(context+'_recaptchaversion');
23777: } else {
23778: return;
23779: }
23780: if (document.getElementById(context+'_recaptchavertxt')) {
23781: versiontext = document.getElementById(context+'_recaptchavertxt');
23782: } else {
23783: return;
23784: }
1.165 raeburn 23785: if (caller.checked) {
23786: if (caller.value == 'recaptcha') {
23787: pubitem.type = 'text';
23788: privitem.type = 'text';
23789: pubitem.size = '40';
23790: privitem.size = '40';
23791: pubtext.innerHTML = "$lt{'pub'}";
23792: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23793: versionitem.type = 'text';
23794: versionitem.size = '3';
1.289 raeburn 23795: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23796: } else {
23797: pubitem.type = 'hidden';
23798: privitem.type = 'hidden';
1.269 raeburn 23799: versionitem.type = 'hidden';
1.165 raeburn 23800: pubtext.innerHTML = '';
23801: privtext.innerHTML = '';
1.269 raeburn 23802: versiontext.innerHTML = '';
1.165 raeburn 23803: }
23804: }
23805: return;
23806: }
23807:
23808: // ]]>
23809: </script>
23810:
23811: END
23812:
23813: }
23814:
1.236 raeburn 23815: sub toggle_display_js {
1.192 raeburn 23816: return <<"END";
23817:
23818: <script type="text/javascript">
23819: // <![CDATA[
23820:
1.236 raeburn 23821: function toggleDisplay(domForm,caller) {
23822: if (document.getElementById(caller)) {
23823: var divitem = document.getElementById(caller);
23824: var optionsElement = domForm.coursecredits;
1.264 raeburn 23825: var checkval = 1;
23826: var dispval = 'block';
1.303 raeburn 23827: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23828: if (caller == 'emailoptions') {
1.372 raeburn 23829: optionsElement = domForm.cancreate_email;
1.236 raeburn 23830: }
1.257 raeburn 23831: if (caller == 'studentsubmission') {
23832: optionsElement = domForm.postsubmit;
23833: }
1.264 raeburn 23834: if (caller == 'cloneinstcode') {
23835: optionsElement = domForm.canclone;
23836: checkval = 'instcode';
23837: }
1.303 raeburn 23838: if (selfcreateRegExp.test(caller)) {
23839: optionsElement = domForm.elements[caller];
23840: checkval = 'other';
23841: dispval = 'inline'
23842: }
1.236 raeburn 23843: if (optionsElement.length) {
1.192 raeburn 23844: var currval;
1.236 raeburn 23845: for (var i=0; i<optionsElement.length; i++) {
23846: if (optionsElement[i].checked) {
23847: currval = optionsElement[i].value;
1.192 raeburn 23848: }
23849: }
1.264 raeburn 23850: if (currval == checkval) {
23851: divitem.style.display = dispval;
1.192 raeburn 23852: } else {
1.236 raeburn 23853: divitem.style.display = 'none';
1.192 raeburn 23854: }
23855: }
23856: }
23857: return;
23858: }
23859:
23860: // ]]>
23861: </script>
23862:
23863: END
23864:
23865: }
23866:
1.165 raeburn 23867: sub captcha_phrases {
23868: return &Apache::lonlocal::texthash (
23869: priv => 'Private key',
23870: pub => 'Public key',
23871: original => 'original (CAPTCHA)',
23872: recaptcha => 'successor (ReCAPTCHA)',
23873: notused => 'unused',
1.289 raeburn 23874: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23875: );
23876: }
23877:
1.205 raeburn 23878: sub devalidate_remote_domconfs {
1.212 raeburn 23879: my ($dom,$cachekeys) = @_;
23880: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23881: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23882: my %thismachine;
23883: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23884: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23885: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23886: 'ipaccess','trust');
1.386 raeburn 23887: my %cache_by_lonhost;
23888: if (exists($cachekeys->{'samllanding'})) {
23889: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23890: my %landing = %{$cachekeys->{'samllanding'}};
23891: my %domservers = &Apache::lonnet::get_servers($dom);
23892: if (keys(%domservers)) {
23893: foreach my $server (keys(%domservers)) {
23894: my @cached;
23895: next if ($thismachine{$server});
23896: if ($landing{$server}) {
23897: push(@cached,&escape('samllanding').':'.&escape($server));
23898: }
23899: if (@cached) {
23900: $cache_by_lonhost{$server} = \@cached;
23901: }
23902: }
23903: }
23904: }
23905: }
1.260 raeburn 23906: if (keys(%servers)) {
1.205 raeburn 23907: foreach my $server (keys(%servers)) {
23908: next if ($thismachine{$server});
1.212 raeburn 23909: my @cached;
23910: foreach my $name (@posscached) {
23911: if ($cachekeys->{$name}) {
1.388 raeburn 23912: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23913: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23914: foreach my $key (keys(%{$cachekeys->{$name}})) {
23915: push(@cached,&escape($name).':'.&escape($key));
23916: }
23917: }
23918: } else {
23919: push(@cached,&escape($name).':'.&escape($dom));
23920: }
1.212 raeburn 23921: }
23922: }
1.386 raeburn 23923: if ((exists($cache_by_lonhost{$server})) &&
23924: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23925: push(@cached,@{$cache_by_lonhost{$server}});
23926: }
1.212 raeburn 23927: if (@cached) {
23928: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23929: }
1.205 raeburn 23930: }
23931: }
23932: return;
23933: }
23934:
1.3 raeburn 23935: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>