Annotation of loncom/interface/domainprefs.pm, revision 1.392
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.392 ! raeburn 4: # $Id: domainprefs.pm,v 1.391 2021/11/22 23:40:59 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.372 raeburn 223: 'ltitools','ssl','trust','lti','privacy','passwords',
1.373 raeburn 224: 'proctoring','wafproxy'],$dom);
1.320 raeburn 225: my %encconfig =
1.384 raeburn 226: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$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.372 raeburn 251: if (ref($domconfig{'proctoring'}) eq 'HASH') {
252: if (ref($encconfig{'proctoring'}) eq 'HASH') {
253: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
254: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
255: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
256: foreach my $item ('key','secret') {
257: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
258: }
259: }
260: }
261: }
262: }
1.373 raeburn 263: my @prefs_order = ('rolecolors','login','defaults','wafproxy','passwords','quotas',
264: 'autoenroll','autoupdate','autocreate','directorysrch',
265: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 266: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 267: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 268: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
269: 'trust','lti');
1.171 raeburn 270: my %existing;
271: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
272: %existing = %{$domconfig{'loadbalancing'}};
273: }
274: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 275: push(@prefs_order,'loadbalancing');
276: }
1.30 raeburn 277: my %prefs = (
278: 'rolecolors' =>
279: { text => 'Default color schemes',
1.67 raeburn 280: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 281: header => [{col1 => 'Student Settings',
282: col2 => '',},
283: {col1 => 'Coordinator Settings',
284: col2 => '',},
285: {col1 => 'Author Settings',
286: col2 => '',},
287: {col1 => 'Administrator Settings',
288: col2 => '',}],
1.230 raeburn 289: print => \&print_rolecolors,
290: modify => \&modify_rolecolors,
1.30 raeburn 291: },
1.110 raeburn 292: 'login' =>
1.30 raeburn 293: { text => 'Log-in page options',
1.67 raeburn 294: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 295: header => [{col1 => 'Log-in Page Items',
296: col2 => '',},
297: {col1 => 'Log-in Help',
1.256 raeburn 298: col2 => 'Value'},
299: {col1 => 'Custom HTML in document head',
1.386 raeburn 300: col2 => 'Value'},
301: {col1 => 'SSO',
302: col2 => 'Dual login: SSO and non-SSO options'},
303: ],
1.230 raeburn 304: print => \&print_login,
305: modify => \&modify_login,
1.30 raeburn 306: },
1.43 raeburn 307: 'defaults' =>
1.236 raeburn 308: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 309: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 310: header => [{col1 => 'Setting',
1.236 raeburn 311: col2 => 'Value'},
312: {col1 => 'Institutional user types',
1.305 raeburn 313: col2 => 'Name displayed'}],
1.230 raeburn 314: print => \&print_defaults,
315: modify => \&modify_defaults,
1.43 raeburn 316: },
1.381 raeburn 317: 'wafproxy' =>
318: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 319: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 320: header => [{col1 => 'Domain(s)',
321: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 322: },
1.381 raeburn 323: {col1 => 'Domain(s)',
324: col2 => 'WAF Configuration',}],
1.373 raeburn 325: print => \&print_wafproxy,
1.381 raeburn 326: modify => \&modify_wafproxy,
1.373 raeburn 327: },
1.354 raeburn 328: 'passwords' =>
329: { text => 'Passwords (Internal authentication)',
330: help => 'Domain_Configuration_Passwords',
331: header => [{col1 => 'Resetting Forgotten Password',
332: col2 => 'Settings'},
333: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
334: col2 => 'Settings'},
335: {col1 => 'Rules for LON-CAPA Passwords',
336: col2 => 'Settings'},
337: {col1 => 'Course Owner Changing Student Passwords',
338: col2 => 'Settings'}],
339: print => \&print_passwords,
340: modify => \&modify_passwords,
341: },
1.30 raeburn 342: 'quotas' =>
1.197 raeburn 343: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 344: help => 'Domain_Configuration_Quotas',
1.77 raeburn 345: header => [{col1 => 'User affiliation',
1.72 raeburn 346: col2 => 'Available tools',
1.213 raeburn 347: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 348: print => \&print_quotas,
349: modify => \&modify_quotas,
1.30 raeburn 350: },
351: 'autoenroll' =>
352: { text => 'Auto-enrollment settings',
1.67 raeburn 353: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 354: header => [{col1 => 'Configuration setting',
355: col2 => 'Value(s)'}],
1.230 raeburn 356: print => \&print_autoenroll,
357: modify => \&modify_autoenroll,
1.30 raeburn 358: },
359: 'autoupdate' =>
360: { text => 'Auto-update settings',
1.67 raeburn 361: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 362: header => [{col1 => 'Setting',
363: col2 => 'Value',},
1.131 raeburn 364: {col1 => 'Setting',
365: col2 => 'Affiliation'},
1.43 raeburn 366: {col1 => 'User population',
1.227 bisitz 367: col2 => 'Updatable user data'}],
1.230 raeburn 368: print => \&print_autoupdate,
369: modify => \&modify_autoupdate,
1.30 raeburn 370: },
1.125 raeburn 371: 'autocreate' =>
372: { text => 'Auto-course creation settings',
373: help => 'Domain_Configuration_Auto_Creation',
374: header => [{col1 => 'Configuration Setting',
375: col2 => 'Value',}],
1.230 raeburn 376: print => \&print_autocreate,
377: modify => \&modify_autocreate,
1.125 raeburn 378: },
1.30 raeburn 379: 'directorysrch' =>
1.277 raeburn 380: { text => 'Directory searches',
1.67 raeburn 381: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 382: header => [{col1 => 'Institutional Directory Setting',
383: col2 => 'Value',},
384: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 385: col2 => 'Value',}],
1.230 raeburn 386: print => \&print_directorysrch,
387: modify => \&modify_directorysrch,
1.30 raeburn 388: },
389: 'contacts' =>
1.286 raeburn 390: { text => 'E-mail addresses and helpform',
1.67 raeburn 391: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 392: header => [{col1 => 'Default e-mail addresses',
393: col2 => 'Value',},
394: {col1 => 'Recipient(s) for notifications',
395: col2 => 'Value',},
1.340 raeburn 396: {col1 => 'Nightly status check e-mail',
397: col2 => 'Settings',},
1.286 raeburn 398: {col1 => 'Ask helpdesk form settings',
399: col2 => 'Value',},],
1.230 raeburn 400: print => \&print_contacts,
401: modify => \&modify_contacts,
1.30 raeburn 402: },
403: 'usercreation' =>
404: { text => 'User creation',
1.67 raeburn 405: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 406: header => [{col1 => 'Format rule type',
407: col2 => 'Format rules in force'},
1.34 raeburn 408: {col1 => 'User account creation',
409: col2 => 'Usernames which may be created',},
1.30 raeburn 410: {col1 => 'Context',
1.43 raeburn 411: col2 => 'Assignable authentication types'}],
1.230 raeburn 412: print => \&print_usercreation,
413: modify => \&modify_usercreation,
1.30 raeburn 414: },
1.224 raeburn 415: 'selfcreation' =>
416: { text => 'Users self-creating accounts',
417: help => 'Domain_Configuration_Self_Creation',
418: header => [{col1 => 'Self-creation with institutional username',
419: col2 => 'Enabled?'},
420: {col1 => 'Institutional user type (login/SSO self-creation)',
421: col2 => 'Information user can enter'},
1.303 raeburn 422: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 423: col2 => 'Settings'}],
1.230 raeburn 424: print => \&print_selfcreation,
425: modify => \&modify_selfcreation,
1.224 raeburn 426: },
1.69 raeburn 427: 'usermodification' =>
1.33 raeburn 428: { text => 'User modification',
1.67 raeburn 429: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 430: header => [{col1 => 'Target user has role',
1.227 bisitz 431: col2 => 'User information updatable in author context'},
1.33 raeburn 432: {col1 => 'Target user has role',
1.227 bisitz 433: col2 => 'User information updatable in course context'}],
1.230 raeburn 434: print => \&print_usermodification,
435: modify => \&modify_usermodification,
1.33 raeburn 436: },
1.69 raeburn 437: 'scantron' =>
1.346 raeburn 438: { text => 'Bubblesheet format',
1.67 raeburn 439: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 440: header => [ {col1 => 'Bubblesheet format file',
441: col2 => ''},
442: {col1 => 'Bubblesheet data upload formats',
443: col2 => 'Settings'}],
1.230 raeburn 444: print => \&print_scantron,
445: modify => \&modify_scantron,
1.46 raeburn 446: },
1.86 raeburn 447: 'requestcourses' =>
448: {text => 'Request creation of courses',
449: help => 'Domain_Configuration_Request_Courses',
450: header => [{col1 => 'User affiliation',
1.102 raeburn 451: col2 => 'Availability/Processing of requests',},
452: {col1 => 'Setting',
1.216 raeburn 453: col2 => 'Value'},
454: {col1 => 'Available textbooks',
1.235 raeburn 455: col2 => ''},
1.242 raeburn 456: {col1 => 'Available templates',
457: col2 => ''},
1.235 raeburn 458: {col1 => 'Validation (not official courses)',
459: col2 => 'Value'},],
1.230 raeburn 460: print => \&print_quotas,
461: modify => \&modify_quotas,
1.86 raeburn 462: },
1.163 raeburn 463: 'requestauthor' =>
1.223 bisitz 464: {text => 'Request Authoring Space',
1.163 raeburn 465: help => 'Domain_Configuration_Request_Author',
466: header => [{col1 => 'User affiliation',
467: col2 => 'Availability/Processing of requests',},
468: {col1 => 'Setting',
469: col2 => 'Value'}],
1.230 raeburn 470: print => \&print_quotas,
471: modify => \&modify_quotas,
1.163 raeburn 472: },
1.69 raeburn 473: 'coursecategories' =>
1.120 raeburn 474: { text => 'Cataloging of courses/communities',
1.67 raeburn 475: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 476: header => [{col1 => 'Catalog type/availability',
477: col2 => '',},
478: {col1 => 'Category settings for standard catalog',
1.57 raeburn 479: col2 => '',},
480: {col1 => 'Categories',
481: col2 => '',
482: }],
1.230 raeburn 483: print => \&print_coursecategories,
484: modify => \&modify_coursecategories,
1.69 raeburn 485: },
486: 'serverstatuses' =>
1.77 raeburn 487: {text => 'Access to server status pages',
1.69 raeburn 488: help => 'Domain_Configuration_Server_Status',
489: header => [{col1 => 'Status Page',
490: col2 => 'Other named users',
491: col3 => 'Specific IPs',
492: }],
1.230 raeburn 493: print => \&print_serverstatuses,
494: modify => \&modify_serverstatuses,
1.69 raeburn 495: },
1.118 jms 496: 'helpsettings' =>
1.282 raeburn 497: {text => 'Support settings',
1.118 jms 498: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 499: header => [{col1 => 'Help Page Settings (logged-in users)',
500: col2 => 'Value'},
501: {col1 => 'Helpdesk Roles',
502: col2 => 'Settings'},],
1.230 raeburn 503: print => \&print_helpsettings,
504: modify => \&modify_helpsettings,
1.118 jms 505: },
1.121 raeburn 506: 'coursedefaults' =>
507: {text => 'Course/Community defaults',
508: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 509: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
510: col2 => 'Value',},
511: {col1 => 'Defaults which can be overridden for each course by a DC',
512: col2 => 'Value',},],
1.230 raeburn 513: print => \&print_coursedefaults,
514: modify => \&modify_coursedefaults,
1.121 raeburn 515: },
1.231 raeburn 516: 'selfenrollment' =>
517: {text => 'Self-enrollment in Course/Community',
518: help => 'Domain_Configuration_Selfenrollment',
519: header => [{col1 => 'Configuration Rights',
520: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
521: {col1 => 'Defaults',
522: col2 => 'Value'},
523: {col1 => 'Self-enrollment validation (optional)',
524: col2 => 'Value'},],
525: print => \&print_selfenrollment,
526: modify => \&modify_selfenrollment,
527: },
1.120 raeburn 528: 'privacy' =>
1.357 raeburn 529: {text => 'Availability of User Information',
1.120 raeburn 530: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 531: header => [{col1 => 'Role assigned in different domain',
532: col2 => 'Approval options'},
533: {col1 => 'Role assigned in different domain to user of type',
534: col2 => 'User information available in that domain'},
535: {col1 => "Role assigned in user's domain",
536: col2 => 'Information viewable by privileged user'},
537: {col1 => "Role assigned in user's domain",
538: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 539: print => \&print_privacy,
540: modify => \&modify_privacy,
1.120 raeburn 541: },
1.141 raeburn 542: 'usersessions' =>
1.145 raeburn 543: {text => 'User session hosting/offloading',
1.137 raeburn 544: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 545: header => [{col1 => 'Domain server',
546: col2 => 'Servers to offload sessions to when busy'},
547: {col1 => 'Hosting of users from other domains',
1.137 raeburn 548: col2 => 'Rules'},
549: {col1 => "Hosting domain's own users elsewhere",
550: col2 => 'Rules'}],
1.230 raeburn 551: print => \&print_usersessions,
552: modify => \&modify_usersessions,
1.137 raeburn 553: },
1.279 raeburn 554: 'loadbalancing' =>
1.185 raeburn 555: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 556: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 557: header => [{col1 => 'Balancers',
1.150 raeburn 558: col2 => 'Default destinations',
1.183 bisitz 559: col3 => 'User affiliation',
1.150 raeburn 560: col4 => 'Overrides'},
561: ],
1.230 raeburn 562: print => \&print_loadbalancing,
563: modify => \&modify_loadbalancing,
1.150 raeburn 564: },
1.279 raeburn 565: 'ltitools' =>
1.267 raeburn 566: {text => 'External Tools (LTI)',
1.296 raeburn 567: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 568: header => [{col1 => 'Setting',
569: col2 => 'Value',}],
570: print => \&print_ltitools,
571: modify => \&modify_ltitools,
572: },
1.372 raeburn 573: 'proctoring' =>
574: {text => 'Remote Proctoring Integration',
575: help => 'Domain_Configuration_Proctoring',
576: header => [{col1 => 'Name',
577: col2 => 'Configuration'}],
578: print => \&print_proctoring,
579: modify => \&modify_proctoring,
580: },
1.279 raeburn 581: 'ssl' =>
1.275 raeburn 582: {text => 'LON-CAPA Network (SSL)',
583: help => 'Domain_Configuration_Network_SSL',
584: header => [{col1 => 'Server',
585: col2 => 'Certificate Status'},
586: {col1 => 'Connections to other servers',
587: col2 => 'Rules'},
1.293 raeburn 588: {col1 => 'Connections from other servers',
589: col2 => 'Rules'},
1.275 raeburn 590: {col1 => "Replicating domain's published content",
591: col2 => 'Rules'}],
592: print => \&print_ssl,
593: modify => \&modify_ssl,
594: },
1.279 raeburn 595: 'trust' =>
596: {text => 'Trust Settings',
597: help => 'Domain_Configuration_Trust',
598: header => [{col1 => "Access to this domain's content by others",
599: col2 => 'Rules'},
600: {col1 => "Access to other domain's content by this domain",
601: col2 => 'Rules'},
602: {col1 => "Enrollment in this domain's courses by others",
603: col2 => 'Rules',},
604: {col1 => "Co-author roles in this domain for others",
605: col2 => 'Rules',},
606: {col1 => "Co-author roles for this domain's users elsewhere",
607: col2 => 'Rules',},
608: {col1 => "Domain roles in this domain assignable to others",
609: col2 => 'Rules'},
610: {col1 => "Course catalog for this domain displayed elsewhere",
611: col2 => 'Rules'},
612: {col1 => "Requests for creation of courses in this domain by others",
613: col2 => 'Rules'},
614: {col1 => "Users in other domains can send messages to this domain",
615: col2 => 'Rules'},],
616: print => \&print_trust,
617: modify => \&modify_trust,
618: },
1.320 raeburn 619: 'lti' =>
620: {text => 'LTI Provider',
621: help => 'Domain_Configuration_LTI_Provider',
622: header => [{col1 => 'Setting',
623: col2 => 'Value',}],
624: print => \&print_lti,
625: modify => \&modify_lti,
626: },
1.3 raeburn 627: );
1.110 raeburn 628: if (keys(%servers) > 1) {
629: $prefs{'login'} = { text => 'Log-in page options',
630: help => 'Domain_Configuration_Login_Page',
631: header => [{col1 => 'Log-in Service',
632: col2 => 'Server Setting',},
633: {col1 => 'Log-in Page Items',
1.168 raeburn 634: col2 => ''},
635: {col1 => 'Log-in Help',
1.256 raeburn 636: col2 => 'Value'},
637: {col1 => 'Custom HTML in document head',
1.386 raeburn 638: col2 => 'Value'},
639: {col1 => 'SSO',
640: col2 => 'Dual login: SSO and non-SSO options'},
641: ],
1.230 raeburn 642: print => \&print_login,
643: modify => \&modify_login,
1.110 raeburn 644: };
645: }
1.174 foxr 646:
1.6 raeburn 647: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 648: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 649: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 650: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 651: text=>"Settings to display/modify"});
1.9 raeburn 652: my $confname = $dom.'-domainconfig';
1.174 foxr 653:
1.3 raeburn 654: if ($phase eq 'process') {
1.212 raeburn 655: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
656: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 657: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 658: $r->rflush();
1.212 raeburn 659: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 660: }
1.30 raeburn 661: } elsif ($phase eq 'display') {
1.192 raeburn 662: my $js = &recaptcha_js().
1.236 raeburn 663: &toggle_display_js();
1.171 raeburn 664: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 665: my ($othertitle,$usertypes,$types) =
666: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 667: $js .= &lonbalance_targets_js($dom,$types,\%servers,
668: $domconfig{'loadbalancing'}).
1.170 raeburn 669: &new_spares_js().
670: &common_domprefs_js().
671: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 672: }
1.216 raeburn 673: if (grep(/^requestcourses$/,@actions)) {
674: my $javascript_validations;
675: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
676: $js .= <<END;
677: <script type="text/javascript">
678: $javascript_validations
679: </script>
680: $coursebrowserjs
681: END
682: }
1.305 raeburn 683: if (grep(/^selfcreation$/,@actions)) {
684: $js .= &selfcreate_javascript();
685: }
1.286 raeburn 686: if (grep(/^contacts$/,@actions)) {
687: $js .= &contacts_javascript();
688: }
1.346 raeburn 689: if (grep(/^scantron$/,@actions)) {
690: $js .= &scantron_javascript();
691: }
1.150 raeburn 692: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 693: } else {
1.180 raeburn 694: # check if domconfig user exists for the domain.
695: my $servadm = $r->dir_config('lonAdmEMail');
696: my ($configuserok,$author_ok,$switchserver) =
697: &config_check($dom,$confname,$servadm);
698: unless ($configuserok eq 'ok') {
1.181 raeburn 699: &Apache::lonconfigsettings::print_header($r,$phase,$context);
700: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 701: $confname).
1.181 raeburn 702: '<br />'
703: );
1.180 raeburn 704: if ($switchserver) {
1.181 raeburn 705: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
706: '<br />'.
707: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
708: '<br />'.
709: &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).
710: '<br />'.
711: &mt('To do that now, use the following link: [_1]',$switchserver)
712: );
713: } else {
714: $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.').
715: '<br />'.
716: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
717: );
1.180 raeburn 718: }
719: $r->print(&Apache::loncommon::end_page());
720: return OK;
721: }
1.21 raeburn 722: if (keys(%domconfig) == 0) {
723: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 724: my @ids=&Apache::lonnet::current_machine_ids();
725: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 726: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 727: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 728: my $custom_img_count = 0;
729: foreach my $img (@loginimages) {
730: if ($designhash{$dom.'.login.'.$img} ne '') {
731: $custom_img_count ++;
732: }
733: }
734: foreach my $role (@roles) {
735: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
736: $custom_img_count ++;
737: }
738: }
739: if ($custom_img_count > 0) {
1.94 raeburn 740: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 741: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 742: $r->print(
743: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
744: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
745: &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 />'.
746: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
747: if ($switch_server) {
1.30 raeburn 748: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 749: }
1.91 raeburn 750: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 751: return OK;
752: }
753: }
754: }
1.91 raeburn 755: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 756: }
757: return OK;
758: }
759:
760: sub process_changes {
1.205 raeburn 761: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 762: my %domconfig;
763: if (ref($values) eq 'HASH') {
764: %domconfig = %{$values};
765: }
1.3 raeburn 766: my $output;
767: if ($action eq 'login') {
1.205 raeburn 768: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 769: } elsif ($action eq 'rolecolors') {
1.9 raeburn 770: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 771: $lastactref,%domconfig);
1.3 raeburn 772: } elsif ($action eq 'quotas') {
1.216 raeburn 773: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 774: } elsif ($action eq 'autoenroll') {
1.205 raeburn 775: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 776: } elsif ($action eq 'autoupdate') {
777: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 778: } elsif ($action eq 'autocreate') {
779: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 780: } elsif ($action eq 'directorysrch') {
1.295 raeburn 781: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 782: } elsif ($action eq 'usercreation') {
1.28 raeburn 783: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 784: } elsif ($action eq 'selfcreation') {
1.305 raeburn 785: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 786: } elsif ($action eq 'usermodification') {
787: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 788: } elsif ($action eq 'contacts') {
1.205 raeburn 789: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 790: } elsif ($action eq 'defaults') {
1.212 raeburn 791: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 792: } elsif ($action eq 'scantron') {
1.205 raeburn 793: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 794: } elsif ($action eq 'coursecategories') {
1.239 raeburn 795: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 796: } elsif ($action eq 'serverstatuses') {
797: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 798: } elsif ($action eq 'requestcourses') {
1.216 raeburn 799: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 800: } elsif ($action eq 'requestauthor') {
1.216 raeburn 801: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 802: } elsif ($action eq 'helpsettings') {
1.285 raeburn 803: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 804: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 805: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 806: } elsif ($action eq 'selfenrollment') {
807: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 808: } elsif ($action eq 'usersessions') {
1.212 raeburn 809: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 810: } elsif ($action eq 'loadbalancing') {
811: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 812: } elsif ($action eq 'ltitools') {
813: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 814: } elsif ($action eq 'proctoring') {
815: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 816: } elsif ($action eq 'ssl') {
817: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 818: } elsif ($action eq 'trust') {
819: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 820: } elsif ($action eq 'lti') {
821: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 822: } elsif ($action eq 'privacy') {
823: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 824: } elsif ($action eq 'passwords') {
825: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 826: } elsif ($action eq 'wafproxy') {
827: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.3 raeburn 828: }
829: return $output;
830: }
831:
832: sub print_config_box {
1.9 raeburn 833: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 834: my $rowtotal = 0;
1.49 raeburn 835: my $output;
836: if ($action eq 'coursecategories') {
837: $output = &coursecategories_javascript($settings);
1.236 raeburn 838: } elsif ($action eq 'defaults') {
839: $output = &defaults_javascript($settings);
1.354 raeburn 840: } elsif ($action eq 'passwords') {
841: $output = &passwords_javascript();
1.282 raeburn 842: } elsif ($action eq 'helpsettings') {
843: my (%privs,%levelscurrent);
844: my %full=();
845: my %levels=(
846: course => {},
847: domain => {},
848: system => {},
849: );
850: my $context = 'domain';
851: my $crstype = 'Course';
852: my $formname = 'display';
853: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
854: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
855: $output =
856: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
857: \@templateroles);
1.334 raeburn 858: } elsif ($action eq 'ltitools') {
859: $output .= <itools_javascript($settings);
860: } elsif ($action eq 'lti') {
861: $output .= <i_javascript($settings);
1.372 raeburn 862: } elsif ($action eq 'proctoring') {
863: $output .= &proctoring_javascript($settings);
1.381 raeburn 864: } elsif ($action eq 'wafproxy') {
865: $output .= &wafproxy_javascript($dom);
1.385 raeburn 866: } elsif ($action eq 'autoupdate') {
867: $output .= &autoupdate_javascript();
1.386 raeburn 868: } elsif ($action eq 'login') {
869: $output .= &saml_javascript();
1.91 raeburn 870: }
1.236 raeburn 871: $output .=
1.30 raeburn 872: '<table class="LC_nested_outer">
1.3 raeburn 873: <tr>
1.306 raeburn 874: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 875: &mt($item->{text}).' '.
876: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
877: '</tr>';
1.30 raeburn 878: $rowtotal ++;
1.110 raeburn 879: my $numheaders = 1;
880: if (ref($item->{'header'}) eq 'ARRAY') {
881: $numheaders = scalar(@{$item->{'header'}});
882: }
883: if ($numheaders > 1) {
1.64 raeburn 884: my $colspan = '';
1.145 raeburn 885: my $rightcolspan = '';
1.369 raeburn 886: my $leftnobr = '';
1.238 raeburn 887: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 888: ($action eq 'directorysrch') ||
1.386 raeburn 889: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 890: $colspan = ' colspan="2"';
891: }
1.145 raeburn 892: if ($action eq 'usersessions') {
893: $rightcolspan = ' colspan="3"';
894: }
1.369 raeburn 895: if ($action eq 'passwords') {
896: $leftnobr = ' LC_nobreak';
897: }
1.30 raeburn 898: $output .= '
1.3 raeburn 899: <tr>
900: <td>
901: <table class="LC_nested">
902: <tr class="LC_info_row">
1.369 raeburn 903: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 904: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 905: </tr>';
1.69 raeburn 906: $rowtotal ++;
1.230 raeburn 907: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 908: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 909: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 910: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 raeburn 911: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 912: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 913: } elsif ($action eq 'passwords') {
914: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 915: } elsif ($action eq 'coursecategories') {
1.230 raeburn 916: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 917: } elsif ($action eq 'scantron') {
918: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 919: } elsif ($action eq 'login') {
1.386 raeburn 920: if ($numheaders == 5) {
1.168 raeburn 921: $colspan = ' colspan="2"';
922: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
923: } else {
924: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
925: }
1.230 raeburn 926: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 927: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 928: } elsif ($action eq 'rolecolors') {
1.30 raeburn 929: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 930: }
1.30 raeburn 931: $output .= '
1.6 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>
936: <td>
937: <table class="LC_nested">
938: <tr class="LC_info_row">
1.230 raeburn 939: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 940: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 941: </tr>';
942: $rowtotal ++;
1.230 raeburn 943: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
944: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 945: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 946: ($action eq 'trust') || ($action eq 'contacts') ||
947: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 948: if ($action eq 'coursecategories') {
949: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
950: $colspan = ' colspan="2"';
1.279 raeburn 951: } elsif ($action eq 'trust') {
952: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 953: } elsif ($action eq 'passwords') {
954: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 955: } else {
956: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
957: }
1.279 raeburn 958: if ($action eq 'trust') {
959: $output .= '
960: </table>
961: </td>
962: </tr>';
963: my @trusthdrs = qw(2 3 4 5 6 7);
964: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
965: for (my $i=0; $i<@trusthdrs; $i++) {
966: $output .= '
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
972: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
973: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
974: </table>
975: </td>
976: </tr>';
977: }
978: $output .= '
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
984: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
985: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
986: } else {
987: $output .= '
1.63 raeburn 988: </table>
989: </td>
990: </tr>
991: <tr>
992: <td>
993: <table class="LC_nested">
994: <tr class="LC_info_row">
995: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 996: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 997: </tr>'."\n";
1.279 raeburn 998: if ($action eq 'coursecategories') {
999: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 1000: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 1001: if ($action eq 'passwords') {
1002: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1003: } else {
1004: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1005: }
1006: $output .= '
1.340 raeburn 1007: </tr>
1008: </table>
1009: </td>
1010: </tr>
1011: <tr>
1012: <td>
1013: <table class="LC_nested">
1014: <tr class="LC_info_row">
1.369 raeburn 1015: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1016: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1017: if ($action eq 'passwords') {
1018: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1019: } else {
1020: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1021: }
1022: $output .= '
1.340 raeburn 1023: </table>
1024: </td>
1025: </tr>
1026: <tr>';
1.279 raeburn 1027: } else {
1028: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1029: }
1.238 raeburn 1030: }
1.63 raeburn 1031: $rowtotal ++;
1.236 raeburn 1032: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1033: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 raeburn 1034: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1035: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1036: } elsif ($action eq 'scantron') {
1037: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1038: } elsif ($action eq 'ssl') {
1039: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1040: </table>
1041: </td>
1042: </tr>
1043: <tr>
1044: <td>
1045: <table class="LC_nested">
1046: <tr class="LC_info_row">
1047: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1048: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1049: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1050: </table>
1051: </td>
1052: </tr>
1053: <tr>
1054: <td>
1055: <table class="LC_nested">
1056: <tr class="LC_info_row">
1057: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1058: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1059: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1060: } elsif ($action eq 'login') {
1.386 raeburn 1061: if ($numheaders == 5) {
1.168 raeburn 1062: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1063: </table>
1064: </td>
1065: </tr>
1066: <tr>
1067: <td>
1068: <table class="LC_nested">
1069: <tr class="LC_info_row">
1070: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1071: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1072: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1073: $rowtotal ++;
1074: } else {
1075: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1076: }
1.256 raeburn 1077: $output .= '
1078: </table>
1079: </td>
1080: </tr>
1081: <tr>
1082: <td>
1083: <table class="LC_nested">
1084: <tr class="LC_info_row">';
1.386 raeburn 1085: if ($numheaders == 5) {
1.256 raeburn 1086: $output .= '
1087: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1088: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1089: </tr>';
1090: } else {
1091: $output .= '
1092: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1093: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1094: </tr>';
1095: }
1096: $rowtotal ++;
1.386 raeburn 1097: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1098: </table>
1099: </td>
1100: </tr>
1101: <tr>
1102: <td>
1103: <table class="LC_nested">
1104: <tr class="LC_info_row">';
1105: if ($numheaders == 5) {
1106: $output .= '
1107: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1108: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1109: </tr>';
1110: } else {
1111: $output .= '
1112: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1113: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1114: </tr>';
1115: }
1116: $rowtotal ++;
1117: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1118: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1119: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1120: $rowtotal ++;
1121: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1122: </table>
1123: </td>
1124: </tr>
1125: <tr>
1126: <td>
1127: <table class="LC_nested">
1128: <tr class="LC_info_row">
1129: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1130: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1131: &textbookcourses_javascript($settings).
1132: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1133: </table>
1134: </td>
1135: </tr>
1136: <tr>
1137: <td>
1138: <table class="LC_nested">
1139: <tr class="LC_info_row">
1140: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1141: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1142: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1143: </table>
1144: </td>
1145: </tr>
1146: <tr>
1147: <td>
1148: <table class="LC_nested">
1149: <tr class="LC_info_row">
1.306 raeburn 1150: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1151: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1152: </tr>'.
1153: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1154: } elsif ($action eq 'requestauthor') {
1155: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1156: $rowtotal ++;
1.122 jms 1157: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1158: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1159: </table>
1160: </td>
1161: </tr>
1162: <tr>
1163: <td>
1164: <table class="LC_nested">
1165: <tr class="LC_info_row">
1.306 raeburn 1166: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1167: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1168: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1169: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1170: </tr>'.
1.30 raeburn 1171: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1172: </table>
1173: </td>
1174: </tr>
1175: <tr>
1176: <td>
1177: <table class="LC_nested">
1178: <tr class="LC_info_row">
1.59 bisitz 1179: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1180: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1181: </tr>'.
1.30 raeburn 1182: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1183: $rowtotal += 2;
1.6 raeburn 1184: }
1.3 raeburn 1185: } else {
1.30 raeburn 1186: $output .= '
1.3 raeburn 1187: <tr>
1188: <td>
1189: <table class="LC_nested">
1.30 raeburn 1190: <tr class="LC_info_row">';
1.277 raeburn 1191: if ($action eq 'login') {
1.30 raeburn 1192: $output .= '
1.59 bisitz 1193: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1194: } elsif ($action eq 'serverstatuses') {
1195: $output .= '
1.306 raeburn 1196: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1197: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1198:
1.6 raeburn 1199: } else {
1.30 raeburn 1200: $output .= '
1.306 raeburn 1201: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1202: }
1.72 raeburn 1203: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1204: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1205: &mt($item->{'header'}->[0]->{'col2'});
1206: if ($action eq 'serverstatuses') {
1207: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1208: }
1.69 raeburn 1209: } else {
1.306 raeburn 1210: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1211: &mt($item->{'header'}->[0]->{'col2'});
1212: }
1213: $output .= '</td>';
1214: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1215: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1216: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1217: &mt($item->{'header'}->[0]->{'col3'});
1218: } else {
1.306 raeburn 1219: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1220: &mt($item->{'header'}->[0]->{'col3'});
1221: }
1.69 raeburn 1222: if ($action eq 'serverstatuses') {
1223: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1224: }
1225: $output .= '</td>';
1.6 raeburn 1226: }
1.150 raeburn 1227: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1228: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1229: &mt($item->{'header'}->[0]->{'col4'});
1230: }
1.69 raeburn 1231: $output .= '</tr>';
1.48 raeburn 1232: $rowtotal ++;
1.168 raeburn 1233: if ($action eq 'quotas') {
1.86 raeburn 1234: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1235: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1236: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1237: ($action eq 'ltitools') || ($action eq 'lti') ||
1238: ($action eq 'proctoring')) {
1.230 raeburn 1239: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1240: }
1.3 raeburn 1241: }
1.30 raeburn 1242: $output .= '
1.3 raeburn 1243: </table>
1244: </td>
1245: </tr>
1.30 raeburn 1246: </table><br />';
1247: return ($output,$rowtotal);
1.1 raeburn 1248: }
1249:
1.3 raeburn 1250: sub print_login {
1.168 raeburn 1251: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1252: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1253: my %choices = &login_choices();
1.386 raeburn 1254: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1255: %lt = &login_file_options();
1256: $switchserver = &check_switchserver($dom,$confname);
1257: }
1.168 raeburn 1258: if ($caller eq 'service') {
1.149 raeburn 1259: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1260: my $choice = $choices{'disallowlogin'};
1261: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1262: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1263: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1264: '<th>'.$choices{'server'}.'</th>'.
1265: '<th>'.$choices{'serverpath'}.'</th>'.
1266: '<th>'.$choices{'custompath'}.'</th>'.
1267: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1268: my %disallowed;
1269: if (ref($settings) eq 'HASH') {
1270: if (ref($settings->{'loginvia'}) eq 'HASH') {
1271: %disallowed = %{$settings->{'loginvia'}};
1272: }
1273: }
1274: foreach my $lonhost (sort(keys(%servers))) {
1275: my $direct = 'selected="selected"';
1.128 raeburn 1276: if (ref($disallowed{$lonhost}) eq 'HASH') {
1277: if ($disallowed{$lonhost}{'server'} ne '') {
1278: $direct = '';
1279: }
1.110 raeburn 1280: }
1.115 raeburn 1281: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1282: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1283: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1284: '</option>';
1.184 raeburn 1285: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1286: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1287: my $selected = '';
1.128 raeburn 1288: if (ref($disallowed{$lonhost}) eq 'HASH') {
1289: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1290: $selected = 'selected="selected"';
1291: }
1.110 raeburn 1292: }
1293: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1294: $servers{$hostid}.'</option>';
1295: }
1.128 raeburn 1296: $datatable .= '</select></td>'.
1297: '<td><select name="'.$lonhost.'_serverpath">';
1298: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1299: my $pathname = $path;
1300: if ($path eq 'custom') {
1301: $pathname = &mt('Custom Path').' ->';
1302: }
1303: my $selected = '';
1304: if (ref($disallowed{$lonhost}) eq 'HASH') {
1305: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1306: $selected = 'selected="selected"';
1307: }
1308: } elsif ($path eq '') {
1309: $selected = 'selected="selected"';
1310: }
1311: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1312: }
1313: $datatable .= '</select></td>';
1314: my ($custom,$exempt);
1315: if (ref($disallowed{$lonhost}) eq 'HASH') {
1316: $custom = $disallowed{$lonhost}{'custompath'};
1317: $exempt = $disallowed{$lonhost}{'exempt'};
1318: }
1319: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1320: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1321: '</tr>';
1.110 raeburn 1322: }
1323: $datatable .= '</table></td></tr>';
1324: return $datatable;
1.168 raeburn 1325: } elsif ($caller eq 'page') {
1326: my %defaultchecked = (
1327: 'coursecatalog' => 'on',
1.188 raeburn 1328: 'helpdesk' => 'on',
1.168 raeburn 1329: 'adminmail' => 'off',
1330: 'newuser' => 'off',
1331: );
1.188 raeburn 1332: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1333: my (%checkedon,%checkedoff);
1.42 raeburn 1334: foreach my $item (@toggles) {
1.168 raeburn 1335: if ($defaultchecked{$item} eq 'on') {
1336: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1337: $checkedoff{$item} = ' ';
1.168 raeburn 1338: } elsif ($defaultchecked{$item} eq 'off') {
1339: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1340: $checkedon{$item} = ' ';
1341: }
1.1 raeburn 1342: }
1.168 raeburn 1343: my @images = ('img','logo','domlogo','login');
1344: my @logintext = ('textcol','bgcol');
1345: my @bgs = ('pgbg','mainbg','sidebg');
1346: my @links = ('link','alink','vlink');
1347: my %designhash = &Apache::loncommon::get_domainconf($dom);
1348: my %defaultdesign = %Apache::loncommon::defaultdesign;
1349: my (%is_custom,%designs);
1350: my %defaults = (
1351: font => $defaultdesign{'login.font'},
1352: );
1.6 raeburn 1353: foreach my $item (@images) {
1.168 raeburn 1354: $defaults{$item} = $defaultdesign{'login.'.$item};
1355: $defaults{'showlogo'}{$item} = 1;
1356: }
1357: foreach my $item (@bgs) {
1358: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1359: }
1.41 raeburn 1360: foreach my $item (@logintext) {
1.168 raeburn 1361: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1362: }
1.168 raeburn 1363: foreach my $item (@links) {
1364: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1365: }
1.168 raeburn 1366: if (ref($settings) eq 'HASH') {
1367: foreach my $item (@toggles) {
1368: if ($settings->{$item} eq '1') {
1369: $checkedon{$item} = ' checked="checked" ';
1370: $checkedoff{$item} = ' ';
1371: } elsif ($settings->{$item} eq '0') {
1372: $checkedoff{$item} = ' checked="checked" ';
1373: $checkedon{$item} = ' ';
1374: }
1375: }
1376: foreach my $item (@images) {
1377: if (defined($settings->{$item})) {
1378: $designs{$item} = $settings->{$item};
1379: $is_custom{$item} = 1;
1380: }
1381: if (defined($settings->{'showlogo'}{$item})) {
1382: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1383: }
1384: }
1385: foreach my $item (@logintext) {
1386: if ($settings->{$item} ne '') {
1387: $designs{'logintext'}{$item} = $settings->{$item};
1388: $is_custom{$item} = 1;
1389: }
1390: }
1391: if ($settings->{'font'} ne '') {
1392: $designs{'font'} = $settings->{'font'};
1393: $is_custom{'font'} = 1;
1394: }
1395: foreach my $item (@bgs) {
1396: if ($settings->{$item} ne '') {
1397: $designs{'bgs'}{$item} = $settings->{$item};
1398: $is_custom{$item} = 1;
1399: }
1400: }
1401: foreach my $item (@links) {
1402: if ($settings->{$item} ne '') {
1403: $designs{'links'}{$item} = $settings->{$item};
1404: $is_custom{$item} = 1;
1405: }
1406: }
1407: } else {
1408: if ($designhash{$dom.'.login.font'} ne '') {
1409: $designs{'font'} = $designhash{$dom.'.login.font'};
1410: $is_custom{'font'} = 1;
1411: }
1412: foreach my $item (@images) {
1413: if ($designhash{$dom.'.login.'.$item} ne '') {
1414: $designs{$item} = $designhash{$dom.'.login.'.$item};
1415: $is_custom{$item} = 1;
1416: }
1417: }
1418: foreach my $item (@bgs) {
1419: if ($designhash{$dom.'.login.'.$item} ne '') {
1420: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1421: $is_custom{$item} = 1;
1422: }
1.6 raeburn 1423: }
1.168 raeburn 1424: foreach my $item (@links) {
1425: if ($designhash{$dom.'.login.'.$item} ne '') {
1426: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1427: $is_custom{$item} = 1;
1428: }
1.6 raeburn 1429: }
1430: }
1.168 raeburn 1431: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1432: logo => 'Institution Logo',
1433: domlogo => 'Domain Logo',
1434: login => 'Login box');
1435: my $itemcount = 1;
1436: foreach my $item (@toggles) {
1437: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1438: $datatable .=
1439: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1440: '</td><td>'.
1441: '<span class="LC_nobreak"><label><input type="radio" name="'.
1442: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1443: '</label> <label><input type="radio" name="'.$item.'"'.
1444: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1445: '</tr>';
1446: $itemcount ++;
1.6 raeburn 1447: }
1.168 raeburn 1448: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1449: $datatable .= '</tr></table></td></tr>';
1450: } elsif ($caller eq 'help') {
1.386 raeburn 1451: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1452: my $itemcount = 1;
1453: $defaulturl = '/adm/loginproblems.html';
1454: $defaulttype = 'default';
1455: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1456: my @currlangs;
1457: if (ref($settings) eq 'HASH') {
1458: if (ref($settings->{'helpurl'}) eq 'HASH') {
1459: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1460: next if ($settings->{'helpurl'}{$key} eq '');
1461: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1462: $type{$key} = 'custom';
1463: unless ($key eq 'nolang') {
1464: push(@currlangs,$key);
1465: }
1466: }
1467: } elsif ($settings->{'helpurl'} ne '') {
1468: $type{'nolang'} = 'custom';
1469: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1470: }
1471: }
1.168 raeburn 1472: foreach my $lang ('nolang',sort(@currlangs)) {
1473: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1474: $datatable .= '<tr'.$css_class.'>';
1475: if ($url{$lang} eq '') {
1476: $url{$lang} = $defaulturl;
1477: }
1478: if ($type{$lang} eq '') {
1479: $type{$lang} = $defaulttype;
1480: }
1481: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1482: if ($lang eq 'nolang') {
1483: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1484: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1485: } else {
1486: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1487: $langchoices{$lang},
1488: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1489: }
1490: $datatable .= '</span></td>'."\n".
1491: '<td class="LC_left_item">';
1492: if ($type{$lang} eq 'custom') {
1493: $datatable .= '<span class="LC_nobreak"><label>'.
1494: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1495: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1496: } else {
1497: $datatable .= $lt{'upl'};
1498: }
1499: $datatable .='<br />';
1500: if ($switchserver) {
1501: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1502: } else {
1503: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1504: }
1.168 raeburn 1505: $datatable .= '</td></tr>';
1506: $itemcount ++;
1.6 raeburn 1507: }
1.168 raeburn 1508: my @addlangs;
1509: foreach my $lang (sort(keys(%langchoices))) {
1510: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1511: push(@addlangs,$lang);
1512: }
1513: if (@addlangs > 0) {
1514: my %toadd;
1515: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1516: $toadd{''} = &mt('Select');
1517: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1518: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1519: &mt('Add log-in help page for a specific language:').' '.
1520: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1521: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1522: if ($switchserver) {
1523: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1524: } else {
1525: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1526: }
1.168 raeburn 1527: $datatable .= '</td></tr>';
1.169 raeburn 1528: $itemcount ++;
1.6 raeburn 1529: }
1.169 raeburn 1530: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1531: } elsif ($caller eq 'headtag') {
1532: my %domservers = &Apache::lonnet::get_servers($dom);
1533: my $choice = $choices{'headtag'};
1534: $css_class = ' class="LC_odd_row"';
1535: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1536: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1537: '<th>'.$choices{'current'}.'</th>'.
1538: '<th>'.$choices{'action'}.'</th>'.
1539: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1540: my (%currurls,%currexempt);
1541: if (ref($settings) eq 'HASH') {
1542: if (ref($settings->{'headtag'}) eq 'HASH') {
1543: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1544: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1545: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1546: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1547: }
1548: }
1549: }
1550: }
1551: foreach my $lonhost (sort(keys(%domservers))) {
1552: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1553: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1554: if ($currurls{$lonhost}) {
1555: $datatable .= '<td class="LC_right_item"><a href="'.
1556: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1557: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1558: '">'.$lt{'curr'}.'</a></td>'.
1559: '<td><span class="LC_nobreak"><label>'.
1560: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1561: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1562: } else {
1563: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1564: }
1565: $datatable .='<br />';
1566: if ($switchserver) {
1567: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1568: } else {
1569: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1570: }
1.330 raeburn 1571: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1572: }
1573: $datatable .= '</table></td></tr>';
1.386 raeburn 1574: } elsif ($caller eq 'saml') {
1575: my %domservers = &Apache::lonnet::get_servers($dom);
1576: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1577: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1578: '<th>'.$choices{'samllanding'}.'</th>'.
1579: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1580: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1581: foreach my $lonhost (keys(%domservers)) {
1582: $samlurl{$lonhost} = '/adm/sso';
1583: $styleon{$lonhost} = 'display:none';
1584: $styleoff{$lonhost} = '';
1585: }
1586: if (ref($settings->{'saml'}) eq 'HASH') {
1587: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1588: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1589: $saml{$lonhost} = 1;
1590: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1591: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1592: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1593: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1594: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1595: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1596: $styleon{$lonhost} = '';
1597: $styleoff{$lonhost} = 'display:none';
1598: } else {
1599: $styleon{$lonhost} = 'display:none';
1600: $styleoff{$lonhost} = '';
1601: }
1602: }
1603: }
1604: my $itemcount = 1;
1605: foreach my $lonhost (sort(keys(%domservers))) {
1606: my $samlon = ' ';
1607: my $samloff = ' checked="checked" ';
1608: if ($saml{$lonhost}) {
1609: $samlon = $samloff;
1610: $samloff = ' ';
1611: }
1612: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1613: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1614: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1615: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1616: &mt('No').'</label>'.(' 'x2).
1617: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1618: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1619: &mt('Yes').'</label></span></td>'.
1620: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1621: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1622: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1623: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1624: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1625: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1626: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1627: $samltext{$lonhost}.'" /></td><td>';
1628: if ($samlimg{$lonhost}) {
1629: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1630: '<span class="LC_nobreak"><label>'.
1631: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1632: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1633: } else {
1634: $datatable .= $lt{'upl'};
1635: }
1636: $datatable .='<br />';
1637: if ($switchserver) {
1638: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1639: } else {
1640: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1641: }
1642: $datatable .= '</td>'.
1643: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1644: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1645: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1646: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1647: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1648: $samltitle{$lonhost}.'</textarea></td>'.
1649: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1650: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1651: '</table></td>'.
1652: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1653: $itemcount ++;
1654: }
1655: $datatable .= '</table></td></tr>';
1.1 raeburn 1656: }
1.6 raeburn 1657: return $datatable;
1658: }
1659:
1660: sub login_choices {
1661: my %choices =
1662: &Apache::lonlocal::texthash (
1.116 bisitz 1663: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1664: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1665: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1666: disallowlogin => "Login page requests redirected",
1667: hostid => "Server",
1.128 raeburn 1668: server => "Redirect to:",
1669: serverpath => "Path",
1670: custompath => "Custom",
1671: exempt => "Exempt IP(s)",
1.110 raeburn 1672: directlogin => "No redirect",
1673: newuser => "Link to create a user account",
1674: img => "Header",
1675: logo => "Main Logo",
1676: domlogo => "Domain Logo",
1677: login => "Log-in Header",
1678: textcol => "Text color",
1679: bgcol => "Box color",
1680: bgs => "Background colors",
1681: links => "Link colors",
1682: font => "Font color",
1683: pgbg => "Header",
1684: mainbg => "Page",
1685: sidebg => "Login box",
1686: link => "Link",
1687: alink => "Active link",
1688: vlink => "Visited link",
1.256 raeburn 1689: headtag => "Custom markup",
1690: action => "Action",
1691: current => "Current",
1.386 raeburn 1692: samllanding => "Dual login?",
1693: samloptions => "Options",
1.6 raeburn 1694: );
1695: return %choices;
1696: }
1697:
1.386 raeburn 1698: sub login_file_options {
1699: return &Apache::lonlocal::texthash(
1700: del => 'Delete?',
1701: rep => 'Replace:',
1702: upl => 'Upload:',
1703: curr => 'View contents',
1704: default => 'Default',
1705: custom => 'Custom',
1706: none => 'None',
1707: );
1708: }
1709:
1.6 raeburn 1710: sub print_rolecolors {
1.30 raeburn 1711: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1712: my %choices = &color_font_choices();
1713: my @bgs = ('pgbg','tabbg','sidebg');
1714: my @links = ('link','alink','vlink');
1715: my @images = ('img');
1716: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1717: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1718: my %defaultdesign = %Apache::loncommon::defaultdesign;
1719: my (%is_custom,%designs);
1.200 raeburn 1720: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1721: if (ref($settings) eq 'HASH') {
1722: if (ref($settings->{$role}) eq 'HASH') {
1723: if ($settings->{$role}->{'img'} ne '') {
1724: $designs{'img'} = $settings->{$role}->{'img'};
1725: $is_custom{'img'} = 1;
1726: }
1727: if ($settings->{$role}->{'font'} ne '') {
1728: $designs{'font'} = $settings->{$role}->{'font'};
1729: $is_custom{'font'} = 1;
1730: }
1.97 tempelho 1731: if ($settings->{$role}->{'fontmenu'} ne '') {
1732: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1733: $is_custom{'fontmenu'} = 1;
1734: }
1.6 raeburn 1735: foreach my $item (@bgs) {
1736: if ($settings->{$role}->{$item} ne '') {
1737: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1738: $is_custom{$item} = 1;
1739: }
1740: }
1741: foreach my $item (@links) {
1742: if ($settings->{$role}->{$item} ne '') {
1743: $designs{'links'}{$item} = $settings->{$role}->{$item};
1744: $is_custom{$item} = 1;
1745: }
1746: }
1747: }
1748: } else {
1749: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1750: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1751: $is_custom{'img'} = 1;
1752: }
1.97 tempelho 1753: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1754: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1755: $is_custom{'fontmenu'} = 1;
1756: }
1.6 raeburn 1757: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1758: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1759: $is_custom{'font'} = 1;
1760: }
1761: foreach my $item (@bgs) {
1762: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1763: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1764: $is_custom{$item} = 1;
1765:
1766: }
1767: }
1768: foreach my $item (@links) {
1769: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1770: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1771: $is_custom{$item} = 1;
1772: }
1773: }
1774: }
1775: my $itemcount = 1;
1.30 raeburn 1776: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1777: $datatable .= '</tr></table></td></tr>';
1778: return $datatable;
1779: }
1780:
1.200 raeburn 1781: sub role_defaults {
1782: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1783: my %defaults;
1784: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1785: return %defaults;
1786: }
1787: my %defaultdesign = %Apache::loncommon::defaultdesign;
1788: if ($role eq 'login') {
1789: %defaults = (
1790: font => $defaultdesign{$role.'.font'},
1791: );
1792: if (ref($logintext) eq 'ARRAY') {
1793: foreach my $item (@{$logintext}) {
1794: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1795: }
1796: }
1797: foreach my $item (@{$images}) {
1798: $defaults{'showlogo'}{$item} = 1;
1799: }
1800: } else {
1801: %defaults = (
1802: img => $defaultdesign{$role.'.img'},
1803: font => $defaultdesign{$role.'.font'},
1804: fontmenu => $defaultdesign{$role.'.fontmenu'},
1805: );
1806: }
1807: foreach my $item (@{$bgs}) {
1808: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1809: }
1810: foreach my $item (@{$links}) {
1811: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1812: }
1813: foreach my $item (@{$images}) {
1814: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1815: }
1816: return %defaults;
1817: }
1818:
1.6 raeburn 1819: sub display_color_options {
1.9 raeburn 1820: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1821: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1822: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1823: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1824: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1825: '<td>'.$choices->{'font'}.'</td>';
1826: if (!$is_custom->{'font'}) {
1.329 raeburn 1827: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1828: } else {
1829: $datatable .= '<td> </td>';
1830: }
1.174 foxr 1831: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1832:
1.8 raeburn 1833: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1834: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1835: ' value="'.$current_color.'" /> '.
1.329 raeburn 1836: ' </span></td></tr>';
1.107 raeburn 1837: unless ($role eq 'login') {
1838: $datatable .= '<tr'.$css_class.'>'.
1839: '<td>'.$choices->{'fontmenu'}.'</td>';
1840: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1841: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1842: } else {
1843: $datatable .= '<td> </td>';
1844: }
1.202 raeburn 1845: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1846: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1847: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1848: '<input class="colorchooser" type="text" size="10" name="'
1849: .$role.'_fontmenu"'.
1850: ' value="'.$current_color.'" /> '.
1.329 raeburn 1851: ' </span></td></tr>';
1.97 tempelho 1852: }
1.9 raeburn 1853: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1854: foreach my $img (@{$images}) {
1.18 albertel 1855: $itemcount ++;
1.6 raeburn 1856: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1857: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1858: '<td>'.$choices->{$img};
1.41 raeburn 1859: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1860: if ($role eq 'login') {
1861: if ($img eq 'login') {
1862: $login_hdr_pick =
1.135 bisitz 1863: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1864: $logincolors =
1865: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1866: $designs,$defaults);
1.70 raeburn 1867: } elsif ($img ne 'domlogo') {
1868: $datatable.= &logo_display_options($img,$defaults,$designs);
1869: }
1870: }
1871: $datatable .= '</td>';
1.6 raeburn 1872: if ($designs->{$img} ne '') {
1873: $imgfile = $designs->{$img};
1.18 albertel 1874: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1875: } else {
1876: $imgfile = $defaults->{$img};
1877: }
1878: if ($imgfile) {
1.9 raeburn 1879: my ($showfile,$fullsize);
1880: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1881: my $urldir = $1;
1882: my $filename = $2;
1883: my @info = &Apache::lonnet::stat_file($designs->{$img});
1884: if (@info) {
1885: my $thumbfile = 'tn-'.$filename;
1886: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1887: if (@thumb) {
1888: $showfile = $urldir.'/'.$thumbfile;
1889: } else {
1890: $showfile = $imgfile;
1891: }
1892: } else {
1893: $showfile = '';
1894: }
1895: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1896: $showfile = $imgfile;
1.6 raeburn 1897: my $imgdir = $1;
1898: my $filename = $2;
1.159 raeburn 1899: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1900: $showfile = "/$imgdir/tn-".$filename;
1901: } else {
1.159 raeburn 1902: my $input = $londocroot.$imgfile;
1903: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1904: if (!-e $output) {
1.9 raeburn 1905: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1906: my ($fullwidth,$fullheight) = &check_dimensions($input);
1907: if ($fullwidth ne '' && $fullheight ne '') {
1908: if ($fullwidth > $width && $fullheight > $height) {
1909: my $size = $width.'x'.$height;
1.316 raeburn 1910: my @args = ('convert','-sample',$size,$input,$output);
1911: system({$args[0]} @args);
1.159 raeburn 1912: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1913: }
1914: }
1.6 raeburn 1915: }
1916: }
1.16 raeburn 1917: }
1.6 raeburn 1918: if ($showfile) {
1.40 raeburn 1919: if ($showfile =~ m{^/(adm|res)/}) {
1920: if ($showfile =~ m{^/res/}) {
1921: my $local_showfile =
1922: &Apache::lonnet::filelocation('',$showfile);
1923: &Apache::lonnet::repcopy($local_showfile);
1924: }
1925: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1926: }
1927: if ($imgfile) {
1928: if ($imgfile =~ m{^/(adm|res)/}) {
1929: if ($imgfile =~ m{^/res/}) {
1930: my $local_imgfile =
1931: &Apache::lonnet::filelocation('',$imgfile);
1932: &Apache::lonnet::repcopy($local_imgfile);
1933: }
1934: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1935: } else {
1936: $fullsize = $imgfile;
1937: }
1938: }
1.41 raeburn 1939: $datatable .= '<td>';
1940: if ($img eq 'login') {
1.135 bisitz 1941: $datatable .= $login_hdr_pick;
1942: }
1.41 raeburn 1943: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1944: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1945: } else {
1.201 raeburn 1946: $datatable .= '<td> </td><td class="LC_left_item">'.
1947: &mt('Upload:').'<br />';
1.6 raeburn 1948: }
1949: } else {
1.201 raeburn 1950: $datatable .= '<td> </td><td class="LC_left_item">'.
1951: &mt('Upload:').'<br />';
1.6 raeburn 1952: }
1.9 raeburn 1953: if ($switchserver) {
1954: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1955: } else {
1.135 bisitz 1956: if ($img ne 'login') { # suppress file selection for Log-in header
1957: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1958: }
1.9 raeburn 1959: }
1960: $datatable .= '</td></tr>';
1.6 raeburn 1961: }
1962: $itemcount ++;
1963: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1964: $datatable .= '<tr'.$css_class.'>'.
1965: '<td>'.$choices->{'bgs'}.'</td>';
1966: my $bgs_def;
1967: foreach my $item (@{$bgs}) {
1968: if (!$is_custom->{$item}) {
1.329 raeburn 1969: $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 1970: }
1971: }
1972: if ($bgs_def) {
1.8 raeburn 1973: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1974: } else {
1975: $datatable .= '<td> </td>';
1976: }
1977: $datatable .= '<td class="LC_right_item">'.
1978: '<table border="0"><tr>';
1.174 foxr 1979:
1.6 raeburn 1980: foreach my $item (@{$bgs}) {
1.306 raeburn 1981: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1982: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1983: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1984: $datatable .= ' ';
1.6 raeburn 1985: }
1.174 foxr 1986: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1987: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1988: }
1989: $datatable .= '</tr></table></td></tr>';
1990: $itemcount ++;
1991: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1992: $datatable .= '<tr'.$css_class.'>'.
1993: '<td>'.$choices->{'links'}.'</td>';
1994: my $links_def;
1995: foreach my $item (@{$links}) {
1996: if (!$is_custom->{$item}) {
1.329 raeburn 1997: $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 1998: }
1999: }
2000: if ($links_def) {
1.8 raeburn 2001: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2002: } else {
2003: $datatable .= '<td> </td>';
2004: }
2005: $datatable .= '<td class="LC_right_item">'.
2006: '<table border="0"><tr>';
2007: foreach my $item (@{$links}) {
1.234 raeburn 2008: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2009: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2010: if ($designs->{'links'}{$item}) {
1.174 foxr 2011: $datatable.=' ';
1.6 raeburn 2012: }
1.174 foxr 2013: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2014: '" /></td>';
2015: }
1.30 raeburn 2016: $$rowtotal += $itemcount;
1.3 raeburn 2017: return $datatable;
2018: }
2019:
1.70 raeburn 2020: sub logo_display_options {
2021: my ($img,$defaults,$designs) = @_;
2022: my $checkedon;
2023: if (ref($defaults) eq 'HASH') {
2024: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2025: if ($defaults->{'showlogo'}{$img}) {
2026: $checkedon = 'checked="checked" ';
2027: }
2028: }
2029: }
2030: if (ref($designs) eq 'HASH') {
2031: if (ref($designs->{'showlogo'}) eq 'HASH') {
2032: if (defined($designs->{'showlogo'}{$img})) {
2033: if ($designs->{'showlogo'}{$img} == 0) {
2034: $checkedon = '';
2035: } elsif ($designs->{'showlogo'}{$img} == 1) {
2036: $checkedon = 'checked="checked" ';
2037: }
2038: }
2039: }
2040: }
2041: return '<br /><label> <input type="checkbox" name="'.
2042: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2043: &mt('show').'</label>'."\n";
2044: }
2045:
1.41 raeburn 2046: sub login_header_options {
1.135 bisitz 2047: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2048: my $output = '';
1.41 raeburn 2049: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2050: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2051: if (!$is_custom->{'textcol'}) {
2052: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2053: ' ';
2054: }
2055: if (!$is_custom->{'bgcol'}) {
2056: $output .= $choices->{'bgcol'}.': '.
2057: '<span id="css_'.$role.'_font" style="background-color: '.
2058: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2059: }
2060: $output .= '<br />';
2061: }
2062: $output .='<br />';
2063: return $output;
2064: }
2065:
2066: sub login_text_colors {
1.201 raeburn 2067: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2068: my $color_menu = '<table border="0"><tr>';
2069: foreach my $item (@{$logintext}) {
1.306 raeburn 2070: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2071: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2072: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2073: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2074: }
2075: $color_menu .= '</tr></table><br />';
2076: return $color_menu;
2077: }
2078:
2079: sub image_changes {
2080: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2081: my $output;
1.135 bisitz 2082: if ($img eq 'login') {
1.331 raeburn 2083: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2084: } elsif (!$is_custom) {
1.70 raeburn 2085: if ($img ne 'domlogo') {
1.331 raeburn 2086: $output = &mt('Default image:').'<br />';
1.41 raeburn 2087: } else {
1.331 raeburn 2088: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2089: }
2090: }
1.331 raeburn 2091: if ($img ne 'login') {
1.135 bisitz 2092: if ($img_import) {
2093: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2094: }
2095: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2096: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2097: if ($is_custom) {
2098: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2099: '<input type="checkbox" name="'.
2100: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2101: '</label> '.&mt('Replace:').'</span><br />';
2102: } else {
1.306 raeburn 2103: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2104: }
1.41 raeburn 2105: }
2106: return $output;
2107: }
2108:
1.3 raeburn 2109: sub print_quotas {
1.86 raeburn 2110: my ($dom,$settings,$rowtotal,$action) = @_;
2111: my $context;
2112: if ($action eq 'quotas') {
2113: $context = 'tools';
2114: } else {
2115: $context = $action;
2116: }
1.197 raeburn 2117: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2118: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2119: my $typecount = 0;
1.101 raeburn 2120: my ($css_class,%titles);
1.86 raeburn 2121: if ($context eq 'requestcourses') {
1.325 raeburn 2122: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2123: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2124: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2125: %titles = &courserequest_titles();
1.163 raeburn 2126: } elsif ($context eq 'requestauthor') {
2127: @usertools = ('author');
2128: @options = ('norequest','approval','automatic');
1.210 raeburn 2129: %titles = &authorrequest_titles();
1.86 raeburn 2130: } else {
1.162 raeburn 2131: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2132: %titles = &tool_titles();
1.86 raeburn 2133: }
1.26 raeburn 2134: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2135: foreach my $type (@{$types}) {
1.197 raeburn 2136: my ($currdefquota,$currauthorquota);
1.163 raeburn 2137: unless (($context eq 'requestcourses') ||
2138: ($context eq 'requestauthor')) {
1.86 raeburn 2139: if (ref($settings) eq 'HASH') {
2140: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2141: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2142: } else {
2143: $currdefquota = $settings->{$type};
2144: }
1.197 raeburn 2145: if (ref($settings->{authorquota}) eq 'HASH') {
2146: $currauthorquota = $settings->{authorquota}->{$type};
2147: }
1.78 raeburn 2148: }
1.72 raeburn 2149: }
1.3 raeburn 2150: if (defined($usertypes->{$type})) {
2151: $typecount ++;
2152: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2153: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2154: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2155: '<td class="LC_left_item">';
1.101 raeburn 2156: if ($context eq 'requestcourses') {
2157: $datatable .= '<table><tr>';
2158: }
2159: my %cell;
1.72 raeburn 2160: foreach my $item (@usertools) {
1.101 raeburn 2161: if ($context eq 'requestcourses') {
2162: my ($curroption,$currlimit);
2163: if (ref($settings) eq 'HASH') {
2164: if (ref($settings->{$item}) eq 'HASH') {
2165: $curroption = $settings->{$item}->{$type};
2166: if ($curroption =~ /^autolimit=(\d*)$/) {
2167: $currlimit = $1;
2168: }
2169: }
2170: }
2171: if (!$curroption) {
2172: $curroption = 'norequest';
2173: }
2174: $datatable .= '<th>'.$titles{$item}.'</th>';
2175: foreach my $option (@options) {
2176: my $val = $option;
2177: if ($option eq 'norequest') {
2178: $val = 0;
2179: }
2180: if ($option eq 'validate') {
2181: my $canvalidate = 0;
2182: if (ref($validations{$item}) eq 'HASH') {
2183: if ($validations{$item}{$type}) {
2184: $canvalidate = 1;
2185: }
2186: }
2187: next if (!$canvalidate);
2188: }
2189: my $checked = '';
2190: if ($option eq $curroption) {
2191: $checked = ' checked="checked"';
2192: } elsif ($option eq 'autolimit') {
2193: if ($curroption =~ /^autolimit/) {
2194: $checked = ' checked="checked"';
2195: }
2196: }
2197: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2198: '<input type="radio" name="crsreq_'.$item.
2199: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2200: $titles{$option}.'</label>';
1.101 raeburn 2201: if ($option eq 'autolimit') {
1.127 raeburn 2202: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2203: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2204: 'value="'.$currlimit.'" />';
1.101 raeburn 2205: }
1.127 raeburn 2206: $cell{$item} .= '</span> ';
1.103 raeburn 2207: if ($option eq 'autolimit') {
1.127 raeburn 2208: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2209: }
1.101 raeburn 2210: }
1.163 raeburn 2211: } elsif ($context eq 'requestauthor') {
2212: my $curroption;
2213: if (ref($settings) eq 'HASH') {
2214: $curroption = $settings->{$type};
2215: }
2216: if (!$curroption) {
2217: $curroption = 'norequest';
2218: }
2219: foreach my $option (@options) {
2220: my $val = $option;
2221: if ($option eq 'norequest') {
2222: $val = 0;
2223: }
2224: my $checked = '';
2225: if ($option eq $curroption) {
2226: $checked = ' checked="checked"';
2227: }
2228: $datatable .= '<span class="LC_nobreak"><label>'.
2229: '<input type="radio" name="authorreq_'.$type.
2230: '" value="'.$val.'"'.$checked.' />'.
2231: $titles{$option}.'</label></span> ';
2232: }
1.101 raeburn 2233: } else {
2234: my $checked = 'checked="checked" ';
2235: if (ref($settings) eq 'HASH') {
2236: if (ref($settings->{$item}) eq 'HASH') {
2237: if ($settings->{$item}->{$type} == 0) {
2238: $checked = '';
2239: } elsif ($settings->{$item}->{$type} == 1) {
2240: $checked = 'checked="checked" ';
2241: }
1.78 raeburn 2242: }
1.72 raeburn 2243: }
1.101 raeburn 2244: $datatable .= '<span class="LC_nobreak"><label>'.
2245: '<input type="checkbox" name="'.$context.'_'.$item.
2246: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2247: '</label></span> ';
1.72 raeburn 2248: }
1.101 raeburn 2249: }
2250: if ($context eq 'requestcourses') {
2251: $datatable .= '</tr><tr>';
2252: foreach my $item (@usertools) {
1.106 raeburn 2253: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2254: }
2255: $datatable .= '</tr></table>';
1.72 raeburn 2256: }
1.86 raeburn 2257: $datatable .= '</td>';
1.163 raeburn 2258: unless (($context eq 'requestcourses') ||
2259: ($context eq 'requestauthor')) {
1.86 raeburn 2260: $datatable .=
1.197 raeburn 2261: '<td class="LC_right_item">'.
2262: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2263: '<input type="text" name="quota_'.$type.
1.72 raeburn 2264: '" value="'.$currdefquota.
1.197 raeburn 2265: '" size="5" /></span>'.(' ' x 2).
2266: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2267: '<input type="text" name="authorquota_'.$type.
2268: '" value="'.$currauthorquota.
2269: '" size="5" /></span></td>';
1.86 raeburn 2270: }
2271: $datatable .= '</tr>';
1.3 raeburn 2272: }
2273: }
2274: }
1.163 raeburn 2275: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2276: $defaultquota = '20';
1.197 raeburn 2277: $authorquota = '500';
1.86 raeburn 2278: if (ref($settings) eq 'HASH') {
2279: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2280: $defaultquota = $settings->{'defaultquota'}->{'default'};
2281: } elsif (defined($settings->{'default'})) {
2282: $defaultquota = $settings->{'default'};
2283: }
1.197 raeburn 2284: if (ref($settings->{'authorquota'}) eq 'HASH') {
2285: $authorquota = $settings->{'authorquota'}->{'default'};
2286: }
1.3 raeburn 2287: }
2288: }
2289: $typecount ++;
2290: $css_class = $typecount%2?' class="LC_odd_row"':'';
2291: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2292: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2293: '<td class="LC_left_item">';
1.101 raeburn 2294: if ($context eq 'requestcourses') {
2295: $datatable .= '<table><tr>';
2296: }
2297: my %defcell;
1.72 raeburn 2298: foreach my $item (@usertools) {
1.101 raeburn 2299: if ($context eq 'requestcourses') {
2300: my ($curroption,$currlimit);
2301: if (ref($settings) eq 'HASH') {
2302: if (ref($settings->{$item}) eq 'HASH') {
2303: $curroption = $settings->{$item}->{'default'};
2304: if ($curroption =~ /^autolimit=(\d*)$/) {
2305: $currlimit = $1;
2306: }
2307: }
2308: }
2309: if (!$curroption) {
2310: $curroption = 'norequest';
2311: }
2312: $datatable .= '<th>'.$titles{$item}.'</th>';
2313: foreach my $option (@options) {
2314: my $val = $option;
2315: if ($option eq 'norequest') {
2316: $val = 0;
2317: }
2318: if ($option eq 'validate') {
2319: my $canvalidate = 0;
2320: if (ref($validations{$item}) eq 'HASH') {
2321: if ($validations{$item}{'default'}) {
2322: $canvalidate = 1;
2323: }
2324: }
2325: next if (!$canvalidate);
2326: }
2327: my $checked = '';
2328: if ($option eq $curroption) {
2329: $checked = ' checked="checked"';
2330: } elsif ($option eq 'autolimit') {
2331: if ($curroption =~ /^autolimit/) {
2332: $checked = ' checked="checked"';
2333: }
2334: }
2335: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2336: '<input type="radio" name="crsreq_'.$item.
2337: '_default" value="'.$val.'"'.$checked.' />'.
2338: $titles{$option}.'</label>';
2339: if ($option eq 'autolimit') {
1.127 raeburn 2340: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2341: $item.'_limit_default" size="1" '.
2342: 'value="'.$currlimit.'" />';
2343: }
1.127 raeburn 2344: $defcell{$item} .= '</span> ';
1.104 raeburn 2345: if ($option eq 'autolimit') {
1.127 raeburn 2346: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2347: }
1.101 raeburn 2348: }
1.163 raeburn 2349: } elsif ($context eq 'requestauthor') {
2350: my $curroption;
2351: if (ref($settings) eq 'HASH') {
1.172 raeburn 2352: $curroption = $settings->{'default'};
1.163 raeburn 2353: }
2354: if (!$curroption) {
2355: $curroption = 'norequest';
2356: }
2357: foreach my $option (@options) {
2358: my $val = $option;
2359: if ($option eq 'norequest') {
2360: $val = 0;
2361: }
2362: my $checked = '';
2363: if ($option eq $curroption) {
2364: $checked = ' checked="checked"';
2365: }
2366: $datatable .= '<span class="LC_nobreak"><label>'.
2367: '<input type="radio" name="authorreq_default"'.
2368: ' value="'.$val.'"'.$checked.' />'.
2369: $titles{$option}.'</label></span> ';
2370: }
1.101 raeburn 2371: } else {
2372: my $checked = 'checked="checked" ';
2373: if (ref($settings) eq 'HASH') {
2374: if (ref($settings->{$item}) eq 'HASH') {
2375: if ($settings->{$item}->{'default'} == 0) {
2376: $checked = '';
2377: } elsif ($settings->{$item}->{'default'} == 1) {
2378: $checked = 'checked="checked" ';
2379: }
1.78 raeburn 2380: }
1.72 raeburn 2381: }
1.101 raeburn 2382: $datatable .= '<span class="LC_nobreak"><label>'.
2383: '<input type="checkbox" name="'.$context.'_'.$item.
2384: '" value="default" '.$checked.'/>'.$titles{$item}.
2385: '</label></span> ';
2386: }
2387: }
2388: if ($context eq 'requestcourses') {
2389: $datatable .= '</tr><tr>';
2390: foreach my $item (@usertools) {
1.106 raeburn 2391: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2392: }
1.101 raeburn 2393: $datatable .= '</tr></table>';
1.72 raeburn 2394: }
1.86 raeburn 2395: $datatable .= '</td>';
1.163 raeburn 2396: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2397: $datatable .= '<td class="LC_right_item">'.
2398: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2399: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2400: $defaultquota.'" size="5" /></span>'.(' ' x2).
2401: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2402: '<input type="text" name="authorquota" value="'.
2403: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2404: }
2405: $datatable .= '</tr>';
1.72 raeburn 2406: $typecount ++;
2407: $css_class = $typecount%2?' class="LC_odd_row"':'';
2408: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2409: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2410: if ($context eq 'requestcourses') {
1.109 raeburn 2411: $datatable .= &mt('(overrides affiliation, if set)').
2412: '</td>'.
2413: '<td class="LC_left_item">'.
2414: '<table><tr>';
1.101 raeburn 2415: } else {
1.109 raeburn 2416: $datatable .= &mt('(overrides affiliation, if checked)').
2417: '</td>'.
2418: '<td class="LC_left_item" colspan="2">'.
2419: '<br />';
1.101 raeburn 2420: }
2421: my %advcell;
1.72 raeburn 2422: foreach my $item (@usertools) {
1.101 raeburn 2423: if ($context eq 'requestcourses') {
2424: my ($curroption,$currlimit);
2425: if (ref($settings) eq 'HASH') {
2426: if (ref($settings->{$item}) eq 'HASH') {
2427: $curroption = $settings->{$item}->{'_LC_adv'};
2428: if ($curroption =~ /^autolimit=(\d*)$/) {
2429: $currlimit = $1;
2430: }
2431: }
2432: }
2433: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2434: my $checked = '';
2435: if ($curroption eq '') {
2436: $checked = ' checked="checked"';
2437: }
2438: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2439: '<input type="radio" name="crsreq_'.$item.
2440: '__LC_adv" value=""'.$checked.' />'.
2441: &mt('No override set').'</label></span> ';
1.101 raeburn 2442: foreach my $option (@options) {
2443: my $val = $option;
2444: if ($option eq 'norequest') {
2445: $val = 0;
2446: }
2447: if ($option eq 'validate') {
2448: my $canvalidate = 0;
2449: if (ref($validations{$item}) eq 'HASH') {
2450: if ($validations{$item}{'_LC_adv'}) {
2451: $canvalidate = 1;
2452: }
2453: }
2454: next if (!$canvalidate);
2455: }
2456: my $checked = '';
1.104 raeburn 2457: if ($val eq $curroption) {
1.101 raeburn 2458: $checked = ' checked="checked"';
2459: } elsif ($option eq 'autolimit') {
2460: if ($curroption =~ /^autolimit/) {
2461: $checked = ' checked="checked"';
2462: }
2463: }
2464: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2465: '<input type="radio" name="crsreq_'.$item.
2466: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2467: $titles{$option}.'</label>';
2468: if ($option eq 'autolimit') {
1.127 raeburn 2469: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2470: $item.'_limit__LC_adv" size="1" '.
2471: 'value="'.$currlimit.'" />';
2472: }
1.127 raeburn 2473: $advcell{$item} .= '</span> ';
1.104 raeburn 2474: if ($option eq 'autolimit') {
1.127 raeburn 2475: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2476: }
1.101 raeburn 2477: }
1.163 raeburn 2478: } elsif ($context eq 'requestauthor') {
2479: my $curroption;
2480: if (ref($settings) eq 'HASH') {
2481: $curroption = $settings->{'_LC_adv'};
2482: }
2483: my $checked = '';
2484: if ($curroption eq '') {
2485: $checked = ' checked="checked"';
2486: }
2487: $datatable .= '<span class="LC_nobreak"><label>'.
2488: '<input type="radio" name="authorreq__LC_adv"'.
2489: ' value=""'.$checked.' />'.
2490: &mt('No override set').'</label></span> ';
2491: foreach my $option (@options) {
2492: my $val = $option;
2493: if ($option eq 'norequest') {
2494: $val = 0;
2495: }
2496: my $checked = '';
2497: if ($val eq $curroption) {
2498: $checked = ' checked="checked"';
2499: }
2500: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2501: '<input type="radio" name="authorreq__LC_adv"'.
2502: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2503: $titles{$option}.'</label></span> ';
2504: }
1.101 raeburn 2505: } else {
2506: my $checked = 'checked="checked" ';
2507: if (ref($settings) eq 'HASH') {
2508: if (ref($settings->{$item}) eq 'HASH') {
2509: if ($settings->{$item}->{'_LC_adv'} == 0) {
2510: $checked = '';
2511: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2512: $checked = 'checked="checked" ';
2513: }
1.79 raeburn 2514: }
1.72 raeburn 2515: }
1.101 raeburn 2516: $datatable .= '<span class="LC_nobreak"><label>'.
2517: '<input type="checkbox" name="'.$context.'_'.$item.
2518: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2519: '</label></span> ';
2520: }
2521: }
2522: if ($context eq 'requestcourses') {
2523: $datatable .= '</tr><tr>';
2524: foreach my $item (@usertools) {
1.106 raeburn 2525: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2526: }
1.101 raeburn 2527: $datatable .= '</tr></table>';
1.72 raeburn 2528: }
1.98 raeburn 2529: $datatable .= '</td></tr>';
1.30 raeburn 2530: $$rowtotal += $typecount;
1.3 raeburn 2531: return $datatable;
2532: }
2533:
1.163 raeburn 2534: sub print_requestmail {
1.305 raeburn 2535: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2536: my ($now,$datatable,%currapp);
1.102 raeburn 2537: $now = time;
2538: if (ref($settings) eq 'HASH') {
2539: if (ref($settings->{'notify'}) eq 'HASH') {
2540: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2541: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2542: }
2543: }
2544: }
1.191 raeburn 2545: my $numinrow = 2;
1.224 raeburn 2546: my $css_class;
1.305 raeburn 2547: if ($$rowtotal%2) {
2548: $css_class = 'LC_odd_row';
2549: }
2550: if ($customcss) {
2551: $css_class .= " $customcss";
2552: }
2553: $css_class =~ s/^\s+//;
2554: if ($css_class) {
2555: $css_class = ' class="'.$css_class.'"';
2556: }
2557: if ($rowstyle) {
2558: $css_class .= ' style="'.$rowstyle.'"';
2559: }
1.163 raeburn 2560: my $text;
2561: if ($action eq 'requestcourses') {
2562: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2563: } elsif ($action eq 'requestauthor') {
2564: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2565: } else {
1.224 raeburn 2566: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2567: }
1.224 raeburn 2568: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2569: ' <td>'.$text.'</td>'.
1.102 raeburn 2570: ' <td class="LC_left_item">';
1.191 raeburn 2571: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2572: $action.'notifyapproval',%currapp);
1.191 raeburn 2573: if ($numdc > 0) {
2574: $datatable .= $table;
1.102 raeburn 2575: } else {
2576: $datatable .= &mt('There are no active Domain Coordinators');
2577: }
2578: $datatable .='</td></tr>';
2579: return $datatable;
2580: }
2581:
1.216 raeburn 2582: sub print_studentcode {
2583: my ($settings,$rowtotal) = @_;
2584: my $rownum = 0;
1.218 raeburn 2585: my ($output,%current);
1.325 raeburn 2586: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2587: if (ref($settings) eq 'HASH') {
2588: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2589: foreach my $type (@crstypes) {
2590: $current{$type} = $settings->{'uniquecode'}{$type};
2591: }
1.218 raeburn 2592: }
2593: }
2594: $output .= '<tr>'.
2595: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2596: '<td class="LC_left_item">';
2597: foreach my $type (@crstypes) {
2598: my $check = ' ';
2599: if ($current{$type}) {
2600: $check = ' checked="checked" ';
2601: }
2602: $output .= '<span class="LC_nobreak"><label>'.
2603: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2604: &mt($type).'</label></span>'.(' 'x2).' ';
2605: }
2606: $output .= '</td></tr>';
2607: $$rowtotal ++;
2608: return $output;
1.216 raeburn 2609: }
2610:
2611: sub print_textbookcourses {
1.242 raeburn 2612: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2613: my $rownum = 0;
2614: my $css_class;
2615: my $itemcount = 1;
2616: my $maxnum = 0;
2617: my $bookshash;
2618: if (ref($settings) eq 'HASH') {
1.242 raeburn 2619: $bookshash = $settings->{$type};
1.216 raeburn 2620: }
2621: my %ordered;
2622: if (ref($bookshash) eq 'HASH') {
2623: foreach my $item (keys(%{$bookshash})) {
2624: if (ref($bookshash->{$item}) eq 'HASH') {
2625: my $num = $bookshash->{$item}{'order'};
2626: $ordered{$num} = $item;
2627: }
2628: }
2629: }
2630: my $confname = $dom.'-domainconfig';
2631: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2632: my $maxnum = scalar(keys(%ordered));
2633: my $datatable;
1.216 raeburn 2634: if (keys(%ordered)) {
2635: my @items = sort { $a <=> $b } keys(%ordered);
2636: for (my $i=0; $i<@items; $i++) {
2637: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2638: my $key = $ordered{$items[$i]};
2639: my %coursehash=&Apache::lonnet::coursedescription($key);
2640: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2641: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2642: if (ref($bookshash->{$key}) eq 'HASH') {
2643: $subject = $bookshash->{$key}->{'subject'};
2644: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2645: if ($type eq 'textbooks') {
1.243 raeburn 2646: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2647: $author = $bookshash->{$key}->{'author'};
2648: $image = $bookshash->{$key}->{'image'};
2649: if ($image ne '') {
2650: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2651: my $imagethumb = "$path/tn-".$imagefile;
2652: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2653: }
1.216 raeburn 2654: }
2655: }
1.242 raeburn 2656: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2657: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2658: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2659: for (my $k=0; $k<=$maxnum; $k++) {
2660: my $vpos = $k+1;
2661: my $selstr;
2662: if ($k == $i) {
2663: $selstr = ' selected="selected" ';
2664: }
2665: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2666: }
2667: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2668: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2669: &mt('Delete?').'</label></span></td>'.
2670: '<td colspan="2">'.
1.242 raeburn 2671: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2672: (' 'x2).
1.242 raeburn 2673: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2674: if ($type eq 'textbooks') {
2675: $datatable .= (' 'x2).
1.243 raeburn 2676: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2677: (' 'x2).
1.242 raeburn 2678: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2679: (' 'x2).
2680: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2681: if ($image) {
1.267 raeburn 2682: $datatable .= $imgsrc.
1.242 raeburn 2683: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2684: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2685: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2686: }
2687: if ($switchserver) {
2688: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2689: } else {
2690: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2691: }
1.216 raeburn 2692: }
1.242 raeburn 2693: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2694: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2695: $coursetitle.'</span></td></tr>'."\n";
2696: $itemcount ++;
2697: }
2698: }
2699: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2700: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2701: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2702: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2703: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2704: for (my $k=0; $k<$maxnum+1; $k++) {
2705: my $vpos = $k+1;
2706: my $selstr;
2707: if ($k == $maxnum) {
2708: $selstr = ' selected="selected" ';
2709: }
2710: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2711: }
2712: $datatable .= '</select> '."\n".
1.334 raeburn 2713: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2714: '<td colspan="2">'.
1.242 raeburn 2715: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2716: (' 'x2).
1.242 raeburn 2717: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2718: (' 'x2);
2719: if ($type eq 'textbooks') {
1.243 raeburn 2720: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2721: (' 'x2).
2722: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2723: (' 'x2).
2724: '<span class="LC_nobreak">'.&mt('Image:').' ';
2725: if ($switchserver) {
2726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2727: } else {
2728: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2729: }
1.334 raeburn 2730: $datatable .= '</span>'."\n";
1.216 raeburn 2731: }
1.334 raeburn 2732: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2733: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2734: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2735: &Apache::loncommon::selectcourse_link
1.334 raeburn 2736: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2737: '</span></td>'."\n".
2738: '</tr>'."\n";
2739: $itemcount ++;
2740: return $datatable;
2741: }
2742:
1.217 raeburn 2743: sub textbookcourses_javascript {
1.242 raeburn 2744: my ($settings) = @_;
2745: return unless(ref($settings) eq 'HASH');
2746: my (%ordered,%total,%jstext);
2747: foreach my $type ('textbooks','templates') {
2748: $total{$type} = 0;
2749: if (ref($settings->{$type}) eq 'HASH') {
2750: foreach my $item (keys(%{$settings->{$type}})) {
2751: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2752: my $num = $settings->{$type}->{$item}{'order'};
2753: $ordered{$type}{$num} = $item;
2754: }
2755: }
2756: $total{$type} = scalar(keys(%{$settings->{$type}}));
2757: }
2758: my @jsarray = ();
2759: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2760: push(@jsarray,$ordered{$type}{$item});
2761: }
2762: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2763: }
2764: return <<"ENDSCRIPT";
2765: <script type="text/javascript">
2766: // <![CDATA[
1.242 raeburn 2767: function reorderBooks(form,item,caller) {
1.217 raeburn 2768: var changedVal;
1.242 raeburn 2769: $jstext{'textbooks'};
2770: $jstext{'templates'};
2771: var newpos;
2772: var maxh;
2773: if (caller == 'textbooks') {
2774: newpos = 'textbooks_addbook_pos';
2775: maxh = 1 + $total{'textbooks'};
2776: } else {
2777: newpos = 'templates_addbook_pos';
2778: maxh = 1 + $total{'templates'};
2779: }
1.217 raeburn 2780: var current = new Array;
2781: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2782: if (item == newpos) {
2783: changedVal = newitemVal;
2784: } else {
2785: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2786: current[newitemVal] = newpos;
2787: }
1.242 raeburn 2788: if (caller == 'textbooks') {
2789: for (var i=0; i<textbooks.length; i++) {
2790: var elementName = 'textbooks_'+textbooks[i];
2791: if (elementName != item) {
2792: if (form.elements[elementName]) {
2793: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2794: current[currVal] = elementName;
2795: }
2796: }
2797: }
2798: }
2799: if (caller == 'templates') {
2800: for (var i=0; i<templates.length; i++) {
2801: var elementName = 'templates_'+templates[i];
2802: if (elementName != item) {
2803: if (form.elements[elementName]) {
2804: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2805: current[currVal] = elementName;
2806: }
1.217 raeburn 2807: }
2808: }
2809: }
2810: var oldVal;
2811: for (var j=0; j<maxh; j++) {
2812: if (current[j] == undefined) {
2813: oldVal = j;
2814: }
2815: }
2816: if (oldVal < changedVal) {
2817: for (var k=oldVal+1; k<=changedVal ; k++) {
2818: var elementName = current[k];
2819: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2820: }
2821: } else {
2822: for (var k=changedVal; k<oldVal; k++) {
2823: var elementName = current[k];
2824: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2825: }
2826: }
2827: return;
2828: }
2829:
2830: // ]]>
2831: </script>
2832:
2833: ENDSCRIPT
2834: }
2835:
1.267 raeburn 2836: sub ltitools_javascript {
2837: my ($settings) = @_;
1.319 raeburn 2838: my $togglejs = <itools_toggle_js();
2839: unless (ref($settings) eq 'HASH') {
2840: return $togglejs;
2841: }
1.267 raeburn 2842: my (%ordered,$total,%jstext);
2843: $total = 0;
2844: foreach my $item (keys(%{$settings})) {
2845: if (ref($settings->{$item}) eq 'HASH') {
2846: my $num = $settings->{$item}{'order'};
2847: $ordered{$num} = $item;
2848: }
2849: }
2850: $total = scalar(keys(%{$settings}));
2851: my @jsarray = ();
2852: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2853: push(@jsarray,$ordered{$item});
2854: }
2855: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2856: return <<"ENDSCRIPT";
2857: <script type="text/javascript">
2858: // <![CDATA[
1.319 raeburn 2859: function reorderLTITools(form,item) {
1.267 raeburn 2860: var changedVal;
2861: $jstext
2862: var newpos = 'ltitools_add_pos';
2863: var maxh = 1 + $total;
2864: var current = new Array;
2865: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2866: if (item == newpos) {
2867: changedVal = newitemVal;
2868: } else {
2869: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2870: current[newitemVal] = newpos;
2871: }
2872: for (var i=0; i<ltitools.length; i++) {
2873: var elementName = 'ltitools_'+ltitools[i];
2874: if (elementName != item) {
2875: if (form.elements[elementName]) {
2876: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2877: current[currVal] = elementName;
2878: }
2879: }
2880: }
2881: var oldVal;
2882: for (var j=0; j<maxh; j++) {
2883: if (current[j] == undefined) {
2884: oldVal = j;
2885: }
2886: }
2887: if (oldVal < changedVal) {
2888: for (var k=oldVal+1; k<=changedVal ; k++) {
2889: var elementName = current[k];
2890: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2891: }
2892: } else {
2893: for (var k=changedVal; k<oldVal; k++) {
2894: var elementName = current[k];
2895: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2896: }
2897: }
2898: return;
2899: }
2900:
2901: // ]]>
2902: </script>
2903:
1.319 raeburn 2904: $togglejs
2905:
2906: ENDSCRIPT
2907: }
2908:
2909: sub ltitools_toggle_js {
2910: return <<"ENDSCRIPT";
2911: <script type="text/javascript">
2912: // <![CDATA[
2913:
2914: function toggleLTITools(form,setting,item) {
2915: var radioname = '';
2916: var divid = '';
2917: if ((setting == 'passback') || (setting == 'roster')) {
2918: radioname = 'ltitools_'+setting+'_'+item;
2919: divid = 'ltitools_'+setting+'time_'+item;
2920: var num = form.elements[radioname].length;
2921: if (num) {
2922: var setvis = '';
2923: for (var i=0; i<num; i++) {
2924: if (form.elements[radioname][i].checked) {
2925: if (form.elements[radioname][i].value == '1') {
2926: if (document.getElementById(divid)) {
2927: document.getElementById(divid).style.display = 'inline-block';
2928: }
2929: setvis = 1;
2930: }
2931: break;
2932: }
2933: }
2934: }
2935: if (!setvis) {
2936: if (document.getElementById(divid)) {
2937: document.getElementById(divid).style.display = 'none';
2938: }
2939: }
2940: }
1.324 raeburn 2941: if (setting == 'user') {
2942: divid = 'ltitools_'+setting+'_div_'+item;
2943: var checkid = 'ltitools_'+setting+'_field_'+item;
2944: if (document.getElementById(divid)) {
2945: if (document.getElementById(checkid)) {
2946: if (document.getElementById(checkid).checked) {
2947: document.getElementById(divid).style.display = 'inline-block';
2948: } else {
2949: document.getElementById(divid).style.display = 'none';
2950: }
2951: }
2952: }
2953: }
1.319 raeburn 2954: return;
2955: }
2956: // ]]>
2957: </script>
2958:
1.267 raeburn 2959: ENDSCRIPT
2960: }
2961:
1.381 raeburn 2962: sub wafproxy_javascript {
2963: my ($dom) = @_;
2964: return <<"ENDSCRIPT";
2965: <script type="text/javascript">
2966: // <![CDATA[
2967: function updateWAF() {
2968: if (document.getElementById('wafproxy_remoteip')) {
2969: var wafremote = 0;
2970: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2971: wafremote = 1;
2972: }
2973: var fields = new Array('header','trust');
2974: for (var i=0; i<fields.length; i++) {
2975: if (document.getElementById('wafproxy_'+fields[i])) {
2976: if (wafremote == 1) {
2977: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2978: }
2979: else {
2980: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2981: }
2982: }
2983: }
2984: if (document.getElementById('wafproxyranges_$dom')) {
2985: if (wafremote == 1) {
2986: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2987: } else {
2988: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2989: if (document.display.wafproxy_vpnaccess[i].checked) {
2990: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2991: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2992: }
2993: }
2994: }
2995: }
2996: }
2997: }
2998: return;
2999: }
3000:
3001: function checkWAF() {
3002: if (document.getElementById('wafproxy_remoteip')) {
3003: var wafvpn = 0;
3004: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3005: if (document.display.wafproxy_vpnaccess[i].checked) {
3006: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3007: wafvpn = 1;
3008: }
3009: break;
3010: }
3011: }
3012: var vpn = new Array('vpnint','vpnext');
3013: for (var i=0; i<vpn.length; i++) {
3014: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3015: if (wafvpn == 1) {
3016: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3017: }
3018: else {
3019: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3020: }
3021: }
3022: }
3023: if (document.getElementById('wafproxyranges_$dom')) {
3024: if (wafvpn == 1) {
3025: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3026: }
3027: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3028: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3029: }
3030: }
3031: }
3032: return;
3033: }
3034:
3035: function toggleWAF() {
3036: if (document.getElementById('wafproxy_table')) {
3037: var wafproxy = 0;
3038: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3039: if (document.display.wafproxy_${dom}[i].checked) {
3040: if (document.display.wafproxy_${dom}[i].value == 1) {
3041: wafproxy = 1;
3042: break;
3043: }
3044: }
3045: }
3046: if (wafproxy == 1) {
3047: document.getElementById('wafproxy_table').style.display='inline';
3048: }
3049: else {
3050: document.getElementById('wafproxy_table').style.display='none';
3051: }
3052: if (document.getElementById('wafproxyrow_${dom}')) {
3053: if (wafproxy == 1) {
3054: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3055: }
3056: else {
3057: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3058: }
3059: }
3060: if (document.getElementById('nowafproxyrow_$dom')) {
3061: if (wafproxy == 1) {
3062: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3063: }
3064: else {
3065: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3066: }
3067: }
3068: }
3069: return;
3070: }
3071: // ]]>
3072: </script>
3073:
3074: ENDSCRIPT
3075: }
3076:
1.372 raeburn 3077: sub proctoring_javascript {
3078: my ($settings) = @_;
3079: my (%ordered,$total,%jstext);
3080: $total = 0;
3081: if (ref($settings) eq 'HASH') {
3082: foreach my $item (keys(%{$settings})) {
3083: if (ref($settings->{$item}) eq 'HASH') {
3084: my $num = $settings->{$item}{'order'};
3085: $ordered{$num} = $item;
3086: }
3087: }
3088: $total = scalar(keys(%{$settings}));
3089: } else {
3090: %ordered = (
3091: 0 => 'proctorio',
3092: 1 => 'examity',
3093: );
3094: $total = 2;
3095: }
3096: my @jsarray = ();
3097: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3098: push(@jsarray,$ordered{$item});
3099: }
3100: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3101: return <<"ENDSCRIPT";
3102: <script type="text/javascript">
3103: // <![CDATA[
3104: function reorderProctoring(form,item) {
3105: var changedVal;
3106: $jstext
3107: var maxh = $total;
3108: var current = new Array;
3109: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3110: for (var i=0; i<proctors.length; i++) {
3111: var elementName = 'proctoring_pos_'+proctors[i];
3112: if (elementName != item) {
3113: if (form.elements[elementName]) {
3114: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3115: current[currVal] = elementName;
3116: }
3117: }
3118: }
3119: var oldVal;
3120: for (var j=0; j<maxh; j++) {
3121: if (current[j] == undefined) {
3122: oldVal = j;
3123: }
3124: }
3125: if (oldVal < changedVal) {
3126: for (var k=oldVal+1; k<=changedVal ; k++) {
3127: var elementName = current[k];
3128: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3129: }
3130: } else {
3131: for (var k=changedVal; k<oldVal; k++) {
3132: var elementName = current[k];
3133: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3134: }
3135: }
3136: return;
3137: }
3138:
3139: function toggleProctoring(form,item) {
3140: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3141: if (fieldsets.length) {
3142: var radioname = 'proctoring_available_'+item;
3143: var num = form.elements[radioname].length;
3144: if (num) {
3145: var setvis = '';
3146: for (var i=0; i<num; i++) {
3147: if (form.elements[radioname][i].checked) {
3148: if (form.elements[radioname][i].value == '1') {
3149: setvis = 1;
3150: break;
3151: }
3152: }
3153: }
3154: for (var j=0; j<fieldsets.length; j++) {
3155: if (setvis) {
3156: fieldsets[j].style.display = 'block';
3157: } else {
3158: fieldsets[j].style.display = 'none';
3159: }
3160: }
3161: }
3162: }
3163: return;
3164: }
3165:
3166: // ]]>
3167: </script>
3168:
3169: ENDSCRIPT
3170: }
3171:
3172:
1.320 raeburn 3173: sub lti_javascript {
3174: my ($settings) = @_;
3175: my $togglejs = <i_toggle_js();
3176: unless (ref($settings) eq 'HASH') {
3177: return $togglejs;
3178: }
3179: my (%ordered,$total,%jstext);
1.390 raeburn 3180: $total = scalar(keys(%{$settings}));
1.320 raeburn 3181: foreach my $item (keys(%{$settings})) {
3182: if (ref($settings->{$item}) eq 'HASH') {
3183: my $num = $settings->{$item}{'order'};
1.390 raeburn 3184: if ($num eq '') {
3185: $num = $total - 1;
3186: }
1.320 raeburn 3187: $ordered{$num} = $item;
3188: }
3189: }
3190: my @jsarray = ();
3191: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3192: push(@jsarray,$ordered{$item});
3193: }
3194: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3195: return <<"ENDSCRIPT";
3196: <script type="text/javascript">
3197: // <![CDATA[
3198: function reorderLTI(form,item) {
3199: var changedVal;
3200: $jstext
3201: var newpos = 'lti_pos_add';
3202: var maxh = 1 + $total;
3203: var current = new Array;
3204: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3205: if (item == newpos) {
3206: changedVal = newitemVal;
3207: } else {
3208: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3209: current[newitemVal] = newpos;
3210: }
3211: for (var i=0; i<lti.length; i++) {
3212: var elementName = 'lti_pos_'+lti[i];
3213: if (elementName != item) {
3214: if (form.elements[elementName]) {
3215: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3216: current[currVal] = elementName;
3217: }
3218: }
3219: }
3220: var oldVal;
3221: for (var j=0; j<maxh; j++) {
3222: if (current[j] == undefined) {
3223: oldVal = j;
3224: }
3225: }
3226: if (oldVal < changedVal) {
3227: for (var k=oldVal+1; k<=changedVal ; k++) {
3228: var elementName = current[k];
3229: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3230: }
3231: } else {
3232: for (var k=changedVal; k<oldVal; k++) {
3233: var elementName = current[k];
3234: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3235: }
3236: }
3237: return;
3238: }
3239: // ]]>
3240: </script>
3241:
3242: $togglejs
3243:
3244: ENDSCRIPT
3245: }
3246:
3247: sub lti_toggle_js {
1.325 raeburn 3248: my %lcauthparmtext = &Apache::lonlocal::texthash (
3249: localauth => 'Local auth argument',
3250: krb => 'Kerberos domain',
3251: );
1.391 raeburn 3252: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3253: &js_escape(\$crsincalert);
1.320 raeburn 3254: return <<"ENDSCRIPT";
3255: <script type="text/javascript">
3256: // <![CDATA[
3257:
3258: function toggleLTI(form,setting,item) {
1.391 raeburn 3259: if ((setting == 'requser') || (setting == 'crsinc')) {
3260: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3261: var setvis = '';
3262: var radioname = 'lti_requser_'+item;
3263: var num = form.elements[radioname].length;
3264: if (num) {
3265: for (var i=0; i<num; i++) {
3266: if (form.elements[radioname][i].checked) {
3267: if (form.elements[radioname][i].value == '1') {
3268: setvis = 1;
3269: break;
3270: }
3271: }
3272: }
3273: }
3274: if (usrfieldsets.length) {
3275: for (var j=0; j<usrfieldsets.length; j++) {
3276: if (setvis) {
3277: usrfieldsets[j].style.display = 'block';
3278: } else {
3279: usrfieldsets[j].style.display = 'none';
3280: }
3281: }
3282: }
3283: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3284: if (crsfieldsets.length) {
3285: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3286: var num = form.elements[radioname].length;
3287: if (num) {
1.391 raeburn 3288: var crsvis = '';
1.345 raeburn 3289: for (var i=0; i<num; i++) {
3290: if (form.elements[radioname][i].checked) {
3291: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3292: if (setvis == '') {
3293: if (setting == 'crsinc'){
3294: alert("$crsincalert");
3295: form.elements[radioname][0].checked = true;
3296: }
3297: } else {
3298: crsvis = 1;
3299: }
3300: break;
1.345 raeburn 3301: }
3302: }
3303: }
1.391 raeburn 3304: setvis = crsvis;
3305: }
3306: for (var j=0; j<crsfieldsets.length; j++) {
3307: if (setvis) {
3308: crsfieldsets[j].style.display = 'block';
3309: } else {
3310: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3311: }
3312: }
3313: }
1.363 raeburn 3314: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3315: var radioname = '';
3316: var divid = '';
3317: if (setting == 'user') {
3318: radioname = 'lti_mapuser_'+item;
3319: divid = 'lti_userfield_'+item;
1.343 raeburn 3320: } else if (setting == 'crs') {
1.320 raeburn 3321: radioname = 'lti_mapcrs_'+item;
3322: divid = 'lti_crsfield_'+item;
1.363 raeburn 3323: } else if (setting == 'callback') {
3324: radioname = 'lti_callback_'+item;
3325: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3326: } else {
1.351 raeburn 3327: radioname = 'lti_passback_'+item;
1.337 raeburn 3328: divid = 'lti_passback_'+item;
1.320 raeburn 3329: }
3330: var num = form.elements[radioname].length;
3331: if (num) {
3332: var setvis = '';
3333: for (var i=0; i<num; i++) {
3334: if (form.elements[radioname][i].checked) {
1.363 raeburn 3335: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3336: if (form.elements[radioname][i].value == '1') {
3337: if (document.getElementById(divid)) {
3338: document.getElementById(divid).style.display = 'inline-block';
3339: }
3340: setvis = 1;
3341: break;
3342: }
3343: } else {
3344: if (form.elements[radioname][i].value == 'other') {
3345: if (document.getElementById(divid)) {
3346: document.getElementById(divid).style.display = 'inline-block';
3347: }
3348: setvis = 1;
3349: break;
1.320 raeburn 3350: }
3351: }
3352: }
3353: }
3354: if (!setvis) {
3355: if (document.getElementById(divid)) {
3356: document.getElementById(divid).style.display = 'none';
3357: }
3358: }
3359: }
3360: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3361: var numsec = form.elements['lti_crssec_'+item].length;
3362: if (numsec) {
3363: var setvis = '';
3364: for (var i=0; i<numsec; i++) {
3365: if (form.elements['lti_crssec_'+item][i].checked) {
3366: if (form.elements['lti_crssec_'+item][i].value == '1') {
3367: if (document.getElementById('lti_crssecfield_'+item)) {
3368: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3369: setvis = 1;
3370: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3371: if (numsrcsec) {
3372: var setsrcvis = '';
3373: for (var j=0; j<numsrcsec; j++) {
3374: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3375: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3376: if (document.getElementById('lti_secsrcfield_'+item)) {
3377: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3378: setsrcvis = 1;
3379: }
3380: }
3381: }
3382: }
3383: if (!setsrcvis) {
3384: if (document.getElementById('lti_secsrcfield_'+item)) {
3385: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3386: }
3387: }
3388: }
3389: }
3390: }
3391: }
3392: }
3393: if (!setvis) {
3394: if (document.getElementById('lti_crssecfield_'+item)) {
3395: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3396: }
3397: if (document.getElementById('lti_secsrcfield_'+item)) {
3398: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3399: }
3400: }
3401: }
1.325 raeburn 3402: } else if (setting == 'lcauth') {
3403: var numauth = form.elements['lti_lcauth_'+item].length;
3404: if (numauth) {
3405: for (var i=0; i<numauth; i++) {
3406: if (form.elements['lti_lcauth_'+item][i].checked) {
3407: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3408: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3409: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3410: } else {
3411: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3412: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3413: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3414: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3415: } else {
3416: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3417: }
3418: }
3419: }
3420: }
3421: }
3422: }
3423: }
1.326 raeburn 3424: } else if (setting == 'lcmenu') {
3425: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3426: var divid = 'lti_menufield_'+item;
3427: var setvis = '';
3428: for (var i=0; i<menus.length; i++) {
3429: var radioname = menus[i];
3430: var num = form.elements[radioname].length;
3431: if (num) {
3432: for (var j=0; j<num; j++) {
3433: if (form.elements[radioname][j].checked) {
3434: if (form.elements[radioname][j].value == '1') {
3435: if (document.getElementById(divid)) {
3436: document.getElementById(divid).style.display = 'inline-block';
3437: }
3438: setvis = 1;
3439: break;
3440: }
3441: }
3442: }
3443: }
3444: if (setvis == 1) {
3445: break;
3446: }
3447: }
3448: if (!setvis) {
3449: if (document.getElementById(divid)) {
3450: document.getElementById(divid).style.display = 'none';
3451: }
3452: }
1.320 raeburn 3453: }
3454: return;
3455: }
3456: // ]]>
3457: </script>
3458:
3459: ENDSCRIPT
3460: }
3461:
1.385 raeburn 3462: sub autoupdate_javascript {
3463: return <<"ENDSCRIPT";
3464: <script type="text/javascript">
3465: // <![CDATA[
3466: function toggleLastActiveDays(form) {
3467: var radioname = 'lastactive';
3468: var divid = 'lastactive_div';
3469: var num = form.elements[radioname].length;
3470: if (num) {
3471: var setvis = '';
3472: for (var i=0; i<num; i++) {
3473: if (form.elements[radioname][i].checked) {
3474: if (form.elements[radioname][i].value == '1') {
3475: if (document.getElementById(divid)) {
3476: document.getElementById(divid).style.display = 'inline-block';
3477: }
3478: setvis = 1;
3479: }
3480: break;
3481: }
3482: }
3483: if (!setvis) {
3484: if (document.getElementById(divid)) {
3485: document.getElementById(divid).style.display = 'none';
3486: }
3487: }
3488: }
3489: return;
3490: }
3491: // ]]>
3492: </script>
3493:
3494: ENDSCRIPT
3495: }
3496:
1.386 raeburn 3497: sub saml_javascript {
3498: return <<"ENDSCRIPT";
3499: <script type="text/javascript">
3500: // <![CDATA[
3501: function toggleSamlOptions(form,hostid) {
3502: var radioname = 'saml_'+hostid;
3503: var tablecellon = 'samloptionson_'+hostid;
3504: var tablecelloff = 'samloptionsoff_'+hostid;
3505: var num = form.elements[radioname].length;
3506: if (num) {
3507: var setvis = '';
3508: for (var i=0; i<num; i++) {
3509: if (form.elements[radioname][i].checked) {
3510: if (form.elements[radioname][i].value == '1') {
3511: if (document.getElementById(tablecellon)) {
3512: document.getElementById(tablecellon).style.display='';
3513: }
3514: if (document.getElementById(tablecelloff)) {
3515: document.getElementById(tablecelloff).style.display='none';
3516: }
3517: setvis = 1;
3518: }
3519: break;
3520: }
3521: }
3522: if (!setvis) {
3523: if (document.getElementById(tablecellon)) {
3524: document.getElementById(tablecellon).style.display='none';
3525: }
3526: if (document.getElementById(tablecelloff)) {
3527: document.getElementById(tablecelloff).style.display='';
3528: }
3529: }
3530: }
3531: return;
3532: }
3533: // ]]>
3534: </script>
3535:
3536: ENDSCRIPT
3537: }
3538:
1.3 raeburn 3539: sub print_autoenroll {
1.30 raeburn 3540: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3541: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3542: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3543: if (ref($settings) eq 'HASH') {
3544: if (exists($settings->{'run'})) {
3545: if ($settings->{'run'} eq '0') {
3546: $runoff = ' checked="checked" ';
3547: $runon = ' ';
3548: } else {
3549: $runon = ' checked="checked" ';
3550: $runoff = ' ';
3551: }
3552: } else {
3553: if ($autorun) {
3554: $runon = ' checked="checked" ';
3555: $runoff = ' ';
3556: } else {
3557: $runoff = ' checked="checked" ';
3558: $runon = ' ';
3559: }
3560: }
1.129 raeburn 3561: if (exists($settings->{'co-owners'})) {
3562: if ($settings->{'co-owners'} eq '0') {
3563: $coownersoff = ' checked="checked" ';
3564: $coownerson = ' ';
3565: } else {
3566: $coownerson = ' checked="checked" ';
3567: $coownersoff = ' ';
3568: }
3569: } else {
3570: $coownersoff = ' checked="checked" ';
3571: $coownerson = ' ';
3572: }
1.3 raeburn 3573: if (exists($settings->{'sender_domain'})) {
3574: $defdom = $settings->{'sender_domain'};
3575: }
1.274 raeburn 3576: if (exists($settings->{'autofailsafe'})) {
3577: $failsafe = $settings->{'autofailsafe'};
3578: }
1.14 raeburn 3579: } else {
3580: if ($autorun) {
3581: $runon = ' checked="checked" ';
3582: $runoff = ' ';
3583: } else {
3584: $runoff = ' checked="checked" ';
3585: $runon = ' ';
3586: }
1.3 raeburn 3587: }
3588: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3589: my $notif_sender;
3590: if (ref($settings) eq 'HASH') {
3591: $notif_sender = $settings->{'sender_uname'};
3592: }
1.3 raeburn 3593: my $datatable='<tr class="LC_odd_row">'.
3594: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3595: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3596: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3597: $runon.' value="1" />'.&mt('Yes').'</label> '.
3598: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3599: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3600: '</tr><tr>'.
3601: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3602: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3603: &mt('username').': '.
3604: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3605: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3606: ': '.$domform.'</span></td></tr>'.
3607: '<tr class="LC_odd_row">'.
3608: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3609: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3610: '<input type="radio" name="autoassign_coowners"'.
3611: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3612: '<label><input type="radio" name="autoassign_coowners"'.
3613: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3614: '</tr><tr>'.
3615: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3616: '<td class="LC_right_item"><span class="LC_nobreak">'.
3617: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3618: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3619: $$rowtotal += 4;
1.3 raeburn 3620: return $datatable;
3621: }
3622:
3623: sub print_autoupdate {
1.30 raeburn 3624: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 3625: my ($enable,$datatable);
1.3 raeburn 3626: if ($position eq 'top') {
1.385 raeburn 3627: my %choices = &Apache::lonlocal::texthash (
3628: run => 'Auto-update active?',
3629: classlists => 'Update information in classlists?',
3630: unexpired => 'Skip updates for users without active or future roles?',
3631: lastactive => 'Skip updates for inactive users?',
3632: );
3633: my $itemcount = 0;
1.3 raeburn 3634: my $updateon = ' ';
3635: my $updateoff = ' checked="checked" ';
3636: if (ref($settings) eq 'HASH') {
3637: if ($settings->{'run'} eq '1') {
3638: $updateon = $updateoff;
3639: $updateoff = ' ';
3640: }
3641: }
1.385 raeburn 3642: $enable = '<tr class="LC_odd_row">'.
3643: '<td>'.$choices{'run'}.'</td>'.
3644: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3645: '<input type="radio" name="autoupdate_run"'.
1.385 raeburn 3646: $updateoff.' value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3647: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 3648: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3649: '</tr>';
1.385 raeburn 3650: my @toggles = ('classlists','unexpired');
3651: my %defaultchecked = ('classlists' => 'off',
3652: 'unexpired' => 'off'
3653: );
3654: $$rowtotal ++;
3655: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3656: \%choices,$itemcount,'','','left','no');
3657: $datatable = $enable.$datatable;
3658: $$rowtotal += $itemcount;
3659: my $lastactiveon = ' ';
3660: my $lastactiveoff = ' checked="checked" ';
3661: my $lastactivestyle = 'none';
3662: my $lastactivedays;
3663: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3664: if (ref($settings) eq 'HASH') {
3665: if ($settings->{'lastactive'} =~ /^\d+$/) {
3666: $lastactiveon = $lastactiveoff;
3667: $lastactiveoff = ' ';
3668: $lastactivestyle = 'inline-block';
3669: $lastactivedays = $settings->{'lastactive'};
3670: }
3671: }
3672: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3673: $datatable .= '<tr'.$css_class.'>'.
3674: '<td>'.$choices{'lastactive'}.'</td>'.
3675: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3676: '<input type="radio" name="lastactive"'.
3677: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3678: ' <label>'.
3679: '<input type="radio" name="lastactive"'.
3680: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3681: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3682: ': '.&mt('inactive = no activity in last [_1] days',
3683: '<input type="text" size="5" name="lastactivedays" value="'.
3684: $lastactivedays.'" />').
3685: '</span></td>'.
3686: '</tr>';
3687: $$rowtotal ++;
1.131 raeburn 3688: } elsif ($position eq 'middle') {
3689: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3690: my $numinrow = 3;
3691: my $locknamesettings;
3692: $datatable .= &insttypes_row($settings,$types,$usertypes,
3693: $dom,$numinrow,$othertitle,
1.305 raeburn 3694: 'lockablenames',$rowtotal);
1.131 raeburn 3695: $$rowtotal ++;
1.3 raeburn 3696: } else {
1.44 raeburn 3697: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3698: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3699: 'permanentemail','id');
1.33 raeburn 3700: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3701: my $numrows = 0;
1.26 raeburn 3702: if (ref($types) eq 'ARRAY') {
3703: if (@{$types} > 0) {
3704: $datatable =
3705: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3706: \@fields,$types,\$numrows);
1.30 raeburn 3707: $$rowtotal += @{$types};
1.26 raeburn 3708: }
1.3 raeburn 3709: }
3710: $datatable .=
3711: &usertype_update_row($settings,{'default' => $othertitle},
3712: \%fieldtitles,\@fields,['default'],
3713: \$numrows);
1.30 raeburn 3714: $$rowtotal ++;
1.3 raeburn 3715: }
3716: return $datatable;
3717: }
3718:
1.125 raeburn 3719: sub print_autocreate {
3720: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3721: my (%createon,%createoff,%currhash);
1.125 raeburn 3722: my @types = ('xml','req');
3723: if (ref($settings) eq 'HASH') {
3724: foreach my $item (@types) {
3725: $createoff{$item} = ' checked="checked" ';
3726: $createon{$item} = ' ';
3727: if (exists($settings->{$item})) {
3728: if ($settings->{$item}) {
3729: $createon{$item} = ' checked="checked" ';
3730: $createoff{$item} = ' ';
3731: }
3732: }
3733: }
1.210 raeburn 3734: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3735: $currhash{$settings->{'xmldc'}} = 1;
3736: }
1.125 raeburn 3737: } else {
3738: foreach my $item (@types) {
3739: $createoff{$item} = ' checked="checked" ';
3740: $createon{$item} = ' ';
3741: }
3742: }
3743: $$rowtotal += 2;
1.191 raeburn 3744: my $numinrow = 2;
1.125 raeburn 3745: my $datatable='<tr class="LC_odd_row">'.
3746: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3747: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3748: '<input type="radio" name="autocreate_xml"'.
3749: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3750: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3751: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3752: '</td></tr><tr>'.
3753: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3754: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3755: '<input type="radio" name="autocreate_req"'.
3756: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3757: '<label><input type="radio" name="autocreate_req"'.
3758: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3759: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3760: 'autocreate_xmldc',%currhash);
1.247 raeburn 3761: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3762: if ($numdc > 1) {
1.247 raeburn 3763: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3764: '</td><td class="LC_left_item">';
1.125 raeburn 3765: } else {
1.247 raeburn 3766: $datatable .= &mt('Course creation processed as:').
3767: '</td><td class="LC_right_item">';
1.125 raeburn 3768: }
1.247 raeburn 3769: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3770: $$rowtotal += $rows;
1.125 raeburn 3771: return $datatable;
3772: }
3773:
1.23 raeburn 3774: sub print_directorysrch {
1.277 raeburn 3775: my ($position,$dom,$settings,$rowtotal) = @_;
3776: my $datatable;
3777: if ($position eq 'top') {
3778: my $instsrchon = ' ';
3779: my $instsrchoff = ' checked="checked" ';
3780: my ($exacton,$containson,$beginson);
3781: my $instlocalon = ' ';
3782: my $instlocaloff = ' checked="checked" ';
3783: if (ref($settings) eq 'HASH') {
3784: if ($settings->{'available'} eq '1') {
3785: $instsrchon = $instsrchoff;
3786: $instsrchoff = ' ';
3787: }
3788: if ($settings->{'localonly'} eq '1') {
3789: $instlocalon = $instlocaloff;
3790: $instlocaloff = ' ';
3791: }
3792: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3793: foreach my $type (@{$settings->{'searchtypes'}}) {
3794: if ($type eq 'exact') {
3795: $exacton = ' checked="checked" ';
3796: } elsif ($type eq 'contains') {
3797: $containson = ' checked="checked" ';
3798: } elsif ($type eq 'begins') {
3799: $beginson = ' checked="checked" ';
3800: }
3801: }
3802: } else {
3803: if ($settings->{'searchtypes'} eq 'exact') {
3804: $exacton = ' checked="checked" ';
3805: } elsif ($settings->{'searchtypes'} eq 'contains') {
3806: $containson = ' checked="checked" ';
3807: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3808: $exacton = ' checked="checked" ';
3809: $containson = ' checked="checked" ';
3810: }
3811: }
1.277 raeburn 3812: }
3813: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3814: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3815:
3816: my $numinrow = 4;
3817: my $cansrchrow = 0;
3818: $datatable='<tr class="LC_odd_row">'.
3819: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3820: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3821: '<input type="radio" name="dirsrch_available"'.
3822: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3823: '<label><input type="radio" name="dirsrch_available"'.
3824: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3825: '</tr><tr>'.
3826: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3827: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3828: '<input type="radio" name="dirsrch_instlocalonly"'.
3829: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3830: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3831: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3832: '</tr>';
3833: $$rowtotal += 2;
3834: if (ref($usertypes) eq 'HASH') {
3835: if (keys(%{$usertypes}) > 0) {
3836: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3837: $numinrow,$othertitle,'cansearch',
3838: $rowtotal);
1.277 raeburn 3839: $cansrchrow = 1;
1.25 raeburn 3840: }
1.23 raeburn 3841: }
1.277 raeburn 3842: if ($cansrchrow) {
3843: $$rowtotal ++;
3844: $datatable .= '<tr>';
3845: } else {
3846: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3847: }
1.277 raeburn 3848: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3849: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3850: foreach my $title (@{$titleorder}) {
3851: if (defined($searchtitles->{$title})) {
3852: my $check = ' ';
3853: if (ref($settings) eq 'HASH') {
3854: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3855: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3856: $check = ' checked="checked" ';
3857: }
1.39 raeburn 3858: }
1.25 raeburn 3859: }
1.277 raeburn 3860: $datatable .= '<td class="LC_left_item">'.
3861: '<span class="LC_nobreak"><label>'.
3862: '<input type="checkbox" name="searchby" '.
3863: 'value="'.$title.'"'.$check.'/>'.
3864: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3865: }
3866: }
1.277 raeburn 3867: $datatable .= '</tr></table></td></tr>';
3868: $$rowtotal ++;
3869: if ($cansrchrow) {
3870: $datatable .= '<tr class="LC_odd_row">';
3871: } else {
3872: $datatable .= '<tr>';
3873: }
3874: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3875: '<td class="LC_left_item" colspan="2">'.
3876: '<span class="LC_nobreak"><label>'.
3877: '<input type="checkbox" name="searchtypes" '.
3878: $exacton.' value="exact" />'.&mt('Exact match').
3879: '</label> '.
3880: '<label><input type="checkbox" name="searchtypes" '.
3881: $beginson.' value="begins" />'.&mt('Begins with').
3882: '</label> '.
3883: '<label><input type="checkbox" name="searchtypes" '.
3884: $containson.' value="contains" />'.&mt('Contains').
3885: '</label></span></td></tr>';
3886: $$rowtotal ++;
1.26 raeburn 3887: } else {
1.277 raeburn 3888: my $domsrchon = ' checked="checked" ';
3889: my $domsrchoff = ' ';
3890: my $domlocalon = ' ';
3891: my $domlocaloff = ' checked="checked" ';
3892: if (ref($settings) eq 'HASH') {
3893: if ($settings->{'lclocalonly'} eq '1') {
3894: $domlocalon = $domlocaloff;
3895: $domlocaloff = ' ';
3896: }
3897: if ($settings->{'lcavailable'} eq '0') {
3898: $domsrchoff = $domsrchon;
3899: $domsrchon = ' ';
3900: }
3901: }
3902: $datatable='<tr class="LC_odd_row">'.
3903: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3904: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3905: '<input type="radio" name="dirsrch_domavailable"'.
3906: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3907: '<label><input type="radio" name="dirsrch_domavailable"'.
3908: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3909: '</tr><tr>'.
3910: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3911: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3912: '<input type="radio" name="dirsrch_domlocalonly"'.
3913: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3914: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3915: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3916: '</tr>';
3917: $$rowtotal += 2;
1.26 raeburn 3918: }
1.25 raeburn 3919: return $datatable;
3920: }
3921:
1.28 raeburn 3922: sub print_contacts {
1.286 raeburn 3923: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3924: my $datatable;
3925: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3926: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3927: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3928: if ($position eq 'top') {
3929: if (ref($settings) eq 'HASH') {
3930: foreach my $item (@contacts) {
3931: if (exists($settings->{$item})) {
3932: $to{$item} = $settings->{$item};
3933: }
3934: }
3935: }
3936: } elsif ($position eq 'middle') {
3937: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3938: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3939: foreach my $type (@mailings) {
3940: $otheremails{$type} = '';
3941: }
1.340 raeburn 3942: } elsif ($position eq 'lower') {
3943: if (ref($settings) eq 'HASH') {
3944: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3945: %lonstatus = %{$settings->{'lonstatus'}};
3946: }
3947: }
1.286 raeburn 3948: } else {
3949: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3950: foreach my $type (@mailings) {
3951: $otheremails{$type} = '';
3952: }
1.286 raeburn 3953: $bccemails{'helpdeskmail'} = '';
3954: $bccemails{'otherdomsmail'} = '';
3955: $includestr{'helpdeskmail'} = '';
3956: $includestr{'otherdomsmail'} = '';
3957: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3958: }
1.28 raeburn 3959: if (ref($settings) eq 'HASH') {
1.340 raeburn 3960: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3961: foreach my $type (@mailings) {
3962: if (exists($settings->{$type})) {
3963: if (ref($settings->{$type}) eq 'HASH') {
3964: foreach my $item (@contacts) {
3965: if ($settings->{$type}{$item}) {
3966: $checked{$type}{$item} = ' checked="checked" ';
3967: }
3968: }
3969: $otheremails{$type} = $settings->{$type}{'others'};
3970: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3971: $bccemails{$type} = $settings->{$type}{'bcc'};
3972: if ($settings->{$type}{'include'} ne '') {
3973: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3974: $includestr{$type} = &unescape($includestr{$type});
3975: }
3976: }
3977: }
3978: } elsif ($type eq 'lonstatusmail') {
3979: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3980: }
1.28 raeburn 3981: }
3982: }
1.286 raeburn 3983: if ($position eq 'bottom') {
3984: foreach my $type (@mailings) {
3985: $bccemails{$type} = $settings->{$type}{'bcc'};
3986: if ($settings->{$type}{'include'} ne '') {
3987: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3988: $includestr{$type} = &unescape($includestr{$type});
3989: }
3990: }
3991: if (ref($settings->{'helpform'}) eq 'HASH') {
3992: if (ref($fields) eq 'ARRAY') {
3993: foreach my $field (@{$fields}) {
3994: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3995: }
1.286 raeburn 3996: }
3997: if (exists($settings->{'helpform'}{'maxsize'})) {
3998: $maxsize = $settings->{'helpform'}{'maxsize'};
3999: } else {
1.289 raeburn 4000: $maxsize = '1.0';
1.286 raeburn 4001: }
4002: } else {
4003: if (ref($fields) eq 'ARRAY') {
4004: foreach my $field (@{$fields}) {
4005: $currfield{$field} = 'yes';
1.134 raeburn 4006: }
1.28 raeburn 4007: }
1.286 raeburn 4008: $maxsize = '1.0';
1.28 raeburn 4009: }
4010: }
4011: } else {
1.286 raeburn 4012: if ($position eq 'top') {
4013: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4014: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4015: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4016: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4017: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4018: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4019: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4020: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4021: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4022: } elsif ($position eq 'bottom') {
4023: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4024: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4025: if (ref($fields) eq 'ARRAY') {
4026: foreach my $field (@{$fields}) {
4027: $currfield{$field} = 'yes';
4028: }
4029: }
4030: $maxsize = '1.0';
4031: }
1.28 raeburn 4032: }
4033: my ($titles,$short_titles) = &contact_titles();
4034: my $rownum = 0;
4035: my $css_class;
1.286 raeburn 4036: if ($position eq 'top') {
4037: foreach my $item (@contacts) {
4038: $css_class = $rownum%2?' class="LC_odd_row"':'';
4039: $datatable .= '<tr'.$css_class.'>'.
4040: '<td><span class="LC_nobreak">'.$titles->{$item}.
4041: '</span></td><td class="LC_right_item">'.
4042: '<input type="text" name="'.$item.'" value="'.
4043: $to{$item}.'" /></td></tr>';
4044: $rownum ++;
4045: }
1.315 raeburn 4046: } elsif ($position eq 'bottom') {
4047: $css_class = $rownum%2?' class="LC_odd_row"':'';
4048: $datatable .= '<tr'.$css_class.'>'.
4049: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4050: &mt('(e-mail, subject, and description always shown)').
4051: '</td><td class="LC_left_item">';
4052: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4053: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4054: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4055: foreach my $field (@{$fields}) {
4056: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4057: if (($field eq 'screenshot') || ($field eq 'cc')) {
4058: $datatable .= ' '.&mt('(logged-in users)');
4059: }
4060: $datatable .='</td><td>';
4061: my $clickaction;
4062: if ($field eq 'screenshot') {
4063: $clickaction = ' onclick="screenshotSize(this);"';
4064: }
4065: if (ref($possoptions->{$field}) eq 'ARRAY') {
4066: foreach my $option (@{$possoptions->{$field}}) {
4067: my $checked;
4068: if ($currfield{$field} eq $option) {
4069: $checked = ' checked="checked"';
4070: }
4071: $datatable .= '<span class="LC_nobreak"><label>'.
4072: '<input type="radio" name="helpform_'.$field.'" '.
4073: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4074: '</label></span>'.(' 'x2);
4075: }
4076: }
4077: if ($field eq 'screenshot') {
4078: my $display;
4079: if ($currfield{$field} eq 'no') {
4080: $display = ' style="display:none"';
4081: }
1.334 raeburn 4082: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4083: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4084: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4085: }
4086: $datatable .= '</td></tr>';
4087: }
4088: $datatable .= '</table>';
4089: }
4090: $datatable .= '</td></tr>'."\n";
4091: $rownum ++;
4092: }
1.340 raeburn 4093: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4094: foreach my $type (@mailings) {
4095: $css_class = $rownum%2?' class="LC_odd_row"':'';
4096: $datatable .= '<tr'.$css_class.'>'.
4097: '<td><span class="LC_nobreak">'.
4098: $titles->{$type}.': </span></td>'.
4099: '<td class="LC_left_item">';
4100: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4101: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4102: }
4103: $datatable .= '<span class="LC_nobreak">';
4104: foreach my $item (@contacts) {
4105: $datatable .= '<label>'.
4106: '<input type="checkbox" name="'.$type.'"'.
4107: $checked{$type}{$item}.
4108: ' value="'.$item.'" />'.$short_titles->{$item}.
4109: '</label> ';
4110: }
4111: $datatable .= '</span><br />'.&mt('Others').': '.
4112: '<input type="text" name="'.$type.'_others" '.
4113: 'value="'.$otheremails{$type}.'" />';
4114: my %locchecked;
4115: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4116: foreach my $loc ('s','b') {
4117: if ($includeloc{$type} eq $loc) {
4118: $locchecked{$loc} = ' checked="checked"';
4119: last;
4120: }
4121: }
4122: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4123: '<input type="text" name="'.$type.'_bcc" '.
4124: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4125: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4126: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4127: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4128: '<span class="LC_nobreak">'.&mt('Location:').' '.
4129: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4130: (' 'x2).
4131: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4132: '</span></fieldset>';
4133: }
4134: $datatable .= '</td></tr>'."\n";
4135: $rownum ++;
4136: }
1.28 raeburn 4137: }
1.286 raeburn 4138: if ($position eq 'middle') {
4139: my %choices;
1.340 raeburn 4140: my $corelink = &core_link_msu();
4141: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4142: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4143: $corelink);
4144: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4145: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4146: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4147: 'reportupdates' => 'on',
4148: 'reportstatus' => 'on');
1.286 raeburn 4149: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4150: \%choices,$rownum);
4151: $datatable .= $reports;
1.340 raeburn 4152: } elsif ($position eq 'lower') {
1.378 raeburn 4153: my (%current,%excluded,%weights);
1.340 raeburn 4154: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4155: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4156: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4157: } else {
1.378 raeburn 4158: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4159: }
4160: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4161: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4162: } else {
1.378 raeburn 4163: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4164: }
4165: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4166: foreach my $type ('E','W','N','U') {
1.340 raeburn 4167: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4168: $weights{$type} = $lonstatus{'weights'}{$type};
4169: } else {
4170: $weights{$type} = $defaults->{$type};
4171: }
4172: }
4173: } else {
1.341 raeburn 4174: foreach my $type ('E','W','N','U') {
1.340 raeburn 4175: $weights{$type} = $defaults->{$type};
4176: }
4177: }
4178: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4179: if (@{$lonstatus{'excluded'}} > 0) {
4180: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4181: }
4182: }
1.378 raeburn 4183: foreach my $item ('errorthreshold','errorsysmail') {
4184: $css_class = $rownum%2?' class="LC_odd_row"':'';
4185: $datatable .= '<tr'.$css_class.'>'.
4186: '<td class="LC_left_item"><span class="LC_nobreak">'.
4187: $titles->{$item}.
4188: '</span></td><td class="LC_left_item">'.
4189: '<input type="text" name="'.$item.'" value="'.
4190: $current{$item}.'" size="5" /></td></tr>';
4191: $rownum ++;
4192: }
1.340 raeburn 4193: $css_class = $rownum%2?' class="LC_odd_row"':'';
4194: $datatable .= '<tr'.$css_class.'>'.
4195: '<td class="LC_left_item">'.
4196: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4197: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4198: foreach my $type ('E','W','N','U') {
1.340 raeburn 4199: $datatable .= '<td>'.$names->{$type}.'<br />'.
4200: '<input type="text" name="errorweights_'.$type.'" value="'.
4201: $weights{$type}.'" size="5" /></td>';
4202: }
4203: $datatable .= '</tr></table></tr>';
4204: $rownum ++;
4205: $css_class = $rownum%2?' class="LC_odd_row"':'';
4206: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4207: $titles->{'errorexcluded'}.'</td>'.
4208: '<td class="LC_left_item"><table>';
4209: my $numinrow = 4;
4210: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4211: for (my $i=0; $i<@ids; $i++) {
4212: my $rem = $i%($numinrow);
4213: if ($rem == 0) {
4214: if ($i > 0) {
4215: $datatable .= '</tr>';
4216: }
4217: $datatable .= '<tr>';
4218: }
4219: my $check;
4220: if ($excluded{$ids[$i]}) {
4221: $check = ' checked="checked" ';
4222: }
4223: $datatable .= '<td class="LC_left_item">'.
4224: '<span class="LC_nobreak"><label>'.
4225: '<input type="checkbox" name="errorexcluded" '.
4226: 'value="'.$ids[$i].'"'.$check.' />'.
4227: $ids[$i].'</label></span></td>';
4228: }
4229: my $colsleft = $numinrow - @ids%($numinrow);
4230: if ($colsleft > 1 ) {
4231: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4232: ' </td>';
4233: } elsif ($colsleft == 1) {
4234: $datatable .= '<td class="LC_left_item"> </td>';
4235: }
4236: $datatable .= '</tr></table></td></tr>';
4237: $rownum ++;
1.286 raeburn 4238: } elsif ($position eq 'bottom') {
1.315 raeburn 4239: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4240: my (@posstypes,%usertypeshash);
4241: if (ref($types) eq 'ARRAY') {
4242: @posstypes = @{$types};
4243: }
4244: if (@posstypes) {
4245: if (ref($usertypes) eq 'HASH') {
4246: %usertypeshash = %{$usertypes};
4247: }
4248: my @overridden;
4249: my $numinrow = 4;
4250: if (ref($settings) eq 'HASH') {
4251: if (ref($settings->{'overrides'}) eq 'HASH') {
4252: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4253: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4254: push(@overridden,$key);
4255: foreach my $item (@contacts) {
4256: if ($settings->{'overrides'}{$key}{$item}) {
4257: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4258: }
4259: }
4260: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4261: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4262: $includeloc{'override_'.$key} = '';
4263: $includestr{'override_'.$key} = '';
4264: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4265: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4266: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4267: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4268: }
1.286 raeburn 4269: }
4270: }
4271: }
1.315 raeburn 4272: }
4273: my $customclass = 'LC_helpdesk_override';
4274: my $optionsprefix = 'LC_options_helpdesk_';
4275:
4276: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4277:
4278: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4279: $numinrow,$othertitle,'overrides',
4280: \$rownum,$onclicktypes,$customclass);
4281: $rownum ++;
4282: $usertypeshash{'default'} = $othertitle;
4283: foreach my $status (@posstypes) {
4284: my $css_class;
4285: if ($rownum%2) {
4286: $css_class = 'LC_odd_row ';
4287: }
4288: $css_class .= $customclass;
4289: my $rowid = $optionsprefix.$status;
4290: my $hidden = 1;
4291: my $currstyle = 'display:none';
4292: if (grep(/^\Q$status\E$/,@overridden)) {
4293: $currstyle = 'display:table-row';
4294: $hidden = 0;
4295: }
4296: my $key = 'override_'.$status;
4297: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4298: $includeloc{$key},$includestr{$key},$status,$rowid,
4299: $usertypeshash{$status},$css_class,$currstyle,
4300: \@contacts,$short_titles);
4301: unless ($hidden) {
4302: $rownum ++;
1.286 raeburn 4303: }
4304: }
1.134 raeburn 4305: }
1.28 raeburn 4306: }
1.30 raeburn 4307: $$rowtotal += $rownum;
1.28 raeburn 4308: return $datatable;
4309: }
4310:
1.340 raeburn 4311: sub core_link_msu {
4312: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4313: &mt('LON-CAPA core group - MSU'),600,500);
4314: }
4315:
1.315 raeburn 4316: sub overridden_helpdesk {
4317: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4318: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4319: my $class = 'LC_left_item';
4320: if ($css_class) {
4321: $css_class = ' class="'.$css_class.'"';
4322: }
4323: if ($rowid) {
4324: $rowid = ' id="'.$rowid.'"';
4325: }
4326: if ($rowstyle) {
4327: $rowstyle = ' style="'.$rowstyle.'"';
4328: }
4329: my ($output,$description);
4330: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4331: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4332: "<td>$description</td>\n".
4333: '<td class="'.$class.'" colspan="2">'.
4334: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4335: '<span class="LC_nobreak">';
4336: if (ref($contacts) eq 'ARRAY') {
4337: foreach my $item (@{$contacts}) {
4338: my $check;
4339: if (ref($checked) eq 'HASH') {
4340: $check = $checked->{$item};
4341: }
4342: my $title;
4343: if (ref($short_titles) eq 'HASH') {
4344: $title = $short_titles->{$item};
4345: }
4346: $output .= '<label>'.
4347: '<input type="checkbox" name="override_'.$type.'"'.$check.
4348: ' value="'.$item.'" />'.$title.'</label> ';
4349: }
4350: }
4351: $output .= '</span><br />'.&mt('Others').': '.
4352: '<input type="text" name="override_'.$type.'_others" '.
4353: 'value="'.$otheremails.'" />';
4354: my %locchecked;
4355: foreach my $loc ('s','b') {
4356: if ($includeloc eq $loc) {
4357: $locchecked{$loc} = ' checked="checked"';
4358: last;
4359: }
4360: }
4361: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4362: '<input type="text" name="override_'.$type.'_bcc" '.
4363: 'value="'.$bccemails.'" /></fieldset>'.
4364: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4365: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4366: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4367: '<span class="LC_nobreak">'.&mt('Location:').' '.
4368: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4369: (' 'x2).
4370: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4371: '</span></fieldset>'.
4372: '</td></tr>'."\n";
4373: return $output;
4374: }
4375:
1.286 raeburn 4376: sub contacts_javascript {
4377: return <<"ENDSCRIPT";
4378:
4379: <script type="text/javascript">
4380: // <![CDATA[
4381:
4382: function screenshotSize(field) {
4383: if (document.getElementById('help_screenshotsize')) {
4384: if (field.value == 'no') {
1.289 raeburn 4385: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4386: } else {
4387: document.getElementById('help_screenshotsize').style.display="";
4388: }
4389: }
4390: return;
4391: }
4392:
1.315 raeburn 4393: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4394: if (form.elements[checkbox].length != undefined) {
4395: var count = 0;
4396: if (docount) {
4397: for (var i=0; i<form.elements[checkbox].length; i++) {
4398: if (form.elements[checkbox][i].checked) {
4399: count ++;
4400: }
4401: }
4402: }
4403: for (var i=0; i<form.elements[checkbox].length; i++) {
4404: var type = form.elements[checkbox][i].value;
4405: if (document.getElementById(prefix+type)) {
4406: if (form.elements[checkbox][i].checked) {
4407: document.getElementById(prefix+type).style.display = 'table-row';
4408: if (count % 2 == 1) {
4409: document.getElementById(prefix+type).className = target+' LC_odd_row';
4410: } else {
4411: document.getElementById(prefix+type).className = target;
4412: }
4413: count ++;
4414: } else {
4415: document.getElementById(prefix+type).style.display = 'none';
4416: }
4417: }
4418: }
4419: }
4420: return;
4421: }
4422:
4423:
1.286 raeburn 4424: // ]]>
4425: </script>
4426:
4427: ENDSCRIPT
4428: }
4429:
1.118 jms 4430: sub print_helpsettings {
1.282 raeburn 4431: my ($position,$dom,$settings,$rowtotal) = @_;
4432: my $confname = $dom.'-domainconfig';
1.285 raeburn 4433: my $formname = 'display';
1.168 raeburn 4434: my ($datatable,$itemcount);
1.282 raeburn 4435: if ($position eq 'top') {
4436: $itemcount = 1;
4437: my (%choices,%defaultchecked,@toggles);
4438: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4439: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4440: &mt('LON-CAPA bug tracker'),600,500));
4441: %defaultchecked = ('submitbugs' => 'on');
4442: @toggles = ('submitbugs');
4443: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4444: \%choices,$itemcount);
4445: $$rowtotal ++;
4446: } else {
4447: my $css_class;
4448: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4449: my (%customroles,%ordered,%current);
1.301 raeburn 4450: if (ref($settings) eq 'HASH') {
4451: if (ref($settings->{'adhoc'}) eq 'HASH') {
4452: %current = %{$settings->{'adhoc'}};
4453: }
1.285 raeburn 4454: }
4455: my $count = 0;
4456: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4457: if ($key=~/^rolesdef\_(\w+)$/) {
4458: my $rolename = $1;
1.285 raeburn 4459: my (%privs,$order);
1.282 raeburn 4460: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4461: $customroles{$rolename} = \%privs;
1.285 raeburn 4462: if (ref($current{$rolename}) eq 'HASH') {
4463: $order = $current{$rolename}{'order'};
4464: }
4465: if ($order eq '') {
4466: $order = $count;
4467: }
4468: $ordered{$order} = $rolename;
4469: $count++;
4470: }
4471: }
4472: my $maxnum = scalar(keys(%ordered));
4473: my @roles_by_num = ();
4474: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4475: push(@roles_by_num,$item);
4476: }
4477: my $context = 'domprefs';
4478: my $crstype = 'Course';
4479: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4480: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4481: my ($numstatustypes,@jsarray);
4482: if (ref($types) eq 'ARRAY') {
4483: if (@{$types} > 0) {
4484: $numstatustypes = scalar(@{$types});
4485: push(@accesstypes,'status');
4486: @jsarray = ('bystatus');
1.282 raeburn 4487: }
4488: }
1.290 raeburn 4489: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4490: if (keys(%domhelpdesk)) {
4491: push(@accesstypes,('inc','exc'));
4492: push(@jsarray,('notinc','notexc'));
4493: }
4494: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4495: my $context = 'domprefs';
4496: my $crstype = 'Course';
1.285 raeburn 4497: my $prefix = 'helproles_';
4498: my $add_class = 'LC_hidden';
4499: foreach my $num (@roles_by_num) {
4500: my $role = $ordered{$num};
4501: my ($desc,$access,@statuses);
4502: if (ref($current{$role}) eq 'HASH') {
4503: $desc = $current{$role}{'desc'};
4504: $access = $current{$role}{'access'};
4505: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4506: @statuses = @{$current{$role}{'insttypes'}};
4507: }
4508: }
4509: if ($desc eq '') {
4510: $desc = $role;
4511: }
4512: my $identifier = 'custhelp'.$num;
1.282 raeburn 4513: my %full=();
4514: my %levels= (
4515: course => {},
4516: domain => {},
4517: system => {},
4518: );
4519: my %levelscurrent=(
4520: course => {},
4521: domain => {},
4522: system => {},
4523: );
4524: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4525: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4527: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4528: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4529: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4530: for (my $k=0; $k<=$maxnum; $k++) {
4531: my $vpos = $k+1;
4532: my $selstr;
4533: if ($k == $num) {
4534: $selstr = ' selected="selected" ';
4535: }
4536: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4537: }
4538: $datatable .= '</select>'.(' 'x2).
4539: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4540: '</td>'.
4541: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4542: &mt('Name shown to users:').
4543: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4544: '</fieldset>'.
4545: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4546: $othertitle,$usertypes,$types,\%domhelpdesk).
4547: '<fieldset>'.
4548: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4549: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4550: \%levelscurrent,$identifier,
4551: 'LC_hidden',$prefix.$num.'_privs').
4552: '</fieldset></td>';
1.282 raeburn 4553: $itemcount ++;
4554: }
4555: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4556: my $newcust = 'custhelp'.$count;
4557: my (%privs,%levelscurrent);
4558: my %full=();
4559: my %levels= (
4560: course => {},
4561: domain => {},
4562: system => {},
4563: );
4564: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4565: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4566: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4567: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4568: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4569: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4570: for (my $k=0; $k<$maxnum+1; $k++) {
4571: my $vpos = $k+1;
4572: my $selstr;
4573: if ($k == $maxnum) {
4574: $selstr = ' selected="selected" ';
4575: }
4576: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4577: }
4578: $datatable .= '</select> '."\n".
1.282 raeburn 4579: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4580: '</label></span></td>'.
1.285 raeburn 4581: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4582: '<span class="LC_nobreak">'.
4583: &mt('Internal name:').
4584: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4585: '</span>'.(' 'x4).
4586: '<span class="LC_nobreak">'.
4587: &mt('Name shown to users:').
4588: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4589: '</span></fieldset>'.
4590: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4591: $usertypes,$types,\%domhelpdesk).
4592: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4593: &Apache::lonuserutils::custom_role_header($context,$crstype,
4594: \@templateroles,$newcust).
4595: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4596: \%levelscurrent,$newcust).
1.334 raeburn 4597: '</fieldset>'.
4598: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4599: '</td></tr>';
1.282 raeburn 4600: $count ++;
4601: $$rowtotal += $count;
4602: }
1.166 raeburn 4603: return $datatable;
1.121 raeburn 4604: }
4605:
1.285 raeburn 4606: sub adhocbutton {
4607: my ($prefix,$num,$field,$visibility) = @_;
4608: my %lt = &Apache::lonlocal::texthash(
4609: show => 'Show details',
4610: hide => 'Hide details',
4611: );
4612: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4613: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4614: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4615: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4616: }
4617:
4618: sub helpsettings_javascript {
4619: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4620: return unless(ref($roles_by_num) eq 'ARRAY');
4621: my %html_js_lt = &Apache::lonlocal::texthash(
4622: show => 'Show details',
4623: hide => 'Hide details',
4624: );
4625: &html_escape(\%html_js_lt);
4626: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4627: return <<"ENDSCRIPT";
4628: <script type="text/javascript">
4629: // <![CDATA[
4630:
4631: function reorderHelpRoles(form,item) {
4632: var changedVal;
4633: $jstext
4634: var newpos = 'helproles_${total}_pos';
4635: var maxh = 1 + $total;
4636: var current = new Array();
4637: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4638: if (item == newpos) {
4639: changedVal = newitemVal;
4640: } else {
4641: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4642: current[newitemVal] = newpos;
4643: }
4644: for (var i=0; i<helproles.length; i++) {
4645: var elementName = 'helproles_'+helproles[i]+'_pos';
4646: if (elementName != item) {
4647: if (form.elements[elementName]) {
4648: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4649: current[currVal] = elementName;
4650: }
4651: }
4652: }
4653: var oldVal;
4654: for (var j=0; j<maxh; j++) {
4655: if (current[j] == undefined) {
4656: oldVal = j;
4657: }
4658: }
4659: if (oldVal < changedVal) {
4660: for (var k=oldVal+1; k<=changedVal ; k++) {
4661: var elementName = current[k];
4662: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4663: }
4664: } else {
4665: for (var k=changedVal; k<oldVal; k++) {
4666: var elementName = current[k];
4667: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4668: }
4669: }
4670: return;
4671: }
4672:
4673: function helpdeskAccess(num) {
4674: var curraccess = null;
4675: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4676: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4677: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4678: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4679: }
4680: }
4681: }
4682: var shown = Array();
4683: var hidden = Array();
4684: if (curraccess == 'none') {
4685: hidden = Array('$hiddenstr');
4686: } else {
4687: if (curraccess == 'status') {
4688: shown = Array('bystatus');
4689: hidden = Array('notinc','notexc');
4690: } else {
4691: if (curraccess == 'exc') {
4692: shown = Array('notexc');
4693: hidden = Array('notinc','bystatus');
4694: }
4695: if (curraccess == 'inc') {
4696: shown = Array('notinc');
4697: hidden = Array('notexc','bystatus');
4698: }
1.293 raeburn 4699: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4700: hidden = Array('notinc','notexc','bystatus');
4701: }
4702: }
4703: }
4704: if (hidden.length > 0) {
4705: for (var i=0; i<hidden.length; i++) {
4706: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4707: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4708: }
4709: }
4710: }
4711: if (shown.length > 0) {
4712: for (var i=0; i<shown.length; i++) {
4713: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4714: if (shown[i] == 'privs') {
4715: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4716: } else {
4717: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4718: }
4719: }
4720: }
4721: }
4722: return;
4723: }
4724:
4725: function toggleHelpdeskItem(num,field) {
4726: if (document.getElementById('helproles_'+num+'_'+field)) {
4727: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4728: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4729: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4730: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4731: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4732: }
4733: } else {
4734: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4735: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4736: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4737: }
4738: }
4739: }
4740: return;
4741: }
4742:
4743: // ]]>
4744: </script>
4745:
4746: ENDSCRIPT
4747: }
4748:
4749: sub helpdeskroles_access {
4750: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4751: $usertypes,$types,$domhelpdesk) = @_;
4752: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4753: my %lt = &Apache::lonlocal::texthash(
4754: 'rou' => 'Role usage',
4755: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4756: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4757: 'dh' => 'All with domain helpdesk role',
4758: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4759: 'none' => 'None',
4760: 'status' => 'Determined based on institutional status',
4761: 'inc' => 'Include all, but exclude specific personnel',
4762: 'exc' => 'Exclude all, but include specific personnel',
4763: );
4764: my %usecheck = (
4765: all => ' checked="checked"',
4766: );
4767: my %displaydiv = (
4768: status => 'none',
4769: inc => 'none',
4770: exc => 'none',
4771: priv => 'block',
4772: );
4773: my $output;
4774: if (ref($current) eq 'HASH') {
4775: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4776: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4777: $usecheck{$current->{access}} = $usecheck{'all'};
4778: delete($usecheck{'all'});
4779: if ($current->{access} =~ /^(status|inc|exc)$/) {
4780: my $access = $1;
4781: $displaydiv{$access} = 'inline';
4782: } elsif ($current->{access} eq 'none') {
4783: $displaydiv{'priv'} = 'none';
4784: }
4785: }
4786: }
4787: }
4788: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4789: '<p>'.$lt{'whi'}.'</p>';
4790: foreach my $access (@{$accesstypes}) {
4791: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4792: ' onclick="helpdeskAccess('."'$num'".');" />'.
4793: $lt{$access}.'</label>';
4794: if ($access eq 'status') {
4795: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4796: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4797: $othertitle,$usertypes,$types).
4798: '</div>';
4799: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4800: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4801: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4802: '</div>';
4803: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4804: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4805: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4806: '</div>';
4807: }
4808: $output .= '</p>';
4809: }
4810: $output .= '</fieldset>';
4811: return $output;
4812: }
4813:
1.121 raeburn 4814: sub radiobutton_prefs {
1.192 raeburn 4815: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 4816: $additional,$align,$firstval) = @_;
1.121 raeburn 4817: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4818: (ref($choices) eq 'HASH'));
4819:
1.170 raeburn 4820: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4821:
4822: foreach my $item (@{$toggles}) {
4823: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4824: $checkedon{$item} = ' checked="checked" ';
4825: $checkedoff{$item} = ' ';
1.121 raeburn 4826: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4827: $checkedoff{$item} = ' checked="checked" ';
4828: $checkedon{$item} = ' ';
4829: }
4830: }
4831: if (ref($settings) eq 'HASH') {
1.121 raeburn 4832: foreach my $item (@{$toggles}) {
1.118 jms 4833: if ($settings->{$item} eq '1') {
4834: $checkedon{$item} = ' checked="checked" ';
4835: $checkedoff{$item} = ' ';
4836: } elsif ($settings->{$item} eq '0') {
4837: $checkedoff{$item} = ' checked="checked" ';
4838: $checkedon{$item} = ' ';
4839: }
4840: }
1.121 raeburn 4841: }
1.192 raeburn 4842: if ($onclick) {
4843: $onclick = ' onclick="'.$onclick.'"';
4844: }
1.121 raeburn 4845: foreach my $item (@{$toggles}) {
1.118 jms 4846: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4847: $datatable .=
1.306 raeburn 4848: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4849: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4850: '</span></td>';
4851: if ($align eq 'left') {
4852: $datatable .= '<td class="LC_left_item">';
4853: } else {
4854: $datatable .= '<td class="LC_right_item">';
4855: }
1.385 raeburn 4856: $datatable .= '<span class="LC_nobreak">';
4857: if ($firstval eq 'no') {
4858: $datatable .=
4859: '<label><input type="radio" name="'.
4860: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4861: '</label> <label><input type="radio" name="'.$item.'" '.
4862: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4863: } else {
4864: $datatable .=
4865: '<label><input type="radio" name="'.
4866: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
4867: '</label> <label><input type="radio" name="'.$item.'" '.
4868: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4869: }
4870: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4871: $itemcount ++;
1.121 raeburn 4872: }
4873: return ($datatable,$itemcount);
4874: }
4875:
1.267 raeburn 4876: sub print_ltitools {
4877: my ($dom,$settings,$rowtotal) = @_;
4878: my $rownum = 0;
4879: my $css_class;
4880: my $itemcount = 1;
4881: my $maxnum = 0;
4882: my %ordered;
4883: if (ref($settings) eq 'HASH') {
4884: foreach my $item (keys(%{$settings})) {
4885: if (ref($settings->{$item}) eq 'HASH') {
4886: my $num = $settings->{$item}{'order'};
4887: $ordered{$num} = $item;
4888: }
4889: }
4890: }
4891: my $confname = $dom.'-domainconfig';
4892: my $switchserver = &check_switchserver($dom,$confname);
4893: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4894: my $datatable;
1.267 raeburn 4895: my %lt = <itools_names();
4896: my @courseroles = ('cc','in','ta','ep','st');
4897: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4898: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4899: if (keys(%ordered)) {
4900: my @items = sort { $a <=> $b } keys(%ordered);
4901: for (my $i=0; $i<@items; $i++) {
4902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4903: my $item = $ordered{$items[$i]};
1.323 raeburn 4904: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4905: if (ref($settings->{$item}) eq 'HASH') {
4906: $title = $settings->{$item}->{'title'};
4907: $url = $settings->{$item}->{'url'};
4908: $key = $settings->{$item}->{'key'};
4909: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4910: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4911: my $image = $settings->{$item}->{'image'};
4912: if ($image ne '') {
4913: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4914: }
1.323 raeburn 4915: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4916: $sigsel{'HMAC-256'} = ' selected="selected"';
4917: } else {
4918: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4919: }
1.267 raeburn 4920: }
1.319 raeburn 4921: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4922: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4923: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4924: for (my $k=0; $k<=$maxnum; $k++) {
4925: my $vpos = $k+1;
4926: my $selstr;
4927: if ($k == $i) {
4928: $selstr = ' selected="selected" ';
4929: }
4930: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4931: }
4932: $datatable .= '</select>'.(' 'x2).
4933: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4934: &mt('Delete?').'</label></span></td>'.
4935: '<td colspan="2">'.
4936: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4937: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4938: (' 'x2).
4939: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4940: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4941: (' 'x2).
4942: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4943: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4944: (' 'x2).
4945: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4946: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4947: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4948: '<br /><br />'.
1.323 raeburn 4949: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4950: ' value="'.$url.'" /></span>'.
4951: (' 'x2).
1.319 raeburn 4952: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4953: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4954: (' 'x2).
1.322 raeburn 4955: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4956: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4957: (' 'x2).
1.267 raeburn 4958: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4959: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4960: '<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>'.
4961: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4962: '</fieldset>'.
4963: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4964: '<span class="LC_nobreak">'.&mt('Display target:');
4965: my %currdisp;
4966: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4967: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4968: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4969: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4970: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4971: } else {
4972: $currdisp{'iframe'} = ' checked="checked"';
4973: }
4974: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4975: $currdisp{'width'} = $1;
4976: }
4977: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4978: $currdisp{'height'} = $1;
4979: }
1.296 raeburn 4980: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4981: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4982: } else {
4983: $currdisp{'iframe'} = ' checked="checked"';
4984: }
1.298 raeburn 4985: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4986: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4987: $lt{$disp}.'</label>'.(' 'x2);
4988: }
4989: $datatable .= (' 'x4);
4990: foreach my $dimen ('width','height') {
4991: $datatable .= '<label>'.$lt{$dimen}.' '.
4992: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4993: (' 'x2);
4994: }
1.334 raeburn 4995: $datatable .= '</span><br />'.
1.296 raeburn 4996: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4997: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4998: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4999: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5000: '</textarea></div><div style=""></div><br />';
1.319 raeburn 5001: my %units = (
5002: 'passback' => 'days',
5003: 'roster' => 'seconds',
5004: );
1.267 raeburn 5005: foreach my $extra ('passback','roster') {
1.319 raeburn 5006: my $validsty = 'none';
5007: my $currvalid;
1.267 raeburn 5008: my $checkedon = '';
5009: my $checkedoff = ' checked="checked"';
5010: if ($settings->{$item}->{$extra}) {
5011: $checkedon = $checkedoff;
5012: $checkedoff = '';
1.319 raeburn 5013: $validsty = 'inline-block';
5014: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
5015: $currvalid = $settings->{$item}->{$extra.'valid'};
5016: }
5017: }
5018: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
5019: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5020: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
5021: &mt('No').'</label>'.(' 'x2).
5022: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
5023: &mt('Yes').'</label></span></div>'.
5024: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
5025: '<span class="LC_nobreak">'.
5026: &mt("at least [_1] $units{$extra} after launch",
5027: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
5028: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5029: }
1.319 raeburn 5030: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 5031: if ($imgsrc) {
5032: $datatable .= $imgsrc.
5033: '<label><input type="checkbox" name="ltitools_image_del"'.
5034: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5035: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5036: } else {
5037: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5038: }
5039: if ($switchserver) {
5040: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5041: } else {
5042: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5043: }
5044: $datatable .= '</span></fieldset>';
1.324 raeburn 5045: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5046: if (ref($settings->{$item}) eq 'HASH') {
5047: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5048: %checkedfields = %{$settings->{$item}->{'fields'}};
5049: }
1.324 raeburn 5050: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5051: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5052: %rolemaps = %{$settings->{$item}->{'roles'}};
5053: $checkedfields{'roles'} = 1;
5054: }
5055: }
5056: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5057: '<span class="LC_nobreak">';
1.324 raeburn 5058: my $userfieldstyle = 'display:none;';
5059: my $seluserdom = '';
5060: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5061: foreach my $field (@fields) {
1.324 raeburn 5062: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5063: if ($checkedfields{$field}) {
5064: $checked = ' checked="checked"';
5065: }
1.324 raeburn 5066: if ($field eq 'user') {
5067: $id = ' id="ltitools_user_field_'.$i.'"';
5068: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5069: if ($checked) {
5070: $userfieldstyle = 'display:inline-block';
5071: if ($userincdom) {
5072: $seluserdom = $unseluserdom;
5073: $unseluserdom = '';
5074: }
5075: }
5076: } else {
5077: $spacer = (' ' x2);
5078: }
1.267 raeburn 5079: $datatable .= '<label>'.
1.324 raeburn 5080: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5081: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5082: }
1.324 raeburn 5083: $datatable .= '</span>';
5084: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5085: '<span class="LC_nobreak"> : '.
5086: '<select name="ltitools_userincdom_'.$i.'">'.
5087: '<option value="">'.&mt('Select').'</option>'.
5088: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5089: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5090: '</select></span></div>';
5091: $datatable .= '</fieldset>'.
1.267 raeburn 5092: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5093: foreach my $role (@courseroles) {
5094: my ($selected,$selectnone);
5095: if (!$rolemaps{$role}) {
5096: $selectnone = ' selected="selected"';
5097: }
1.306 raeburn 5098: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5099: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5100: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5101: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5102: foreach my $ltirole (@ltiroles) {
5103: unless ($selectnone) {
5104: if ($rolemaps{$role} eq $ltirole) {
5105: $selected = ' selected="selected"';
5106: } else {
5107: $selected = '';
5108: }
5109: }
5110: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5111: }
5112: $datatable .= '</select></td>';
5113: }
1.273 raeburn 5114: $datatable .= '</tr></table></fieldset>';
5115: my %courseconfig;
5116: if (ref($settings->{$item}) eq 'HASH') {
5117: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5118: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5119: }
5120: }
5121: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5122: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5123: my $checked;
5124: if ($courseconfig{$item}) {
5125: $checked = ' checked="checked"';
5126: }
5127: $datatable .= '<label>'.
5128: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5129: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5130: }
5131: $datatable .= '</span></fieldset>'.
1.267 raeburn 5132: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5133: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5134: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5135: my %custom = %{$settings->{$item}->{'custom'}};
5136: if (keys(%custom) > 0) {
5137: foreach my $key (sort(keys(%custom))) {
5138: $datatable .= '<tr><td><span class="LC_nobreak">'.
5139: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5140: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5141: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5142: ' value="'.$custom{$key}.'" /></td></tr>';
5143: }
5144: }
5145: }
5146: $datatable .= '<tr><td><span class="LC_nobreak">'.
5147: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5148: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5149: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5150: $datatable .= '</table></fieldset></td></tr>'."\n";
5151: $itemcount ++;
5152: }
5153: }
5154: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5155: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5156: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5157: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5158: '<select name="ltitools_add_pos"'.$chgstr.'>';
5159: for (my $k=0; $k<$maxnum+1; $k++) {
5160: my $vpos = $k+1;
5161: my $selstr;
5162: if ($k == $maxnum) {
5163: $selstr = ' selected="selected" ';
5164: }
5165: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5166: }
5167: $datatable .= '</select> '."\n".
1.334 raeburn 5168: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5169: '<td colspan="2">'.
5170: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5171: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5172: (' 'x2).
5173: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5174: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5175: (' 'x2).
5176: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5177: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5178: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5179: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5180: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5181: '<br />'.
1.323 raeburn 5182: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5183: (' 'x2).
5184: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5185: (' 'x2).
1.322 raeburn 5186: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5187: (' 'x2).
1.267 raeburn 5188: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5189: '<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".
5190: '</fieldset>'.
5191: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5192: '<span class="LC_nobreak">'.&mt('Display target:');
5193: my %defaultdisp;
5194: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5195: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5196: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5197: $lt{$disp}.'</label>'.(' 'x2);
5198: }
5199: $datatable .= (' 'x4);
5200: foreach my $dimen ('width','height') {
5201: $datatable .= '<label>'.$lt{$dimen}.' '.
5202: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5203: (' 'x2);
5204: }
1.334 raeburn 5205: $datatable .= '</span><br />'.
1.296 raeburn 5206: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5207: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5208: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5209: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5210: '</div><div style=""></div><br />';
1.319 raeburn 5211: my %units = (
5212: 'passback' => 'days',
5213: 'roster' => 'seconds',
5214: );
5215: my %defaulttimes = (
5216: 'passback' => '7',
1.322 raeburn 5217: 'roster' => '300',
1.319 raeburn 5218: );
1.267 raeburn 5219: foreach my $extra ('passback','roster') {
1.319 raeburn 5220: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5221: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5222: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5223: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5224: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5225: &mt('Yes').'</label></span></div>'.
5226: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5227: '<span class="LC_nobreak">'.
5228: &mt("at least [_1] $units{$extra} after launch",
5229: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5230: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5231: }
1.319 raeburn 5232: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5233: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5234: if ($switchserver) {
5235: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5236: } else {
5237: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5238: }
5239: $datatable .= '</span></fieldset>'.
5240: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5241: '<span class="LC_nobreak">';
5242: foreach my $field (@fields) {
1.324 raeburn 5243: my ($id,$onclick,$spacer);
5244: if ($field eq 'user') {
5245: $id = ' id="ltitools_user_field_add"';
5246: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5247: } else {
5248: $spacer = (' ' x2);
5249: }
1.267 raeburn 5250: $datatable .= '<label>'.
1.324 raeburn 5251: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5252: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5253: }
1.324 raeburn 5254: $datatable .= '</span>'.
5255: '<div style="display:none;" id="ltitools_user_div_add">'.
5256: '<span class="LC_nobreak"> : '.
5257: '<select name="ltitools_userincdom_add">'.
5258: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5259: '<option value="0">'.&mt('username').'</option>'.
5260: '<option value="1">'.&mt('username:domain').'</option>'.
5261: '</select></span></div></fieldset>';
5262: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5263: foreach my $role (@courseroles) {
5264: my ($checked,$checkednone);
1.306 raeburn 5265: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5266: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5267: '<select name="ltitools_add_roles_'.$role.'">'.
5268: '<option value="" selected="selected">'.&mt('Select').'</option>';
5269: foreach my $ltirole (@ltiroles) {
5270: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5271: }
5272: $datatable .= '</select></td>';
5273: }
5274: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5275: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5276: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5277: $datatable .= '<label>'.
5278: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5279: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5280: }
5281: $datatable .= '</span></fieldset>'.
1.267 raeburn 5282: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5283: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5284: '<tr><td><span class="LC_nobreak">'.
5285: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5286: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5287: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5288: '</table></fieldset>'."\n".
1.267 raeburn 5289: '</td>'."\n".
5290: '</tr>'."\n";
5291: $itemcount ++;
5292: return $datatable;
5293: }
5294:
5295: sub ltitools_names {
5296: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5297: 'title' => 'Title',
5298: 'version' => 'Version',
5299: 'msgtype' => 'Message Type',
1.323 raeburn 5300: 'sigmethod' => 'Signature Method',
1.296 raeburn 5301: 'url' => 'URL',
5302: 'key' => 'Key',
1.322 raeburn 5303: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5304: 'secret' => 'Secret',
5305: 'icon' => 'Icon',
1.324 raeburn 5306: 'user' => 'User',
1.296 raeburn 5307: 'fullname' => 'Full Name',
5308: 'firstname' => 'First Name',
5309: 'lastname' => 'Last Name',
5310: 'email' => 'E-mail',
5311: 'roles' => 'Role',
1.298 raeburn 5312: 'window' => 'Window',
5313: 'tab' => 'Tab',
1.296 raeburn 5314: 'iframe' => 'iFrame',
5315: 'height' => 'Height',
5316: 'width' => 'Width',
5317: 'linktext' => 'Default Link Text',
5318: 'explanation' => 'Default Explanation',
5319: 'passback' => 'Tool can return grades:',
5320: 'roster' => 'Tool can retrieve roster:',
5321: 'crstarget' => 'Display target',
5322: 'crslabel' => 'Course label',
5323: 'crstitle' => 'Course title',
5324: 'crslinktext' => 'Link Text',
5325: 'crsexplanation' => 'Explanation',
1.318 raeburn 5326: 'crsappend' => 'Provider URL',
1.267 raeburn 5327: );
5328: return %lt;
5329: }
5330:
1.372 raeburn 5331: sub print_proctoring {
5332: my ($dom,$settings,$rowtotal) = @_;
5333: my $itemcount = 1;
5334: my (%ordered,%providernames,%current,%currentdef);
5335: my $confname = $dom.'-domainconfig';
5336: my $switchserver = &check_switchserver($dom,$confname);
5337: if (ref($settings) eq 'HASH') {
5338: foreach my $item (keys(%{$settings})) {
5339: if (ref($settings->{$item}) eq 'HASH') {
5340: my $num = $settings->{$item}{'order'};
5341: $ordered{$num} = $item;
5342: }
5343: }
5344: } else {
5345: %ordered = (
5346: 1 => 'proctorio',
5347: 2 => 'examity',
5348: );
5349: }
5350: %providernames = &proctoring_providernames();
5351: my $maxnum = scalar(keys(%ordered));
5352: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5353: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5354: if (ref($requref) eq 'HASH') {
5355: %requserfields = %{$requref};
5356: }
5357: if (ref($opturef) eq 'HASH') {
5358: %optuserfields = %{$opturef};
5359: }
5360: if (ref($defref) eq 'HASH') {
5361: %defaults = %{$defref};
5362: }
5363: if (ref($extref) eq 'HASH') {
5364: %extended = %{$extref};
5365: }
5366: if (ref($crsref) eq 'HASH') {
5367: %crsconf = %{$crsref};
5368: }
5369: if (ref($rolesref) eq 'ARRAY') {
5370: @courseroles = @{$rolesref};
5371: }
5372: if (ref($ltiref) eq 'ARRAY') {
5373: @ltiroles = @{$ltiref};
5374: }
5375: my $datatable;
5376: my $css_class;
5377: if (keys(%ordered)) {
5378: my @items = sort { $a <=> $b } keys(%ordered);
5379: for (my $i=0; $i<@items; $i++) {
5380: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5381: my $provider = $ordered{$items[$i]};
5382: my $optionsty = 'none';
5383: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5384: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5385: if (ref($settings) eq 'HASH') {
5386: if (ref($settings->{$provider}) eq 'HASH') {
5387: %current = %{$settings->{$provider}};
5388: if ($current{'available'}) {
5389: $optionsty = 'block';
5390: $available = 1;
5391: }
5392: if ($current{'lifetime'} =~ /^\d+$/) {
5393: $lifetime = $current{'lifetime'};
5394: }
5395: if ($current{'version'} =~ /^\d+\.\d+$/) {
5396: $version = $current{'version'};
5397: }
5398: if ($current{'image'} ne '') {
5399: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5400: }
5401: if (ref($current{'fields'}) eq 'ARRAY') {
5402: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5403: }
5404: $userincdom = $current{'incdom'};
5405: if (ref($current{'roles'}) eq 'HASH') {
5406: %rolemaps = %{$current{'roles'}};
5407: $checkedfields{'roles'} = 1;
5408: }
5409: if (ref($current{'defaults'}) eq 'ARRAY') {
5410: foreach my $val (@{$current{'defaults'}}) {
5411: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5412: $inuse{$val} = 1;
5413: } else {
5414: foreach my $poss (keys(%{$extended{$provider}})) {
5415: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5416: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5417: $inuse{$poss} = $val;
5418: last;
5419: }
5420: }
5421: }
5422: }
5423: }
5424: } elsif (ref($current{'defaults'}) eq 'HASH') {
5425: foreach my $key (keys(%{$current{'defaults'}})) {
5426: my $currval = $current{'defaults'}{$key};
5427: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5428: $inuse{$key} = 1;
5429: } else {
5430: my $match;
5431: foreach my $poss (keys(%{$extended{$provider}})) {
5432: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5433: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5434: $inuse{$poss} = $key;
5435: last;
5436: }
5437: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5438: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5439: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5440: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5441: $currentdef{$inner} = $currval;
5442: $match = 1;
5443: last;
5444: }
5445: } elsif ($inner eq $key) {
5446: $currentdef{$key} = $currval;
5447: $match = 1;
5448: last;
5449: }
5450: }
5451: }
5452: last if ($match);
5453: }
5454: }
5455: }
5456: }
5457: if (ref($current{'crsconf'}) eq 'ARRAY') {
5458: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5459: }
5460: }
5461: }
5462: my %lt = &proctoring_titles($provider);
5463: my %fieldtitles = &proctoring_fieldtitles($provider);
5464: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5465: my %checkedavailable = (
5466: yes => '',
5467: no => ' checked="checked"',
5468: );
5469: if ($available) {
5470: $checkedavailable{'yes'} = $checkedavailable{'no'};
5471: $checkedavailable{'no'} = '';
5472: }
5473: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5474: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5475: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5476: for (my $k=0; $k<$maxnum; $k++) {
5477: my $vpos = $k+1;
5478: my $selstr;
5479: if ($k == $i) {
5480: $selstr = ' selected="selected" ';
5481: }
5482: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5483: }
5484: if ($version eq '') {
5485: if ($provider eq 'proctorio') {
5486: $version = '1.0';
5487: } elsif ($provider eq 'examity') {
5488: $version = '1.1';
5489: }
5490: }
5491: if ($lifetime eq '') {
5492: $lifetime = '300';
5493: }
5494: $datatable .=
5495: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5496: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5497: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5498: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5499: '</td>'.
5500: '<td colspan="2">'.
5501: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5502: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5503: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5504: (' 'x2).
5505: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5506: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5507: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5508: (' 'x2).
5509: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5510: '<br />'.
5511: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5512: '<br />'.
5513: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5514: (' 'x2).
5515: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5516: '<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";
5517: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5518: if ($imgsrc) {
5519: $datatable .= $imgsrc.
5520: '<label><input type="checkbox" name="proctoring_image_del"'.
5521: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5522: '<span class="LC_nobreak"> '.&mt('Replace:');
5523: }
5524: $datatable .= ' ';
5525: if ($switchserver) {
5526: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5527: } else {
5528: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5529: }
5530: unless ($imgsrc) {
5531: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5532: }
5533: $datatable .= '</fieldset>'."\n";
5534: if (ref($requserfields{$provider}) eq 'ARRAY') {
5535: if (@{$requserfields{$provider}} > 0) {
5536: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5537: foreach my $field (@{$requserfields{$provider}}) {
5538: $datatable .= '<span class="LC_nobreak">'.
5539: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5540: $lt{$field}.'</label>';
5541: if ($field eq 'user') {
5542: my $seluserdom = '';
5543: my $unseluserdom = ' selected="selected"';
5544: if ($userincdom) {
5545: $seluserdom = $unseluserdom;
5546: $unseluserdom = '';
5547: }
5548: $datatable .= ': '.
5549: '<select name="proctoring_userincdom_'.$provider.'">'.
5550: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5551: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5552: '</select> ';
5553: } else {
5554: $datatable .= ' ';
5555: if ($field eq 'roles') {
5556: $showroles = 1;
5557: }
5558: }
5559: $datatable .= '</span> ';
5560: }
5561: }
5562: $datatable .= '</fieldset>'."\n";
5563: }
5564: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5565: if (@{$optuserfields{$provider}} > 0) {
5566: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5567: foreach my $field (@{$optuserfields{$provider}}) {
5568: my $checked;
5569: if ($checkedfields{$field}) {
5570: $checked = ' checked="checked"';
5571: }
5572: $datatable .= '<span class="LC_nobreak">'.
5573: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5574: }
5575: $datatable .= '</fieldset>'."\n";
5576: }
5577: }
5578: if (ref($defaults{$provider}) eq 'ARRAY') {
5579: if (@{$defaults{$provider}}) {
5580: my (%options,@selectboxes);
5581: if (ref($extended{$provider}) eq 'HASH') {
5582: %options = %{$extended{$provider}};
5583: }
5584: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5585: my ($rem,$numinrow,$dropdowns);
5586: if ($provider eq 'proctorio') {
5587: $datatable .= '<table>';
5588: $numinrow = 4;
5589: }
5590: my $i = 0;
5591: foreach my $field (@{$defaults{$provider}}) {
5592: my $checked;
5593: if ($inuse{$field}) {
5594: $checked = ' checked="checked"';
5595: }
5596: if ($provider eq 'examity') {
5597: if ($field eq 'display') {
5598: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5599: foreach my $option ('iframe','tab','window') {
5600: my $checkdisp;
5601: if ($currentdef{'target'} eq $option) {
5602: $checkdisp = ' checked="checked"';
5603: }
5604: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5605: $fieldtitles{$option}.'</label>'.(' 'x2);
5606: }
5607: $datatable .= (' 'x4);
5608: foreach my $dimen ('width','height') {
5609: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5610: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5611: 'value="'.$currentdef{$dimen}.'" /></label>'.
5612: (' 'x2);
5613: }
5614: $datatable .= '</span><br />'.
5615: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5616: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5617: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5618: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5619: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5620: $currentdef{'explanation'}.
5621: '</textarea></div><div style=""></div><br />';
5622: }
5623: } else {
5624: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5625: my ($output,$selnone);
5626: unless ($checked) {
5627: $selnone = ' selected="selected"';
5628: }
5629: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5630: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5631: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5632: foreach my $option (@{$options{$field}}) {
5633: my $sel;
5634: if ($inuse{$field} eq $option) {
5635: $sel = ' selected="selected"';
5636: }
5637: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5638: }
5639: $output .= '</select></span>';
5640: push(@selectboxes,$output);
5641: } else {
5642: $rem = $i%($numinrow);
5643: if ($rem == 0) {
5644: if ($i > 0) {
5645: $datatable .= '</tr>';
5646: }
5647: $datatable .= '<tr>';
5648: }
5649: $datatable .= '<td class="LC_left_item">'.
5650: '<span class="LC_nobreak">'.
5651: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5652: $fieldtitles{$field}.'</label></span></td>';
5653: $i++;
5654: }
5655: }
5656: }
5657: if ($provider eq 'proctorio') {
5658: if ($numinrow) {
5659: $rem = $i%$numinrow;
5660: }
5661: my $colsleft = $numinrow - $rem;
5662: if ($colsleft > 1) {
5663: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5664: } else {
5665: $datatable .= '<td class="LC_left_item">';
5666: }
5667: $datatable .= ' '.
5668: '</td></tr></table>';
5669: if (@selectboxes) {
5670: $datatable .= '<hr /><table>';
5671: $numinrow = 2;
5672: for (my $i=0; $i<@selectboxes; $i++) {
5673: $rem = $i%($numinrow);
5674: if ($rem == 0) {
5675: if ($i > 0) {
5676: $datatable .= '</tr>';
5677: }
5678: $datatable .= '<tr>';
5679: }
5680: $datatable .= '<td class="LC_left_item">'.
5681: $selectboxes[$i].'</td>';
5682: }
5683: if ($numinrow) {
5684: $rem = $i%$numinrow;
5685: }
5686: $colsleft = $numinrow - $rem;
5687: if ($colsleft > 1) {
5688: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5689: } else {
5690: $datatable .= '<td class="LC_left_item">';
5691: }
5692: $datatable .= ' '.
5693: '</td></tr></table>';
5694: }
5695: }
5696: $datatable .= '</fieldset>';
5697: }
5698: if (ref($crsconf{$provider}) eq 'ARRAY') {
5699: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5700: '<legend>'.&mt('Configurable in course').'</legend>';
5701: my ($rem,$numinrow);
5702: if ($provider eq 'proctorio') {
5703: $datatable .= '<table>';
5704: $numinrow = 4;
5705: }
5706: my $i = 0;
5707: foreach my $item (@{$crsconf{$provider}}) {
5708: my $name;
5709: if ($provider eq 'examity') {
5710: $name = $lt{'crs'.$item};
5711: } elsif ($provider eq 'proctorio') {
5712: $name = $fieldtitles{$item};
5713: $rem = $i%($numinrow);
5714: if ($rem == 0) {
5715: if ($i > 0) {
5716: $datatable .= '</tr>';
5717: }
5718: $datatable .= '<tr>';
5719: }
5720: $datatable .= '<td class="LC_left_item>';
5721: }
5722: my $checked;
5723: if ($crsconfig{$item}) {
5724: $checked = ' checked="checked"';
5725: }
5726: $datatable .= '<span class="LC_nobreak"><label>'.
5727: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5728: $name.'</label></span>';
5729: if ($provider eq 'examity') {
5730: $datatable .= ' ';
5731: }
5732: $datatable .= "\n";
5733: $i++;
5734: }
5735: if ($provider eq 'proctorio') {
5736: if ($numinrow) {
5737: $rem = $i%$numinrow;
5738: }
5739: my $colsleft = $numinrow - $rem;
5740: if ($colsleft > 1) {
5741: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5742: } else {
5743: $datatable .= '<td class="LC_left_item">';
5744: }
5745: $datatable .= ' '.
5746: '</td></tr></table>';
5747: }
5748: $datatable .= '</fieldset>';
5749: }
5750: if ($showroles) {
5751: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5752: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5753: foreach my $role (@courseroles) {
5754: my ($selected,$selectnone);
5755: if (!$rolemaps{$role}) {
5756: $selectnone = ' selected="selected"';
5757: }
5758: $datatable .= '<td style="text-align: center">'.
5759: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5760: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5761: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5762: foreach my $ltirole (@ltiroles) {
5763: unless ($selectnone) {
5764: if ($rolemaps{$role} eq $ltirole) {
5765: $selected = ' selected="selected"';
5766: } else {
5767: $selected = '';
5768: }
5769: }
5770: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5771: }
5772: $datatable .= '</select></td>';
5773: }
5774: $datatable .= '</tr></table></fieldset>'.
5775: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5776: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5777: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5778: '<tr><td></td><td>lms</td>'.
5779: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5780: ' value="Loncapa" disabled="disabled"/></td></tr>';
5781: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5782: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5783: my %custom = %{$settings->{$provider}->{'custom'}};
5784: if (keys(%custom) > 0) {
5785: foreach my $key (sort(keys(%custom))) {
5786: next if ($key eq 'lms');
5787: $datatable .= '<tr><td><span class="LC_nobreak">'.
5788: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5789: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5790: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5791: ' value="'.$custom{$key}.'" /></td></tr>';
5792: }
5793: }
5794: }
5795: $datatable .= '<tr><td><span class="LC_nobreak">'.
5796: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5797: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5798: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5799: '</table></fieldset></td></tr>'."\n";
5800: }
5801: $datatable .= '</td></tr>';
5802: }
5803: $itemcount ++;
5804: }
5805: }
5806: return $datatable;
5807: }
5808:
5809: sub proctoring_data {
5810: my $requserfields = {
5811: proctorio => ['user'],
5812: examity => ['roles','user'],
5813: };
5814: my $optuserfields = {
5815: proctorio => ['fullname'],
5816: examity => ['fullname','firstname','lastname','email'],
5817: };
5818: my $defaults = {
5819: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5820: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5821: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5822: 'closetabs','onescreen','print','downloads','cache','rightclick',
5823: 'reentry','calculator','whiteboard'],
5824: examity => ['display'],
5825: };
5826: my $extended = {
5827: proctorio => {
5828: verifyid => ['verifyidauto','verifyidlive'],
5829: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5830: tabslinks => ['notabs','linksonly'],
5831: reentry => ['noreentry','agentreentry'],
5832: calculator => ['calculatorbasic','calculatorsci'],
5833: },
5834: examity => {
5835: display => {
5836: target => ['iframe','tab','window'],
5837: width => '',
5838: height => '',
5839: linktext => '',
5840: explanation => '',
5841: },
5842: },
5843: };
5844: my $crsconf = {
5845: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5846: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5847: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5848: 'closetabs','onescreen','print','downloads','cache','rightclick',
5849: 'reentry','calculator','whiteboard'],
5850: examity => ['label','title','target','linktext','explanation','append'],
5851: };
5852: my $courseroles = ['cc','in','ta','ep','st'];
5853: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5854: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5855: }
5856:
5857: sub proctoring_titles {
5858: my ($item) = @_;
5859: my (%common_lt,%custom_lt);
5860: %common_lt = &Apache::lonlocal::texthash (
5861: 'avai' => 'Available?',
5862: 'base' => 'Basic Settings',
5863: 'requ' => 'User data required to be sent on launch',
5864: 'optu' => 'User data optionally sent on launch',
5865: 'udsl' => 'User data sent on launch',
5866: 'defa' => 'Defaults for items configurable in course',
5867: 'sigmethod' => 'Signature Method',
5868: 'key' => 'Key',
5869: 'lifetime' => 'Nonce lifetime (s)',
5870: 'secret' => 'Secret',
5871: 'icon' => 'Icon',
5872: 'fullname' => 'Full Name',
5873: 'visible' => 'Visible input',
5874: 'username' => 'username',
5875: 'user' => 'User',
5876: );
5877: if ($item eq 'proctorio') {
5878: %custom_lt = &Apache::lonlocal::texthash (
5879: 'version' => 'OAuth version',
5880: 'url' => 'API URL',
5881: 'uname:dom' => 'username-domain',
5882: );
5883: } elsif ($item eq 'examity') {
5884: %custom_lt = &Apache::lonlocal::texthash (
5885: 'version' => 'LTI Version',
5886: 'url' => 'URL',
5887: 'uname:dom' => 'username:domain',
5888: 'msgtype' => 'Message Type',
5889: 'firstname' => 'First Name',
5890: 'lastname' => 'Last Name',
5891: 'email' => 'E-mail',
5892: 'roles' => 'Role',
5893: 'crstarget' => 'Display target',
5894: 'crslabel' => 'Course label',
5895: 'crstitle' => 'Course title',
5896: 'crslinktext' => 'Link Text',
5897: 'crsexplanation' => 'Explanation',
5898: 'crsappend' => 'Provider URL',
5899: );
5900: }
5901: my %lt = (%common_lt,%custom_lt);
5902: return %lt;
5903: }
5904:
5905: sub proctoring_fieldtitles {
5906: my ($item) = @_;
5907: if ($item eq 'proctorio') {
5908: return &Apache::lonlocal::texthash (
5909: 'recordvideo' => 'Record video',
5910: 'recordaudio' => 'Record audio',
5911: 'recordscreen' => 'Record screen',
5912: 'recordwebtraffic' => 'Record web traffic',
5913: 'recordroomstart' => 'Record room scan',
5914: 'verifyvideo' => 'Verify webcam',
5915: 'verifyaudio' => 'Verify microphone',
5916: 'verifydesktop' => 'Verify desktop recording',
5917: 'verifyid' => 'Photo ID verification',
5918: 'verifysignature' => 'Require signature',
5919: 'fullscreen' => 'Fullscreen',
5920: 'clipboard' => 'Disable copy/paste',
5921: 'tabslinks' => 'New tabs/windows',
5922: 'closetabs' => 'Close other tabs',
5923: 'onescreen' => 'Limit to single screen',
5924: 'print' => 'Disable Printing',
5925: 'downloads' => 'Disable Downloads',
5926: 'cache' => 'Empty cache after exam',
5927: 'rightclick' => 'Disable right click',
5928: 'reentry' => 'Re-entry to exam',
5929: 'calculator' => 'Onscreen calculator',
5930: 'whiteboard' => 'Onscreen whiteboard',
5931: 'verifyidauto' => 'Automated verification',
5932: 'verifyidlive' => 'Live agent verification',
5933: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5934: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5935: 'fullscreensever' => 'Forced, navigation away ends exam',
5936: 'notabs' => 'Disaallowed',
5937: 'linksonly' => 'Allowed from links in exam',
5938: 'noreentry' => 'Disallowed',
5939: 'agentreentry' => 'Agent required for re-entry',
5940: 'calculatorbasic' => 'Basic',
5941: 'calculatorsci' => 'Scientific',
5942: );
5943: } elsif ($item eq 'examity') {
5944: return &Apache::lonlocal::texthash (
5945: 'target' => 'Display target',
5946: 'window' => 'Window',
5947: 'tab' => 'Tab',
5948: 'iframe' => 'iFrame',
5949: 'height' => 'Height (pixels)',
5950: 'width' => 'Width (pixels)',
5951: 'linktext' => 'Default Link Text',
5952: 'explanation' => 'Default Explanation',
5953: 'append' => 'Provider URL',
5954: );
5955: }
5956: }
5957:
5958: sub proctoring_providernames {
5959: return (
5960: proctorio => 'Proctorio',
5961: examity => 'Examity',
5962: );
5963: }
5964:
1.320 raeburn 5965: sub print_lti {
5966: my ($dom,$settings,$rowtotal) = @_;
5967: my $itemcount = 1;
5968: my $maxnum = 0;
5969: my $css_class;
5970: my %ordered;
5971: if (ref($settings) eq 'HASH') {
5972: foreach my $item (keys(%{$settings})) {
5973: if (ref($settings->{$item}) eq 'HASH') {
5974: my $num = $settings->{$item}{'order'};
1.390 raeburn 5975: if ($num eq '') {
5976: $num = scalar(keys(%{$settings}));
5977: }
1.320 raeburn 5978: $ordered{$num} = $item;
5979: }
5980: }
5981: }
5982: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5983: my $datatable;
1.320 raeburn 5984: my %lt = <i_names();
5985: if (keys(%ordered)) {
5986: my @items = sort { $a <=> $b } keys(%ordered);
5987: for (my $i=0; $i<@items; $i++) {
5988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5989: my $item = $ordered{$items[$i]};
1.391 raeburn 5990: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320 raeburn 5991: if (ref($settings->{$item}) eq 'HASH') {
5992: $key = $settings->{$item}->{'key'};
5993: $secret = $settings->{$item}->{'secret'};
5994: $lifetime = $settings->{$item}->{'lifetime'};
5995: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5996: $requser = $settings->{$item}->{'requser'};
1.391 raeburn 5997: $crsinc = $settings->{$item}->{'crsinc'};
1.320 raeburn 5998: $current = $settings->{$item};
5999: }
1.345 raeburn 6000: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6001: my %checkedrequser = (
6002: yes => ' checked="checked"',
6003: no => '',
6004: );
6005: if (!$requser) {
6006: $checkedrequser{'no'} = $checkedrequser{'yes'};
6007: $checkedrequser{'yes'} = '';
1.352 raeburn 6008: }
1.391 raeburn 6009: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6010: my %checkedcrsinc = (
6011: yes => ' checked="checked"',
6012: no => '',
6013: );
6014: if (!$crsinc) {
6015: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6016: $checkedcrsinc{'yes'} = '';
6017: }
1.320 raeburn 6018: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6019: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6020: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6021: for (my $k=0; $k<=$maxnum; $k++) {
6022: my $vpos = $k+1;
6023: my $selstr;
6024: if ($k == $i) {
6025: $selstr = ' selected="selected" ';
6026: }
6027: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6028: }
6029: $datatable .= '</select>'.(' 'x2).
6030: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6031: &mt('Delete?').'</label></span></td>'.
6032: '<td colspan="2">'.
6033: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6034: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6035: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 6036: (' 'x2).
6037: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6038: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6039: (' 'x2).
6040: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 6041: 'value="'.$lifetime.'" size="3" /></span>'.
6042: (' 'x2).
6043: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6044: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6045: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6046: '<br /><br />'.
1.391 raeburn 6047: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6048: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6049: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6050: (' 'x4).
1.320 raeburn 6051: '<span class="LC_nobreak">'.$lt{'key'}.
6052: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6053: (' 'x2).
6054: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6055: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6056: '<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>'.
6057: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 6058: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 6059: $itemcount ++;
6060: }
6061: }
6062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6063: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6064: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6065: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6066: '<select name="lti_pos_add"'.$chgstr.'>';
6067: for (my $k=0; $k<$maxnum+1; $k++) {
6068: my $vpos = $k+1;
6069: my $selstr;
6070: if ($k == $maxnum) {
6071: $selstr = ' selected="selected" ';
6072: }
6073: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6074: }
6075: $datatable .= '</select> '."\n".
1.334 raeburn 6076: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 6077: '<td colspan="2">'.
6078: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6079: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6080: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 6081: (' 'x2).
6082: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6083: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6084: (' 'x2).
1.345 raeburn 6085: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6086: (' 'x2).
6087: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6088: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6089: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6090: '<br /><br />'.
1.391 raeburn 6091: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6092: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6093: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6094: (' 'x4).
1.320 raeburn 6095: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6096: (' 'x2).
6097: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6098: '<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".
1.325 raeburn 6099: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 6100: '</td>'."\n".
6101: '</tr>'."\n";
6102: $$rowtotal ++;
6103: return $datatable;;
6104: }
6105:
6106: sub lti_names {
6107: my %lt = &Apache::lonlocal::texthash(
6108: 'version' => 'LTI Version',
6109: 'url' => 'URL',
6110: 'key' => 'Key',
1.322 raeburn 6111: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6112: 'consumer' => 'Consumer',
1.320 raeburn 6113: 'secret' => 'Secret',
1.345 raeburn 6114: 'requser' => "User's identity sent",
1.391 raeburn 6115: 'crsinc' => "Course's identity sent",
1.320 raeburn 6116: 'email' => 'Email address',
6117: 'sourcedid' => 'User ID',
6118: 'other' => 'Other',
6119: 'passback' => 'Can return grades to Consumer:',
6120: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6121: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6122: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6123: );
6124: return %lt;
6125: }
6126:
6127: sub lti_options {
1.325 raeburn 6128: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6129: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6130: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6131: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 ! raeburn 6132: $checked{'storecrs'}{'Y'} = ' checked="checked"';
! 6133: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6134: $checked{'mapcrstype'} = {};
6135: $checked{'makeuser'} = {};
6136: $checked{'selfenroll'} = {};
6137: $checked{'crssec'} = {};
6138: $checked{'crssecsrc'} = {};
1.325 raeburn 6139: $checked{'lcauth'} = {};
1.326 raeburn 6140: $checked{'menuitem'} = {};
1.325 raeburn 6141: if ($num eq 'add') {
6142: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6143: }
1.320 raeburn 6144: my $userfieldsty = 'none';
6145: my $crsfieldsty = 'none';
6146: my $crssecfieldsty = 'none';
6147: my $secsrcfieldsty = 'none';
1.363 raeburn 6148: my $callbacksty = 'none';
1.337 raeburn 6149: my $passbacksty = 'none';
1.345 raeburn 6150: my $optionsty = 'block';
1.391 raeburn 6151: my $crssty = 'block';
1.325 raeburn 6152: my $lcauthparm;
6153: my $lcauthparmstyle = 'display:none';
6154: my $lcauthparmtext;
1.326 raeburn 6155: my $menusty;
1.325 raeburn 6156: my $numinrow = 4;
1.326 raeburn 6157: my %menutitles = <imenu_titles();
1.320 raeburn 6158:
6159: if (ref($current) eq 'HASH') {
1.345 raeburn 6160: if (!$current->{'requser'}) {
6161: $optionsty = 'none';
1.391 raeburn 6162: $crssty = 'none';
6163: } elsif (!$current->{'crsinc'}) {
6164: $crssty = 'none';
1.345 raeburn 6165: }
1.320 raeburn 6166: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6167: $checked{'mapuser'}{'sourcedid'} = '';
6168: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6169: $checked{'mapuser'}{'email'} = ' checked="checked"';
6170: } else {
6171: $checked{'mapuser'}{'other'} = ' checked="checked"';
6172: $userfield = $current->{'mapuser'};
6173: $userfieldsty = 'inline-block';
6174: }
6175: }
6176: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6177: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6178: if ($current->{'mapcrs'} eq 'context_id') {
6179: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6180: } else {
6181: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6182: $cidfield = $current->{'mapcrs'};
6183: $crsfieldsty = 'inline-block';
6184: }
6185: }
6186: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6187: foreach my $type (@{$current->{'mapcrstype'}}) {
6188: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6189: }
6190: }
1.392 ! raeburn 6191: if (!$current->{'storecrs'}) {
! 6192: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
! 6193: $checked{'storecrs'}{'Y'} = '';
! 6194: }
1.345 raeburn 6195: if ($current->{'makecrs'}) {
1.320 raeburn 6196: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6197: }
1.320 raeburn 6198: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6199: foreach my $role (@{$current->{'makeuser'}}) {
6200: $checked{'makeuser'}{$role} = ' checked="checked"';
6201: }
6202: }
1.325 raeburn 6203: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6204: $checked{'lcauth'}{$1} = ' checked="checked"';
6205: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6206: $lcauthparm = $current->{'lcauthparm'};
6207: $lcauthparmstyle = 'display:table-row';
6208: if ($current->{'lcauth'} eq 'localauth') {
6209: $lcauthparmtext = &mt('Local auth argument');
6210: } else {
6211: $lcauthparmtext = &mt('Kerberos domain');
6212: }
6213: }
6214: }
1.320 raeburn 6215: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6216: foreach my $role (@{$current->{'selfenroll'}}) {
6217: $checked{'selfenroll'}{$role} = ' checked="checked"';
6218: }
6219: }
6220: if (ref($current->{'maproles'}) eq 'HASH') {
6221: %rolemaps = %{$current->{'maproles'}};
6222: }
6223: if ($current->{'section'} ne '') {
6224: $checked{'crssec'}{'Y'} = ' checked="checked"';
6225: $crssecfieldsty = 'inline-block';
6226: if ($current->{'section'} eq 'course_section_sourcedid') {
6227: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6228: } else {
6229: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6230: $crssecsrc = $current->{'section'};
6231: $secsrcfieldsty = 'inline-block';
6232: }
6233: } else {
6234: $checked{'crssec'}{'N'} = ' checked="checked"';
6235: }
1.363 raeburn 6236: if ($current->{'callback'} ne '') {
6237: $callback = $current->{'callback'};
6238: $checked{'callback'}{'Y'} = ' checked="checked"';
6239: $callbacksty = 'inline-block';
6240: } else {
6241: $checked{'callback'}{'N'} = ' checked="checked"';
6242: }
1.326 raeburn 6243: if ($current->{'topmenu'}) {
6244: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6245: } else {
6246: $checked{'topmenu'}{'N'} = ' checked="checked"';
6247: }
6248: if ($current->{'inlinemenu'}) {
6249: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6250: } else {
6251: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6252: }
6253: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6254: $menusty = 'inline-block';
6255: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6256: foreach my $item (@{$current->{'lcmenu'}}) {
6257: if (exists($menutitles{$item})) {
6258: $checked{'menuitem'}{$item} = ' checked="checked"';
6259: }
6260: }
6261: }
6262: } else {
6263: $menusty = 'none';
6264: }
1.320 raeburn 6265: } else {
6266: $checked{'makecrs'}{'N'} = ' checked="checked"';
6267: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6268: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6269: $checked{'topmenu'}{'N'} = ' checked="checked"';
6270: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6271: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6272: $menusty = 'inline-block';
1.320 raeburn 6273: }
1.325 raeburn 6274: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6275: my %coursetypetitles = &Apache::lonlocal::texthash (
6276: official => 'Official',
6277: unofficial => 'Unofficial',
6278: community => 'Community',
6279: textbook => 'Textbook',
6280: placement => 'Placement Test',
1.325 raeburn 6281: lti => 'LTI Provider',
1.320 raeburn 6282: );
1.325 raeburn 6283: my @authtypes = ('internal','krb4','krb5','localauth');
6284: my %shortauth = (
6285: internal => 'int',
6286: krb4 => 'krb4',
6287: krb5 => 'krb5',
6288: localauth => 'loc'
6289: );
6290: my %authnames = &authtype_names();
1.320 raeburn 6291: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6292: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6293: my @courseroles = ('cc','in','ta','ep','st');
6294: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6295: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6296: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6297: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6298: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6299: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6300: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6301: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 ! raeburn 6302: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6303: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6304: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6305: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6306: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6307: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6308: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6309: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6310: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6311: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6312: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6313: foreach my $option ('sourcedid','email','other') {
6314: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6315: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6316: ($option eq 'other' ? '' : (' 'x2) );
6317: }
6318: $output .= '</span></div>'.
6319: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6320: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6321: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6322: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6323: foreach my $ltirole (@ltiroles) {
6324: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6325: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6326: }
6327: $output .= '</fieldset>'.
1.391 raeburn 6328: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6329: '<table>'.
6330: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6331: '</table>'.
6332: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6333: '<td class="LC_left_item">';
6334: foreach my $auth ('lti',@authtypes) {
6335: my $authtext;
6336: if ($auth eq 'lti') {
6337: $authtext = &mt('None');
6338: } else {
6339: $authtext = $authnames{$shortauth{$auth}};
6340: }
6341: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6342: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6343: $authtext.'</label></span> ';
6344: }
6345: $output .= '</td></tr>'.
6346: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6347: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6348: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6349: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6350: '</table></fieldset>'.
1.391 raeburn 6351: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6352: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6353: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6354: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6355: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6356: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6357: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6358: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6359: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6360: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6361: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6362: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6363: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6364: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6365: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6366: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6367: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6368: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6369: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6370: (' 'x2);
6371: }
6372: $output .= '</span></div></fieldset>'.
6373: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6374: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6375: &mt('Unique course identifier').': ';
6376: foreach my $option ('course_offering_sourcedid','context_id','other') {
6377: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6378: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6379: ($option eq 'other' ? '' : (' 'x2) );
6380: }
1.334 raeburn 6381: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6382: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6383: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6384: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6385: foreach my $type (@coursetypes) {
6386: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6387: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6388: (' 'x2);
6389: }
1.392 ! raeburn 6390: $output .= '</span><br /><br />'.
! 6391: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
! 6392: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
! 6393: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
! 6394: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
! 6395: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
! 6396: '</fieldset>'.
1.391 raeburn 6397: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6398: foreach my $ltirole (@lticourseroles) {
6399: my ($selected,$selectnone);
6400: if ($rolemaps{$ltirole} eq '') {
6401: $selectnone = ' selected="selected"';
6402: }
6403: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6404: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6405: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6406: foreach my $role (@courseroles) {
6407: unless ($selectnone) {
6408: if ($rolemaps{$ltirole} eq $role) {
6409: $selected = ' selected="selected"';
6410: } else {
6411: $selected = '';
6412: }
6413: }
6414: $output .= '<option value="'.$role.'"'.$selected.'>'.
6415: &Apache::lonnet::plaintext($role,'Course').
6416: '</option>';
6417: }
6418: $output .= '</select></td>';
6419: }
6420: $output .= '</tr></table></fieldset>'.
6421: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6422: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6423: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6424: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6425: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6426: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6427: '</fieldset>'.
1.391 raeburn 6428: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6429: foreach my $lticrsrole (@lticourseroles) {
6430: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6431: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6432: }
6433: $output .= '</fieldset>'.
1.391 raeburn 6434: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6435: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6436: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6437: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6438: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6439: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6440: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6441: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6442: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6443: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6444: &mt('Standard field').'</label>'.(' 'x2).
6445: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6446: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6447: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6448: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6449: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6450: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6451: foreach my $extra ('roster','passback') {
1.320 raeburn 6452: my $checkedon = '';
6453: my $checkedoff = ' checked="checked"';
1.337 raeburn 6454: if ($extra eq 'passback') {
6455: $pb1p1chk = ' checked="checked"';
6456: $pb1p0chk = '';
6457: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6458: } else {
6459: $onclickpb = '';
6460: }
1.320 raeburn 6461: if (ref($current) eq 'HASH') {
6462: if (($current->{$extra})) {
6463: $checkedon = $checkedoff;
6464: $checkedoff = '';
1.337 raeburn 6465: if ($extra eq 'passback') {
6466: $passbacksty = 'inline-block';
6467: }
6468: if ($current->{'passbackformat'} eq '1.0') {
6469: $pb1p0chk = ' checked="checked"';
6470: $pb1p1chk = '';
6471: }
1.320 raeburn 6472: }
6473: }
6474: $output .= $lt{$extra}.' '.
1.337 raeburn 6475: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6476: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6477: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6478: &mt('Yes').'</label><br />';
6479: }
1.337 raeburn 6480: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6481: '<span class="LC_nobreak">'.&mt('Grade format').
6482: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6483: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6484: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6485: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6486: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6487: $output .= '</span></div></fieldset>';
1.320 raeburn 6488: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6489: #
6490: # $output .= '</fieldset>'.
6491: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6492: return $output;
6493: }
6494:
1.326 raeburn 6495: sub ltimenu_titles {
6496: return &Apache::lonlocal::texthash(
6497: fullname => 'Full name',
6498: coursetitle => 'Course title',
6499: role => 'Role',
6500: logout => 'Logout',
6501: grades => 'Grades',
6502: );
6503: }
6504:
1.121 raeburn 6505: sub print_coursedefaults {
1.139 raeburn 6506: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6507: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6508: my $itemcount = 1;
1.192 raeburn 6509: my %choices = &Apache::lonlocal::texthash (
6510: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6511: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6512: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6513: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6514: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6515: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6516: texengine => 'Default method to display mathematics',
1.257 raeburn 6517: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6518: canclone => "People who may clone a course (besides course's owner and coordinators)",
6519: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6520: );
1.198 raeburn 6521: my %staticdefaults = (
6522: anonsurvey_threshold => 10,
6523: uploadquota => 500,
1.257 raeburn 6524: postsubmit => 60,
1.276 raeburn 6525: mysqltables => 172800,
1.198 raeburn 6526: );
1.139 raeburn 6527: if ($position eq 'top') {
1.257 raeburn 6528: %defaultchecked = (
6529: 'canuse_pdfforms' => 'off',
6530: 'uselcmath' => 'on',
6531: 'usejsme' => 'on',
1.289 raeburn 6532: 'canclone' => 'none',
1.257 raeburn 6533: );
6534: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6535: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6536: if (ref($settings) eq 'HASH') {
6537: if ($settings->{'texengine'}) {
6538: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6539: $deftex = $settings->{'texengine'};
6540: }
6541: }
6542: }
6543: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6544: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6545: '<span class="LC_nobreak">'.$choices{'texengine'}.
6546: '</span></td><td class="LC_right_item">'.
6547: '<select name="texengine">'."\n";
6548: my %texoptions = (
6549: MathJax => 'MathJax',
6550: mimetex => &mt('Convert to Images'),
6551: tth => &mt('TeX to HTML'),
6552: );
6553: foreach my $renderer ('MathJax','mimetex','tth') {
6554: my $selected = '';
6555: if ($renderer eq $deftex) {
6556: $selected = ' selected="selected"';
6557: }
6558: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6559: }
6560: $mathdisp .= '</select></td></tr>'."\n";
6561: $itemcount ++;
1.139 raeburn 6562: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6563: \%choices,$itemcount);
1.314 raeburn 6564: $datatable = $mathdisp.$datatable;
1.264 raeburn 6565: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6566: $datatable .=
1.306 raeburn 6567: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6568: '<span class="LC_nobreak">'.$choices{'canclone'}.
6569: '</span></td><td class="LC_left_item">';
6570: my $currcanclone = 'none';
6571: my $onclick;
6572: my @cloneoptions = ('none','domain');
1.380 raeburn 6573: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6574: none => 'No additional course requesters',
6575: domain => "Any course requester in course's domain",
6576: instcode => 'Course requests for official courses ...',
6577: );
6578: my (%codedefaults,@code_order,@posscodes);
6579: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6580: \@code_order) eq 'ok') {
6581: if (@code_order > 0) {
6582: push(@cloneoptions,'instcode');
6583: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6584: }
6585: }
6586: if (ref($settings) eq 'HASH') {
6587: if ($settings->{'canclone'}) {
6588: if (ref($settings->{'canclone'}) eq 'HASH') {
6589: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6590: if (@code_order > 0) {
6591: $currcanclone = 'instcode';
6592: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6593: }
6594: }
6595: } elsif ($settings->{'canclone'} eq 'domain') {
6596: $currcanclone = $settings->{'canclone'};
6597: }
6598: }
1.289 raeburn 6599: }
1.264 raeburn 6600: foreach my $option (@cloneoptions) {
6601: my ($checked,$additional);
6602: if ($currcanclone eq $option) {
6603: $checked = ' checked="checked"';
6604: }
6605: if ($option eq 'instcode') {
6606: if (@code_order) {
6607: my $show = 'none';
6608: if ($checked) {
6609: $show = 'block';
6610: }
1.317 raeburn 6611: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6612: &mt('Institutional codes for new and cloned course have identical:').
6613: '<br />';
6614: foreach my $item (@code_order) {
6615: my $codechk;
6616: if ($checked) {
6617: if (grep(/^\Q$item\E$/,@posscodes)) {
6618: $codechk = ' checked="checked"';
6619: }
6620: }
6621: $additional .= '<label>'.
6622: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6623: $item.'</label>';
6624: }
6625: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6626: }
6627: }
6628: $datatable .=
6629: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6630: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6631: '</label> '.$additional.'</span><br />';
6632: }
6633: $datatable .= '</td>'.
6634: '</tr>';
6635: $itemcount ++;
1.139 raeburn 6636: } else {
6637: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6638: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6639: my $currusecredits = 0;
1.257 raeburn 6640: my $postsubmitclient = 1;
1.271 raeburn 6641: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6642: if (ref($settings) eq 'HASH') {
6643: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6644: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6645: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6646: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6647: }
6648: }
1.192 raeburn 6649: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6650: foreach my $type (@types) {
6651: next if ($type eq 'community');
6652: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6653: if ($defcredits{$type} ne '') {
6654: $currusecredits = 1;
6655: }
6656: }
6657: }
6658: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6659: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6660: $postsubmitclient = 0;
6661: foreach my $type (@types) {
6662: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6663: }
6664: } else {
6665: foreach my $type (@types) {
6666: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6667: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6668: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6669: } else {
6670: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6671: }
6672: } else {
6673: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6674: }
6675: }
6676: }
6677: } else {
6678: foreach my $type (@types) {
6679: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6680: }
6681: }
1.276 raeburn 6682: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6683: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6684: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6685: }
6686: } else {
6687: foreach my $type (@types) {
6688: $currmysql{$type} = $staticdefaults{'mysqltables'};
6689: }
6690: }
1.258 raeburn 6691: } else {
6692: foreach my $type (@types) {
6693: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6694: }
1.139 raeburn 6695: }
6696: if (!$currdefresponder) {
1.198 raeburn 6697: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6698: } elsif ($currdefresponder < 1) {
6699: $currdefresponder = 1;
6700: }
1.198 raeburn 6701: foreach my $type (@types) {
6702: if ($curruploadquota{$type} eq '') {
6703: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6704: }
6705: }
1.139 raeburn 6706: $datatable .=
1.192 raeburn 6707: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6708: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6709: '</span></td>'.
6710: '<td class="LC_right_item"><span class="LC_nobreak">'.
6711: '<input type="text" name="anonsurvey_threshold"'.
6712: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6713: '</td></tr>'."\n";
6714: $itemcount ++;
6715: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6716: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6717: $choices{'uploadquota'}.
6718: '</span></td>'.
1.306 raeburn 6719: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6720: '<table><tr>';
1.198 raeburn 6721: foreach my $type (@types) {
1.306 raeburn 6722: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6723: '<input type="text" name="uploadquota_'.$type.'"'.
6724: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6725: }
6726: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6727: $itemcount ++;
1.236 raeburn 6728: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6729: my $display = 'none';
1.192 raeburn 6730: if ($currusecredits) {
6731: $display = 'block';
6732: }
6733: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6734: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6735: foreach my $type (@types) {
6736: next if ($type eq 'community');
1.306 raeburn 6737: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6738: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6739: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6740: }
6741: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6742: %defaultchecked = ('coursecredits' => 'off');
6743: @toggles = ('coursecredits');
6744: my $current = {
6745: 'coursecredits' => $currusecredits,
6746: };
6747: (my $table,$itemcount) =
6748: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6749: \%choices,$itemcount,$onclick,$additional,'left');
6750: $datatable .= $table;
6751: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6752: my $display = 'none';
6753: if ($postsubmitclient) {
6754: $display = 'block';
6755: }
6756: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6757: &mt('Number of seconds submit is disabled').'<br />'.
6758: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6759: '<table><tr>';
1.257 raeburn 6760: foreach my $type (@types) {
1.306 raeburn 6761: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6762: '<input type="text" name="'.$type.'_timeout" value="'.
6763: $deftimeout{$type}.'" size="5" /></td>';
6764: }
6765: $additional .= '</tr></table></div>'."\n";
6766: %defaultchecked = ('postsubmit' => 'on');
6767: @toggles = ('postsubmit');
1.280 raeburn 6768: $current = {
6769: 'postsubmit' => $postsubmitclient,
6770: };
1.257 raeburn 6771: ($table,$itemcount) =
6772: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6773: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6774: $datatable .= $table;
1.276 raeburn 6775: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6776: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6777: $choices{'mysqltables'}.
6778: '</span></td>'.
1.306 raeburn 6779: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6780: '<table><tr>';
6781: foreach my $type (@types) {
1.306 raeburn 6782: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6783: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6784: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6785: }
6786: $datatable .= '</tr></table></td></tr>'."\n";
6787: $itemcount ++;
6788:
1.139 raeburn 6789: }
1.192 raeburn 6790: $$rowtotal += $itemcount;
1.121 raeburn 6791: return $datatable;
1.118 jms 6792: }
6793:
1.231 raeburn 6794: sub print_selfenrollment {
6795: my ($position,$dom,$settings,$rowtotal) = @_;
6796: my ($css_class,$datatable);
6797: my $itemcount = 1;
1.271 raeburn 6798: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6799: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6800: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6801: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6802: my @rows;
6803: my $key;
6804: if ($position eq 'top') {
6805: $key = 'admin';
6806: if (ref($rowsref) eq 'ARRAY') {
6807: @rows = @{$rowsref};
6808: }
6809: } elsif ($position eq 'middle') {
6810: $key = 'default';
6811: @rows = ('types','registered','approval','limit');
6812: }
6813: foreach my $row (@rows) {
6814: if (defined($titlesref->{$row})) {
6815: $itemcount ++;
6816: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6817: $datatable .= '<tr'.$css_class.'>'.
6818: '<td>'.$titlesref->{$row}.'</td>'.
6819: '<td class="LC_left_item">'.
6820: '<table><tr>';
6821: my (%current,%currentcap);
6822: if (ref($settings) eq 'HASH') {
6823: if (ref($settings->{$key}) eq 'HASH') {
6824: foreach my $type (@types) {
6825: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6826: $current{$type} = $settings->{$key}->{$type}->{$row};
6827: }
6828: if (($row eq 'limit') && ($key eq 'default')) {
6829: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6830: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6831: }
6832: }
6833: }
6834: }
6835: }
6836: my %roles = (
6837: '0' => &Apache::lonnet::plaintext('dc'),
6838: );
6839:
6840: foreach my $type (@types) {
6841: unless (($row eq 'registered') && ($key eq 'default')) {
6842: $datatable .= '<th>'.&mt($type).'</th>';
6843: }
6844: }
6845: unless (($row eq 'registered') && ($key eq 'default')) {
6846: $datatable .= '</tr><tr>';
6847: }
6848: foreach my $type (@types) {
6849: if ($type eq 'community') {
6850: $roles{'1'} = &mt('Community personnel');
6851: } else {
6852: $roles{'1'} = &mt('Course personnel');
6853: }
6854: $datatable .= '<td style="vertical-align: top">';
6855: if ($position eq 'top') {
6856: my %checked;
6857: if ($current{$type} eq '0') {
6858: $checked{'0'} = ' checked="checked"';
6859: } else {
6860: $checked{'1'} = ' checked="checked"';
6861: }
6862: foreach my $role ('1','0') {
6863: $datatable .= '<span class="LC_nobreak"><label>'.
6864: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6865: 'value="'.$role.'"'.$checked{$role}.' />'.
6866: $roles{$role}.'</label></span> ';
6867: }
6868: } else {
6869: if ($row eq 'types') {
6870: my %checked;
6871: if ($current{$type} =~ /^(all|dom)$/) {
6872: $checked{$1} = ' checked="checked"';
6873: } else {
6874: $checked{''} = ' checked="checked"';
6875: }
6876: foreach my $val ('','dom','all') {
6877: $datatable .= '<span class="LC_nobreak"><label>'.
6878: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6879: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6880: }
6881: } elsif ($row eq 'registered') {
6882: my %checked;
6883: if ($current{$type} eq '1') {
6884: $checked{'1'} = ' checked="checked"';
6885: } else {
6886: $checked{'0'} = ' checked="checked"';
6887: }
6888: foreach my $val ('0','1') {
6889: $datatable .= '<span class="LC_nobreak"><label>'.
6890: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6891: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6892: }
6893: } elsif ($row eq 'approval') {
6894: my %checked;
6895: if ($current{$type} =~ /^([12])$/) {
6896: $checked{$1} = ' checked="checked"';
6897: } else {
6898: $checked{'0'} = ' checked="checked"';
6899: }
6900: for my $val (0..2) {
6901: $datatable .= '<span class="LC_nobreak"><label>'.
6902: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6903: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6904: }
6905: } elsif ($row eq 'limit') {
6906: my %checked;
6907: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6908: $checked{$1} = ' checked="checked"';
6909: } else {
6910: $checked{'none'} = ' checked="checked"';
6911: }
6912: my $cap;
6913: if ($currentcap{$type} =~ /^\d+$/) {
6914: $cap = $currentcap{$type};
6915: }
6916: foreach my $val ('none','allstudents','selfenrolled') {
6917: $datatable .= '<span class="LC_nobreak"><label>'.
6918: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6919: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6920: }
6921: $datatable .= '<br />'.
6922: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6923: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6924: '</span>';
6925: }
6926: }
6927: $datatable .= '</td>';
6928: }
6929: $datatable .= '</tr>';
6930: }
6931: $datatable .= '</table></td></tr>';
6932: }
6933: } elsif ($position eq 'bottom') {
1.235 raeburn 6934: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6935: }
6936: $$rowtotal += $itemcount;
6937: return $datatable;
6938: }
6939:
6940: sub print_validation_rows {
6941: my ($caller,$dom,$settings,$rowtotal) = @_;
6942: my ($itemsref,$namesref,$fieldsref);
6943: if ($caller eq 'selfenroll') {
6944: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6945: } elsif ($caller eq 'requestcourses') {
6946: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6947: }
6948: my %currvalidation;
6949: if (ref($settings) eq 'HASH') {
6950: if (ref($settings->{'validation'}) eq 'HASH') {
6951: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6952: }
1.235 raeburn 6953: }
6954: my $datatable;
6955: my $itemcount = 0;
6956: foreach my $item (@{$itemsref}) {
6957: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6958: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6959: $namesref->{$item}.
6960: '</span></td>'.
6961: '<td class="LC_left_item">';
6962: if (($item eq 'url') || ($item eq 'button')) {
6963: $datatable .= '<span class="LC_nobreak">'.
6964: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6965: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6966: } elsif ($item eq 'fields') {
6967: my @currfields;
6968: if (ref($currvalidation{$item}) eq 'ARRAY') {
6969: @currfields = @{$currvalidation{$item}};
6970: }
6971: foreach my $field (@{$fieldsref}) {
6972: my $check = '';
6973: if (grep(/^\Q$field\E$/,@currfields)) {
6974: $check = ' checked="checked"';
6975: }
6976: $datatable .= '<span class="LC_nobreak"><label>'.
6977: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6978: ' value="'.$field.'"'.$check.' />'.$field.
6979: '</label></span> ';
6980: }
6981: } elsif ($item eq 'markup') {
1.334 raeburn 6982: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6983: $currvalidation{$item}.
1.231 raeburn 6984: '</textarea>';
1.235 raeburn 6985: }
6986: $datatable .= '</td></tr>'."\n";
6987: if (ref($rowtotal)) {
1.231 raeburn 6988: $itemcount ++;
6989: }
6990: }
1.235 raeburn 6991: if ($caller eq 'requestcourses') {
6992: my %currhash;
1.248 raeburn 6993: if (ref($settings) eq 'HASH') {
6994: if (ref($settings->{'validation'}) eq 'HASH') {
6995: if ($settings->{'validation'}{'dc'} ne '') {
6996: $currhash{$settings->{'validation'}{'dc'}} = 1;
6997: }
1.235 raeburn 6998: }
6999: }
7000: my $numinrow = 2;
7001: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7002: 'validationdc',%currhash);
1.247 raeburn 7003: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7004: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7005: if ($numdc > 1) {
1.247 raeburn 7006: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7007: } else {
1.247 raeburn 7008: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7009: }
1.247 raeburn 7010: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7011: $itemcount ++;
7012: }
7013: if (ref($rowtotal)) {
7014: $$rowtotal += $itemcount;
7015: }
1.231 raeburn 7016: return $datatable;
7017: }
7018:
1.357 raeburn 7019: sub print_privacy {
7020: my ($position,$dom,$settings,$rowtotal) = @_;
7021: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7022: my $itemcount = 0;
7023: unless ($position eq 'top') {
7024: @items = ('domain','author','course','community');
7025: %names = &Apache::lonlocal::texthash (
7026: domain => 'Assigned domain role(s)',
7027: author => 'Assigned co-author role(s)',
7028: course => 'Assigned course role(s)',
7029: community => 'Assigned community role',
7030: );
7031: $numinrow = 4;
7032: ($othertitle,$usertypes,$types) =
7033: &Apache::loncommon::sorted_inst_types($dom);
7034: }
7035: if (($position eq 'top') || ($position eq 'middle')) {
7036: my (%by_ip,%by_location,@intdoms,@instdoms);
7037: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7038: if ($position eq 'top') {
7039: my %curr;
7040: my @options = ('none','user','domain','auto');
7041: my %titles = &Apache::lonlocal::texthash (
7042: none => 'Not allowed',
7043: user => 'User authorizes',
7044: domain => 'DC authorizes',
7045: auto => 'Unrestricted',
7046: instdom => 'Other domain shares institution/provider',
7047: extdom => 'Other domain has different institution/provider',
7048: );
7049: my %names = &Apache::lonlocal::texthash (
7050: domain => 'Domain role',
7051: author => 'Co-author role',
7052: course => 'Course role',
7053: community => 'Community role',
7054: );
7055: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7056: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7057: foreach my $domtype ('instdom','extdom') {
7058: my (%checked,$skip);
7059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7060: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7061: '<td class="LC_left_item">';
7062: if ($domtype eq 'instdom') {
7063: unless (@instdoms > 1) {
7064: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7065: $skip = 1;
7066: }
7067: } elsif ($domtype eq 'extdom') {
7068: if (keys(%by_location) == 0) {
7069: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7070: $skip = 1;
7071: }
7072: }
7073: unless ($skip) {
7074: foreach my $roletype ('domain','author','course','community') {
7075: $checked{'auto'} = ' checked="checked"';
7076: if (ref($settings) eq 'HASH') {
7077: if (ref($settings->{approval}) eq 'HASH') {
7078: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7079: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7080: $checked{$1} = ' checked="checked"';
7081: $checked{'auto'} = '';
7082: }
7083: }
7084: }
7085: }
7086: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7087: foreach my $option (@options) {
7088: $datatable .= '<span class="LC_nobreak"><label>'.
7089: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7090: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7091: '</label></span> ';
7092: }
7093: $datatable .= '</fieldset>';
7094: }
7095: }
7096: $datatable .= '</td></tr>';
7097: $itemcount ++;
7098: }
7099: } elsif ($position eq 'middle') {
7100: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7101: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7102: foreach my $item (@{$types}) {
7103: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7104: $numinrow,$itemcount,'','','','','',
7105: '',$usertypes->{$item});
7106: $itemcount ++;
7107: }
7108: }
7109: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7110: $numinrow,$itemcount,'','','','','',
7111: '',$othertitle);
7112: $itemcount ++;
7113: } else {
1.360 raeburn 7114: my (@insttypes,%insttitles);
7115: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7116: @insttypes = @{$types};
7117: %insttitles = %{$usertypes};
7118: }
7119: foreach my $item (@insttypes,'default') {
7120: my $title;
7121: if ($item eq 'default') {
7122: $title = $othertitle;
7123: } else {
7124: $title = $insttitles{$item};
7125: }
7126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7127: $datatable .= '<tr'.$css_class.'>'.
7128: '<td class="LC_left_item">'.$title.'</td>'.
7129: '<td class="LC_left_item">'.
7130: &mt('Nothing to set here, as there are no other domains').
7131: '</td></tr>';
7132: $itemcount ++;
7133: }
1.357 raeburn 7134: }
7135: }
7136: } else {
7137: my $prefix;
7138: if ($position eq 'lower') {
7139: $prefix = 'priv';
7140: } else {
7141: $prefix = 'unpriv';
7142: }
7143: foreach my $item (@items) {
7144: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7145: $numinrow,$itemcount,'','','','','',
7146: '',$names{$item});
7147: $itemcount ++;
7148: }
7149: }
7150: if (ref($rowtotal)) {
7151: $$rowtotal += $itemcount;
7152: }
7153: return $datatable;
7154: }
7155:
1.354 raeburn 7156: sub print_passwords {
7157: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7158: my ($datatable,$css_class);
7159: my $itemcount = 0;
7160: my %titles = &Apache::lonlocal::texthash (
7161: captcha => '"Forgot Password" CAPTCHA validation',
7162: link => 'Reset link expiration (hours)',
7163: case => 'Case-sensitive usernames/e-mail',
7164: prelink => 'Information required (form 1)',
7165: postlink => 'Information required (form 2)',
7166: emailsrc => 'LON-CAPA e-mail address type(s)',
7167: customtext => 'Domain specific text (HTML)',
7168: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7169: intauth_check => 'Check bcrypt cost if authenticated',
7170: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7171: permanent => 'Permanent e-mail address',
7172: critical => 'Critical notification address',
7173: notify => 'Notification address',
7174: min => 'Minimum password length',
7175: max => 'Maximum password length',
7176: chars => 'Required characters',
7177: expire => 'Password expiration (days)',
1.356 raeburn 7178: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7179: );
7180: if ($position eq 'top') {
7181: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7182: my $shownlinklife = 2;
7183: my $prelink = 'both';
7184: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7185: if (ref($settings) eq 'HASH') {
7186: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7187: $shownlinklife = $settings->{resetlink};
7188: }
7189: if (ref($settings->{resetcase}) eq 'ARRAY') {
7190: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7191: }
7192: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7193: $prelink = $settings->{resetprelink};
7194: }
7195: if (ref($settings->{resetpostlink}) eq 'HASH') {
7196: %postlink = %{$settings->{resetpostlink}};
7197: }
7198: if (ref($settings->{resetemail}) eq 'ARRAY') {
7199: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7200: }
7201: if ($settings->{resetremove}) {
7202: $nostdtext = 1;
7203: }
7204: if ($settings->{resetcustom}) {
7205: $customurl = $settings->{resetcustom};
7206: }
7207: } else {
7208: if (ref($types) eq 'ARRAY') {
7209: foreach my $item (@{$types}) {
7210: $casesens{$item} = 1;
7211: $postlink{$item} = ['username','email'];
7212: }
7213: }
7214: $casesens{'default'} = 1;
7215: $postlink{'default'} = ['username','email'];
7216: $prelink = 'both';
7217: %emailsrc = (
7218: permanent => 1,
7219: critical => 1,
7220: notify => 1,
7221: );
7222: }
7223: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7224: $itemcount ++;
7225: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7226: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7227: '<td class="LC_left_item">'.
7228: '<input type="textbox" value="'.$shownlinklife.'" '.
7229: 'name="passwords_link" size="3" /></td></tr>';
7230: $itemcount ++;
7231: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7232: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7233: '<td class="LC_left_item">';
7234: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7235: foreach my $item (@{$types}) {
7236: my $checkedcase;
7237: if ($casesens{$item}) {
7238: $checkedcase = ' checked="checked"';
7239: }
7240: $datatable .= '<span class="LC_nobreak"><label>'.
7241: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7242: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7243: '</span> ';
1.354 raeburn 7244: }
7245: }
7246: my $checkedcase;
7247: if ($casesens{'default'}) {
7248: $checkedcase = ' checked="checked"';
7249: }
7250: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7251: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7252: $othertitle.'</label></span></td>';
7253: $itemcount ++;
7254: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7255: my %checkedpre = (
7256: both => ' checked="checked"',
7257: either => '',
7258: );
7259: if ($prelink eq 'either') {
7260: $checkedpre{either} = ' checked="checked"';
7261: $checkedpre{both} = '';
7262: }
7263: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7264: '<td class="LC_left_item"><span class="LC_nobreak">'.
7265: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7266: &mt('Both username and e-mail address').'</label></span> '.
7267: '<span class="LC_nobreak"><label>'.
7268: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7269: &mt('Either username or e-mail address').'</label></span></td></tr>';
7270: $itemcount ++;
7271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7272: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7273: '<td class="LC_left_item">';
7274: my %postlinked;
7275: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7276: foreach my $item (@{$types}) {
7277: undef(%postlinked);
7278: $datatable .= '<fieldset style="display: inline-block;">'.
7279: '<legend>'.$usertypes->{$item}.'</legend>';
7280: if (ref($postlink{$item}) eq 'ARRAY') {
7281: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7282: }
7283: foreach my $field ('email','username') {
7284: my $checked;
7285: if ($postlinked{$field}) {
7286: $checked = ' checked="checked"';
7287: }
7288: $datatable .= '<span class="LC_nobreak"><label>'.
7289: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7290: $field.'"'.$checked.' />'.$field.'</label>'.
7291: '<span> ';
7292: }
7293: $datatable .= '</fieldset>';
7294: }
7295: }
7296: if (ref($postlink{'default'}) eq 'ARRAY') {
7297: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7298: }
7299: $datatable .= '<fieldset style="display: inline-block;">'.
7300: '<legend>'.$othertitle.'</legend>';
7301: foreach my $field ('email','username') {
7302: my $checked;
7303: if ($postlinked{$field}) {
7304: $checked = ' checked="checked"';
7305: }
7306: $datatable .= '<span class="LC_nobreak"><label>'.
7307: '<input type="checkbox" name="passwords_postlink_default" value="'.
7308: $field.'"'.$checked.' />'.$field.'</label>'.
7309: '<span> ';
7310: }
7311: $datatable .= '</fieldset></td></tr>';
7312: $itemcount ++;
7313: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7314: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7315: '<td class="LC_left_item">';
7316: foreach my $type ('permanent','critical','notify') {
7317: my $checkedemail;
7318: if ($emailsrc{$type}) {
7319: $checkedemail = ' checked="checked"';
7320: }
7321: $datatable .= '<span class="LC_nobreak"><label>'.
7322: '<input type="checkbox" name="passwords_emailsrc" value="'.
7323: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7324: '<span> ';
7325: }
7326: $datatable .= '</td></tr>';
7327: $itemcount ++;
7328: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7329: my $switchserver = &check_switchserver($dom,$confname);
7330: my ($showstd,$noshowstd);
7331: if ($nostdtext) {
7332: $noshowstd = ' checked="checked"';
7333: } else {
7334: $showstd = ' checked="checked"';
7335: }
7336: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7337: '<td class="LC_left_item"><span class="LC_nobreak">'.
7338: &mt('Retain standard text:').
7339: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7340: &mt('Yes').'</label>'.' '.
7341: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7342: &mt('No').'</label></span><br />'.
7343: '<span class="LC_fontsize_small">'.
7344: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7345: &mt('Include custom text:');
7346: if ($customurl) {
1.369 raeburn 7347: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7348: undef,undef,undef,undef,'background-color:#ffffff');
7349: $datatable .= '<span class="LC_nobreak"> '.$link.
7350: '<label><input type="checkbox" name="passwords_custom_del"'.
7351: ' value="1" />'.&mt('Delete?').'</label></span>'.
7352: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7353: }
7354: if ($switchserver) {
7355: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7356: } else {
7357: $datatable .='<span class="LC_nobreak"> '.
7358: '<input type="file" name="passwords_customfile" /></span>';
7359: }
7360: $datatable .= '</td></tr>';
7361: } elsif ($position eq 'middle') {
7362: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7363: my @items = ('intauth_cost','intauth_check','intauth_switch');
7364: my %defaults;
7365: if (ref($domconf{'defaults'}) eq 'HASH') {
7366: %defaults = %{$domconf{'defaults'}};
7367: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7368: $defaults{'intauth_cost'} = 10;
7369: }
7370: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7371: $defaults{'intauth_check'} = 0;
7372: }
7373: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7374: $defaults{'intauth_switch'} = 0;
7375: }
7376: } else {
7377: %defaults = (
7378: 'intauth_cost' => 10,
7379: 'intauth_check' => 0,
7380: 'intauth_switch' => 0,
7381: );
7382: }
7383: foreach my $item (@items) {
7384: if ($itemcount%2) {
7385: $css_class = '';
7386: } else {
7387: $css_class = ' class="LC_odd_row" ';
7388: }
7389: $datatable .= '<tr'.$css_class.'>'.
7390: '<td><span class="LC_nobreak">'.$titles{$item}.
7391: '</span></td><td class="LC_left_item" colspan="3">';
7392: if ($item eq 'intauth_switch') {
7393: my @options = (0,1,2);
7394: my %optiondesc = &Apache::lonlocal::texthash (
7395: 0 => 'No',
7396: 1 => 'Yes',
7397: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7398: );
7399: $datatable .= '<table width="100%">';
7400: foreach my $option (@options) {
7401: my $checked = ' ';
7402: if ($defaults{$item} eq $option) {
7403: $checked = ' checked="checked"';
7404: }
7405: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7406: '<label><input type="radio" name="'.$item.
7407: '" value="'.$option.'"'.$checked.' />'.
7408: $optiondesc{$option}.'</label></span></td></tr>';
7409: }
7410: $datatable .= '</table>';
7411: } elsif ($item eq 'intauth_check') {
7412: my @options = (0,1,2);
7413: my %optiondesc = &Apache::lonlocal::texthash (
7414: 0 => 'No',
7415: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7416: 2 => 'Yes, disallow login if stored cost is less than domain default',
7417: );
7418: $datatable .= '<table width="100%">';
7419: foreach my $option (@options) {
7420: my $checked = ' ';
7421: my $onclick;
7422: if ($defaults{$item} eq $option) {
7423: $checked = ' checked="checked"';
7424: }
7425: if ($option == 2) {
7426: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7427: }
7428: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7429: '<label><input type="radio" name="'.$item.
7430: '" value="'.$option.'"'.$checked.$onclick.' />'.
7431: $optiondesc{$option}.'</label></span></td></tr>';
7432: }
7433: $datatable .= '</table>';
7434: } else {
7435: $datatable .= '<input type="text" name="'.$item.'" value="'.
7436: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7437: }
7438: $datatable .= '</td></tr>';
7439: $itemcount ++;
7440: }
7441: } elsif ($position eq 'lower') {
1.356 raeburn 7442: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7443: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7444: if (ref($settings) eq 'HASH') {
7445: if ($settings->{min}) {
7446: $min = $settings->{min};
7447: }
7448: if ($settings->{max}) {
7449: $max = $settings->{max};
7450: }
7451: if (ref($settings->{chars}) eq 'ARRAY') {
7452: map { $chars{$_} = 1; } (@{$settings->{chars}});
7453: }
7454: if ($settings->{expire}) {
7455: $expire = $settings->{expire};
7456: }
1.358 raeburn 7457: if ($settings->{numsaved}) {
7458: $numsaved = $settings->{numsaved};
1.356 raeburn 7459: }
1.354 raeburn 7460: }
7461: my %rulenames = &Apache::lonlocal::texthash(
7462: uc => 'At least one upper case letter',
7463: lc => 'At least one lower case letter',
7464: num => 'At least one number',
7465: spec => 'At least one non-alphanumeric',
7466: );
7467: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7468: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7469: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7470: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7471: 'onblur="javascript:warnIntPass(this);" />'.
7472: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7473: '</span></td></tr>';
7474: $itemcount ++;
7475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7476: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7477: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7478: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7479: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7480: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7481: '</span></td></tr>';
7482: $itemcount ++;
7483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7484: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7485: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7486: '</span></td>';
7487: my $numinrow = 2;
7488: my @possrules = ('uc','lc','num','spec');
7489: $datatable .= '<td class="LC_left_item"><table>';
7490: for (my $i=0; $i<@possrules; $i++) {
7491: my ($rem,$checked);
7492: if ($chars{$possrules[$i]}) {
7493: $checked = ' checked="checked"';
7494: }
7495: $rem = $i%($numinrow);
7496: if ($rem == 0) {
7497: if ($i > 0) {
7498: $datatable .= '</tr>';
7499: }
7500: $datatable .= '<tr>';
7501: }
7502: $datatable .= '<td><span class="LC_nobreak"><label>'.
7503: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7504: $rulenames{$possrules[$i]}.'</label></span></td>';
7505: }
7506: my $rem = @possrules%($numinrow);
7507: my $colsleft = $numinrow - $rem;
7508: if ($colsleft > 1 ) {
7509: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7510: ' </td>';
7511: } elsif ($colsleft == 1) {
7512: $datatable .= '<td class="LC_left_item"> </td>';
7513: }
7514: $datatable .='</table></td></tr>';
7515: $itemcount ++;
7516: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7517: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7518: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7519: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7520: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7521: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7522: '</span></td></tr>';
1.356 raeburn 7523: $itemcount ++;
7524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7525: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7526: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7527: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7528: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7529: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7530: '</span></td></tr>';
1.354 raeburn 7531: } else {
1.359 raeburn 7532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7533: my %ownerchg = (
7534: by => {},
7535: for => {},
7536: );
7537: my %ownertitles = &Apache::lonlocal::texthash (
7538: by => 'Course owner status(es) allowed',
7539: for => 'Student status(es) allowed',
7540: );
1.354 raeburn 7541: if (ref($settings) eq 'HASH') {
1.359 raeburn 7542: if (ref($settings->{crsownerchg}) eq 'HASH') {
7543: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7544: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7545: }
7546: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7547: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7548: }
1.354 raeburn 7549: }
7550: }
7551: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7552: $datatable .= '<tr '.$css_class.'>'.
7553: '<td>'.
7554: &mt('Requirements').'<ul>'.
1.359 raeburn 7555: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7556: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7557: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7558: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7559: '</ul>'.
7560: '</td>'.
1.359 raeburn 7561: '<td class="LC_left_item">';
7562: foreach my $item ('by','for') {
7563: $datatable .= '<fieldset style="display: inline-block;">'.
7564: '<legend>'.$ownertitles{$item}.'</legend>';
7565: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7566: foreach my $type (@{$types}) {
7567: my $checked;
7568: if ($ownerchg{$item}{$type}) {
7569: $checked = ' checked="checked"';
7570: }
7571: $datatable .= '<span class="LC_nobreak"><label>'.
7572: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7573: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7574: '</span> ';
1.359 raeburn 7575: }
7576: }
7577: my $checked;
7578: if ($ownerchg{$item}{'default'}) {
7579: $checked = ' checked="checked"';
7580: }
7581: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7582: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7583: $othertitle.'</label></span></fieldset>';
7584: }
7585: $datatable .= '</td></tr>';
1.354 raeburn 7586: }
7587: return $datatable;
7588: }
7589:
1.373 raeburn 7590: sub print_wafproxy {
7591: my ($position,$dom,$settings,$rowtotal) = @_;
7592: my $css_class;
7593: my $itemcount = 0;
7594: my $datatable;
7595: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7596: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7597: my %lt = &wafproxy_titles();
1.373 raeburn 7598: foreach my $server (sort(keys(%servers))) {
7599: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7600: next if ($serverhome eq '');
1.373 raeburn 7601: my $serverdom;
7602: if ($serverhome ne $server) {
7603: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7604: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7605: $othercontrol{$server} = $serverdom;
7606: }
1.373 raeburn 7607: } else {
7608: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7609: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7610: if ($serverdom ne $dom) {
7611: $othercontrol{$server} = $serverdom;
7612: } else {
7613: $setdom = 1;
7614: if (ref($settings) eq 'HASH') {
7615: if (ref($settings->{'alias'}) eq 'HASH') {
7616: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7617: if ($aliases{$dom} ne '') {
7618: $showdom = 1;
7619: }
1.373 raeburn 7620: }
1.388 raeburn 7621: if (ref($settings->{'saml'}) eq 'HASH') {
7622: $saml{$dom} = $settings->{'saml'};
7623: }
1.373 raeburn 7624: }
7625: }
7626: }
7627: }
1.381 raeburn 7628: if ($setdom) {
7629: %{$values{$dom}} = ();
7630: if (ref($settings) eq 'HASH') {
7631: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7632: $values{$dom}{$item} = $settings->{$item};
7633: }
7634: }
7635: }
1.373 raeburn 7636: if (keys(%othercontrol)) {
7637: %otherdoms = reverse(%othercontrol);
7638: foreach my $domain (keys(%otherdoms)) {
7639: %{$values{$domain}} = ();
7640: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 7641: if (ref($config{'wafproxy'}) eq 'HASH') {
7642: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 7643: if (exists($config{'wafproxy'}{'saml'})) {
7644: $saml{$domain} = $config{'wafproxy'}{'saml'};
7645: }
1.383 raeburn 7646: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7647: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 7648: }
7649: }
7650: }
7651: }
7652: if ($position eq 'top') {
7653: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7654: my %aliasinfo;
1.373 raeburn 7655: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7656: $itemcount ++;
7657: my $dom_in_effect;
7658: my $aliasrows = '<tr>'.
1.383 raeburn 7659: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7660: &mt('Hostname').': '.
7661: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 7662: if ($othercontrol{$server}) {
1.381 raeburn 7663: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 7664: my ($current,$forsaml);
1.383 raeburn 7665: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7666: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 7667: }
1.388 raeburn 7668: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7669: if ($saml{$dom_in_effect}{$server}) {
7670: $forsaml = 1;
7671: }
7672: }
1.383 raeburn 7673: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7674: &mt('Alias').': ';
1.373 raeburn 7675: if ($current) {
1.381 raeburn 7676: $aliasrows .= $current;
1.388 raeburn 7677: if ($forsaml) {
7678: $aliasrows .= ' ('.&mt('also for Shibboleth').')';
7679: }
1.373 raeburn 7680: } else {
1.383 raeburn 7681: $aliasrows .= &mt('None');
1.373 raeburn 7682: }
1.383 raeburn 7683: $aliasrows .= ' <span class="LC_small">('.
7684: &mt('controlled by domain: [_1]',
7685: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 7686: } else {
1.381 raeburn 7687: $dom_in_effect = $dom;
1.388 raeburn 7688: my ($current,$samlon,$samloff);
7689: $samloff = ' checked="checked"';
1.373 raeburn 7690: if (ref($aliases{$dom}) eq 'HASH') {
7691: if ($aliases{$dom}{$server}) {
7692: $current = $aliases{$dom}{$server};
7693: }
7694: }
1.388 raeburn 7695: if (ref($saml{$dom}) eq 'HASH') {
7696: if ($saml{$dom}{$server}) {
7697: $samlon = $samloff;
7698: undef($samloff);
7699: }
7700: }
1.383 raeburn 7701: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7702: &mt('Alias').': '.
1.381 raeburn 7703: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 7704: 'value="'.$current.'" size="30" />'.
7705: (' 'x2).'<span class="LC_nobreak">'.
7706: &mt('Alias used for Shibboleth').': <label>'.
7707: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7708: &mt('No').'</label> <label>'.
7709: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7710: &mt('Yes').'</label></span>'.
7711: '</td>';
1.381 raeburn 7712: }
7713: $aliasrows .= '</tr>';
7714: $aliasinfo{$dom_in_effect} .= $aliasrows;
7715: }
7716: if ($aliasinfo{$dom}) {
7717: my ($onclick,$wafon,$wafoff,$showtable);
7718: $onclick = ' onclick="javascript:toggleWAF();"';
7719: $wafoff = ' checked="checked"';
7720: $showtable = ' style="display:none";';
7721: if ($showdom) {
7722: $wafon = $wafoff;
7723: $wafoff = '';
7724: $showtable = ' style="display:inline;"';
7725: }
7726: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7727: $datatable = '<tr'.$css_class.'>'.
7728: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7729: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7730: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7731: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7732: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7733: &mt('No').'</label></span></td>'.
7734: '<td class="LC_left_item">'.
7735: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7736: '</table></td></tr>';
7737: $itemcount++;
7738: }
1.383 raeburn 7739: if (keys(%otherdoms)) {
7740: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 7741: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 7742: $datatable .= '<tr'.$css_class.'>'.
7743: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7744: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7745: '</table></td></tr>';
1.381 raeburn 7746: $itemcount++;
1.373 raeburn 7747: }
7748: }
7749: } else {
1.383 raeburn 7750: my %ip_methods = &remoteip_methods();
1.373 raeburn 7751: if ($setdom) {
7752: $itemcount ++;
7753: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 7754: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 7755: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 7756: $wafstyle = ' style="display:none;"';
7757: $nowafstyle = ' style="display:table-row;"';
7758: $currwafdisplay = ' style="display: none"';
7759: $wafrangestyle = ' style="display: none"';
7760: $curr_remotip = 'n';
1.382 raeburn 7761: $ssltossl = ' checked="checked"';
1.381 raeburn 7762: if ($showdom) {
7763: $wafstyle = ' style="display:table-row;"';
7764: $nowafstyle = ' style="display:none;"';
7765: if (keys(%{$values{$dom}})) {
7766: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7767: $curr_remotip = $values{$dom}{remoteip};
7768: }
7769: if ($curr_remotip eq 'h') {
7770: $currwafdisplay = ' style="display:table-row"';
7771: $wafrangestyle = ' style="display:inline-block;"';
7772: }
1.382 raeburn 7773: if ($values{$dom}{'sslopt'}) {
7774: $alltossl = ' checked="checked"';
7775: $ssltossl = '';
7776: }
1.381 raeburn 7777: }
7778: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7779: $vpndircheck = ' checked="checked"';
7780: $currwafvpn = ' style="display:table-row;"';
7781: $wafrangestyle = ' style="display:inline-block;"';
7782: } else {
7783: $vpnaliascheck = ' checked="checked"';
7784: $currwafvpn = ' style="display:none;"';
7785: }
7786: }
7787: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7788: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7789: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7790: '</tr>'.
7791: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 7792: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 7793: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7794: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'</div></td>'.
7795: '<td class="LC_left_item"><table>'.
7796: '<tr>'.
7797: '<td valign="top">'.$lt{'remoteip'}.': '.
7798: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7799: foreach my $option ('m','h','n') {
7800: my $sel;
7801: if ($option eq $curr_remotip) {
7802: $sel = ' selected="selected"';
7803: }
7804: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7805: $ip_methods{$option}.'</option>';
7806: }
7807: $datatable .= '</select></td></tr>'."\n".
7808: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7809: $lt{'ipheader'}.': '.
7810: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7811: 'name="wafproxy_ipheader" />'.
7812: '</td></tr>'."\n".
7813: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 7814: $lt{'trusted'}.':<br />'.
1.381 raeburn 7815: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7816: $values{$dom}{'trusted'}.'</textarea>'.
7817: '</td></tr>'."\n".
7818: '<tr><td><hr /></td></tr>'."\n".
7819: '<tr>'.
7820: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7821: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7822: $lt{'vpndirect'}.'</label>'.(' 'x2).
7823: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7824: $lt{'vpnaliased'}.'</label></span></td></tr>';
7825: foreach my $item ('vpnint','vpnext') {
7826: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 7827: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 7828: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7829: $values{$dom}{$item}.'</textarea>'.
7830: '</td></tr>'."\n";
1.373 raeburn 7831: }
1.382 raeburn 7832: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7833: '<tr>'.
7834: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7835: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7836: $lt{'alltossl'}.'</label>'.(' 'x2).
7837: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7838: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7839: '</table></td></tr>';
1.373 raeburn 7840: }
7841: if (keys(%otherdoms)) {
7842: foreach my $domain (sort(keys(%otherdoms))) {
7843: $itemcount ++;
7844: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7845: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 7846: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 7847: '<td class="LC_left_item"><table>';
1.382 raeburn 7848: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 7849: my $showval = &mt('None');
1.382 raeburn 7850: if ($item eq 'ssl') {
7851: $showval = $lt{'ssltossl'};
7852: }
1.373 raeburn 7853: if ($values{$domain}{$item}) {
1.381 raeburn 7854: $showval = $values{$domain}{$item};
1.382 raeburn 7855: if ($item eq 'ssl') {
7856: $showval = $lt{'alltossl'};
1.383 raeburn 7857: } elsif ($item eq 'remoteip') {
7858: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 7859: }
1.373 raeburn 7860: }
7861: $datatable .= '<tr>'.
7862: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7863: }
1.381 raeburn 7864: $datatable .= '</table></td></tr>';
1.373 raeburn 7865: }
7866: }
7867: }
7868: $$rowtotal += $itemcount;
7869: return $datatable;
7870: }
7871:
7872: sub wafproxy_titles {
7873: return &Apache::lonlocal::texthash(
1.381 raeburn 7874: remoteip => "Method for determining user's IP",
7875: ipheader => 'Request header containing remote IP',
7876: trusted => 'Trusted IP range(s)',
7877: vpnaccess => 'Access from institutional VPN',
7878: vpndirect => 'via regular hostname (no WAF)',
7879: vpnaliased => 'via aliased hostname (WAF)',
7880: vpnint => 'Internal IP Range(s) for VPN sessions',
7881: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 7882: sslopt => 'Forwarding http/https',
1.381 raeburn 7883: alltossl => 'WAF forwards both http and https requests to https',
7884: ssltossl => 'WAF forwards http requests to http and https to https',
7885: );
7886: }
7887:
7888: sub remoteip_methods {
7889: return &Apache::lonlocal::texthash(
7890: m => 'Use Apache mod_remoteip',
7891: h => 'Use headers parsed by LON-CAPA',
7892: n => 'Not in use',
1.373 raeburn 7893: );
7894: }
7895:
1.137 raeburn 7896: sub print_usersessions {
7897: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7898: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7899: my (%by_ip,%by_location,@intdoms,@instdoms);
7900: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7901:
7902: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7903: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7904: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7905: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7906: if ($position eq 'top') {
1.152 raeburn 7907: if (keys(%serverhomes) > 1) {
1.145 raeburn 7908: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7909: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7910: if (ref($settings) eq 'HASH') {
7911: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7912: $curroffloadnow = $settings->{'offloadnow'};
7913: }
1.371 raeburn 7914: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7915: $curroffloadoth = $settings->{'offloadoth'};
7916: }
1.261 raeburn 7917: }
1.371 raeburn 7918: my $other_insts = scalar(keys(%by_location));
7919: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7920: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7921: } else {
1.140 raeburn 7922: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7923: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7924: '</td></tr>';
1.140 raeburn 7925: }
1.137 raeburn 7926: } else {
1.279 raeburn 7927: my %titles = &usersession_titles();
7928: my ($prefix,@types);
7929: if ($position eq 'bottom') {
7930: $prefix = 'remote';
7931: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7932: } else {
1.279 raeburn 7933: $prefix = 'hosted';
7934: @types = ('excludedomain','includedomain');
7935: }
7936: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7937: }
7938: $$rowtotal += $itemcount;
7939: return $datatable;
7940: }
7941:
7942: sub rules_by_location {
7943: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7944: my ($datatable,$itemcount,$css_class);
7945: if (keys(%{$by_location}) == 0) {
7946: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7947: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7948: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7949: '</td></tr>';
7950: $itemcount = 1;
7951: } else {
7952: $itemcount = 0;
7953: my $numinrow = 5;
7954: my (%current,%checkedon,%checkedoff);
7955: my @locations = sort(keys(%{$by_location}));
7956: foreach my $type (@{$types}) {
7957: $checkedon{$type} = '';
7958: $checkedoff{$type} = ' checked="checked"';
7959: }
7960: if (ref($settings) eq 'HASH') {
7961: if (ref($settings->{$prefix}) eq 'HASH') {
7962: foreach my $key (keys(%{$settings->{$prefix}})) {
7963: $current{$key} = $settings->{$prefix}{$key};
7964: if ($key eq 'version') {
7965: if ($current{$key} ne '') {
1.145 raeburn 7966: $checkedon{$key} = ' checked="checked"';
7967: $checkedoff{$key} = '';
7968: }
1.279 raeburn 7969: } elsif (ref($current{$key}) eq 'ARRAY') {
7970: $checkedon{$key} = ' checked="checked"';
7971: $checkedoff{$key} = '';
1.137 raeburn 7972: }
7973: }
7974: }
1.279 raeburn 7975: }
7976: foreach my $type (@{$types}) {
7977: next if ($type ne 'version' && !@locations);
7978: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7979: $datatable .= '<tr'.$css_class.'>
7980: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7981: <span class="LC_nobreak">
7982: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7983: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7984: if ($type eq 'version') {
7985: my @lcversions = &Apache::lonnet::all_loncaparevs();
7986: my $selector = '<select name="'.$prefix.'_version">';
7987: foreach my $version (@lcversions) {
7988: my $selected = '';
7989: if ($current{'version'} eq $version) {
7990: $selected = ' selected="selected"';
1.145 raeburn 7991: }
1.279 raeburn 7992: $selector .= ' <option value="'.$version.'"'.
7993: $selected.'>'.$version.'</option>';
7994: }
7995: $selector .= '</select> ';
7996: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7997: } else {
7998: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7999: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8000: ' />'.(' 'x2).
8001: '<input type="button" value="'.&mt('uncheck all').'" '.
8002: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8003: "\n".
8004: '</div><div><table>';
8005: my $rem;
8006: for (my $i=0; $i<@locations; $i++) {
8007: my ($showloc,$value,$checkedtype);
8008: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8009: my $ip = $by_location->{$locations[$i]}->[0];
8010: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8011: $value = join(':',@{$by_ip->{$ip}});
8012: $showloc = join(', ',@{$by_ip->{$ip}});
8013: if (ref($current{$type}) eq 'ARRAY') {
8014: foreach my $loc (@{$by_ip->{$ip}}) {
8015: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8016: $checkedtype = ' checked="checked"';
8017: last;
1.145 raeburn 8018: }
1.138 raeburn 8019: }
8020: }
8021: }
1.137 raeburn 8022: }
1.279 raeburn 8023: $rem = $i%($numinrow);
8024: if ($rem == 0) {
8025: if ($i > 0) {
8026: $datatable .= '</tr>';
8027: }
8028: $datatable .= '<tr>';
8029: }
8030: $datatable .= '<td class="LC_left_item">'.
8031: '<span class="LC_nobreak"><label>'.
8032: '<input type="checkbox" name="'.$prefix.'_'.$type.
8033: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8034: '</label></span></td>';
8035: }
8036: $rem = @locations%($numinrow);
8037: my $colsleft = $numinrow - $rem;
8038: if ($colsleft > 1 ) {
8039: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8040: ' </td>';
8041: } elsif ($colsleft == 1) {
8042: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8043: }
1.279 raeburn 8044: $datatable .= '</tr></table>';
1.137 raeburn 8045: }
1.279 raeburn 8046: $datatable .= '</td></tr>';
8047: $itemcount ++;
1.137 raeburn 8048: }
8049: }
1.279 raeburn 8050: return ($datatable,$itemcount);
1.137 raeburn 8051: }
8052:
1.275 raeburn 8053: sub print_ssl {
8054: my ($position,$dom,$settings,$rowtotal) = @_;
8055: my ($css_class,$datatable);
8056: my $itemcount = 1;
8057: if ($position eq 'top') {
1.281 raeburn 8058: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8059: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8060: my $same_institution;
8061: if ($intdom ne '') {
8062: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8063: if (ref($internet_names) eq 'ARRAY') {
8064: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8065: $same_institution = 1;
8066: }
8067: }
8068: }
1.275 raeburn 8069: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8070: $datatable = '<tr'.$css_class.'><td colspan="2">';
8071: if ($same_institution) {
8072: my %domservers = &Apache::lonnet::get_servers($dom);
8073: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8074: } else {
8075: $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.");
8076: }
8077: $datatable .= '</td></tr>';
1.275 raeburn 8078: $itemcount ++;
8079: } else {
8080: my %titles = &ssl_titles();
8081: my (%by_ip,%by_location,@intdoms,@instdoms);
8082: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8083: my @alldoms = &Apache::lonnet::all_domains();
8084: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8085: my @domservers = &Apache::lonnet::get_servers($dom);
8086: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8087: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8088: if (($position eq 'connto') || ($position eq 'connfrom')) {
8089: my $legacy;
8090: unless (ref($settings) eq 'HASH') {
8091: my $name;
8092: if ($position eq 'connto') {
8093: $name = 'loncAllowInsecure';
8094: } else {
8095: $name = 'londAllowInsecure';
8096: }
8097: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8098: my @ids=&Apache::lonnet::current_machine_ids();
8099: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8100: my %what = (
8101: $name => 1,
8102: );
8103: my ($result,$returnhash) =
8104: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8105: if ($result eq 'ok') {
8106: if (ref($returnhash) eq 'HASH') {
8107: $legacy = $returnhash->{$name};
8108: }
8109: }
8110: } else {
8111: $legacy = $Apache::lonnet::perlvar{$name};
8112: }
8113: }
1.275 raeburn 8114: foreach my $type ('dom','intdom','other') {
8115: my %checked;
8116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8117: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8118: '<td class="LC_right_item">';
8119: my $skip;
8120: if ($type eq 'dom') {
8121: unless (keys(%servers) > 1) {
8122: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8123: $skip = 1;
8124: }
8125: }
8126: if ($type eq 'intdom') {
8127: unless (@instdoms > 1) {
8128: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8129: $skip = 1;
8130: }
8131: } elsif ($type eq 'other') {
8132: if (keys(%by_location) == 0) {
8133: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8134: $skip = 1;
8135: }
8136: }
8137: unless ($skip) {
8138: $checked{'yes'} = ' checked="checked"';
8139: if (ref($settings) eq 'HASH') {
1.293 raeburn 8140: if (ref($settings->{$position}) eq 'HASH') {
8141: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8142: $checked{$1} = $checked{'yes'};
8143: delete($checked{'yes'});
8144: }
8145: }
1.293 raeburn 8146: } else {
8147: if ($legacy == 0) {
8148: $checked{'req'} = $checked{'yes'};
8149: delete($checked{'yes'});
8150: }
1.275 raeburn 8151: }
8152: foreach my $option ('no','yes','req') {
8153: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8154: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8155: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8156: '</label></span>'.(' 'x2);
8157: }
8158: }
8159: $datatable .= '</td></tr>';
8160: $itemcount ++;
8161: }
8162: } else {
8163: my $prefix = 'replication';
8164: my @types = ('certreq','nocertreq');
1.279 raeburn 8165: if (keys(%by_location) == 0) {
8166: $datatable .= '<tr'.$css_class.'><td>'.
8167: &mt('Nothing to set here, as there are no other institutions').
8168: '</td></tr>';
8169: $itemcount ++;
1.275 raeburn 8170: } else {
1.279 raeburn 8171: ($datatable,$itemcount) =
8172: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8173: }
8174: }
8175: }
8176: $$rowtotal += $itemcount;
8177: return $datatable;
8178: }
8179:
8180: sub ssl_titles {
8181: return &Apache::lonlocal::texthash (
8182: dom => 'LON-CAPA servers/VMs from same domain',
8183: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8184: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8185: connto => 'Connections to other servers',
8186: connfrom => 'Connections from other servers',
1.275 raeburn 8187: replication => 'Replicating content to other institutions',
8188: certreq => 'Client certificate required, but specific domains exempt',
8189: nocertreq => 'No client certificate required, except for specific domains',
8190: no => 'SSL not used',
8191: yes => 'SSL Optional (used if available)',
8192: req => 'SSL Required',
8193: );
1.279 raeburn 8194: }
8195:
8196: sub print_trust {
8197: my ($prefix,$dom,$settings,$rowtotal) = @_;
8198: my ($css_class,$datatable,%checked,%choices);
8199: my (%by_ip,%by_location,@intdoms,@instdoms);
8200: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8201: my $itemcount = 1;
8202: my %titles = &trust_titles();
8203: my @types = ('exc','inc');
8204: if ($prefix eq 'top') {
8205: $prefix = 'content';
8206: } elsif ($prefix eq 'bottom') {
8207: $prefix = 'msg';
8208: }
8209: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8210: $$rowtotal += $itemcount;
8211: return $datatable;
8212: }
8213:
8214: sub trust_titles {
8215: return &Apache::lonlocal::texthash(
8216: content => "Access to this domain's content by others",
8217: shared => "Access to other domain's content by this domain",
8218: enroll => "Enrollment in this domain's courses by others",
8219: othcoau => "Co-author roles in this domain for others",
8220: coaurem => "Co-author roles for this domain's users elsewhere",
8221: domroles => "Domain roles in this domain assignable to others",
8222: catalog => "Course Catalog for this domain displayed elsewhere",
8223: reqcrs => "Requests for creation of courses in this domain by others",
8224: msg => "Users in other domains can send messages to this domain",
8225: exc => "Allow all, but exclude specific domains",
8226: inc => "Deny all, but include specific domains",
8227: );
1.275 raeburn 8228: }
8229:
1.138 raeburn 8230: sub build_location_hashes {
1.275 raeburn 8231: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8232: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8233: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8234: my %iphost = &Apache::lonnet::get_iphost();
8235: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8236: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8237: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8238: foreach my $id (@{$iphost{$primary_ip}}) {
8239: my $intdom = &Apache::lonnet::internet_dom($id);
8240: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8241: push(@{$intdoms},$intdom);
8242: }
8243: }
8244: }
8245: foreach my $ip (keys(%iphost)) {
8246: if (ref($iphost{$ip}) eq 'ARRAY') {
8247: foreach my $id (@{$iphost{$ip}}) {
8248: my $location = &Apache::lonnet::internet_dom($id);
8249: if ($location) {
1.275 raeburn 8250: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8251: my $dom = &Apache::lonnet::host_domain($id);
8252: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8253: push(@{$instdoms},$dom);
8254: }
8255: next;
8256: }
1.138 raeburn 8257: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8258: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8259: push(@{$by_ip->{$ip}},$location);
8260: }
8261: } else {
8262: $by_ip->{$ip} = [$location];
8263: }
8264: }
8265: }
8266: }
8267: }
8268: foreach my $ip (sort(keys(%{$by_ip}))) {
8269: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8270: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8271: my $first = $by_ip->{$ip}->[0];
8272: if (ref($by_location->{$first}) eq 'ARRAY') {
8273: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8274: push(@{$by_location->{$first}},$ip);
8275: }
8276: } else {
8277: $by_location->{$first} = [$ip];
8278: }
8279: }
8280: }
8281: return;
8282: }
8283:
1.145 raeburn 8284: sub current_offloads_to {
8285: my ($dom,$settings,$servers) = @_;
8286: my (%spareid,%otherdomconfigs);
1.152 raeburn 8287: if (ref($servers) eq 'HASH') {
1.145 raeburn 8288: foreach my $lonhost (sort(keys(%{$servers}))) {
8289: my $gotspares;
1.152 raeburn 8290: if (ref($settings) eq 'HASH') {
8291: if (ref($settings->{'spares'}) eq 'HASH') {
8292: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8293: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8294: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8295: $gotspares = 1;
8296: }
1.145 raeburn 8297: }
8298: }
8299: unless ($gotspares) {
8300: my $gotspares;
8301: my $serverhomeID =
8302: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8303: my $serverhomedom =
8304: &Apache::lonnet::host_domain($serverhomeID);
8305: if ($serverhomedom ne $dom) {
8306: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8307: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8308: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8309: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8310: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8311: $gotspares = 1;
8312: }
8313: }
8314: } else {
8315: $otherdomconfigs{$serverhomedom} =
8316: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8317: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8318: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8319: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8320: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8321: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8322: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8323: $gotspares = 1;
8324: }
8325: }
8326: }
8327: }
8328: }
8329: }
8330: }
8331: unless ($gotspares) {
8332: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8333: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8334: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8335: } else {
8336: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8337: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8338: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8339: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8340: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8341: } else {
1.150 raeburn 8342: my %what = (
8343: spareid => 1,
8344: );
8345: my ($result,$returnhash) =
8346: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8347: if ($result eq 'ok') {
8348: if (ref($returnhash) eq 'HASH') {
8349: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8350: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8351: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8352: }
8353: }
1.145 raeburn 8354: }
8355: }
8356: }
8357: }
8358: }
8359: }
8360: return %spareid;
8361: }
8362:
8363: sub spares_row {
1.371 raeburn 8364: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8365: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8366: my $css_class;
8367: my $numinrow = 4;
8368: my $itemcount = 1;
8369: my $datatable;
1.152 raeburn 8370: my %typetitles = &sparestype_titles();
8371: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8372: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8373: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8374: my ($othercontrol,$serverdom);
8375: if ($serverhome ne $server) {
8376: $serverdom = &Apache::lonnet::host_domain($serverhome);
8377: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8378: } else {
8379: $serverdom = &Apache::lonnet::host_domain($server);
8380: if ($serverdom ne $dom) {
8381: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8382: }
8383: }
8384: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8385: my ($checkednow,$checkedoth);
1.261 raeburn 8386: if (ref($curroffloadnow) eq 'HASH') {
8387: if ($curroffloadnow->{$server}) {
8388: $checkednow = ' checked="checked"';
8389: }
8390: }
1.371 raeburn 8391: if (ref($curroffloadoth) eq 'HASH') {
8392: if ($curroffloadoth->{$server}) {
8393: $checkedoth = ' checked="checked"';
8394: }
8395: }
1.145 raeburn 8396: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8397: $datatable .= '<tr'.$css_class.'>
8398: <td rowspan="2">
1.183 bisitz 8399: <span class="LC_nobreak">'.
8400: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8401: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8402: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8403: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8404: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8405: "\n";
1.371 raeburn 8406: if ($other_insts) {
8407: $datatable .= '<br />'.
8408: '<span class="LC_nobreak">'."\n".
8409: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8410: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8411: "\n";
8412: }
1.145 raeburn 8413: my (%current,%canselect);
1.152 raeburn 8414: my @choices =
8415: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8416: foreach my $type ('primary','default') {
8417: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8418: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8419: my @spares = @{$spareid->{$server}{$type}};
8420: if (@spares > 0) {
1.152 raeburn 8421: if ($othercontrol) {
8422: $current{$type} = join(', ',@spares);
8423: } else {
8424: $current{$type} .= '<table>';
8425: my $numspares = scalar(@spares);
8426: for (my $i=0; $i<@spares; $i++) {
8427: my $rem = $i%($numinrow);
8428: if ($rem == 0) {
8429: if ($i > 0) {
8430: $current{$type} .= '</tr>';
8431: }
8432: $current{$type} .= '<tr>';
1.145 raeburn 8433: }
1.152 raeburn 8434: $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'".');" /> '.
8435: $spareid->{$server}{$type}[$i].
8436: '</label></td>'."\n";
8437: }
8438: my $rem = @spares%($numinrow);
8439: my $colsleft = $numinrow - $rem;
8440: if ($colsleft > 1 ) {
8441: $current{$type} .= '<td colspan="'.$colsleft.
8442: '" class="LC_left_item">'.
8443: ' </td>';
8444: } elsif ($colsleft == 1) {
8445: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8446: }
1.152 raeburn 8447: $current{$type} .= '</tr></table>';
1.150 raeburn 8448: }
1.145 raeburn 8449: }
8450: }
8451: if ($current{$type} eq '') {
8452: $current{$type} = &mt('None specified');
8453: }
1.152 raeburn 8454: if ($othercontrol) {
8455: if ($type eq 'primary') {
8456: $canselect{$type} = $othercontrol;
8457: }
8458: } else {
8459: $canselect{$type} =
8460: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8461: '<select name="newspare_'.$type.'_'.$server.'" '.
8462: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8463: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8464: if (@choices > 0) {
8465: foreach my $lonhost (@choices) {
8466: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8467: }
8468: }
8469: $canselect{$type} .= '</select>'."\n";
8470: }
8471: } else {
8472: $current{$type} = &mt('Could not be determined');
8473: if ($type eq 'primary') {
8474: $canselect{$type} = $othercontrol;
8475: }
1.145 raeburn 8476: }
1.152 raeburn 8477: if ($type eq 'default') {
8478: $datatable .= '<tr'.$css_class.'>';
8479: }
8480: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8481: '<td>'.$current{$type}.'</td>'."\n".
8482: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8483: }
8484: $itemcount ++;
8485: }
8486: }
8487: $$rowtotal += $itemcount;
8488: return $datatable;
8489: }
8490:
1.152 raeburn 8491: sub possible_newspares {
8492: my ($server,$currspares,$serverhomes,$altids) = @_;
8493: my $serverhostname = &Apache::lonnet::hostname($server);
8494: my %excluded;
8495: if ($serverhostname ne '') {
8496: %excluded = (
8497: $serverhostname => 1,
8498: );
8499: }
8500: if (ref($currspares) eq 'HASH') {
8501: foreach my $type (keys(%{$currspares})) {
8502: if (ref($currspares->{$type}) eq 'ARRAY') {
8503: if (@{$currspares->{$type}} > 0) {
8504: foreach my $curr (@{$currspares->{$type}}) {
8505: my $hostname = &Apache::lonnet::hostname($curr);
8506: $excluded{$hostname} = 1;
8507: }
8508: }
8509: }
8510: }
8511: }
8512: my @choices;
8513: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8514: if (keys(%{$serverhomes}) > 1) {
8515: foreach my $name (sort(keys(%{$serverhomes}))) {
8516: unless ($excluded{$name}) {
8517: if (exists($altids->{$serverhomes->{$name}})) {
8518: push(@choices,$altids->{$serverhomes->{$name}});
8519: } else {
8520: push(@choices,$serverhomes->{$name});
1.145 raeburn 8521: }
8522: }
8523: }
8524: }
8525: }
1.152 raeburn 8526: return sort(@choices);
1.145 raeburn 8527: }
8528:
1.150 raeburn 8529: sub print_loadbalancing {
8530: my ($dom,$settings,$rowtotal) = @_;
8531: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8532: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8533: my $numinrow = 1;
8534: my $datatable;
8535: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8536: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8537: if (ref($settings) eq 'HASH') {
8538: %existing = %{$settings};
8539: }
8540: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8541: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8542: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8543: } else {
8544: return;
8545: }
8546: my ($othertitle,$usertypes,$types) =
8547: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8548: my $rownum = 8;
1.150 raeburn 8549: if (ref($types) eq 'ARRAY') {
8550: $rownum += scalar(@{$types});
8551: }
1.171 raeburn 8552: my @css_class = ('LC_odd_row','LC_even_row');
8553: my $balnum = 0;
8554: my $islast;
8555: my (@toshow,$disabledtext);
8556: if (keys(%currbalancer) > 0) {
8557: @toshow = sort(keys(%currbalancer));
8558: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8559: push(@toshow,'');
8560: }
8561: } else {
8562: @toshow = ('');
8563: $disabledtext = &mt('No existing load balancer');
8564: }
8565: foreach my $lonhost (@toshow) {
8566: if ($balnum == scalar(@toshow)-1) {
8567: $islast = 1;
8568: } else {
8569: $islast = 0;
8570: }
8571: my $cssidx = $balnum%2;
8572: my $targets_div_style = 'display: none';
8573: my $disabled_div_style = 'display: block';
8574: my $homedom_div_style = 'display: none';
8575: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8576: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8577: '<p>';
8578: if ($lonhost eq '') {
1.210 raeburn 8579: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8580: if (keys(%currbalancer) > 0) {
8581: $datatable .= &mt('Add balancer:');
8582: } else {
8583: $datatable .= &mt('Enable balancer:');
8584: }
8585: $datatable .= ' '.
8586: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8587: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8588: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8589: '<option value="" selected="selected">'.&mt('None').
8590: '</option>'."\n";
8591: foreach my $server (sort(keys(%servers))) {
8592: next if ($currbalancer{$server});
8593: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8594: }
1.210 raeburn 8595: $datatable .=
1.171 raeburn 8596: '</select>'."\n".
8597: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8598: } else {
8599: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8600: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8601: &mt('Stop balancing').'</label>'.
8602: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8603: $targets_div_style = 'display: block';
8604: $disabled_div_style = 'display: none';
8605: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8606: $homedom_div_style = 'display: block';
8607: }
8608: }
1.306 raeburn 8609: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8610: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8611: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8612: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8613: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8614: my @sparestypes = ('primary','default');
8615: my %typetitles = &sparestype_titles();
1.284 raeburn 8616: my %hostherechecked = (
8617: no => ' checked="checked"',
8618: );
1.342 raeburn 8619: my %balcookiechecked = (
8620: no => ' checked="checked"',
8621: );
1.171 raeburn 8622: foreach my $sparetype (@sparestypes) {
8623: my $targettable;
8624: for (my $i=0; $i<$numspares; $i++) {
8625: my $checked;
8626: if (ref($currtargets{$lonhost}) eq 'HASH') {
8627: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8628: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8629: $checked = ' checked="checked"';
8630: }
8631: }
8632: }
8633: my ($chkboxval,$disabled);
8634: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8635: $chkboxval = $spares[$i];
8636: }
8637: if (exists($currbalancer{$spares[$i]})) {
8638: $disabled = ' disabled="disabled"';
8639: }
1.210 raeburn 8640: $targettable .=
1.253 raeburn 8641: '<td><span class="LC_nobreak"><label>'.
8642: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8643: $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 8644: '</span></label></span></td>';
1.171 raeburn 8645: my $rem = $i%($numinrow);
8646: if ($rem == 0) {
8647: if (($i > 0) && ($i < $numspares-1)) {
8648: $targettable .= '</tr>';
8649: }
8650: if ($i < $numspares-1) {
8651: $targettable .= '<tr>';
1.150 raeburn 8652: }
8653: }
8654: }
1.171 raeburn 8655: if ($targettable ne '') {
8656: my $rem = $numspares%($numinrow);
8657: my $colsleft = $numinrow - $rem;
8658: if ($colsleft > 1 ) {
8659: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8660: ' </td>';
8661: } elsif ($colsleft == 1) {
8662: $targettable .= '<td class="LC_left_item"> </td>';
8663: }
8664: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8665: '<table><tr>'.$targettable.'</tr></table><br />';
8666: }
1.284 raeburn 8667: $hostherechecked{$sparetype} = '';
8668: if (ref($currtargets{$lonhost}) eq 'HASH') {
8669: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8670: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8671: $hostherechecked{$sparetype} = ' checked="checked"';
8672: $hostherechecked{'no'} = '';
8673: }
8674: }
8675: }
8676: }
1.342 raeburn 8677: if ($currcookies{$lonhost}) {
8678: %balcookiechecked = (
8679: yes => ' checked="checked"',
8680: );
8681: }
1.284 raeburn 8682: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8683: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8684: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8685: foreach my $sparetype (@sparestypes) {
8686: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8687: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8688: '</i></label><br />';
1.171 raeburn 8689: }
1.342 raeburn 8690: $datatable .= &mt('Use balancer cookie').'<br />'.
8691: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8692: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8693: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8694: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8695: '</div></td></tr>'.
1.171 raeburn 8696: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8697: $othertitle,$usertypes,$types,\%servers,
8698: \%currbalancer,$lonhost,
8699: $targets_div_style,$homedom_div_style,
8700: $css_class[$cssidx],$balnum,$islast);
8701: $$rowtotal += $rownum;
8702: $balnum ++;
8703: }
8704: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8705: return $datatable;
8706: }
8707:
8708: sub get_loadbalancers_config {
1.342 raeburn 8709: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8710: return unless ((ref($servers) eq 'HASH') &&
8711: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8712: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8713: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8714: if (keys(%{$existing}) > 0) {
8715: my $oldlonhost;
8716: foreach my $key (sort(keys(%{$existing}))) {
8717: if ($key eq 'lonhost') {
8718: $oldlonhost = $existing->{'lonhost'};
8719: $currbalancer->{$oldlonhost} = 1;
8720: } elsif ($key eq 'targets') {
8721: if ($oldlonhost) {
8722: $currtargets->{$oldlonhost} = $existing->{'targets'};
8723: }
8724: } elsif ($key eq 'rules') {
8725: if ($oldlonhost) {
8726: $currrules->{$oldlonhost} = $existing->{'rules'};
8727: }
8728: } elsif (ref($existing->{$key}) eq 'HASH') {
8729: $currbalancer->{$key} = 1;
8730: $currtargets->{$key} = $existing->{$key}{'targets'};
8731: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8732: if ($existing->{$key}{'cookie'}) {
8733: $currcookies->{$key} = 1;
8734: }
1.150 raeburn 8735: }
8736: }
1.171 raeburn 8737: } else {
8738: my ($balancerref,$targetsref) =
8739: &Apache::lonnet::get_lonbalancer_config($servers);
8740: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8741: foreach my $server (sort(keys(%{$balancerref}))) {
8742: $currbalancer->{$server} = 1;
8743: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8744: }
8745: }
8746: }
1.171 raeburn 8747: return;
1.150 raeburn 8748: }
8749:
8750: sub loadbalancing_rules {
8751: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8752: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8753: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8754: my $output;
1.171 raeburn 8755: my $num = 0;
1.210 raeburn 8756: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8757: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8758: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8759: foreach my $type (@{$alltypes}) {
1.171 raeburn 8760: $num ++;
1.150 raeburn 8761: my $current;
8762: if (ref($currrules) eq 'HASH') {
8763: $current = $currrules->{$type};
8764: }
1.253 raeburn 8765: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8766: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8767: $current = '';
8768: }
8769: }
8770: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8771: $servers,$currbalancer,$lonhost,$dom,
8772: $targets_div_style,$homedom_div_style,
8773: $css_class,$balnum,$num,$islast);
1.150 raeburn 8774: }
8775: }
8776: return $output;
8777: }
8778:
8779: sub loadbalancing_titles {
8780: my ($dom,$intdom,$usertypes,$types) = @_;
8781: my %othertypes = (
8782: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8783: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8784: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8785: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8786: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8787: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8788: );
1.209 raeburn 8789: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8790: my @available;
1.150 raeburn 8791: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8792: @available = @{$types};
1.150 raeburn 8793: }
1.302 raeburn 8794: unless (grep(/^default$/,@available)) {
8795: push(@available,'default');
8796: }
8797: unshift(@alltypes,@available);
1.150 raeburn 8798: my %titles;
8799: foreach my $type (@alltypes) {
8800: if ($type =~ /^_LC_/) {
8801: $titles{$type} = $othertypes{$type};
8802: } elsif ($type eq 'default') {
8803: $titles{$type} = &mt('All users from [_1]',$dom);
8804: if (ref($types) eq 'ARRAY') {
8805: if (@{$types} > 0) {
8806: $titles{$type} = &mt('Other users from [_1]',$dom);
8807: }
8808: }
8809: } elsif (ref($usertypes) eq 'HASH') {
8810: $titles{$type} = $usertypes->{$type};
8811: }
8812: }
8813: return (\@alltypes,\%othertypes,\%titles);
8814: }
8815:
8816: sub loadbalance_rule_row {
1.171 raeburn 8817: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8818: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8819: my @rulenames;
1.150 raeburn 8820: my %ruletitles = &offloadtype_text();
1.209 raeburn 8821: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8822: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8823: } else {
1.209 raeburn 8824: @rulenames = ('default','homeserver');
8825: if ($type eq '_LC_external') {
8826: push(@rulenames,'externalbalancer');
8827: } else {
8828: push(@rulenames,'specific');
8829: }
8830: push(@rulenames,'none');
1.150 raeburn 8831: }
8832: my $style = $targets_div_style;
1.253 raeburn 8833: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8834: $style = $homedom_div_style;
8835: }
1.171 raeburn 8836: my $space;
8837: if ($islast && $num == 1) {
1.317 raeburn 8838: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8839: }
1.210 raeburn 8840: my $output =
1.306 raeburn 8841: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8842: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8843: '<td valaign="top">'.$space.
8844: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8845: for (my $i=0; $i<@rulenames; $i++) {
8846: my $rule = $rulenames[$i];
8847: my ($checked,$extra);
8848: if ($rulenames[$i] eq 'default') {
8849: $rule = '';
8850: }
8851: if ($rulenames[$i] eq 'specific') {
8852: if (ref($servers) eq 'HASH') {
8853: my $default;
8854: if (($current ne '') && (exists($servers->{$current}))) {
8855: $checked = ' checked="checked"';
8856: }
8857: unless ($checked) {
8858: $default = ' selected="selected"';
8859: }
1.210 raeburn 8860: $extra =
1.171 raeburn 8861: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8862: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8863: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8864: '<option value=""'.$default.'></option>'."\n";
8865: foreach my $server (sort(keys(%{$servers}))) {
8866: if (ref($currbalancer) eq 'HASH') {
8867: next if (exists($currbalancer->{$server}));
8868: }
1.150 raeburn 8869: my $selected;
1.171 raeburn 8870: if ($server eq $current) {
1.150 raeburn 8871: $selected = ' selected="selected"';
8872: }
1.171 raeburn 8873: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8874: }
8875: $extra .= '</select>';
8876: }
8877: } elsif ($rule eq $current) {
8878: $checked = ' checked="checked"';
8879: }
8880: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8881: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8882: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8883: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8884: ')"'.$checked.' /> ';
8885: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8886: $output .= $ruletitles{'particular'};
8887: } else {
8888: $output .= $ruletitles{$rulenames[$i]};
8889: }
8890: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8891: }
8892: $output .= '</div></td></tr>'."\n";
8893: return $output;
8894: }
8895:
8896: sub offloadtype_text {
8897: my %ruletitles = &Apache::lonlocal::texthash (
8898: 'default' => 'Offloads to default destinations',
8899: 'homeserver' => "Offloads to user's home server",
8900: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8901: 'specific' => 'Offloads to specific server',
1.161 raeburn 8902: 'none' => 'No offload',
1.209 raeburn 8903: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8904: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8905: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8906: );
8907: return %ruletitles;
8908: }
8909:
8910: sub sparestype_titles {
8911: my %typestitles = &Apache::lonlocal::texthash (
8912: 'primary' => 'primary',
8913: 'default' => 'default',
8914: );
8915: return %typestitles;
8916: }
8917:
1.28 raeburn 8918: sub contact_titles {
8919: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8920: 'supportemail' => 'Support E-mail address',
8921: 'adminemail' => 'Default Server Admin E-mail address',
8922: 'errormail' => 'Error reports to be e-mailed to',
8923: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8924: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8925: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8926: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8927: 'requestsmail' => 'E-mail from course requests requiring approval',
8928: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8929: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8930: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 8931: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8932: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 8933: 'errorweights' => 'Weights used to compute error count',
8934: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8935: );
8936: my %short_titles = &Apache::lonlocal::texthash (
8937: adminemail => 'Admin E-mail address',
8938: supportemail => 'Support E-mail',
8939: );
8940: return (\%titles,\%short_titles);
8941: }
8942:
1.286 raeburn 8943: sub helpform_fields {
8944: my %titles = &Apache::lonlocal::texthash (
8945: 'username' => 'Name',
8946: 'user' => 'Username/domain',
8947: 'phone' => 'Phone',
8948: 'cc' => 'Cc e-mail',
8949: 'course' => 'Course Details',
8950: 'section' => 'Sections',
1.289 raeburn 8951: 'screenshot' => 'File upload',
1.286 raeburn 8952: );
8953: my @fields = ('username','phone','user','course','section','cc','screenshot');
8954: my %possoptions = (
8955: username => ['yes','no','req'],
1.289 raeburn 8956: phone => ['yes','no','req'],
1.286 raeburn 8957: user => ['yes','no'],
1.289 raeburn 8958: cc => ['yes','no'],
1.286 raeburn 8959: course => ['yes','no'],
8960: section => ['yes','no'],
8961: screenshot => ['yes','no'],
8962: );
8963: my %fieldoptions = &Apache::lonlocal::texthash (
8964: 'yes' => 'Optional',
8965: 'req' => 'Required',
8966: 'no' => "Not shown",
8967: );
8968: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8969: }
8970:
1.72 raeburn 8971: sub tool_titles {
8972: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8973: aboutme => 'Personal web page',
1.86 raeburn 8974: blog => 'Blog',
1.162 raeburn 8975: webdav => 'WebDAV',
1.86 raeburn 8976: portfolio => 'Portfolio',
1.88 bisitz 8977: official => 'Official courses (with institutional codes)',
8978: unofficial => 'Unofficial courses',
1.98 raeburn 8979: community => 'Communities',
1.216 raeburn 8980: textbook => 'Textbook courses',
1.271 raeburn 8981: placement => 'Placement tests',
1.86 raeburn 8982: );
1.72 raeburn 8983: return %titles;
8984: }
8985:
1.101 raeburn 8986: sub courserequest_titles {
8987: my %titles = &Apache::lonlocal::texthash (
8988: official => 'Official',
8989: unofficial => 'Unofficial',
8990: community => 'Communities',
1.216 raeburn 8991: textbook => 'Textbook',
1.271 raeburn 8992: placement => 'Placement tests',
1.325 raeburn 8993: lti => 'LTI Provider',
1.101 raeburn 8994: norequest => 'Not allowed',
1.325 raeburn 8995: approval => 'Approval by DC',
1.101 raeburn 8996: validate => 'With validation',
8997: autolimit => 'Numerical limit',
1.103 raeburn 8998: unlimited => '(blank for unlimited)',
1.101 raeburn 8999: );
9000: return %titles;
9001: }
9002:
1.163 raeburn 9003: sub authorrequest_titles {
9004: my %titles = &Apache::lonlocal::texthash (
9005: norequest => 'Not allowed',
9006: approval => 'Approval by Dom. Coord.',
9007: automatic => 'Automatic approval',
9008: );
9009: return %titles;
1.210 raeburn 9010: }
1.163 raeburn 9011:
1.101 raeburn 9012: sub courserequest_conditions {
9013: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9014: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9015: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9016: );
9017: return %conditions;
9018: }
9019:
9020:
1.27 raeburn 9021: sub print_usercreation {
1.30 raeburn 9022: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9023: my $numinrow = 4;
1.28 raeburn 9024: my $datatable;
9025: if ($position eq 'top') {
1.30 raeburn 9026: $$rowtotal ++;
1.34 raeburn 9027: my $rowcount = 0;
1.32 raeburn 9028: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9029: if (ref($rules) eq 'HASH') {
9030: if (keys(%{$rules}) > 0) {
1.32 raeburn 9031: $datatable .= &user_formats_row('username',$settings,$rules,
9032: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9033: $$rowtotal ++;
1.32 raeburn 9034: $rowcount ++;
9035: }
9036: }
9037: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9038: if (ref($idrules) eq 'HASH') {
9039: if (keys(%{$idrules}) > 0) {
9040: $datatable .= &user_formats_row('id',$settings,$idrules,
9041: $idruleorder,$numinrow,$rowcount);
9042: $$rowtotal ++;
9043: $rowcount ++;
1.28 raeburn 9044: }
9045: }
1.39 raeburn 9046: if ($rowcount == 0) {
9047: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9048: $$rowtotal ++;
9049: $rowcount ++;
9050: }
1.34 raeburn 9051: } elsif ($position eq 'middle') {
1.224 raeburn 9052: my @creators = ('author','course','requestcrs');
1.37 raeburn 9053: my ($rules,$ruleorder) =
9054: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9055: my %lt = &usercreation_types();
9056: my %checked;
9057: if (ref($settings) eq 'HASH') {
9058: if (ref($settings->{'cancreate'}) eq 'HASH') {
9059: foreach my $item (@creators) {
9060: $checked{$item} = $settings->{'cancreate'}{$item};
9061: }
9062: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9063: foreach my $item (@creators) {
9064: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9065: $checked{$item} = 'none';
9066: }
9067: }
9068: }
9069: }
9070: my $rownum = 0;
9071: foreach my $item (@creators) {
9072: $rownum ++;
1.224 raeburn 9073: if ($checked{$item} eq '') {
9074: $checked{$item} = 'any';
1.34 raeburn 9075: }
9076: my $css_class;
9077: if ($rownum%2) {
9078: $css_class = '';
9079: } else {
9080: $css_class = ' class="LC_odd_row" ';
9081: }
9082: $datatable .= '<tr'.$css_class.'>'.
9083: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9084: '</span></td><td style="text-align: right">';
1.224 raeburn 9085: my @options = ('any');
9086: if (ref($rules) eq 'HASH') {
9087: if (keys(%{$rules}) > 0) {
9088: push(@options,('official','unofficial'));
1.37 raeburn 9089: }
9090: }
1.224 raeburn 9091: push(@options,'none');
1.37 raeburn 9092: foreach my $option (@options) {
1.50 raeburn 9093: my $type = 'radio';
1.34 raeburn 9094: my $check = ' ';
1.224 raeburn 9095: if ($checked{$item} eq $option) {
9096: $check = ' checked="checked" ';
1.34 raeburn 9097: }
9098: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9099: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9100: $item.'" value="'.$option.'"'.$check.'/> '.
9101: $lt{$option}.'</label> </span>';
9102: }
9103: $datatable .= '</td></tr>';
9104: }
1.28 raeburn 9105: } else {
9106: my @contexts = ('author','course','domain');
1.325 raeburn 9107: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9108: my %checked;
9109: if (ref($settings) eq 'HASH') {
9110: if (ref($settings->{'authtypes'}) eq 'HASH') {
9111: foreach my $item (@contexts) {
9112: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9113: foreach my $auth (@authtypes) {
9114: if ($settings->{'authtypes'}{$item}{$auth}) {
9115: $checked{$item}{$auth} = ' checked="checked" ';
9116: }
9117: }
9118: }
9119: }
1.27 raeburn 9120: }
1.35 raeburn 9121: } else {
9122: foreach my $item (@contexts) {
1.36 raeburn 9123: foreach my $auth (@authtypes) {
1.35 raeburn 9124: $checked{$item}{$auth} = ' checked="checked" ';
9125: }
9126: }
1.27 raeburn 9127: }
1.28 raeburn 9128: my %title = &context_names();
9129: my %authname = &authtype_names();
9130: my $rownum = 0;
9131: my $css_class;
9132: foreach my $item (@contexts) {
9133: if ($rownum%2) {
9134: $css_class = '';
9135: } else {
9136: $css_class = ' class="LC_odd_row" ';
9137: }
1.30 raeburn 9138: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9139: '<td>'.$title{$item}.
9140: '</td><td class="LC_left_item">'.
9141: '<span class="LC_nobreak">';
9142: foreach my $auth (@authtypes) {
9143: $datatable .= '<label>'.
9144: '<input type="checkbox" name="'.$item.'_auth" '.
9145: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9146: $authname{$auth}.'</label> ';
9147: }
9148: $datatable .= '</span></td></tr>';
9149: $rownum ++;
1.27 raeburn 9150: }
1.30 raeburn 9151: $$rowtotal += $rownum;
1.27 raeburn 9152: }
9153: return $datatable;
9154: }
9155:
1.224 raeburn 9156: sub print_selfcreation {
9157: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9158: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9159: $emaildomain,$datatable);
1.224 raeburn 9160: if (ref($settings) eq 'HASH') {
9161: if (ref($settings->{'cancreate'}) eq 'HASH') {
9162: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9163: if (ref($createsettings) eq 'HASH') {
9164: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9165: @selfcreate = @{$createsettings->{'selfcreate'}};
9166: } elsif ($createsettings->{'selfcreate'} ne '') {
9167: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9168: @selfcreate = ('email','login','sso');
9169: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9170: @selfcreate = ($createsettings->{'selfcreate'});
9171: }
9172: }
9173: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9174: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9175: }
1.305 raeburn 9176: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9177: $emailoptions = $createsettings->{'emailoptions'};
9178: }
1.303 raeburn 9179: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9180: $emailverified = $createsettings->{'emailverified'};
9181: }
9182: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9183: $emaildomain = $createsettings->{'emaildomain'};
9184: }
1.224 raeburn 9185: }
9186: }
9187: }
9188: my %radiohash;
9189: my $numinrow = 4;
9190: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9191: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9192: if ($position eq 'top') {
9193: my %choices = &Apache::lonlocal::texthash (
9194: cancreate_login => 'Institutional Login',
9195: cancreate_sso => 'Institutional Single Sign On',
9196: );
9197: my @toggles = sort(keys(%choices));
9198: my %defaultchecked = (
9199: 'cancreate_login' => 'off',
9200: 'cancreate_sso' => 'off',
9201: );
1.228 raeburn 9202: my ($onclick,$itemcount);
1.224 raeburn 9203: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9204: \%choices,$itemcount,$onclick);
1.228 raeburn 9205: $$rowtotal += $itemcount;
9206:
1.224 raeburn 9207: if (ref($usertypes) eq 'HASH') {
9208: if (keys(%{$usertypes}) > 0) {
9209: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9210: $dom,$numinrow,$othertitle,
1.305 raeburn 9211: 'statustocreate',$rowtotal);
1.224 raeburn 9212: $$rowtotal ++;
9213: }
9214: }
1.240 raeburn 9215: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9216: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9217: $fieldtitles{'inststatus'} = &mt('Institutional status');
9218: my $rem;
9219: my $numperrow = 2;
9220: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9221: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9222: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9223: '<td class="LC_left_item">'."\n".
1.334 raeburn 9224: '<table>'."\n";
1.240 raeburn 9225: for (my $i=0; $i<@fields; $i++) {
9226: $rem = $i%($numperrow);
9227: if ($rem == 0) {
9228: if ($i > 0) {
9229: $datatable .= '</tr>';
9230: }
9231: $datatable .= '<tr>';
9232: }
9233: my $currval;
1.248 raeburn 9234: if (ref($createsettings) eq 'HASH') {
9235: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9236: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9237: }
1.240 raeburn 9238: }
9239: $datatable .= '<td class="LC_left_item">'.
9240: '<span class="LC_nobreak">'.
9241: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9242: 'value="'.$currval.'" size="10" /> '.
9243: $fieldtitles{$fields[$i]}.'</span></td>';
9244: }
9245: my $colsleft = $numperrow - $rem;
9246: if ($colsleft > 1 ) {
9247: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9248: ' </td>';
9249: } elsif ($colsleft == 1) {
9250: $datatable .= '<td class="LC_left_item"> </td>';
9251: }
9252: $datatable .= '</tr></table></td></tr>';
9253: $$rowtotal ++;
1.224 raeburn 9254: } elsif ($position eq 'middle') {
9255: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9256: my @posstypes;
1.224 raeburn 9257: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9258: @posstypes = @{$types};
9259: }
9260: unless (grep(/^default$/,@posstypes)) {
9261: push(@posstypes,'default');
9262: }
9263: my %usertypeshash;
9264: if (ref($usertypes) eq 'HASH') {
9265: %usertypeshash = %{$usertypes};
9266: }
9267: $usertypeshash{'default'} = $othertitle;
9268: foreach my $status (@posstypes) {
9269: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9270: $numinrow,$$rowtotal,\%usertypeshash);
9271: $$rowtotal ++;
1.224 raeburn 9272: }
9273: } else {
1.236 raeburn 9274: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9275: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9276: );
9277: my @toggles = sort(keys(%choices));
9278: my %defaultchecked = (
9279: 'cancreate_email' => 'off',
9280: );
1.305 raeburn 9281: my $customclass = 'LC_selfcreate_email';
9282: my $classprefix = 'LC_canmodify_emailusername_';
9283: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9284: my $display = 'none';
1.305 raeburn 9285: my $rowstyle = 'display:none';
1.236 raeburn 9286: if (grep(/^\Qemail\E$/,@selfcreate)) {
9287: $display = 'block';
1.305 raeburn 9288: $rowstyle = 'display:table-row';
1.236 raeburn 9289: }
1.305 raeburn 9290: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9291: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9292: \%choices,$$rowtotal,$onclick);
9293: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9294: $rowstyle);
9295: $$rowtotal ++;
9296: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9297: $rowstyle);
9298: $$rowtotal ++;
9299: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9300: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9301: my ($emailrules,$emailruleorder) =
9302: &Apache::lonnet::inst_userrules($dom,'email');
9303: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9304: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9305: if (ref($types) eq 'ARRAY') {
9306: @posstypes = @{$types};
9307: }
9308: if (@posstypes) {
9309: unless (grep(/^default$/,@posstypes)) {
9310: push(@posstypes,'default');
1.302 raeburn 9311: }
9312: if (ref($usertypes) eq 'HASH') {
9313: %usertypeshash = %{$usertypes};
9314: }
1.305 raeburn 9315: my $currassign;
9316: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9317: $currassign = {
9318: selfassign => $domdefaults{'inststatusguest'},
9319: };
9320: @ordered = @{$domdefaults{'inststatusguest'}};
9321: } else {
9322: $currassign = { selfassign => [] };
9323: }
9324: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9325: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9326: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9327: $numinrow,$othertitle,'selfassign',
9328: $rowtotal,$onclicktypes,$customclass,
9329: $rowstyle);
9330: $$rowtotal ++;
1.302 raeburn 9331: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9332: foreach my $status (@posstypes) {
9333: my $css_class;
9334: if ($$rowtotal%2) {
9335: $css_class = 'LC_odd_row ';
9336: }
9337: $css_class .= $customclass;
9338: my $rowid = $optionsprefix.$status;
9339: my $hidden = 1;
9340: my $currstyle = 'display:none';
9341: if (grep(/^\Q$status\E$/,@ordered)) {
9342: $currstyle = $rowstyle;
9343: $hidden = 0;
9344: }
9345: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9346: $emailrules,$emailruleorder,$settings,$status,$rowid,
9347: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9348: unless ($hidden) {
9349: $$rowtotal ++;
9350: }
1.224 raeburn 9351: }
1.302 raeburn 9352: } else {
1.305 raeburn 9353: my $css_class;
9354: if ($$rowtotal%2) {
9355: $css_class = 'LC_odd_row ';
9356: }
9357: $css_class .= $customclass;
1.302 raeburn 9358: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9359: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9360: $emailrules,$emailruleorder,$settings,'default','',
9361: $othertitle,$css_class,$rowstyle,$intdom);
9362: $$rowtotal ++;
1.224 raeburn 9363: }
9364: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9365: $numinrow = 1;
1.305 raeburn 9366: if (@posstypes) {
9367: foreach my $status (@posstypes) {
9368: my $rowid = $classprefix.$status;
9369: my $datarowstyle = 'display:none';
9370: if (grep(/^\Q$status\E$/,@ordered)) {
9371: $datarowstyle = $rowstyle;
9372: }
9373: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9374: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9375: $infotitles,$rowid,$customclass,$datarowstyle);
9376: unless ($datarowstyle eq 'display:none') {
9377: $$rowtotal ++;
9378: }
1.224 raeburn 9379: }
1.305 raeburn 9380: } else {
9381: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9382: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9383: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9384: }
9385: }
9386: return $datatable;
9387: }
9388:
1.305 raeburn 9389: sub selfcreate_javascript {
9390: return <<"ENDSCRIPT";
9391:
9392: <script type="text/javascript">
9393: // <![CDATA[
9394:
9395: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9396: var x = document.getElementsByClassName(target);
9397: var insttypes = 0;
9398: var insttypeRegExp = new RegExp(prefix);
9399: if ((x.length != undefined) && (x.length > 0)) {
9400: if (form.elements[radio].length != undefined) {
9401: for (var i=0; i<form.elements[radio].length; i++) {
9402: if (form.elements[radio][i].checked) {
9403: if (form.elements[radio][i].value == 1) {
9404: for (var j=0; j<x.length; j++) {
9405: if (x[j].id == 'undefined') {
9406: x[j].style.display = 'table-row';
9407: } else if (insttypeRegExp.test(x[j].id)) {
9408: insttypes ++;
9409: } else {
9410: x[j].style.display = 'table-row';
9411: }
9412: }
9413: } else {
9414: for (var j=0; j<x.length; j++) {
9415: x[j].style.display = 'none';
9416: }
1.236 raeburn 9417: }
1.305 raeburn 9418: break;
9419: }
9420: }
9421: if (insttypes > 0) {
9422: toggleDataRow(form,checkbox,target,altprefix);
9423: toggleDataRow(form,checkbox,target,prefix,1);
9424: }
9425: }
9426: }
9427: return;
9428: }
9429:
9430: function toggleDataRow(form,checkbox,target,prefix,docount) {
9431: if (form.elements[checkbox].length != undefined) {
9432: var count = 0;
9433: if (docount) {
9434: for (var i=0; i<form.elements[checkbox].length; i++) {
9435: if (form.elements[checkbox][i].checked) {
9436: count ++;
1.236 raeburn 9437: }
1.305 raeburn 9438: }
9439: }
9440: for (var i=0; i<form.elements[checkbox].length; i++) {
9441: var type = form.elements[checkbox][i].value;
9442: if (document.getElementById(prefix+type)) {
9443: if (form.elements[checkbox][i].checked) {
9444: document.getElementById(prefix+type).style.display = 'table-row';
9445: if (count % 2 == 1) {
9446: document.getElementById(prefix+type).className = target+' LC_odd_row';
9447: } else {
9448: document.getElementById(prefix+type).className = target;
1.236 raeburn 9449: }
1.305 raeburn 9450: count ++;
1.236 raeburn 9451: } else {
1.305 raeburn 9452: document.getElementById(prefix+type).style.display = 'none';
9453: }
9454: }
9455: }
9456: }
9457: return;
9458: }
9459:
9460: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9461: var caller = radio+'_'+status;
9462: if (form.elements[caller].length != undefined) {
9463: for (var i=0; i<form.elements[caller].length; i++) {
9464: if (form.elements[caller][i].checked) {
9465: if (document.getElementById(altprefix+'_inst_'+status)) {
9466: var curr = form.elements[caller][i].value;
9467: if (prefix) {
9468: document.getElementById(prefix+'_'+status).style.display = 'none';
9469: }
9470: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9471: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9472: if (curr == 'custom') {
9473: if (prefix) {
9474: document.getElementById(prefix+'_'+status).style.display = 'inline';
9475: }
9476: } else if (curr == 'inst') {
9477: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9478: } else if (curr == 'noninst') {
9479: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9480: }
1.305 raeburn 9481: break;
1.236 raeburn 9482: }
9483: }
9484: }
9485: }
9486: }
9487:
1.305 raeburn 9488: // ]]>
9489: </script>
9490:
9491: ENDSCRIPT
9492: }
9493:
9494: sub noninst_users {
9495: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9496: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9497: my $class = 'LC_left_item';
9498: if ($css_class) {
9499: $css_class = ' class="'.$css_class.'"';
9500: }
9501: if ($rowid) {
9502: $rowid = ' id="'.$rowid.'"';
9503: }
9504: if ($rowstyle) {
9505: $rowstyle = ' style="'.$rowstyle.'"';
9506: }
9507: my ($output,$description);
9508: if ($type eq 'default') {
9509: $description = &mt('Requests for: [_1]',$typetitle);
9510: } else {
9511: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9512: }
9513: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9514: "<td>$description</td>\n".
9515: '<td class="'.$class.'" colspan="2">'.
9516: '<table><tr>';
9517: my %headers = &Apache::lonlocal::texthash(
9518: approve => 'Processing',
9519: email => 'E-mail',
9520: username => 'Username',
9521: );
9522: foreach my $item ('approve','email','username') {
9523: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9524: }
1.305 raeburn 9525: $output .= '</tr><tr>';
9526: foreach my $item ('approve','email','username') {
1.306 raeburn 9527: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9528: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9529: if ($item eq 'approve') {
9530: %choices = &Apache::lonlocal::texthash (
9531: automatic => 'Automatically approved',
9532: approval => 'Queued for approval',
9533: );
9534: @options = ('automatic','approval');
9535: $hashref = $processing;
9536: $defoption = 'automatic';
9537: $name = 'cancreate_emailprocess_'.$type;
9538: } elsif ($item eq 'email') {
9539: %choices = &Apache::lonlocal::texthash (
9540: any => 'Any e-mail',
9541: inst => 'Institutional only',
9542: noninst => 'Non-institutional only',
9543: custom => 'Custom restrictions',
9544: );
9545: @options = ('any','inst','noninst');
9546: my $showcustom;
9547: if (ref($emailrules) eq 'HASH') {
9548: if (keys(%{$emailrules}) > 0) {
9549: push(@options,'custom');
9550: $showcustom = 'cancreate_emailrule';
9551: if (ref($settings) eq 'HASH') {
9552: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9553: foreach my $rule (@{$settings->{'email_rule'}}) {
9554: if (exists($emailrules->{$rule})) {
9555: $hascustom ++;
9556: }
9557: }
9558: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9559: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9560: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9561: if (exists($emailrules->{$rule})) {
9562: $hascustom ++;
9563: }
9564: }
9565: }
9566: }
9567: }
9568: }
9569: }
9570: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9571: "'cancreate_emaildomain','$type'".');"';
9572: $hashref = $emailoptions;
9573: $defoption = 'any';
9574: $name = 'cancreate_emailoptions_'.$type;
9575: } elsif ($item eq 'username') {
9576: %choices = &Apache::lonlocal::texthash (
9577: all => 'Same as e-mail',
9578: first => 'Omit @domain',
9579: free => 'Free to choose',
9580: );
9581: @options = ('all','first','free');
9582: $hashref = $emailverified;
9583: $defoption = 'all';
9584: $name = 'cancreate_usernameoptions_'.$type;
9585: }
9586: foreach my $option (@options) {
9587: my $checked;
9588: if (ref($hashref) eq 'HASH') {
9589: if ($type eq '') {
9590: if (!exists($hashref->{'default'})) {
9591: if ($option eq $defoption) {
9592: $checked = ' checked="checked"';
9593: }
9594: } else {
9595: if ($hashref->{'default'} eq $option) {
9596: $checked = ' checked="checked"';
9597: }
1.303 raeburn 9598: }
9599: } else {
1.305 raeburn 9600: if (!exists($hashref->{$type})) {
9601: if ($option eq $defoption) {
9602: $checked = ' checked="checked"';
9603: }
9604: } else {
9605: if ($hashref->{$type} eq $option) {
9606: $checked = ' checked="checked"';
9607: }
1.303 raeburn 9608: }
9609: }
1.305 raeburn 9610: } elsif (($item eq 'email') && ($hascustom)) {
9611: if ($option eq 'custom') {
9612: $checked = ' checked="checked"';
9613: }
9614: } elsif ($option eq $defoption) {
9615: $checked = ' checked="checked"';
9616: }
9617: $output .= '<span class="LC_nobreak"><label>'.
9618: '<input type="radio" name="'.$name.'"'.
9619: $checked.' value="'.$option.'"'.$onclick.' />'.
9620: $choices{$option}.'</label></span><br />';
9621: if ($item eq 'email') {
9622: if ($option eq 'custom') {
9623: my $id = 'cancreate_emailrule_'.$type;
9624: my $display = 'none';
9625: if ($checked) {
9626: $display = 'inline';
1.303 raeburn 9627: }
1.305 raeburn 9628: my $numinrow = 2;
9629: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9630: '<legend>'.&mt('Disallow').'</legend><table>'.
9631: &user_formats_row('email',$settings,$emailrules,
9632: $emailruleorder,$numinrow,'',$type);
9633: '</table></fieldset>';
9634: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9635: my %text = &Apache::lonlocal::texthash (
9636: inst => 'must end:',
9637: noninst => 'cannot end:',
9638: );
9639: my $value;
9640: if (ref($emaildomain) eq 'HASH') {
9641: if (ref($emaildomain->{$type}) eq 'HASH') {
9642: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9643: }
9644: }
1.305 raeburn 9645: if ($value eq '') {
9646: $value = '@'.$intdom;
9647: }
9648: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9649: my $display = 'none';
9650: if ($checked) {
9651: $display = 'inline';
9652: }
9653: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9654: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9655: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9656: '</div>';
1.303 raeburn 9657: }
9658: }
9659: }
1.305 raeburn 9660: $output .= '</td>'."\n";
1.303 raeburn 9661: }
1.305 raeburn 9662: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9663: return $output;
9664: }
9665:
1.165 raeburn 9666: sub captcha_choice {
1.305 raeburn 9667: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9668: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9669: $vertext,$currver);
1.165 raeburn 9670: my %lt = &captcha_phrases();
9671: $keyentry = 'hidden';
1.354 raeburn 9672: my $colspan=2;
1.165 raeburn 9673: if ($context eq 'cancreate') {
1.224 raeburn 9674: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9675: } elsif ($context eq 'login') {
9676: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9677: } elsif ($context eq 'passwords') {
9678: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9679: $colspan=1;
1.165 raeburn 9680: }
9681: if (ref($settings) eq 'HASH') {
9682: if ($settings->{'captcha'}) {
9683: $checked{$settings->{'captcha'}} = ' checked="checked"';
9684: } else {
9685: $checked{'original'} = ' checked="checked"';
9686: }
9687: if ($settings->{'captcha'} eq 'recaptcha') {
9688: $pubtext = $lt{'pub'};
9689: $privtext = $lt{'priv'};
9690: $keyentry = 'text';
1.269 raeburn 9691: $vertext = $lt{'ver'};
9692: $currver = $settings->{'recaptchaversion'};
9693: if ($currver ne '2') {
9694: $currver = 1;
9695: }
1.165 raeburn 9696: }
9697: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9698: $currpub = $settings->{'recaptchakeys'}{'public'};
9699: $currpriv = $settings->{'recaptchakeys'}{'private'};
9700: }
9701: } else {
9702: $checked{'original'} = ' checked="checked"';
9703: }
1.305 raeburn 9704: my $css_class;
9705: if ($itemcount%2) {
9706: $css_class = 'LC_odd_row';
9707: }
9708: if ($customcss) {
9709: $css_class .= " $customcss";
9710: }
9711: $css_class =~ s/^\s+//;
9712: if ($css_class) {
9713: $css_class = ' class="'.$css_class.'"';
9714: }
9715: if ($rowstyle) {
9716: $css_class .= ' style="'.$rowstyle.'"';
9717: }
1.169 raeburn 9718: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9719: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9720: '<table><tr><td>'."\n";
9721: foreach my $option ('original','recaptcha','notused') {
9722: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9723: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9724: $lt{$option}.'</label></span>';
9725: unless ($option eq 'notused') {
9726: $output .= (' 'x2)."\n";
9727: }
9728: }
9729: #
9730: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9731: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9732: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9733: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9734: #
1.165 raeburn 9735: $output .= '</td></tr>'."\n".
1.305 raeburn 9736: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9737: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9738: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9739: $currpub.'" size="40" /></span><br />'."\n".
9740: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9741: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9742: $currpriv.'" size="40" /></span><br />'.
9743: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9744: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9745: $currver.'" size="3" /></span><br />'.
9746: '</td></tr></table>'."\n".
1.165 raeburn 9747: '</td></tr>';
9748: return $output;
9749: }
9750:
1.32 raeburn 9751: sub user_formats_row {
1.305 raeburn 9752: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9753: my $output;
9754: my %text = (
9755: 'username' => 'new usernames',
9756: 'id' => 'IDs',
9757: );
1.305 raeburn 9758: unless ($type eq 'email') {
9759: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9760: $output = '<tr '.$css_class.'>'.
9761: '<td><span class="LC_nobreak">'.
9762: &mt("Format rules to check for $text{$type}: ").
9763: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9764: }
1.27 raeburn 9765: my $rem;
9766: if (ref($ruleorder) eq 'ARRAY') {
9767: for (my $i=0; $i<@{$ruleorder}; $i++) {
9768: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9769: my $rem = $i%($numinrow);
9770: if ($rem == 0) {
9771: if ($i > 0) {
9772: $output .= '</tr>';
9773: }
9774: $output .= '<tr>';
9775: }
9776: my $check = ' ';
1.39 raeburn 9777: if (ref($settings) eq 'HASH') {
9778: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9779: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9780: $check = ' checked="checked" ';
9781: }
1.305 raeburn 9782: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9783: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9784: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9785: $check = ' checked="checked" ';
9786: }
9787: }
1.27 raeburn 9788: }
9789: }
1.305 raeburn 9790: my $name = $type.'_rule';
9791: if ($type eq 'email') {
9792: $name .= '_'.$status;
9793: }
1.27 raeburn 9794: $output .= '<td class="LC_left_item">'.
9795: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9796: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9797: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9798: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9799: }
9800: }
9801: $rem = @{$ruleorder}%($numinrow);
9802: }
1.305 raeburn 9803: my $colsleft;
9804: if ($rem) {
9805: $colsleft = $numinrow - $rem;
9806: }
1.27 raeburn 9807: if ($colsleft > 1 ) {
9808: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9809: ' </td>';
9810: } elsif ($colsleft == 1) {
9811: $output .= '<td class="LC_left_item"> </td>';
9812: }
1.305 raeburn 9813: $output .= '</tr></table>';
9814: unless ($type eq 'email') {
9815: $output .= '</td></tr>';
9816: }
1.27 raeburn 9817: return $output;
9818: }
9819:
1.34 raeburn 9820: sub usercreation_types {
9821: my %lt = &Apache::lonlocal::texthash (
9822: author => 'When adding a co-author',
9823: course => 'When adding a user to a course',
1.100 raeburn 9824: requestcrs => 'When requesting a course',
1.34 raeburn 9825: any => 'Any',
9826: official => 'Institutional only ',
9827: unofficial => 'Non-institutional only',
9828: none => 'None',
9829: );
9830: return %lt;
1.48 raeburn 9831: }
1.34 raeburn 9832:
1.224 raeburn 9833: sub selfcreation_types {
9834: my %lt = &Apache::lonlocal::texthash (
9835: selfcreate => 'User creates own account',
9836: any => 'Any',
9837: official => 'Institutional only ',
9838: unofficial => 'Non-institutional only',
9839: email => 'E-mail address',
9840: login => 'Institutional Login',
9841: sso => 'SSO',
9842: );
9843: }
9844:
1.28 raeburn 9845: sub authtype_names {
9846: my %lt = &Apache::lonlocal::texthash(
9847: int => 'Internal',
9848: krb4 => 'Kerberos 4',
9849: krb5 => 'Kerberos 5',
9850: loc => 'Local',
1.325 raeburn 9851: lti => 'LTI',
1.28 raeburn 9852: );
9853: return %lt;
9854: }
9855:
9856: sub context_names {
9857: my %context_title = &Apache::lonlocal::texthash(
9858: author => 'Creating users when an Author',
9859: course => 'Creating users when in a course',
9860: domain => 'Creating users when a Domain Coordinator',
9861: );
9862: return %context_title;
9863: }
9864:
1.33 raeburn 9865: sub print_usermodification {
9866: my ($position,$dom,$settings,$rowtotal) = @_;
9867: my $numinrow = 4;
9868: my ($context,$datatable,$rowcount);
9869: if ($position eq 'top') {
9870: $rowcount = 0;
9871: $context = 'author';
9872: foreach my $role ('ca','aa') {
9873: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9874: $numinrow,$rowcount);
9875: $$rowtotal ++;
9876: $rowcount ++;
9877: }
1.230 raeburn 9878: } elsif ($position eq 'bottom') {
1.33 raeburn 9879: $context = 'course';
9880: $rowcount = 0;
9881: foreach my $role ('st','ep','ta','in','cr') {
9882: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9883: $numinrow,$rowcount);
9884: $$rowtotal ++;
9885: $rowcount ++;
9886: }
9887: }
9888: return $datatable;
9889: }
9890:
1.43 raeburn 9891: sub print_defaults {
1.236 raeburn 9892: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9893: my $rownum = 0;
1.294 raeburn 9894: my ($datatable,$css_class,$titles);
9895: unless ($position eq 'bottom') {
9896: $titles = &defaults_titles($dom);
9897: }
1.236 raeburn 9898: if ($position eq 'top') {
9899: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9900: 'datelocale_def','portal_def');
9901: my %defaults;
9902: if (ref($settings) eq 'HASH') {
9903: %defaults = %{$settings};
1.43 raeburn 9904: } else {
1.236 raeburn 9905: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9906: foreach my $item (@items) {
9907: $defaults{$item} = $domdefaults{$item};
9908: }
1.43 raeburn 9909: }
1.236 raeburn 9910: foreach my $item (@items) {
9911: if ($rownum%2) {
9912: $css_class = '';
9913: } else {
9914: $css_class = ' class="LC_odd_row" ';
9915: }
9916: $datatable .= '<tr'.$css_class.'>'.
9917: '<td><span class="LC_nobreak">'.$titles->{$item}.
9918: '</span></td><td class="LC_right_item" colspan="3">';
9919: if ($item eq 'auth_def') {
1.325 raeburn 9920: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9921: my %shortauth = (
9922: internal => 'int',
9923: krb4 => 'krb4',
9924: krb5 => 'krb5',
1.325 raeburn 9925: localauth => 'loc',
9926: lti => 'lti',
1.236 raeburn 9927: );
9928: my %authnames = &authtype_names();
9929: foreach my $auth (@authtypes) {
9930: my $checked = ' ';
9931: if ($defaults{$item} eq $auth) {
9932: $checked = ' checked="checked" ';
9933: }
9934: $datatable .= '<label><input type="radio" name="'.$item.
9935: '" value="'.$auth.'"'.$checked.'/>'.
9936: $authnames{$shortauth{$auth}}.'</label> ';
9937: }
9938: } elsif ($item eq 'timezone_def') {
9939: my $includeempty = 1;
9940: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9941: } elsif ($item eq 'datelocale_def') {
9942: my $includeempty = 1;
9943: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9944: } elsif ($item eq 'lang_def') {
1.263 raeburn 9945: my $includeempty = 1;
9946: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9947: } else {
9948: my $size;
9949: if ($item eq 'portal_def') {
9950: $size = ' size="25"';
9951: }
9952: $datatable .= '<input type="text" name="'.$item.'" value="'.
9953: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9954: }
1.236 raeburn 9955: $datatable .= '</td></tr>';
9956: $rownum ++;
9957: }
1.354 raeburn 9958: } else {
1.294 raeburn 9959: my %defaults;
9960: if (ref($settings) eq 'HASH') {
1.354 raeburn 9961: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9962: my $maxnum = @{$settings->{'inststatusorder'}};
9963: for (my $i=0; $i<$maxnum; $i++) {
9964: $css_class = $rownum%2?' class="LC_odd_row"':'';
9965: my $item = $settings->{'inststatusorder'}->[$i];
9966: my $title = $settings->{'inststatustypes'}->{$item};
9967: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9968: $datatable .= '<tr'.$css_class.'>'.
9969: '<td><span class="LC_nobreak">'.
9970: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9971: for (my $k=0; $k<=$maxnum; $k++) {
9972: my $vpos = $k+1;
9973: my $selstr;
9974: if ($k == $i) {
9975: $selstr = ' selected="selected" ';
9976: }
9977: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9978: }
9979: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9980: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9981: &mt('delete').'</span></td>'.
1.380 raeburn 9982: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 9983: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9984: '</span></td></tr>';
9985: }
9986: $css_class = $rownum%2?' class="LC_odd_row"':'';
9987: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9988: $datatable .= '<tr '.$css_class.'>'.
9989: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9990: for (my $k=0; $k<=$maxnum; $k++) {
9991: my $vpos = $k+1;
9992: my $selstr;
9993: if ($k == $maxnum) {
9994: $selstr = ' selected="selected" ';
9995: }
9996: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9997: }
9998: $datatable .= '</select> '.&mt('Internal ID:').
9999: '<input type="text" size="10" name="addinststatus" value="" />'.
10000: ' '.&mt('(new)').
10001: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10002: &mt('Name displayed').':'.
1.354 raeburn 10003: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10004: '</tr>'."\n";
10005: $rownum ++;
1.294 raeburn 10006: }
1.354 raeburn 10007: }
10008: }
10009: $$rowtotal += $rownum;
1.43 raeburn 10010: return $datatable;
10011: }
10012:
1.168 raeburn 10013: sub get_languages_hash {
10014: my %langchoices;
10015: foreach my $id (&Apache::loncommon::languageids()) {
10016: my $code = &Apache::loncommon::supportedlanguagecode($id);
10017: if ($code ne '') {
10018: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10019: }
10020: }
10021: return %langchoices;
10022: }
10023:
1.43 raeburn 10024: sub defaults_titles {
1.141 raeburn 10025: my ($dom) = @_;
1.43 raeburn 10026: my %titles = &Apache::lonlocal::texthash (
10027: 'auth_def' => 'Default authentication type',
10028: 'auth_arg_def' => 'Default authentication argument',
10029: 'lang_def' => 'Default language',
1.54 raeburn 10030: 'timezone_def' => 'Default timezone',
1.68 raeburn 10031: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10032: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 10033: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10034: 'intauth_check' => 'Check bcrypt cost if authenticated',
10035: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10036: );
1.141 raeburn 10037: if ($dom) {
10038: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10039: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10040: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10041: $protocol = 'http' if ($protocol ne 'https');
10042: if ($uint_dom) {
10043: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10044: $uint_dom);
10045: }
10046: }
1.43 raeburn 10047: return (\%titles);
10048: }
10049:
1.346 raeburn 10050: sub print_scantron {
10051: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10052: if ($position eq 'top') {
10053: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10054: } else {
10055: return &print_scantronconfig($dom,$settings,\$rowtotal);
10056: }
10057: }
10058:
10059: sub scantron_javascript {
10060: return <<"ENDSCRIPT";
10061:
10062: <script type="text/javascript">
10063: // <![CDATA[
10064:
10065: function toggleScantron(form) {
1.347 raeburn 10066: var csvfieldset = new Array();
1.346 raeburn 10067: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10068: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10069: }
10070: if (document.getElementById('scantroncsv_options')) {
10071: csvfieldset.push(document.getElementById('scantroncsv_options'));
10072: }
10073: if (csvfieldset.length) {
1.346 raeburn 10074: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10075: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10076: if (scantroncsv.checked) {
1.347 raeburn 10077: for (var i=0; i<csvfieldset.length; i++) {
10078: csvfieldset[i].style.display = 'block';
10079: }
1.346 raeburn 10080: } else {
1.347 raeburn 10081: for (var i=0; i<csvfieldset.length; i++) {
10082: csvfieldset[i].style.display = 'none';
10083: }
1.346 raeburn 10084: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10085: if (csvselects.length) {
10086: for (var j=0; j<csvselects.length; j++) {
10087: csvselects[j].selectedIndex = 0;
10088: }
10089: }
10090: }
10091: }
10092: }
10093: return;
10094: }
10095: // ]]>
10096: </script>
10097:
10098: ENDSCRIPT
10099:
10100: }
10101:
1.46 raeburn 10102: sub print_scantronformat {
10103: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10104: my $itemcount = 1;
1.60 raeburn 10105: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10106: %confhash);
1.46 raeburn 10107: my $switchserver = &check_switchserver($dom,$confname);
10108: my %lt = &Apache::lonlocal::texthash (
1.95 www 10109: default => 'Default bubblesheet format file error',
10110: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10111: );
10112: my %scantronfiles = (
10113: default => 'default.tab',
10114: custom => 'custom.tab',
10115: );
10116: foreach my $key (keys(%scantronfiles)) {
10117: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10118: .$scantronfiles{$key};
10119: }
10120: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10121: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10122: if (!$switchserver) {
10123: my $servadm = $r->dir_config('lonAdmEMail');
10124: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10125: if ($configuserok eq 'ok') {
10126: if ($author_ok eq 'ok') {
10127: my %legacyfile = (
1.346 raeburn 10128: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10129: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10130: );
10131: my %md5chk;
10132: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10133: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10134: chomp($md5chk{$type});
1.46 raeburn 10135: }
10136: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10137: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10138: ($scantronurls{$type},my $error) =
1.46 raeburn 10139: &legacy_scantronformat($r,$dom,$confname,
10140: $type,$legacyfile{$type},
10141: $scantronurls{$type},
10142: $scantronfiles{$type});
1.60 raeburn 10143: if ($error ne '') {
10144: $error{$type} = $error;
10145: }
10146: }
10147: if (keys(%error) == 0) {
10148: $is_custom = 1;
1.346 raeburn 10149: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10150: $scantronurls{'custom'};
1.346 raeburn 10151: my $putresult =
1.60 raeburn 10152: &Apache::lonnet::put_dom('configuration',
10153: \%confhash,$dom);
10154: if ($putresult ne 'ok') {
1.346 raeburn 10155: $error{'custom'} =
1.60 raeburn 10156: '<span class="LC_error">'.
10157: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10158: }
1.46 raeburn 10159: }
10160: } else {
1.60 raeburn 10161: ($scantronurls{'default'},my $error) =
1.46 raeburn 10162: &legacy_scantronformat($r,$dom,$confname,
10163: 'default',$legacyfile{'default'},
10164: $scantronurls{'default'},
10165: $scantronfiles{'default'});
1.60 raeburn 10166: if ($error eq '') {
10167: $confhash{'scantron'}{'scantronformat'} = '';
10168: my $putresult =
10169: &Apache::lonnet::put_dom('configuration',
10170: \%confhash,$dom);
10171: if ($putresult ne 'ok') {
10172: $error{'default'} =
10173: '<span class="LC_error">'.
10174: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10175: }
10176: } else {
10177: $error{'default'} = $error;
10178: }
1.46 raeburn 10179: }
10180: }
10181: }
10182: } else {
1.95 www 10183: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10184: }
10185: }
10186: if (ref($settings) eq 'HASH') {
10187: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10188: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10189: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10190: $scantronurl = '';
10191: } else {
10192: $scantronurl = $settings->{'scantronformat'};
10193: }
10194: $is_custom = 1;
10195: } else {
10196: $scantronurl = $scantronurls{'default'};
10197: }
10198: } else {
1.60 raeburn 10199: if ($is_custom) {
10200: $scantronurl = $scantronurls{'custom'};
10201: } else {
10202: $scantronurl = $scantronurls{'default'};
10203: }
1.46 raeburn 10204: }
10205: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10206: $datatable .= '<tr'.$css_class.'>';
10207: if (!$is_custom) {
1.65 raeburn 10208: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10209: '<span class="LC_nobreak">';
1.46 raeburn 10210: if ($scantronurl) {
1.199 raeburn 10211: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10212: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10213: } else {
10214: $datatable = &mt('File unavailable for display');
10215: }
1.65 raeburn 10216: $datatable .= '</span></td>';
1.60 raeburn 10217: if (keys(%error) == 0) {
1.306 raeburn 10218: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10219: if (!$switchserver) {
10220: $datatable .= &mt('Upload:').'<br />';
10221: }
10222: } else {
10223: my $errorstr;
10224: foreach my $key (sort(keys(%error))) {
10225: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10226: }
10227: $datatable .= '<td>'.$errorstr;
10228: }
1.46 raeburn 10229: } else {
10230: if (keys(%error) > 0) {
10231: my $errorstr;
10232: foreach my $key (sort(keys(%error))) {
10233: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10234: }
1.60 raeburn 10235: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10236: } elsif ($scantronurl) {
1.199 raeburn 10237: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10238: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10239: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10240: $link.
10241: '<label><input type="checkbox" name="scantronformat_del"'.
10242: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10243: '<td><span class="LC_nobreak"> '.
10244: &mt('Replace:').'</span><br />';
1.46 raeburn 10245: }
10246: }
10247: if (keys(%error) == 0) {
10248: if ($switchserver) {
10249: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10250: } else {
1.65 raeburn 10251: $datatable .='<span class="LC_nobreak"> '.
10252: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10253: }
10254: }
10255: $datatable .= '</td></tr>';
10256: $$rowtotal ++;
10257: return $datatable;
10258: }
10259:
10260: sub legacy_scantronformat {
10261: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10262: my ($url,$error);
10263: my @statinfo = &Apache::lonnet::stat_file($newurl);
10264: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
10265: (my $result,$url) =
10266: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
10267: '','',$newfile);
10268: if ($result ne 'ok') {
1.130 raeburn 10269: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10270: }
10271: }
10272: return ($url,$error);
10273: }
1.43 raeburn 10274:
1.346 raeburn 10275: sub print_scantronconfig {
10276: my ($dom,$settings,$rowtotal) = @_;
10277: my $itemcount = 2;
10278: my $is_checked = ' checked="checked"';
1.347 raeburn 10279: my %optionson = (
10280: hdr => ' checked="checked"',
10281: pad => ' checked="checked"',
10282: rem => ' checked="checked"',
10283: );
10284: my %optionsoff = (
10285: hdr => '',
10286: pad => '',
10287: rem => '',
10288: );
1.346 raeburn 10289: my $currcsvsty = 'none';
1.347 raeburn 10290: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10291: my @fields = &scantroncsv_fields();
10292: my %titles = &scantronconfig_titles();
10293: if (ref($settings) eq 'HASH') {
10294: if (ref($settings->{config}) eq 'HASH') {
10295: if ($settings->{config}->{dat}) {
10296: $checked{'dat'} = $is_checked;
10297: }
10298: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10299: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10300: %csvfields = %{$settings->{config}->{csv}->{fields}};
10301: if (keys(%csvfields) > 0) {
10302: $checked{'csv'} = $is_checked;
10303: $currcsvsty = 'block';
10304: }
10305: }
10306: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10307: %csvoptions = %{$settings->{config}->{csv}->{options}};
10308: foreach my $option (keys(%optionson)) {
10309: unless ($csvoptions{$option}) {
10310: $optionsoff{$option} = $optionson{$option};
10311: $optionson{$option} = '';
10312: }
10313: }
1.346 raeburn 10314: }
10315: }
10316: } else {
10317: $checked{'dat'} = $is_checked;
10318: }
10319: } else {
10320: $checked{'dat'} = $is_checked;
10321: }
10322: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10323: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10324: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10325: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10326: foreach my $item ('dat','csv') {
10327: my $id;
10328: if ($item eq 'csv') {
10329: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10330: }
1.346 raeburn 10331: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10332: $titles{$item}.'</label>'.(' 'x3);
10333: if ($item eq 'csv') {
10334: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10335: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10336: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10337: foreach my $col (@fields) {
10338: my $selnone;
10339: if ($csvfields{$col} eq '') {
10340: $selnone = ' selected="selected"';
10341: }
10342: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10343: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10344: '<option value=""'.$selnone.'></option>';
10345: for (my $i=0; $i<20; $i++) {
10346: my $shown = $i+1;
10347: my $sel;
10348: unless ($selnone) {
10349: if (exists($csvfields{$col})) {
10350: if ($csvfields{$col} == $i) {
10351: $sel = ' selected="selected"';
10352: }
10353: }
10354: }
10355: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10356: }
10357: $datatable .= '</select></td></tr>';
10358: }
1.347 raeburn 10359: $datatable .= '</table></fieldset>'.
10360: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10361: '<legend>'.&mt('CSV Options').'</legend>';
10362: foreach my $option ('hdr','pad','rem') {
10363: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10364: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10365: &mt('Yes').'</label>'.(' 'x2)."\n".
10366: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10367: }
10368: $datatable .= '</fieldset>';
1.346 raeburn 10369: $itemcount ++;
10370: }
10371: }
10372: $datatable .= '</td></tr>';
10373: $$rowtotal ++;
10374: return $datatable;
10375: }
10376:
10377: sub scantronconfig_titles {
10378: return &Apache::lonlocal::texthash(
10379: dat => 'Standard format (.dat)',
10380: csv => 'Comma separated values (.csv)',
1.347 raeburn 10381: hdr => 'Remove first line in file (contains column titles)',
10382: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10383: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10384: CODE => 'CODE',
10385: ID => 'Student ID',
10386: PaperID => 'Paper ID',
10387: FirstName => 'First Name',
10388: LastName => 'Last Name',
10389: FirstQuestion => 'First Question Response',
10390: Section => 'Section',
10391: );
10392: }
10393:
10394: sub scantroncsv_fields {
10395: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10396: }
10397:
1.49 raeburn 10398: sub print_coursecategories {
1.57 raeburn 10399: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10400: my $datatable;
10401: if ($position eq 'top') {
1.238 raeburn 10402: my (%checked);
10403: my @catitems = ('unauth','auth');
10404: my @cattypes = ('std','domonly','codesrch','none');
10405: $checked{'unauth'} = 'std';
10406: $checked{'auth'} = 'std';
10407: if (ref($settings) eq 'HASH') {
10408: foreach my $type (@cattypes) {
10409: if ($type eq $settings->{'unauth'}) {
10410: $checked{'unauth'} = $type;
10411: }
10412: if ($type eq $settings->{'auth'}) {
10413: $checked{'auth'} = $type;
10414: }
10415: }
10416: }
10417: my %lt = &Apache::lonlocal::texthash (
10418: unauth => 'Catalog type for unauthenticated users',
10419: auth => 'Catalog type for authenticated users',
10420: none => 'No catalog',
10421: std => 'Standard catalog',
10422: domonly => 'Domain-only catalog',
10423: codesrch => "Code search form",
10424: );
10425: my $itemcount = 0;
10426: foreach my $item (@catitems) {
10427: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10428: $datatable .= '<tr '.$css_class.'>'.
10429: '<td>'.$lt{$item}.'</td>'.
10430: '<td class="LC_right_item"><span class="LC_nobreak">';
10431: foreach my $type (@cattypes) {
10432: my $ischecked;
10433: if ($checked{$item} eq $type) {
10434: $ischecked=' checked="checked"';
10435: }
10436: $datatable .= '<label>'.
10437: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10438: ' />'.$lt{$type}.'</label> ';
10439: }
1.327 raeburn 10440: $datatable .= '</span></td></tr>';
1.238 raeburn 10441: $itemcount ++;
10442: }
10443: $$rowtotal += $itemcount;
10444: } elsif ($position eq 'middle') {
1.57 raeburn 10445: my $toggle_cats_crs = ' ';
10446: my $toggle_cats_dom = ' checked="checked" ';
10447: my $can_cat_crs = ' ';
10448: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10449: my $toggle_catscomm_comm = ' ';
10450: my $toggle_catscomm_dom = ' checked="checked" ';
10451: my $can_catcomm_comm = ' ';
10452: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10453: my $toggle_catsplace_place = ' ';
10454: my $toggle_catsplace_dom = ' checked="checked" ';
10455: my $can_catplace_place = ' ';
10456: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10457:
1.57 raeburn 10458: if (ref($settings) eq 'HASH') {
10459: if ($settings->{'togglecats'} eq 'crs') {
10460: $toggle_cats_crs = $toggle_cats_dom;
10461: $toggle_cats_dom = ' ';
10462: }
10463: if ($settings->{'categorize'} eq 'crs') {
10464: $can_cat_crs = $can_cat_dom;
10465: $can_cat_dom = ' ';
10466: }
1.120 raeburn 10467: if ($settings->{'togglecatscomm'} eq 'comm') {
10468: $toggle_catscomm_comm = $toggle_catscomm_dom;
10469: $toggle_catscomm_dom = ' ';
10470: }
10471: if ($settings->{'categorizecomm'} eq 'comm') {
10472: $can_catcomm_comm = $can_catcomm_dom;
10473: $can_catcomm_dom = ' ';
10474: }
1.272 raeburn 10475: if ($settings->{'togglecatsplace'} eq 'place') {
10476: $toggle_catsplace_place = $toggle_catsplace_dom;
10477: $toggle_catsplace_dom = ' ';
10478: }
10479: if ($settings->{'categorizeplace'} eq 'place') {
10480: $can_catplace_place = $can_catplace_dom;
10481: $can_catplace_dom = ' ';
10482: }
1.57 raeburn 10483: }
10484: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10485: togglecats => 'Show/Hide a course in catalog',
10486: togglecatscomm => 'Show/Hide a community in catalog',
10487: togglecatsplace => 'Show/Hide a placement test in catalog',
10488: categorize => 'Assign a category to a course',
10489: categorizecomm => 'Assign a category to a community',
10490: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10491: );
10492: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10493: dom => 'Set in Domain',
10494: crs => 'Set in Course',
10495: comm => 'Set in Community',
10496: place => 'Set in Placement Test',
1.57 raeburn 10497: );
10498: $datatable = '<tr class="LC_odd_row">'.
10499: '<td>'.$title{'togglecats'}.'</td>'.
10500: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10501: '<input type="radio" name="togglecats"'.
10502: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10503: '<label><input type="radio" name="togglecats"'.
10504: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10505: '</tr><tr>'.
10506: '<td>'.$title{'categorize'}.'</td>'.
10507: '<td class="LC_right_item"><span class="LC_nobreak">'.
10508: '<label><input type="radio" name="categorize"'.
10509: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10510: '<label><input type="radio" name="categorize"'.
10511: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10512: '</tr><tr class="LC_odd_row">'.
10513: '<td>'.$title{'togglecatscomm'}.'</td>'.
10514: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10515: '<input type="radio" name="togglecatscomm"'.
10516: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10517: '<label><input type="radio" name="togglecatscomm"'.
10518: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10519: '</tr><tr>'.
10520: '<td>'.$title{'categorizecomm'}.'</td>'.
10521: '<td class="LC_right_item"><span class="LC_nobreak">'.
10522: '<label><input type="radio" name="categorizecomm"'.
10523: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10524: '<label><input type="radio" name="categorizecomm"'.
10525: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10526: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10527: '<td>'.$title{'togglecatsplace'}.'</td>'.
10528: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10529: '<input type="radio" name="togglecatsplace"'.
10530: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10531: '<label><input type="radio" name="togglecatscomm"'.
10532: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10533: '</tr><tr>'.
10534: '<td>'.$title{'categorizeplace'}.'</td>'.
10535: '<td class="LC_right_item"><span class="LC_nobreak">'.
10536: '<label><input type="radio" name="categorizeplace"'.
10537: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10538: '<label><input type="radio" name="categorizeplace"'.
10539: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10540: '</tr>';
1.272 raeburn 10541: $$rowtotal += 6;
1.57 raeburn 10542: } else {
10543: my $css_class;
10544: my $itemcount = 1;
10545: my $cathash;
10546: if (ref($settings) eq 'HASH') {
10547: $cathash = $settings->{'cats'};
10548: }
10549: if (ref($cathash) eq 'HASH') {
10550: my (@cats,@trails,%allitems,%idx,@jsarray);
10551: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10552: \%allitems,\%idx,\@jsarray);
10553: my $maxdepth = scalar(@cats);
10554: my $colattrib = '';
10555: if ($maxdepth > 2) {
10556: $colattrib = ' colspan="2" ';
10557: }
10558: my @path;
10559: if (@cats > 0) {
10560: if (ref($cats[0]) eq 'ARRAY') {
10561: my $numtop = @{$cats[0]};
10562: my $maxnum = $numtop;
1.120 raeburn 10563: my %default_names = (
10564: instcode => &mt('Official courses'),
10565: communities => &mt('Communities'),
1.272 raeburn 10566: placement => &mt('Placement Tests'),
1.120 raeburn 10567: );
10568:
10569: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10570: ($cathash->{'instcode::0'} eq '') ||
10571: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10572: ($cathash->{'communities::0'} eq '') ||
10573: (!grep(/^placement$/,@{$cats[0]})) ||
10574: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10575: $maxnum ++;
10576: }
10577: my $lastidx;
10578: for (my $i=0; $i<$numtop; $i++) {
10579: my $parent = $cats[0][$i];
10580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10581: my $item = &escape($parent).'::0';
10582: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10583: $lastidx = $idx{$item};
10584: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10585: .'<select name="'.$item.'"'.$chgstr.'>';
10586: for (my $k=0; $k<=$maxnum; $k++) {
10587: my $vpos = $k+1;
10588: my $selstr;
10589: if ($k == $i) {
10590: $selstr = ' selected="selected" ';
10591: }
10592: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10593: }
1.214 raeburn 10594: $datatable .= '</select></span></td><td>';
1.272 raeburn 10595: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10596: $datatable .= '<span class="LC_nobreak">'
10597: .$default_names{$parent}.'</span>';
10598: if ($parent eq 'instcode') {
10599: $datatable .= '<br /><span class="LC_nobreak">('
10600: .&mt('with institutional codes')
10601: .')</span></td><td'.$colattrib.'>';
10602: } else {
10603: $datatable .= '<table><tr><td>';
10604: }
10605: $datatable .= '<span class="LC_nobreak">'
10606: .'<label><input type="radio" name="'
10607: .$parent.'" value="1" checked="checked" />'
10608: .&mt('Display').'</label>';
10609: if ($parent eq 'instcode') {
10610: $datatable .= ' ';
10611: } else {
10612: $datatable .= '</span></td></tr><tr><td>'
10613: .'<span class="LC_nobreak">';
10614: }
10615: $datatable .= '<label><input type="radio" name="'
10616: .$parent.'" value="0" />'
10617: .&mt('Do not display').'</label></span>';
1.272 raeburn 10618: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10619: $datatable .= '</td></tr></table>';
10620: }
10621: $datatable .= '</td>';
1.57 raeburn 10622: } else {
10623: $datatable .= $parent
1.214 raeburn 10624: .' <span class="LC_nobreak"><label>'
10625: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10626: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10627: }
10628: my $depth = 1;
10629: push(@path,$parent);
10630: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10631: pop(@path);
10632: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10633: $itemcount ++;
10634: }
1.48 raeburn 10635: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10636: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10637: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10638: for (my $k=0; $k<=$maxnum; $k++) {
10639: my $vpos = $k+1;
10640: my $selstr;
1.57 raeburn 10641: if ($k == $numtop) {
1.48 raeburn 10642: $selstr = ' selected="selected" ';
10643: }
10644: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10645: }
1.59 bisitz 10646: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10647: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10648: .'</tr>'."\n";
1.48 raeburn 10649: $itemcount ++;
1.272 raeburn 10650: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10651: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10652: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10653: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10654: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10655: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10656: for (my $k=0; $k<=$maxnum; $k++) {
10657: my $vpos = $k+1;
10658: my $selstr;
10659: if ($k == $maxnum) {
10660: $selstr = ' selected="selected" ';
10661: }
10662: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10663: }
1.120 raeburn 10664: $datatable .= '</select></span></td>'.
10665: '<td><span class="LC_nobreak">'.
10666: $default_names{$default}.'</span>';
10667: if ($default eq 'instcode') {
10668: $datatable .= '<br /><span class="LC_nobreak">('
10669: .&mt('with institutional codes').')</span>';
10670: }
10671: $datatable .= '</td>'
10672: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10673: .&mt('Display').'</label> '
10674: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10675: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10676: }
10677: }
10678: }
1.57 raeburn 10679: } else {
10680: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10681: }
10682: } else {
1.327 raeburn 10683: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10684: .&initialize_categories($itemcount);
1.48 raeburn 10685: }
1.57 raeburn 10686: $$rowtotal += $itemcount;
1.48 raeburn 10687: }
10688: return $datatable;
10689: }
10690:
1.69 raeburn 10691: sub print_serverstatuses {
10692: my ($dom,$settings,$rowtotal) = @_;
10693: my $datatable;
10694: my @pages = &serverstatus_pages();
10695: my (%namedaccess,%machineaccess);
10696: foreach my $type (@pages) {
10697: $namedaccess{$type} = '';
10698: $machineaccess{$type}= '';
10699: }
10700: if (ref($settings) eq 'HASH') {
10701: foreach my $type (@pages) {
10702: if (exists($settings->{$type})) {
10703: if (ref($settings->{$type}) eq 'HASH') {
10704: foreach my $key (keys(%{$settings->{$type}})) {
10705: if ($key eq 'namedusers') {
10706: $namedaccess{$type} = $settings->{$type}->{$key};
10707: } elsif ($key eq 'machines') {
10708: $machineaccess{$type} = $settings->{$type}->{$key};
10709: }
10710: }
10711: }
10712: }
10713: }
10714: }
1.81 raeburn 10715: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10716: my $rownum = 0;
10717: my $css_class;
10718: foreach my $type (@pages) {
10719: $rownum ++;
10720: $css_class = $rownum%2?' class="LC_odd_row"':'';
10721: $datatable .= '<tr'.$css_class.'>'.
10722: '<td><span class="LC_nobreak">'.
10723: $titles->{$type}.'</span></td>'.
10724: '<td class="LC_left_item">'.
10725: '<input type="text" name="'.$type.'_namedusers" '.
10726: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10727: '<td class="LC_right_item">'.
10728: '<span class="LC_nobreak">'.
10729: '<input type="text" name="'.$type.'_machines" '.
10730: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10731: '</span></td></tr>'."\n";
1.69 raeburn 10732: }
10733: $$rowtotal += $rownum;
10734: return $datatable;
10735: }
10736:
10737: sub serverstatus_pages {
10738: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10739: 'checksums','clusterstatus','certstatus','metadata_keywords',
10740: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10741: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10742: }
10743:
1.236 raeburn 10744: sub defaults_javascript {
10745: my ($settings) = @_;
1.354 raeburn 10746: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10747: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10748: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10749: if ($maxnum eq '') {
10750: $maxnum = 0;
10751: }
10752: $maxnum ++;
1.249 raeburn 10753: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10754: return <<"ENDSCRIPT";
10755: <script type="text/javascript">
10756: // <![CDATA[
10757: function reorderTypes(form,caller) {
10758: var changedVal;
10759: $jstext
10760: var newpos = 'addinststatus_pos';
10761: var current = new Array;
10762: var maxh = $maxnum;
10763: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10764: var oldVal;
10765: if (caller == newpos) {
10766: changedVal = newitemVal;
10767: } else {
10768: var curritem = 'inststatus_pos_'+caller;
10769: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10770: current[newitemVal] = newpos;
10771: }
10772: for (var i=0; i<inststatuses.length; i++) {
10773: if (inststatuses[i] != caller) {
10774: var elementName = 'inststatus_pos_'+inststatuses[i];
10775: if (form.elements[elementName]) {
10776: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10777: current[currVal] = elementName;
10778: }
10779: }
10780: }
10781: for (var j=0; j<maxh; j++) {
10782: if (current[j] == undefined) {
10783: oldVal = j;
10784: }
10785: }
10786: if (oldVal < changedVal) {
10787: for (var k=oldVal+1; k<=changedVal ; k++) {
10788: var elementName = current[k];
10789: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10790: }
10791: } else {
10792: for (var k=changedVal; k<oldVal; k++) {
10793: var elementName = current[k];
10794: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10795: }
10796: }
10797: return;
10798: }
10799:
10800: // ]]>
10801: </script>
10802:
10803: ENDSCRIPT
10804: }
1.354 raeburn 10805: return;
10806: }
10807:
10808: sub passwords_javascript {
1.365 raeburn 10809: my %intalert = &Apache::lonlocal::texthash (
10810: 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.',
10811: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10812: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10813: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10814: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10815: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10816: );
10817: &js_escape(\%intalert);
10818: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10819: my $intauthjs = <<"ENDSCRIPT";
10820:
10821: function warnIntAuth(field) {
10822: if (field.name == 'intauth_check') {
10823: if (field.value == '2') {
1.365 raeburn 10824: alert('$intalert{authcheck}');
1.354 raeburn 10825: }
10826: }
10827: if (field.name == 'intauth_cost') {
10828: field.value.replace(/\s/g,'');
10829: if (field.value != '') {
10830: var regexdigit=/^\\d+\$/;
10831: if (!regexdigit.test(field.value)) {
1.365 raeburn 10832: alert('$intalert{authcost}');
10833: }
10834: }
10835: }
10836: return;
10837: }
10838:
10839: function warnIntPass(field) {
10840: field.value.replace(/^\s+/,'');
10841: field.value.replace(/\s+\$/,'');
10842: var regexdigit=/^\\d+\$/;
10843: if (field.name == 'passwords_min') {
10844: if (field.value == '') {
10845: alert('$intalert{passmin}');
10846: field.value = '$defmin';
10847: } else {
10848: if (!regexdigit.test(field.value)) {
10849: alert('$intalert{passmin}');
10850: field.value = '$defmin';
10851: }
1.366 raeburn 10852: var minval = parseInt(field.value,10);
1.365 raeburn 10853: if (minval < $defmin) {
10854: alert('$intalert{passmin}');
10855: field.value = '$defmin';
10856: }
10857: }
10858: } else {
10859: if (field.value == '0') {
10860: field.value = '';
10861: }
10862: if (field.value != '') {
10863: if (field.name == 'passwords_expire') {
10864: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10865: if (!regexpposnum.test(field.value)) {
10866: alert('$intalert{passexp}');
10867: field.value = '';
10868: } else {
10869: var expval = parseFloat(field.value);
10870: if (expval == 0) {
10871: alert('$intalert{passexp}');
10872: field.value = '';
10873: }
10874: }
10875: } else {
10876: if (!regexdigit.test(field.value)) {
10877: if (field.name == 'passwords_max') {
10878: alert('$intalert{passmax}');
10879: } else {
10880: if (field.name == 'passwords_numsaved') {
10881: alert('$intalert{passnum}');
10882: }
10883: }
1.370 raeburn 10884: field.value = '';
1.365 raeburn 10885: }
1.354 raeburn 10886: }
10887: }
10888: }
10889: return;
10890: }
10891:
10892: ENDSCRIPT
10893: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10894: }
10895:
1.49 raeburn 10896: sub coursecategories_javascript {
10897: my ($settings) = @_;
1.57 raeburn 10898: my ($output,$jstext,$cathash);
1.49 raeburn 10899: if (ref($settings) eq 'HASH') {
1.57 raeburn 10900: $cathash = $settings->{'cats'};
10901: }
10902: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10903: my (@cats,@jsarray,%idx);
1.57 raeburn 10904: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10905: if (@jsarray > 0) {
10906: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10907: for (my $i=0; $i<@jsarray; $i++) {
10908: if (ref($jsarray[$i]) eq 'ARRAY') {
10909: my $catstr = join('","',@{$jsarray[$i]});
10910: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10911: }
10912: }
10913: }
10914: } else {
10915: $jstext = ' var categories = Array(1);'."\n".
10916: ' categories[0] = Array("instcode_pos");'."\n";
10917: }
1.237 bisitz 10918: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10919: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10920: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10921: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10922: &js_escape(\$instcode_reserved);
10923: &js_escape(\$communities_reserved);
1.272 raeburn 10924: &js_escape(\$placement_reserved);
1.265 damieng 10925: &js_escape(\$choose_again);
1.49 raeburn 10926: $output = <<"ENDSCRIPT";
10927: <script type="text/javascript">
1.109 raeburn 10928: // <![CDATA[
1.49 raeburn 10929: function reorderCats(form,parent,item,idx) {
10930: var changedVal;
10931: $jstext
10932: var newpos = 'addcategory_pos';
10933: if (parent == '') {
10934: var has_instcode = 0;
10935: var maxtop = categories[idx].length;
10936: for (var j=0; j<maxtop; j++) {
10937: if (categories[idx][j] == 'instcode::0') {
10938: has_instcode == 1;
10939: }
10940: }
10941: if (has_instcode == 0) {
10942: categories[idx][maxtop] = 'instcode_pos';
10943: }
10944: } else {
10945: newpos += '_'+parent;
10946: }
10947: var maxh = 1 + categories[idx].length;
10948: var current = new Array;
10949: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10950: if (item == newpos) {
10951: changedVal = newitemVal;
10952: } else {
10953: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10954: current[newitemVal] = newpos;
10955: }
10956: for (var i=0; i<categories[idx].length; i++) {
10957: var elementName = categories[idx][i];
10958: if (elementName != item) {
10959: if (form.elements[elementName]) {
10960: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10961: current[currVal] = elementName;
10962: }
10963: }
10964: }
10965: var oldVal;
10966: for (var j=0; j<maxh; j++) {
10967: if (current[j] == undefined) {
10968: oldVal = j;
10969: }
10970: }
10971: if (oldVal < changedVal) {
10972: for (var k=oldVal+1; k<=changedVal ; k++) {
10973: var elementName = current[k];
10974: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10975: }
10976: } else {
10977: for (var k=changedVal; k<oldVal; k++) {
10978: var elementName = current[k];
10979: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10980: }
10981: }
10982: return;
10983: }
1.120 raeburn 10984:
10985: function categoryCheck(form) {
10986: if (form.elements['addcategory_name'].value == 'instcode') {
10987: alert('$instcode_reserved\\n$choose_again');
10988: return false;
10989: }
10990: if (form.elements['addcategory_name'].value == 'communities') {
10991: alert('$communities_reserved\\n$choose_again');
10992: return false;
10993: }
1.272 raeburn 10994: if (form.elements['addcategory_name'].value == 'placement') {
10995: alert('$placement_reserved\\n$choose_again');
10996: return false;
10997: }
1.120 raeburn 10998: return true;
10999: }
11000:
1.109 raeburn 11001: // ]]>
1.49 raeburn 11002: </script>
11003:
11004: ENDSCRIPT
11005: return $output;
11006: }
11007:
1.48 raeburn 11008: sub initialize_categories {
11009: my ($itemcount) = @_;
1.120 raeburn 11010: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11011: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11012: instcode => 'Official courses (with institutional codes)',
11013: communities => 'Communities',
1.272 raeburn 11014: placement => 'Placement Tests',
1.120 raeburn 11015: );
1.328 raeburn 11016: my %selnum = (
11017: instcode => '0',
11018: communities => '1',
11019: placement => '2',
11020: );
11021: my %selected;
1.272 raeburn 11022: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11023: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11024: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11025: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11026: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11027: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11028: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11029: .'<option value="0"'.$selected{'0'}.'>1</option>'
11030: .'<option value="1"'.$selected{'1'}.'>2</option>'
11031: .'<option value="2"'.$selected{'2'}.'>3</option>'
11032: .'<option value="3">4</option></select> '
1.120 raeburn 11033: .$default_names{$default}
11034: .'</span></td><td><span class="LC_nobreak">'
11035: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11036: .&mt('Display').'</label> <label>'
11037: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11038: .'</label></span></td></tr>';
1.120 raeburn 11039: $itemcount ++;
11040: }
1.48 raeburn 11041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11042: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11043: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11044: .'<select name="addcategory_pos"'.$chgstr.'>'
11045: .'<option value="0">1</option>'
11046: .'<option value="1">2</option>'
1.328 raeburn 11047: .'<option value="2">3</option>'
11048: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11049: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11050: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11051: .'</td></tr>';
1.48 raeburn 11052: return $datatable;
11053: }
11054:
11055: sub build_category_rows {
1.49 raeburn 11056: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11057: my ($text,$name,$item,$chgstr);
1.48 raeburn 11058: if (ref($cats) eq 'ARRAY') {
11059: my $maxdepth = scalar(@{$cats});
11060: if (ref($cats->[$depth]) eq 'HASH') {
11061: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11062: my $numchildren = @{$cats->[$depth]{$parent}};
11063: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11064: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11065: my ($idxnum,$parent_name,$parent_item);
11066: my $higher = $depth - 1;
11067: if ($higher == 0) {
11068: $parent_name = &escape($parent).'::'.$higher;
11069: } else {
11070: if (ref($path) eq 'ARRAY') {
11071: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11072: }
11073: }
11074: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11075: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11076: if ($j < $numchildren) {
1.48 raeburn 11077: $name = $cats->[$depth]{$parent}[$j];
11078: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11079: $idxnum = $idx->{$item};
11080: } else {
11081: $name = $parent_name;
11082: $item = $parent_item;
1.48 raeburn 11083: }
1.49 raeburn 11084: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11085: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11086: for (my $i=0; $i<=$numchildren; $i++) {
11087: my $vpos = $i+1;
11088: my $selstr;
11089: if ($j == $i) {
11090: $selstr = ' selected="selected" ';
11091: }
11092: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11093: }
11094: $text .= '</select> ';
11095: if ($j < $numchildren) {
11096: my $deeper = $depth+1;
11097: $text .= $name.' '
11098: .'<label><input type="checkbox" name="deletecategory" value="'
11099: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11100: if(ref($path) eq 'ARRAY') {
11101: push(@{$path},$name);
1.49 raeburn 11102: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11103: pop(@{$path});
11104: }
11105: } else {
1.330 raeburn 11106: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11107: if ($j == $numchildren) {
11108: $text .= $name;
11109: } else {
11110: $text .= $item;
11111: }
11112: $text .= '" value="" />';
11113: }
11114: $text .= '</td></tr>';
11115: }
11116: $text .= '</table></td>';
11117: } else {
11118: my $higher = $depth-1;
11119: if ($higher == 0) {
11120: $name = &escape($parent).'::'.$higher;
11121: } else {
11122: if (ref($path) eq 'ARRAY') {
11123: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11124: }
11125: }
11126: my $colspan;
11127: if ($parent ne 'instcode') {
11128: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11129: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11130: }
11131: }
11132: }
11133: }
11134: return $text;
11135: }
11136:
1.33 raeburn 11137: sub modifiable_userdata_row {
1.305 raeburn 11138: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11139: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11140: my ($role,$rolename,$statustype);
11141: $role = $item;
1.224 raeburn 11142: if ($context eq 'cancreate') {
1.305 raeburn 11143: if ($item =~ /^(emailusername)_(.+)$/) {
11144: $role = $1;
11145: $statustype = $2;
1.228 raeburn 11146: if (ref($usertypes) eq 'HASH') {
11147: if ($usertypes->{$statustype}) {
11148: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11149: } else {
11150: $rolename = &mt('Data provided by user');
11151: }
11152: }
1.224 raeburn 11153: }
11154: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11155: if (ref($usertypes) eq 'HASH') {
11156: $rolename = $usertypes->{$role};
11157: } else {
11158: $rolename = $role;
11159: }
1.325 raeburn 11160: } elsif ($context eq 'lti') {
11161: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11162: } elsif ($context eq 'privacy') {
11163: $rolename = $itemdesc;
1.33 raeburn 11164: } else {
1.63 raeburn 11165: if ($role eq 'cr') {
11166: $rolename = &mt('Custom role');
11167: } else {
11168: $rolename = &Apache::lonnet::plaintext($role);
11169: }
1.33 raeburn 11170: }
1.224 raeburn 11171: my (@fields,%fieldtitles);
11172: if (ref($fieldsref) eq 'ARRAY') {
11173: @fields = @{$fieldsref};
11174: } else {
11175: @fields = ('lastname','firstname','middlename','generation',
11176: 'permanentemail','id');
11177: }
11178: if ((ref($titlesref) eq 'HASH')) {
11179: %fieldtitles = %{$titlesref};
11180: } else {
11181: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11182: }
1.33 raeburn 11183: my $output;
1.305 raeburn 11184: my $css_class;
11185: if ($rowcount%2) {
11186: $css_class = 'LC_odd_row';
11187: }
11188: if ($customcss) {
11189: $css_class .= " $customcss";
11190: }
11191: $css_class =~ s/^\s+//;
11192: if ($css_class) {
11193: $css_class = ' class="'.$css_class.'"';
11194: }
11195: if ($rowstyle) {
11196: $css_class .= ' style="'.$rowstyle.'"';
11197: }
11198: if ($rowid) {
11199: $rowid = ' id="'.$rowid.'"';
11200: }
11201: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11202: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11203: '<td class="LC_left_item" colspan="2"><table>';
11204: my $rem;
11205: my %checks;
1.325 raeburn 11206: my %current;
1.33 raeburn 11207: if (ref($settings) eq 'HASH') {
1.325 raeburn 11208: my $hashref;
11209: if ($context eq 'lti') {
11210: if (ref($settings) eq 'HASH') {
11211: $hashref = $settings->{'instdata'};
11212: }
1.357 raeburn 11213: } elsif ($context eq 'privacy') {
11214: my ($key,$inner) = split(/_/,$role);
11215: if (ref($settings) eq 'HASH') {
11216: if (ref($settings->{$key}) eq 'HASH') {
11217: $hashref = $settings->{$key}->{$inner};
11218: }
11219: }
1.325 raeburn 11220: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11221: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11222: $hashref = $settings->{'lti_instdata'};
11223: }
11224: if ($role eq 'emailusername') {
11225: if ($statustype) {
11226: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11227: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11228: }
1.325 raeburn 11229: }
11230: }
11231: }
11232: if (ref($hashref) eq 'HASH') {
11233: foreach my $field (@fields) {
11234: if ($hashref->{$field}) {
11235: if ($role eq 'emailusername') {
11236: $checks{$field} = $hashref->{$field};
11237: } else {
11238: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11239: }
11240: }
11241: }
11242: }
11243: }
1.305 raeburn 11244:
11245: my $total = scalar(@fields);
11246: for (my $i=0; $i<$total; $i++) {
11247: $rem = $i%($numinrow);
1.33 raeburn 11248: if ($rem == 0) {
11249: if ($i > 0) {
11250: $output .= '</tr>';
11251: }
11252: $output .= '<tr>';
11253: }
11254: my $check = ' ';
1.228 raeburn 11255: unless ($role eq 'emailusername') {
11256: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11257: $check = $checks{$fields[$i]};
1.357 raeburn 11258: } elsif ($context eq 'privacy') {
11259: if ($role =~ /^priv_(domain|course)$/) {
11260: if (ref($settings) ne 'HASH') {
11261: $check = ' checked="checked" ';
11262: }
11263: } elsif ($role =~ /^priv_(author|community)$/) {
11264: if (ref($settings) ne 'HASH') {
11265: unless ($fields[$i] eq 'id') {
11266: $check = ' checked="checked" ';
11267: }
11268: }
11269: } elsif ($role =~ /^(unpriv|othdom)_/) {
11270: if (ref($settings) ne 'HASH') {
11271: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11272: $check = ' checked="checked" ';
11273: }
11274: }
11275: }
1.325 raeburn 11276: } elsif ($context ne 'lti') {
1.228 raeburn 11277: if ($role eq 'st') {
11278: if (ref($settings) ne 'HASH') {
11279: $check = ' checked="checked" ';
11280: }
1.33 raeburn 11281: }
11282: }
11283: }
11284: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11285: '<span class="LC_nobreak">';
1.325 raeburn 11286: my $prefix = 'canmodify';
1.228 raeburn 11287: if ($role eq 'emailusername') {
11288: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11289: $checks{$fields[$i]} = 'omit';
11290: }
11291: foreach my $option ('required','optional','omit') {
11292: my $checked='';
11293: if ($checks{$fields[$i]} eq $option) {
11294: $checked='checked="checked" ';
11295: }
11296: $output .= '<label>'.
1.325 raeburn 11297: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11298: &mt($option).'</label>'.(' ' x2);
11299: }
11300: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11301: } else {
1.325 raeburn 11302: if ($context eq 'lti') {
11303: $prefix = 'lti';
1.357 raeburn 11304: } elsif ($context eq 'privacy') {
11305: $prefix = 'privacy';
1.325 raeburn 11306: }
1.228 raeburn 11307: $output .= '<label>'.
1.325 raeburn 11308: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11309: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11310: '</label>';
11311: }
11312: $output .= '</span></td>';
1.33 raeburn 11313: }
1.305 raeburn 11314: $rem = $total%$numinrow;
11315: my $colsleft;
11316: if ($rem) {
11317: $colsleft = $numinrow - $rem;
11318: }
11319: if ($colsleft > 1) {
1.33 raeburn 11320: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11321: ' </td>';
11322: } elsif ($colsleft == 1) {
11323: $output .= '<td class="LC_left_item"> </td>';
11324: }
11325: $output .= '</tr></table></td></tr>';
11326: return $output;
11327: }
1.28 raeburn 11328:
1.93 raeburn 11329: sub insttypes_row {
1.305 raeburn 11330: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11331: $customcss,$rowstyle) = @_;
1.93 raeburn 11332: my %lt = &Apache::lonlocal::texthash (
11333: cansearch => 'Users allowed to search',
11334: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11335: lockablenames => 'User preference to lock name',
1.305 raeburn 11336: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11337: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11338: );
11339: my $showdom;
11340: if ($context eq 'cansearch') {
11341: $showdom = ' ('.$dom.')';
11342: }
1.165 raeburn 11343: my $class = 'LC_left_item';
11344: if ($context eq 'statustocreate') {
11345: $class = 'LC_right_item';
11346: }
1.305 raeburn 11347: my $css_class;
11348: if ($$rowtotal%2) {
11349: $css_class = 'LC_odd_row';
11350: }
11351: if ($customcss) {
11352: $css_class .= ' '.$customcss;
11353: }
11354: $css_class =~ s/^\s+//;
11355: if ($css_class) {
11356: $css_class = ' class="'.$css_class.'"';
11357: }
11358: if ($rowstyle) {
11359: $css_class .= ' style="'.$rowstyle.'"';
11360: }
11361: if ($onclick) {
11362: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11363: }
11364: my $output = '<tr'.$css_class.'>'.
11365: '<td>'.$lt{$context}.$showdom.
11366: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11367: my $rem;
11368: if (ref($types) eq 'ARRAY') {
11369: for (my $i=0; $i<@{$types}; $i++) {
11370: if (defined($usertypes->{$types->[$i]})) {
11371: my $rem = $i%($numinrow);
11372: if ($rem == 0) {
11373: if ($i > 0) {
11374: $output .= '</tr>';
11375: }
11376: $output .= '<tr>';
1.23 raeburn 11377: }
1.26 raeburn 11378: my $check = ' ';
1.99 raeburn 11379: if (ref($settings) eq 'HASH') {
11380: if (ref($settings->{$context}) eq 'ARRAY') {
11381: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11382: $check = ' checked="checked" ';
11383: }
1.315 raeburn 11384: } elsif (ref($settings->{$context}) eq 'HASH') {
11385: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11386: $check = ' checked="checked" ';
11387: }
1.99 raeburn 11388: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11389: $check = ' checked="checked" ';
11390: }
1.23 raeburn 11391: }
1.26 raeburn 11392: $output .= '<td class="LC_left_item">'.
11393: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11394: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11395: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11396: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11397: }
11398: }
1.26 raeburn 11399: $rem = @{$types}%($numinrow);
1.23 raeburn 11400: }
11401: my $colsleft = $numinrow - $rem;
1.315 raeburn 11402: if ($context eq 'overrides') {
11403: if ($colsleft > 1) {
11404: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11405: } else {
11406: $output .= '<td class="LC_left_item">';
11407: }
11408: $output .= ' ';
1.23 raeburn 11409: } else {
1.334 raeburn 11410: if ($rem == 0) {
1.315 raeburn 11411: $output .= '<tr>';
11412: }
11413: if ($colsleft > 1) {
11414: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11415: } else {
11416: $output .= '<td class="LC_left_item">';
11417: }
11418: my $defcheck = ' ';
11419: if (ref($settings) eq 'HASH') {
11420: if (ref($settings->{$context}) eq 'ARRAY') {
11421: if (grep(/^default$/,@{$settings->{$context}})) {
11422: $defcheck = ' checked="checked" ';
11423: }
11424: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11425: $defcheck = ' checked="checked" ';
11426: }
1.26 raeburn 11427: }
1.315 raeburn 11428: $output .= '<span class="LC_nobreak"><label>'.
11429: '<input type="checkbox" name="'.$context.'" '.
11430: 'value="default"'.$defcheck.$onclick.' />'.
11431: $othertitle.'</label></span>';
1.23 raeburn 11432: }
1.315 raeburn 11433: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11434: return $output;
1.23 raeburn 11435: }
11436:
11437: sub sorted_searchtitles {
11438: my %searchtitles = &Apache::lonlocal::texthash(
11439: 'uname' => 'username',
11440: 'lastname' => 'last name',
11441: 'lastfirst' => 'last name, first name',
11442: );
11443: my @titleorder = ('uname','lastname','lastfirst');
11444: return (\%searchtitles,\@titleorder);
11445: }
11446:
1.25 raeburn 11447: sub sorted_searchtypes {
11448: my %srchtypes_desc = (
11449: exact => 'is exact match',
11450: contains => 'contains ..',
11451: begins => 'begins with ..',
11452: );
11453: my @srchtypeorder = ('exact','begins','contains');
11454: return (\%srchtypes_desc,\@srchtypeorder);
11455: }
11456:
1.3 raeburn 11457: sub usertype_update_row {
11458: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11459: my $datatable;
11460: my $numinrow = 4;
11461: foreach my $type (@{$types}) {
11462: if (defined($usertypes->{$type})) {
11463: $$rownums ++;
11464: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11465: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11466: '</td><td class="LC_left_item"><table>';
11467: for (my $i=0; $i<@{$fields}; $i++) {
11468: my $rem = $i%($numinrow);
11469: if ($rem == 0) {
11470: if ($i > 0) {
11471: $datatable .= '</tr>';
11472: }
11473: $datatable .= '<tr>';
11474: }
11475: my $check = ' ';
1.39 raeburn 11476: if (ref($settings) eq 'HASH') {
11477: if (ref($settings->{'fields'}) eq 'HASH') {
11478: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11479: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11480: $check = ' checked="checked" ';
11481: }
1.3 raeburn 11482: }
11483: }
11484: }
11485:
11486: if ($i == @{$fields}-1) {
11487: my $colsleft = $numinrow - $rem;
11488: if ($colsleft > 1) {
11489: $datatable .= '<td colspan="'.$colsleft.'">';
11490: } else {
11491: $datatable .= '<td>';
11492: }
11493: } else {
11494: $datatable .= '<td>';
11495: }
1.8 raeburn 11496: $datatable .= '<span class="LC_nobreak"><label>'.
11497: '<input type="checkbox" name="updateable_'.$type.
11498: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11499: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11500: }
11501: $datatable .= '</tr></table></td></tr>';
11502: }
11503: }
11504: return $datatable;
1.1 raeburn 11505: }
11506:
11507: sub modify_login {
1.205 raeburn 11508: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11509: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11510: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
11511: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168 raeburn 11512: %title = ( coursecatalog => 'Display course catalog',
11513: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11514: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11515: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11516: loginheader => 'Log-in box header',
11517: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11518: @offon = ('off','on');
1.112 raeburn 11519: if (ref($domconfig{login}) eq 'HASH') {
11520: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11521: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11522: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11523: }
11524: }
1.386 raeburn 11525: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11526: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11527: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11528: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11529: $saml{$lonhost} = 1;
11530: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11531: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11532: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11533: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11534: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
11535: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11536: }
11537: }
11538: }
1.112 raeburn 11539: }
1.9 raeburn 11540: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11541: \%domconfig,\%loginhash);
1.188 raeburn 11542: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11543: foreach my $item (@toggles) {
11544: $loginhash{login}{$item} = $env{'form.'.$item};
11545: }
1.41 raeburn 11546: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11547: if (ref($colchanges{'login'}) eq 'HASH') {
11548: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11549: \%loginhash);
11550: }
1.110 raeburn 11551:
1.149 raeburn 11552: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11553: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11554: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11555: if (keys(%servers) > 1) {
11556: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11557: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11558: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11559: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11560: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11561: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11562: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11563: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11564: $changes{'loginvia'}{$lonhost} = 1;
11565: } else {
11566: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11567: $changes{'loginvia'}{$lonhost} = 1;
11568: }
11569: } else {
11570: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11571: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11572: $changes{'loginvia'}{$lonhost} = 1;
11573: }
11574: }
11575: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11576: foreach my $item (@loginvia_attribs) {
11577: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11578: }
11579: } else {
11580: foreach my $item (@loginvia_attribs) {
11581: my $new = $env{'form.'.$lonhost.'_'.$item};
11582: if (($item eq 'serverpath') && ($new eq 'custom')) {
11583: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11584: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11585: $new = '/';
11586: }
11587: }
11588: if (($item eq 'custompath') &&
11589: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11590: $new = '';
11591: }
11592: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11593: $changes{'loginvia'}{$lonhost} = 1;
11594: }
11595: if ($item eq 'exempt') {
1.256 raeburn 11596: $new = &check_exempt_addresses($new);
1.128 raeburn 11597: }
11598: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11599: }
11600: }
1.112 raeburn 11601: } else {
1.128 raeburn 11602: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11603: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11604: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11605: foreach my $item (@loginvia_attribs) {
11606: my $new = $env{'form.'.$lonhost.'_'.$item};
11607: if (($item eq 'serverpath') && ($new eq 'custom')) {
11608: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11609: $new = '/';
11610: }
11611: }
11612: if (($item eq 'custompath') &&
11613: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11614: $new = '';
11615: }
11616: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11617: }
1.110 raeburn 11618: }
11619: }
11620: }
11621: }
1.119 raeburn 11622:
1.168 raeburn 11623: my $servadm = $r->dir_config('lonAdmEMail');
11624: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11625: if (ref($domconfig{'login'}) eq 'HASH') {
11626: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11627: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11628: if ($lang eq 'nolang') {
11629: push(@currlangs,$lang);
11630: } elsif (defined($langchoices{$lang})) {
11631: push(@currlangs,$lang);
11632: } else {
11633: next;
11634: }
11635: }
11636: }
11637: }
11638: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11639: if (@currlangs > 0) {
11640: foreach my $lang (@currlangs) {
11641: if (grep(/^\Q$lang\E$/,@delurls)) {
11642: $changes{'helpurl'}{$lang} = 1;
11643: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11644: $changes{'helpurl'}{$lang} = 1;
11645: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11646: push(@newlangs,$lang);
11647: } else {
11648: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11649: }
11650: }
11651: }
11652: unless (grep(/^nolang$/,@currlangs)) {
11653: if ($env{'form.loginhelpurl_nolang.filename'}) {
11654: $changes{'helpurl'}{'nolang'} = 1;
11655: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11656: push(@newlangs,'nolang');
11657: }
11658: }
11659: if ($env{'form.loginhelpurl_add_lang'}) {
11660: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11661: ($env{'form.loginhelpurl_add_file.filename'})) {
11662: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11663: $addedfile = $env{'form.loginhelpurl_add_lang'};
11664: }
11665: }
11666: if ((@newlangs > 0) || ($addedfile)) {
11667: my $error;
11668: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11669: if ($configuserok eq 'ok') {
11670: if ($switchserver) {
11671: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11672: } elsif ($author_ok eq 'ok') {
11673: my @allnew = @newlangs;
11674: if ($addedfile ne '') {
11675: push(@allnew,$addedfile);
11676: }
11677: foreach my $lang (@allnew) {
11678: my $formelem = 'loginhelpurl_'.$lang;
11679: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11680: $formelem = 'loginhelpurl_add_file';
11681: }
11682: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11683: "help/$lang",'','',$newfile{$lang});
11684: if ($result eq 'ok') {
11685: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11686: $changes{'helpurl'}{$lang} = 1;
11687: } else {
11688: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11689: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11690: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11691: (!grep(/^\Q$lang\E$/,@delurls))) {
11692: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11693: }
11694: }
11695: }
11696: } else {
11697: $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);
11698: }
11699: } else {
11700: $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);
11701: }
11702: if ($error) {
11703: &Apache::lonnet::logthis($error);
11704: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11705: }
11706: }
1.256 raeburn 11707:
11708: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11709: if (ref($domconfig{'login'}) eq 'HASH') {
11710: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11711: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11712: if ($domservers{$lonhost}) {
11713: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11714: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11715: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11716: }
11717: }
11718: }
11719: }
11720: }
11721: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11722: foreach my $lonhost (sort(keys(%domservers))) {
11723: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11724: $changes{'headtag'}{$lonhost} = 1;
11725: } else {
11726: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11727: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11728: }
11729: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11730: push(@newhosts,$lonhost);
11731: } elsif ($currheadtagurls{$lonhost}) {
11732: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11733: if ($currexempt{$lonhost}) {
1.289 raeburn 11734: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11735: $changes{'headtag'}{$lonhost} = 1;
11736: }
11737: } elsif ($possexempt{$lonhost}) {
11738: $changes{'headtag'}{$lonhost} = 1;
11739: }
11740: if ($possexempt{$lonhost}) {
11741: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11742: }
11743: }
11744: }
11745: }
11746: if (@newhosts) {
11747: my $error;
11748: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11749: if ($configuserok eq 'ok') {
11750: if ($switchserver) {
11751: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11752: } elsif ($author_ok eq 'ok') {
11753: foreach my $lonhost (@newhosts) {
11754: my $formelem = 'loginheadtag_'.$lonhost;
11755: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11756: "login/headtag/$lonhost",'','',
11757: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11758: if ($result eq 'ok') {
11759: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11760: $changes{'headtag'}{$lonhost} = 1;
11761: if ($possexempt{$lonhost}) {
11762: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11763: }
11764: } else {
11765: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11766: $newheadtagurls{$lonhost},$result);
11767: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11768: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11769: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11770: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11771: }
11772: }
11773: }
11774: } else {
11775: $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);
11776: }
11777: } else {
11778: $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);
11779: }
11780: if ($error) {
11781: &Apache::lonnet::logthis($error);
11782: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11783: }
11784: }
1.386 raeburn 11785: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11786: my @newsamlimgs;
11787: foreach my $lonhost (keys(%domservers)) {
11788: if ($env{'form.saml_'.$lonhost}) {
11789: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11790: push(@newsamlimgs,$lonhost);
11791: }
11792: foreach my $item ('text','alt','url','title','notsso') {
11793: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11794: }
11795: if ($saml{$lonhost}) {
11796: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11797: #FIXME Need to obsolete published image
11798: delete($currsaml{$lonhost}{'img'});
11799: $changes{'saml'}{$lonhost} = 1;
11800: }
11801: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11802: $changes{'saml'}{$lonhost} = 1;
11803: }
11804: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11805: $changes{'saml'}{$lonhost} = 1;
11806: }
11807: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11808: $changes{'saml'}{$lonhost} = 1;
11809: }
11810: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11811: $changes{'saml'}{$lonhost} = 1;
11812: }
11813: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11814: $changes{'saml'}{$lonhost} = 1;
11815: }
11816: } else {
11817: $changes{'saml'}{$lonhost} = 1;
11818: }
11819: foreach my $item ('text','alt','url','title','notsso') {
11820: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11821: }
11822: } else {
1.389 raeburn 11823: if ($saml{$lonhost}) {
11824: $changes{'saml'}{$lonhost} = 1;
11825: delete($currsaml{$lonhost});
11826: }
1.386 raeburn 11827: }
11828: }
11829: foreach my $posshost (keys(%currsaml)) {
11830: unless (exists($domservers{$posshost})) {
11831: delete($currsaml{$posshost});
11832: }
11833: }
11834: %{$loginhash{'login'}{'saml'}} = %currsaml;
11835: if (@newsamlimgs) {
11836: my $error;
11837: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11838: if ($configuserok eq 'ok') {
11839: if ($switchserver) {
11840: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11841: } elsif ($author_ok eq 'ok') {
11842: foreach my $lonhost (@newsamlimgs) {
11843: my $formelem = 'saml_img_'.$lonhost;
11844: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11845: "login/saml/$lonhost",'','',
11846: $env{'form.saml_img_'.$lonhost.'.filename'});
11847: if ($result eq 'ok') {
11848: $currsaml{$lonhost}{'img'} = $imgurl;
11849: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11850: $changes{'saml'}{$lonhost} = 1;
11851: } else {
11852: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11853: $lonhost,$result);
11854: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11855: }
11856: }
11857: } else {
11858: $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);
11859: }
11860: } else {
11861: $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);
11862: }
11863: if ($error) {
11864: &Apache::lonnet::logthis($error);
11865: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11866: }
11867: }
1.169 raeburn 11868: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11869:
11870: my $defaulthelpfile = '/adm/loginproblems.html';
11871: my $defaulttext = &mt('Default in use');
11872:
1.1 raeburn 11873: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11874: $dom);
11875: if ($putresult eq 'ok') {
1.188 raeburn 11876: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11877: my %defaultchecked = (
11878: 'coursecatalog' => 'on',
1.188 raeburn 11879: 'helpdesk' => 'on',
1.42 raeburn 11880: 'adminmail' => 'off',
1.43 raeburn 11881: 'newuser' => 'off',
1.42 raeburn 11882: );
1.55 raeburn 11883: if (ref($domconfig{'login'}) eq 'HASH') {
11884: foreach my $item (@toggles) {
11885: if ($defaultchecked{$item} eq 'on') {
11886: if (($domconfig{'login'}{$item} eq '0') &&
11887: ($env{'form.'.$item} eq '1')) {
11888: $changes{$item} = 1;
11889: } elsif (($domconfig{'login'}{$item} eq '' ||
11890: $domconfig{'login'}{$item} eq '1') &&
11891: ($env{'form.'.$item} eq '0')) {
11892: $changes{$item} = 1;
11893: }
11894: } elsif ($defaultchecked{$item} eq 'off') {
11895: if (($domconfig{'login'}{$item} eq '1') &&
11896: ($env{'form.'.$item} eq '0')) {
11897: $changes{$item} = 1;
11898: } elsif (($domconfig{'login'}{$item} eq '' ||
11899: $domconfig{'login'}{$item} eq '0') &&
11900: ($env{'form.'.$item} eq '1')) {
11901: $changes{$item} = 1;
11902: }
1.42 raeburn 11903: }
11904: }
1.41 raeburn 11905: }
1.6 raeburn 11906: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11907: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 11908: if (exists($changes{'saml'})) {
11909: my $hostid_in_use;
11910: my @hosts = &Apache::lonnet::current_machine_ids();
11911: if (@hosts > 1) {
11912: foreach my $hostid (@hosts) {
11913: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11914: $hostid_in_use = $hostid;
11915: last;
11916: }
11917: }
11918: } else {
11919: $hostid_in_use = $r->dir_config('lonHostID');
11920: }
11921: if (($hostid_in_use) &&
11922: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 11923: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 11924: }
11925: if (ref($lastactref) eq 'HASH') {
11926: if (ref($changes{'saml'}) eq 'HASH') {
11927: my %updates;
11928: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11929: $lastactref->{'samllanding'} = \%updates;
11930: }
11931: }
11932: }
1.212 raeburn 11933: if (ref($lastactref) eq 'HASH') {
11934: $lastactref->{'domainconfig'} = 1;
11935: }
1.1 raeburn 11936: $resulttext = &mt('Changes made:').'<ul>';
11937: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11938: if ($item eq 'loginvia') {
1.112 raeburn 11939: if (ref($changes{$item}) eq 'HASH') {
11940: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11941: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11942: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11943: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11944: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11945: $protocol = 'http' if ($protocol ne 'https');
11946: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11947:
11948: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11949: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11950: } else {
11951: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11952: }
11953: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11954: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11955: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11956: }
11957: $resulttext .= '</li>';
11958: } else {
11959: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11960: }
1.112 raeburn 11961: } else {
1.128 raeburn 11962: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11963: }
11964: }
1.128 raeburn 11965: $resulttext .= '</ul></li>';
1.112 raeburn 11966: }
1.168 raeburn 11967: } elsif ($item eq 'helpurl') {
11968: if (ref($changes{$item}) eq 'HASH') {
11969: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11970: if (grep(/^\Q$lang\E$/,@delurls)) {
11971: my ($chg,$link);
11972: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11973: if ($lang eq 'nolang') {
11974: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11975: } else {
11976: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11977: }
11978: $resulttext .= '<li>'.$chg.'</li>';
11979: } else {
11980: my $chg;
11981: if ($lang eq 'nolang') {
11982: $chg = &mt('custom log-in help file for no preferred language');
11983: } else {
11984: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11985: }
11986: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11987: $loginhash{'login'}{'helpurl'}{$lang}.
11988: '?inhibitmenu=yes',$chg,600,500).
11989: '</li>';
11990: }
11991: }
11992: }
1.256 raeburn 11993: } elsif ($item eq 'headtag') {
11994: if (ref($changes{$item}) eq 'HASH') {
11995: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11996: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11997: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11998: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11999: $resulttext .= '<li><a href="'.
12000: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12001: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12002: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12003: if ($possexempt{$lonhost}) {
12004: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12005: } else {
12006: $resulttext .= &mt('included for any client IP');
12007: }
12008: $resulttext .= '</li>';
12009: }
12010: }
12011: }
1.386 raeburn 12012: } elsif ($item eq 'saml') {
12013: if (ref($changes{$item}) eq 'HASH') {
12014: my %notlt = (
12015: text => 'Text for log-in by SSO',
12016: img => 'SSO button image',
12017: alt => 'Alt text for button image',
12018: url => 'SSO URL',
12019: title => 'Tooltip for SSO link',
12020: notsso => 'Text for non-SSO log-in',
12021: );
12022: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12023: if (ref($currsaml{$lonhost}) eq 'HASH') {
12024: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12025: '<ul>';
12026: foreach my $key ('text','img','alt','url','title','notsso') {
12027: if ($currsaml{$lonhost}{$key} eq '') {
12028: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12029: } else {
12030: my $value = "'$currsaml{$lonhost}{$key}'";
12031: if ($key eq 'img') {
12032: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
12033: }
12034: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12035: $value).'</li>';
12036: }
12037: }
12038: $resulttext .= '</ul></li>';
12039: } else {
12040: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12041: }
12042: }
12043: }
1.169 raeburn 12044: } elsif ($item eq 'captcha') {
12045: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12046: my $chgtxt;
1.169 raeburn 12047: if ($loginhash{'login'}{$item} eq 'notused') {
12048: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12049: } else {
12050: my %captchas = &captcha_phrases();
12051: if ($captchas{$loginhash{'login'}{$item}}) {
12052: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12053: } else {
12054: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12055: }
12056: }
12057: $resulttext .= '<li>'.$chgtxt.'</li>';
12058: }
12059: } elsif ($item eq 'recaptchakeys') {
12060: if (ref($loginhash{'login'}) eq 'HASH') {
12061: my ($privkey,$pubkey);
12062: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12063: $pubkey = $loginhash{'login'}{$item}{'public'};
12064: $privkey = $loginhash{'login'}{$item}{'private'};
12065: }
12066: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12067: if (!$pubkey) {
12068: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12069: } else {
12070: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12071: }
12072: if (!$privkey) {
12073: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12074: } else {
1.251 raeburn 12075: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12076: }
12077: $chgtxt .= '</ul>';
12078: $resulttext .= '<li>'.$chgtxt.'</li>';
12079: }
1.269 raeburn 12080: } elsif ($item eq 'recaptchaversion') {
12081: if (ref($loginhash{'login'}) eq 'HASH') {
12082: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12083: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12084: '</li>';
12085: }
12086: }
1.41 raeburn 12087: } else {
12088: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12089: }
1.1 raeburn 12090: }
1.6 raeburn 12091: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12092: } else {
12093: $resulttext = &mt('No changes made to log-in page settings');
12094: }
12095: } else {
1.11 albertel 12096: $resulttext = '<span class="LC_error">'.
12097: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12098: }
1.6 raeburn 12099: if ($errors) {
1.9 raeburn 12100: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12101: $errors.'</ul>';
12102: }
12103: return $resulttext;
12104: }
12105:
1.256 raeburn 12106: sub check_exempt_addresses {
12107: my ($iplist) = @_;
12108: $iplist =~ s/^\s+//;
12109: $iplist =~ s/\s+$//;
12110: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12111: my (@okips,$new);
12112: foreach my $ip (@poss_ips) {
12113: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12114: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12115: push(@okips,$ip);
12116: }
12117: }
12118: }
12119: if (@okips > 0) {
12120: $new = join(',',@okips);
12121: } else {
12122: $new = '';
12123: }
12124: return $new;
12125: }
12126:
1.6 raeburn 12127: sub color_font_choices {
12128: my %choices =
12129: &Apache::lonlocal::texthash (
12130: img => "Header",
12131: bgs => "Background colors",
12132: links => "Link colors",
1.55 raeburn 12133: images => "Images",
1.6 raeburn 12134: font => "Font color",
1.201 raeburn 12135: fontmenu => "Font menu",
1.76 raeburn 12136: pgbg => "Page",
1.6 raeburn 12137: tabbg => "Header",
12138: sidebg => "Border",
12139: link => "Link",
12140: alink => "Active link",
12141: vlink => "Visited link",
12142: );
12143: return %choices;
12144: }
12145:
12146: sub modify_rolecolors {
1.205 raeburn 12147: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12148: my ($resulttext,%rolehash);
12149: $rolehash{'rolecolors'} = {};
1.55 raeburn 12150: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12151: if ($domconfig{'rolecolors'} eq '') {
12152: $domconfig{'rolecolors'} = {};
12153: }
12154: }
1.9 raeburn 12155: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12156: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12157: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12158: $dom);
12159: if ($putresult eq 'ok') {
12160: if (keys(%changes) > 0) {
1.41 raeburn 12161: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12162: if (ref($lastactref) eq 'HASH') {
12163: $lastactref->{'domainconfig'} = 1;
12164: }
1.6 raeburn 12165: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12166: $rolehash{'rolecolors'});
12167: } else {
12168: $resulttext = &mt('No changes made to default color schemes');
12169: }
12170: } else {
1.11 albertel 12171: $resulttext = '<span class="LC_error">'.
12172: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12173: }
12174: if ($errors) {
12175: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12176: $errors.'</ul>';
12177: }
12178: return $resulttext;
12179: }
12180:
12181: sub modify_colors {
1.9 raeburn 12182: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12183: my (%changes,%choices);
1.51 raeburn 12184: my @bgs;
1.6 raeburn 12185: my @links = ('link','alink','vlink');
1.41 raeburn 12186: my @logintext;
1.6 raeburn 12187: my @images;
12188: my $servadm = $r->dir_config('lonAdmEMail');
12189: my $errors;
1.200 raeburn 12190: my %defaults;
1.6 raeburn 12191: foreach my $role (@{$roles}) {
12192: if ($role eq 'login') {
1.12 raeburn 12193: %choices = &login_choices();
1.41 raeburn 12194: @logintext = ('textcol','bgcol');
1.12 raeburn 12195: } else {
12196: %choices = &color_font_choices();
12197: }
12198: if ($role eq 'login') {
1.41 raeburn 12199: @images = ('img','logo','domlogo','login');
1.51 raeburn 12200: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12201: } else {
12202: @images = ('img');
1.200 raeburn 12203: @bgs = ('pgbg','tabbg','sidebg');
12204: }
12205: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12206: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12207: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12208: }
12209: if ($role eq 'login') {
12210: foreach my $item (@logintext) {
1.234 raeburn 12211: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12212: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12213: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12214: }
12215: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12216: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12217: }
12218: }
12219: } else {
1.234 raeburn 12220: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12221: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12222: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12223: }
12224: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12225: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12226: }
1.6 raeburn 12227: }
1.200 raeburn 12228: foreach my $item (@bgs) {
1.234 raeburn 12229: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12230: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12231: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12232: }
12233: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12234: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12235: }
12236: }
12237: foreach my $item (@links) {
1.234 raeburn 12238: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12239: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12240: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12241: }
12242: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12243: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12244: }
1.6 raeburn 12245: }
1.46 raeburn 12246: my ($configuserok,$author_ok,$switchserver) =
12247: &config_check($dom,$confname,$servadm);
1.9 raeburn 12248: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12249: if (ref($domconfig->{$role}) ne 'HASH') {
12250: $domconfig->{$role} = {};
12251: }
1.8 raeburn 12252: foreach my $img (@images) {
1.70 raeburn 12253: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
12254: if (defined($env{'form.login_showlogo_'.$img})) {
12255: $confhash->{$role}{'showlogo'}{$img} = 1;
12256: } else {
12257: $confhash->{$role}{'showlogo'}{$img} = 0;
12258: }
12259: }
1.18 albertel 12260: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12261: && !defined($domconfig->{$role}{$img})
12262: && !$env{'form.'.$role.'_del_'.$img}
12263: && $env{'form.'.$role.'_import_'.$img}) {
12264: # import the old configured image from the .tab setting
12265: # if they haven't provided a new one
12266: $domconfig->{$role}{$img} =
12267: $env{'form.'.$role.'_import_'.$img};
12268: }
1.6 raeburn 12269: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12270: my $error;
1.6 raeburn 12271: if ($configuserok eq 'ok') {
1.9 raeburn 12272: if ($switchserver) {
1.12 raeburn 12273: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12274: } else {
12275: if ($author_ok eq 'ok') {
12276: my ($result,$logourl) =
12277: &publishlogo($r,'upload',$role.'_'.$img,
12278: $dom,$confname,$img,$width,$height);
12279: if ($result eq 'ok') {
12280: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12281: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12282: } else {
1.12 raeburn 12283: $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 12284: }
12285: } else {
1.46 raeburn 12286: $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 12287: }
12288: }
12289: } else {
1.46 raeburn 12290: $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 12291: }
12292: if ($error) {
1.8 raeburn 12293: &Apache::lonnet::logthis($error);
1.11 albertel 12294: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12295: }
12296: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12297: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12298: my $error;
12299: if ($configuserok eq 'ok') {
12300: # is confname an author?
12301: if ($switchserver eq '') {
12302: if ($author_ok eq 'ok') {
12303: my ($result,$logourl) =
12304: &publishlogo($r,'copy',$domconfig->{$role}{$img},
12305: $dom,$confname,$img,$width,$height);
12306: if ($result eq 'ok') {
12307: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12308: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12309: }
12310: }
12311: }
12312: }
1.6 raeburn 12313: }
12314: }
12315: }
12316: if (ref($domconfig) eq 'HASH') {
12317: if (ref($domconfig->{$role}) eq 'HASH') {
12318: foreach my $img (@images) {
12319: if ($domconfig->{$role}{$img} ne '') {
12320: if ($env{'form.'.$role.'_del_'.$img}) {
12321: $confhash->{$role}{$img} = '';
1.12 raeburn 12322: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12323: } else {
1.9 raeburn 12324: if ($confhash->{$role}{$img} eq '') {
12325: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12326: }
1.6 raeburn 12327: }
12328: } else {
12329: if ($env{'form.'.$role.'_del_'.$img}) {
12330: $confhash->{$role}{$img} = '';
1.12 raeburn 12331: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12332: }
12333: }
1.70 raeburn 12334: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
12335: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12336: if ($confhash->{$role}{'showlogo'}{$img} ne
12337: $domconfig->{$role}{'showlogo'}{$img}) {
12338: $changes{$role}{'showlogo'}{$img} = 1;
12339: }
12340: } else {
12341: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12342: $changes{$role}{'showlogo'}{$img} = 1;
12343: }
12344: }
12345: }
12346: }
1.6 raeburn 12347: if ($domconfig->{$role}{'font'} ne '') {
12348: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12349: $changes{$role}{'font'} = 1;
12350: }
12351: } else {
12352: if ($confhash->{$role}{'font'}) {
12353: $changes{$role}{'font'} = 1;
12354: }
12355: }
1.107 raeburn 12356: if ($role ne 'login') {
12357: if ($domconfig->{$role}{'fontmenu'} ne '') {
12358: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12359: $changes{$role}{'fontmenu'} = 1;
12360: }
12361: } else {
12362: if ($confhash->{$role}{'fontmenu'}) {
12363: $changes{$role}{'fontmenu'} = 1;
12364: }
1.97 tempelho 12365: }
12366: }
1.6 raeburn 12367: foreach my $item (@bgs) {
12368: if ($domconfig->{$role}{$item} ne '') {
12369: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12370: $changes{$role}{'bgs'}{$item} = 1;
12371: }
12372: } else {
12373: if ($confhash->{$role}{$item}) {
12374: $changes{$role}{'bgs'}{$item} = 1;
12375: }
12376: }
12377: }
12378: foreach my $item (@links) {
12379: if ($domconfig->{$role}{$item} ne '') {
12380: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12381: $changes{$role}{'links'}{$item} = 1;
12382: }
12383: } else {
12384: if ($confhash->{$role}{$item}) {
12385: $changes{$role}{'links'}{$item} = 1;
12386: }
12387: }
12388: }
1.41 raeburn 12389: foreach my $item (@logintext) {
12390: if ($domconfig->{$role}{$item} ne '') {
12391: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12392: $changes{$role}{'logintext'}{$item} = 1;
12393: }
12394: } else {
12395: if ($confhash->{$role}{$item}) {
12396: $changes{$role}{'logintext'}{$item} = 1;
12397: }
12398: }
12399: }
1.6 raeburn 12400: } else {
12401: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12402: \@logintext,$confhash,\%changes);
1.6 raeburn 12403: }
12404: } else {
12405: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12406: \@logintext,$confhash,\%changes);
1.6 raeburn 12407: }
12408: }
12409: return ($errors,%changes);
12410: }
12411:
1.46 raeburn 12412: sub config_check {
12413: my ($dom,$confname,$servadm) = @_;
12414: my ($configuserok,$author_ok,$switchserver,%currroles);
12415: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12416: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12417: $confname,$servadm);
12418: if ($configuserok eq 'ok') {
12419: $switchserver = &check_switchserver($dom,$confname);
12420: if ($switchserver eq '') {
12421: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12422: }
12423: }
12424: return ($configuserok,$author_ok,$switchserver);
12425: }
12426:
1.6 raeburn 12427: sub default_change_checker {
1.41 raeburn 12428: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12429: foreach my $item (@{$links}) {
12430: if ($confhash->{$role}{$item}) {
12431: $changes->{$role}{'links'}{$item} = 1;
12432: }
12433: }
12434: foreach my $item (@{$bgs}) {
12435: if ($confhash->{$role}{$item}) {
12436: $changes->{$role}{'bgs'}{$item} = 1;
12437: }
12438: }
1.41 raeburn 12439: foreach my $item (@{$logintext}) {
12440: if ($confhash->{$role}{$item}) {
12441: $changes->{$role}{'logintext'}{$item} = 1;
12442: }
12443: }
1.6 raeburn 12444: foreach my $img (@{$images}) {
12445: if ($env{'form.'.$role.'_del_'.$img}) {
12446: $confhash->{$role}{$img} = '';
1.12 raeburn 12447: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12448: }
1.70 raeburn 12449: if ($role eq 'login') {
12450: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12451: $changes->{$role}{'showlogo'}{$img} = 1;
12452: }
12453: }
1.6 raeburn 12454: }
12455: if ($confhash->{$role}{'font'}) {
12456: $changes->{$role}{'font'} = 1;
12457: }
1.48 raeburn 12458: }
1.6 raeburn 12459:
12460: sub display_colorchgs {
12461: my ($dom,$changes,$roles,$confhash) = @_;
12462: my (%choices,$resulttext);
12463: if (!grep(/^login$/,@{$roles})) {
12464: $resulttext = &mt('Changes made:').'<br />';
12465: }
12466: foreach my $role (@{$roles}) {
12467: if ($role eq 'login') {
12468: %choices = &login_choices();
12469: } else {
12470: %choices = &color_font_choices();
12471: }
12472: if (ref($changes->{$role}) eq 'HASH') {
12473: if ($role ne 'login') {
12474: $resulttext .= '<h4>'.&mt($role).'</h4>';
12475: }
12476: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12477: if ($role ne 'login') {
12478: $resulttext .= '<ul>';
12479: }
12480: if (ref($changes->{$role}{$key}) eq 'HASH') {
12481: if ($role ne 'login') {
12482: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12483: }
12484: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12485: if (($role eq 'login') && ($key eq 'showlogo')) {
12486: if ($confhash->{$role}{$key}{$item}) {
12487: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12488: } else {
12489: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12490: }
12491: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12492: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12493: } else {
1.12 raeburn 12494: my $newitem = $confhash->{$role}{$item};
12495: if ($key eq 'images') {
1.306 raeburn 12496: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 12497: }
12498: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12499: }
12500: }
12501: if ($role ne 'login') {
12502: $resulttext .= '</ul></li>';
12503: }
12504: } else {
12505: if ($confhash->{$role}{$key} eq '') {
12506: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12507: } else {
12508: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12509: }
12510: }
12511: if ($role ne 'login') {
12512: $resulttext .= '</ul>';
12513: }
12514: }
12515: }
12516: }
1.3 raeburn 12517: return $resulttext;
1.1 raeburn 12518: }
12519:
1.9 raeburn 12520: sub thumb_dimensions {
12521: return ('200','50');
12522: }
12523:
1.16 raeburn 12524: sub check_dimensions {
12525: my ($inputfile) = @_;
12526: my ($fullwidth,$fullheight);
12527: if ($inputfile =~ m|^[/\w.\-]+$|) {
12528: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12529: my $imageinfo = <PIPE>;
12530: if (!close(PIPE)) {
12531: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12532: }
12533: chomp($imageinfo);
12534: my ($fullsize) =
1.21 raeburn 12535: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12536: if ($fullsize) {
12537: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12538: }
12539: }
12540: }
12541: return ($fullwidth,$fullheight);
12542: }
12543:
1.9 raeburn 12544: sub check_configuser {
12545: my ($uhome,$dom,$confname,$servadm) = @_;
12546: my ($configuserok,%currroles);
12547: if ($uhome eq 'no_host') {
12548: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 12549: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12550: $configuserok =
12551: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12552: $configpass,'','','','','',undef,$servadm);
12553: } else {
12554: $configuserok = 'ok';
12555: %currroles =
12556: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12557: }
12558: return ($configuserok,%currroles);
12559: }
12560:
12561: sub check_authorstatus {
12562: my ($dom,$confname,%currroles) = @_;
12563: my $author_ok;
1.40 raeburn 12564: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12565: my $start = time;
12566: my $end = 0;
12567: $author_ok =
12568: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12569: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12570: } else {
12571: $author_ok = 'ok';
12572: }
12573: return $author_ok;
12574: }
12575:
12576: sub publishlogo {
1.46 raeburn 12577: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 12578: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 12579: if ($action eq 'upload') {
12580: $fname=$env{'form.'.$formname.'.filename'};
12581: chop($env{'form.'.$formname});
12582: } else {
12583: ($fname) = ($formname =~ /([^\/]+)$/);
12584: }
1.46 raeburn 12585: if ($savefileas ne '') {
12586: $fname = $savefileas;
12587: }
1.9 raeburn 12588: $fname=&Apache::lonnet::clean_filename($fname);
12589: # See if there is anything left
12590: unless ($fname) { return ('error: no uploaded file'); }
12591: $fname="$subdir/$fname";
1.210 raeburn 12592: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 12593: my $filepath="$docroot/priv";
12594: my $relpath = "$dom/$confname";
1.9 raeburn 12595: my ($fnamepath,$file,$fetchthumb);
12596: $file=$fname;
12597: if ($fname=~m|/|) {
12598: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
12599: }
1.164 raeburn 12600: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 12601: my $count;
1.164 raeburn 12602: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 12603: $filepath.="/$parts[$count]";
12604: if ((-e $filepath)!=1) {
12605: mkdir($filepath,02770);
12606: }
12607: }
12608: # Check for bad extension and disallow upload
12609: if ($file=~/\.(\w+)$/ &&
12610: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
12611: $output =
1.207 bisitz 12612: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 12613: } elsif ($file=~/\.(\w+)$/ &&
12614: !defined(&Apache::loncommon::fileembstyle($1))) {
12615: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
12616: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 12617: $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 12618: } elsif (-d "$filepath/$file") {
1.195 bisitz 12619: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 12620: } else {
12621: my $source = $filepath.'/'.$file;
12622: my $logfile;
1.316 raeburn 12623: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 12624: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 12625: }
12626: print $logfile
12627: "\n================= Publish ".localtime()." ================\n".
12628: $env{'user.name'}.':'.$env{'user.domain'}."\n";
12629: # Save the file
1.316 raeburn 12630: if (!open(FH,">",$source)) {
1.9 raeburn 12631: &Apache::lonnet::logthis('Failed to create '.$source);
12632: return (&mt('Failed to create file'));
12633: }
12634: if ($action eq 'upload') {
12635: if (!print FH ($env{'form.'.$formname})) {
12636: &Apache::lonnet::logthis('Failed to write to '.$source);
12637: return (&mt('Failed to write file'));
12638: }
12639: } else {
12640: my $original = &Apache::lonnet::filelocation('',$formname);
12641: if(!copy($original,$source)) {
12642: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
12643: return (&mt('Failed to write file'));
12644: }
12645: }
12646: close(FH);
12647: chmod(0660, $source); # Permissions to rw-rw---.
12648:
12649: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
12650: my $copyfile=$targetdir.'/'.$file;
12651:
12652: my @parts=split(/\//,$targetdir);
12653: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
12654: for (my $count=5;$count<=$#parts;$count++) {
12655: $path.="/$parts[$count]";
12656: if (!-e $path) {
12657: print $logfile "\nCreating directory ".$path;
12658: mkdir($path,02770);
12659: }
12660: }
12661: my $versionresult;
12662: if (-e $copyfile) {
12663: $versionresult = &logo_versioning($targetdir,$file,$logfile);
12664: } else {
12665: $versionresult = 'ok';
12666: }
12667: if ($versionresult eq 'ok') {
12668: if (copy($source,$copyfile)) {
12669: print $logfile "\nCopied original source to ".$copyfile."\n";
12670: $output = 'ok';
12671: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 12672: push(@{$modified_urls},[$copyfile,$source]);
12673: my $metaoutput =
12674: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
12675: unless ($registered_cleanup) {
12676: my $handlers = $r->get_handlers('PerlCleanupHandler');
12677: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12678: $registered_cleanup=1;
12679: }
1.9 raeburn 12680: } else {
12681: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
12682: $output = &mt('Failed to copy file to RES space').", $!";
12683: }
12684: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
12685: my $inputfile = $filepath.'/'.$file;
12686: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 12687: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
12688: if ($fullwidth ne '' && $fullheight ne '') {
12689: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
12690: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 12691: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
12692: system({$args[0]} @args);
1.16 raeburn 12693: chmod(0660, $filepath.'/tn-'.$file);
12694: if (-e $outfile) {
12695: my $copyfile=$targetdir.'/tn-'.$file;
12696: if (copy($outfile,$copyfile)) {
12697: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 12698: my $thumb_metaoutput =
12699: &write_metadata($dom,$confname,$formname,
12700: $targetdir,'tn-'.$file,$logfile);
12701: push(@{$modified_urls},[$copyfile,$outfile]);
12702: unless ($registered_cleanup) {
12703: my $handlers = $r->get_handlers('PerlCleanupHandler');
12704: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12705: $registered_cleanup=1;
12706: }
1.267 raeburn 12707: $madethumb = 1;
1.16 raeburn 12708: } else {
12709: print $logfile "\nUnable to write ".$copyfile.
12710: ':'.$!."\n";
12711: }
12712: }
1.9 raeburn 12713: }
12714: }
12715: }
12716: } else {
12717: $output = $versionresult;
12718: }
12719: }
1.267 raeburn 12720: return ($output,$logourl,$madethumb);
1.9 raeburn 12721: }
12722:
12723: sub logo_versioning {
12724: my ($targetdir,$file,$logfile) = @_;
12725: my $target = $targetdir.'/'.$file;
12726: my ($maxversion,$fn,$extn,$output);
12727: $maxversion = 0;
12728: if ($file =~ /^(.+)\.(\w+)$/) {
12729: $fn=$1;
12730: $extn=$2;
12731: }
12732: opendir(DIR,$targetdir);
12733: while (my $filename=readdir(DIR)) {
12734: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
12735: $maxversion=($1>$maxversion)?$1:$maxversion;
12736: }
12737: }
12738: $maxversion++;
12739: print $logfile "\nCreating old version ".$maxversion."\n";
12740: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12741: if (copy($target,$copyfile)) {
12742: print $logfile "Copied old target to ".$copyfile."\n";
12743: $copyfile=$copyfile.'.meta';
12744: if (copy($target.'.meta',$copyfile)) {
12745: print $logfile "Copied old target metadata to ".$copyfile."\n";
12746: $output = 'ok';
12747: } else {
12748: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12749: $output = &mt('Failed to copy old meta').", $!, ";
12750: }
12751: } else {
12752: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12753: $output = &mt('Failed to copy old target').", $!, ";
12754: }
12755: return $output;
12756: }
12757:
12758: sub write_metadata {
12759: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12760: my (%metadatafields,%metadatakeys,$output);
12761: $metadatafields{'title'}=$formname;
12762: $metadatafields{'creationdate'}=time;
12763: $metadatafields{'lastrevisiondate'}=time;
12764: $metadatafields{'copyright'}='public';
12765: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12766: $env{'user.domain'};
12767: $metadatafields{'authorspace'}=$confname.':'.$dom;
12768: $metadatafields{'domain'}=$dom;
12769: {
12770: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12771: my $mfh;
1.316 raeburn 12772: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12773: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12774: unless ($_=~/\./) {
12775: my $unikey=$_;
12776: $unikey=~/^([A-Za-z]+)/;
12777: my $tag=$1;
12778: $tag=~tr/A-Z/a-z/;
12779: print $mfh "\n\<$tag";
12780: foreach (split(/\,/,$metadatakeys{$unikey})) {
12781: my $value=$metadatafields{$unikey.'.'.$_};
12782: $value=~s/\"/\'\'/g;
12783: print $mfh ' '.$_.'="'.$value.'"';
12784: }
12785: print $mfh '>'.
12786: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12787: .'</'.$tag.'>';
12788: }
12789: }
12790: $output = 'ok';
12791: print $logfile "\nWrote metadata";
12792: close($mfh);
12793: } else {
12794: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12795: $output = &mt('Could not write metadata');
12796: }
12797: }
1.155 raeburn 12798: return $output;
12799: }
12800:
12801: sub notifysubscribed {
12802: foreach my $targetsource (@{$modified_urls}){
12803: next unless (ref($targetsource) eq 'ARRAY');
12804: my ($target,$source)=@{$targetsource};
12805: if ($source ne '') {
1.316 raeburn 12806: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12807: print $logfh "\nCleanup phase: Notifications\n";
12808: my @subscribed=&subscribed_hosts($target);
12809: foreach my $subhost (@subscribed) {
12810: print $logfh "\nNotifying host ".$subhost.':';
12811: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12812: print $logfh $reply;
12813: }
12814: my @subscribedmeta=&subscribed_hosts("$target.meta");
12815: foreach my $subhost (@subscribedmeta) {
12816: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12817: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12818: $subhost);
12819: print $logfh $reply;
12820: }
12821: print $logfh "\n============ Done ============\n";
1.160 raeburn 12822: close($logfh);
1.155 raeburn 12823: }
12824: }
12825: }
12826: return OK;
12827: }
12828:
12829: sub subscribed_hosts {
12830: my ($target) = @_;
12831: my @subscribed;
1.316 raeburn 12832: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12833: while (my $subline=<$fh>) {
12834: if ($subline =~ /^($match_lonid):/) {
12835: my $host = $1;
12836: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12837: unless (grep(/^\Q$host\E$/,@subscribed)) {
12838: push(@subscribed,$host);
12839: }
12840: }
12841: }
12842: }
12843: }
12844: return @subscribed;
1.9 raeburn 12845: }
12846:
12847: sub check_switchserver {
12848: my ($dom,$confname) = @_;
12849: my ($allowed,$switchserver);
12850: my $home = &Apache::lonnet::homeserver($confname,$dom);
12851: if ($home eq 'no_host') {
12852: $home = &Apache::lonnet::domain($dom,'primary');
12853: }
12854: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12855: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12856: if (!$allowed) {
1.180 raeburn 12857: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12858: }
12859: return $switchserver;
12860: }
12861:
1.1 raeburn 12862: sub modify_quotas {
1.216 raeburn 12863: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12864: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12865: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12866: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12867: $validationfieldsref);
1.86 raeburn 12868: if ($action eq 'quotas') {
12869: $context = 'tools';
1.163 raeburn 12870: } else {
1.86 raeburn 12871: $context = $action;
12872: }
12873: if ($context eq 'requestcourses') {
1.325 raeburn 12874: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12875: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12876: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12877: %titles = &courserequest_titles();
12878: $toolregexp = join('|',@usertools);
12879: %conditions = &courserequest_conditions();
1.216 raeburn 12880: $confname = $dom.'-domainconfig';
12881: my $servadm = $r->dir_config('lonAdmEMail');
12882: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12883: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12884: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12885: } elsif ($context eq 'requestauthor') {
12886: @usertools = ('author');
12887: %titles = &authorrequest_titles();
1.86 raeburn 12888: } else {
1.162 raeburn 12889: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12890: %titles = &tool_titles();
1.86 raeburn 12891: }
1.212 raeburn 12892: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12893: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12894: foreach my $key (keys(%env)) {
1.101 raeburn 12895: if ($context eq 'requestcourses') {
12896: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12897: my $item = $1;
12898: my $type = $2;
12899: if ($type =~ /^limit_(.+)/) {
12900: $limithash{$item}{$1} = $env{$key};
12901: } else {
12902: $confhash{$item}{$type} = $env{$key};
12903: }
12904: }
1.163 raeburn 12905: } elsif ($context eq 'requestauthor') {
12906: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12907: $confhash{$1} = $env{$key};
12908: }
1.101 raeburn 12909: } else {
1.86 raeburn 12910: if ($key =~ /^form\.quota_(.+)$/) {
12911: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12912: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12913: $confhash{'authorquota'}{$1} = $env{$key};
12914: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12915: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12916: }
1.72 raeburn 12917: }
12918: }
1.163 raeburn 12919: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12920: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12921: @approvalnotify = sort(@approvalnotify);
12922: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12923: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12924: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12925: foreach my $type (@hasuniquecode) {
12926: if (grep(/^\Q$type\E$/,@crstypes)) {
12927: $confhash{'uniquecode'}{$type} = 1;
12928: }
1.216 raeburn 12929: }
1.242 raeburn 12930: my (%newbook,%allpos);
1.216 raeburn 12931: if ($context eq 'requestcourses') {
1.242 raeburn 12932: foreach my $type ('textbooks','templates') {
12933: @{$allpos{$type}} = ();
12934: my $invalid;
12935: if ($type eq 'textbooks') {
12936: $invalid = &mt('Invalid LON-CAPA course for textbook');
12937: } else {
12938: $invalid = &mt('Invalid LON-CAPA course for template');
12939: }
12940: if ($env{'form.'.$type.'_addbook'}) {
12941: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12942: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12943: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12944: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12945: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12946: } else {
12947: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12948: my $position = $env{'form.'.$type.'_addbook_pos'};
12949: $position =~ s/\D+//g;
12950: if ($position ne '') {
12951: $allpos{$type}[$position] = $newbook{$type};
12952: }
1.216 raeburn 12953: }
1.242 raeburn 12954: } else {
12955: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12956: }
12957: }
1.242 raeburn 12958: }
1.216 raeburn 12959: }
1.102 raeburn 12960: if (ref($domconfig{$action}) eq 'HASH') {
12961: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12962: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12963: $changes{'notify'}{'approval'} = 1;
12964: }
12965: } else {
1.144 raeburn 12966: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12967: $changes{'notify'}{'approval'} = 1;
12968: }
12969: }
1.218 raeburn 12970: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12971: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12972: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12973: unless ($confhash{'uniquecode'}{$crstype}) {
12974: $changes{'uniquecode'} = 1;
12975: }
12976: }
12977: unless ($changes{'uniquecode'}) {
12978: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12979: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12980: $changes{'uniquecode'} = 1;
12981: }
12982: }
12983: }
12984: } else {
12985: $changes{'uniquecode'} = 1;
12986: }
12987: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12988: $changes{'uniquecode'} = 1;
1.216 raeburn 12989: }
12990: if ($context eq 'requestcourses') {
1.242 raeburn 12991: foreach my $type ('textbooks','templates') {
12992: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12993: my %deletions;
12994: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12995: if (@todelete) {
12996: map { $deletions{$_} = 1; } @todelete;
12997: }
12998: my %imgdeletions;
12999: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
13000: if (@todeleteimages) {
13001: map { $imgdeletions{$_} = 1; } @todeleteimages;
13002: }
13003: my $maxnum = $env{'form.'.$type.'_maxnum'};
13004: for (my $i=0; $i<=$maxnum; $i++) {
13005: my $itemid = $env{'form.'.$type.'_id_'.$i};
13006: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13007: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13008: if ($deletions{$key}) {
13009: if ($domconfig{$action}{$type}{$key}{'image'}) {
13010: #FIXME need to obsolete item in RES space
13011: }
13012: next;
13013: } else {
13014: my $newpos = $env{'form.'.$itemid};
13015: $newpos =~ s/\D+//g;
1.243 raeburn 13016: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13017: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13018: ($type eq 'templates'));
1.242 raeburn 13019: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13020: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13021: $changes{$type}{$key} = 1;
13022: }
13023: }
13024: $allpos{$type}[$newpos] = $key;
13025: }
13026: if ($imgdeletions{$key}) {
13027: $changes{$type}{$key} = 1;
1.216 raeburn 13028: #FIXME need to obsolete item in RES space
1.242 raeburn 13029: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13030: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13031: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13032: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13033: } else {
13034: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13035: $cdom,$cnum,$type,$configuserok,
13036: $switchserver,$author_ok);
13037: if ($imgurl) {
13038: $confhash{$type}{$key}{'image'} = $imgurl;
13039: $changes{$type}{$key} = 1;
13040: }
13041: if ($error) {
13042: &Apache::lonnet::logthis($error);
13043: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13044: }
13045: }
1.242 raeburn 13046: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13047: $confhash{$type}{$key}{'image'} =
13048: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13049: }
13050: }
13051: }
13052: }
13053: }
13054: }
1.102 raeburn 13055: } else {
1.144 raeburn 13056: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13057: $changes{'notify'}{'approval'} = 1;
13058: }
1.218 raeburn 13059: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13060: $changes{'uniquecode'} = 1;
13061: }
13062: }
13063: if ($context eq 'requestcourses') {
1.242 raeburn 13064: foreach my $type ('textbooks','templates') {
13065: if ($newbook{$type}) {
13066: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13067: foreach my $item ('subject','title','publisher','author') {
13068: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13069: ($type eq 'template'));
1.242 raeburn 13070: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13071: if ($env{'form.'.$type.'_addbook_'.$item}) {
13072: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13073: }
13074: }
13075: if ($type eq 'textbooks') {
13076: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13077: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13078: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13079: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13080: } else {
13081: my ($imageurl,$error) =
13082: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13083: $configuserok,$switchserver,$author_ok);
13084: if ($imageurl) {
13085: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13086: }
13087: if ($error) {
13088: &Apache::lonnet::logthis($error);
13089: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13090: }
1.242 raeburn 13091: }
13092: }
1.216 raeburn 13093: }
13094: }
1.242 raeburn 13095: if (@{$allpos{$type}} > 0) {
13096: my $idx = 0;
13097: foreach my $item (@{$allpos{$type}}) {
13098: if ($item ne '') {
13099: $confhash{$type}{$item}{'order'} = $idx;
13100: if (ref($domconfig{$action}) eq 'HASH') {
13101: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13102: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13103: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13104: $changes{$type}{$item} = 1;
13105: }
1.216 raeburn 13106: }
13107: }
13108: }
1.242 raeburn 13109: $idx ++;
1.216 raeburn 13110: }
13111: }
13112: }
13113: }
1.235 raeburn 13114: if (ref($validationitemsref) eq 'ARRAY') {
13115: foreach my $item (@{$validationitemsref}) {
13116: if ($item eq 'fields') {
13117: my @changed;
13118: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13119: if (@{$confhash{'validation'}{$item}} > 0) {
13120: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13121: }
1.266 raeburn 13122: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13123: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13124: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13125: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13126: $domconfig{'requestcourses'}{'validation'}{$item});
13127: } else {
13128: @changed = @{$confhash{'validation'}{$item}};
13129: }
1.235 raeburn 13130: } else {
13131: @changed = @{$confhash{'validation'}{$item}};
13132: }
13133: } else {
13134: @changed = @{$confhash{'validation'}{$item}};
13135: }
13136: if (@changed) {
13137: if ($confhash{'validation'}{$item}) {
13138: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13139: } else {
13140: $changes{'validation'}{$item} = &mt('None');
13141: }
13142: }
13143: } else {
13144: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13145: if ($item eq 'markup') {
13146: if ($env{'form.requestcourses_validation_'.$item}) {
13147: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13148: }
13149: }
1.266 raeburn 13150: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13151: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13152: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13153: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13154: }
13155: } else {
13156: if ($confhash{'validation'}{$item} ne '') {
13157: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13158: }
1.235 raeburn 13159: }
13160: } else {
13161: if ($confhash{'validation'}{$item} ne '') {
13162: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13163: }
13164: }
13165: }
13166: }
13167: }
13168: if ($env{'form.validationdc'}) {
13169: my $newval = $env{'form.validationdc'};
1.285 raeburn 13170: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13171: if (exists($domcoords{$newval})) {
13172: $confhash{'validation'}{'dc'} = $newval;
13173: }
13174: }
13175: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13176: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13177: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13178: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13179: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13180: if ($confhash{'validation'}{'dc'} eq '') {
13181: $changes{'validation'}{'dc'} = &mt('None');
13182: } else {
13183: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13184: }
1.235 raeburn 13185: }
1.266 raeburn 13186: } elsif ($confhash{'validation'}{'dc'} ne '') {
13187: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13188: }
13189: } elsif ($confhash{'validation'}{'dc'} ne '') {
13190: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13191: }
13192: } elsif ($confhash{'validation'}{'dc'} ne '') {
13193: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13194: }
1.266 raeburn 13195: } else {
13196: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13197: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13198: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13199: $changes{'validation'}{'dc'} = &mt('None');
13200: }
13201: }
1.235 raeburn 13202: }
13203: }
1.102 raeburn 13204: }
13205: } else {
1.86 raeburn 13206: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13207: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13208: }
1.72 raeburn 13209: foreach my $item (@usertools) {
13210: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13211: my $unset;
1.101 raeburn 13212: if ($context eq 'requestcourses') {
1.104 raeburn 13213: $unset = '0';
13214: if ($type eq '_LC_adv') {
13215: $unset = '';
13216: }
1.101 raeburn 13217: if ($confhash{$item}{$type} eq 'autolimit') {
13218: $confhash{$item}{$type} .= '=';
13219: unless ($limithash{$item}{$type} =~ /\D/) {
13220: $confhash{$item}{$type} .= $limithash{$item}{$type};
13221: }
13222: }
1.163 raeburn 13223: } elsif ($context eq 'requestauthor') {
13224: $unset = '0';
13225: if ($type eq '_LC_adv') {
13226: $unset = '';
13227: }
1.72 raeburn 13228: } else {
1.101 raeburn 13229: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13230: $confhash{$item}{$type} = 1;
13231: } else {
13232: $confhash{$item}{$type} = 0;
13233: }
1.72 raeburn 13234: }
1.86 raeburn 13235: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13236: if ($action eq 'requestauthor') {
13237: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13238: $changes{$type} = 1;
13239: }
13240: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13241: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13242: $changes{$item}{$type} = 1;
13243: }
13244: } else {
13245: if ($context eq 'requestcourses') {
1.104 raeburn 13246: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13247: $changes{$item}{$type} = 1;
13248: }
13249: } else {
13250: if (!$confhash{$item}{$type}) {
13251: $changes{$item}{$type} = 1;
13252: }
13253: }
13254: }
13255: } else {
13256: if ($context eq 'requestcourses') {
1.104 raeburn 13257: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13258: $changes{$item}{$type} = 1;
13259: }
1.163 raeburn 13260: } elsif ($context eq 'requestauthor') {
13261: if ($confhash{$type} ne $unset) {
13262: $changes{$type} = 1;
13263: }
1.72 raeburn 13264: } else {
13265: if (!$confhash{$item}{$type}) {
13266: $changes{$item}{$type} = 1;
13267: }
13268: }
13269: }
1.1 raeburn 13270: }
13271: }
1.163 raeburn 13272: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13273: if (ref($domconfig{'quotas'}) eq 'HASH') {
13274: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13275: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13276: if (exists($confhash{'defaultquota'}{$key})) {
13277: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13278: $changes{'defaultquota'}{$key} = 1;
13279: }
13280: } else {
13281: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13282: }
13283: }
1.86 raeburn 13284: } else {
13285: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13286: if (exists($confhash{'defaultquota'}{$key})) {
13287: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13288: $changes{'defaultquota'}{$key} = 1;
13289: }
13290: } else {
13291: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13292: }
1.1 raeburn 13293: }
13294: }
1.197 raeburn 13295: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13296: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13297: if (exists($confhash{'authorquota'}{$key})) {
13298: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13299: $changes{'authorquota'}{$key} = 1;
13300: }
13301: } else {
13302: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13303: }
13304: }
13305: }
1.1 raeburn 13306: }
1.86 raeburn 13307: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13308: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13309: if (ref($domconfig{'quotas'}) eq 'HASH') {
13310: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13311: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13312: $changes{'defaultquota'}{$key} = 1;
13313: }
13314: } else {
13315: if (!exists($domconfig{'quotas'}{$key})) {
13316: $changes{'defaultquota'}{$key} = 1;
13317: }
1.72 raeburn 13318: }
13319: } else {
1.86 raeburn 13320: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13321: }
1.1 raeburn 13322: }
13323: }
1.197 raeburn 13324: if (ref($confhash{'authorquota'}) eq 'HASH') {
13325: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13326: if (ref($domconfig{'quotas'}) eq 'HASH') {
13327: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13328: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13329: $changes{'authorquota'}{$key} = 1;
13330: }
13331: } else {
13332: $changes{'authorquota'}{$key} = 1;
13333: }
13334: } else {
13335: $changes{'authorquota'}{$key} = 1;
13336: }
13337: }
13338: }
1.1 raeburn 13339: }
1.72 raeburn 13340:
1.163 raeburn 13341: if ($context eq 'requestauthor') {
13342: $domdefaults{'requestauthor'} = \%confhash;
13343: } else {
13344: foreach my $key (keys(%confhash)) {
1.242 raeburn 13345: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13346: $domdefaults{$key} = $confhash{$key};
13347: }
1.163 raeburn 13348: }
1.72 raeburn 13349: }
1.163 raeburn 13350:
1.1 raeburn 13351: my %quotahash = (
1.86 raeburn 13352: $action => { %confhash }
1.1 raeburn 13353: );
13354: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13355: $dom);
13356: if ($putresult eq 'ok') {
13357: if (keys(%changes) > 0) {
1.72 raeburn 13358: my $cachetime = 24*60*60;
13359: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13360: if (ref($lastactref) eq 'HASH') {
13361: $lastactref->{'domdefaults'} = 1;
13362: }
1.1 raeburn 13363: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13364: unless (($context eq 'requestcourses') ||
1.163 raeburn 13365: ($context eq 'requestauthor')) {
1.86 raeburn 13366: if (ref($changes{'defaultquota'}) eq 'HASH') {
13367: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13368: foreach my $type (@{$types},'default') {
13369: if (defined($changes{'defaultquota'}{$type})) {
13370: my $typetitle = $usertypes->{$type};
13371: if ($type eq 'default') {
13372: $typetitle = $othertitle;
13373: }
1.213 raeburn 13374: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13375: }
13376: }
1.86 raeburn 13377: $resulttext .= '</ul></li>';
1.72 raeburn 13378: }
1.197 raeburn 13379: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13380: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13381: foreach my $type (@{$types},'default') {
13382: if (defined($changes{'authorquota'}{$type})) {
13383: my $typetitle = $usertypes->{$type};
13384: if ($type eq 'default') {
13385: $typetitle = $othertitle;
13386: }
1.213 raeburn 13387: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13388: }
13389: }
13390: $resulttext .= '</ul></li>';
13391: }
1.72 raeburn 13392: }
1.80 raeburn 13393: my %newenv;
1.72 raeburn 13394: foreach my $item (@usertools) {
1.163 raeburn 13395: my (%haschgs,%inconf);
13396: if ($context eq 'requestauthor') {
13397: %haschgs = %changes;
1.210 raeburn 13398: %inconf = %confhash;
1.163 raeburn 13399: } else {
13400: if (ref($changes{$item}) eq 'HASH') {
13401: %haschgs = %{$changes{$item}};
13402: }
13403: if (ref($confhash{$item}) eq 'HASH') {
13404: %inconf = %{$confhash{$item}};
13405: }
13406: }
13407: if (keys(%haschgs) > 0) {
1.80 raeburn 13408: my $newacc =
13409: &Apache::lonnet::usertools_access($env{'user.name'},
13410: $env{'user.domain'},
1.86 raeburn 13411: $item,'reload',$context);
1.210 raeburn 13412: if (($context eq 'requestcourses') ||
1.163 raeburn 13413: ($context eq 'requestauthor')) {
1.108 raeburn 13414: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13415: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13416: }
13417: } else {
13418: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13419: $newenv{'environment.availabletools.'.$item} = $newacc;
13420: }
1.80 raeburn 13421: }
1.163 raeburn 13422: unless ($context eq 'requestauthor') {
13423: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13424: }
1.72 raeburn 13425: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 13426: if ($haschgs{$type}) {
1.72 raeburn 13427: my $typetitle = $usertypes->{$type};
13428: if ($type eq 'default') {
13429: $typetitle = $othertitle;
13430: } elsif ($type eq '_LC_adv') {
13431: $typetitle = 'LON-CAPA Advanced Users';
13432: }
1.163 raeburn 13433: if ($inconf{$type}) {
1.101 raeburn 13434: if ($context eq 'requestcourses') {
13435: my $cond;
1.163 raeburn 13436: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13437: if ($1 eq '') {
13438: $cond = &mt('(Automatic processing of any request).');
13439: } else {
13440: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13441: }
13442: } else {
1.163 raeburn 13443: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13444: }
13445: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 13446: } elsif ($context eq 'requestauthor') {
13447: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13448: $titles{$inconf{$type}},$typetitle);
13449:
1.101 raeburn 13450: } else {
13451: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13452: }
1.72 raeburn 13453: } else {
1.104 raeburn 13454: if ($type eq '_LC_adv') {
1.163 raeburn 13455: if ($inconf{$type} eq '0') {
1.104 raeburn 13456: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13457: } else {
13458: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13459: }
13460: } else {
13461: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13462: }
1.72 raeburn 13463: }
13464: }
1.26 raeburn 13465: }
1.163 raeburn 13466: unless ($context eq 'requestauthor') {
13467: $resulttext .= '</ul></li>';
13468: }
1.26 raeburn 13469: }
1.1 raeburn 13470: }
1.163 raeburn 13471: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13472: if (ref($changes{'notify'}) eq 'HASH') {
13473: if ($changes{'notify'}{'approval'}) {
13474: if (ref($confhash{'notify'}) eq 'HASH') {
13475: if ($confhash{'notify'}{'approval'}) {
13476: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13477: } else {
1.163 raeburn 13478: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13479: }
13480: }
13481: }
13482: }
13483: }
1.216 raeburn 13484: if ($action eq 'requestcourses') {
13485: my @offon = ('off','on');
13486: if ($changes{'uniquecode'}) {
1.218 raeburn 13487: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13488: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13489: $resulttext .= '<li>'.
13490: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13491: '</li>';
13492: } else {
13493: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13494: '</li>';
13495: }
1.216 raeburn 13496: }
1.242 raeburn 13497: foreach my $type ('textbooks','templates') {
13498: if (ref($changes{$type}) eq 'HASH') {
13499: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13500: foreach my $key (sort(keys(%{$changes{$type}}))) {
13501: my %coursehash = &Apache::lonnet::coursedescription($key);
13502: my $coursetitle = $coursehash{'description'};
13503: my $position = $confhash{$type}{$key}{'order'} + 1;
13504: $resulttext .= '<li>';
1.243 raeburn 13505: foreach my $item ('subject','title','publisher','author') {
13506: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13507: ($type eq 'templates'));
1.242 raeburn 13508: my $name = $item.':';
13509: $name =~ s/^(\w)/\U$1/;
13510: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13511: }
13512: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13513: if ($type eq 'textbooks') {
13514: if ($confhash{$type}{$key}{'image'}) {
13515: $resulttext .= ' '.&mt('Image: [_1]',
13516: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13517: ' alt="Textbook cover" />').'<br />';
13518: }
13519: }
13520: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 13521: }
1.242 raeburn 13522: $resulttext .= '</ul></li>';
1.216 raeburn 13523: }
13524: }
1.235 raeburn 13525: if (ref($changes{'validation'}) eq 'HASH') {
13526: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13527: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13528: foreach my $item (@{$validationitemsref}) {
13529: if (exists($changes{'validation'}{$item})) {
13530: if ($item eq 'markup') {
13531: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13532: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13533: } else {
13534: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13535: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13536: }
13537: }
13538: }
13539: if (exists($changes{'validation'}{'dc'})) {
13540: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13541: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13542: }
13543: }
13544: }
1.216 raeburn 13545: }
1.1 raeburn 13546: $resulttext .= '</ul>';
1.80 raeburn 13547: if (keys(%newenv)) {
13548: &Apache::lonnet::appenv(\%newenv);
13549: }
1.1 raeburn 13550: } else {
1.86 raeburn 13551: if ($context eq 'requestcourses') {
13552: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 13553: } elsif ($context eq 'requestauthor') {
13554: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13555: } else {
1.90 weissno 13556: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13557: }
1.1 raeburn 13558: }
13559: } else {
1.11 albertel 13560: $resulttext = '<span class="LC_error">'.
13561: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13562: }
1.216 raeburn 13563: if ($errors) {
13564: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13565: '<ul>'.$errors.'</ul></p>';
13566: }
1.3 raeburn 13567: return $resulttext;
1.1 raeburn 13568: }
13569:
1.216 raeburn 13570: sub process_textbook_image {
1.242 raeburn 13571: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 13572: my $filename = $env{'form.'.$caller.'.filename'};
13573: my ($error,$url);
13574: my ($width,$height) = (50,50);
13575: if ($configuserok eq 'ok') {
13576: if ($switchserver) {
13577: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13578: $switchserver);
13579: } elsif ($author_ok eq 'ok') {
13580: my ($result,$imageurl) =
13581: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 13582: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 13583: if ($result eq 'ok') {
13584: $url = $imageurl;
13585: } else {
13586: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13587: }
13588: } else {
13589: $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);
13590: }
13591: } else {
13592: $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);
13593: }
13594: return ($url,$error);
13595: }
13596:
1.267 raeburn 13597: sub modify_ltitools {
13598: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13599: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 13600: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 13601: my $confname = $dom.'-domainconfig';
13602: my $servadm = $r->dir_config('lonAdmEMail');
13603: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13604: my (%posslti,%possfield);
13605: my @courseroles = ('cc','in','ta','ep','st');
13606: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
13607: map { $posslti{$_} = 1; } @ltiroles;
13608: my @allfields = ('fullname','firstname','lastname','email','user','roles');
13609: map { $possfield{$_} = 1; } @allfields;
13610: my %lt = <itools_names();
13611: if ($env{'form.ltitools_add'}) {
13612: my $title = $env{'form.ltitools_add_title'};
13613: $title =~ s/(`)/'/g;
13614: ($newid,my $error) = &get_ltitools_id($dom,$title);
13615: if ($newid) {
13616: my $position = $env{'form.ltitools_add_pos'};
13617: $position =~ s/\D+//g;
13618: if ($position ne '') {
13619: $allpos[$position] = $newid;
13620: }
13621: $changes{$newid} = 1;
1.322 raeburn 13622: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 13623: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 13624: if ($item eq 'lifetime') {
13625: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
13626: }
1.267 raeburn 13627: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 13628: if (($item eq 'key') || ($item eq 'secret')) {
13629: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13630: } else {
13631: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13632: }
1.267 raeburn 13633: }
13634: }
13635: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
13636: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
13637: }
13638: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
13639: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
13640: }
1.323 raeburn 13641: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
13642: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
13643: } else {
13644: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
13645: }
1.296 raeburn 13646: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 13647: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
13648: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 13649: if (($item eq 'width') || ($item eq 'height')) {
13650: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
13651: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13652: }
13653: } else {
13654: if ($env{'form.ltitools_add_'.$item} ne '') {
13655: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13656: }
1.267 raeburn 13657: }
13658: }
13659: if ($env{'form.ltitools_add_target'} eq 'window') {
13660: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 13661: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
13662: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 13663: } else {
13664: $confhash{$newid}{'display'}{'target'} = 'iframe';
13665: }
13666: foreach my $item ('passback','roster') {
1.319 raeburn 13667: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 13668: $confhash{$newid}{$item} = 1;
1.319 raeburn 13669: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
13670: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
13671: $lifetime =~ s/^\s+|\s+$//g;
13672: if ($lifetime =~ /^\d+\.?\d*$/) {
13673: $confhash{$newid}{$item.'valid'} = $lifetime;
13674: }
13675: }
1.267 raeburn 13676: }
13677: }
13678: if ($env{'form.ltitools_add_image.filename'} ne '') {
13679: my ($imageurl,$error) =
1.307 raeburn 13680: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 13681: $configuserok,$switchserver,$author_ok);
13682: if ($imageurl) {
13683: $confhash{$newid}{'image'} = $imageurl;
13684: }
13685: if ($error) {
13686: &Apache::lonnet::logthis($error);
13687: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13688: }
13689: }
13690: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
13691: foreach my $field (@fields) {
13692: if ($possfield{$field}) {
13693: if ($field eq 'roles') {
13694: foreach my $role (@courseroles) {
13695: my $choice = $env{'form.ltitools_add_roles_'.$role};
13696: if (($choice ne '') && ($posslti{$choice})) {
13697: $confhash{$newid}{'roles'}{$role} = $choice;
13698: if ($role eq 'cc') {
13699: $confhash{$newid}{'roles'}{'co'} = $choice;
13700: }
13701: }
13702: }
13703: } else {
13704: $confhash{$newid}{'fields'}{$field} = 1;
13705: }
13706: }
13707: }
1.324 raeburn 13708: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
13709: if ($confhash{$newid}{'fields'}{'user'}) {
13710: if ($env{'form.ltitools_userincdom_add'}) {
13711: $confhash{$newid}{'incdom'} = 1;
13712: }
13713: }
13714: }
1.273 raeburn 13715: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
13716: foreach my $item (@courseconfig) {
13717: $confhash{$newid}{'crsconf'}{$item} = 1;
13718: }
1.267 raeburn 13719: if ($env{'form.ltitools_add_custom'}) {
13720: my $name = $env{'form.ltitools_add_custom_name'};
13721: my $value = $env{'form.ltitools_add_custom_value'};
13722: $value =~ s/(`)/'/g;
13723: $name =~ s/(`)/'/g;
13724: $confhash{$newid}{'custom'}{$name} = $value;
13725: }
13726: } else {
13727: my $error = &mt('Failed to acquire unique ID for new external tool');
13728: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13729: }
13730: }
13731: if (ref($domconfig{$action}) eq 'HASH') {
13732: my %deletions;
13733: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
13734: if (@todelete) {
13735: map { $deletions{$_} = 1; } @todelete;
13736: }
13737: my %customadds;
13738: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
13739: if (@newcustom) {
13740: map { $customadds{$_} = 1; } @newcustom;
13741: }
13742: my %imgdeletions;
13743: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13744: if (@todeleteimages) {
13745: map { $imgdeletions{$_} = 1; } @todeleteimages;
13746: }
13747: my $maxnum = $env{'form.ltitools_maxnum'};
13748: for (my $i=0; $i<=$maxnum; $i++) {
13749: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13750: $itemid =~ s/\D+//g;
1.267 raeburn 13751: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13752: if ($deletions{$itemid}) {
13753: if ($domconfig{$action}{$itemid}{'image'}) {
13754: #FIXME need to obsolete item in RES space
13755: }
13756: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13757: next;
13758: } else {
13759: my $newpos = $env{'form.ltitools_'.$itemid};
13760: $newpos =~ s/\D+//g;
1.322 raeburn 13761: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13762: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13763: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13764: $changes{$itemid} = 1;
13765: }
13766: }
1.297 raeburn 13767: foreach my $item ('key','secret') {
13768: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13769: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13770: $changes{$itemid} = 1;
13771: }
13772: }
1.267 raeburn 13773: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13774: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13775: }
13776: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13777: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13778: }
1.323 raeburn 13779: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13780: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13781: } else {
13782: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13783: }
13784: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13785: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13786: $changes{$itemid} = 1;
13787: }
13788: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13789: $changes{$itemid} = 1;
13790: }
1.267 raeburn 13791: foreach my $size ('width','height') {
13792: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13793: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13794: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13795: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13796: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13797: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13798: $changes{$itemid} = 1;
13799: }
13800: } else {
13801: $changes{$itemid} = 1;
13802: }
1.296 raeburn 13803: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13804: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13805: $changes{$itemid} = 1;
13806: }
13807: }
13808: }
13809: foreach my $item ('linktext','explanation') {
13810: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13811: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13812: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13813: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13814: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13815: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13816: $changes{$itemid} = 1;
13817: }
13818: } else {
13819: $changes{$itemid} = 1;
13820: }
13821: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13822: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13823: $changes{$itemid} = 1;
13824: }
1.267 raeburn 13825: }
13826: }
13827: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13828: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13829: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13830: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13831: } else {
13832: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13833: }
13834: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13835: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13836: $changes{$itemid} = 1;
13837: }
13838: } else {
13839: $changes{$itemid} = 1;
13840: }
13841: foreach my $extra ('passback','roster') {
13842: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13843: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13844: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13845: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13846: $lifetime =~ s/^\s+|\s+$//g;
13847: if ($lifetime =~ /^\d+\.?\d*$/) {
13848: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13849: }
13850: }
1.267 raeburn 13851: }
13852: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13853: $changes{$itemid} = 1;
13854: }
1.319 raeburn 13855: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13856: $changes{$itemid} = 1;
13857: }
1.267 raeburn 13858: }
1.273 raeburn 13859: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13860: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13861: if (grep(/^\Q$item\E$/,@courseconfig)) {
13862: $confhash{$itemid}{'crsconf'}{$item} = 1;
13863: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13864: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13865: $changes{$itemid} = 1;
13866: }
13867: } else {
13868: $changes{$itemid} = 1;
13869: }
13870: }
13871: }
1.267 raeburn 13872: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13873: foreach my $field (@fields) {
13874: if ($possfield{$field}) {
13875: if ($field eq 'roles') {
13876: foreach my $role (@courseroles) {
13877: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13878: if (($choice ne '') && ($posslti{$choice})) {
13879: $confhash{$itemid}{'roles'}{$role} = $choice;
13880: if ($role eq 'cc') {
13881: $confhash{$itemid}{'roles'}{'co'} = $choice;
13882: }
13883: }
13884: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13885: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13886: $changes{$itemid} = 1;
13887: }
13888: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13889: $changes{$itemid} = 1;
13890: }
13891: }
13892: } else {
13893: $confhash{$itemid}{'fields'}{$field} = 1;
13894: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13895: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13896: $changes{$itemid} = 1;
13897: }
13898: } else {
13899: $changes{$itemid} = 1;
13900: }
13901: }
13902: }
13903: }
1.324 raeburn 13904: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13905: if ($confhash{$itemid}{'fields'}{'user'}) {
13906: if ($env{'form.ltitools_userincdom_'.$i}) {
13907: $confhash{$itemid}{'incdom'} = 1;
13908: }
13909: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13910: $changes{$itemid} = 1;
13911: }
13912: }
13913: }
1.267 raeburn 13914: $allpos[$newpos] = $itemid;
13915: }
13916: if ($imgdeletions{$itemid}) {
13917: $changes{$itemid} = 1;
13918: #FIXME need to obsolete item in RES space
13919: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13920: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13921: $itemid,$configuserok,$switchserver,
13922: $author_ok);
13923: if ($imgurl) {
13924: $confhash{$itemid}{'image'} = $imgurl;
13925: $changes{$itemid} = 1;
13926: }
13927: if ($error) {
13928: &Apache::lonnet::logthis($error);
13929: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13930: }
13931: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13932: $confhash{$itemid}{'image'} =
13933: $domconfig{$action}{$itemid}{'image'};
13934: }
13935: if ($customadds{$i}) {
13936: my $name = $env{'form.ltitools_custom_name_'.$i};
13937: $name =~ s/(`)/'/g;
13938: $name =~ s/^\s+//;
13939: $name =~ s/\s+$//;
13940: my $value = $env{'form.ltitools_custom_value_'.$i};
13941: $value =~ s/(`)/'/g;
13942: $value =~ s/^\s+//;
13943: $value =~ s/\s+$//;
13944: if ($name ne '') {
13945: $confhash{$itemid}{'custom'}{$name} = $value;
13946: $changes{$itemid} = 1;
13947: }
13948: }
13949: my %customdels;
13950: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13951: if (@customdeletions) {
13952: $changes{$itemid} = 1;
13953: }
13954: map { $customdels{$_} = 1; } @customdeletions;
13955: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13956: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13957: unless ($customdels{$key}) {
13958: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13959: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13960: }
13961: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13962: $changes{$itemid} = 1;
13963: }
13964: }
13965: }
13966: }
13967: unless ($changes{$itemid}) {
13968: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13969: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13970: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13971: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13972: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13973: $changes{$itemid} = 1;
13974: last;
13975: }
13976: }
13977: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13978: $changes{$itemid} = 1;
13979: }
13980: }
13981: last if ($changes{$itemid});
13982: }
13983: }
13984: }
13985: }
13986: }
13987: if (@allpos > 0) {
13988: my $idx = 0;
13989: foreach my $itemid (@allpos) {
13990: if ($itemid ne '') {
13991: $confhash{$itemid}{'order'} = $idx;
13992: if (ref($domconfig{$action}) eq 'HASH') {
13993: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13994: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13995: $changes{$itemid} = 1;
13996: }
13997: }
13998: }
13999: $idx ++;
14000: }
14001: }
14002: }
14003: my %ltitoolshash = (
14004: $action => { %confhash }
14005: );
14006: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
14007: $dom);
14008: if ($putresult eq 'ok') {
1.297 raeburn 14009: my %ltienchash = (
14010: $action => { %encconfig }
14011: );
1.384 raeburn 14012: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 14013: if (keys(%changes) > 0) {
14014: my $cachetime = 24*60*60;
1.297 raeburn 14015: my %ltiall = %confhash;
14016: foreach my $id (keys(%ltiall)) {
14017: if (ref($encconfig{$id}) eq 'HASH') {
14018: foreach my $item ('key','secret') {
14019: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14020: }
14021: }
14022: }
14023: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 14024: if (ref($lastactref) eq 'HASH') {
14025: $lastactref->{'ltitools'} = 1;
14026: }
14027: $resulttext = &mt('Changes made:').'<ul>';
14028: my %bynum;
14029: foreach my $itemid (sort(keys(%changes))) {
14030: my $position = $confhash{$itemid}{'order'};
14031: $bynum{$position} = $itemid;
14032: }
14033: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14034: my $itemid = $bynum{$pos};
14035: if (ref($confhash{$itemid}) ne 'HASH') {
14036: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14037: } else {
14038: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
14039: if ($confhash{$itemid}{'image'}) {
14040: $resulttext .= ' '.
14041: '<img src="'.$confhash{$itemid}{'image'}.'"'.
14042: ' alt="'.&mt('Tool Provider icon').'" />';
14043: }
14044: $resulttext .= '</li><ul>';
14045: my $position = $pos + 1;
14046: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 14047: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 14048: if ($confhash{$itemid}{$item} ne '') {
14049: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14050: }
14051: }
1.297 raeburn 14052: if ($encconfig{$itemid}{'key'} ne '') {
14053: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14054: }
14055: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 14056: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 14057: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 14058: $resulttext .= ('*'x$num).'</li>';
14059: }
1.273 raeburn 14060: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 14061: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 14062: my $numconfig = 0;
14063: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
14064: foreach my $item (@possconfig) {
14065: if ($confhash{$itemid}{'crsconf'}{$item}) {
14066: $numconfig ++;
1.296 raeburn 14067: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 14068: }
14069: }
14070: }
14071: if (!$numconfig) {
1.372 raeburn 14072: $resulttext .= ' '.&mt('None');
1.273 raeburn 14073: }
14074: $resulttext .= '</li>';
1.267 raeburn 14075: foreach my $item ('passback','roster') {
14076: $resulttext .= '<li>'.$lt{$item}.' ';
14077: if ($confhash{$itemid}{$item}) {
14078: $resulttext .= &mt('Yes');
1.319 raeburn 14079: if ($confhash{$itemid}{$item.'valid'}) {
14080: if ($item eq 'passback') {
14081: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
14082: $confhash{$itemid}{$item.'valid'});
14083: } else {
14084: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
14085: $confhash{$itemid}{$item.'valid'});
14086: }
14087: }
1.267 raeburn 14088: } else {
14089: $resulttext .= &mt('No');
14090: }
14091: $resulttext .= '</li>';
14092: }
14093: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
14094: my $displaylist;
14095: if ($confhash{$itemid}{'display'}{'target'}) {
14096: $displaylist = &mt('Display target').': '.
14097: $confhash{$itemid}{'display'}{'target'}.',';
14098: }
14099: foreach my $size ('width','height') {
14100: if ($confhash{$itemid}{'display'}{$size}) {
14101: $displaylist .= (' 'x2).$lt{$size}.': '.
14102: $confhash{$itemid}{'display'}{$size}.',';
14103: }
14104: }
14105: if ($displaylist) {
14106: $displaylist =~ s/,$//;
14107: $resulttext .= '<li>'.$displaylist.'</li>';
14108: }
1.296 raeburn 14109: foreach my $item ('linktext','explanation') {
14110: if ($confhash{$itemid}{'display'}{$item}) {
14111: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
14112: }
14113: }
14114: }
1.267 raeburn 14115: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14116: my $fieldlist;
14117: foreach my $field (@allfields) {
14118: if ($confhash{$itemid}{'fields'}{$field}) {
14119: $fieldlist .= (' 'x2).$lt{$field}.',';
14120: }
14121: }
14122: if ($fieldlist) {
14123: $fieldlist =~ s/,$//;
1.324 raeburn 14124: if ($confhash{$itemid}{'fields'}{'user'}) {
14125: if ($confhash{$itemid}{'incdom'}) {
14126: $fieldlist .= ' ('.&mt('username:domain').')';
14127: } else {
14128: $fieldlist .= ' ('.&mt('username').')';
14129: }
14130: }
1.267 raeburn 14131: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
14132: }
14133: }
14134: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
14135: my $rolemaps;
14136: foreach my $role (@courseroles) {
14137: if ($confhash{$itemid}{'roles'}{$role}) {
14138: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14139: $confhash{$itemid}{'roles'}{$role}.',';
14140: }
14141: }
14142: if ($rolemaps) {
14143: $rolemaps =~ s/,$//;
14144: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14145: }
14146: }
14147: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
14148: my $customlist;
14149: if (keys(%{$confhash{$itemid}{'custom'}})) {
14150: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
14151: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
14152: }
14153: }
14154: if ($customlist) {
1.317 raeburn 14155: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 14156: }
14157: }
14158: $resulttext .= '</ul></li>';
14159: }
14160: }
14161: $resulttext .= '</ul>';
14162: } else {
14163: $resulttext = &mt('No changes made.');
14164: }
14165: } else {
14166: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14167: }
14168: if ($errors) {
14169: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14170: $errors.'</ul>';
14171: }
14172: return $resulttext;
14173: }
14174:
14175: sub process_ltitools_image {
14176: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
14177: my $filename = $env{'form.'.$caller.'.filename'};
14178: my ($error,$url);
14179: my ($width,$height) = (21,21);
14180: if ($configuserok eq 'ok') {
14181: if ($switchserver) {
14182: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
14183: $switchserver);
14184: } elsif ($author_ok eq 'ok') {
14185: my ($result,$imageurl,$madethumb) =
14186: &publishlogo($r,'upload',$caller,$dom,$confname,
14187: "ltitools/$itemid/icon",$width,$height);
14188: if ($result eq 'ok') {
14189: if ($madethumb) {
14190: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14191: my $imagethumb = "$path/tn-".$imagefile;
14192: $url = $imagethumb;
14193: } else {
14194: $url = $imageurl;
14195: }
14196: } else {
14197: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14198: }
14199: } else {
14200: $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);
14201: }
14202: } else {
14203: $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);
14204: }
14205: return ($url,$error);
14206: }
14207:
14208: sub get_ltitools_id {
14209: my ($cdom,$title) = @_;
14210: # get lock on ltitools db
14211: my $lockhash = {
14212: lock => $env{'user.name'}.
14213: ':'.$env{'user.domain'},
14214: };
14215: my $tries = 0;
14216: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14217: my ($id,$error);
14218:
14219: while (($gotlock ne 'ok') && ($tries<10)) {
14220: $tries ++;
14221: sleep (0.1);
14222: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14223: }
14224: if ($gotlock eq 'ok') {
14225: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
14226: if ($currids{'lock'}) {
14227: delete($currids{'lock'});
14228: if (keys(%currids)) {
14229: my @curr = sort { $a <=> $b } keys(%currids);
14230: if ($curr[-1] =~ /^\d+$/) {
14231: $id = 1 + $curr[-1];
14232: }
14233: } else {
14234: $id = 1;
14235: }
14236: if ($id) {
14237: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
14238: $error = 'nostore';
14239: }
14240: } else {
14241: $error = 'nonumber';
14242: }
14243: }
14244: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
14245: } else {
14246: $error = 'nolock';
14247: }
14248: return ($id,$error);
14249: }
14250:
1.372 raeburn 14251: sub modify_proctoring {
14252: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14253: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14254: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14255: my $confname = $dom.'-domainconfig';
14256: my $servadm = $r->dir_config('lonAdmEMail');
14257: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14258: my %providernames = &proctoring_providernames();
14259: my $maxnum = scalar(keys(%providernames));
14260:
14261: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14262: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14263: if (ref($requref) eq 'HASH') {
14264: %requserfields = %{$requref};
14265: }
14266: if (ref($opturef) eq 'HASH') {
14267: %optuserfields = %{$opturef};
14268: }
14269: if (ref($defref) eq 'HASH') {
14270: %defaults = %{$defref};
14271: }
14272: if (ref($extref) eq 'HASH') {
14273: %extended = %{$extref};
14274: }
14275: if (ref($crsref) eq 'HASH') {
14276: %crsconf = %{$crsref};
14277: }
14278: if (ref($rolesref) eq 'ARRAY') {
14279: @courseroles = @{$rolesref};
14280: }
14281: if (ref($ltiref) eq 'ARRAY') {
14282: @ltiroles = @{$ltiref};
14283: }
14284:
14285: if (ref($domconfig{$action}) eq 'HASH') {
14286: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14287: if (@todeleteimages) {
14288: map { $imgdeletions{$_} = 1; } @todeleteimages;
14289: }
14290: }
14291: my %customadds;
14292: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14293: if (@newcustom) {
14294: map { $customadds{$_} = 1; } @newcustom;
14295: }
14296: foreach my $provider (sort(keys(%providernames))) {
14297: $confhash{$provider} = {};
14298: my $pos = $env{'form.proctoring_pos_'.$provider};
14299: $pos =~ s/\D+//g;
14300: $allpos[$pos] = $provider;
14301: my (%current,%currentenc);
14302: my $showroles = 0;
14303: if (ref($domconfig{$action}) eq 'HASH') {
14304: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14305: %current = %{$domconfig{$action}{$provider}};
14306: foreach my $item ('key','secret') {
14307: $currentenc{$item} = $current{$item};
14308: delete($current{$item});
14309: }
14310: }
14311: }
14312: if ($env{'form.proctoring_available_'.$provider}) {
14313: $confhash{$provider}{'available'} = 1;
14314: unless ($current{'available'}) {
14315: $changes{$provider} = 1;
14316: }
14317: } else {
14318: %{$confhash{$provider}} = %current;
14319: %{$encconfhash{$provider}} = %currentenc;
14320: $confhash{$provider}{'available'} = 0;
14321: if ($current{'available'}) {
14322: $changes{$provider} = 1;
14323: }
14324: }
14325: if ($confhash{$provider}{'available'}) {
14326: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14327: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14328: if ($field eq 'lifetime') {
14329: if ($possval =~ /^\d+$/) {
14330: $confhash{$provider}{$field} = $possval;
14331: }
14332: } elsif ($field eq 'version') {
14333: if ($possval =~ /^\d+\.\d+$/) {
14334: $confhash{$provider}{$field} = $possval;
14335: }
14336: } elsif ($field eq 'sigmethod') {
14337: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14338: $confhash{$provider}{$field} = $possval;
14339: }
14340: } elsif ($field eq 'url') {
14341: $confhash{$provider}{$field} = $possval;
14342: } elsif (($field eq 'key') || ($field eq 'secret')) {
14343: $encconfhash{$provider}{$field} = $possval;
14344: unless ($currentenc{$field} eq $possval) {
14345: $changes{$provider} = 1;
14346: }
14347: }
14348: unless (($field eq 'key') || ($field eq 'secret')) {
14349: unless ($current{$field} eq $confhash{$provider}{$field}) {
14350: $changes{$provider} = 1;
14351: }
14352: }
14353: }
14354: if ($imgdeletions{$provider}) {
14355: $changes{$provider} = 1;
14356: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14357: my ($imageurl,$error) =
14358: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14359: $configuserok,$switchserver,$author_ok);
14360: if ($imageurl) {
14361: $confhash{$provider}{'image'} = $imageurl;
14362: $changes{$provider} = 1;
14363: }
14364: if ($error) {
14365: &Apache::lonnet::logthis($error);
14366: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14367: }
14368: } elsif (exists($current{'image'})) {
14369: $confhash{$provider}{'image'} = $current{'image'};
14370: }
14371: if (ref($requserfields{$provider}) eq 'ARRAY') {
14372: if (@{$requserfields{$provider}} > 0) {
14373: if (grep(/^user$/,@{$requserfields{$provider}})) {
14374: if ($env{'form.proctoring_userincdom_'.$provider}) {
14375: $confhash{$provider}{'incdom'} = 1;
14376: }
14377: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14378: $changes{$provider} = 1;
14379: }
14380: }
14381: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14382: $showroles = 1;
14383: }
14384: }
14385: }
14386: $confhash{$provider}{'fields'} = [];
14387: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14388: if (@{$optuserfields{$provider}} > 0) {
14389: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14390: foreach my $field (@{$optuserfields{$provider}}) {
14391: if (grep(/^\Q$field\E$/,@optfields)) {
14392: push(@{$confhash{$provider}{'fields'}},$field);
14393: }
14394: }
14395: }
14396: if (ref($current{'fields'}) eq 'ARRAY') {
14397: unless ($changes{$provider}) {
14398: my @new = sort(@{$confhash{$provider}{'fields'}});
14399: my @old = sort(@{$current{'fields'}});
14400: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14401: if (@diffs) {
14402: $changes{$provider} = 1;
14403: }
14404: }
14405: } elsif (@{$confhash{$provider}{'fields'}}) {
14406: $changes{$provider} = 1;
14407: }
14408: }
14409: if (ref($defaults{$provider}) eq 'ARRAY') {
14410: if (@{$defaults{$provider}} > 0) {
14411: my %options;
14412: if (ref($extended{$provider}) eq 'HASH') {
14413: %options = %{$extended{$provider}};
14414: }
14415: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14416: foreach my $field (@{$defaults{$provider}}) {
14417: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14418: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14419: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14420: push(@{$confhash{$provider}{'defaults'}},$poss);
14421: }
14422: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14423: foreach my $inner (keys(%{$options{$field}})) {
14424: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14425: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14426: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14427: $confhash{$provider}{'defaults'}{$inner} = $poss;
14428: }
14429: } else {
14430: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14431: }
14432: }
14433: } else {
14434: if (grep(/^\Q$field\E$/,@checked)) {
14435: push(@{$confhash{$provider}{'defaults'}},$field);
14436: }
14437: }
14438: }
14439: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14440: if (ref($current{'defaults'}) eq 'ARRAY') {
14441: unless ($changes{$provider}) {
14442: my @new = sort(@{$confhash{$provider}{'defaults'}});
14443: my @old = sort(@{$current{'defaults'}});
14444: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14445: if (@diffs) {
14446: $changes{$provider} = 1;
14447: }
14448: }
14449: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14450: if (@{$current{'defaults'}}) {
14451: $changes{$provider} = 1;
14452: }
14453: }
14454: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14455: if (ref($current{'defaults'}) eq 'HASH') {
14456: unless ($changes{$provider}) {
14457: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14458: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14459: $changes{$provider} = 1;
14460: last;
14461: }
14462: }
14463: }
14464: unless ($changes{$provider}) {
14465: foreach my $key (keys(%{$current{'defaults'}})) {
14466: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14467: $changes{$provider} = 1;
14468: last;
14469: }
14470: }
14471: }
14472: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14473: $changes{$provider} = 1;
14474: }
14475: }
14476: }
14477: }
14478: if (ref($crsconf{$provider}) eq 'ARRAY') {
14479: if (@{$crsconf{$provider}} > 0) {
14480: $confhash{$provider}{'crsconf'} = [];
14481: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14482: foreach my $crsfield (@{$crsconf{$provider}}) {
14483: if (grep(/^\Q$crsfield\E$/,@checked)) {
14484: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14485: }
14486: }
14487: if (ref($current{'crsconf'}) eq 'ARRAY') {
14488: unless ($changes{$provider}) {
14489: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14490: my @old = sort(@{$current{'crsconf'}});
14491: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14492: if (@diffs) {
14493: $changes{$provider} = 1;
14494: }
14495: }
14496: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14497: $changes{$provider} = 1;
14498: }
14499: }
14500: }
14501: if ($showroles) {
14502: $confhash{$provider}{'roles'} = {};
14503: foreach my $role (@courseroles) {
14504: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14505: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14506: $confhash{$provider}{'roles'}{$role} = $poss;
14507: }
14508: }
14509: unless ($changes{$provider}) {
14510: if (ref($current{'roles'}) eq 'HASH') {
14511: foreach my $role (keys(%{$current{'roles'}})) {
14512: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14513: $changes{$provider} = 1;
14514: last
14515: }
14516: }
14517: unless ($changes{$provider}) {
14518: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14519: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14520: $changes{$provider} = 1;
14521: last;
14522: }
14523: }
14524: }
14525: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14526: $changes{$provider} = 1;
14527: }
14528: }
14529: }
14530: if (ref($current{'custom'}) eq 'HASH') {
14531: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14532: foreach my $key (keys(%{$current{'custom'}})) {
14533: if (grep(/^\Q$key\E$/,@customdels)) {
14534: $changes{$provider} = 1;
14535: } else {
14536: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14537: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14538: $changes{$provider} = 1;
14539: }
14540: }
14541: }
14542: }
14543: if ($customadds{$provider}) {
14544: my $name = $env{'form.proctoring_custom_name_'.$provider};
14545: $name =~ s/(`)/'/g;
14546: $name =~ s/^\s+//;
14547: $name =~ s/\s+$//;
14548: my $value = $env{'form.proctoring_custom_value_'.$provider};
14549: $value =~ s/(`)/'/g;
14550: $value =~ s/^\s+//;
14551: $value =~ s/\s+$//;
14552: if ($name ne '') {
14553: $confhash{$provider}{'custom'}{$name} = $value;
14554: $changes{$provider} = 1;
14555: }
14556: }
14557: }
14558: }
14559: if (@allpos > 0) {
14560: my $idx = 0;
14561: foreach my $provider (@allpos) {
14562: if ($provider ne '') {
14563: $confhash{$provider}{'order'} = $idx;
14564: unless ($changes{$provider}) {
14565: if (ref($domconfig{$action}) eq 'HASH') {
14566: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14567: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14568: $changes{$provider} = 1;
14569: }
14570: }
14571: }
14572: }
14573: $idx ++;
14574: }
14575: }
14576: }
14577: my %proc_hash = (
14578: $action => { %confhash }
14579: );
14580: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14581: $dom);
14582: if ($putresult eq 'ok') {
14583: my %proc_enchash = (
14584: $action => { %encconfhash }
14585: );
1.384 raeburn 14586: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14587: if (keys(%changes) > 0) {
14588: my $cachetime = 24*60*60;
14589: my %procall = %confhash;
14590: foreach my $provider (keys(%procall)) {
14591: if (ref($encconfhash{$provider}) eq 'HASH') {
14592: foreach my $key ('key','secret') {
14593: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14594: }
14595: }
14596: }
14597: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14598: if (ref($lastactref) eq 'HASH') {
14599: $lastactref->{'proctoring'} = 1;
14600: }
14601: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14602: my %bynum;
14603: foreach my $provider (sort(keys(%changes))) {
14604: my $position = $confhash{$provider}{'order'};
14605: $bynum{$position} = $provider;
14606: }
14607: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14608: my $provider = $bynum{$pos};
14609: my %lt = &proctoring_titles($provider);
14610: my %fieldtitles = &proctoring_fieldtitles($provider);
14611: if (!$confhash{$provider}{'available'}) {
14612: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14613: } else {
14614: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14615: if ($confhash{$provider}{'image'}) {
14616: $resulttext .= ' '.
14617: '<img src="'.$confhash{$provider}{'image'}.'"'.
14618: ' alt="'.&mt('Proctoring icon').'" />';
14619: }
14620: $resulttext .= '<ul>';
14621: my $position = $pos + 1;
14622: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14623: foreach my $key ('version','sigmethod','url','lifetime') {
14624: if ($confhash{$provider}{$key} ne '') {
14625: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14626: }
14627: }
14628: if ($encconfhash{$provider}{'key'} ne '') {
14629: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14630: }
14631: if ($encconfhash{$provider}{'secret'} ne '') {
14632: $resulttext .= '<li>'.$lt{'secret'}.': ';
14633: my $num = length($encconfhash{$provider}{'secret'});
14634: $resulttext .= ('*'x$num).'</li>';
14635: }
14636: my (@fields,$showroles);
14637: if (ref($requserfields{$provider}) eq 'ARRAY') {
14638: push(@fields,@{$requserfields{$provider}});
14639: }
14640: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14641: push(@fields,@{$confhash{$provider}{'fields'}});
14642: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14643: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14644: }
14645: if (@fields) {
14646: if (grep(/^roles$/,@fields)) {
14647: $showroles = 1;
14648: }
14649: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14650: join('", "', map { $lt{$_}; } @fields).'"</li>';
14651: }
14652: if (ref($requserfields{$provider}) eq 'ARRAY') {
14653: if (grep(/^user$/,@{$requserfields{$provider}})) {
14654: if ($confhash{$provider}{'incdom'}) {
14655: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14656: } else {
14657: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14658: }
14659: }
14660: }
14661: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14662: if (@{$confhash{$provider}{'defaults'}} > 0) {
14663: $resulttext .= '<li>'.$lt{'defa'};
14664: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14665: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14666: }
14667: $resulttext =~ s/,$//;
14668: $resulttext .= '</li>';
14669: }
14670: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14671: if (keys(%{$confhash{$provider}{'defaults'}})) {
14672: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14673: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14674: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14675: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14676: }
14677: }
14678: $resulttext .= '</ul></li>';
14679: }
14680: }
14681: if (ref($crsconf{$provider}) eq 'ARRAY') {
14682: if (@{$crsconf{$provider}} > 0) {
14683: $resulttext .= '<li>'.&mt('Configurable in course:');
14684: my $numconfig = 0;
14685: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14686: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14687: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14688: $numconfig ++;
14689: if ($provider eq 'examity') {
14690: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14691: } else {
14692: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14693: }
14694: }
14695: $resulttext =~ s/,$//;
14696: }
14697: }
14698: if (!$numconfig) {
14699: $resulttext .= ' '.&mt('None');
14700: }
14701: $resulttext .= '</li>';
14702: }
14703: }
14704: if ($showroles) {
14705: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14706: my $rolemaps;
14707: foreach my $role (@courseroles) {
14708: if ($confhash{$provider}{'roles'}{$role}) {
14709: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14710: $confhash{$provider}{'roles'}{$role}.',';
14711: }
14712: }
14713: if ($rolemaps) {
14714: $rolemaps =~ s/,$//;
14715: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14716: }
14717: }
14718: }
14719: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
14720: my $customlist;
14721: if (keys(%{$confhash{$provider}{'custom'}})) {
14722: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
14723: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
14724: }
14725: $customlist =~ s/,$//;
14726: }
14727: if ($customlist) {
14728: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
14729: }
14730: }
14731: $resulttext .= '</ul></li>';
14732: }
14733: }
14734: $resulttext .= '</ul>';
14735: } else {
14736: $resulttext = &mt('No changes made.');
14737: }
14738: } else {
14739: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14740: }
14741: if ($errors) {
14742: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14743: $errors.'</ul>';
14744: }
14745: return $resulttext;
14746: }
14747:
14748: sub process_proctoring_image {
14749: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14750: my $filename = $env{'form.'.$caller.'.filename'};
14751: my ($error,$url);
14752: my ($width,$height) = (21,21);
14753: if ($configuserok eq 'ok') {
14754: if ($switchserver) {
14755: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14756: $switchserver);
14757: } elsif ($author_ok eq 'ok') {
14758: my ($result,$imageurl,$madethumb) =
14759: &publishlogo($r,'upload',$caller,$dom,$confname,
14760: "proctoring/$provider/icon",$width,$height);
14761: if ($result eq 'ok') {
14762: if ($madethumb) {
14763: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14764: my $imagethumb = "$path/tn-".$imagefile;
14765: $url = $imagethumb;
14766: } else {
14767: $url = $imageurl;
14768: }
14769: } else {
14770: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14771: }
14772: } else {
14773: $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);
14774: }
14775: } else {
14776: $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);
14777: }
14778: return ($url,$error);
14779: }
14780:
1.320 raeburn 14781: sub modify_lti {
14782: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14783: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14784: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14785: my (%posslti,%posslticrs,%posscrstype);
14786: my @courseroles = ('cc','in','ta','ep','st');
14787: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14788: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 ! raeburn 14789: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 14790: my %coursetypetitles = &Apache::lonlocal::texthash (
14791: official => 'Official',
14792: unofficial => 'Unofficial',
14793: community => 'Community',
14794: textbook => 'Textbook',
14795: placement => 'Placement Test',
1.392 ! raeburn 14796: lti => 'LTI Provider',
1.320 raeburn 14797: );
1.325 raeburn 14798: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14799: my %lt = <i_names();
14800: map { $posslti{$_} = 1; } @ltiroles;
14801: map { $posslticrs{$_} = 1; } @lticourseroles;
14802: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14803:
1.326 raeburn 14804: my %menutitles = <imenu_titles();
14805:
1.320 raeburn 14806: my (@items,%deletions,%itemids);
14807: if ($env{'form.lti_add'}) {
14808: my $consumer = $env{'form.lti_consumer_add'};
14809: $consumer =~ s/(`)/'/g;
14810: ($newid,my $error) = &get_lti_id($dom,$consumer);
14811: if ($newid) {
14812: $itemids{'add'} = $newid;
14813: push(@items,'add');
14814: $changes{$newid} = 1;
14815: } else {
14816: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14817: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14818: }
14819: }
14820: if (ref($domconfig{$action}) eq 'HASH') {
14821: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14822: if (@todelete) {
14823: map { $deletions{$_} = 1; } @todelete;
14824: }
14825: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 14826: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 14827: my $itemid = $env{'form.lti_id_'.$i};
14828: $itemid =~ s/\D+//g;
14829: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14830: if ($deletions{$itemid}) {
14831: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14832: } else {
1.390 raeburn 14833: push(@items,$i);
14834: $itemids{$i} = $itemid;
1.320 raeburn 14835: }
14836: }
14837: }
14838: }
14839: foreach my $idx (@items) {
14840: my $itemid = $itemids{$idx};
14841: next unless ($itemid);
1.390 raeburn 14842: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 14843: $position =~ s/\D+//g;
14844: if ($position ne '') {
14845: $allpos[$position] = $itemid;
14846: }
1.391 raeburn 14847: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 14848: my $formitem = 'form.lti_'.$item.'_'.$idx;
14849: $env{$formitem} =~ s/(`)/'/g;
14850: if ($item eq 'lifetime') {
14851: $env{$formitem} =~ s/[^\d.]//g;
14852: }
14853: if ($env{$formitem} ne '') {
14854: if (($item eq 'key') || ($item eq 'secret')) {
14855: $encconfig{$itemid}{$item} = $env{$formitem};
14856: } else {
14857: $confhash{$itemid}{$item} = $env{$formitem};
14858: unless (($idx eq 'add') || ($changes{$itemid})) {
14859: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14860: $changes{$itemid} = 1;
14861: }
14862: }
14863: }
14864: }
14865: }
14866: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14867: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14868: }
1.345 raeburn 14869: if ($confhash{$itemid}{'requser'}) {
14870: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14871: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14872: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14873: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14874: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14875: my $mapuser = $env{'form.lti_customuser_'.$idx};
14876: $mapuser =~ s/(`)/'/g;
14877: $mapuser =~ s/^\s+|\s+$//g;
14878: $confhash{$itemid}{'mapuser'} = $mapuser;
14879: }
14880: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14881: my @makeuser;
14882: foreach my $ltirole (sort(@possmakeuser)) {
14883: if ($posslti{$ltirole}) {
14884: push(@makeuser,$ltirole);
14885: }
14886: }
14887: $confhash{$itemid}{'makeuser'} = \@makeuser;
14888: if (@makeuser) {
14889: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14890: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14891: $confhash{$itemid}{'lcauth'} = $lcauth;
14892: if ($lcauth ne 'internal') {
14893: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14894: $lcauthparm =~ s/^(\s+|\s+)$//g;
14895: $lcauthparm =~ s/`//g;
14896: if ($lcauthparm ne '') {
14897: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14898: }
14899: }
14900: } else {
14901: $confhash{$itemid}{'lcauth'} = 'lti';
14902: }
1.320 raeburn 14903: }
1.345 raeburn 14904: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14905: if (@possinstdata) {
14906: foreach my $field (@possinstdata) {
14907: if (exists($fieldtitles{$field})) {
14908: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14909: }
14910: }
14911: }
1.363 raeburn 14912: if ($env{'form.lti_callback_'.$idx}) {
14913: if ($env{'form.lti_callbackparam_'.$idx}) {
14914: my $callback = $env{'form.lti_callbackparam_'.$idx};
14915: $callback =~ s/^\s+|\s+$//g;
14916: $confhash{$itemid}{'callback'} = $callback;
14917: }
14918: }
1.391 raeburn 14919: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 14920: if ($env{'form.lti_'.$field.'_'.$idx}) {
14921: $confhash{$itemid}{$field} = 1;
14922: }
1.320 raeburn 14923: }
1.345 raeburn 14924: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14925: $confhash{$itemid}{lcmenu} = [];
14926: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14927: foreach my $field (@possmenu) {
14928: if (exists($menutitles{$field})) {
14929: if ($field eq 'grades') {
14930: next unless ($env{'form.lti_inlinemenu_'.$idx});
14931: }
14932: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14933: }
14934: }
14935: }
1.391 raeburn 14936: if ($confhash{$itemid}{'crsinc'}) {
14937: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14938: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14939: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14940: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14941: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14942: $mapcrs =~ s/(`)/'/g;
14943: $mapcrs =~ s/^\s+|\s+$//g;
14944: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14945: }
14946: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14947: my @crstypes;
14948: foreach my $type (sort(@posstypes)) {
14949: if ($posscrstype{$type}) {
14950: push(@crstypes,$type);
14951: }
14952: }
14953: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 ! raeburn 14954: if ($env{'form.lti_storecrs_'.$idx}) {
! 14955: $confhash{$itemid}{'storecrs'} = 1;
! 14956: }
1.391 raeburn 14957: if ($env{'form.lti_makecrs_'.$idx}) {
14958: $confhash{$itemid}{'makecrs'} = 1;
14959: }
14960: foreach my $ltirole (@lticourseroles) {
14961: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14962: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14963: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14964: }
14965: }
14966: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14967: my @selfenroll;
14968: foreach my $type (sort(@possenroll)) {
14969: if ($posslticrs{$type}) {
14970: push(@selfenroll,$type);
14971: }
14972: }
14973: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14974: if ($env{'form.lti_crssec_'.$idx}) {
14975: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14976: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14977: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14978: my $section = $env{'form.lti_customsection_'.$idx};
14979: $section =~ s/(`)/'/g;
14980: $section =~ s/^\s+|\s+$//g;
14981: if ($section ne '') {
14982: $confhash{$itemid}{'section'} = $section;
14983: }
14984: }
14985: }
14986: foreach my $field ('passback','roster') {
14987: if ($env{'form.lti_'.$field.'_'.$idx}) {
14988: $confhash{$itemid}{$field} = 1;
14989: }
14990: }
14991: if ($env{'form.lti_passback_'.$idx}) {
14992: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14993: $confhash{$itemid}{'passbackformat'} = '1.0';
14994: } else {
14995: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 14996: }
14997: }
1.391 raeburn 14998: }
14999: unless (($idx eq 'add') || ($changes{$itemid})) {
15000: if ($confhash{$itemid}{'crsinc'}) {
1.392 ! raeburn 15001: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 15002: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15003: $changes{$itemid} = 1;
15004: }
1.345 raeburn 15005: }
15006: unless ($changes{$itemid}) {
1.391 raeburn 15007: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
15008: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15009: $changes{$itemid} = 1;
15010: }
15011: }
1.345 raeburn 15012: }
1.391 raeburn 15013: foreach my $field ('mapcrstype','selfenroll') {
15014: unless ($changes{$itemid}) {
15015: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15016: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15017: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15018: $confhash{$itemid}{$field});
15019: if (@diffs) {
15020: $changes{$itemid} = 1;
15021: }
15022: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15023: $changes{$itemid} = 1;
15024: }
15025: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15026: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15027: $changes{$itemid} = 1;
15028: }
15029: }
1.391 raeburn 15030: }
15031: }
15032: unless ($changes{$itemid}) {
15033: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
15034: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15035: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
15036: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
15037: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15038: $changes{$itemid} = 1;
15039: last;
15040: }
15041: }
1.391 raeburn 15042: unless ($changes{$itemid}) {
15043: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15044: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
15045: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
15046: $changes{$itemid} = 1;
15047: last;
15048: }
15049: }
15050: }
15051: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
15052: $changes{$itemid} = 1;
1.345 raeburn 15053: }
1.391 raeburn 15054: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15055: unless ($changes{$itemid}) {
15056: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15057: $changes{$itemid} = 1;
15058: }
15059: }
15060: }
15061: }
15062: }
15063: unless ($changes{$itemid}) {
15064: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
15065: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15066: $changes{$itemid} = 1;
1.320 raeburn 15067: }
1.391 raeburn 15068: }
15069: unless ($changes{$itemid}) {
15070: foreach my $field ('makeuser','lcmenu') {
15071: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15072: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15073: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15074: $confhash{$itemid}{$field});
15075: if (@diffs) {
15076: $changes{$itemid} = 1;
15077: }
15078: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15079: $changes{$itemid} = 1;
15080: }
15081: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15082: if (@{$confhash{$itemid}{$field}} > 0) {
15083: $changes{$itemid} = 1;
15084: }
1.345 raeburn 15085: }
1.320 raeburn 15086: }
15087: }
15088: }
15089: }
15090: }
15091: }
15092: if (@allpos > 0) {
15093: my $idx = 0;
15094: foreach my $itemid (@allpos) {
15095: if ($itemid ne '') {
15096: $confhash{$itemid}{'order'} = $idx;
15097: if (ref($domconfig{$action}) eq 'HASH') {
15098: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15099: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15100: $changes{$itemid} = 1;
15101: }
15102: }
15103: }
15104: $idx ++;
15105: }
15106: }
15107: }
15108: my %ltihash = (
15109: $action => { %confhash }
15110: );
15111: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
15112: $dom);
15113: if ($putresult eq 'ok') {
15114: my %ltienchash = (
15115: $action => { %encconfig }
15116: );
1.384 raeburn 15117: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320 raeburn 15118: if (keys(%changes) > 0) {
15119: my $cachetime = 24*60*60;
15120: my %ltiall = %confhash;
15121: foreach my $id (keys(%ltiall)) {
15122: if (ref($encconfig{$id}) eq 'HASH') {
15123: foreach my $item ('key','secret') {
15124: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15125: }
15126: }
15127: }
15128: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15129: if (ref($lastactref) eq 'HASH') {
15130: $lastactref->{'lti'} = 1;
15131: }
15132: $resulttext = &mt('Changes made:').'<ul>';
15133: my %bynum;
15134: foreach my $itemid (sort(keys(%changes))) {
15135: my $position = $confhash{$itemid}{'order'};
15136: $bynum{$position} = $itemid;
15137: }
15138: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15139: my $itemid = $bynum{$pos};
15140: if (ref($confhash{$itemid}) ne 'HASH') {
15141: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15142: } else {
1.390 raeburn 15143: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15144: my $position = $pos + 1;
15145: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15146: foreach my $item ('version','lifetime') {
15147: if ($confhash{$itemid}{$item} ne '') {
15148: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15149: }
15150: }
15151: if ($encconfig{$itemid}{'key'} ne '') {
15152: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15153: }
15154: if ($encconfig{$itemid}{'secret'} ne '') {
15155: $resulttext .= '<li>'.$lt{'secret'}.': ';
15156: my $num = length($encconfig{$itemid}{'secret'});
15157: $resulttext .= ('*'x$num).'</li>';
15158: }
1.345 raeburn 15159: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 15160: if ($confhash{$itemid}{'callback'}) {
15161: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15162: } else {
1.392 ! raeburn 15163: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 15164: }
1.345 raeburn 15165: if ($confhash{$itemid}{'mapuser'}) {
15166: my $shownmapuser;
15167: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15168: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15169: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15170: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15171: } else {
15172: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15173: }
1.345 raeburn 15174: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15175: }
1.345 raeburn 15176: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15177: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15178: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15179: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15180: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15181: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15182: } else {
15183: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15184: $confhash{$itemid}{'lcauth'});
15185: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15186: $resulttext .= '; '.&mt('a randomly generated password will be created');
15187: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15188: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15189: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15190: }
15191: } else {
15192: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15193: }
15194: }
15195: $resulttext .= '</li>';
15196: } else {
15197: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15198: }
1.320 raeburn 15199: }
1.345 raeburn 15200: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15201: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15202: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15203: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15204: } else {
1.345 raeburn 15205: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15206: }
1.320 raeburn 15207: }
1.391 raeburn 15208: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15209: $resulttext .= '<li>'.$lt{$item}.': ';
15210: if ($confhash{$itemid}{$item}) {
15211: $resulttext .= &mt('Yes');
15212: } else {
15213: $resulttext .= &mt('No');
1.337 raeburn 15214: }
1.345 raeburn 15215: $resulttext .= '</li>';
1.320 raeburn 15216: }
1.345 raeburn 15217: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15218: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15219: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 15220: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15221: } else {
15222: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15223: }
15224: }
15225: if ($confhash{$itemid}{'crsinc'}) {
15226: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15227: my $rolemaps;
15228: foreach my $role (@ltiroles) {
15229: if ($confhash{$itemid}{'maproles'}{$role}) {
15230: $rolemaps .= (' 'x2).$role.'='.
15231: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15232: 'Course').',';
15233: }
15234: }
15235: if ($rolemaps) {
15236: $rolemaps =~ s/,$//;
15237: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15238: }
15239: }
15240: if ($confhash{$itemid}{'mapcrs'}) {
15241: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15242: }
15243: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15244: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15245: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15246: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15247: '</li>';
15248: } else {
15249: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15250: }
15251: }
1.392 ! raeburn 15252: if ($confhash{$itemid}{'storecrs'}) {
! 15253: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
! 15254: }
1.391 raeburn 15255: if ($confhash{$itemid}{'makecrs'}) {
15256: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
15257: } else {
15258: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
15259: }
15260: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15261: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15262: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15263: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15264: '</li>';
15265: } else {
15266: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15267: }
15268: }
15269: if ($confhash{$itemid}{'section'}) {
15270: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15271: $resulttext .= '<li>'.&mt('User section from standard field:').
15272: ' (course_section_sourcedid)'.'</li>';
15273: } else {
15274: $resulttext .= '<li>'.&mt('User section from:').' '.
15275: $confhash{$itemid}{'section'}.'</li>';
15276: }
1.345 raeburn 15277: } else {
1.391 raeburn 15278: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
15279: }
15280: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15281: $resulttext .= '<li>'.$lt{$item}.': ';
15282: if ($confhash{$itemid}{$item}) {
15283: $resulttext .= &mt('Yes');
15284: if ($item eq 'passback') {
15285: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15286: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15287: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15288: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15289: }
15290: }
15291: } else {
15292: $resulttext .= &mt('No');
15293: }
15294: $resulttext .= '</li>';
15295: }
15296: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15297: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15298: $resulttext .= '<li>'.&mt('Menu items:').' '.
15299: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15300: } else {
15301: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15302: }
1.345 raeburn 15303: }
1.326 raeburn 15304: }
15305: }
1.320 raeburn 15306: $resulttext .= '</ul></li>';
15307: }
15308: }
15309: $resulttext .= '</ul>';
15310: } else {
15311: $resulttext = &mt('No changes made.');
15312: }
15313: } else {
15314: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15315: }
15316: if ($errors) {
15317: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15318: $errors.'</ul>';
15319: }
15320: return $resulttext;
15321: }
15322:
15323: sub get_lti_id {
15324: my ($domain,$consumer) = @_;
15325: # get lock on lti db
15326: my $lockhash = {
15327: lock => $env{'user.name'}.
15328: ':'.$env{'user.domain'},
15329: };
15330: my $tries = 0;
15331: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15332: my ($id,$error);
15333:
15334: while (($gotlock ne 'ok') && ($tries<10)) {
15335: $tries ++;
15336: sleep (0.1);
15337: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15338: }
15339: if ($gotlock eq 'ok') {
15340: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15341: if ($currids{'lock'}) {
15342: delete($currids{'lock'});
15343: if (keys(%currids)) {
15344: my @curr = sort { $a <=> $b } keys(%currids);
15345: if ($curr[-1] =~ /^\d+$/) {
15346: $id = 1 + $curr[-1];
15347: }
15348: } else {
15349: $id = 1;
15350: }
15351: if ($id) {
15352: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15353: $error = 'nostore';
15354: }
15355: } else {
15356: $error = 'nonumber';
15357: }
15358: }
15359: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15360: } else {
15361: $error = 'nolock';
15362: }
15363: return ($id,$error);
15364: }
15365:
1.3 raeburn 15366: sub modify_autoenroll {
1.205 raeburn 15367: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15368: my ($resulttext,%changes);
15369: my %currautoenroll;
15370: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15371: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15372: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15373: }
15374: }
15375: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15376: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15377: sender => 'Sender for notification messages',
1.274 raeburn 15378: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
15379: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15380: my @offon = ('off','on');
1.17 raeburn 15381: my $sender_uname = $env{'form.sender_uname'};
15382: my $sender_domain = $env{'form.sender_domain'};
15383: if ($sender_domain eq '') {
15384: $sender_uname = '';
15385: } elsif ($sender_uname eq '') {
15386: $sender_domain = '';
15387: }
1.129 raeburn 15388: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 15389: my $failsafe = $env{'form.autoenroll_failsafe'};
15390: $failsafe =~ s{^\s+|\s+$}{}g;
15391: if ($failsafe =~ /\D/) {
15392: undef($failsafe);
15393: }
1.1 raeburn 15394: my %autoenrollhash = (
1.129 raeburn 15395: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15396: 'sender_uname' => $sender_uname,
15397: 'sender_domain' => $sender_domain,
15398: 'co-owners' => $coowners,
1.274 raeburn 15399: 'autofailsafe' => $failsafe,
1.1 raeburn 15400: }
15401: );
1.4 raeburn 15402: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15403: $dom);
1.1 raeburn 15404: if ($putresult eq 'ok') {
15405: if (exists($currautoenroll{'run'})) {
15406: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15407: $changes{'run'} = 1;
15408: }
15409: } elsif ($autorun) {
15410: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15411: $changes{'run'} = 1;
1.1 raeburn 15412: }
15413: }
1.17 raeburn 15414: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15415: $changes{'sender'} = 1;
15416: }
1.17 raeburn 15417: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15418: $changes{'sender'} = 1;
15419: }
1.129 raeburn 15420: if ($currautoenroll{'co-owners'} ne '') {
15421: if ($currautoenroll{'co-owners'} ne $coowners) {
15422: $changes{'coowners'} = 1;
15423: }
15424: } elsif ($coowners) {
15425: $changes{'coowners'} = 1;
1.274 raeburn 15426: }
15427: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
15428: $changes{'autofailsafe'} = 1;
15429: }
1.1 raeburn 15430: if (keys(%changes) > 0) {
15431: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15432: if ($changes{'run'}) {
1.1 raeburn 15433: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15434: }
15435: if ($changes{'sender'}) {
1.17 raeburn 15436: if ($sender_uname eq '' || $sender_domain eq '') {
15437: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15438: } else {
15439: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15440: }
1.1 raeburn 15441: }
1.129 raeburn 15442: if ($changes{'coowners'}) {
15443: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15444: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15445: if (ref($lastactref) eq 'HASH') {
15446: $lastactref->{'domainconfig'} = 1;
15447: }
1.129 raeburn 15448: }
1.274 raeburn 15449: if ($changes{'autofailsafe'}) {
15450: if ($failsafe ne '') {
1.299 raeburn 15451: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 15452: } else {
1.299 raeburn 15453: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 15454: }
15455: &Apache::lonnet::get_domain_defaults($dom,1);
15456: if (ref($lastactref) eq 'HASH') {
15457: $lastactref->{'domdefaults'} = 1;
15458: }
15459: }
1.1 raeburn 15460: $resulttext .= '</ul>';
15461: } else {
15462: $resulttext = &mt('No changes made to auto-enrollment settings');
15463: }
15464: } else {
1.11 albertel 15465: $resulttext = '<span class="LC_error">'.
15466: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15467: }
1.3 raeburn 15468: return $resulttext;
1.1 raeburn 15469: }
15470:
15471: sub modify_autoupdate {
1.3 raeburn 15472: my ($dom,%domconfig) = @_;
1.1 raeburn 15473: my ($resulttext,%currautoupdate,%fields,%changes);
15474: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
15475: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
15476: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
15477: }
15478: }
15479: my @offon = ('off','on');
15480: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 15481: run => 'Auto-update:',
15482: classlists => 'Updates to user information in classlists?',
15483: unexpired => 'Skip updates for users without active or future roles?',
15484: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 15485: );
1.44 raeburn 15486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 15487: my %fieldtitles = &Apache::lonlocal::texthash (
15488: id => 'Student/Employee ID',
1.20 raeburn 15489: permanentemail => 'E-mail address',
1.1 raeburn 15490: lastname => 'Last Name',
15491: firstname => 'First Name',
15492: middlename => 'Middle Name',
1.132 raeburn 15493: generation => 'Generation',
1.1 raeburn 15494: );
1.142 raeburn 15495: $othertitle = &mt('All users');
1.1 raeburn 15496: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 15497: $othertitle = &mt('Other users');
1.1 raeburn 15498: }
15499: foreach my $key (keys(%env)) {
15500: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 15501: my ($usertype,$item) = ($1,$2);
15502: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
15503: if ($usertype eq 'default') {
15504: push(@{$fields{$1}},$2);
15505: } elsif (ref($types) eq 'ARRAY') {
15506: if (grep(/^\Q$usertype\E$/,@{$types})) {
15507: push(@{$fields{$1}},$2);
15508: }
15509: }
15510: }
1.1 raeburn 15511: }
15512: }
1.131 raeburn 15513: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
15514: @lockablenames = sort(@lockablenames);
15515: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
15516: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15517: if (@changed) {
15518: $changes{'lockablenames'} = 1;
15519: }
15520: } else {
15521: if (@lockablenames) {
15522: $changes{'lockablenames'} = 1;
15523: }
15524: }
1.1 raeburn 15525: my %updatehash = (
15526: autoupdate => { run => $env{'form.autoupdate_run'},
15527: classlists => $env{'form.classlists'},
1.385 raeburn 15528: unexpired => $env{'form.unexpired'},
1.1 raeburn 15529: fields => {%fields},
1.131 raeburn 15530: lockablenames => \@lockablenames,
1.1 raeburn 15531: }
15532: );
1.385 raeburn 15533: my $lastactivedays;
15534: if ($env{'form.lastactive'}) {
15535: $lastactivedays = $env{'form.lastactivedays'};
15536: $lastactivedays =~ s/^\s+|\s+$//g;
15537: unless ($lastactivedays =~ /^\d+$/) {
15538: undef($lastactivedays);
15539: $env{'form.lastactive'} = 0;
15540: }
15541: }
15542: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 15543: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 15544: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 15545: if (exists($updatehash{autoupdate}{$key})) {
15546: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
15547: $changes{$key} = 1;
15548: }
15549: }
15550: } elsif ($key eq 'fields') {
15551: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 15552: foreach my $item (@{$types},'default') {
1.1 raeburn 15553: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
15554: my $change = 0;
15555: foreach my $type (@{$currautoupdate{$key}{$item}}) {
15556: if (!exists($fields{$item})) {
15557: $change = 1;
1.132 raeburn 15558: last;
1.1 raeburn 15559: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15560: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15561: $change = 1;
1.132 raeburn 15562: last;
1.1 raeburn 15563: }
15564: }
15565: }
15566: if ($change) {
15567: push(@{$changes{$key}},$item);
15568: }
1.26 raeburn 15569: }
1.1 raeburn 15570: }
15571: }
1.131 raeburn 15572: } elsif ($key eq 'lockablenames') {
15573: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15574: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15575: if (@changed) {
15576: $changes{'lockablenames'} = 1;
15577: }
15578: } else {
15579: if (@lockablenames) {
15580: $changes{'lockablenames'} = 1;
15581: }
15582: }
15583: }
15584: }
15585: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15586: if (@lockablenames) {
15587: $changes{'lockablenames'} = 1;
1.1 raeburn 15588: }
15589: }
1.385 raeburn 15590: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15591: if ($updatehash{'autoupdate'}{'unexpired'}) {
15592: $changes{'unexpired'} = 1;
15593: }
15594: }
15595: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15596: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15597: $changes{'lastactive'} = 1;
15598: }
15599: }
1.26 raeburn 15600: foreach my $item (@{$types},'default') {
15601: if (defined($fields{$item})) {
15602: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15603: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15604: my $change = 0;
15605: if (ref($fields{$item}) eq 'ARRAY') {
15606: foreach my $type (@{$fields{$item}}) {
15607: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15608: $change = 1;
15609: last;
15610: }
15611: }
15612: }
15613: if ($change) {
15614: push(@{$changes{'fields'}},$item);
15615: }
15616: } else {
1.26 raeburn 15617: push(@{$changes{'fields'}},$item);
15618: }
15619: } else {
15620: push(@{$changes{'fields'}},$item);
1.1 raeburn 15621: }
15622: }
15623: }
15624: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15625: $dom);
15626: if ($putresult eq 'ok') {
15627: if (keys(%changes) > 0) {
15628: $resulttext = &mt('Changes made:').'<ul>';
15629: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15630: if ($key eq 'lockablenames') {
15631: $resulttext .= '<li>';
15632: if (@lockablenames) {
15633: $usertypes->{'default'} = $othertitle;
15634: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15635: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15636: } else {
15637: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15638: }
15639: $resulttext .= '</li>';
15640: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15641: foreach my $item (@{$changes{$key}}) {
15642: my @newvalues;
15643: foreach my $type (@{$fields{$item}}) {
15644: push(@newvalues,$fieldtitles{$type});
15645: }
1.3 raeburn 15646: my $newvaluestr;
15647: if (@newvalues > 0) {
15648: $newvaluestr = join(', ',@newvalues);
15649: } else {
15650: $newvaluestr = &mt('none');
1.6 raeburn 15651: }
1.1 raeburn 15652: if ($item eq 'default') {
1.26 raeburn 15653: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15654: } else {
1.26 raeburn 15655: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15656: }
15657: }
15658: } else {
15659: my $newvalue;
15660: if ($key eq 'run') {
15661: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 15662: } elsif ($key eq 'lastactive') {
15663: $newvalue = $offon[$env{'form.lastactive'}];
15664: unless ($lastactivedays eq '') {
15665: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15666: }
1.1 raeburn 15667: } else {
15668: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15669: }
1.1 raeburn 15670: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15671: }
15672: }
15673: $resulttext .= '</ul>';
15674: } else {
1.3 raeburn 15675: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15676: }
15677: } else {
1.11 albertel 15678: $resulttext = '<span class="LC_error">'.
15679: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15680: }
1.3 raeburn 15681: return $resulttext;
1.1 raeburn 15682: }
15683:
1.125 raeburn 15684: sub modify_autocreate {
15685: my ($dom,%domconfig) = @_;
15686: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15687: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15688: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15689: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15690: }
15691: }
15692: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15693: req => 'Auto-creation of validated requests for official courses',
15694: xmldc => 'Identity of course creator of courses from XML files',
15695: );
15696: my @types = ('xml','req');
15697: foreach my $item (@types) {
15698: $newvals{$item} = $env{'form.autocreate_'.$item};
15699: $newvals{$item} =~ s/\D//g;
15700: $newvals{$item} = 0 if ($newvals{$item} eq '');
15701: }
15702: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 15703: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15704: unless (exists($domcoords{$newvals{'xmldc'}})) {
15705: $newvals{'xmldc'} = '';
15706: }
15707: %autocreatehash = (
15708: autocreate => { xml => $newvals{'xml'},
15709: req => $newvals{'req'},
15710: }
15711: );
15712: if ($newvals{'xmldc'} ne '') {
15713: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15714: }
15715: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15716: $dom);
15717: if ($putresult eq 'ok') {
15718: my @items = @types;
15719: if ($newvals{'xml'}) {
15720: push(@items,'xmldc');
15721: }
15722: foreach my $item (@items) {
15723: if (exists($currautocreate{$item})) {
15724: if ($currautocreate{$item} ne $newvals{$item}) {
15725: $changes{$item} = 1;
15726: }
15727: } elsif ($newvals{$item}) {
15728: $changes{$item} = 1;
15729: }
15730: }
15731: if (keys(%changes) > 0) {
15732: my @offon = ('off','on');
15733: $resulttext = &mt('Changes made:').'<ul>';
15734: foreach my $item (@types) {
15735: if ($changes{$item}) {
15736: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 15737: $resulttext .= '<li>'.
15738: &mt("$title{$item} set to [_1]$newtxt [_2]",
15739: '<b>','</b>').
15740: '</li>';
1.125 raeburn 15741: }
15742: }
15743: if ($changes{'xmldc'}) {
15744: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15745: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 15746: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15747: }
15748: $resulttext .= '</ul>';
15749: } else {
15750: $resulttext = &mt('No changes made to auto-creation settings');
15751: }
15752: } else {
15753: $resulttext = '<span class="LC_error">'.
15754: &mt('An error occurred: [_1]',$putresult).'</span>';
15755: }
15756: return $resulttext;
15757: }
15758:
1.23 raeburn 15759: sub modify_directorysrch {
1.295 raeburn 15760: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15761: my ($resulttext,%changes);
15762: my %currdirsrch;
15763: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15764: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15765: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15766: }
15767: }
1.277 raeburn 15768: my %title = ( available => 'Institutional directory search available',
15769: localonly => 'Other domains can search institution',
15770: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 15771: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15772: searchby => 'Search types',
15773: searchtypes => 'Search latitude');
15774: my @offon = ('off','on');
1.24 raeburn 15775: my @otherdoms = ('Yes','No');
1.23 raeburn 15776:
1.25 raeburn 15777: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15778: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15779: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15780:
1.44 raeburn 15781: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15782: if (keys(%{$usertypes}) == 0) {
15783: @cansearch = ('default');
15784: } else {
15785: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15786: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15787: if (!grep(/^\Q$type\E$/,@cansearch)) {
15788: push(@{$changes{'cansearch'}},$type);
15789: }
1.23 raeburn 15790: }
1.26 raeburn 15791: foreach my $type (@cansearch) {
15792: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15793: push(@{$changes{'cansearch'}},$type);
15794: }
1.23 raeburn 15795: }
1.26 raeburn 15796: } else {
15797: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15798: }
15799: }
15800:
15801: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15802: foreach my $by (@{$currdirsrch{'searchby'}}) {
15803: if (!grep(/^\Q$by\E$/,@searchby)) {
15804: push(@{$changes{'searchby'}},$by);
15805: }
15806: }
15807: foreach my $by (@searchby) {
15808: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15809: push(@{$changes{'searchby'}},$by);
15810: }
15811: }
15812: } else {
15813: push(@{$changes{'searchby'}},@searchby);
15814: }
1.25 raeburn 15815:
15816: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15817: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15818: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15819: push(@{$changes{'searchtypes'}},$type);
15820: }
15821: }
15822: foreach my $type (@searchtypes) {
15823: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15824: push(@{$changes{'searchtypes'}},$type);
15825: }
15826: }
15827: } else {
15828: if (exists($currdirsrch{'searchtypes'})) {
15829: foreach my $type (@searchtypes) {
15830: if ($type ne $currdirsrch{'searchtypes'}) {
15831: push(@{$changes{'searchtypes'}},$type);
15832: }
15833: }
15834: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15835: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15836: }
15837: } else {
15838: push(@{$changes{'searchtypes'}},@searchtypes);
15839: }
15840: }
15841:
1.23 raeburn 15842: my %dirsrch_hash = (
15843: directorysrch => { available => $env{'form.dirsrch_available'},
15844: cansearch => \@cansearch,
1.277 raeburn 15845: localonly => $env{'form.dirsrch_instlocalonly'},
15846: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15847: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15848: searchby => \@searchby,
1.25 raeburn 15849: searchtypes => \@searchtypes,
1.23 raeburn 15850: }
15851: );
15852: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15853: $dom);
15854: if ($putresult eq 'ok') {
15855: if (exists($currdirsrch{'available'})) {
15856: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15857: $changes{'available'} = 1;
15858: }
15859: } else {
15860: if ($env{'form.dirsrch_available'} eq '1') {
15861: $changes{'available'} = 1;
15862: }
15863: }
1.277 raeburn 15864: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15865: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15866: $changes{'lcavailable'} = 1;
15867: }
1.277 raeburn 15868: } else {
15869: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15870: $changes{'lcavailable'} = 1;
15871: }
15872: }
1.24 raeburn 15873: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15874: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15875: $changes{'localonly'} = 1;
15876: }
1.24 raeburn 15877: } else {
1.277 raeburn 15878: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15879: $changes{'localonly'} = 1;
15880: }
15881: }
1.277 raeburn 15882: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15883: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15884: $changes{'lclocalonly'} = 1;
15885: }
1.277 raeburn 15886: } else {
15887: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15888: $changes{'lclocalonly'} = 1;
15889: }
15890: }
1.23 raeburn 15891: if (keys(%changes) > 0) {
15892: $resulttext = &mt('Changes made:').'<ul>';
15893: if ($changes{'available'}) {
15894: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15895: }
1.277 raeburn 15896: if ($changes{'lcavailable'}) {
15897: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15898: }
1.24 raeburn 15899: if ($changes{'localonly'}) {
1.277 raeburn 15900: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15901: }
1.277 raeburn 15902: if ($changes{'lclocalonly'}) {
15903: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15904: }
1.23 raeburn 15905: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15906: my $chgtext;
1.26 raeburn 15907: if (ref($usertypes) eq 'HASH') {
15908: if (keys(%{$usertypes}) > 0) {
15909: foreach my $type (@{$types}) {
15910: if (grep(/^\Q$type\E$/,@cansearch)) {
15911: $chgtext .= $usertypes->{$type}.'; ';
15912: }
15913: }
15914: if (grep(/^default$/,@cansearch)) {
15915: $chgtext .= $othertitle;
15916: } else {
15917: $chgtext =~ s/\; $//;
15918: }
1.210 raeburn 15919: $resulttext .=
1.178 raeburn 15920: '<li>'.
15921: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15922: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15923: '</li>';
1.23 raeburn 15924: }
15925: }
15926: }
15927: if (ref($changes{'searchby'}) eq 'ARRAY') {
15928: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15929: my $chgtext;
15930: foreach my $type (@{$titleorder}) {
15931: if (grep(/^\Q$type\E$/,@searchby)) {
15932: if (defined($searchtitles->{$type})) {
15933: $chgtext .= $searchtitles->{$type}.'; ';
15934: }
15935: }
15936: }
15937: $chgtext =~ s/\; $//;
15938: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15939: }
1.25 raeburn 15940: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15941: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15942: my $chgtext;
15943: foreach my $type (@{$srchtypeorder}) {
15944: if (grep(/^\Q$type\E$/,@searchtypes)) {
15945: if (defined($srchtypes_desc->{$type})) {
15946: $chgtext .= $srchtypes_desc->{$type}.'; ';
15947: }
15948: }
15949: }
15950: $chgtext =~ s/\; $//;
1.178 raeburn 15951: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15952: }
15953: $resulttext .= '</ul>';
1.295 raeburn 15954: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15955: if (ref($lastactref) eq 'HASH') {
15956: $lastactref->{'directorysrch'} = 1;
15957: }
1.23 raeburn 15958: } else {
1.277 raeburn 15959: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15960: }
15961: } else {
15962: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15963: &mt('An error occurred: [_1]',$putresult).'</span>';
15964: }
15965: return $resulttext;
15966: }
15967:
1.28 raeburn 15968: sub modify_contacts {
1.205 raeburn 15969: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15970: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15971: if (ref($domconfig{'contacts'}) eq 'HASH') {
15972: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15973: $currsetting{$key} = $domconfig{'contacts'}{$key};
15974: }
15975: }
1.286 raeburn 15976: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15977: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15978: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15979: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15980: my @toggles = ('reporterrors','reportupdates','reportstatus');
15981: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15982: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15983: foreach my $type (@mailings) {
15984: @{$newsetting{$type}} =
15985: &Apache::loncommon::get_env_multiple('form.'.$type);
15986: foreach my $item (@contacts) {
15987: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15988: $contacts_hash{contacts}{$type}{$item} = 1;
15989: } else {
15990: $contacts_hash{contacts}{$type}{$item} = 0;
15991: }
1.289 raeburn 15992: }
1.28 raeburn 15993: $others{$type} = $env{'form.'.$type.'_others'};
15994: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15995: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15996: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15997: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15998: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15999: $includestr{$type} = $env{'form.'.$type.'_includestr'};
16000: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
16001: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16002: }
1.134 raeburn 16003: }
1.28 raeburn 16004: }
16005: foreach my $item (@contacts) {
16006: $to{$item} = $env{'form.'.$item};
16007: $contacts_hash{'contacts'}{$item} = $to{$item};
16008: }
1.203 raeburn 16009: foreach my $item (@toggles) {
16010: if ($env{'form.'.$item} =~ /^(0|1)$/) {
16011: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
16012: }
16013: }
1.340 raeburn 16014: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
16015: foreach my $item (@lonstatus) {
16016: if ($item eq 'excluded') {
16017: my (%serverhomes,@excluded);
16018: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16019: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16020: if (@possexcluded) {
16021: foreach my $id (sort(@possexcluded)) {
16022: if ($serverhomes{$id}) {
16023: push(@excluded,$id);
16024: }
16025: }
16026: }
16027: if (@excluded) {
16028: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16029: }
16030: } elsif ($item eq 'weights') {
1.377 raeburn 16031: foreach my $type ('E','W','N','U') {
1.340 raeburn 16032: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16033: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16034: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16035: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16036: $env{'form.error'.$item.'_'.$type};
16037: }
16038: }
16039: }
16040: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16041: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16042: if ($env{'form.error'.$item} =~ /^\d+$/) {
16043: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16044: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16045: }
16046: }
16047: }
16048: }
1.286 raeburn 16049: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16050: foreach my $field (@{$fields}) {
16051: if (ref($possoptions->{$field}) eq 'ARRAY') {
16052: my $value = $env{'form.helpform_'.$field};
16053: $value =~ s/^\s+|\s+$//g;
16054: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16055: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16056: if ($field eq 'screenshot') {
16057: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16058: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16059: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16060: }
16061: }
16062: }
16063: }
16064: }
16065: }
1.315 raeburn 16066: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16067: my (@statuses,%usertypeshash,@overrides);
16068: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16069: @statuses = @{$types};
16070: if (ref($usertypes) eq 'HASH') {
16071: %usertypeshash = %{$usertypes};
16072: }
16073: }
16074: if (@statuses) {
16075: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16076: foreach my $type (@possoverrides) {
16077: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16078: push(@overrides,$type);
16079: }
16080: }
16081: if (@overrides) {
16082: foreach my $type (@overrides) {
16083: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16084: foreach my $item (@contacts) {
16085: if (grep(/^\Q$item\E$/,@standard)) {
16086: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16087: $newsetting{'override_'.$type}{$item} = 1;
16088: } else {
16089: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16090: $newsetting{'override_'.$type}{$item} = 0;
16091: }
16092: }
16093: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16094: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16095: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16096: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16097: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16098: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16099: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16100: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16101: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16102: }
16103: }
16104: }
16105: }
1.28 raeburn 16106: if (keys(%currsetting) > 0) {
16107: foreach my $item (@contacts) {
16108: if ($to{$item} ne $currsetting{$item}) {
16109: $changes{$item} = 1;
16110: }
16111: }
16112: foreach my $type (@mailings) {
16113: foreach my $item (@contacts) {
16114: if (ref($currsetting{$type}) eq 'HASH') {
16115: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16116: push(@{$changes{$type}},$item);
16117: }
16118: } else {
16119: push(@{$changes{$type}},@{$newsetting{$type}});
16120: }
16121: }
16122: if ($others{$type} ne $currsetting{$type}{'others'}) {
16123: push(@{$changes{$type}},'others');
16124: }
1.289 raeburn 16125: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16126: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16127: push(@{$changes{$type}},'bcc');
16128: }
1.286 raeburn 16129: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16130: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16131: push(@{$changes{$type}},'include');
16132: }
16133: }
16134: }
16135: if (ref($fields) eq 'ARRAY') {
16136: if (ref($currsetting{'helpform'}) eq 'HASH') {
16137: foreach my $field (@{$fields}) {
16138: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16139: push(@{$changes{'helpform'}},$field);
16140: }
16141: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16142: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16143: push(@{$changes{'helpform'}},'maxsize');
16144: }
16145: }
16146: }
16147: } else {
16148: foreach my $field (@{$fields}) {
16149: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16150: push(@{$changes{'helpform'}},$field);
16151: }
16152: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16153: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16154: push(@{$changes{'helpform'}},'maxsize');
16155: }
16156: }
16157: }
1.134 raeburn 16158: }
1.28 raeburn 16159: }
1.315 raeburn 16160: if (@statuses) {
16161: if (ref($currsetting{'overrides'}) eq 'HASH') {
16162: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16163: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16164: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16165: foreach my $item (@contacts,'bcc','others','include') {
16166: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16167: push(@{$changes{'overrides'}},$key);
16168: last;
16169: }
16170: }
16171: } else {
16172: push(@{$changes{'overrides'}},$key);
16173: }
16174: }
16175: }
16176: foreach my $key (@overrides) {
16177: unless (exists($currsetting{'overrides'}{$key})) {
16178: push(@{$changes{'overrides'}},$key);
16179: }
16180: }
16181: } else {
16182: foreach my $key (@overrides) {
16183: push(@{$changes{'overrides'}},$key);
16184: }
16185: }
16186: }
1.340 raeburn 16187: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16188: foreach my $key ('excluded','weights','threshold','sysmail') {
16189: if ($key eq 'excluded') {
16190: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16191: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16192: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16193: (@{$currsetting{'lonstatus'}{$key}})) {
16194: my @diffs =
16195: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16196: $currsetting{'lonstatus'}{$key});
16197: if (@diffs) {
16198: push(@{$changes{'lonstatus'}},$key);
16199: }
16200: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16201: push(@{$changes{'lonstatus'}},$key);
16202: }
16203: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16204: (@{$currsetting{'lonstatus'}{$key}})) {
16205: push(@{$changes{'lonstatus'}},$key);
16206: }
16207: } elsif ($key eq 'weights') {
16208: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16209: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16210: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16211: foreach my $type ('E','W','N','U') {
1.340 raeburn 16212: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16213: $currsetting{'lonstatus'}{$key}{$type}) {
16214: push(@{$changes{'lonstatus'}},$key);
16215: last;
16216: }
16217: }
16218: } else {
1.341 raeburn 16219: foreach my $type ('E','W','N','U') {
1.340 raeburn 16220: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16221: push(@{$changes{'lonstatus'}},$key);
16222: last;
16223: }
16224: }
16225: }
16226: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16227: foreach my $type ('E','W','N','U') {
1.340 raeburn 16228: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16229: push(@{$changes{'lonstatus'}},$key);
16230: last;
16231: }
16232: }
16233: }
16234: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16235: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16236: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16237: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16238: push(@{$changes{'lonstatus'}},$key);
16239: }
16240: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16241: push(@{$changes{'lonstatus'}},$key);
16242: }
16243: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16244: push(@{$changes{'lonstatus'}},$key);
16245: }
16246: }
16247: }
16248: } else {
16249: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16250: foreach my $key ('excluded','weights','threshold','sysmail') {
16251: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16252: push(@{$changes{'lonstatus'}},$key);
16253: }
16254: }
16255: }
16256: }
1.28 raeburn 16257: } else {
16258: my %default;
16259: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16260: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16261: $default{'errormail'} = 'adminemail';
16262: $default{'packagesmail'} = 'adminemail';
16263: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16264: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16265: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16266: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16267: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16268: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16269: foreach my $item (@contacts) {
16270: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16271: $changes{$item} = 1;
1.203 raeburn 16272: }
1.28 raeburn 16273: }
16274: foreach my $type (@mailings) {
16275: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16276: push(@{$changes{$type}},@{$newsetting{$type}});
16277: }
16278: if ($others{$type} ne '') {
16279: push(@{$changes{$type}},'others');
1.134 raeburn 16280: }
1.286 raeburn 16281: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16282: if ($bcc{$type} ne '') {
16283: push(@{$changes{$type}},'bcc');
16284: }
1.286 raeburn 16285: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16286: push(@{$changes{$type}},'include');
16287: }
1.134 raeburn 16288: }
1.28 raeburn 16289: }
1.286 raeburn 16290: if (ref($fields) eq 'ARRAY') {
16291: foreach my $field (@{$fields}) {
16292: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16293: push(@{$changes{'helpform'}},$field);
16294: }
16295: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16296: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16297: push(@{$changes{'helpform'}},'maxsize');
16298: }
16299: }
16300: }
1.289 raeburn 16301: }
1.340 raeburn 16302: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16303: foreach my $key ('excluded','weights','threshold','sysmail') {
16304: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16305: push(@{$changes{'lonstatus'}},$key);
16306: }
16307: }
16308: }
1.28 raeburn 16309: }
1.203 raeburn 16310: foreach my $item (@toggles) {
16311: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16312: $changes{$item} = 1;
16313: } elsif ((!$env{'form.'.$item}) &&
16314: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16315: $changes{$item} = 1;
16316: }
16317: }
1.28 raeburn 16318: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16319: $dom);
16320: if ($putresult eq 'ok') {
16321: if (keys(%changes) > 0) {
1.205 raeburn 16322: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16323: if (ref($lastactref) eq 'HASH') {
16324: $lastactref->{'domainconfig'} = 1;
16325: }
1.28 raeburn 16326: my ($titles,$short_titles) = &contact_titles();
16327: $resulttext = &mt('Changes made:').'<ul>';
16328: foreach my $item (@contacts) {
16329: if ($changes{$item}) {
16330: $resulttext .= '<li>'.$titles->{$item}.
16331: &mt(' set to: ').
16332: '<span class="LC_cusr_emph">'.
16333: $to{$item}.'</span></li>';
16334: }
16335: }
16336: foreach my $type (@mailings) {
16337: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16338: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16339: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16340: } else {
16341: $resulttext .= '<li>'.$titles->{$type}.': ';
16342: }
1.28 raeburn 16343: my @text;
16344: foreach my $item (@{$newsetting{$type}}) {
16345: push(@text,$short_titles->{$item});
16346: }
16347: if ($others{$type} ne '') {
16348: push(@text,$others{$type});
16349: }
1.286 raeburn 16350: if (@text) {
16351: $resulttext .= '<span class="LC_cusr_emph">'.
16352: join(', ',@text).'</span>';
16353: }
16354: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16355: if ($bcc{$type} ne '') {
1.286 raeburn 16356: my $bcctext;
16357: if (@text) {
1.289 raeburn 16358: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16359: } else {
16360: $bcctext = '(Bcc)';
16361: }
16362: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16363: } elsif (!@text) {
16364: $resulttext .= &mt('No one');
16365: }
1.289 raeburn 16366: if ($includestr{$type} ne '') {
1.286 raeburn 16367: if ($includeloc{$type} eq 'b') {
16368: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16369: } elsif ($includeloc{$type} eq 's') {
16370: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16371: }
1.134 raeburn 16372: }
1.286 raeburn 16373: } elsif (!@text) {
16374: $resulttext .= &mt('No recipients');
1.134 raeburn 16375: }
16376: $resulttext .= '</li>';
1.28 raeburn 16377: }
16378: }
1.315 raeburn 16379: if (ref($changes{'overrides'}) eq 'ARRAY') {
16380: my @deletions;
16381: foreach my $type (@{$changes{'overrides'}}) {
16382: if ($usertypeshash{$type}) {
16383: if (grep(/^\Q$type\E/,@overrides)) {
16384: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16385: $usertypeshash{$type}).'<ul><li>';
16386: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16387: my @text;
16388: foreach my $item (@contacts) {
16389: if ($newsetting{'override_'.$type}{$item}) {
16390: push(@text,$short_titles->{$item});
16391: }
16392: }
16393: if ($newsetting{'override_'.$type}{'others'} ne '') {
16394: push(@text,$newsetting{'override_'.$type}{'others'});
16395: }
16396:
16397: if (@text) {
16398: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16399: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16400: }
16401: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16402: my $bcctext;
16403: if (@text) {
16404: $bcctext = ' '.&mt('with Bcc to');
16405: } else {
16406: $bcctext = '(Bcc)';
16407: }
16408: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16409: } elsif (!@text) {
16410: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16411: }
16412: $resulttext .= '</li>';
16413: if ($newsetting{'override_'.$type}{'include'} ne '') {
16414: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16415: if ($loc eq 'b') {
16416: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16417: } elsif ($loc eq 's') {
16418: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16419: }
16420: }
16421: }
16422: $resulttext .= '</li></ul></li>';
16423: } else {
16424: push(@deletions,$usertypeshash{$type});
16425: }
16426: }
16427: }
16428: if (@deletions) {
16429: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16430: join(', ',@deletions)).'</li>';
16431: }
16432: }
1.203 raeburn 16433: my @offon = ('off','on');
1.340 raeburn 16434: my $corelink = &core_link_msu();
1.203 raeburn 16435: if ($changes{'reporterrors'}) {
16436: $resulttext .= '<li>'.
16437: &mt('E-mail error reports to [_1] set to "'.
16438: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16439: $corelink).
1.203 raeburn 16440: '</li>';
16441: }
16442: if ($changes{'reportupdates'}) {
16443: $resulttext .= '<li>'.
16444: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16445: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16446: $corelink).
1.203 raeburn 16447: '</li>';
16448: }
1.340 raeburn 16449: if ($changes{'reportstatus'}) {
16450: $resulttext .= '<li>'.
16451: &mt('E-mail status if errors above threshold to [_1] set to "'.
16452: $offon[$env{'form.reportstatus'}].'".',
16453: $corelink).
16454: '</li>';
16455: }
16456: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16457: $resulttext .= '<li>'.
16458: &mt('Nightly status check e-mail settings').':<ul>';
16459: my (%defval,%use_def,%shown);
16460: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
16461: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
16462: $defval{'weights'} =
1.341 raeburn 16463: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 16464: $defval{'excluded'} = &mt('None');
16465: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
16466: foreach my $item ('threshold','sysmail','weights','excluded') {
16467: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
16468: if (($item eq 'threshold') || ($item eq 'sysmail')) {
16469: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
16470: } elsif ($item eq 'weights') {
16471: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 16472: foreach my $type ('E','W','N','U') {
1.340 raeburn 16473: $shown{$item} .= $lonstatus_names->{$type}.'=';
16474: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
16475: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
16476: } else {
16477: $shown{$item} .= $lonstatus_defs->{$type};
16478: }
16479: $shown{$item} .= ', ';
16480: }
16481: $shown{$item} =~ s/, $//;
16482: } else {
16483: $shown{$item} = $defval{$item};
16484: }
16485: } elsif ($item eq 'excluded') {
16486: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
16487: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
16488: } else {
16489: $shown{$item} = $defval{$item};
16490: }
16491: }
16492: } else {
16493: $shown{$item} = $defval{$item};
16494: }
16495: }
16496: } else {
16497: foreach my $item ('threshold','weights','excluded','sysmail') {
16498: $shown{$item} = $defval{$item};
16499: }
16500: }
16501: foreach my $item ('threshold','weights','excluded','sysmail') {
16502: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
16503: $shown{$item}).'</li>';
16504: }
16505: $resulttext .= '</ul></li>';
16506: }
1.286 raeburn 16507: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
16508: my (@optional,@required,@unused,$maxsizechg);
16509: foreach my $field (@{$changes{'helpform'}}) {
16510: if ($field eq 'maxsize') {
16511: $maxsizechg = 1;
16512: next;
16513: }
16514: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 16515: push(@optional,$field);
1.286 raeburn 16516: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
16517: push(@unused,$field);
16518: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 16519: push(@required,$field);
1.286 raeburn 16520: }
16521: }
16522: if (@optional) {
16523: $resulttext .= '<li>'.
16524: &mt('Help form fields changed to "Optional": [_1].',
16525: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
16526: '</li>';
16527: }
16528: if (@required) {
16529: $resulttext .= '<li>'.
16530: &mt('Help form fields changed to "Required": [_1].',
16531: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
16532: '</li>';
16533: }
16534: if (@unused) {
16535: $resulttext .= '<li>'.
16536: &mt('Help form fields changed to "Not shown": [_1].',
16537: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
16538: '</li>';
16539: }
16540: if ($maxsizechg) {
16541: $resulttext .= '<li>'.
16542: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
16543: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
16544: '</li>';
16545: }
16546: }
1.28 raeburn 16547: $resulttext .= '</ul>';
16548: } else {
1.288 raeburn 16549: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 16550: }
16551: } else {
16552: $resulttext = '<span class="LC_error">'.
16553: &mt('An error occurred: [_1].',$putresult).'</span>';
16554: }
16555: return $resulttext;
16556: }
16557:
1.357 raeburn 16558: sub modify_privacy {
16559: my ($dom,%domconfig) = @_;
16560: my ($resulttext,%current,%changes);
16561: if (ref($domconfig{'privacy'}) eq 'HASH') {
16562: %current = %{$domconfig{'privacy'}};
16563: }
16564: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
16565: my @items = ('domain','author','course','community');
16566: my %names = &Apache::lonlocal::texthash (
16567: domain => 'Assigned domain role(s)',
16568: author => 'Assigned co-author role(s)',
16569: course => 'Assigned course role(s)',
16570: community => 'Assigned community role',
16571: );
16572: my %roles = &Apache::lonlocal::texthash (
16573: domain => 'Domain role',
16574: author => 'Co-author role',
16575: course => 'Course role',
16576: community => 'Community role',
16577: );
16578: my %titles = &Apache::lonlocal::texthash (
16579: approval => 'Approval for role in different domain',
16580: othdom => 'User information available in other domain',
16581: priv => 'Information viewable by privileged user in same domain',
16582: unpriv => 'Information viewable by unprivileged user in same domain',
16583: instdom => 'Other domain shares institution/provider',
16584: extdom => 'Other domain has different institution/provider',
16585: none => 'Not allowed',
16586: user => 'User authorizes',
16587: domain => 'Domain Coordinator authorizes',
16588: auto => 'Unrestricted',
16589: );
16590: my %fieldnames = &Apache::lonlocal::texthash (
16591: id => 'Student/Employee ID',
16592: permanentemail => 'E-mail address',
16593: lastname => 'Last Name',
16594: firstname => 'First Name',
16595: middlename => 'Middle Name',
16596: generation => 'Generation',
16597: );
16598: my ($othertitle,$usertypes,$types) =
16599: &Apache::loncommon::sorted_inst_types($dom);
16600: my (%by_ip,%by_location,@intdoms,@instdoms);
16601: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16602:
16603: my %privacyhash = (
16604: 'approval' => {
16605: instdom => {},
16606: extdom => {},
16607: },
16608: 'othdom' => {},
16609: 'priv' => {},
16610: 'unpriv' => {},
16611: );
16612: foreach my $item (@items) {
16613: if (@instdoms > 1) {
16614: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
16615: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
16616: }
16617: if (ref($current{'approval'}) eq 'HASH') {
16618: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
16619: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
16620: $changes{'approval'} = 1;
16621: }
16622: }
16623: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
16624: $changes{'approval'} = 1;
16625: }
16626: }
16627: if (keys(%by_location) > 0) {
16628: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
16629: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
16630: }
16631: if (ref($current{'approval'}) eq 'HASH') {
16632: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
16633: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
16634: $changes{'approval'} = 1;
16635: }
16636: }
16637: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
16638: $changes{'approval'} = 1;
16639: }
16640: }
16641: foreach my $status ('priv','unpriv') {
16642: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
16643: my @newvalues;
16644: foreach my $field (@possibles) {
16645: if (grep(/^\Q$field\E$/,@fields)) {
16646: $privacyhash{$status}{$item}{$field} = 1;
16647: push(@newvalues,$field);
16648: }
16649: }
16650: @newvalues = sort(@newvalues);
16651: if (ref($current{$status}) eq 'HASH') {
16652: if (ref($current{$status}{$item}) eq 'HASH') {
16653: my @currvalues = sort(keys(%{$current{$status}{$item}}));
16654: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16655: if (@diffs > 0) {
16656: $changes{$status} = 1;
16657: }
16658: }
16659: } else {
16660: my @stdfields;
16661: foreach my $field (@fields) {
16662: if ($field eq 'id') {
16663: next if ($status eq 'unpriv');
16664: next if (($status eq 'priv') && ($item eq 'community'));
16665: }
16666: push(@stdfields,$field);
16667: }
16668: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16669: if (@diffs > 0) {
16670: $changes{$status} = 1;
16671: }
16672: }
16673: }
16674: }
16675: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
16676: my @statuses;
16677: if (ref($types) eq 'ARRAY') {
16678: @statuses = @{$types};
16679: }
16680: foreach my $type (@statuses,'default') {
16681: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
16682: my @newvalues;
16683: foreach my $field (sort(@possfields)) {
16684: if (grep(/^\Q$field\E$/,@fields)) {
16685: $privacyhash{'othdom'}{$type}{$field} = 1;
16686: push(@newvalues,$field);
16687: }
16688: }
16689: @newvalues = sort(@newvalues);
16690: if (ref($current{'othdom'}) eq 'HASH') {
16691: if (ref($current{'othdom'}{$type}) eq 'HASH') {
16692: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
16693: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16694: if (@diffs > 0) {
16695: $changes{'othdom'} = 1;
16696: }
16697: }
16698: } else {
16699: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
16700: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16701: if (@diffs > 0) {
16702: $changes{'othdom'} = 1;
16703: }
16704: }
16705: }
16706: }
16707: my %confighash = (
16708: privacy => \%privacyhash,
16709: );
16710: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16711: if ($putresult eq 'ok') {
16712: if (keys(%changes) > 0) {
16713: $resulttext = &mt('Changes made: ').'<ul>';
16714: foreach my $key ('approval','othdom','priv','unpriv') {
16715: if ($changes{$key}) {
16716: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16717: if ($key eq 'approval') {
16718: if (keys(%{$privacyhash{$key}{instdom}})) {
16719: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
16720: foreach my $item (@items) {
16721: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
16722: }
16723: $resulttext .= '</ul></li>';
16724: }
16725: if (keys(%{$privacyhash{$key}{extdom}})) {
16726: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
16727: foreach my $item (@items) {
16728: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
16729: }
16730: $resulttext .= '</ul></li>';
16731: }
16732: } elsif ($key eq 'othdom') {
16733: my @statuses;
16734: if (ref($types) eq 'ARRAY') {
16735: @statuses = @{$types};
16736: }
16737: if (ref($privacyhash{$key}) eq 'HASH') {
16738: foreach my $status (@statuses,'default') {
16739: if ($status eq 'default') {
16740: $resulttext .= '<li>'.$othertitle.': ';
16741: } elsif (ref($usertypes) eq 'HASH') {
16742: $resulttext .= '<li>'.$usertypes->{$status}.': ';
16743: } else {
16744: next;
16745: }
16746: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
16747: if (keys(%{$privacyhash{$key}{$status}})) {
16748: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
16749: } else {
16750: $resulttext .= &mt('none');
16751: }
16752: }
16753: $resulttext .= '</li>';
16754: }
16755: }
16756: } else {
16757: foreach my $item (@items) {
16758: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
16759: $resulttext .= '<li>'.$names{$item}.': ';
16760: if (keys(%{$privacyhash{$key}{$item}})) {
16761: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
16762: } else {
16763: $resulttext .= &mt('none');
16764: }
16765: $resulttext .= '</li>';
16766: }
16767: }
16768: }
16769: $resulttext .= '</ul></li>';
16770: }
16771: }
16772: } else {
16773: $resulttext = &mt('No changes made to user information settings');
16774: }
16775: } else {
16776: $resulttext = '<span class="LC_error">'.
16777: &mt('An error occurred: [_1]',$putresult).'</span>';
16778: }
16779: return $resulttext;
16780: }
16781:
1.354 raeburn 16782: sub modify_passwords {
16783: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 16784: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
16785: $updatedefaults,$updateconf);
1.354 raeburn 16786: my $customfn = 'resetpw.html';
16787: if (ref($domconfig{'passwords'}) eq 'HASH') {
16788: %current = %{$domconfig{'passwords'}};
16789: }
16790: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16791: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16792: if (ref($types) eq 'ARRAY') {
16793: @oktypes = @{$types};
16794: }
16795: push(@oktypes,'default');
16796:
16797: my %titles = &Apache::lonlocal::texthash (
16798: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
16799: intauth_check => 'Check bcrypt cost if authenticated',
16800: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16801: permanent => 'Permanent e-mail address',
16802: critical => 'Critical notification address',
16803: notify => 'Notification address',
16804: min => 'Minimum password length',
16805: max => 'Maximum password length',
16806: chars => 'Required characters',
16807: expire => 'Password expiration (days)',
1.356 raeburn 16808: numsaved => 'Number of previous passwords to save',
1.354 raeburn 16809: reset => 'Resetting Forgotten Password',
16810: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16811: rules => 'Rules for LON-CAPA Passwords',
16812: crsownerchg => 'Course Owner Changing Student Passwords',
16813: username => 'Username',
16814: email => 'E-mail address',
16815: );
16816:
16817: #
16818: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16819: #
16820: my (%curr_defaults,%save_defaults);
16821: if (ref($domconfig{'defaults'}) eq 'HASH') {
16822: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16823: if ($key =~ /^intauth_(cost|check|switch)$/) {
16824: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16825: } else {
16826: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16827: }
16828: }
16829: }
16830: my %staticdefaults = (
16831: 'resetlink' => 2,
16832: 'resetcase' => \@oktypes,
16833: 'resetprelink' => 'both',
16834: 'resetemail' => ['critical','notify','permanent'],
16835: 'intauth_cost' => 10,
16836: 'intauth_check' => 0,
16837: 'intauth_switch' => 0,
16838: );
1.365 raeburn 16839: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16840: foreach my $type (@oktypes) {
16841: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16842: }
16843: my $linklife = $env{'form.passwords_link'};
16844: $linklife =~ s/^\s+|\s+$//g;
16845: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16846: $newvalues{'resetlink'} = $linklife;
16847: if ($current{'resetlink'}) {
16848: if ($current{'resetlink'} ne $linklife) {
16849: $changes{'reset'} = 1;
16850: }
1.368 raeburn 16851: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16852: if ($staticdefaults{'resetlink'} ne $linklife) {
16853: $changes{'reset'} = 1;
16854: }
16855: }
16856: } elsif ($current{'resetlink'}) {
16857: $changes{'reset'} = 1;
16858: }
16859: my @casesens;
16860: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16861: foreach my $case (sort(@posscase)) {
16862: if (grep(/^\Q$case\E$/,@oktypes)) {
16863: push(@casesens,$case);
16864: }
16865: }
16866: $newvalues{'resetcase'} = \@casesens;
16867: if (ref($current{'resetcase'}) eq 'ARRAY') {
16868: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16869: if (@diffs > 0) {
16870: $changes{'reset'} = 1;
16871: }
1.368 raeburn 16872: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16873: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16874: if (@diffs > 0) {
16875: $changes{'reset'} = 1;
16876: }
16877: }
16878: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16879: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16880: if (exists($current{'resetprelink'})) {
16881: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16882: $changes{'reset'} = 1;
16883: }
1.368 raeburn 16884: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16885: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16886: $changes{'reset'} = 1;
16887: }
16888: }
16889: } elsif ($current{'resetprelink'}) {
16890: $changes{'reset'} = 1;
16891: }
16892: foreach my $type (@oktypes) {
16893: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16894: my @postlink;
16895: foreach my $item (sort(@possplink)) {
16896: if ($item =~ /^(email|username)$/) {
16897: push(@postlink,$item);
16898: }
16899: }
16900: $newvalues{'resetpostlink'}{$type} = \@postlink;
16901: unless ($changes{'reset'}) {
16902: if (ref($current{'resetpostlink'}) eq 'HASH') {
16903: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16904: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16905: if (@diffs > 0) {
16906: $changes{'reset'} = 1;
16907: }
16908: } else {
16909: $changes{'reset'} = 1;
16910: }
1.368 raeburn 16911: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16912: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16913: if (@diffs > 0) {
16914: $changes{'reset'} = 1;
16915: }
16916: }
16917: }
16918: }
16919: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16920: my @resetemail;
16921: foreach my $item (sort(@possemailsrc)) {
16922: if ($item =~ /^(permanent|critical|notify)$/) {
16923: push(@resetemail,$item);
16924: }
16925: }
16926: $newvalues{'resetemail'} = \@resetemail;
16927: unless ($changes{'reset'}) {
16928: if (ref($current{'resetemail'}) eq 'ARRAY') {
16929: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16930: if (@diffs > 0) {
16931: $changes{'reset'} = 1;
16932: }
1.368 raeburn 16933: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16934: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16935: if (@diffs > 0) {
16936: $changes{'reset'} = 1;
16937: }
16938: }
16939: }
16940: if ($env{'form.passwords_stdtext'} == 0) {
16941: $newvalues{'resetremove'} = 1;
16942: unless ($current{'resetremove'}) {
16943: $changes{'reset'} = 1;
16944: }
16945: } elsif ($current{'resetremove'}) {
16946: $changes{'reset'} = 1;
16947: }
16948: if ($env{'form.passwords_customfile.filename'} ne '') {
16949: my $servadm = $r->dir_config('lonAdmEMail');
16950: my ($configuserok,$author_ok,$switchserver) =
16951: &config_check($dom,$confname,$servadm);
16952: my $error;
16953: if ($configuserok eq 'ok') {
16954: if ($switchserver) {
16955: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16956: } else {
16957: if ($author_ok eq 'ok') {
16958: my ($result,$customurl) =
16959: &publishlogo($r,'upload','passwords_customfile',$dom,
16960: $confname,'customtext/resetpw','','',$customfn);
16961: if ($result eq 'ok') {
16962: $newvalues{'resetcustom'} = $customurl;
16963: $changes{'reset'} = 1;
16964: } else {
16965: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16966: }
16967: } else {
16968: $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);
16969: }
16970: }
16971: } else {
16972: $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);
16973: }
16974: if ($error) {
16975: &Apache::lonnet::logthis($error);
16976: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16977: }
16978: } elsif ($current{'resetcustom'}) {
16979: if ($env{'form.passwords_custom_del'}) {
16980: $changes{'reset'} = 1;
16981: } else {
16982: $newvalues{'resetcustom'} = $current{'resetcustom'};
16983: }
16984: }
16985: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16986: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16987: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16988: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16989: $changes{'intauth'} = 1;
16990: }
16991: } else {
16992: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16993: }
16994: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16995: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16996: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16997: $changes{'intauth'} = 1;
16998: }
16999: } else {
17000: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17001: }
17002: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
17003: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
17004: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
17005: $changes{'intauth'} = 1;
17006: }
17007: } else {
17008: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17009: }
17010: foreach my $item ('cost','check','switch') {
17011: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
17012: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
17013: $updatedefaults = 1;
17014: }
17015: }
1.356 raeburn 17016: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17017: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 17018: my $ruleok;
17019: if ($rule eq 'expire') {
1.365 raeburn 17020: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17021: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 17022: $ruleok = 1;
1.356 raeburn 17023: }
1.365 raeburn 17024: } elsif ($rule eq 'min') {
17025: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
17026: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
17027: $ruleok = 1;
17028: }
17029: }
17030: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
17031: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 17032: $ruleok = 1;
17033: }
17034: if ($ruleok) {
1.354 raeburn 17035: $newvalues{$rule} = $env{'form.passwords_'.$rule};
17036: if (exists($current{$rule})) {
17037: if ($newvalues{$rule} ne $current{$rule}) {
17038: $changes{'rules'} = 1;
17039: }
17040: } elsif ($rule eq 'min') {
17041: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
17042: $changes{'rules'} = 1;
17043: }
1.370 raeburn 17044: } else {
17045: $changes{'rules'} = 1;
1.354 raeburn 17046: }
17047: } elsif (exists($current{$rule})) {
17048: $changes{'rules'} = 1;
17049: }
17050: }
17051: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
17052: my @chars;
17053: foreach my $item (sort(@posschars)) {
17054: if ($item =~ /^(uc|lc|num|spec)$/) {
17055: push(@chars,$item);
17056: }
17057: }
17058: $newvalues{'chars'} = \@chars;
17059: unless ($changes{'rules'}) {
17060: if (ref($current{'chars'}) eq 'ARRAY') {
17061: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
17062: if (@diffs > 0) {
17063: $changes{'rules'} = 1;
17064: }
17065: } else {
17066: if (@chars > 0) {
17067: $changes{'rules'} = 1;
17068: }
17069: }
17070: }
1.359 raeburn 17071: my %crsownerchg = (
17072: by => [],
17073: for => [],
17074: );
17075: foreach my $item ('by','for') {
17076: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17077: foreach my $type (sort(@posstypes)) {
17078: if (grep(/^\Q$type\E$/,@oktypes)) {
17079: push(@{$crsownerchg{$item}},$type);
17080: }
17081: }
17082: }
17083: $newvalues{'crsownerchg'} = \%crsownerchg;
17084: if (ref($current{'crsownerchg'}) eq 'HASH') {
17085: foreach my $item ('by','for') {
17086: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17087: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17088: if (@diffs > 0) {
17089: $changes{'crsownerchg'} = 1;
17090: last;
17091: }
17092: }
17093: }
1.368 raeburn 17094: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17095: foreach my $item ('by','for') {
17096: if (@{$crsownerchg{$item}} > 0) {
17097: $changes{'crsownerchg'} = 1;
17098: last;
17099: }
1.354 raeburn 17100: }
17101: }
17102:
17103: my %confighash = (
17104: defaults => \%save_defaults,
17105: passwords => \%newvalues,
17106: );
17107: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17108:
17109: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17110: if ($putresult eq 'ok') {
17111: if (keys(%changes) > 0) {
17112: $resulttext = &mt('Changes made: ').'<ul>';
17113: foreach my $key ('reset','intauth','rules','crsownerchg') {
17114: if ($changes{$key}) {
1.355 raeburn 17115: unless ($key eq 'intauth') {
17116: $updateconf = 1;
17117: }
1.354 raeburn 17118: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17119: if ($key eq 'reset') {
17120: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17121: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17122: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17123: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17124: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17125: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17126: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17127: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17128: }
1.354 raeburn 17129: } else {
17130: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17131: }
17132: if ($confighash{'passwords'}{'resetlink'}) {
17133: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17134: } else {
17135: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17136: &mt('Will default to 2 hours').'</li>';
17137: }
17138: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17139: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17140: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17141: } else {
17142: my $casesens;
17143: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17144: if ($type eq 'default') {
17145: $casesens .= $othertitle.', ';
17146: } elsif ($usertypes->{$type} ne '') {
17147: $casesens .= $usertypes->{$type}.', ';
17148: }
17149: }
17150: $casesens =~ s/\Q, \E$//;
17151: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17152: }
17153: } else {
17154: $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>';
17155: }
17156: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17157: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17158: } else {
17159: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17160: }
17161: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17162: my $output;
17163: if (ref($types) eq 'ARRAY') {
17164: foreach my $type (@{$types}) {
17165: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17166: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17167: $output .= $usertypes->{$type}.' -- '.&mt('none');
17168: } else {
17169: $output .= $usertypes->{$type}.' -- '.
17170: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17171: }
17172: }
17173: }
17174: }
17175: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17176: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17177: $output .= $othertitle.' -- '.&mt('none');
17178: } else {
17179: $output .= $othertitle.' -- '.
17180: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17181: }
17182: }
17183: if ($output) {
17184: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17185: } else {
17186: $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>';
17187: }
17188: } else {
17189: $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>';
17190: }
17191: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17192: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17193: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17194: } else {
17195: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17196: }
17197: } else {
1.379 raeburn 17198: $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 17199: }
17200: if ($confighash{'passwords'}{'resetremove'}) {
17201: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17202: } else {
17203: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17204: }
17205: if ($confighash{'passwords'}{'resetcustom'}) {
17206: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17207: &mt('custom text'),600,500,undef,undef,
17208: undef,undef,'background-color:#ffffff');
17209: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17210: } else {
17211: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17212: }
17213: } elsif ($key eq 'intauth') {
17214: foreach my $item ('cost','switch','check') {
17215: my $value = $save_defaults{$key.'_'.$item};
17216: if ($item eq 'switch') {
17217: my %optiondesc = &Apache::lonlocal::texthash (
17218: 0 => 'No',
17219: 1 => 'Yes',
17220: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17221: );
17222: if ($value =~ /^(0|1|2)$/) {
17223: $value = $optiondesc{$value};
17224: } else {
17225: $value = &mt('none -- defaults to No');
17226: }
17227: } elsif ($item eq 'check') {
17228: my %optiondesc = &Apache::lonlocal::texthash (
17229: 0 => 'No',
17230: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17231: 2 => 'Yes, disallow login if stored cost is less than domain default',
17232: );
17233: if ($value =~ /^(0|1|2)$/) {
17234: $value = $optiondesc{$value};
17235: } else {
17236: $value = &mt('none -- defaults to No');
17237: }
17238: }
17239: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17240: }
17241: } elsif ($key eq 'rules') {
1.356 raeburn 17242: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17243: if ($confighash{'passwords'}{$rule} eq '') {
17244: if ($rule eq 'min') {
1.356 raeburn 17245: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17246: ' '.&mt('Default of [_1] will be used',
17247: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17248: } else {
17249: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17250: }
17251: } else {
17252: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17253: }
17254: }
1.370 raeburn 17255: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17256: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17257: my %rulenames = &Apache::lonlocal::texthash(
17258: uc => 'At least one upper case letter',
17259: lc => 'At least one lower case letter',
17260: num => 'At least one number',
17261: spec => 'At least one non-alphanumeric',
17262: );
17263: my $needed = '<ul><li>'.
17264: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17265: '</li></ul>';
17266: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17267: } else {
17268: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17269: }
17270: } else {
17271: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17272: }
1.354 raeburn 17273: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17274: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17275: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17276: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17277: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17278: } else {
17279: my %crsownerstr;
17280: foreach my $item ('by','for') {
17281: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17282: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17283: if ($type eq 'default') {
17284: $crsownerstr{$item} .= $othertitle.', ';
17285: } elsif ($usertypes->{$type} ne '') {
17286: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17287: }
17288: }
17289: $crsownerstr{$item} =~ s/\Q, \E$//;
17290: }
17291: }
17292: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17293: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17294: }
1.354 raeburn 17295: } else {
1.359 raeburn 17296: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17297: }
17298: }
17299: $resulttext .= '</ul></li>';
17300: }
17301: }
17302: $resulttext .= '</ul>';
17303: } else {
17304: $resulttext = &mt('No changes made to password settings');
17305: }
1.355 raeburn 17306: my $cachetime = 24*60*60;
1.354 raeburn 17307: if ($updatedefaults) {
17308: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17309: if (ref($lastactref) eq 'HASH') {
17310: $lastactref->{'domdefaults'} = 1;
17311: }
17312: }
1.355 raeburn 17313: if ($updateconf) {
17314: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17315: if (ref($lastactref) eq 'HASH') {
17316: $lastactref->{'passwdconf'} = 1;
17317: }
17318: }
1.354 raeburn 17319: } else {
17320: $resulttext = '<span class="LC_error">'.
17321: &mt('An error occurred: [_1]',$putresult).'</span>';
17322: }
17323: if ($errors) {
17324: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17325: $errors.'</ul></p>';
17326: }
17327: return $resulttext;
17328: }
17329:
1.28 raeburn 17330: sub modify_usercreation {
1.27 raeburn 17331: my ($dom,%domconfig) = @_;
1.224 raeburn 17332: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17333: my $warningmsg;
1.27 raeburn 17334: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17335: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17336: if ($key eq 'cancreate') {
17337: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17338: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17339: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17340: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17341: } else {
1.224 raeburn 17342: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17343: }
17344: }
17345: }
17346: } elsif ($key eq 'email_rule') {
17347: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17348: } else {
17349: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17350: }
1.27 raeburn 17351: }
17352: }
17353: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17354: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17355: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17356: foreach my $item(@contexts) {
1.224 raeburn 17357: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17358: }
1.34 raeburn 17359: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17360: foreach my $item (@contexts) {
1.224 raeburn 17361: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17362: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17363: }
1.27 raeburn 17364: }
1.34 raeburn 17365: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17366: foreach my $item (@contexts) {
1.43 raeburn 17367: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17368: if ($cancreate{$item} ne 'any') {
17369: push(@{$changes{'cancreate'}},$item);
17370: }
17371: } else {
17372: if ($cancreate{$item} ne 'none') {
17373: push(@{$changes{'cancreate'}},$item);
17374: }
1.27 raeburn 17375: }
17376: }
17377: } else {
1.43 raeburn 17378: foreach my $item (@contexts) {
1.34 raeburn 17379: push(@{$changes{'cancreate'}},$item);
17380: }
1.27 raeburn 17381: }
1.34 raeburn 17382:
1.27 raeburn 17383: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17384: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17385: if (!grep(/^\Q$type\E$/,@username_rule)) {
17386: push(@{$changes{'username_rule'}},$type);
17387: }
17388: }
17389: foreach my $type (@username_rule) {
17390: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17391: push(@{$changes{'username_rule'}},$type);
17392: }
17393: }
17394: } else {
17395: push(@{$changes{'username_rule'}},@username_rule);
17396: }
17397:
1.32 raeburn 17398: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17399: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17400: if (!grep(/^\Q$type\E$/,@id_rule)) {
17401: push(@{$changes{'id_rule'}},$type);
17402: }
17403: }
17404: foreach my $type (@id_rule) {
17405: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17406: push(@{$changes{'id_rule'}},$type);
17407: }
17408: }
17409: } else {
17410: push(@{$changes{'id_rule'}},@id_rule);
17411: }
17412:
1.43 raeburn 17413: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17414: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17415: my %authhash;
1.43 raeburn 17416: foreach my $item (@authen_contexts) {
1.28 raeburn 17417: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17418: foreach my $auth (@authtypes) {
17419: if (grep(/^\Q$auth\E$/,@authallowed)) {
17420: $authhash{$item}{$auth} = 1;
17421: } else {
17422: $authhash{$item}{$auth} = 0;
17423: }
17424: }
17425: }
17426: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17427: foreach my $item (@authen_contexts) {
1.28 raeburn 17428: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17429: foreach my $auth (@authtypes) {
17430: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17431: push(@{$changes{'authtypes'}},$item);
17432: last;
17433: }
17434: }
17435: }
17436: }
17437: } else {
1.43 raeburn 17438: foreach my $item (@authen_contexts) {
1.28 raeburn 17439: push(@{$changes{'authtypes'}},$item);
17440: }
17441: }
17442:
1.224 raeburn 17443: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17444: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17445: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17446: $save_usercreate{'id_rule'} = \@id_rule;
17447: $save_usercreate{'username_rule'} = \@username_rule,
17448: $save_usercreate{'authtypes'} = \%authhash;
17449:
1.27 raeburn 17450: my %usercreation_hash = (
1.224 raeburn 17451: usercreation => \%save_usercreate,
17452: );
1.27 raeburn 17453:
17454: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17455: $dom);
1.50 raeburn 17456:
1.224 raeburn 17457: if ($putresult eq 'ok') {
17458: if (keys(%changes) > 0) {
17459: $resulttext = &mt('Changes made:').'<ul>';
17460: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17461: my %lt = &usercreation_types();
17462: foreach my $type (@{$changes{'cancreate'}}) {
17463: my $chgtext = $lt{$type}.', ';
17464: if ($cancreate{$type} eq 'none') {
17465: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
17466: } elsif ($cancreate{$type} eq 'any') {
17467: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
17468: } elsif ($cancreate{$type} eq 'official') {
17469: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
17470: } elsif ($cancreate{$type} eq 'unofficial') {
17471: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
17472: }
17473: $resulttext .= '<li>'.$chgtext.'</li>';
17474: }
17475: }
17476: if (ref($changes{'username_rule'}) eq 'ARRAY') {
17477: my ($rules,$ruleorder) =
17478: &Apache::lonnet::inst_userrules($dom,'username');
17479: my $chgtext = '<ul>';
17480: foreach my $type (@username_rule) {
17481: if (ref($rules->{$type}) eq 'HASH') {
17482: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
17483: }
17484: }
17485: $chgtext .= '</ul>';
17486: if (@username_rule > 0) {
17487: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17488: } else {
17489: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
17490: }
17491: }
17492: if (ref($changes{'id_rule'}) eq 'ARRAY') {
17493: my ($idrules,$idruleorder) =
17494: &Apache::lonnet::inst_userrules($dom,'id');
17495: my $chgtext = '<ul>';
17496: foreach my $type (@id_rule) {
17497: if (ref($idrules->{$type}) eq 'HASH') {
17498: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
17499: }
17500: }
17501: $chgtext .= '</ul>';
17502: if (@id_rule > 0) {
17503: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17504: } else {
17505: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
17506: }
17507: }
17508: my %authname = &authtype_names();
17509: my %context_title = &context_names();
17510: if (ref($changes{'authtypes'}) eq 'ARRAY') {
17511: my $chgtext = '<ul>';
17512: foreach my $type (@{$changes{'authtypes'}}) {
17513: my @allowed;
17514: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
17515: foreach my $auth (@authtypes) {
17516: if ($authhash{$type}{$auth}) {
17517: push(@allowed,$authname{$auth});
17518: }
17519: }
17520: if (@allowed > 0) {
17521: $chgtext .= join(', ',@allowed).'</li>';
17522: } else {
17523: $chgtext .= &mt('none').'</li>';
17524: }
17525: }
17526: $chgtext .= '</ul>';
17527: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
17528: $resulttext .= '</li>';
17529: }
17530: $resulttext .= '</ul>';
17531: } else {
17532: $resulttext = &mt('No changes made to user creation settings');
17533: }
17534: } else {
17535: $resulttext = '<span class="LC_error">'.
17536: &mt('An error occurred: [_1]',$putresult).'</span>';
17537: }
17538: if ($warningmsg ne '') {
17539: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17540: }
17541: return $resulttext;
17542: }
17543:
17544: sub modify_selfcreation {
1.305 raeburn 17545: my ($dom,$lastactref,%domconfig) = @_;
17546: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
17547: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
17548: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 17549: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
17550: if (ref($typesref) eq 'ARRAY') {
17551: @types = @{$typesref};
17552: }
17553: if (ref($usertypesref) eq 'HASH') {
17554: %usertypes = %{$usertypesref};
1.228 raeburn 17555: }
1.303 raeburn 17556: $usertypes{'default'} = $othertitle;
1.224 raeburn 17557: #
17558: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
17559: #
17560: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17561: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
17562: if ($key eq 'cancreate') {
17563: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17564: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
17565: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 17566: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
17567: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
17568: ($item eq 'emailusername') || ($item eq 'shibenv') ||
17569: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 17570: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 17571: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17572: } else {
17573: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17574: }
17575: }
17576: }
17577: } elsif ($key eq 'email_rule') {
17578: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17579: } else {
17580: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17581: }
17582: }
17583: }
17584: #
17585: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
17586: #
17587: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17588: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
17589: if ($key eq 'selfcreate') {
17590: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
17591: } else {
17592: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
17593: }
17594: }
17595: }
1.305 raeburn 17596: #
17597: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
17598: #
17599: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17600: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
17601: if ($key eq 'inststatusguest') {
17602: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
17603: } else {
17604: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
17605: }
17606: }
17607: }
1.224 raeburn 17608:
17609: my @contexts = ('selfcreate');
17610: @{$cancreate{'selfcreate'}} = ();
17611: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 17612: if (@types) {
17613: @{$cancreate{'statustocreate'}} = ();
17614: }
1.236 raeburn 17615: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 17616: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 17617: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 17618: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 17619: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 17620: my %selfcreatetypes = (
17621: sso => 'users authenticated by institutional single sign on',
17622: login => 'users authenticated by institutional log-in',
1.303 raeburn 17623: email => 'users verified by e-mail',
1.50 raeburn 17624: );
1.224 raeburn 17625: #
17626: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
17627: # is permitted.
17628: #
1.305 raeburn 17629: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 17630:
1.305 raeburn 17631: my (@statuses,%email_rule);
1.228 raeburn 17632: foreach my $item ('login','sso','email') {
1.224 raeburn 17633: if ($item eq 'email') {
1.236 raeburn 17634: if ($env{'form.cancreate_email'}) {
1.305 raeburn 17635: if (@types) {
17636: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
17637: foreach my $status (@poss_statuses) {
17638: if (grep(/^\Q$status\E$/,(@types,'default'))) {
17639: push(@statuses,$status);
17640: }
17641: }
17642: $save_inststatus{'inststatusguest'} = \@statuses;
17643: } else {
17644: push(@statuses,'default');
17645: }
17646: if (@statuses) {
17647: my %curr_rule;
17648: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
17649: foreach my $type (@statuses) {
17650: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 17651: }
1.305 raeburn 17652: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
17653: foreach my $type (@statuses) {
17654: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
17655: }
17656: }
17657: push(@{$cancreate{'selfcreate'}},'email');
17658: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
17659: my %curremaildom;
17660: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
17661: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
17662: }
17663: foreach my $type (@statuses) {
17664: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
17665: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
17666: }
17667: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
17668: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
17669: }
17670: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
17671: #
17672: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
17673: #
17674: my $chosen = $1;
17675: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
17676: my $emaildom;
17677: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
17678: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
17679: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
17680: if (ref($curremaildom{$type}) eq 'HASH') {
17681: if (exists($curremaildom{$type}{$chosen})) {
17682: if ($curremaildom{$type}{$chosen} ne $emaildom) {
17683: push(@{$changes{'cancreate'}},'emaildomain');
17684: }
17685: } elsif ($emaildom ne '') {
17686: push(@{$changes{'cancreate'}},'emaildomain');
17687: }
17688: } elsif ($emaildom ne '') {
17689: push(@{$changes{'cancreate'}},'emaildomain');
17690: }
17691: }
17692: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17693: } elsif ($chosen eq 'custom') {
17694: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
17695: $email_rule{$type} = [];
17696: if (ref($emailrules) eq 'HASH') {
17697: foreach my $rule (@possemail_rules) {
17698: if (exists($emailrules->{$rule})) {
17699: push(@{$email_rule{$type}},$rule);
17700: }
17701: }
17702: }
17703: if (@{$email_rule{$type}}) {
17704: $cancreate{'emailoptions'}{$type} = 'custom';
17705: if (ref($curr_rule{$type}) eq 'ARRAY') {
17706: if (@{$curr_rule{$type}} > 0) {
17707: foreach my $rule (@{$curr_rule{$type}}) {
17708: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
17709: push(@{$changes{'email_rule'}},$type);
17710: }
17711: }
17712: }
17713: foreach my $type (@{$email_rule{$type}}) {
17714: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
17715: push(@{$changes{'email_rule'}},$type);
17716: }
17717: }
17718: } else {
17719: push(@{$changes{'email_rule'}},$type);
17720: }
17721: }
17722: } else {
17723: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17724: }
17725: }
17726: }
17727: if (@types) {
17728: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17729: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
17730: if (@changed) {
17731: push(@{$changes{'inststatus'}},'inststatusguest');
17732: }
17733: } else {
17734: push(@{$changes{'inststatus'}},'inststatusguest');
17735: }
17736: }
17737: } else {
17738: delete($env{'form.cancreate_email'});
17739: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17740: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17741: push(@{$changes{'inststatus'}},'inststatusguest');
17742: }
17743: }
17744: }
17745: } else {
17746: $save_inststatus{'inststatusguest'} = [];
17747: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17748: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17749: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 17750: }
17751: }
1.224 raeburn 17752: }
17753: } else {
17754: if ($env{'form.cancreate_'.$item}) {
17755: push(@{$cancreate{'selfcreate'}},$item);
17756: }
17757: }
17758: }
1.305 raeburn 17759: my (%userinfo,%savecaptcha);
1.224 raeburn 17760: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
17761: #
1.228 raeburn 17762: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
17763: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 17764: #
1.236 raeburn 17765:
1.244 raeburn 17766: if ($env{'form.cancreate_email'}) {
1.228 raeburn 17767: push(@contexts,'emailusername');
1.305 raeburn 17768: if (@statuses) {
17769: foreach my $type (@statuses) {
1.228 raeburn 17770: if (ref($infofields) eq 'ARRAY') {
17771: foreach my $field (@{$infofields}) {
17772: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
17773: $cancreate{'emailusername'}{$type}{$field} = $1;
17774: }
17775: }
1.224 raeburn 17776: }
17777: }
17778: }
17779: #
17780: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 17781: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 17782: #
17783:
17784: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
17785: @approvalnotify = sort(@approvalnotify);
17786: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
17787: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17788: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17789: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17790: push(@{$changes{'cancreate'}},'notify');
17791: }
17792: } else {
17793: if ($cancreate{'notify'}{'approval'}) {
17794: push(@{$changes{'cancreate'}},'notify');
17795: }
17796: }
17797: } elsif ($cancreate{'notify'}{'approval'}) {
17798: push(@{$changes{'cancreate'}},'notify');
17799: }
17800:
17801: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17802: }
17803: #
1.236 raeburn 17804: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 17805: # institutional log-in.
17806: #
17807: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17808: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17809: ($domdefaults{'auth_def'} eq 'localauth'))) {
17810: $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.').' '.
17811: &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.');
17812: }
17813: }
17814: my @fields = ('lastname','firstname','middlename','generation',
17815: 'permanentemail','id');
1.240 raeburn 17816: my @shibfields = (@fields,'inststatus');
1.224 raeburn 17817: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17818: #
17819: # Where usernames may created for institutional log-in and/or institutional single sign on:
17820: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17821: # may self-create accounts
17822: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17823: # which the user may supply, if institutional data is unavailable.
17824: #
17825: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 17826: if (@types) {
1.305 raeburn 17827: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17828: push(@contexts,'statustocreate');
1.303 raeburn 17829: foreach my $type (@types) {
1.224 raeburn 17830: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17831: foreach my $field (@fields) {
17832: if (grep(/^\Q$field\E$/,@modifiable)) {
17833: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17834: } else {
17835: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17836: }
17837: }
17838: }
17839: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17840: foreach my $type (@types) {
1.224 raeburn 17841: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17842: foreach my $field (@fields) {
17843: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17844: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17845: push(@{$changes{'selfcreate'}},$type);
17846: last;
17847: }
17848: }
17849: }
17850: }
17851: } else {
1.303 raeburn 17852: foreach my $type (@types) {
1.224 raeburn 17853: push(@{$changes{'selfcreate'}},$type);
17854: }
17855: }
17856: }
1.240 raeburn 17857: foreach my $field (@shibfields) {
17858: if ($env{'form.shibenv_'.$field} ne '') {
17859: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17860: }
17861: }
17862: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17863: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17864: foreach my $field (@shibfields) {
17865: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17866: push(@{$changes{'cancreate'}},'shibenv');
17867: }
17868: }
17869: } else {
17870: foreach my $field (@shibfields) {
17871: if ($env{'form.shibenv_'.$field}) {
17872: push(@{$changes{'cancreate'}},'shibenv');
17873: last;
17874: }
17875: }
17876: }
17877: }
1.224 raeburn 17878: }
17879: foreach my $item (@contexts) {
17880: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17881: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17882: if (ref($cancreate{$item}) eq 'ARRAY') {
17883: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17884: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17885: push(@{$changes{'cancreate'}},$item);
17886: }
17887: }
17888: }
17889: }
17890: if (ref($cancreate{$item}) eq 'ARRAY') {
17891: foreach my $type (@{$cancreate{$item}}) {
17892: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17893: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17894: push(@{$changes{'cancreate'}},$item);
17895: }
17896: }
17897: }
17898: }
17899: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17900: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17901: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17902: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17903: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17904: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17905: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17906: push(@{$changes{'cancreate'}},$item);
17907: }
17908: }
17909: }
1.305 raeburn 17910: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17911: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17912: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17913: push(@{$changes{'cancreate'}},$item);
17914: }
1.224 raeburn 17915: }
17916: }
17917: }
1.305 raeburn 17918: foreach my $type (keys(%{$cancreate{$item}})) {
17919: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17920: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17921: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17922: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17923: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17924: push(@{$changes{'cancreate'}},$item);
17925: }
17926: }
17927: } else {
17928: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17929: push(@{$changes{'cancreate'}},$item);
17930: }
17931: }
17932: }
1.305 raeburn 17933: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17934: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17935: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17936: push(@{$changes{'cancreate'}},$item);
17937: }
1.224 raeburn 17938: }
17939: }
17940: }
17941: }
17942: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17943: if (ref($cancreate{$item}) eq 'ARRAY') {
17944: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17945: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17946: push(@{$changes{'cancreate'}},$item);
17947: }
17948: }
1.305 raeburn 17949: }
17950: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17951: if (ref($cancreate{$item}) eq 'HASH') {
17952: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17953: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17954: }
17955: }
17956: } elsif ($item eq 'emailusername') {
1.228 raeburn 17957: if (ref($cancreate{$item}) eq 'HASH') {
17958: foreach my $type (keys(%{$cancreate{$item}})) {
17959: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17960: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17961: if ($cancreate{$item}{$type}{$field}) {
17962: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17963: push(@{$changes{'cancreate'}},$item);
17964: }
17965: last;
17966: }
17967: }
17968: }
17969: }
1.224 raeburn 17970: }
17971: }
17972: }
17973: #
17974: # Populate %save_usercreate hash with updates to self-creation configuration.
17975: #
17976: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17977: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17978: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17979: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17980: if (ref($cancreate{'notify'}) eq 'HASH') {
17981: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17982: }
1.236 raeburn 17983: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17984: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17985: }
1.303 raeburn 17986: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17987: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17988: }
1.305 raeburn 17989: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17990: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17991: }
1.303 raeburn 17992: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17993: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17994: }
1.224 raeburn 17995: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17996: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17997: }
1.240 raeburn 17998: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17999: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
18000: }
1.224 raeburn 18001: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 18002: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 18003:
18004: my %userconfig_hash = (
18005: usercreation => \%save_usercreate,
18006: usermodification => \%save_usermodify,
1.305 raeburn 18007: inststatus => \%save_inststatus,
1.224 raeburn 18008: );
1.305 raeburn 18009:
1.224 raeburn 18010: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
18011: $dom);
18012: #
1.305 raeburn 18013: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 18014: #
1.27 raeburn 18015: if ($putresult eq 'ok') {
18016: if (keys(%changes) > 0) {
18017: $resulttext = &mt('Changes made:').'<ul>';
18018: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18019: my %lt = &selfcreation_types();
1.34 raeburn 18020: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18021: my $chgtext = '';
1.45 raeburn 18022: if ($type eq 'selfcreate') {
1.50 raeburn 18023: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18024: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18025: } else {
1.224 raeburn 18026: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18027: '<ul>';
1.50 raeburn 18028: foreach my $case (@{$cancreate{$type}}) {
18029: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18030: }
18031: $chgtext .= '</ul>';
1.100 raeburn 18032: if (ref($cancreate{$type}) eq 'ARRAY') {
18033: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18034: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18035: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18036: $chgtext .= '<span class="LC_warning">'.
18037: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18038: '</span><br />';
18039: }
18040: }
18041: }
18042: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18043: if (!@statuses) {
18044: $chgtext .= '<span class="LC_warning">'.
18045: &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.").
18046: '</span><br />';
1.303 raeburn 18047:
1.100 raeburn 18048: }
18049: }
18050: }
1.43 raeburn 18051: }
1.240 raeburn 18052: } elsif ($type eq 'shibenv') {
18053: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18054: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18055: } else {
18056: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18057: '<ul>';
18058: foreach my $field (@shibfields) {
18059: next if ($cancreate{$type}{$field} eq '');
18060: if ($field eq 'inststatus') {
18061: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18062: } else {
18063: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18064: }
18065: }
18066: $chgtext .= '</ul>';
1.303 raeburn 18067: }
1.93 raeburn 18068: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18069: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18070: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18071: if (@{$cancreate{'selfcreate'}} > 0) {
18072: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18073: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18074: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18075: $chgtext .= '<br />'.
18076: '<span class="LC_warning">'.
18077: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18078: '</span>';
18079: }
1.303 raeburn 18080: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18081: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18082: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18083: } else {
18084: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18085: }
18086: $chgtext .= '<ul>';
18087: foreach my $case (@{$cancreate{$type}}) {
18088: if ($case eq 'default') {
18089: $chgtext .= '<li>'.$othertitle.'</li>';
18090: } else {
1.303 raeburn 18091: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18092: }
18093: }
1.100 raeburn 18094: $chgtext .= '</ul>';
18095: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18096: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18097: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18098: '</span>';
1.100 raeburn 18099: }
18100: }
18101: } else {
18102: if (@{$cancreate{$type}} == 0) {
18103: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18104: } else {
18105: $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 18106: }
18107: }
1.303 raeburn 18108: $chgtext .= '<br />';
1.93 raeburn 18109: }
1.236 raeburn 18110: } elsif ($type eq 'selfcreateprocessing') {
18111: my %choices = &Apache::lonlocal::texthash (
18112: automatic => 'Automatic approval',
18113: approval => 'Queued for approval',
18114: );
1.305 raeburn 18115: if (@types) {
18116: if (@statuses) {
1.303 raeburn 18117: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18118: '<ul>';
1.305 raeburn 18119: foreach my $status (@statuses) {
18120: if ($status eq 'default') {
18121: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18122: } else {
1.305 raeburn 18123: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18124: }
18125: }
18126: $chgtext .= '</ul>';
18127: }
18128: } else {
18129: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18130: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18131: }
18132: } elsif ($type eq 'emailverified') {
18133: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18134: all => 'Same as e-mail',
18135: first => 'Omit @domain',
18136: free => 'Free to choose',
1.303 raeburn 18137: );
1.305 raeburn 18138: if (@types) {
18139: if (@statuses) {
1.303 raeburn 18140: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18141: '<ul>';
1.305 raeburn 18142: foreach my $status (@statuses) {
1.362 raeburn 18143: if ($status eq 'default') {
1.305 raeburn 18144: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18145: } else {
1.305 raeburn 18146: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18147: }
18148: }
18149: $chgtext .= '</ul>';
18150: }
18151: } else {
1.305 raeburn 18152: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18153: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18154: }
1.305 raeburn 18155: } elsif ($type eq 'emailoptions') {
18156: my %options = &Apache::lonlocal::texthash (
18157: any => 'Any e-mail',
18158: inst => 'Institutional only',
18159: noninst => 'Non-institutional only',
18160: custom => 'Custom restrictions',
18161: );
18162: if (@types) {
18163: if (@statuses) {
18164: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18165: '<ul>';
18166: foreach my $status (@statuses) {
18167: if ($type eq 'default') {
18168: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18169: } else {
18170: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18171: }
18172: }
1.305 raeburn 18173: $chgtext .= '</ul>';
18174: }
18175: } else {
18176: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18177: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18178: } else {
18179: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18180: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18181: }
1.305 raeburn 18182: }
18183: } elsif ($type eq 'emaildomain') {
18184: my $output;
18185: if (@statuses) {
18186: foreach my $type (@statuses) {
18187: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18188: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18189: if ($type eq 'default') {
18190: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18191: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18192: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18193: } else {
18194: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18195: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18196: }
1.303 raeburn 18197: } else {
1.305 raeburn 18198: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18199: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18200: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18201: } else {
18202: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
18203: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18204: }
1.303 raeburn 18205: }
1.305 raeburn 18206: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18207: if ($type eq 'default') {
18208: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18209: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18210: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18211: } else {
18212: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18213: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18214: }
1.303 raeburn 18215: } else {
1.305 raeburn 18216: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18217: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18218: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18219: } else {
18220: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
18221: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18222: }
1.303 raeburn 18223: }
18224: }
18225: }
18226: }
1.305 raeburn 18227: }
18228: if ($output ne '') {
18229: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18230: '<ul>'.$output.'</ul>';
1.236 raeburn 18231: }
1.165 raeburn 18232: } elsif ($type eq 'captcha') {
1.224 raeburn 18233: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18234: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18235: } else {
18236: my %captchas = &captcha_phrases();
1.224 raeburn 18237: if ($captchas{$savecaptcha{$type}}) {
18238: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18239: } else {
1.210 raeburn 18240: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18241: }
18242: }
18243: } elsif ($type eq 'recaptchakeys') {
18244: my ($privkey,$pubkey);
1.224 raeburn 18245: if (ref($savecaptcha{$type}) eq 'HASH') {
18246: $pubkey = $savecaptcha{$type}{'public'};
18247: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18248: }
18249: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18250: if (!$pubkey) {
18251: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18252: } else {
18253: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18254: }
18255: if (!$privkey) {
18256: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18257: } else {
18258: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18259: }
18260: $chgtext .= '</ul>';
1.269 raeburn 18261: } elsif ($type eq 'recaptchaversion') {
18262: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18263: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18264: }
1.224 raeburn 18265: } elsif ($type eq 'emailusername') {
18266: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18267: if (@statuses) {
18268: foreach my $type (@statuses) {
1.228 raeburn 18269: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18270: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18271: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18272: '<ul>';
18273: foreach my $field (@{$infofields}) {
18274: if ($cancreate{'emailusername'}{$type}{$field}) {
18275: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18276: }
18277: }
1.245 raeburn 18278: $chgtext .= '</ul>';
18279: } else {
1.303 raeburn 18280: $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 18281: }
18282: } else {
1.303 raeburn 18283: $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 18284: }
18285: }
18286: }
18287: }
18288: } elsif ($type eq 'notify') {
1.303 raeburn 18289: my $numapprove = 0;
1.224 raeburn 18290: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18291: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18292: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18293: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18294: $numapprove ++;
1.224 raeburn 18295: }
18296: }
1.43 raeburn 18297: }
1.303 raeburn 18298: unless ($numapprove) {
18299: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18300: }
1.34 raeburn 18301: }
1.224 raeburn 18302: if ($chgtext) {
18303: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18304: }
18305: }
18306: }
1.305 raeburn 18307: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18308: my ($emailrules,$emailruleorder) =
18309: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18310: foreach my $type (@{$changes{'email_rule'}}) {
18311: if (ref($email_rule{$type}) eq 'ARRAY') {
18312: my $chgtext = '<ul>';
18313: foreach my $rule (@{$email_rule{$type}}) {
18314: if (ref($emailrules->{$rule}) eq 'HASH') {
18315: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18316: }
18317: }
18318: $chgtext .= '</ul>';
1.310 raeburn 18319: my $typename;
1.305 raeburn 18320: if (@types) {
18321: if ($type eq 'default') {
18322: $typename = $othertitle;
18323: } else {
18324: $typename = $usertypes{$type};
18325: }
18326: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18327: }
18328: if (@{$email_rule{$type}} > 0) {
18329: $resulttext .= '<li>'.
18330: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18331: $usertypes{$type}).
18332: $chgtext.
18333: '</li>';
18334: } else {
18335: $resulttext .= '<li>'.
1.310 raeburn 18336: &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 18337: '</li>'.
1.310 raeburn 18338: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18339: }
1.43 raeburn 18340: }
18341: }
1.305 raeburn 18342: }
18343: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18344: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18345: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18346: my $chgtext = '<ul>';
18347: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18348: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18349: }
18350: $chgtext .= '</ul>';
18351: $resulttext .= '<li>'.
18352: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18353: $chgtext.
18354: '</li>';
18355: } else {
18356: $resulttext .= '<li>'.
18357: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18358: '</li>';
18359: }
1.43 raeburn 18360: }
18361: }
1.224 raeburn 18362: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18363: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18364: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18365: foreach my $type (@{$changes{'selfcreate'}}) {
18366: my $typename = $type;
1.303 raeburn 18367: if (keys(%usertypes) > 0) {
18368: if ($usertypes{$type} ne '') {
18369: $typename = $usertypes{$type};
1.224 raeburn 18370: }
18371: }
18372: my @modifiable;
18373: $resulttext .= '<li>'.
18374: &mt('Self-creation of account by users with status: [_1]',
18375: '<span class="LC_cusr_emph">'.$typename.'</span>').
18376: ' - '.&mt('modifiable fields (if institutional data blank): ');
18377: foreach my $field (@fields) {
18378: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18379: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18380: }
18381: }
1.224 raeburn 18382: if (@modifiable > 0) {
18383: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18384: } else {
1.224 raeburn 18385: $resulttext .= &mt('none');
1.43 raeburn 18386: }
1.224 raeburn 18387: $resulttext .= '</li>';
1.28 raeburn 18388: }
1.224 raeburn 18389: $resulttext .= '</ul></li>';
1.28 raeburn 18390: }
1.27 raeburn 18391: $resulttext .= '</ul>';
1.305 raeburn 18392: my $cachetime = 24*60*60;
18393: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18394: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18395: if (ref($lastactref) eq 'HASH') {
18396: $lastactref->{'domdefaults'} = 1;
18397: }
1.27 raeburn 18398: } else {
1.224 raeburn 18399: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18400: }
18401: } else {
18402: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18403: &mt('An error occurred: [_1]',$putresult).'</span>';
18404: }
1.43 raeburn 18405: if ($warningmsg ne '') {
18406: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18407: }
1.23 raeburn 18408: return $resulttext;
18409: }
18410:
1.165 raeburn 18411: sub process_captcha {
1.369 raeburn 18412: my ($container,$changes,$newsettings,$currsettings) = @_;
18413: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18414: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18415: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18416: $newsettings->{'captcha'} = 'original';
18417: }
1.369 raeburn 18418: my %current;
18419: if (ref($currsettings) eq 'HASH') {
18420: %current = %{$currsettings};
18421: }
18422: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18423: if ($container eq 'cancreate') {
1.169 raeburn 18424: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18425: push(@{$changes->{'cancreate'}},'captcha');
18426: } elsif (!defined($changes->{'cancreate'})) {
18427: $changes->{'cancreate'} = ['captcha'];
18428: }
1.368 raeburn 18429: } elsif ($container eq 'passwords') {
18430: $changes->{'reset'} = 1;
1.169 raeburn 18431: } else {
18432: $changes->{'captcha'} = 1;
1.165 raeburn 18433: }
18434: }
1.269 raeburn 18435: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18436: if ($newsettings->{'captcha'} eq 'recaptcha') {
18437: $newpub = $env{'form.'.$container.'_recaptchapub'};
18438: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18439: $newpub =~ s/[^\w\-]//g;
18440: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18441: $newsettings->{'recaptchakeys'} = {
18442: public => $newpub,
18443: private => $newpriv,
18444: };
1.269 raeburn 18445: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18446: $newversion =~ s/\D//g;
18447: if ($newversion ne '2') {
18448: $newversion = 1;
18449: }
18450: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18451: }
1.369 raeburn 18452: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18453: $currpub = $current{'recaptchakeys'}{'public'};
18454: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18455: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18456: $newsettings->{'recaptchakeys'} = {
18457: public => '',
18458: private => '',
18459: }
18460: }
1.165 raeburn 18461: }
1.369 raeburn 18462: if ($current{'captcha'} eq 'recaptcha') {
18463: $currversion = $current{'recaptchaversion'};
1.269 raeburn 18464: if ($currversion ne '2') {
18465: $currversion = 1;
18466: }
18467: }
18468: if ($currversion ne $newversion) {
18469: if ($container eq 'cancreate') {
18470: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18471: push(@{$changes->{'cancreate'}},'recaptchaversion');
18472: } elsif (!defined($changes->{'cancreate'})) {
18473: $changes->{'cancreate'} = ['recaptchaversion'];
18474: }
1.368 raeburn 18475: } elsif ($container eq 'passwords') {
18476: $changes->{'reset'} = 1;
1.269 raeburn 18477: } else {
18478: $changes->{'recaptchaversion'} = 1;
18479: }
18480: }
1.165 raeburn 18481: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 18482: if ($container eq 'cancreate') {
18483: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18484: push(@{$changes->{'cancreate'}},'recaptchakeys');
18485: } elsif (!defined($changes->{'cancreate'})) {
18486: $changes->{'cancreate'} = ['recaptchakeys'];
18487: }
1.368 raeburn 18488: } elsif ($container eq 'passwords') {
18489: $changes->{'reset'} = 1;
1.169 raeburn 18490: } else {
1.210 raeburn 18491: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 18492: }
18493: }
18494: return;
18495: }
18496:
1.33 raeburn 18497: sub modify_usermodification {
18498: my ($dom,%domconfig) = @_;
1.224 raeburn 18499: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 18500: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18501: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 18502: if ($key eq 'selfcreate') {
18503: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
18504: } else {
18505: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
18506: }
1.33 raeburn 18507: }
18508: }
1.224 raeburn 18509: my @contexts = ('author','course');
1.33 raeburn 18510: my %context_title = (
18511: author => 'In author context',
18512: course => 'In course context',
18513: );
18514: my @fields = ('lastname','firstname','middlename','generation',
18515: 'permanentemail','id');
18516: my %roles = (
18517: author => ['ca','aa'],
18518: course => ['st','ep','ta','in','cr'],
18519: );
18520: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18521: foreach my $context (@contexts) {
18522: foreach my $role (@{$roles{$context}}) {
18523: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
18524: foreach my $item (@fields) {
18525: if (grep(/^\Q$item\E$/,@modifiable)) {
18526: $modifyhash{$context}{$role}{$item} = 1;
18527: } else {
18528: $modifyhash{$context}{$role}{$item} = 0;
18529: }
18530: }
18531: }
18532: if (ref($curr_usermodification{$context}) eq 'HASH') {
18533: foreach my $role (@{$roles{$context}}) {
18534: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
18535: foreach my $field (@fields) {
18536: if ($modifyhash{$context}{$role}{$field} ne
18537: $curr_usermodification{$context}{$role}{$field}) {
18538: push(@{$changes{$context}},$role);
18539: last;
18540: }
18541: }
18542: }
18543: }
18544: } else {
18545: foreach my $context (@contexts) {
18546: foreach my $role (@{$roles{$context}}) {
18547: push(@{$changes{$context}},$role);
18548: }
18549: }
18550: }
18551: }
18552: my %usermodification_hash = (
18553: usermodification => \%modifyhash,
18554: );
18555: my $putresult = &Apache::lonnet::put_dom('configuration',
18556: \%usermodification_hash,$dom);
18557: if ($putresult eq 'ok') {
18558: if (keys(%changes) > 0) {
18559: $resulttext = &mt('Changes made: ').'<ul>';
18560: foreach my $context (@contexts) {
18561: if (ref($changes{$context}) eq 'ARRAY') {
18562: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
18563: if (ref($changes{$context}) eq 'ARRAY') {
18564: foreach my $role (@{$changes{$context}}) {
18565: my $rolename;
1.224 raeburn 18566: if ($role eq 'cr') {
18567: $rolename = &mt('Custom');
1.33 raeburn 18568: } else {
1.224 raeburn 18569: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 18570: }
18571: my @modifiable;
1.224 raeburn 18572: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 18573: foreach my $field (@fields) {
18574: if ($modifyhash{$context}{$role}{$field}) {
18575: push(@modifiable,$fieldtitles{$field});
18576: }
18577: }
18578: if (@modifiable > 0) {
18579: $resulttext .= join(', ',@modifiable);
18580: } else {
18581: $resulttext .= &mt('none');
18582: }
18583: $resulttext .= '</li>';
18584: }
18585: $resulttext .= '</ul></li>';
18586: }
18587: }
18588: }
18589: $resulttext .= '</ul>';
18590: } else {
18591: $resulttext = &mt('No changes made to user modification settings');
18592: }
18593: } else {
18594: $resulttext = '<span class="LC_error">'.
18595: &mt('An error occurred: [_1]',$putresult).'</span>';
18596: }
18597: return $resulttext;
18598: }
18599:
1.43 raeburn 18600: sub modify_defaults {
1.212 raeburn 18601: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 18602: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 18603: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 18604: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 18605: 'portal_def');
1.325 raeburn 18606: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 18607: foreach my $item (@items) {
18608: $newvalues{$item} = $env{'form.'.$item};
18609: if ($item eq 'auth_def') {
18610: if ($newvalues{$item} ne '') {
18611: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
18612: push(@errors,$item);
18613: }
18614: }
18615: } elsif ($item eq 'lang_def') {
18616: if ($newvalues{$item} ne '') {
18617: if ($newvalues{$item} =~ /^(\w+)/) {
18618: my $langcode = $1;
1.103 raeburn 18619: if ($langcode ne 'x_chef') {
18620: if (code2language($langcode) eq '') {
18621: push(@errors,$item);
18622: }
1.43 raeburn 18623: }
18624: } else {
18625: push(@errors,$item);
18626: }
18627: }
1.54 raeburn 18628: } elsif ($item eq 'timezone_def') {
18629: if ($newvalues{$item} ne '') {
1.62 raeburn 18630: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 18631: push(@errors,$item);
18632: }
18633: }
1.68 raeburn 18634: } elsif ($item eq 'datelocale_def') {
18635: if ($newvalues{$item} ne '') {
18636: my @datelocale_ids = DateTime::Locale->ids();
18637: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
18638: push(@errors,$item);
18639: }
18640: }
1.141 raeburn 18641: } elsif ($item eq 'portal_def') {
18642: if ($newvalues{$item} ne '') {
18643: 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])\/?$/) {
18644: push(@errors,$item);
18645: }
18646: }
1.43 raeburn 18647: }
18648: if (grep(/^\Q$item\E$/,@errors)) {
18649: $newvalues{$item} = $domdefaults{$item};
18650: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
18651: $changes{$item} = 1;
18652: }
1.72 raeburn 18653: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 18654: }
1.354 raeburn 18655: my %staticdefaults = (
18656: 'intauth_cost' => 10,
18657: 'intauth_check' => 0,
18658: 'intauth_switch' => 0,
18659: );
18660: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
18661: if (exists($domdefaults{$item})) {
18662: $newvalues{$item} = $domdefaults{$item};
18663: } else {
18664: $newvalues{$item} = $staticdefaults{$item};
18665: }
18666: }
1.43 raeburn 18667: my %defaults_hash = (
1.72 raeburn 18668: defaults => \%newvalues,
18669: );
1.43 raeburn 18670: my $title = &defaults_titles();
1.236 raeburn 18671:
18672: my $currinststatus;
18673: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18674: $currinststatus = $domconfig{'inststatus'};
18675: } else {
18676: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18677: $currinststatus = {
18678: inststatustypes => $usertypes,
18679: inststatusorder => $types,
18680: inststatusguest => [],
18681: };
18682: }
18683: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
18684: my @allpos;
18685: my %alltypes;
1.305 raeburn 18686: my @inststatusguest;
18687: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
18688: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
18689: unless (grep(/^\Q$type\E$/,@todelete)) {
18690: push(@inststatusguest,$type);
18691: }
18692: }
18693: }
18694: my ($currtitles,$currorder);
1.236 raeburn 18695: if (ref($currinststatus) eq 'HASH') {
18696: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
18697: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
18698: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
18699: if ($currinststatus->{inststatustypes}->{$type} ne '') {
18700: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
18701: }
18702: }
18703: unless (grep(/^\Q$type\E$/,@todelete)) {
18704: my $position = $env{'form.inststatus_pos_'.$type};
18705: $position =~ s/\D+//g;
18706: $allpos[$position] = $type;
18707: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18708: $alltypes{$type} =~ s/`//g;
18709: }
18710: }
18711: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18712: $currtitles =~ s/,$//;
18713: }
18714: }
18715: if ($env{'form.addinststatus'}) {
18716: my $newtype = $env{'form.addinststatus'};
18717: $newtype =~ s/\W//g;
18718: unless (exists($alltypes{$newtype})) {
18719: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18720: $alltypes{$newtype} =~ s/`//g;
18721: my $position = $env{'form.addinststatus_pos'};
18722: $position =~ s/\D+//g;
18723: if ($position ne '') {
18724: $allpos[$position] = $newtype;
18725: }
18726: }
18727: }
1.305 raeburn 18728: my @orderedstatus;
1.236 raeburn 18729: foreach my $type (@allpos) {
18730: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18731: push(@orderedstatus,$type);
18732: }
18733: }
18734: foreach my $type (keys(%alltypes)) {
18735: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18736: delete($alltypes{$type});
18737: }
18738: }
18739: $defaults_hash{'inststatus'} = {
18740: inststatustypes => \%alltypes,
18741: inststatusorder => \@orderedstatus,
1.305 raeburn 18742: inststatusguest => \@inststatusguest,
1.236 raeburn 18743: };
18744: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18745: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18746: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18747: }
18748: }
18749: if ($currorder ne join(',',@orderedstatus)) {
18750: $changes{'inststatus'}{'inststatusorder'} = 1;
18751: }
18752: my $newtitles;
18753: foreach my $item (@orderedstatus) {
18754: $newtitles .= $alltypes{$item}.',';
18755: }
18756: $newtitles =~ s/,$//;
18757: if ($currtitles ne $newtitles) {
18758: $changes{'inststatus'}{'inststatustypes'} = 1;
18759: }
1.43 raeburn 18760: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18761: $dom);
18762: if ($putresult eq 'ok') {
18763: if (keys(%changes) > 0) {
18764: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 18765: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18766: 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";
18767: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 18768: if ($item eq 'inststatus') {
18769: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 18770: if (@orderedstatus) {
1.236 raeburn 18771: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18772: foreach my $type (@orderedstatus) {
18773: $resulttext .= $alltypes{$type}.', ';
18774: }
18775: $resulttext =~ s/, $//;
18776: $resulttext .= '</li>';
1.305 raeburn 18777: } else {
18778: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 18779: }
18780: }
18781: } else {
18782: my $value = $env{'form.'.$item};
18783: if ($value eq '') {
18784: $value = &mt('none');
18785: } elsif ($item eq 'auth_def') {
18786: my %authnames = &authtype_names();
18787: my %shortauth = (
18788: internal => 'int',
18789: krb4 => 'krb4',
18790: krb5 => 'krb5',
18791: localauth => 'loc',
1.325 raeburn 18792: lti => 'lti',
1.236 raeburn 18793: );
18794: $value = $authnames{$shortauth{$value}};
18795: }
18796: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
18797: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 18798: }
18799: }
18800: $resulttext .= '</ul>';
18801: $mailmsgtext .= "\n";
18802: my $cachetime = 24*60*60;
1.72 raeburn 18803: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 18804: if (ref($lastactref) eq 'HASH') {
18805: $lastactref->{'domdefaults'} = 1;
18806: }
1.68 raeburn 18807: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 18808: my $notify = 1;
18809: if (ref($domconfig{'contacts'}) eq 'HASH') {
18810: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18811: $notify = 0;
18812: }
18813: }
18814: if ($notify) {
18815: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18816: "LON-CAPA Domain Settings Change - $dom",
18817: $mailmsgtext);
18818: }
1.54 raeburn 18819: }
1.43 raeburn 18820: } else {
1.54 raeburn 18821: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18822: }
18823: } else {
18824: $resulttext = '<span class="LC_error">'.
18825: &mt('An error occurred: [_1]',$putresult).'</span>';
18826: }
18827: if (@errors > 0) {
18828: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18829: foreach my $item (@errors) {
18830: $resulttext .= ' "'.$title->{$item}.'",';
18831: }
18832: $resulttext =~ s/,$//;
18833: }
18834: return $resulttext;
18835: }
18836:
1.46 raeburn 18837: sub modify_scantron {
1.205 raeburn 18838: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18839: my ($resulttext,%confhash,%changes,$errors);
18840: my $custom = 'custom.tab';
18841: my $default = 'default.tab';
18842: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18843: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18844: &config_check($dom,$confname,$servadm);
18845: if ($env{'form.scantronformat.filename'} ne '') {
18846: my $error;
18847: if ($configuserok eq 'ok') {
18848: if ($switchserver) {
1.130 raeburn 18849: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18850: } else {
18851: if ($author_ok eq 'ok') {
18852: my ($result,$scantronurl) =
18853: &publishlogo($r,'upload','scantronformat',$dom,
18854: $confname,'scantron','','',$custom);
18855: if ($result eq 'ok') {
18856: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18857: $changes{'scantronformat'} = 1;
1.46 raeburn 18858: } else {
18859: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18860: }
18861: } else {
18862: $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);
18863: }
18864: }
18865: } else {
18866: $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);
18867: }
18868: if ($error) {
18869: &Apache::lonnet::logthis($error);
18870: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18871: }
18872: }
1.48 raeburn 18873: if (ref($domconfig{'scantron'}) eq 'HASH') {
18874: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18875: if ($env{'form.scantronformat_del'}) {
18876: $confhash{'scantron'}{'scantronformat'} = '';
18877: $changes{'scantronformat'} = 1;
1.347 raeburn 18878: } else {
18879: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18880: }
18881: }
18882: }
1.347 raeburn 18883: my @options = ('hdr','pad','rem');
1.346 raeburn 18884: my @fields = &scantroncsv_fields();
18885: my %titles = &scantronconfig_titles();
1.347 raeburn 18886: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18887: my ($newdat,$currdat,%newcol,%currcol);
18888: if (grep(/^dat$/,@formats)) {
18889: $confhash{'scantron'}{config}{dat} = 1;
18890: $newdat = 1;
18891: } else {
18892: $newdat = 0;
18893: }
18894: if (grep(/^csv$/,@formats)) {
18895: my %bynum;
18896: foreach my $field (@fields) {
18897: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18898: my $posscol = $1;
18899: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18900: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18901: $bynum{$posscol} = $field;
18902: $newcol{$field} = $posscol;
18903: }
18904: }
18905: }
1.347 raeburn 18906: if (keys(%newcol)) {
18907: foreach my $option (@options) {
18908: if ($env{'form.scantroncsv_'.$option}) {
18909: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18910: }
18911: }
18912: }
1.346 raeburn 18913: }
18914: $currdat = 1;
18915: if (ref($domconfig{'scantron'}) eq 'HASH') {
18916: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18917: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18918: $currdat = 0;
18919: }
18920: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18921: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18922: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18923: }
1.346 raeburn 18924: }
18925: }
18926: }
18927: if ($currdat != $newdat) {
18928: $changes{'config'} = 1;
18929: } else {
18930: foreach my $field (@fields) {
18931: if ($currcol{$field} ne '') {
18932: if ($currcol{$field} ne $newcol{$field}) {
18933: $changes{'config'} = 1;
18934: last;
1.347 raeburn 18935: }
1.346 raeburn 18936: } elsif ($newcol{$field} ne '') {
18937: $changes{'config'} = 1;
18938: last;
18939: }
18940: }
18941: }
1.46 raeburn 18942: if (keys(%confhash) > 0) {
18943: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18944: $dom);
18945: if ($putresult eq 'ok') {
18946: if (keys(%changes) > 0) {
1.48 raeburn 18947: if (ref($confhash{'scantron'}) eq 'HASH') {
18948: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18949: if ($changes{'scantronformat'}) {
18950: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18951: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18952: } else {
18953: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18954: }
18955: }
1.347 raeburn 18956: if ($changes{'config'}) {
1.346 raeburn 18957: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18958: if ($confhash{'scantron'}{'config'}{'dat'}) {
18959: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18960: }
18961: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18962: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18963: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18964: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18965: foreach my $field (@fields) {
18966: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18967: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18968: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18969: }
18970: }
18971: $resulttext .= '</ul></li>';
18972: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18973: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18974: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18975: foreach my $option (@options) {
18976: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18977: $resulttext .= '<li>'.$titles{$option}.'</li>';
18978: }
18979: }
18980: $resulttext .= '</ul></li>';
18981: }
1.346 raeburn 18982: }
18983: }
18984: }
18985: }
18986: } else {
18987: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18988: }
1.46 raeburn 18989: }
1.48 raeburn 18990: $resulttext .= '</ul>';
18991: } else {
1.130 raeburn 18992: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18993: }
18994: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18995: if (ref($lastactref) eq 'HASH') {
18996: $lastactref->{'domainconfig'} = 1;
18997: }
1.46 raeburn 18998: } else {
1.346 raeburn 18999: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 19000: }
19001: } else {
19002: $resulttext = '<span class="LC_error">'.
19003: &mt('An error occurred: [_1]',$putresult).'</span>';
19004: }
19005: } else {
1.130 raeburn 19006: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 19007: }
19008: if ($errors) {
1.353 raeburn 19009: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
19010: $errors.'</ul></p>';
1.46 raeburn 19011: }
19012: return $resulttext;
19013: }
19014:
1.48 raeburn 19015: sub modify_coursecategories {
1.239 raeburn 19016: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 19017: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19018: $cathash);
1.48 raeburn 19019: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19020: my @catitems = ('unauth','auth');
19021: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19022: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19023: $cathash = $domconfig{'coursecategories'}{'cats'};
19024: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19025: $changes{'togglecats'} = 1;
19026: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19027: }
19028: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19029: $changes{'categorize'} = 1;
19030: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19031: }
1.120 raeburn 19032: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19033: $changes{'togglecatscomm'} = 1;
19034: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19035: }
19036: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19037: $changes{'categorizecomm'} = 1;
19038: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19039:
19040: }
19041: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19042: $changes{'togglecatsplace'} = 1;
19043: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19044: }
19045: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19046: $changes{'categorizeplace'} = 1;
19047: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19048: }
1.238 raeburn 19049: foreach my $item (@catitems) {
19050: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19051: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19052: $changes{$item} = 1;
19053: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19054: }
19055: }
19056: }
1.57 raeburn 19057: } else {
19058: $changes{'togglecats'} = 1;
19059: $changes{'categorize'} = 1;
1.124 raeburn 19060: $changes{'togglecatscomm'} = 1;
19061: $changes{'categorizecomm'} = 1;
1.272 raeburn 19062: $changes{'togglecatsplace'} = 1;
19063: $changes{'categorizeplace'} = 1;
1.87 raeburn 19064: $domconfig{'coursecategories'} = {
19065: togglecats => $env{'form.togglecats'},
19066: categorize => $env{'form.categorize'},
1.124 raeburn 19067: togglecatscomm => $env{'form.togglecatscomm'},
19068: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19069: togglecatsplace => $env{'form.togglecatsplace'},
19070: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19071: };
1.238 raeburn 19072: foreach my $item (@catitems) {
19073: if ($env{'form.coursecat_'.$item} ne 'std') {
19074: $changes{$item} = 1;
19075: }
19076: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19077: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19078: }
19079: }
1.57 raeburn 19080: }
19081: if (ref($cathash) eq 'HASH') {
19082: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19083: push (@deletecategory,'instcode::0');
19084: }
1.120 raeburn 19085: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19086: push(@deletecategory,'communities::0');
19087: }
1.272 raeburn 19088: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19089: push(@deletecategory,'placement::0');
19090: }
1.48 raeburn 19091: }
1.57 raeburn 19092: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19093: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19094: if (@deletecategory > 0) {
19095: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19096: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19097: foreach my $item (@deletecategory) {
1.57 raeburn 19098: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19099: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19100: $deletions{$item} = 1;
1.57 raeburn 19101: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19102: }
19103: }
19104: }
1.57 raeburn 19105: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19106: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19107: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19108: $reorderings{$item} = 1;
1.57 raeburn 19109: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19110: }
19111: if ($env{'form.addcategory_name_'.$item} ne '') {
19112: my $newcat = $env{'form.addcategory_name_'.$item};
19113: my $newdepth = $depth+1;
19114: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19115: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19116: $adds{$newitem} = 1;
19117: }
19118: if ($env{'form.subcat_'.$item} ne '') {
19119: my $newcat = $env{'form.subcat_'.$item};
19120: my $newdepth = $depth+1;
19121: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19122: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19123: $adds{$newitem} = 1;
19124: }
19125: }
19126: }
19127: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19128: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19129: my $newitem = 'instcode::0';
1.57 raeburn 19130: if ($cathash->{$newitem} eq '') {
19131: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19132: $adds{$newitem} = 1;
19133: }
19134: } else {
19135: my $newitem = 'instcode::0';
1.57 raeburn 19136: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19137: $adds{$newitem} = 1;
19138: }
19139: }
1.120 raeburn 19140: if ($env{'form.communities'} eq '1') {
19141: if (ref($cathash) eq 'HASH') {
19142: my $newitem = 'communities::0';
19143: if ($cathash->{$newitem} eq '') {
19144: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19145: $adds{$newitem} = 1;
19146: }
19147: } else {
19148: my $newitem = 'communities::0';
19149: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19150: $adds{$newitem} = 1;
19151: }
19152: }
1.272 raeburn 19153: if ($env{'form.placement'} eq '1') {
19154: if (ref($cathash) eq 'HASH') {
19155: my $newitem = 'placement::0';
19156: if ($cathash->{$newitem} eq '') {
19157: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19158: $adds{$newitem} = 1;
19159: }
19160: } else {
19161: my $newitem = 'placement::0';
19162: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19163: $adds{$newitem} = 1;
19164: }
19165: }
1.48 raeburn 19166: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19167: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19168: ($env{'form.addcategory_name'} ne 'communities') &&
19169: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19170: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19171: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19172: $adds{$newitem} = 1;
19173: }
1.48 raeburn 19174: }
1.57 raeburn 19175: my $putresult;
1.48 raeburn 19176: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19177: if (keys(%deletions) > 0) {
19178: foreach my $key (keys(%deletions)) {
19179: if ($predelallitems{$key} ne '') {
19180: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19181: }
19182: }
19183: }
19184: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19185: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19186: if (ref($chkcats[0]) eq 'ARRAY') {
19187: my $depth = 0;
19188: my $chg = 0;
19189: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19190: my $name = $chkcats[0][$i];
19191: my $item;
19192: if ($name eq '') {
19193: $chg ++;
19194: } else {
19195: $item = &escape($name).'::0';
19196: if ($chg) {
1.57 raeburn 19197: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19198: }
19199: $depth ++;
1.57 raeburn 19200: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19201: $depth --;
19202: }
19203: }
19204: }
1.57 raeburn 19205: }
19206: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19207: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19208: if ($putresult eq 'ok') {
1.57 raeburn 19209: my %title = (
1.120 raeburn 19210: togglecats => 'Show/Hide a course in catalog',
19211: categorize => 'Assign a category to a course',
19212: togglecatscomm => 'Show/Hide a community in catalog',
19213: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19214: );
19215: my %level = (
1.120 raeburn 19216: dom => 'set in Domain ("Modify Course/Community")',
19217: crs => 'set in Course ("Course Configuration")',
19218: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19219: none => 'No catalog',
19220: std => 'Standard catalog',
19221: domonly => 'Domain-only catalog',
19222: codesrch => 'Code search form',
1.57 raeburn 19223: );
1.48 raeburn 19224: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19225: if ($changes{'togglecats'}) {
19226: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19227: }
19228: if ($changes{'categorize'}) {
19229: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19230: }
1.120 raeburn 19231: if ($changes{'togglecatscomm'}) {
19232: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19233: }
19234: if ($changes{'categorizecomm'}) {
19235: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19236: }
1.238 raeburn 19237: if ($changes{'unauth'}) {
19238: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19239: }
19240: if ($changes{'auth'}) {
19241: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19242: }
1.57 raeburn 19243: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19244: my $cathash;
19245: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19246: $cathash = $domconfig{'coursecategories'}{'cats'};
19247: } else {
19248: $cathash = {};
19249: }
19250: my (@cats,@trails,%allitems);
19251: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19252: if (keys(%deletions) > 0) {
19253: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19254: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19255: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19256: }
19257: $resulttext .= '</ul></li>';
19258: }
19259: if (keys(%reorderings) > 0) {
19260: my %sort_by_trail;
19261: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19262: foreach my $key (keys(%reorderings)) {
19263: if ($allitems{$key} ne '') {
19264: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19265: }
1.48 raeburn 19266: }
1.57 raeburn 19267: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19268: $resulttext .= '<li>'.$trails[$trail].'</li>';
19269: }
19270: $resulttext .= '</ul></li>';
1.48 raeburn 19271: }
1.57 raeburn 19272: if (keys(%adds) > 0) {
19273: my %sort_by_trail;
19274: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19275: foreach my $key (keys(%adds)) {
19276: if ($allitems{$key} ne '') {
19277: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19278: }
19279: }
19280: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19281: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19282: }
1.57 raeburn 19283: $resulttext .= '</ul></li>';
1.48 raeburn 19284: }
1.364 raeburn 19285: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19286: if (ref($lastactref) eq 'HASH') {
19287: $lastactref->{'cats'} = 1;
19288: }
1.48 raeburn 19289: }
19290: $resulttext .= '</ul>';
1.239 raeburn 19291: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19292: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19293: if ($changes{'auth'}) {
19294: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19295: }
19296: if ($changes{'unauth'}) {
19297: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19298: }
19299: my $cachetime = 24*60*60;
19300: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19301: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19302: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19303: }
19304: }
1.48 raeburn 19305: } else {
19306: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19307: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19308: }
19309: } else {
1.120 raeburn 19310: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19311: }
19312: return $resulttext;
19313: }
19314:
1.69 raeburn 19315: sub modify_serverstatuses {
19316: my ($dom,%domconfig) = @_;
19317: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19318: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19319: %currserverstatus = %{$domconfig{'serverstatuses'}};
19320: }
19321: my @pages = &serverstatus_pages();
19322: foreach my $type (@pages) {
19323: $newserverstatus{$type}{'namedusers'} = '';
19324: $newserverstatus{$type}{'machines'} = '';
19325: if (defined($env{'form.'.$type.'_namedusers'})) {
19326: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19327: my @okusers;
19328: foreach my $user (@users) {
19329: my ($uname,$udom) = split(/:/,$user);
19330: if (($udom =~ /^$match_domain$/) &&
19331: (&Apache::lonnet::domain($udom)) &&
19332: ($uname =~ /^$match_username$/)) {
19333: if (!grep(/^\Q$user\E/,@okusers)) {
19334: push(@okusers,$user);
19335: }
19336: }
19337: }
19338: if (@okusers > 0) {
19339: @okusers = sort(@okusers);
19340: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19341: }
19342: }
19343: if (defined($env{'form.'.$type.'_machines'})) {
19344: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19345: my @okmachines;
19346: foreach my $ip (@machines) {
19347: my @parts = split(/\./,$ip);
19348: next if (@parts < 4);
19349: my $badip = 0;
19350: for (my $i=0; $i<4; $i++) {
19351: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19352: $badip = 1;
19353: last;
19354: }
19355: }
19356: if (!$badip) {
19357: push(@okmachines,$ip);
19358: }
19359: }
19360: @okmachines = sort(@okmachines);
19361: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19362: }
19363: }
19364: my %serverstatushash = (
19365: serverstatuses => \%newserverstatus,
19366: );
19367: foreach my $type (@pages) {
1.83 raeburn 19368: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19369: my (@current,@new);
1.83 raeburn 19370: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19371: if ($currserverstatus{$type}{$setting} ne '') {
19372: @current = split(/,/,$currserverstatus{$type}{$setting});
19373: }
19374: }
19375: if ($newserverstatus{$type}{$setting} ne '') {
19376: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19377: }
19378: if (@current > 0) {
19379: if (@new > 0) {
19380: foreach my $item (@current) {
19381: if (!grep(/^\Q$item\E$/,@new)) {
19382: $changes{$type}{$setting} = 1;
1.82 raeburn 19383: last;
19384: }
19385: }
1.84 raeburn 19386: foreach my $item (@new) {
19387: if (!grep(/^\Q$item\E$/,@current)) {
19388: $changes{$type}{$setting} = 1;
19389: last;
1.82 raeburn 19390: }
19391: }
19392: } else {
1.83 raeburn 19393: $changes{$type}{$setting} = 1;
1.69 raeburn 19394: }
1.83 raeburn 19395: } elsif (@new > 0) {
19396: $changes{$type}{$setting} = 1;
1.69 raeburn 19397: }
19398: }
19399: }
19400: if (keys(%changes) > 0) {
1.81 raeburn 19401: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19402: my $putresult = &Apache::lonnet::put_dom('configuration',
19403: \%serverstatushash,$dom);
19404: if ($putresult eq 'ok') {
19405: $resulttext .= &mt('Changes made:').'<ul>';
19406: foreach my $type (@pages) {
1.84 raeburn 19407: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19408: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19409: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19410: if ($newserverstatus{$type}{'namedusers'} eq '') {
19411: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19412: } else {
19413: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19414: }
1.84 raeburn 19415: }
19416: if ($changes{$type}{'machines'}) {
1.69 raeburn 19417: if ($newserverstatus{$type}{'machines'} eq '') {
19418: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19419: } else {
19420: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19421: }
19422:
19423: }
19424: $resulttext .= '</ul></li>';
19425: }
19426: }
19427: $resulttext .= '</ul>';
19428: } else {
19429: $resulttext = '<span class="LC_error">'.
19430: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19431:
19432: }
19433: } else {
19434: $resulttext = &mt('No changes made to access to server status pages');
19435: }
19436: return $resulttext;
19437: }
19438:
1.118 jms 19439: sub modify_helpsettings {
1.285 raeburn 19440: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19441: my ($resulttext,$errors,%changes,%helphash);
19442: my %defaultchecked = ('submitbugs' => 'on');
19443: my @offon = ('off','on');
1.118 jms 19444: my @toggles = ('submitbugs');
1.285 raeburn 19445: my %current = ('submitbugs' => '',
19446: 'adhoc' => {},
19447: );
1.118 jms 19448: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19449: %current = %{$domconfig{'helpsettings'}};
19450: }
1.285 raeburn 19451: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19452: foreach my $item (@toggles) {
19453: if ($defaultchecked{$item} eq 'on') {
19454: if ($current{$item} eq '') {
19455: if ($env{'form.'.$item} eq '0') {
19456: $changes{$item} = 1;
19457: }
19458: } elsif ($current{$item} ne $env{'form.'.$item}) {
19459: $changes{$item} = 1;
19460: }
19461: } elsif ($defaultchecked{$item} eq 'off') {
19462: if ($current{$item} eq '') {
19463: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 19464: $changes{$item} = 1;
19465: }
1.282 raeburn 19466: } elsif ($current{$item} ne $env{'form.'.$item}) {
19467: $changes{$item} = 1;
19468: }
19469: }
19470: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
19471: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
19472: }
19473: }
1.285 raeburn 19474: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 19475: my $confname = $dom.'-domainconfig';
19476: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 19477: my (@allpos,%newsettings,%changedprivs,$newrole);
19478: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 19479: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 19480: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 19481: my %lt = &Apache::lonlocal::texthash(
19482: s => 'system',
19483: d => 'domain',
19484: order => 'Display order',
19485: access => 'Role usage',
1.291 raeburn 19486: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 19487: dh => 'All with domain helpdesk role',
19488: da => 'All with domain helpdesk assistant role',
1.285 raeburn 19489: none => 'None',
19490: status => 'Determined based on institutional status',
19491: inc => 'Include all, but exclude specific personnel',
19492: exc => 'Exclude all, but include specific personnel',
19493: );
19494: for (my $num=0; $num<=$maxnum; $num++) {
19495: my ($prefix,$identifier,$rolename,%curr);
19496: if ($num == $maxnum) {
19497: next unless ($env{'form.newcusthelp'} == $maxnum);
19498: $identifier = 'custhelp'.$num;
19499: $prefix = 'helproles_'.$num;
19500: $rolename = $env{'form.custhelpname'.$num};
19501: $rolename=~s/[^A-Za-z0-9]//gs;
19502: next if ($rolename eq '');
19503: next if (exists($existing{'rolesdef_'.$rolename}));
19504: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19505: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19506: $newprivs{'c'},$confname,$dom);
19507: if ($result ne 'ok') {
19508: $errors .= '<li><span class="LC_error">'.
19509: &mt('An error occurred storing the new custom role: [_1]',
19510: $result).'</span></li>';
19511: next;
19512: } else {
19513: $changedprivs{$rolename} = \%newprivs;
19514: $newrole = $rolename;
19515: }
19516: } else {
19517: $prefix = 'helproles_'.$num;
19518: $rolename = $env{'form.'.$prefix};
19519: next if ($rolename eq '');
19520: next unless (exists($existing{'rolesdef_'.$rolename}));
19521: $identifier = 'custhelp'.$num;
19522: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19523: my %currprivs;
1.289 raeburn 19524: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 19525: split(/\_/,$existing{'rolesdef_'.$rolename});
19526: foreach my $level ('c','d','s') {
19527: if ($newprivs{$level} ne $currprivs{$level}) {
19528: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19529: $newprivs{'c'},$confname,$dom);
19530: if ($result ne 'ok') {
19531: $errors .= '<li><span class="LC_error">'.
19532: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
19533: $rolename,$result).'</span></li>';
19534: } else {
19535: $changedprivs{$rolename} = \%newprivs;
19536: }
19537: last;
19538: }
19539: }
19540: if (ref($current{'adhoc'}) eq 'HASH') {
19541: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19542: %curr = %{$current{'adhoc'}{$rolename}};
19543: }
19544: }
19545: }
19546: my $newpos = $env{'form.'.$prefix.'_pos'};
19547: $newpos =~ s/\D+//g;
19548: $allpos[$newpos] = $rolename;
19549: my $newdesc = $env{'form.'.$prefix.'_desc'};
19550: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
19551: if ($curr{'desc'}) {
19552: if ($curr{'desc'} ne $newdesc) {
19553: $changes{'customrole'}{$rolename}{'desc'} = 1;
19554: $newsettings{$rolename}{'desc'} = $newdesc;
19555: }
19556: } elsif ($newdesc ne '') {
19557: $changes{'customrole'}{$rolename}{'desc'} = 1;
19558: $newsettings{$rolename}{'desc'} = $newdesc;
19559: }
19560: my $access = $env{'form.'.$prefix.'_access'};
19561: if (grep(/^\Q$access\E$/,@accesstypes)) {
19562: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
19563: if ($access eq 'status') {
19564: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
19565: if (scalar(@statuses) == 0) {
1.289 raeburn 19566: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 19567: } else {
19568: my (@shownstatus,$numtypes);
19569: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19570: if (ref($types) eq 'ARRAY') {
19571: $numtypes = scalar(@{$types});
19572: foreach my $type (sort(@statuses)) {
19573: if ($type eq 'default') {
19574: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19575: } elsif (grep(/^\Q$type\E$/,@{$types})) {
19576: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19577: push(@shownstatus,$usertypes->{$type});
19578: }
19579: }
19580: }
19581: if (grep(/^default$/,@statuses)) {
19582: push(@shownstatus,$othertitle);
19583: }
19584: if (scalar(@shownstatus) == 1+$numtypes) {
19585: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
19586: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
19587: } else {
19588: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
19589: if (ref($curr{'status'}) eq 'ARRAY') {
19590: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19591: if (@diffs) {
19592: $changes{'customrole'}{$rolename}{$access} = 1;
19593: }
19594: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19595: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 19596: }
1.166 raeburn 19597: }
19598: }
1.285 raeburn 19599: } elsif (($access eq 'inc') || ($access eq 'exc')) {
19600: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
19601: my @newspecstaff;
19602: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19603: foreach my $person (sort(@personnel)) {
19604: if ($domhelpdesk{$person}) {
19605: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
19606: }
19607: }
19608: if (ref($curr{$access}) eq 'ARRAY') {
19609: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19610: if (@diffs) {
19611: $changes{'customrole'}{$rolename}{$access} = 1;
19612: }
19613: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19614: $changes{'customrole'}{$rolename}{$access} = 1;
19615: }
19616: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19617: my ($uname,$udom) = split(/:/,$person);
19618: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
19619: }
19620: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 19621: }
1.285 raeburn 19622: } else {
19623: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
19624: }
19625: unless ($curr{'access'} eq $access) {
19626: $changes{'customrole'}{$rolename}{'access'} = 1;
19627: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 19628: }
19629: }
1.285 raeburn 19630: if (@allpos > 0) {
19631: my $idx = 0;
19632: foreach my $rolename (@allpos) {
19633: if ($rolename ne '') {
19634: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
19635: if (ref($current{'adhoc'}) eq 'HASH') {
19636: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19637: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
19638: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 19639: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 19640: }
19641: }
1.282 raeburn 19642: }
1.285 raeburn 19643: $idx ++;
1.166 raeburn 19644: }
19645: }
1.118 jms 19646: }
1.123 jms 19647: my $putresult;
19648: if (keys(%changes) > 0) {
1.166 raeburn 19649: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 19650: if ($putresult eq 'ok') {
1.285 raeburn 19651: if (ref($helphash{'helpsettings'}) eq 'HASH') {
19652: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
19653: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
19654: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
19655: }
19656: }
19657: my $cachetime = 24*60*60;
19658: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19659: if (ref($lastactref) eq 'HASH') {
19660: $lastactref->{'domdefaults'} = 1;
19661: }
19662: } else {
19663: $errors .= '<li><span class="LC_error">'.
19664: &mt('An error occurred storing the settings: [_1]',
19665: $putresult).'</span></li>';
19666: }
19667: }
19668: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
19669: $resulttext = &mt('Changes made:').'<ul>';
19670: my (%shownprivs,@levelorder);
19671: @levelorder = ('c','d','s');
19672: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 19673: foreach my $item (sort(keys(%changes))) {
19674: if ($item eq 'submitbugs') {
19675: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
19676: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
19677: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 19678: } elsif ($item eq 'customrole') {
19679: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 19680: my @keyorder = ('order','desc','access','status','exc','inc');
19681: my %keytext = &Apache::lonlocal::texthash(
19682: order => 'Order',
19683: desc => 'Role description',
19684: access => 'Role usage',
1.300 droeschl 19685: status => 'Allowed institutional types',
1.285 raeburn 19686: exc => 'Allowed personnel',
19687: inc => 'Disallowed personnel',
19688: );
1.282 raeburn 19689: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 19690: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
19691: if ($role eq $newrole) {
19692: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
19693: $role).'<ul>';
19694: } else {
19695: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19696: $role).'<ul>';
19697: }
19698: foreach my $key (@keyorder) {
19699: if ($changes{'customrole'}{$role}{$key}) {
19700: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19701: $keytext{$key},$newsettings{$role}{$key}).
19702: '</li>';
19703: }
19704: }
19705: if (ref($changedprivs{$role}) eq 'HASH') {
19706: $shownprivs{$role} = 1;
19707: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19708: foreach my $level (@levelorder) {
19709: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19710: next if ($item eq '');
19711: my ($priv) = split(/\&/,$item,2);
19712: if (&Apache::lonnet::plaintext($priv)) {
19713: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19714: unless ($level eq 'c') {
19715: $resulttext .= ' ('.$lt{$level}.')';
19716: }
19717: $resulttext .= '</li>';
19718: }
19719: }
19720: }
19721: $resulttext .= '</ul>';
19722: }
19723: $resulttext .= '</ul></li>';
19724: }
19725: }
19726: }
19727: }
19728: }
19729: }
19730: if (keys(%changedprivs)) {
19731: foreach my $role (sort(keys(%changedprivs))) {
19732: unless ($shownprivs{$role}) {
19733: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19734: $role).'<ul>'.
19735: '<li>'.&mt('Privileges set to :').'<ul>';
19736: foreach my $level (@levelorder) {
19737: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19738: next if ($item eq '');
19739: my ($priv) = split(/\&/,$item,2);
19740: if (&Apache::lonnet::plaintext($priv)) {
19741: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19742: unless ($level eq 'c') {
19743: $resulttext .= ' ('.$lt{$level}.')';
19744: }
19745: $resulttext .= '</li>';
19746: }
1.282 raeburn 19747: }
19748: }
1.285 raeburn 19749: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 19750: }
19751: }
19752: }
1.285 raeburn 19753: $resulttext .= '</ul>';
19754: } else {
19755: $resulttext = &mt('No changes made to help settings');
1.118 jms 19756: }
19757: if ($errors) {
1.168 raeburn 19758: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 19759: $errors.'</ul>';
1.118 jms 19760: }
19761: return $resulttext;
19762: }
19763:
1.121 raeburn 19764: sub modify_coursedefaults {
1.212 raeburn 19765: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19766: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 19767: my %defaultchecked = (
19768: 'canuse_pdfforms' => 'off',
19769: 'uselcmath' => 'on',
19770: 'usejsme' => 'on'
19771: );
19772: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 19773: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 19774: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
19775: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19776: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 19777: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 19778: my %staticdefaults = (
19779: anonsurvey_threshold => 10,
19780: uploadquota => 500,
1.257 raeburn 19781: postsubmit => 60,
1.276 raeburn 19782: mysqltables => 172800,
1.198 raeburn 19783: );
1.314 raeburn 19784: my %texoptions = (
19785: MathJax => 'MathJax',
19786: mimetex => &mt('Convert to Images'),
19787: tth => &mt('TeX to HTML'),
19788: );
1.121 raeburn 19789: $defaultshash{'coursedefaults'} = {};
19790:
19791: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19792: if ($domconfig{'coursedefaults'} eq '') {
19793: $domconfig{'coursedefaults'} = {};
19794: }
19795: }
19796:
19797: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19798: foreach my $item (@toggles) {
19799: if ($defaultchecked{$item} eq 'on') {
19800: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19801: ($env{'form.'.$item} eq '0')) {
19802: $changes{$item} = 1;
1.192 raeburn 19803: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19804: $changes{$item} = 1;
19805: }
19806: } elsif ($defaultchecked{$item} eq 'off') {
19807: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19808: ($env{'form.'.$item} eq '1')) {
19809: $changes{$item} = 1;
19810: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19811: $changes{$item} = 1;
19812: }
19813: }
19814: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19815: }
1.198 raeburn 19816: foreach my $item (@numbers) {
19817: my ($currdef,$newdef);
1.208 raeburn 19818: $newdef = $env{'form.'.$item};
1.198 raeburn 19819: if ($item eq 'anonsurvey_threshold') {
19820: $currdef = $domconfig{'coursedefaults'}{$item};
19821: $newdef =~ s/\D//g;
19822: if ($newdef eq '' || $newdef < 1) {
19823: $newdef = 1;
19824: }
19825: $defaultshash{'coursedefaults'}{$item} = $newdef;
19826: } else {
1.276 raeburn 19827: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
19828: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19829: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19830: }
19831: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19832: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19833: }
19834: if ($currdef ne $newdef) {
19835: if ($item eq 'anonsurvey_threshold') {
19836: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19837: $changes{$item} = 1;
19838: }
1.276 raeburn 19839: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19840: my $setting = $1;
1.276 raeburn 19841: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19842: $changes{$setting} = 1;
1.198 raeburn 19843: }
19844: }
1.139 raeburn 19845: }
19846: }
1.314 raeburn 19847: my $texengine;
19848: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19849: $texengine = $env{'form.texengine'};
1.349 raeburn 19850: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19851: if ($currdef eq '') {
19852: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19853: $changes{'texengine'} = 1;
19854: }
1.349 raeburn 19855: } elsif ($currdef ne $texengine) {
1.314 raeburn 19856: $changes{'texengine'} = 1;
19857: }
19858: }
19859: if ($texengine ne '') {
19860: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19861: }
1.264 raeburn 19862: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19863: my @currclonecode;
19864: if (ref($currclone) eq 'HASH') {
19865: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19866: @currclonecode = @{$currclone->{'instcode'}};
19867: }
19868: }
19869: my $newclone;
1.289 raeburn 19870: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19871: $newclone = $env{'form.canclone'};
19872: }
19873: if ($newclone eq 'instcode') {
19874: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19875: my (%codedefaults,@code_order,@clonecode);
19876: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19877: \@code_order);
19878: foreach my $item (@code_order) {
19879: if (grep(/^\Q$item\E$/,@newcodes)) {
19880: push(@clonecode,$item);
19881: }
19882: }
19883: if (@clonecode) {
19884: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19885: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19886: if (@diffs) {
19887: $changes{'canclone'} = 1;
19888: }
19889: } else {
19890: $newclone eq '';
19891: }
19892: } elsif ($newclone ne '') {
1.289 raeburn 19893: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19894: }
1.264 raeburn 19895: if ($newclone ne $currclone) {
19896: $changes{'canclone'} = 1;
19897: }
1.257 raeburn 19898: my %credits;
19899: foreach my $type (@types) {
19900: unless ($type eq 'community') {
19901: $credits{$type} = $env{'form.'.$type.'_credits'};
19902: $credits{$type} =~ s/[^\d.]+//g;
19903: }
19904: }
19905: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19906: ($env{'form.coursecredits'} eq '1')) {
19907: $changes{'coursecredits'} = 1;
19908: foreach my $type (keys(%credits)) {
19909: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19910: }
19911: } else {
1.289 raeburn 19912: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19913: foreach my $type (@types) {
19914: unless ($type eq 'community') {
1.289 raeburn 19915: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19916: $changes{'coursecredits'} = 1;
19917: }
19918: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19919: }
19920: }
19921: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19922: foreach my $type (@types) {
19923: unless ($type eq 'community') {
19924: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19925: $changes{'coursecredits'} = 1;
19926: last;
19927: }
19928: }
19929: }
19930: }
19931: }
19932: if ($env{'form.postsubmit'} eq '1') {
19933: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19934: my %currtimeout;
19935: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19936: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19937: $changes{'postsubmit'} = 1;
19938: }
19939: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19940: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19941: }
19942: } else {
19943: $changes{'postsubmit'} = 1;
19944: }
19945: foreach my $type (@types) {
19946: my $timeout = $env{'form.'.$type.'_timeout'};
19947: $timeout =~ s/\D//g;
19948: if ($timeout == $staticdefaults{'postsubmit'}) {
19949: $timeout = '';
19950: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19951: $timeout = '0';
19952: }
19953: unless ($timeout eq '') {
19954: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19955: }
19956: if (exists($currtimeout{$type})) {
19957: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19958: $changes{'postsubmit'} = 1;
1.257 raeburn 19959: }
19960: } elsif ($timeout ne '') {
19961: $changes{'postsubmit'} = 1;
19962: }
19963: }
19964: } else {
19965: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19966: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19967: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19968: $changes{'postsubmit'} = 1;
19969: }
19970: } else {
19971: $changes{'postsubmit'} = 1;
19972: }
1.192 raeburn 19973: }
1.121 raeburn 19974: }
19975: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19976: $dom);
19977: if ($putresult eq 'ok') {
19978: if (keys(%changes) > 0) {
1.213 raeburn 19979: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19980: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19981: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19982: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19983: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19984: if ($changes{$item}) {
19985: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19986: }
1.289 raeburn 19987: }
1.192 raeburn 19988: if ($changes{'coursecredits'}) {
19989: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19990: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19991: $domdefaults{$type.'credits'} =
19992: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19993: }
19994: }
19995: }
19996: if ($changes{'postsubmit'}) {
19997: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19998: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19999: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20000: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
20001: $domdefaults{$type.'postsubtimeout'} =
20002: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20003: }
20004: }
1.192 raeburn 20005: }
20006: }
1.198 raeburn 20007: if ($changes{'uploadquota'}) {
20008: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20009: foreach my $type (@types) {
20010: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
20011: }
20012: }
20013: }
1.264 raeburn 20014: if ($changes{'canclone'}) {
20015: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20016: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20017: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20018: if (@clonecodes) {
20019: $domdefaults{'canclone'} = join('+',@clonecodes);
20020: }
20021: }
20022: } else {
20023: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20024: }
20025: }
1.121 raeburn 20026: my $cachetime = 24*60*60;
20027: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20028: if (ref($lastactref) eq 'HASH') {
20029: $lastactref->{'domdefaults'} = 1;
20030: }
1.121 raeburn 20031: }
20032: $resulttext = &mt('Changes made:').'<ul>';
20033: foreach my $item (sort(keys(%changes))) {
20034: if ($item eq 'canuse_pdfforms') {
20035: if ($env{'form.'.$item} eq '1') {
20036: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20037: } else {
20038: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20039: }
1.257 raeburn 20040: } elsif ($item eq 'uselcmath') {
20041: if ($env{'form.'.$item} eq '1') {
20042: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20043: } else {
20044: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20045: }
20046: } elsif ($item eq 'usejsme') {
20047: if ($env{'form.'.$item} eq '1') {
20048: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20049: } else {
1.289 raeburn 20050: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20051: }
1.314 raeburn 20052: } elsif ($item eq 'texengine') {
20053: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20054: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20055: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20056: }
1.139 raeburn 20057: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20058: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20059: } elsif ($item eq 'uploadquota') {
20060: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20061: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20062: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20063: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20064: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20065: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20066: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20067: '</ul>'.
20068: '</li>';
20069: } else {
20070: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20071: }
1.276 raeburn 20072: } elsif ($item eq 'mysqltables') {
20073: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20074: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20075: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20076: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20077: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20078: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20079: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20080: '</ul>'.
20081: '</li>';
20082: } else {
20083: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20084: }
1.257 raeburn 20085: } elsif ($item eq 'postsubmit') {
20086: if ($domdefaults{'postsubmit'} eq 'off') {
20087: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20088: } else {
20089: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20090: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20091: $resulttext .= &mt('durations:').'<ul>';
20092: foreach my $type (@types) {
20093: $resulttext .= '<li>';
20094: my $timeout;
20095: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20096: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20097: }
20098: my $display;
20099: if ($timeout eq '0') {
20100: $display = &mt('unlimited');
20101: } elsif ($timeout eq '') {
20102: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20103: } else {
20104: $display = &mt('[quant,_1,second]',$timeout);
20105: }
20106: if ($type eq 'community') {
20107: $resulttext .= &mt('Communities');
20108: } elsif ($type eq 'official') {
20109: $resulttext .= &mt('Official courses');
20110: } elsif ($type eq 'unofficial') {
20111: $resulttext .= &mt('Unofficial courses');
20112: } elsif ($type eq 'textbook') {
20113: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20114: } elsif ($type eq 'placement') {
20115: $resulttext .= &mt('Placement tests');
1.257 raeburn 20116: }
20117: $resulttext .= ' -- '.$display.'</li>';
20118: }
20119: $resulttext .= '</ul>';
20120: }
1.289 raeburn 20121: $resulttext .= '</li>';
1.257 raeburn 20122: }
1.192 raeburn 20123: } elsif ($item eq 'coursecredits') {
20124: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20125: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20126: ($domdefaults{'unofficialcredits'} eq '') &&
20127: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20128: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20129: } else {
20130: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20131: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20132: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20133: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20134: '</ul>'.
20135: '</li>';
20136: }
20137: } else {
20138: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20139: }
1.264 raeburn 20140: } elsif ($item eq 'canclone') {
20141: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20142: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20143: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20144: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20145: }
20146: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20147: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20148: } else {
1.289 raeburn 20149: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20150: }
1.140 raeburn 20151: }
1.121 raeburn 20152: }
20153: $resulttext .= '</ul>';
20154: } else {
20155: $resulttext = &mt('No changes made to course defaults');
20156: }
20157: } else {
20158: $resulttext = '<span class="LC_error">'.
20159: &mt('An error occurred: [_1]',$putresult).'</span>';
20160: }
20161: return $resulttext;
20162: }
20163:
1.231 raeburn 20164: sub modify_selfenrollment {
20165: my ($dom,$lastactref,%domconfig) = @_;
20166: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20167: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20168: my %titles = &tool_titles();
1.232 raeburn 20169: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20170: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20171: $ordered{'default'} = ['types','registered','approval','limit'];
20172:
20173: my (%roles,%shown,%toplevel);
20174: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20175:
20176: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20177: if ($domconfig{'selfenrollment'} eq '') {
20178: $domconfig{'selfenrollment'} = {};
20179: }
20180: }
20181: %toplevel = (
20182: admin => 'Configuration Rights',
20183: default => 'Default settings',
20184: validation => 'Validation of self-enrollment requests',
20185: );
1.233 raeburn 20186: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20187:
20188: if (ref($ordered{'admin'}) eq 'ARRAY') {
20189: foreach my $item (@{$ordered{'admin'}}) {
20190: foreach my $type (@types) {
20191: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20192: $selfenrollhash{'admin'}{$type}{$item} = 1;
20193: } else {
20194: $selfenrollhash{'admin'}{$type}{$item} = 0;
20195: }
20196: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20197: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20198: if ($selfenrollhash{'admin'}{$type}{$item} ne
20199: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20200: push(@{$changes{'admin'}{$type}},$item);
20201: }
20202: } else {
20203: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20204: push(@{$changes{'admin'}{$type}},$item);
20205: }
20206: }
20207: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20208: push(@{$changes{'admin'}{$type}},$item);
20209: }
20210: }
20211: }
20212: }
20213:
20214: foreach my $item (@{$ordered{'default'}}) {
20215: foreach my $type (@types) {
20216: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20217: if ($item eq 'types') {
20218: unless (($value eq 'all') || ($value eq 'dom')) {
20219: $value = '';
20220: }
20221: } elsif ($item eq 'registered') {
20222: unless ($value eq '1') {
20223: $value = 0;
20224: }
20225: } elsif ($item eq 'approval') {
20226: unless ($value =~ /^[012]$/) {
20227: $value = 0;
20228: }
20229: } else {
20230: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20231: $value = 'none';
20232: }
20233: }
20234: $selfenrollhash{'default'}{$type}{$item} = $value;
20235: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20236: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20237: if ($selfenrollhash{'default'}{$type}{$item} ne
20238: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20239: push(@{$changes{'default'}{$type}},$item);
20240: }
20241: } else {
20242: push(@{$changes{'default'}{$type}},$item);
20243: }
20244: } else {
20245: push(@{$changes{'default'}{$type}},$item);
20246: }
20247: if ($item eq 'limit') {
20248: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20249: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20250: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20251: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20252: }
20253: } else {
20254: $selfenrollhash{'default'}{$type}{'cap'} = '';
20255: }
20256: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20257: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20258: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20259: push(@{$changes{'default'}{$type}},'cap');
20260: }
20261: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20262: push(@{$changes{'default'}{$type}},'cap');
20263: }
20264: }
20265: }
20266: }
20267:
20268: foreach my $item (@{$itemsref}) {
20269: if ($item eq 'fields') {
20270: my @changed;
20271: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20272: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20273: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20274: }
20275: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20276: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20277: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20278: $domconfig{'selfenrollment'}{'validation'}{$item});
20279: } else {
20280: @changed = @{$selfenrollhash{'validation'}{$item}};
20281: }
20282: } else {
20283: @changed = @{$selfenrollhash{'validation'}{$item}};
20284: }
20285: if (@changed) {
20286: if ($selfenrollhash{'validation'}{$item}) {
20287: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20288: } else {
20289: $changes{'validation'}{$item} = &mt('None');
20290: }
20291: }
20292: } else {
20293: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20294: if ($item eq 'markup') {
20295: if ($env{'form.selfenroll_validation_'.$item}) {
20296: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20297: }
20298: }
20299: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20300: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20301: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20302: }
20303: }
20304: }
20305: }
20306:
20307: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20308: $dom);
20309: if ($putresult eq 'ok') {
20310: if (keys(%changes) > 0) {
20311: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20312: $resulttext = &mt('Changes made:').'<ul>';
20313: foreach my $key ('admin','default','validation') {
20314: if (ref($changes{$key}) eq 'HASH') {
20315: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20316: if ($key eq 'validation') {
20317: foreach my $item (@{$itemsref}) {
20318: if (exists($changes{$key}{$item})) {
20319: if ($item eq 'markup') {
20320: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20321: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20322: } else {
20323: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20324: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20325: }
20326: }
20327: }
20328: } else {
20329: foreach my $type (@types) {
20330: if ($type eq 'community') {
20331: $roles{'1'} = &mt('Community personnel');
20332: } else {
20333: $roles{'1'} = &mt('Course personnel');
20334: }
20335: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20336: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20337: if ($key eq 'admin') {
20338: my @mgrdc = ();
20339: if (ref($ordered{$key}) eq 'ARRAY') {
20340: foreach my $item (@{$ordered{'admin'}}) {
20341: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20342: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20343: push(@mgrdc,$item);
20344: }
20345: }
20346: }
20347: if (@mgrdc) {
20348: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20349: } else {
20350: delete($domdefaults{$type.'selfenrolladmdc'});
20351: }
20352: }
20353: } else {
20354: if (ref($ordered{$key}) eq 'ARRAY') {
20355: foreach my $item (@{$ordered{$key}}) {
20356: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20357: $domdefaults{$type.'selfenroll'.$item} =
20358: $selfenrollhash{$key}{$type}{$item};
20359: }
20360: }
20361: }
20362: }
20363: }
1.231 raeburn 20364: $resulttext .= '<li>'.$titles{$type}.'<ul>';
20365: foreach my $item (@{$ordered{$key}}) {
20366: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20367: $resulttext .= '<li>';
20368: if ($key eq 'admin') {
20369: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
20370: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
20371: } else {
20372: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
20373: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
20374: }
20375: $resulttext .= '</li>';
20376: }
20377: }
20378: $resulttext .= '</ul></li>';
20379: }
20380: }
20381: $resulttext .= '</ul></li>';
20382: }
20383: }
1.305 raeburn 20384: }
20385: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
20386: my $cachetime = 24*60*60;
20387: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20388: if (ref($lastactref) eq 'HASH') {
20389: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 20390: }
1.231 raeburn 20391: }
20392: $resulttext .= '</ul>';
20393: } else {
20394: $resulttext = &mt('No changes made to self-enrollment settings');
20395: }
20396: } else {
20397: $resulttext = '<span class="LC_error">'.
20398: &mt('An error occurred: [_1]',$putresult).'</span>';
20399: }
20400: return $resulttext;
20401: }
20402:
1.373 raeburn 20403: sub modify_wafproxy {
20404: my ($dom,$action,$lastactref,%domconfig) = @_;
20405: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 20406: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
20407: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 20408: foreach my $server (sort(keys(%servers))) {
20409: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20410: if ($serverhome eq $server) {
20411: my $serverdom = &Apache::lonnet::host_domain($server);
20412: if ($serverdom eq $dom) {
20413: $canset{$server} = 1;
20414: }
20415: }
20416: }
1.381 raeburn 20417: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
20418: %{$values{$dom}} = ();
20419: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
20420: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
20421: }
1.388 raeburn 20422: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
20423: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
20424: }
1.382 raeburn 20425: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 20426: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
20427: }
20428: }
1.373 raeburn 20429: my $output;
20430: if (keys(%canset)) {
20431: %{$wafproxy{'alias'}} = ();
1.388 raeburn 20432: %{$wafproxy{'saml'}} = ();
1.373 raeburn 20433: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 20434: if ($env{'form.wafproxy_'.$dom}) {
20435: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
20436: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
20437: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
20438: $changes{'alias'} = 1;
20439: }
1.388 raeburn 20440: if ($env{'form.wafproxy_alias_saml_'.$key}) {
20441: $wafproxy{'saml'}{$key} = 1;
20442: }
20443: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
20444: $changes{'saml'} = 1;
20445: }
1.381 raeburn 20446: } else {
20447: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 20448: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 20449: if ($curralias{$key}) {
20450: $changes{'alias'} = 1;
20451: }
1.388 raeburn 20452: if ($currsaml{$key}) {
20453: $changes{'saml'} = 1;
20454: }
1.373 raeburn 20455: }
20456: if ($wafproxy{'alias'}{$key} eq '') {
20457: if ($curralias{$key}) {
20458: $expirecache{$key} = 1;
20459: }
20460: delete($wafproxy{'alias'}{$key});
20461: }
1.388 raeburn 20462: if ($wafproxy{'saml'}{$key} eq '') {
20463: if ($currsaml{$key}) {
20464: $expiresaml{$key} = 1;
20465: }
20466: delete($wafproxy{'saml'}{$key});
20467: }
1.373 raeburn 20468: }
20469: unless (keys(%{$wafproxy{'alias'}})) {
20470: delete($wafproxy{'alias'});
20471: }
1.388 raeburn 20472: unless (keys(%{$wafproxy{'saml'}})) {
20473: delete($wafproxy{'saml'});
20474: }
20475: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 20476: my %warn = (
20477: trusted => 'trusted IP range(s)',
1.381 raeburn 20478: vpnint => 'internal IP range(s) for VPN sessions(s)',
20479: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 20480: );
1.382 raeburn 20481: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20482: my $possible = $env{'form.wafproxy_'.$item};
20483: $possible =~ s/^\s+|\s+$//g;
20484: if ($possible ne '') {
1.381 raeburn 20485: if ($item eq 'remoteip') {
20486: if ($possible =~ /^[mhn]$/) {
20487: $wafproxy{$item} = $possible;
20488: }
20489: } elsif ($item eq 'ipheader') {
20490: if ($wafproxy{'remoteip'} eq 'h') {
20491: $wafproxy{$item} = $possible;
20492: }
1.382 raeburn 20493: } elsif ($item eq 'sslopt') {
20494: if ($possible =~ /^0|1$/) {
20495: $wafproxy{$item} = $possible;
20496: }
1.373 raeburn 20497: } else {
20498: my (@ok,$count);
1.381 raeburn 20499: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
20500: unless ($env{'form.wafproxy_vpnaccess'}) {
20501: $possible = '';
20502: }
20503: } elsif ($item eq 'trusted') {
20504: unless ($wafproxy{'remoteip'} eq 'h') {
20505: $possible = '';
20506: }
20507: }
20508: unless ($possible eq '') {
20509: $possible =~ s/[\r\n]+/\s/g;
20510: $possible =~ s/\s*-\s*/-/g;
20511: $possible =~ s/\s+/,/g;
20512: }
1.373 raeburn 20513: $count = 0;
1.381 raeburn 20514: if ($possible ne '') {
1.373 raeburn 20515: foreach my $poss (split(/\,/,$possible)) {
20516: $count ++;
20517: if (&validate_ip_pattern($poss)) {
20518: push(@ok,$poss);
20519: }
20520: }
20521: if (@ok) {
20522: $wafproxy{$item} = join(',',@ok);
20523: }
20524: my $diff = $count - scalar(@ok);
20525: if ($diff) {
20526: push(@warnings,'<li>'.
20527: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
20528: $diff,$warn{$item}).
20529: '</li>');
20530: }
20531: }
20532: }
1.381 raeburn 20533: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 20534: $changes{$item} = 1;
20535: }
1.381 raeburn 20536: } elsif ($currvalue{$item}) {
20537: $changes{$item} = 1;
20538: }
20539: }
20540: } else {
20541: if (keys(%curralias)) {
20542: $changes{'alias'} = 1;
1.388 raeburn 20543: }
20544: if (keys(%currsaml)) {
20545: $changes{'saml'} = 1;
1.381 raeburn 20546: }
20547: if (keys(%currvalue)) {
20548: foreach my $key (keys(%currvalue)) {
20549: $changes{$key} = 1;
1.373 raeburn 20550: }
20551: }
20552: }
20553: if (keys(%changes)) {
20554: my %defaultshash = (
20555: wafproxy => \%wafproxy,
20556: );
20557: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20558: $dom);
20559: if ($putresult eq 'ok') {
20560: my $cachetime = 24*60*60;
20561: my (%domdefaults,$updatedomdefs);
1.382 raeburn 20562: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20563: if ($changes{$item}) {
20564: unless ($updatedomdefs) {
20565: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20566: $updatedomdefs = 1;
20567: }
20568: if ($wafproxy{$item}) {
20569: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20570: } elsif (exists($domdefaults{'waf_'.$item})) {
20571: delete($domdefaults{'waf_'.$item});
20572: }
20573: }
20574: }
20575: if ($updatedomdefs) {
20576: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20577: if (ref($lastactref) eq 'HASH') {
20578: $lastactref->{'domdefaults'} = 1;
20579: }
20580: }
20581: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20582: my %updates = %expirecache;
20583: foreach my $key (keys(%expirecache)) {
20584: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20585: }
20586: if (ref($wafproxy{'alias'}) eq 'HASH') {
20587: my $cachetime = 24*60*60;
20588: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20589: $updates{$key} = 1;
20590: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20591: $cachetime);
20592: }
20593: }
20594: if (ref($lastactref) eq 'HASH') {
20595: $lastactref->{'proxyalias'} = \%updates;
20596: }
20597: }
1.388 raeburn 20598: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20599: my %samlupdates = %expiresaml;
20600: foreach my $key (keys(%expiresaml)) {
20601: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20602: }
20603: if (ref($wafproxy{'saml'}) eq 'HASH') {
20604: my $cachetime = 24*60*60;
20605: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20606: $samlupdates{$key} = 1;
20607: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20608: $cachetime);
20609: }
20610: }
20611: if (ref($lastactref) eq 'HASH') {
20612: $lastactref->{'proxysaml'} = \%samlupdates;
20613: }
20614: }
1.373 raeburn 20615: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382 raeburn 20616: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20617: if ($changes{$item}) {
20618: if ($item eq 'alias') {
20619: my $numaliased = 0;
20620: if (ref($wafproxy{'alias'}) eq 'HASH') {
20621: my $shown;
20622: if (keys(%{$wafproxy{'alias'}})) {
20623: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20624: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20625: &Apache::lonnet::hostname($server),
20626: $wafproxy{'alias'}{$server}).'</li>';
20627: $numaliased ++;
20628: }
20629: if ($numaliased) {
20630: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20631: '<ul>'.$shown.'</ul>').'</li>';
20632: }
20633: }
20634: }
20635: unless ($numaliased) {
20636: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20637: }
1.388 raeburn 20638: } elsif ($item eq 'saml') {
20639: my $shown;
20640: if (ref($wafproxy{'saml'}) eq 'HASH') {
20641: if (keys(%{$wafproxy{'saml'}})) {
20642: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20643: }
20644: }
20645: if ($shown) {
20646: $output .= '<li>'.&mt('Alias used by Shibboleth for: [_1]',
20647: $shown).'</li>';
20648: } else {
20649: $output .= '<li>'.&mt('No alias used for Shibboleth').'</li>';
20650: }
1.373 raeburn 20651: } else {
1.381 raeburn 20652: if ($item eq 'remoteip') {
20653: my %ip_methods = &remoteip_methods();
20654: if ($wafproxy{$item} =~ /^[mh]$/) {
20655: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20656: $ip_methods{$wafproxy{$item}}).'</li>';
20657: } else {
20658: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20659: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20660: '</li>';
20661: } else {
20662: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20663: }
20664: }
20665: } elsif ($item eq 'ipheader') {
1.373 raeburn 20666: if ($wafproxy{$item}) {
1.381 raeburn 20667: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 20668: $wafproxy{$item}).'</li>';
20669: } else {
1.381 raeburn 20670: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 20671: }
20672: } elsif ($item eq 'trusted') {
20673: if ($wafproxy{$item}) {
1.381 raeburn 20674: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 20675: $wafproxy{$item}).'</li>';
20676: } else {
20677: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20678: }
1.381 raeburn 20679: } elsif ($item eq 'vpnint') {
20680: if ($wafproxy{$item}) {
20681: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20682: $wafproxy{$item}).'</li>';
20683: } else {
20684: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20685: }
20686: } elsif ($item eq 'vpnext') {
1.373 raeburn 20687: if ($wafproxy{$item}) {
1.381 raeburn 20688: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 20689: $wafproxy{$item}).'</li>';
20690: } else {
1.381 raeburn 20691: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 20692: }
1.382 raeburn 20693: } elsif ($item eq 'sslopt') {
20694: if ($wafproxy{$item}) {
20695: $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>';
20696: } else {
20697: $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>';
20698: }
1.373 raeburn 20699: }
20700: }
20701: }
20702: }
20703: } else {
20704: $output = '<span class="LC_error">'.
20705: &mt('An error occurred: [_1]',$putresult).'</span>';
20706: }
20707: } elsif (keys(%canset)) {
20708: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20709: }
20710: if (@warnings) {
20711: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20712: join("\n",@warnings).'</ul>';
20713: }
20714: return $output;
20715: }
20716:
20717: sub validate_ip_pattern {
20718: my ($pattern) = @_;
20719: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20720: my ($start,$end) = ($1,$2);
20721: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20722: return 1;
20723: }
20724: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
20725: return 1;
20726: }
20727: return
20728: }
20729:
1.137 raeburn 20730: sub modify_usersessions {
1.212 raeburn 20731: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20732: my @hostingtypes = ('version','excludedomain','includedomain');
20733: my @offloadtypes = ('primary','default');
20734: my %types = (
20735: remote => \@hostingtypes,
20736: hosted => \@hostingtypes,
20737: spares => \@offloadtypes,
20738: );
20739: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20740: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 20741: my (%by_ip,%by_location,@intdoms,@instdoms);
20742: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 20743: my @locations = sort(keys(%by_location));
1.137 raeburn 20744: my (%defaultshash,%changes);
20745: foreach my $prefix (@prefixes) {
20746: $defaultshash{'usersessions'}{$prefix} = {};
20747: }
1.212 raeburn 20748: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20749: my $resulttext;
1.138 raeburn 20750: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20751: foreach my $prefix (@prefixes) {
1.145 raeburn 20752: next if ($prefix eq 'spares');
20753: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20754: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20755: if ($type eq 'version') {
20756: my $value = $env{'form.'.$prefix.'_'.$type};
20757: my $okvalue;
20758: if ($value ne '') {
20759: if (grep(/^\Q$value\E$/,@lcversions)) {
20760: $okvalue = $value;
20761: }
20762: }
20763: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20764: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20765: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20766: if ($inuse == 0) {
20767: $changes{$prefix}{$type} = 1;
20768: } else {
20769: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20770: $changes{$prefix}{$type} = 1;
20771: }
20772: if ($okvalue ne '') {
20773: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20774: }
20775: }
20776: } else {
20777: if (($inuse == 1) && ($okvalue ne '')) {
20778: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20779: $changes{$prefix}{$type} = 1;
20780: }
20781: }
20782: } else {
20783: if (($inuse == 1) && ($okvalue ne '')) {
20784: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20785: $changes{$prefix}{$type} = 1;
20786: }
20787: }
20788: } else {
20789: if (($inuse == 1) && ($okvalue ne '')) {
20790: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20791: $changes{$prefix}{$type} = 1;
20792: }
20793: }
20794: } else {
20795: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20796: my @okvals;
20797: foreach my $val (@vals) {
1.138 raeburn 20798: if ($val =~ /:/) {
20799: my @items = split(/:/,$val);
20800: foreach my $item (@items) {
20801: if (ref($by_location{$item}) eq 'ARRAY') {
20802: push(@okvals,$item);
20803: }
20804: }
20805: } else {
20806: if (ref($by_location{$val}) eq 'ARRAY') {
20807: push(@okvals,$val);
20808: }
1.137 raeburn 20809: }
20810: }
20811: @okvals = sort(@okvals);
20812: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20813: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20814: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20815: if ($inuse == 0) {
20816: $changes{$prefix}{$type} = 1;
20817: } else {
20818: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20819: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20820: if (@changed > 0) {
20821: $changes{$prefix}{$type} = 1;
20822: }
20823: }
20824: } else {
20825: if ($inuse == 1) {
20826: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20827: $changes{$prefix}{$type} = 1;
20828: }
20829: }
20830: } else {
20831: if ($inuse == 1) {
20832: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20833: $changes{$prefix}{$type} = 1;
20834: }
20835: }
20836: } else {
20837: if ($inuse == 1) {
20838: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20839: $changes{$prefix}{$type} = 1;
20840: }
20841: }
20842: }
20843: }
20844: }
1.145 raeburn 20845:
20846: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20847: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20848: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20849: my $savespares;
20850:
20851: foreach my $lonhost (sort(keys(%servers))) {
20852: my $serverhomeID =
20853: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20854: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20855: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20856: my %spareschg;
20857: foreach my $type (@{$types{'spares'}}) {
20858: my @okspares;
20859: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20860: foreach my $server (@checked) {
1.152 raeburn 20861: if (&Apache::lonnet::hostname($server) ne '') {
20862: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20863: unless (grep(/^\Q$server\E$/,@okspares)) {
20864: push(@okspares,$server);
20865: }
1.145 raeburn 20866: }
20867: }
20868: }
20869: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20870: my $newspare;
1.152 raeburn 20871: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20872: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20873: $newspare = $new;
20874: }
20875: }
1.152 raeburn 20876: my @spares;
20877: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20878: @spares = sort(@okspares,$newspare);
20879: } else {
20880: @spares = sort(@okspares);
20881: }
20882: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20883: if (ref($spareid{$lonhost}) eq 'HASH') {
20884: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20885: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20886: if (@diffs > 0) {
20887: $spareschg{$type} = 1;
20888: }
20889: }
20890: }
20891: }
20892: if (keys(%spareschg) > 0) {
20893: $changes{'spares'}{$lonhost} = \%spareschg;
20894: }
20895: }
1.261 raeburn 20896: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 20897: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 20898: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20899: my @okoffload;
20900: if (@offloadnow) {
20901: foreach my $server (@offloadnow) {
20902: if (&Apache::lonnet::hostname($server) ne '') {
20903: unless (grep(/^\Q$server\E$/,@okoffload)) {
20904: push(@okoffload,$server);
20905: }
20906: }
20907: }
20908: if (@okoffload) {
20909: foreach my $lonhost (@okoffload) {
20910: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20911: }
20912: }
20913: }
1.371 raeburn 20914: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20915: my @okoffloadoth;
20916: if (@offloadoth) {
20917: foreach my $server (@offloadoth) {
20918: if (&Apache::lonnet::hostname($server) ne '') {
20919: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20920: push(@okoffloadoth,$server);
20921: }
20922: }
20923: }
20924: if (@okoffloadoth) {
20925: foreach my $lonhost (@okoffloadoth) {
20926: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20927: }
20928: }
20929: }
1.145 raeburn 20930: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20931: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20932: if (ref($changes{'spares'}) eq 'HASH') {
20933: if (keys(%{$changes{'spares'}}) > 0) {
20934: $savespares = 1;
20935: }
20936: }
20937: } else {
20938: $savespares = 1;
20939: }
1.371 raeburn 20940: foreach my $offload ('offloadnow','offloadoth') {
20941: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20942: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20943: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20944: $changes{$offload} = 1;
20945: last;
20946: }
1.261 raeburn 20947: }
1.371 raeburn 20948: unless ($changes{$offload}) {
20949: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20950: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20951: $changes{$offload} = 1;
20952: last;
20953: }
1.261 raeburn 20954: }
20955: }
1.371 raeburn 20956: } else {
20957: if (($offload eq 'offloadnow') && (@okoffload)) {
20958: $changes{'offloadnow'} = 1;
20959: }
20960: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20961: $changes{'offloadoth'} = 1;
20962: }
20963: }
20964: }
20965: } else {
20966: if (@okoffload) {
1.261 raeburn 20967: $changes{'offloadnow'} = 1;
20968: }
1.371 raeburn 20969: if (@okoffloadoth) {
20970: $changes{'offloadoth'} = 1;
20971: }
1.145 raeburn 20972: }
1.147 raeburn 20973: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20974: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20975: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20976: $dom);
20977: if ($putresult eq 'ok') {
20978: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20979: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20980: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20981: }
20982: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20983: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20984: }
1.261 raeburn 20985: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20986: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20987: }
1.371 raeburn 20988: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20989: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20990: }
1.137 raeburn 20991: }
20992: my $cachetime = 24*60*60;
20993: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20994: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20995: if (ref($lastactref) eq 'HASH') {
20996: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20997: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20998: }
1.147 raeburn 20999: if (keys(%changes) > 0) {
21000: my %lt = &usersession_titles();
21001: $resulttext = &mt('Changes made:').'<ul>';
21002: foreach my $prefix (@prefixes) {
21003: if (ref($changes{$prefix}) eq 'HASH') {
21004: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21005: if ($prefix eq 'spares') {
21006: if (ref($changes{$prefix}) eq 'HASH') {
21007: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
21008: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 21009: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 21010: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
21011: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 21012: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
21013: foreach my $type (@{$types{$prefix}}) {
21014: if ($changes{$prefix}{$lonhost}{$type}) {
21015: my $offloadto = &mt('None');
21016: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
21017: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21018: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21019: }
1.145 raeburn 21020: }
1.147 raeburn 21021: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21022: }
1.137 raeburn 21023: }
21024: }
1.147 raeburn 21025: $resulttext .= '</li>';
1.137 raeburn 21026: }
21027: }
1.147 raeburn 21028: } else {
21029: foreach my $type (@{$types{$prefix}}) {
21030: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21031: my ($newvalue,$notinuse);
1.147 raeburn 21032: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21033: if (ref($defaultshash{'usersessions'}{$prefix})) {
21034: if ($type eq 'version') {
21035: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21036: } else {
21037: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21038: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21039: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21040: }
21041: } else {
21042: $notinuse = 1;
1.147 raeburn 21043: }
1.145 raeburn 21044: }
21045: }
21046: }
1.147 raeburn 21047: if ($newvalue eq '') {
21048: if ($type eq 'version') {
21049: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21050: } elsif ($notinuse) {
21051: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21052: } else {
21053: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21054: }
1.145 raeburn 21055: } else {
1.147 raeburn 21056: if ($type eq 'version') {
1.344 raeburn 21057: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21058: }
21059: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21060: }
1.137 raeburn 21061: }
21062: }
21063: }
1.147 raeburn 21064: $resulttext .= '</ul>';
1.137 raeburn 21065: }
21066: }
1.261 raeburn 21067: if ($changes{'offloadnow'}) {
21068: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21069: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21070: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21071: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21072: $resulttext .= '<li>'.$lonhost.'</li>';
21073: }
21074: $resulttext .= '</ul>';
21075: } else {
1.371 raeburn 21076: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21077: }
21078: } else {
21079: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21080: }
21081: }
21082: if ($changes{'offloadoth'}) {
21083: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21084: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21085: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21086: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21087: $resulttext .= '<li>'.$lonhost.'</li>';
21088: }
21089: $resulttext .= '</ul>';
21090: } else {
21091: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21092: }
21093: } else {
1.371 raeburn 21094: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21095: }
21096: }
1.147 raeburn 21097: $resulttext .= '</ul>';
21098: } else {
21099: $resulttext = $nochgmsg;
1.137 raeburn 21100: }
21101: } else {
21102: $resulttext = '<span class="LC_error">'.
21103: &mt('An error occurred: [_1]',$putresult).'</span>';
21104: }
21105: } else {
1.147 raeburn 21106: $resulttext = $nochgmsg;
1.137 raeburn 21107: }
21108: return $resulttext;
21109: }
21110:
1.275 raeburn 21111: sub modify_ssl {
21112: my ($dom,$lastactref,%domconfig) = @_;
21113: my (%by_ip,%by_location,@intdoms,@instdoms);
21114: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21115: my @locations = sort(keys(%by_location));
21116: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21117: my (%defaultshash,%changes);
21118: my $action = 'ssl';
1.293 raeburn 21119: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21120: foreach my $prefix (@prefixes) {
21121: $defaultshash{$action}{$prefix} = {};
21122: }
21123: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21124: my $resulttext;
21125: my %iphost = &Apache::lonnet::get_iphost();
21126: my @reptypes = ('certreq','nocertreq');
21127: my @connecttypes = ('dom','intdom','other');
21128: my %types = (
1.293 raeburn 21129: connto => \@connecttypes,
21130: connfrom => \@connecttypes,
21131: replication => \@reptypes,
1.275 raeburn 21132: );
21133: foreach my $prefix (sort(keys(%types))) {
21134: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21135: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21136: my $value = 'yes';
21137: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21138: $value = $env{'form.'.$prefix.'_'.$type};
21139: }
1.335 raeburn 21140: if (ref($domconfig{$action}) eq 'HASH') {
21141: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21142: if ($domconfig{$action}{$prefix}{$type} ne '') {
21143: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21144: $changes{$prefix}{$type} = 1;
21145: }
21146: $defaultshash{$action}{$prefix}{$type} = $value;
21147: } else {
21148: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21149: $changes{$prefix}{$type} = 1;
21150: }
21151: } else {
21152: $defaultshash{$action}{$prefix}{$type} = $value;
21153: $changes{$prefix}{$type} = 1;
21154: }
21155: } else {
21156: $defaultshash{$action}{$prefix}{$type} = $value;
21157: $changes{$prefix}{$type} = 1;
21158: }
21159: if (($type eq 'dom') && (keys(%servers) == 1)) {
21160: delete($changes{$prefix}{$type});
21161: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21162: delete($changes{$prefix}{$type});
21163: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21164: delete($changes{$prefix}{$type});
21165: }
21166: } elsif ($prefix eq 'replication') {
21167: if (@locations > 0) {
21168: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21169: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21170: my @okvals;
21171: foreach my $val (@vals) {
21172: if ($val =~ /:/) {
21173: my @items = split(/:/,$val);
21174: foreach my $item (@items) {
21175: if (ref($by_location{$item}) eq 'ARRAY') {
21176: push(@okvals,$item);
21177: }
21178: }
21179: } else {
21180: if (ref($by_location{$val}) eq 'ARRAY') {
21181: push(@okvals,$val);
21182: }
21183: }
21184: }
21185: @okvals = sort(@okvals);
21186: if (ref($domconfig{$action}) eq 'HASH') {
21187: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21188: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21189: if ($inuse == 0) {
21190: $changes{$prefix}{$type} = 1;
21191: } else {
21192: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21193: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21194: if (@changed > 0) {
21195: $changes{$prefix}{$type} = 1;
21196: }
21197: }
21198: } else {
21199: if ($inuse == 1) {
21200: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21201: $changes{$prefix}{$type} = 1;
21202: }
21203: }
21204: } else {
21205: if ($inuse == 1) {
21206: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21207: $changes{$prefix}{$type} = 1;
21208: }
21209: }
21210: } else {
21211: if ($inuse == 1) {
21212: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21213: $changes{$prefix}{$type} = 1;
21214: }
21215: }
21216: }
21217: }
21218: }
21219: }
1.336 raeburn 21220: if (keys(%changes)) {
21221: foreach my $prefix (keys(%changes)) {
21222: if (ref($changes{$prefix}) eq 'HASH') {
21223: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21224: delete($changes{$prefix});
21225: }
21226: } else {
21227: delete($changes{$prefix});
21228: }
21229: }
21230: }
1.275 raeburn 21231: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21232: if (keys(%changes) > 0) {
21233: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21234: $dom);
21235: if ($putresult eq 'ok') {
21236: if (ref($defaultshash{$action}) eq 'HASH') {
21237: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21238: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21239: }
1.293 raeburn 21240: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21241: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21242: }
21243: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21244: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21245: }
21246: }
21247: my $cachetime = 24*60*60;
21248: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21249: if (ref($lastactref) eq 'HASH') {
21250: $lastactref->{'domdefaults'} = 1;
21251: }
21252: if (keys(%changes) > 0) {
21253: my %titles = &ssl_titles();
21254: $resulttext = &mt('Changes made:').'<ul>';
21255: foreach my $prefix (@prefixes) {
21256: if (ref($changes{$prefix}) eq 'HASH') {
21257: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21258: foreach my $type (@{$types{$prefix}}) {
21259: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21260: my ($newvalue,$notinuse);
1.275 raeburn 21261: if (ref($defaultshash{$action}) eq 'HASH') {
21262: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21263: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21264: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21265: } else {
21266: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21267: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21268: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21269: }
21270: } else {
21271: $notinuse = 1;
1.275 raeburn 21272: }
21273: }
21274: }
1.344 raeburn 21275: if ($notinuse) {
21276: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21277: } elsif ($newvalue eq '') {
1.275 raeburn 21278: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21279: } else {
21280: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21281: }
21282: }
21283: }
21284: }
21285: $resulttext .= '</ul>';
21286: }
21287: }
21288: } else {
21289: $resulttext = $nochgmsg;
21290: }
21291: } else {
21292: $resulttext = '<span class="LC_error">'.
21293: &mt('An error occurred: [_1]',$putresult).'</span>';
21294: }
21295: } else {
21296: $resulttext = $nochgmsg;
21297: }
21298: return $resulttext;
21299: }
21300:
1.279 raeburn 21301: sub modify_trust {
21302: my ($dom,$lastactref,%domconfig) = @_;
21303: my (%by_ip,%by_location,@intdoms,@instdoms);
21304: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21305: my @locations = sort(keys(%by_location));
21306: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21307: my @types = ('exc','inc');
21308: my (%defaultshash,%changes);
21309: foreach my $prefix (@prefixes) {
21310: $defaultshash{'trust'}{$prefix} = {};
21311: }
21312: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21313: my $resulttext;
21314: foreach my $prefix (@prefixes) {
21315: foreach my $type (@types) {
21316: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21317: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21318: my @okvals;
21319: foreach my $val (@vals) {
21320: if ($val =~ /:/) {
21321: my @items = split(/:/,$val);
21322: foreach my $item (@items) {
21323: if (ref($by_location{$item}) eq 'ARRAY') {
21324: push(@okvals,$item);
21325: }
21326: }
21327: } else {
21328: if (ref($by_location{$val}) eq 'ARRAY') {
21329: push(@okvals,$val);
21330: }
21331: }
21332: }
21333: @okvals = sort(@okvals);
21334: if (ref($domconfig{'trust'}) eq 'HASH') {
21335: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21336: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21337: if ($inuse == 0) {
21338: $changes{$prefix}{$type} = 1;
21339: } else {
21340: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21341: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
21342: if (@changed > 0) {
21343: $changes{$prefix}{$type} = 1;
21344: }
21345: }
21346: } else {
21347: if ($inuse == 1) {
21348: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21349: $changes{$prefix}{$type} = 1;
21350: }
21351: }
21352: } else {
21353: if ($inuse == 1) {
21354: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21355: $changes{$prefix}{$type} = 1;
21356: }
21357: }
21358: } else {
21359: if ($inuse == 1) {
21360: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21361: $changes{$prefix}{$type} = 1;
21362: }
21363: }
21364: }
21365: }
21366: my $nochgmsg = &mt('No changes made to trust settings.');
21367: if (keys(%changes) > 0) {
21368: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21369: $dom);
21370: if ($putresult eq 'ok') {
21371: if (ref($defaultshash{'trust'}) eq 'HASH') {
21372: foreach my $prefix (@prefixes) {
21373: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
21374: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
21375: }
21376: }
21377: }
21378: my $cachetime = 24*60*60;
21379: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21380: if (ref($lastactref) eq 'HASH') {
21381: $lastactref->{'domdefaults'} = 1;
21382: }
21383: if (keys(%changes) > 0) {
21384: my %lt = &trust_titles();
21385: $resulttext = &mt('Changes made:').'<ul>';
21386: foreach my $prefix (@prefixes) {
21387: if (ref($changes{$prefix}) eq 'HASH') {
21388: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21389: foreach my $type (@types) {
21390: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21391: my ($newvalue,$notinuse);
1.279 raeburn 21392: if (ref($defaultshash{'trust'}) eq 'HASH') {
21393: if (ref($defaultshash{'trust'}{$prefix})) {
21394: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21395: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
21396: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
21397: }
1.344 raeburn 21398: } else {
21399: $notinuse = 1;
1.279 raeburn 21400: }
21401: }
21402: }
1.344 raeburn 21403: if ($notinuse) {
21404: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
21405: } elsif ($newvalue eq '') {
1.279 raeburn 21406: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21407: } else {
21408: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
21409: }
21410: }
21411: }
21412: $resulttext .= '</ul>';
21413: }
21414: }
21415: $resulttext .= '</ul>';
21416: } else {
21417: $resulttext = $nochgmsg;
21418: }
21419: } else {
21420: $resulttext = '<span class="LC_error">'.
21421: &mt('An error occurred: [_1]',$putresult).'</span>';
21422: }
21423: } else {
21424: $resulttext = $nochgmsg;
21425: }
21426: return $resulttext;
21427: }
21428:
1.150 raeburn 21429: sub modify_loadbalancing {
21430: my ($dom,%domconfig) = @_;
21431: my $primary_id = &Apache::lonnet::domain($dom,'primary');
21432: my $intdom = &Apache::lonnet::internet_dom($primary_id);
21433: my ($othertitle,$usertypes,$types) =
21434: &Apache::loncommon::sorted_inst_types($dom);
21435: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 21436: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 21437: my @sparestypes = ('primary','default');
21438: my %typetitles = &sparestype_titles();
21439: my $resulttext;
1.342 raeburn 21440: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21441: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21442: %existing = %{$domconfig{'loadbalancing'}};
21443: }
21444: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 21445: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 21446: my ($saveloadbalancing,%defaultshash,%changes);
21447: my ($alltypes,$othertypes,$titles) =
21448: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
21449: my %ruletitles = &offloadtype_text();
21450: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
21451: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
21452: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
21453: if ($balancer eq '') {
21454: next;
21455: }
1.210 raeburn 21456: if (!exists($servers{$balancer})) {
1.171 raeburn 21457: if (exists($currbalancer{$balancer})) {
21458: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 21459: }
1.171 raeburn 21460: next;
21461: }
21462: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
21463: push(@{$changes{'delete'}},$balancer);
21464: next;
21465: }
21466: if (!exists($currbalancer{$balancer})) {
21467: push(@{$changes{'add'}},$balancer);
21468: }
21469: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
21470: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
21471: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
21472: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21473: $saveloadbalancing = 1;
21474: }
21475: foreach my $sparetype (@sparestypes) {
21476: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
21477: my @offloadto;
21478: foreach my $target (@targets) {
21479: if (($servers{$target}) && ($target ne $balancer)) {
21480: if ($sparetype eq 'default') {
21481: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
21482: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 21483: }
21484: }
1.171 raeburn 21485: unless(grep(/^\Q$target\E$/,@offloadto)) {
21486: push(@offloadto,$target);
21487: }
1.150 raeburn 21488: }
21489: }
1.284 raeburn 21490: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
21491: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
21492: push(@offloadto,$balancer);
21493: }
21494: }
21495: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 21496: }
1.342 raeburn 21497: if ($env{'form.loadbalancing_cookie_'.$i}) {
21498: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
21499: if (exists($currbalancer{$balancer})) {
21500: unless ($currcookies{$balancer}) {
21501: $changes{'curr'}{$balancer}{'cookie'} = 1;
21502: }
21503: }
21504: } elsif (exists($currbalancer{$balancer})) {
21505: if ($currcookies{$balancer}) {
21506: $changes{'curr'}{$balancer}{'cookie'} = 1;
21507: }
21508: }
1.171 raeburn 21509: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 21510: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21511: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
21512: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 21513: if (@targetdiffs > 0) {
1.171 raeburn 21514: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21515: }
1.171 raeburn 21516: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21517: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21518: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21519: }
21520: }
21521: }
21522: } else {
1.171 raeburn 21523: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 21524: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21525: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21526: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21527: $changes{'curr'}{$balancer}{'targets'} = 1;
21528: }
1.150 raeburn 21529: }
21530: }
1.210 raeburn 21531: }
1.150 raeburn 21532: }
21533: my $ishomedom;
1.171 raeburn 21534: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
21535: $ishomedom = 1;
1.150 raeburn 21536: }
21537: if (ref($alltypes) eq 'ARRAY') {
21538: foreach my $type (@{$alltypes}) {
21539: my $rule;
1.210 raeburn 21540: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 21541: (!$ishomedom)) {
1.171 raeburn 21542: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
21543: }
21544: if ($rule eq 'specific') {
1.255 raeburn 21545: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 21546: if (exists($servers{$specifiedhost})) {
1.255 raeburn 21547: $rule = $specifiedhost;
21548: }
1.150 raeburn 21549: }
1.171 raeburn 21550: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
21551: if (ref($currrules{$balancer}) eq 'HASH') {
21552: if ($rule ne $currrules{$balancer}{$type}) {
21553: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21554: }
21555: } elsif ($rule ne '') {
1.171 raeburn 21556: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21557: }
21558: }
21559: }
1.171 raeburn 21560: }
21561: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
21562: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
21563: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
21564: $defaultshash{'loadbalancing'} = {};
21565: }
21566: my $putresult = &Apache::lonnet::put_dom('configuration',
21567: \%defaultshash,$dom);
21568: if ($putresult eq 'ok') {
21569: if (keys(%changes) > 0) {
1.252 raeburn 21570: my %toupdate;
1.171 raeburn 21571: if (ref($changes{'delete'}) eq 'ARRAY') {
21572: foreach my $balancer (sort(@{$changes{'delete'}})) {
21573: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 21574: $toupdate{$balancer} = 1;
1.150 raeburn 21575: }
1.171 raeburn 21576: }
21577: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 21578: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 21579: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 21580: $toupdate{$balancer} = 1;
1.171 raeburn 21581: }
21582: }
21583: if (ref($changes{'curr'}) eq 'HASH') {
21584: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 21585: $toupdate{$balancer} = 1;
1.171 raeburn 21586: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
21587: if ($changes{'curr'}{$balancer}{'targets'}) {
21588: my %offloadstr;
21589: foreach my $sparetype (@sparestypes) {
21590: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21591: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21592: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21593: }
21594: }
1.150 raeburn 21595: }
1.171 raeburn 21596: if (keys(%offloadstr) == 0) {
21597: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 21598: } else {
1.171 raeburn 21599: my $showoffload;
21600: foreach my $sparetype (@sparestypes) {
21601: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
21602: if (defined($offloadstr{$sparetype})) {
21603: $showoffload .= $offloadstr{$sparetype};
21604: } else {
21605: $showoffload .= &mt('None');
21606: }
21607: $showoffload .= (' 'x3);
21608: }
21609: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 21610: }
21611: }
21612: }
1.171 raeburn 21613: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
21614: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
21615: foreach my $type (@{$alltypes}) {
21616: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
21617: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21618: my $balancetext;
21619: if ($rule eq '') {
21620: $balancetext = $ruletitles{'default'};
1.209 raeburn 21621: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 21622: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 21623: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 21624: foreach my $sparetype (@sparestypes) {
21625: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21626: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21627: }
21628: }
1.253 raeburn 21629: foreach my $item (@{$alltypes}) {
21630: next if ($item =~ /^_LC_ipchange/);
21631: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
21632: if ($hasrule eq 'homeserver') {
21633: map { $toupdate{$_} = 1; } (keys(%libraryservers));
21634: } else {
21635: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
21636: if ($servers{$hasrule}) {
21637: $toupdate{$hasrule} = 1;
21638: }
21639: }
21640: }
21641: }
1.254 raeburn 21642: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
21643: $balancetext = $ruletitles{$rule};
21644: } else {
21645: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21646: $balancetext = $ruletitles{'particular'}.' '.$receiver;
21647: if ($receiver) {
21648: $toupdate{$receiver};
21649: }
21650: }
21651: } else {
21652: $balancetext = $ruletitles{$rule};
1.252 raeburn 21653: }
1.171 raeburn 21654: } else {
21655: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
21656: }
1.210 raeburn 21657: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 21658: }
21659: }
21660: }
21661: }
1.342 raeburn 21662: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 21663: if ($currcookies{$balancer}) {
21664: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
21665: $balancer).'</li>';
21666: } else {
21667: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
21668: $balancer).'</li>';
21669: }
1.342 raeburn 21670: }
1.375 raeburn 21671: }
21672: }
21673: if (keys(%toupdate)) {
21674: my %thismachine;
21675: my $updatedhere;
21676: my $cachetime = 60*60*24;
21677: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
21678: foreach my $lonhost (keys(%toupdate)) {
21679: if ($thismachine{$lonhost}) {
21680: unless ($updatedhere) {
21681: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
21682: $defaultshash{'loadbalancing'},
21683: $cachetime);
21684: $updatedhere = 1;
1.252 raeburn 21685: }
1.375 raeburn 21686: } else {
21687: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
21688: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 21689: }
1.150 raeburn 21690: }
1.171 raeburn 21691: }
21692: if ($resulttext ne '') {
21693: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 21694: } else {
21695: $resulttext = $nochgmsg;
21696: }
21697: } else {
1.171 raeburn 21698: $resulttext = $nochgmsg;
1.150 raeburn 21699: }
21700: } else {
1.171 raeburn 21701: $resulttext = '<span class="LC_error">'.
21702: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 21703: }
21704: } else {
1.171 raeburn 21705: $resulttext = $nochgmsg;
1.150 raeburn 21706: }
21707: return $resulttext;
21708: }
21709:
1.48 raeburn 21710: sub recurse_check {
21711: my ($chkcats,$categories,$depth,$name) = @_;
21712: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
21713: my $chg = 0;
21714: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
21715: my $category = $chkcats->[$depth]{$name}[$j];
21716: my $item;
21717: if ($category eq '') {
21718: $chg ++;
21719: } else {
21720: my $deeper = $depth + 1;
21721: $item = &escape($category).':'.&escape($name).':'.$depth;
21722: if ($chg) {
21723: $categories->{$item} -= $chg;
21724: }
21725: &recurse_check($chkcats,$categories,$deeper,$category);
21726: $deeper --;
21727: }
21728: }
21729: }
21730: return;
21731: }
21732:
21733: sub recurse_cat_deletes {
21734: my ($item,$coursecategories,$deletions) = @_;
21735: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
21736: my $subdepth = $depth + 1;
21737: if (ref($coursecategories) eq 'HASH') {
21738: foreach my $subitem (keys(%{$coursecategories})) {
21739: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
21740: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
21741: delete($coursecategories->{$subitem});
21742: $deletions->{$subitem} = 1;
21743: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 21744: }
1.48 raeburn 21745: }
21746: }
21747: return;
21748: }
21749:
1.125 raeburn 21750: sub active_dc_picker {
1.191 raeburn 21751: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 21752: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 21753: my @domcoord = keys(%domcoords);
21754: if (keys(%currhash)) {
21755: foreach my $dc (keys(%currhash)) {
21756: unless (exists($domcoords{$dc})) {
21757: push(@domcoord,$dc);
21758: }
21759: }
21760: }
21761: @domcoord = sort(@domcoord);
1.210 raeburn 21762: my $numdcs = scalar(@domcoord);
1.191 raeburn 21763: my $rows = 0;
21764: my $table;
1.125 raeburn 21765: if ($numdcs > 1) {
1.191 raeburn 21766: $table = '<table>';
21767: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 21768: my $rem = $i%($numinrow);
21769: if ($rem == 0) {
21770: if ($i > 0) {
1.191 raeburn 21771: $table .= '</tr>';
1.125 raeburn 21772: }
1.191 raeburn 21773: $table .= '<tr>';
21774: $rows ++;
1.125 raeburn 21775: }
1.191 raeburn 21776: my $check = '';
21777: if ($inputtype eq 'radio') {
21778: if (keys(%currhash) == 0) {
21779: if (!$i) {
21780: $check = ' checked="checked"';
21781: }
21782: } elsif (exists($currhash{$domcoord[$i]})) {
21783: $check = ' checked="checked"';
21784: }
21785: } else {
21786: if (exists($currhash{$domcoord[$i]})) {
21787: $check = ' checked="checked"';
1.125 raeburn 21788: }
21789: }
1.191 raeburn 21790: if ($i == @domcoord - 1) {
1.125 raeburn 21791: my $colsleft = $numinrow - $rem;
21792: if ($colsleft > 1) {
1.191 raeburn 21793: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 21794: } else {
1.191 raeburn 21795: $table .= '<td class="LC_left_item">';
1.125 raeburn 21796: }
21797: } else {
1.191 raeburn 21798: $table .= '<td class="LC_left_item">';
21799: }
21800: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
21801: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
21802: $table .= '<span class="LC_nobreak"><label>'.
21803: '<input type="'.$inputtype.'" name="'.$name.'"'.
21804: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
21805: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 21806: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 21807: }
1.219 raeburn 21808: $table .= '</label></span></td>';
1.191 raeburn 21809: }
21810: $table .= '</tr></table>';
21811: } elsif ($numdcs == 1) {
1.219 raeburn 21812: my ($dcname,$dcdom) = split(':',$domcoord[0]);
21813: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 21814: if ($inputtype eq 'radio') {
1.247 raeburn 21815: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 21816: if ($user ne $dcname.':'.$dcdom) {
21817: $table .= ' ('.$dcname.':'.$dcdom.')';
21818: }
1.191 raeburn 21819: } else {
21820: my $check;
21821: if (exists($currhash{$domcoord[0]})) {
21822: $check = ' checked="checked"';
1.125 raeburn 21823: }
1.247 raeburn 21824: $table = '<span class="LC_nobreak"><label>'.
21825: '<input type="checkbox" name="'.$name.'" '.
21826: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 21827: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 21828: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 21829: }
1.220 raeburn 21830: $table .= '</label></span>';
1.191 raeburn 21831: $rows ++;
1.125 raeburn 21832: }
21833: }
1.191 raeburn 21834: return ($numdcs,$table,$rows);
1.125 raeburn 21835: }
21836:
1.137 raeburn 21837: sub usersession_titles {
21838: return &Apache::lonlocal::texthash(
21839: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
21840: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 21841: spares => 'Servers offloaded to, when busy',
1.137 raeburn 21842: version => 'LON-CAPA version requirement',
1.138 raeburn 21843: excludedomain => 'Allow all, but exclude specific domains',
21844: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 21845: primary => 'Primary (checked first)',
1.154 raeburn 21846: default => 'Default',
1.137 raeburn 21847: );
21848: }
21849:
1.152 raeburn 21850: sub id_for_thisdom {
21851: my (%servers) = @_;
21852: my %altids;
21853: foreach my $server (keys(%servers)) {
21854: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21855: if ($serverhome ne $server) {
21856: $altids{$serverhome} = $server;
21857: }
21858: }
21859: return %altids;
21860: }
21861:
1.150 raeburn 21862: sub count_servers {
21863: my ($currbalancer,%servers) = @_;
21864: my (@spares,$numspares);
21865: foreach my $lonhost (sort(keys(%servers))) {
21866: next if ($currbalancer eq $lonhost);
21867: push(@spares,$lonhost);
21868: }
21869: if ($currbalancer) {
21870: $numspares = scalar(@spares);
21871: } else {
21872: $numspares = scalar(@spares) - 1;
21873: }
21874: return ($numspares,@spares);
21875: }
21876:
21877: sub lonbalance_targets_js {
1.171 raeburn 21878: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21879: my $select = &mt('Select');
21880: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21881: if (ref($servers) eq 'HASH') {
21882: $alltargets = join("','",sort(keys(%{$servers})));
21883: my @homedoms;
21884: foreach my $server (sort(keys(%{$servers}))) {
21885: if (&Apache::lonnet::host_domain($server) eq $dom) {
21886: push(@homedoms,'1');
21887: } else {
21888: push(@homedoms,'0');
21889: }
21890: }
21891: $allishome = join("','",@homedoms);
21892: }
21893: if (ref($types) eq 'ARRAY') {
21894: if (@{$types} > 0) {
21895: @alltypes = @{$types};
21896: }
21897: }
21898: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21899: $allinsttypes = join("','",@alltypes);
1.342 raeburn 21900: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21901: if (ref($settings) eq 'HASH') {
21902: %existing = %{$settings};
21903: }
21904: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 21905: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 21906: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21907: return <<"END";
21908:
21909: <script type="text/javascript">
21910: // <![CDATA[
21911:
1.171 raeburn 21912: currBalancers = new Array('$balancers');
21913:
21914: function toggleTargets(balnum) {
21915: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21916: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21917: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21918: var prevbalancer = prevhostitem.value;
21919: var baltotal = document.getElementById('loadbalancing_total').value;
21920: prevhostitem.value = balancer;
21921: if (prevbalancer != '') {
21922: var prevIdx = currBalancers.indexOf(prevbalancer);
21923: if (prevIdx != -1) {
21924: currBalancers.splice(prevIdx,1);
21925: }
21926: }
1.150 raeburn 21927: if (balancer == '') {
1.171 raeburn 21928: hideSpares(balnum);
1.150 raeburn 21929: } else {
1.171 raeburn 21930: var currIdx = currBalancers.indexOf(balancer);
21931: if (currIdx == -1) {
21932: currBalancers.push(balancer);
21933: }
1.150 raeburn 21934: var homedoms = new Array('$allishome');
1.171 raeburn 21935: var ishomedom = homedoms[lonhostitem.selectedIndex];
21936: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21937: }
1.171 raeburn 21938: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21939: return;
21940: }
21941:
1.171 raeburn 21942: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21943: var alltargets = new Array('$alltargets');
21944: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21945: var offloadtypes = new Array('primary','default');
21946:
1.171 raeburn 21947: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21948: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21949:
1.151 raeburn 21950: for (var i=0; i<offloadtypes.length; i++) {
21951: var count = 0;
21952: for (var j=0; j<alltargets.length; j++) {
21953: if (alltargets[j] != balancer) {
1.171 raeburn 21954: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21955: item.value = alltargets[j];
21956: item.style.textAlign='left';
21957: item.style.textFace='normal';
21958: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21959: if (currBalancers.indexOf(alltargets[j]) == -1) {
21960: item.disabled = '';
21961: } else {
21962: item.disabled = 'disabled';
21963: item.checked = false;
21964: }
1.151 raeburn 21965: count ++;
21966: }
1.150 raeburn 21967: }
21968: }
1.151 raeburn 21969: for (var k=0; k<insttypes.length; k++) {
21970: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21971: if (ishomedom == 1) {
1.171 raeburn 21972: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21973: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21974: } else {
1.171 raeburn 21975: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21976: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21977: }
21978: } else {
1.171 raeburn 21979: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21980: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21981: }
1.151 raeburn 21982: if ((insttypes[k] != '_LC_external') &&
21983: ((insttypes[k] != '_LC_internetdom') ||
21984: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21985: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21986: item.options.length = 0;
21987: item.options[0] = new Option("","",true,true);
1.210 raeburn 21988: var idx = 0;
1.151 raeburn 21989: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21990: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21991: idx ++;
21992: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21993: }
21994: }
21995: }
21996: }
21997: return;
21998: }
21999:
1.171 raeburn 22000: function hideSpares(balnum) {
1.150 raeburn 22001: var alltargets = new Array('$alltargets');
22002: var insttypes = new Array('$allinsttypes');
22003: var offloadtypes = new Array('primary','default');
22004:
1.171 raeburn 22005: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
22006: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 22007:
22008: var total = alltargets.length - 1;
22009: for (var i=0; i<offloadtypes; i++) {
22010: for (var j=0; j<total; j++) {
1.171 raeburn 22011: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
22012: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
22013: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 22014: }
1.150 raeburn 22015: }
22016: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 22017: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22018: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22019: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22020: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22021: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22022: }
22023: }
22024: return;
22025: }
22026:
1.171 raeburn 22027: function checkOffloads(item,balnum,type) {
1.150 raeburn 22028: var alltargets = new Array('$alltargets');
22029: var offloadtypes = new Array('primary','default');
22030: if (item.checked) {
22031: var total = alltargets.length - 1;
22032: var other;
22033: if (type == offloadtypes[0]) {
1.151 raeburn 22034: other = offloadtypes[1];
1.150 raeburn 22035: } else {
1.151 raeburn 22036: other = offloadtypes[0];
1.150 raeburn 22037: }
22038: for (var i=0; i<total; i++) {
1.171 raeburn 22039: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22040: if (server == item.value) {
1.171 raeburn 22041: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22042: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22043: }
22044: }
22045: }
22046: }
22047: return;
22048: }
22049:
1.171 raeburn 22050: function singleServerToggle(balnum,type) {
22051: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22052: if (offloadtoSelIdx == 0) {
1.171 raeburn 22053: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22054: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22055:
22056: } else {
1.171 raeburn 22057: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22058: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22059: }
22060: return;
22061: }
22062:
1.171 raeburn 22063: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22064: if (type == '_LC_external') {
1.171 raeburn 22065: return;
1.150 raeburn 22066: }
1.171 raeburn 22067: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22068: for (var i=0; i<typesRules.length; i++) {
22069: if (formname.elements[typesRules[i]].checked) {
22070: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22071: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22072: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22073: } else {
1.171 raeburn 22074: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22075: }
22076: }
22077: }
22078: return;
22079: }
22080:
22081: function balancerDeleteChange(balnum) {
22082: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22083: var baltotal = document.getElementById('loadbalancing_total').value;
22084: var addtarget;
22085: var removetarget;
22086: var action = 'delete';
22087: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22088: var lonhost = hostitem.value;
22089: var currIdx = currBalancers.indexOf(lonhost);
22090: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22091: if (currIdx != -1) {
22092: currBalancers.splice(currIdx,1);
22093: }
22094: addtarget = lonhost;
22095: } else {
22096: if (currIdx == -1) {
22097: currBalancers.push(lonhost);
22098: }
22099: removetarget = lonhost;
22100: action = 'undelete';
22101: }
22102: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22103: }
22104: return;
22105: }
22106:
22107: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22108: if (baltotal > 1) {
22109: var offloadtypes = new Array('primary','default');
22110: var alltargets = new Array('$alltargets');
22111: var insttypes = new Array('$allinsttypes');
22112: for (var i=0; i<baltotal; i++) {
22113: if (i != balnum) {
22114: for (var j=0; j<offloadtypes.length; j++) {
22115: var total = alltargets.length - 1;
22116: for (var k=0; k<total; k++) {
22117: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22118: var server = serveritem.value;
22119: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22120: if (server == addtarget) {
22121: serveritem.disabled = '';
22122: }
22123: }
22124: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22125: if (server == removetarget) {
22126: serveritem.disabled = 'disabled';
22127: serveritem.checked = false;
22128: }
22129: }
22130: }
22131: }
22132: for (var j=0; j<insttypes.length; j++) {
22133: if (insttypes[j] != '_LC_external') {
22134: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22135: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22136: var currSel = singleserver.selectedIndex;
22137: var currVal = singleserver.options[currSel].value;
22138: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22139: var numoptions = singleserver.options.length;
22140: var needsnew = 1;
22141: for (var k=0; k<numoptions; k++) {
22142: if (singleserver.options[k] == addtarget) {
22143: needsnew = 0;
22144: break;
22145: }
22146: }
22147: if (needsnew == 1) {
22148: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22149: }
22150: }
22151: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22152: singleserver.options.length = 0;
22153: if ((currVal) && (currVal != removetarget)) {
22154: singleserver.options[0] = new Option("","",false,false);
22155: } else {
22156: singleserver.options[0] = new Option("","",true,true);
22157: }
22158: var idx = 0;
22159: for (var m=0; m<alltargets.length; m++) {
22160: if (currBalancers.indexOf(alltargets[m]) == -1) {
22161: idx ++;
22162: if (currVal == alltargets[m]) {
22163: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22164: } else {
22165: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22166: }
22167: }
22168: }
22169: }
22170: }
22171: }
22172: }
1.150 raeburn 22173: }
22174: }
22175: }
22176: return;
22177: }
22178:
1.152 raeburn 22179: // ]]>
22180: </script>
22181:
22182: END
22183: }
22184:
1.372 raeburn 22185:
1.152 raeburn 22186: sub new_spares_js {
22187: my @sparestypes = ('primary','default');
22188: my $types = join("','",@sparestypes);
22189: my $select = &mt('Select');
22190: return <<"END";
22191:
22192: <script type="text/javascript">
22193: // <![CDATA[
22194:
22195: function updateNewSpares(formname,lonhost) {
22196: var types = new Array('$types');
22197: var include = new Array();
22198: var exclude = new Array();
22199: for (var i=0; i<types.length; i++) {
22200: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22201: for (var j=0; j<spareboxes.length; j++) {
22202: if (formname.elements[spareboxes[j]].checked) {
22203: exclude.push(formname.elements[spareboxes[j]].value);
22204: } else {
22205: include.push(formname.elements[spareboxes[j]].value);
22206: }
22207: }
22208: }
22209: for (var i=0; i<types.length; i++) {
22210: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22211: var selIdx = newSpare.selectedIndex;
22212: var currnew = newSpare.options[selIdx].value;
22213: var okSpares = new Array();
22214: for (var j=0; j<newSpare.options.length; j++) {
22215: var possible = newSpare.options[j].value;
22216: if (possible != '') {
22217: if (exclude.indexOf(possible) == -1) {
22218: okSpares.push(possible);
22219: } else {
22220: if (currnew == possible) {
22221: selIdx = 0;
22222: }
22223: }
22224: }
22225: }
22226: for (var k=0; k<include.length; k++) {
22227: if (okSpares.indexOf(include[k]) == -1) {
22228: okSpares.push(include[k]);
22229: }
22230: }
22231: okSpares.sort();
22232: newSpare.options.length = 0;
22233: if (selIdx == 0) {
22234: newSpare.options[0] = new Option("$select","",true,true);
22235: } else {
22236: newSpare.options[0] = new Option("$select","",false,false);
22237: }
22238: for (var m=0; m<okSpares.length; m++) {
22239: var idx = m+1;
22240: var selThis = 0;
22241: if (selIdx != 0) {
22242: if (okSpares[m] == currnew) {
22243: selThis = 1;
22244: }
22245: }
22246: if (selThis == 1) {
22247: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22248: } else {
22249: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22250: }
22251: }
22252: }
22253: return;
22254: }
22255:
22256: function checkNewSpares(lonhost,type) {
22257: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22258: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22259: if (chosen != '') {
1.152 raeburn 22260: var othertype;
22261: var othernewSpare;
22262: if (type == 'primary') {
22263: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22264: }
22265: if (type == 'default') {
22266: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22267: }
22268: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22269: othernewSpare.selectedIndex = 0;
22270: }
22271: }
22272: return;
22273: }
22274:
22275: // ]]>
22276: </script>
22277:
22278: END
22279:
22280: }
22281:
22282: sub common_domprefs_js {
22283: return <<"END";
22284:
22285: <script type="text/javascript">
22286: // <![CDATA[
22287:
1.150 raeburn 22288: function getIndicesByName(formname,item) {
1.152 raeburn 22289: var group = new Array();
1.150 raeburn 22290: for (var i=0;i<formname.elements.length;i++) {
22291: if (formname.elements[i].name == item) {
1.152 raeburn 22292: group.push(formname.elements[i].id);
1.150 raeburn 22293: }
22294: }
1.152 raeburn 22295: return group;
1.150 raeburn 22296: }
22297:
22298: // ]]>
22299: </script>
22300:
22301: END
1.152 raeburn 22302:
1.150 raeburn 22303: }
22304:
1.165 raeburn 22305: sub recaptcha_js {
22306: my %lt = &captcha_phrases();
22307: return <<"END";
22308:
22309: <script type="text/javascript">
22310: // <![CDATA[
22311:
22312: function updateCaptcha(caller,context) {
22313: var privitem;
22314: var pubitem;
22315: var privtext;
22316: var pubtext;
1.269 raeburn 22317: var versionitem;
22318: var versiontext;
1.165 raeburn 22319: if (document.getElementById(context+'_recaptchapub')) {
22320: pubitem = document.getElementById(context+'_recaptchapub');
22321: } else {
22322: return;
22323: }
22324: if (document.getElementById(context+'_recaptchapriv')) {
22325: privitem = document.getElementById(context+'_recaptchapriv');
22326: } else {
22327: return;
22328: }
22329: if (document.getElementById(context+'_recaptchapubtxt')) {
22330: pubtext = document.getElementById(context+'_recaptchapubtxt');
22331: } else {
22332: return;
22333: }
22334: if (document.getElementById(context+'_recaptchaprivtxt')) {
22335: privtext = document.getElementById(context+'_recaptchaprivtxt');
22336: } else {
22337: return;
22338: }
1.269 raeburn 22339: if (document.getElementById(context+'_recaptchaversion')) {
22340: versionitem = document.getElementById(context+'_recaptchaversion');
22341: } else {
22342: return;
22343: }
22344: if (document.getElementById(context+'_recaptchavertxt')) {
22345: versiontext = document.getElementById(context+'_recaptchavertxt');
22346: } else {
22347: return;
22348: }
1.165 raeburn 22349: if (caller.checked) {
22350: if (caller.value == 'recaptcha') {
22351: pubitem.type = 'text';
22352: privitem.type = 'text';
22353: pubitem.size = '40';
22354: privitem.size = '40';
22355: pubtext.innerHTML = "$lt{'pub'}";
22356: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 22357: versionitem.type = 'text';
22358: versionitem.size = '3';
1.289 raeburn 22359: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 22360: } else {
22361: pubitem.type = 'hidden';
22362: privitem.type = 'hidden';
1.269 raeburn 22363: versionitem.type = 'hidden';
1.165 raeburn 22364: pubtext.innerHTML = '';
22365: privtext.innerHTML = '';
1.269 raeburn 22366: versiontext.innerHTML = '';
1.165 raeburn 22367: }
22368: }
22369: return;
22370: }
22371:
22372: // ]]>
22373: </script>
22374:
22375: END
22376:
22377: }
22378:
1.236 raeburn 22379: sub toggle_display_js {
1.192 raeburn 22380: return <<"END";
22381:
22382: <script type="text/javascript">
22383: // <![CDATA[
22384:
1.236 raeburn 22385: function toggleDisplay(domForm,caller) {
22386: if (document.getElementById(caller)) {
22387: var divitem = document.getElementById(caller);
22388: var optionsElement = domForm.coursecredits;
1.264 raeburn 22389: var checkval = 1;
22390: var dispval = 'block';
1.303 raeburn 22391: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 22392: if (caller == 'emailoptions') {
1.372 raeburn 22393: optionsElement = domForm.cancreate_email;
1.236 raeburn 22394: }
1.257 raeburn 22395: if (caller == 'studentsubmission') {
22396: optionsElement = domForm.postsubmit;
22397: }
1.264 raeburn 22398: if (caller == 'cloneinstcode') {
22399: optionsElement = domForm.canclone;
22400: checkval = 'instcode';
22401: }
1.303 raeburn 22402: if (selfcreateRegExp.test(caller)) {
22403: optionsElement = domForm.elements[caller];
22404: checkval = 'other';
22405: dispval = 'inline'
22406: }
1.236 raeburn 22407: if (optionsElement.length) {
1.192 raeburn 22408: var currval;
1.236 raeburn 22409: for (var i=0; i<optionsElement.length; i++) {
22410: if (optionsElement[i].checked) {
22411: currval = optionsElement[i].value;
1.192 raeburn 22412: }
22413: }
1.264 raeburn 22414: if (currval == checkval) {
22415: divitem.style.display = dispval;
1.192 raeburn 22416: } else {
1.236 raeburn 22417: divitem.style.display = 'none';
1.192 raeburn 22418: }
22419: }
22420: }
22421: return;
22422: }
22423:
22424: // ]]>
22425: </script>
22426:
22427: END
22428:
22429: }
22430:
1.165 raeburn 22431: sub captcha_phrases {
22432: return &Apache::lonlocal::texthash (
22433: priv => 'Private key',
22434: pub => 'Public key',
22435: original => 'original (CAPTCHA)',
22436: recaptcha => 'successor (ReCAPTCHA)',
22437: notused => 'unused',
1.289 raeburn 22438: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 22439: );
22440: }
22441:
1.205 raeburn 22442: sub devalidate_remote_domconfs {
1.212 raeburn 22443: my ($dom,$cachekeys) = @_;
22444: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 22445: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22446: my %thismachine;
22447: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 22448: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.388 raeburn 22449: 'directorysrch','passwdconf','cats','proxyalias','proxysaml');
1.386 raeburn 22450: my %cache_by_lonhost;
22451: if (exists($cachekeys->{'samllanding'})) {
22452: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
22453: my %landing = %{$cachekeys->{'samllanding'}};
22454: my %domservers = &Apache::lonnet::get_servers($dom);
22455: if (keys(%domservers)) {
22456: foreach my $server (keys(%domservers)) {
22457: my @cached;
22458: next if ($thismachine{$server});
22459: if ($landing{$server}) {
22460: push(@cached,&escape('samllanding').':'.&escape($server));
22461: }
22462: if (@cached) {
22463: $cache_by_lonhost{$server} = \@cached;
22464: }
22465: }
22466: }
22467: }
22468: }
1.260 raeburn 22469: if (keys(%servers)) {
1.205 raeburn 22470: foreach my $server (keys(%servers)) {
22471: next if ($thismachine{$server});
1.212 raeburn 22472: my @cached;
22473: foreach my $name (@posscached) {
22474: if ($cachekeys->{$name}) {
1.388 raeburn 22475: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 22476: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 22477: foreach my $key (keys(%{$cachekeys->{$name}})) {
22478: push(@cached,&escape($name).':'.&escape($key));
22479: }
22480: }
22481: } else {
22482: push(@cached,&escape($name).':'.&escape($dom));
22483: }
1.212 raeburn 22484: }
22485: }
1.386 raeburn 22486: if ((exists($cache_by_lonhost{$server})) &&
22487: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
22488: push(@cached,@{$cache_by_lonhost{$server}});
22489: }
1.212 raeburn 22490: if (@cached) {
22491: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
22492: }
1.205 raeburn 22493: }
22494: }
22495: return;
22496: }
22497:
1.3 raeburn 22498: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>