Annotation of loncom/interface/domainprefs.pm, revision 1.390
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.390 ! raeburn 4: # $Id: domainprefs.pm,v 1.389 2021/11/03 13:49:57 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.320 raeburn 3252: return <<"ENDSCRIPT";
3253: <script type="text/javascript">
3254: // <![CDATA[
3255:
3256: function toggleLTI(form,setting,item) {
1.345 raeburn 3257: if (setting == 'requser') {
3258: var fieldsets = document.getElementsByClassName('ltioption_'+item);
3259: if (fieldsets.length) {
3260: var radioname = 'lti_'+setting+'_'+item;
3261: var num = form.elements[radioname].length;
3262: if (num) {
3263: var setvis = '';
3264: for (var i=0; i<num; i++) {
3265: if (form.elements[radioname][i].checked) {
3266: if (form.elements[radioname][i].value == '1') {
3267: setvis = 1;
3268: break;
3269: }
3270: }
3271: }
1.352 raeburn 3272: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 3273: if (setvis) {
3274: fieldsets[j].style.display = 'block';
3275: } else {
3276: fieldsets[j].style.display = 'none';
3277: }
3278: }
3279: }
3280: }
1.363 raeburn 3281: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3282: var radioname = '';
3283: var divid = '';
3284: if (setting == 'user') {
3285: radioname = 'lti_mapuser_'+item;
3286: divid = 'lti_userfield_'+item;
1.343 raeburn 3287: } else if (setting == 'crs') {
1.320 raeburn 3288: radioname = 'lti_mapcrs_'+item;
3289: divid = 'lti_crsfield_'+item;
1.363 raeburn 3290: } else if (setting == 'callback') {
3291: radioname = 'lti_callback_'+item;
3292: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3293: } else {
1.351 raeburn 3294: radioname = 'lti_passback_'+item;
1.337 raeburn 3295: divid = 'lti_passback_'+item;
1.320 raeburn 3296: }
3297: var num = form.elements[radioname].length;
3298: if (num) {
3299: var setvis = '';
3300: for (var i=0; i<num; i++) {
3301: if (form.elements[radioname][i].checked) {
1.363 raeburn 3302: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3303: if (form.elements[radioname][i].value == '1') {
3304: if (document.getElementById(divid)) {
3305: document.getElementById(divid).style.display = 'inline-block';
3306: }
3307: setvis = 1;
3308: break;
3309: }
3310: } else {
3311: if (form.elements[radioname][i].value == 'other') {
3312: if (document.getElementById(divid)) {
3313: document.getElementById(divid).style.display = 'inline-block';
3314: }
3315: setvis = 1;
3316: break;
1.320 raeburn 3317: }
3318: }
3319: }
3320: }
3321: if (!setvis) {
3322: if (document.getElementById(divid)) {
3323: document.getElementById(divid).style.display = 'none';
3324: }
3325: }
3326: }
3327: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3328: var numsec = form.elements['lti_crssec_'+item].length;
3329: if (numsec) {
3330: var setvis = '';
3331: for (var i=0; i<numsec; i++) {
3332: if (form.elements['lti_crssec_'+item][i].checked) {
3333: if (form.elements['lti_crssec_'+item][i].value == '1') {
3334: if (document.getElementById('lti_crssecfield_'+item)) {
3335: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3336: setvis = 1;
3337: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3338: if (numsrcsec) {
3339: var setsrcvis = '';
3340: for (var j=0; j<numsrcsec; j++) {
3341: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3342: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3343: if (document.getElementById('lti_secsrcfield_'+item)) {
3344: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3345: setsrcvis = 1;
3346: }
3347: }
3348: }
3349: }
3350: if (!setsrcvis) {
3351: if (document.getElementById('lti_secsrcfield_'+item)) {
3352: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3353: }
3354: }
3355: }
3356: }
3357: }
3358: }
3359: }
3360: if (!setvis) {
3361: if (document.getElementById('lti_crssecfield_'+item)) {
3362: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3363: }
3364: if (document.getElementById('lti_secsrcfield_'+item)) {
3365: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3366: }
3367: }
3368: }
1.325 raeburn 3369: } else if (setting == 'lcauth') {
3370: var numauth = form.elements['lti_lcauth_'+item].length;
3371: if (numauth) {
3372: for (var i=0; i<numauth; i++) {
3373: if (form.elements['lti_lcauth_'+item][i].checked) {
3374: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3375: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3376: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3377: } else {
3378: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3379: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3380: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3381: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3382: } else {
3383: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3384: }
3385: }
3386: }
3387: }
3388: }
3389: }
3390: }
1.326 raeburn 3391: } else if (setting == 'lcmenu') {
3392: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3393: var divid = 'lti_menufield_'+item;
3394: var setvis = '';
3395: for (var i=0; i<menus.length; i++) {
3396: var radioname = menus[i];
3397: var num = form.elements[radioname].length;
3398: if (num) {
3399: for (var j=0; j<num; j++) {
3400: if (form.elements[radioname][j].checked) {
3401: if (form.elements[radioname][j].value == '1') {
3402: if (document.getElementById(divid)) {
3403: document.getElementById(divid).style.display = 'inline-block';
3404: }
3405: setvis = 1;
3406: break;
3407: }
3408: }
3409: }
3410: }
3411: if (setvis == 1) {
3412: break;
3413: }
3414: }
3415: if (!setvis) {
3416: if (document.getElementById(divid)) {
3417: document.getElementById(divid).style.display = 'none';
3418: }
3419: }
1.320 raeburn 3420: }
3421: return;
3422: }
3423: // ]]>
3424: </script>
3425:
3426: ENDSCRIPT
3427: }
3428:
1.385 raeburn 3429: sub autoupdate_javascript {
3430: return <<"ENDSCRIPT";
3431: <script type="text/javascript">
3432: // <![CDATA[
3433: function toggleLastActiveDays(form) {
3434: var radioname = 'lastactive';
3435: var divid = 'lastactive_div';
3436: var num = form.elements[radioname].length;
3437: if (num) {
3438: var setvis = '';
3439: for (var i=0; i<num; i++) {
3440: if (form.elements[radioname][i].checked) {
3441: if (form.elements[radioname][i].value == '1') {
3442: if (document.getElementById(divid)) {
3443: document.getElementById(divid).style.display = 'inline-block';
3444: }
3445: setvis = 1;
3446: }
3447: break;
3448: }
3449: }
3450: if (!setvis) {
3451: if (document.getElementById(divid)) {
3452: document.getElementById(divid).style.display = 'none';
3453: }
3454: }
3455: }
3456: return;
3457: }
3458: // ]]>
3459: </script>
3460:
3461: ENDSCRIPT
3462: }
3463:
1.386 raeburn 3464: sub saml_javascript {
3465: return <<"ENDSCRIPT";
3466: <script type="text/javascript">
3467: // <![CDATA[
3468: function toggleSamlOptions(form,hostid) {
3469: var radioname = 'saml_'+hostid;
3470: var tablecellon = 'samloptionson_'+hostid;
3471: var tablecelloff = 'samloptionsoff_'+hostid;
3472: var num = form.elements[radioname].length;
3473: if (num) {
3474: var setvis = '';
3475: for (var i=0; i<num; i++) {
3476: if (form.elements[radioname][i].checked) {
3477: if (form.elements[radioname][i].value == '1') {
3478: if (document.getElementById(tablecellon)) {
3479: document.getElementById(tablecellon).style.display='';
3480: }
3481: if (document.getElementById(tablecelloff)) {
3482: document.getElementById(tablecelloff).style.display='none';
3483: }
3484: setvis = 1;
3485: }
3486: break;
3487: }
3488: }
3489: if (!setvis) {
3490: if (document.getElementById(tablecellon)) {
3491: document.getElementById(tablecellon).style.display='none';
3492: }
3493: if (document.getElementById(tablecelloff)) {
3494: document.getElementById(tablecelloff).style.display='';
3495: }
3496: }
3497: }
3498: return;
3499: }
3500: // ]]>
3501: </script>
3502:
3503: ENDSCRIPT
3504: }
3505:
1.3 raeburn 3506: sub print_autoenroll {
1.30 raeburn 3507: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3508: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3509: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3510: if (ref($settings) eq 'HASH') {
3511: if (exists($settings->{'run'})) {
3512: if ($settings->{'run'} eq '0') {
3513: $runoff = ' checked="checked" ';
3514: $runon = ' ';
3515: } else {
3516: $runon = ' checked="checked" ';
3517: $runoff = ' ';
3518: }
3519: } else {
3520: if ($autorun) {
3521: $runon = ' checked="checked" ';
3522: $runoff = ' ';
3523: } else {
3524: $runoff = ' checked="checked" ';
3525: $runon = ' ';
3526: }
3527: }
1.129 raeburn 3528: if (exists($settings->{'co-owners'})) {
3529: if ($settings->{'co-owners'} eq '0') {
3530: $coownersoff = ' checked="checked" ';
3531: $coownerson = ' ';
3532: } else {
3533: $coownerson = ' checked="checked" ';
3534: $coownersoff = ' ';
3535: }
3536: } else {
3537: $coownersoff = ' checked="checked" ';
3538: $coownerson = ' ';
3539: }
1.3 raeburn 3540: if (exists($settings->{'sender_domain'})) {
3541: $defdom = $settings->{'sender_domain'};
3542: }
1.274 raeburn 3543: if (exists($settings->{'autofailsafe'})) {
3544: $failsafe = $settings->{'autofailsafe'};
3545: }
1.14 raeburn 3546: } else {
3547: if ($autorun) {
3548: $runon = ' checked="checked" ';
3549: $runoff = ' ';
3550: } else {
3551: $runoff = ' checked="checked" ';
3552: $runon = ' ';
3553: }
1.3 raeburn 3554: }
3555: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3556: my $notif_sender;
3557: if (ref($settings) eq 'HASH') {
3558: $notif_sender = $settings->{'sender_uname'};
3559: }
1.3 raeburn 3560: my $datatable='<tr class="LC_odd_row">'.
3561: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3562: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3563: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3564: $runon.' value="1" />'.&mt('Yes').'</label> '.
3565: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3566: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3567: '</tr><tr>'.
3568: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3569: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3570: &mt('username').': '.
3571: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3572: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3573: ': '.$domform.'</span></td></tr>'.
3574: '<tr class="LC_odd_row">'.
3575: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3576: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3577: '<input type="radio" name="autoassign_coowners"'.
3578: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3579: '<label><input type="radio" name="autoassign_coowners"'.
3580: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3581: '</tr><tr>'.
3582: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3583: '<td class="LC_right_item"><span class="LC_nobreak">'.
3584: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3585: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3586: $$rowtotal += 4;
1.3 raeburn 3587: return $datatable;
3588: }
3589:
3590: sub print_autoupdate {
1.30 raeburn 3591: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 3592: my ($enable,$datatable);
1.3 raeburn 3593: if ($position eq 'top') {
1.385 raeburn 3594: my %choices = &Apache::lonlocal::texthash (
3595: run => 'Auto-update active?',
3596: classlists => 'Update information in classlists?',
3597: unexpired => 'Skip updates for users without active or future roles?',
3598: lastactive => 'Skip updates for inactive users?',
3599: );
3600: my $itemcount = 0;
1.3 raeburn 3601: my $updateon = ' ';
3602: my $updateoff = ' checked="checked" ';
3603: if (ref($settings) eq 'HASH') {
3604: if ($settings->{'run'} eq '1') {
3605: $updateon = $updateoff;
3606: $updateoff = ' ';
3607: }
3608: }
1.385 raeburn 3609: $enable = '<tr class="LC_odd_row">'.
3610: '<td>'.$choices{'run'}.'</td>'.
3611: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3612: '<input type="radio" name="autoupdate_run"'.
1.385 raeburn 3613: $updateoff.' value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3614: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 3615: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3616: '</tr>';
1.385 raeburn 3617: my @toggles = ('classlists','unexpired');
3618: my %defaultchecked = ('classlists' => 'off',
3619: 'unexpired' => 'off'
3620: );
3621: $$rowtotal ++;
3622: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3623: \%choices,$itemcount,'','','left','no');
3624: $datatable = $enable.$datatable;
3625: $$rowtotal += $itemcount;
3626: my $lastactiveon = ' ';
3627: my $lastactiveoff = ' checked="checked" ';
3628: my $lastactivestyle = 'none';
3629: my $lastactivedays;
3630: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3631: if (ref($settings) eq 'HASH') {
3632: if ($settings->{'lastactive'} =~ /^\d+$/) {
3633: $lastactiveon = $lastactiveoff;
3634: $lastactiveoff = ' ';
3635: $lastactivestyle = 'inline-block';
3636: $lastactivedays = $settings->{'lastactive'};
3637: }
3638: }
3639: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3640: $datatable .= '<tr'.$css_class.'>'.
3641: '<td>'.$choices{'lastactive'}.'</td>'.
3642: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3643: '<input type="radio" name="lastactive"'.
3644: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3645: ' <label>'.
3646: '<input type="radio" name="lastactive"'.
3647: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3648: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3649: ': '.&mt('inactive = no activity in last [_1] days',
3650: '<input type="text" size="5" name="lastactivedays" value="'.
3651: $lastactivedays.'" />').
3652: '</span></td>'.
3653: '</tr>';
3654: $$rowtotal ++;
1.131 raeburn 3655: } elsif ($position eq 'middle') {
3656: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3657: my $numinrow = 3;
3658: my $locknamesettings;
3659: $datatable .= &insttypes_row($settings,$types,$usertypes,
3660: $dom,$numinrow,$othertitle,
1.305 raeburn 3661: 'lockablenames',$rowtotal);
1.131 raeburn 3662: $$rowtotal ++;
1.3 raeburn 3663: } else {
1.44 raeburn 3664: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3665: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3666: 'permanentemail','id');
1.33 raeburn 3667: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3668: my $numrows = 0;
1.26 raeburn 3669: if (ref($types) eq 'ARRAY') {
3670: if (@{$types} > 0) {
3671: $datatable =
3672: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3673: \@fields,$types,\$numrows);
1.30 raeburn 3674: $$rowtotal += @{$types};
1.26 raeburn 3675: }
1.3 raeburn 3676: }
3677: $datatable .=
3678: &usertype_update_row($settings,{'default' => $othertitle},
3679: \%fieldtitles,\@fields,['default'],
3680: \$numrows);
1.30 raeburn 3681: $$rowtotal ++;
1.3 raeburn 3682: }
3683: return $datatable;
3684: }
3685:
1.125 raeburn 3686: sub print_autocreate {
3687: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3688: my (%createon,%createoff,%currhash);
1.125 raeburn 3689: my @types = ('xml','req');
3690: if (ref($settings) eq 'HASH') {
3691: foreach my $item (@types) {
3692: $createoff{$item} = ' checked="checked" ';
3693: $createon{$item} = ' ';
3694: if (exists($settings->{$item})) {
3695: if ($settings->{$item}) {
3696: $createon{$item} = ' checked="checked" ';
3697: $createoff{$item} = ' ';
3698: }
3699: }
3700: }
1.210 raeburn 3701: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3702: $currhash{$settings->{'xmldc'}} = 1;
3703: }
1.125 raeburn 3704: } else {
3705: foreach my $item (@types) {
3706: $createoff{$item} = ' checked="checked" ';
3707: $createon{$item} = ' ';
3708: }
3709: }
3710: $$rowtotal += 2;
1.191 raeburn 3711: my $numinrow = 2;
1.125 raeburn 3712: my $datatable='<tr class="LC_odd_row">'.
3713: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3714: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3715: '<input type="radio" name="autocreate_xml"'.
3716: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3717: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3718: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3719: '</td></tr><tr>'.
3720: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3721: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3722: '<input type="radio" name="autocreate_req"'.
3723: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3724: '<label><input type="radio" name="autocreate_req"'.
3725: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3726: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3727: 'autocreate_xmldc',%currhash);
1.247 raeburn 3728: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3729: if ($numdc > 1) {
1.247 raeburn 3730: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3731: '</td><td class="LC_left_item">';
1.125 raeburn 3732: } else {
1.247 raeburn 3733: $datatable .= &mt('Course creation processed as:').
3734: '</td><td class="LC_right_item">';
1.125 raeburn 3735: }
1.247 raeburn 3736: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3737: $$rowtotal += $rows;
1.125 raeburn 3738: return $datatable;
3739: }
3740:
1.23 raeburn 3741: sub print_directorysrch {
1.277 raeburn 3742: my ($position,$dom,$settings,$rowtotal) = @_;
3743: my $datatable;
3744: if ($position eq 'top') {
3745: my $instsrchon = ' ';
3746: my $instsrchoff = ' checked="checked" ';
3747: my ($exacton,$containson,$beginson);
3748: my $instlocalon = ' ';
3749: my $instlocaloff = ' checked="checked" ';
3750: if (ref($settings) eq 'HASH') {
3751: if ($settings->{'available'} eq '1') {
3752: $instsrchon = $instsrchoff;
3753: $instsrchoff = ' ';
3754: }
3755: if ($settings->{'localonly'} eq '1') {
3756: $instlocalon = $instlocaloff;
3757: $instlocaloff = ' ';
3758: }
3759: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3760: foreach my $type (@{$settings->{'searchtypes'}}) {
3761: if ($type eq 'exact') {
3762: $exacton = ' checked="checked" ';
3763: } elsif ($type eq 'contains') {
3764: $containson = ' checked="checked" ';
3765: } elsif ($type eq 'begins') {
3766: $beginson = ' checked="checked" ';
3767: }
3768: }
3769: } else {
3770: if ($settings->{'searchtypes'} eq 'exact') {
3771: $exacton = ' checked="checked" ';
3772: } elsif ($settings->{'searchtypes'} eq 'contains') {
3773: $containson = ' checked="checked" ';
3774: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3775: $exacton = ' checked="checked" ';
3776: $containson = ' checked="checked" ';
3777: }
3778: }
1.277 raeburn 3779: }
3780: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3781: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3782:
3783: my $numinrow = 4;
3784: my $cansrchrow = 0;
3785: $datatable='<tr class="LC_odd_row">'.
3786: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3787: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3788: '<input type="radio" name="dirsrch_available"'.
3789: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3790: '<label><input type="radio" name="dirsrch_available"'.
3791: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3792: '</tr><tr>'.
3793: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3795: '<input type="radio" name="dirsrch_instlocalonly"'.
3796: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3797: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3798: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3799: '</tr>';
3800: $$rowtotal += 2;
3801: if (ref($usertypes) eq 'HASH') {
3802: if (keys(%{$usertypes}) > 0) {
3803: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3804: $numinrow,$othertitle,'cansearch',
3805: $rowtotal);
1.277 raeburn 3806: $cansrchrow = 1;
1.25 raeburn 3807: }
1.23 raeburn 3808: }
1.277 raeburn 3809: if ($cansrchrow) {
3810: $$rowtotal ++;
3811: $datatable .= '<tr>';
3812: } else {
3813: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3814: }
1.277 raeburn 3815: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3816: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3817: foreach my $title (@{$titleorder}) {
3818: if (defined($searchtitles->{$title})) {
3819: my $check = ' ';
3820: if (ref($settings) eq 'HASH') {
3821: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3822: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3823: $check = ' checked="checked" ';
3824: }
1.39 raeburn 3825: }
1.25 raeburn 3826: }
1.277 raeburn 3827: $datatable .= '<td class="LC_left_item">'.
3828: '<span class="LC_nobreak"><label>'.
3829: '<input type="checkbox" name="searchby" '.
3830: 'value="'.$title.'"'.$check.'/>'.
3831: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3832: }
3833: }
1.277 raeburn 3834: $datatable .= '</tr></table></td></tr>';
3835: $$rowtotal ++;
3836: if ($cansrchrow) {
3837: $datatable .= '<tr class="LC_odd_row">';
3838: } else {
3839: $datatable .= '<tr>';
3840: }
3841: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3842: '<td class="LC_left_item" colspan="2">'.
3843: '<span class="LC_nobreak"><label>'.
3844: '<input type="checkbox" name="searchtypes" '.
3845: $exacton.' value="exact" />'.&mt('Exact match').
3846: '</label> '.
3847: '<label><input type="checkbox" name="searchtypes" '.
3848: $beginson.' value="begins" />'.&mt('Begins with').
3849: '</label> '.
3850: '<label><input type="checkbox" name="searchtypes" '.
3851: $containson.' value="contains" />'.&mt('Contains').
3852: '</label></span></td></tr>';
3853: $$rowtotal ++;
1.26 raeburn 3854: } else {
1.277 raeburn 3855: my $domsrchon = ' checked="checked" ';
3856: my $domsrchoff = ' ';
3857: my $domlocalon = ' ';
3858: my $domlocaloff = ' checked="checked" ';
3859: if (ref($settings) eq 'HASH') {
3860: if ($settings->{'lclocalonly'} eq '1') {
3861: $domlocalon = $domlocaloff;
3862: $domlocaloff = ' ';
3863: }
3864: if ($settings->{'lcavailable'} eq '0') {
3865: $domsrchoff = $domsrchon;
3866: $domsrchon = ' ';
3867: }
3868: }
3869: $datatable='<tr class="LC_odd_row">'.
3870: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3871: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3872: '<input type="radio" name="dirsrch_domavailable"'.
3873: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3874: '<label><input type="radio" name="dirsrch_domavailable"'.
3875: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3876: '</tr><tr>'.
3877: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3878: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3879: '<input type="radio" name="dirsrch_domlocalonly"'.
3880: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3881: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3882: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3883: '</tr>';
3884: $$rowtotal += 2;
1.26 raeburn 3885: }
1.25 raeburn 3886: return $datatable;
3887: }
3888:
1.28 raeburn 3889: sub print_contacts {
1.286 raeburn 3890: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3891: my $datatable;
3892: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3893: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3894: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3895: if ($position eq 'top') {
3896: if (ref($settings) eq 'HASH') {
3897: foreach my $item (@contacts) {
3898: if (exists($settings->{$item})) {
3899: $to{$item} = $settings->{$item};
3900: }
3901: }
3902: }
3903: } elsif ($position eq 'middle') {
3904: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3905: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3906: foreach my $type (@mailings) {
3907: $otheremails{$type} = '';
3908: }
1.340 raeburn 3909: } elsif ($position eq 'lower') {
3910: if (ref($settings) eq 'HASH') {
3911: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3912: %lonstatus = %{$settings->{'lonstatus'}};
3913: }
3914: }
1.286 raeburn 3915: } else {
3916: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3917: foreach my $type (@mailings) {
3918: $otheremails{$type} = '';
3919: }
1.286 raeburn 3920: $bccemails{'helpdeskmail'} = '';
3921: $bccemails{'otherdomsmail'} = '';
3922: $includestr{'helpdeskmail'} = '';
3923: $includestr{'otherdomsmail'} = '';
3924: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3925: }
1.28 raeburn 3926: if (ref($settings) eq 'HASH') {
1.340 raeburn 3927: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3928: foreach my $type (@mailings) {
3929: if (exists($settings->{$type})) {
3930: if (ref($settings->{$type}) eq 'HASH') {
3931: foreach my $item (@contacts) {
3932: if ($settings->{$type}{$item}) {
3933: $checked{$type}{$item} = ' checked="checked" ';
3934: }
3935: }
3936: $otheremails{$type} = $settings->{$type}{'others'};
3937: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3938: $bccemails{$type} = $settings->{$type}{'bcc'};
3939: if ($settings->{$type}{'include'} ne '') {
3940: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3941: $includestr{$type} = &unescape($includestr{$type});
3942: }
3943: }
3944: }
3945: } elsif ($type eq 'lonstatusmail') {
3946: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3947: }
1.28 raeburn 3948: }
3949: }
1.286 raeburn 3950: if ($position eq 'bottom') {
3951: foreach my $type (@mailings) {
3952: $bccemails{$type} = $settings->{$type}{'bcc'};
3953: if ($settings->{$type}{'include'} ne '') {
3954: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3955: $includestr{$type} = &unescape($includestr{$type});
3956: }
3957: }
3958: if (ref($settings->{'helpform'}) eq 'HASH') {
3959: if (ref($fields) eq 'ARRAY') {
3960: foreach my $field (@{$fields}) {
3961: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3962: }
1.286 raeburn 3963: }
3964: if (exists($settings->{'helpform'}{'maxsize'})) {
3965: $maxsize = $settings->{'helpform'}{'maxsize'};
3966: } else {
1.289 raeburn 3967: $maxsize = '1.0';
1.286 raeburn 3968: }
3969: } else {
3970: if (ref($fields) eq 'ARRAY') {
3971: foreach my $field (@{$fields}) {
3972: $currfield{$field} = 'yes';
1.134 raeburn 3973: }
1.28 raeburn 3974: }
1.286 raeburn 3975: $maxsize = '1.0';
1.28 raeburn 3976: }
3977: }
3978: } else {
1.286 raeburn 3979: if ($position eq 'top') {
3980: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3981: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3982: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3983: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3984: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3985: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3986: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3987: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3988: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3989: } elsif ($position eq 'bottom') {
3990: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3991: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3992: if (ref($fields) eq 'ARRAY') {
3993: foreach my $field (@{$fields}) {
3994: $currfield{$field} = 'yes';
3995: }
3996: }
3997: $maxsize = '1.0';
3998: }
1.28 raeburn 3999: }
4000: my ($titles,$short_titles) = &contact_titles();
4001: my $rownum = 0;
4002: my $css_class;
1.286 raeburn 4003: if ($position eq 'top') {
4004: foreach my $item (@contacts) {
4005: $css_class = $rownum%2?' class="LC_odd_row"':'';
4006: $datatable .= '<tr'.$css_class.'>'.
4007: '<td><span class="LC_nobreak">'.$titles->{$item}.
4008: '</span></td><td class="LC_right_item">'.
4009: '<input type="text" name="'.$item.'" value="'.
4010: $to{$item}.'" /></td></tr>';
4011: $rownum ++;
4012: }
1.315 raeburn 4013: } elsif ($position eq 'bottom') {
4014: $css_class = $rownum%2?' class="LC_odd_row"':'';
4015: $datatable .= '<tr'.$css_class.'>'.
4016: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4017: &mt('(e-mail, subject, and description always shown)').
4018: '</td><td class="LC_left_item">';
4019: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4020: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4021: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4022: foreach my $field (@{$fields}) {
4023: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4024: if (($field eq 'screenshot') || ($field eq 'cc')) {
4025: $datatable .= ' '.&mt('(logged-in users)');
4026: }
4027: $datatable .='</td><td>';
4028: my $clickaction;
4029: if ($field eq 'screenshot') {
4030: $clickaction = ' onclick="screenshotSize(this);"';
4031: }
4032: if (ref($possoptions->{$field}) eq 'ARRAY') {
4033: foreach my $option (@{$possoptions->{$field}}) {
4034: my $checked;
4035: if ($currfield{$field} eq $option) {
4036: $checked = ' checked="checked"';
4037: }
4038: $datatable .= '<span class="LC_nobreak"><label>'.
4039: '<input type="radio" name="helpform_'.$field.'" '.
4040: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4041: '</label></span>'.(' 'x2);
4042: }
4043: }
4044: if ($field eq 'screenshot') {
4045: my $display;
4046: if ($currfield{$field} eq 'no') {
4047: $display = ' style="display:none"';
4048: }
1.334 raeburn 4049: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4050: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4051: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4052: }
4053: $datatable .= '</td></tr>';
4054: }
4055: $datatable .= '</table>';
4056: }
4057: $datatable .= '</td></tr>'."\n";
4058: $rownum ++;
4059: }
1.340 raeburn 4060: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4061: foreach my $type (@mailings) {
4062: $css_class = $rownum%2?' class="LC_odd_row"':'';
4063: $datatable .= '<tr'.$css_class.'>'.
4064: '<td><span class="LC_nobreak">'.
4065: $titles->{$type}.': </span></td>'.
4066: '<td class="LC_left_item">';
4067: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4068: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4069: }
4070: $datatable .= '<span class="LC_nobreak">';
4071: foreach my $item (@contacts) {
4072: $datatable .= '<label>'.
4073: '<input type="checkbox" name="'.$type.'"'.
4074: $checked{$type}{$item}.
4075: ' value="'.$item.'" />'.$short_titles->{$item}.
4076: '</label> ';
4077: }
4078: $datatable .= '</span><br />'.&mt('Others').': '.
4079: '<input type="text" name="'.$type.'_others" '.
4080: 'value="'.$otheremails{$type}.'" />';
4081: my %locchecked;
4082: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4083: foreach my $loc ('s','b') {
4084: if ($includeloc{$type} eq $loc) {
4085: $locchecked{$loc} = ' checked="checked"';
4086: last;
4087: }
4088: }
4089: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4090: '<input type="text" name="'.$type.'_bcc" '.
4091: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4092: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4093: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4094: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4095: '<span class="LC_nobreak">'.&mt('Location:').' '.
4096: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4097: (' 'x2).
4098: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4099: '</span></fieldset>';
4100: }
4101: $datatable .= '</td></tr>'."\n";
4102: $rownum ++;
4103: }
1.28 raeburn 4104: }
1.286 raeburn 4105: if ($position eq 'middle') {
4106: my %choices;
1.340 raeburn 4107: my $corelink = &core_link_msu();
4108: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4109: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4110: $corelink);
4111: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4112: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4113: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4114: 'reportupdates' => 'on',
4115: 'reportstatus' => 'on');
1.286 raeburn 4116: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4117: \%choices,$rownum);
4118: $datatable .= $reports;
1.340 raeburn 4119: } elsif ($position eq 'lower') {
1.378 raeburn 4120: my (%current,%excluded,%weights);
1.340 raeburn 4121: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4122: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4123: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4124: } else {
1.378 raeburn 4125: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4126: }
4127: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4128: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4129: } else {
1.378 raeburn 4130: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4131: }
4132: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4133: foreach my $type ('E','W','N','U') {
1.340 raeburn 4134: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4135: $weights{$type} = $lonstatus{'weights'}{$type};
4136: } else {
4137: $weights{$type} = $defaults->{$type};
4138: }
4139: }
4140: } else {
1.341 raeburn 4141: foreach my $type ('E','W','N','U') {
1.340 raeburn 4142: $weights{$type} = $defaults->{$type};
4143: }
4144: }
4145: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4146: if (@{$lonstatus{'excluded'}} > 0) {
4147: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4148: }
4149: }
1.378 raeburn 4150: foreach my $item ('errorthreshold','errorsysmail') {
4151: $css_class = $rownum%2?' class="LC_odd_row"':'';
4152: $datatable .= '<tr'.$css_class.'>'.
4153: '<td class="LC_left_item"><span class="LC_nobreak">'.
4154: $titles->{$item}.
4155: '</span></td><td class="LC_left_item">'.
4156: '<input type="text" name="'.$item.'" value="'.
4157: $current{$item}.'" size="5" /></td></tr>';
4158: $rownum ++;
4159: }
1.340 raeburn 4160: $css_class = $rownum%2?' class="LC_odd_row"':'';
4161: $datatable .= '<tr'.$css_class.'>'.
4162: '<td class="LC_left_item">'.
4163: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4164: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4165: foreach my $type ('E','W','N','U') {
1.340 raeburn 4166: $datatable .= '<td>'.$names->{$type}.'<br />'.
4167: '<input type="text" name="errorweights_'.$type.'" value="'.
4168: $weights{$type}.'" size="5" /></td>';
4169: }
4170: $datatable .= '</tr></table></tr>';
4171: $rownum ++;
4172: $css_class = $rownum%2?' class="LC_odd_row"':'';
4173: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4174: $titles->{'errorexcluded'}.'</td>'.
4175: '<td class="LC_left_item"><table>';
4176: my $numinrow = 4;
4177: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4178: for (my $i=0; $i<@ids; $i++) {
4179: my $rem = $i%($numinrow);
4180: if ($rem == 0) {
4181: if ($i > 0) {
4182: $datatable .= '</tr>';
4183: }
4184: $datatable .= '<tr>';
4185: }
4186: my $check;
4187: if ($excluded{$ids[$i]}) {
4188: $check = ' checked="checked" ';
4189: }
4190: $datatable .= '<td class="LC_left_item">'.
4191: '<span class="LC_nobreak"><label>'.
4192: '<input type="checkbox" name="errorexcluded" '.
4193: 'value="'.$ids[$i].'"'.$check.' />'.
4194: $ids[$i].'</label></span></td>';
4195: }
4196: my $colsleft = $numinrow - @ids%($numinrow);
4197: if ($colsleft > 1 ) {
4198: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4199: ' </td>';
4200: } elsif ($colsleft == 1) {
4201: $datatable .= '<td class="LC_left_item"> </td>';
4202: }
4203: $datatable .= '</tr></table></td></tr>';
4204: $rownum ++;
1.286 raeburn 4205: } elsif ($position eq 'bottom') {
1.315 raeburn 4206: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4207: my (@posstypes,%usertypeshash);
4208: if (ref($types) eq 'ARRAY') {
4209: @posstypes = @{$types};
4210: }
4211: if (@posstypes) {
4212: if (ref($usertypes) eq 'HASH') {
4213: %usertypeshash = %{$usertypes};
4214: }
4215: my @overridden;
4216: my $numinrow = 4;
4217: if (ref($settings) eq 'HASH') {
4218: if (ref($settings->{'overrides'}) eq 'HASH') {
4219: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4220: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4221: push(@overridden,$key);
4222: foreach my $item (@contacts) {
4223: if ($settings->{'overrides'}{$key}{$item}) {
4224: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4225: }
4226: }
4227: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4228: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4229: $includeloc{'override_'.$key} = '';
4230: $includestr{'override_'.$key} = '';
4231: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4232: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4233: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4234: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4235: }
1.286 raeburn 4236: }
4237: }
4238: }
1.315 raeburn 4239: }
4240: my $customclass = 'LC_helpdesk_override';
4241: my $optionsprefix = 'LC_options_helpdesk_';
4242:
4243: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4244:
4245: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4246: $numinrow,$othertitle,'overrides',
4247: \$rownum,$onclicktypes,$customclass);
4248: $rownum ++;
4249: $usertypeshash{'default'} = $othertitle;
4250: foreach my $status (@posstypes) {
4251: my $css_class;
4252: if ($rownum%2) {
4253: $css_class = 'LC_odd_row ';
4254: }
4255: $css_class .= $customclass;
4256: my $rowid = $optionsprefix.$status;
4257: my $hidden = 1;
4258: my $currstyle = 'display:none';
4259: if (grep(/^\Q$status\E$/,@overridden)) {
4260: $currstyle = 'display:table-row';
4261: $hidden = 0;
4262: }
4263: my $key = 'override_'.$status;
4264: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4265: $includeloc{$key},$includestr{$key},$status,$rowid,
4266: $usertypeshash{$status},$css_class,$currstyle,
4267: \@contacts,$short_titles);
4268: unless ($hidden) {
4269: $rownum ++;
1.286 raeburn 4270: }
4271: }
1.134 raeburn 4272: }
1.28 raeburn 4273: }
1.30 raeburn 4274: $$rowtotal += $rownum;
1.28 raeburn 4275: return $datatable;
4276: }
4277:
1.340 raeburn 4278: sub core_link_msu {
4279: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4280: &mt('LON-CAPA core group - MSU'),600,500);
4281: }
4282:
1.315 raeburn 4283: sub overridden_helpdesk {
4284: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4285: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4286: my $class = 'LC_left_item';
4287: if ($css_class) {
4288: $css_class = ' class="'.$css_class.'"';
4289: }
4290: if ($rowid) {
4291: $rowid = ' id="'.$rowid.'"';
4292: }
4293: if ($rowstyle) {
4294: $rowstyle = ' style="'.$rowstyle.'"';
4295: }
4296: my ($output,$description);
4297: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4298: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4299: "<td>$description</td>\n".
4300: '<td class="'.$class.'" colspan="2">'.
4301: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4302: '<span class="LC_nobreak">';
4303: if (ref($contacts) eq 'ARRAY') {
4304: foreach my $item (@{$contacts}) {
4305: my $check;
4306: if (ref($checked) eq 'HASH') {
4307: $check = $checked->{$item};
4308: }
4309: my $title;
4310: if (ref($short_titles) eq 'HASH') {
4311: $title = $short_titles->{$item};
4312: }
4313: $output .= '<label>'.
4314: '<input type="checkbox" name="override_'.$type.'"'.$check.
4315: ' value="'.$item.'" />'.$title.'</label> ';
4316: }
4317: }
4318: $output .= '</span><br />'.&mt('Others').': '.
4319: '<input type="text" name="override_'.$type.'_others" '.
4320: 'value="'.$otheremails.'" />';
4321: my %locchecked;
4322: foreach my $loc ('s','b') {
4323: if ($includeloc eq $loc) {
4324: $locchecked{$loc} = ' checked="checked"';
4325: last;
4326: }
4327: }
4328: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4329: '<input type="text" name="override_'.$type.'_bcc" '.
4330: 'value="'.$bccemails.'" /></fieldset>'.
4331: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4332: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4333: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4334: '<span class="LC_nobreak">'.&mt('Location:').' '.
4335: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4336: (' 'x2).
4337: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4338: '</span></fieldset>'.
4339: '</td></tr>'."\n";
4340: return $output;
4341: }
4342:
1.286 raeburn 4343: sub contacts_javascript {
4344: return <<"ENDSCRIPT";
4345:
4346: <script type="text/javascript">
4347: // <![CDATA[
4348:
4349: function screenshotSize(field) {
4350: if (document.getElementById('help_screenshotsize')) {
4351: if (field.value == 'no') {
1.289 raeburn 4352: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4353: } else {
4354: document.getElementById('help_screenshotsize').style.display="";
4355: }
4356: }
4357: return;
4358: }
4359:
1.315 raeburn 4360: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4361: if (form.elements[checkbox].length != undefined) {
4362: var count = 0;
4363: if (docount) {
4364: for (var i=0; i<form.elements[checkbox].length; i++) {
4365: if (form.elements[checkbox][i].checked) {
4366: count ++;
4367: }
4368: }
4369: }
4370: for (var i=0; i<form.elements[checkbox].length; i++) {
4371: var type = form.elements[checkbox][i].value;
4372: if (document.getElementById(prefix+type)) {
4373: if (form.elements[checkbox][i].checked) {
4374: document.getElementById(prefix+type).style.display = 'table-row';
4375: if (count % 2 == 1) {
4376: document.getElementById(prefix+type).className = target+' LC_odd_row';
4377: } else {
4378: document.getElementById(prefix+type).className = target;
4379: }
4380: count ++;
4381: } else {
4382: document.getElementById(prefix+type).style.display = 'none';
4383: }
4384: }
4385: }
4386: }
4387: return;
4388: }
4389:
4390:
1.286 raeburn 4391: // ]]>
4392: </script>
4393:
4394: ENDSCRIPT
4395: }
4396:
1.118 jms 4397: sub print_helpsettings {
1.282 raeburn 4398: my ($position,$dom,$settings,$rowtotal) = @_;
4399: my $confname = $dom.'-domainconfig';
1.285 raeburn 4400: my $formname = 'display';
1.168 raeburn 4401: my ($datatable,$itemcount);
1.282 raeburn 4402: if ($position eq 'top') {
4403: $itemcount = 1;
4404: my (%choices,%defaultchecked,@toggles);
4405: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4406: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4407: &mt('LON-CAPA bug tracker'),600,500));
4408: %defaultchecked = ('submitbugs' => 'on');
4409: @toggles = ('submitbugs');
4410: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4411: \%choices,$itemcount);
4412: $$rowtotal ++;
4413: } else {
4414: my $css_class;
4415: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4416: my (%customroles,%ordered,%current);
1.301 raeburn 4417: if (ref($settings) eq 'HASH') {
4418: if (ref($settings->{'adhoc'}) eq 'HASH') {
4419: %current = %{$settings->{'adhoc'}};
4420: }
1.285 raeburn 4421: }
4422: my $count = 0;
4423: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4424: if ($key=~/^rolesdef\_(\w+)$/) {
4425: my $rolename = $1;
1.285 raeburn 4426: my (%privs,$order);
1.282 raeburn 4427: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4428: $customroles{$rolename} = \%privs;
1.285 raeburn 4429: if (ref($current{$rolename}) eq 'HASH') {
4430: $order = $current{$rolename}{'order'};
4431: }
4432: if ($order eq '') {
4433: $order = $count;
4434: }
4435: $ordered{$order} = $rolename;
4436: $count++;
4437: }
4438: }
4439: my $maxnum = scalar(keys(%ordered));
4440: my @roles_by_num = ();
4441: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4442: push(@roles_by_num,$item);
4443: }
4444: my $context = 'domprefs';
4445: my $crstype = 'Course';
4446: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4447: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4448: my ($numstatustypes,@jsarray);
4449: if (ref($types) eq 'ARRAY') {
4450: if (@{$types} > 0) {
4451: $numstatustypes = scalar(@{$types});
4452: push(@accesstypes,'status');
4453: @jsarray = ('bystatus');
1.282 raeburn 4454: }
4455: }
1.290 raeburn 4456: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4457: if (keys(%domhelpdesk)) {
4458: push(@accesstypes,('inc','exc'));
4459: push(@jsarray,('notinc','notexc'));
4460: }
4461: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4462: my $context = 'domprefs';
4463: my $crstype = 'Course';
1.285 raeburn 4464: my $prefix = 'helproles_';
4465: my $add_class = 'LC_hidden';
4466: foreach my $num (@roles_by_num) {
4467: my $role = $ordered{$num};
4468: my ($desc,$access,@statuses);
4469: if (ref($current{$role}) eq 'HASH') {
4470: $desc = $current{$role}{'desc'};
4471: $access = $current{$role}{'access'};
4472: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4473: @statuses = @{$current{$role}{'insttypes'}};
4474: }
4475: }
4476: if ($desc eq '') {
4477: $desc = $role;
4478: }
4479: my $identifier = 'custhelp'.$num;
1.282 raeburn 4480: my %full=();
4481: my %levels= (
4482: course => {},
4483: domain => {},
4484: system => {},
4485: );
4486: my %levelscurrent=(
4487: course => {},
4488: domain => {},
4489: system => {},
4490: );
4491: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4492: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4493: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4494: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4495: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4496: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4497: for (my $k=0; $k<=$maxnum; $k++) {
4498: my $vpos = $k+1;
4499: my $selstr;
4500: if ($k == $num) {
4501: $selstr = ' selected="selected" ';
4502: }
4503: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4504: }
4505: $datatable .= '</select>'.(' 'x2).
4506: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4507: '</td>'.
4508: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4509: &mt('Name shown to users:').
4510: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4511: '</fieldset>'.
4512: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4513: $othertitle,$usertypes,$types,\%domhelpdesk).
4514: '<fieldset>'.
4515: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4516: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4517: \%levelscurrent,$identifier,
4518: 'LC_hidden',$prefix.$num.'_privs').
4519: '</fieldset></td>';
1.282 raeburn 4520: $itemcount ++;
4521: }
4522: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4523: my $newcust = 'custhelp'.$count;
4524: my (%privs,%levelscurrent);
4525: my %full=();
4526: my %levels= (
4527: course => {},
4528: domain => {},
4529: system => {},
4530: );
4531: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4532: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4533: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4534: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4535: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4536: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4537: for (my $k=0; $k<$maxnum+1; $k++) {
4538: my $vpos = $k+1;
4539: my $selstr;
4540: if ($k == $maxnum) {
4541: $selstr = ' selected="selected" ';
4542: }
4543: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4544: }
4545: $datatable .= '</select> '."\n".
1.282 raeburn 4546: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4547: '</label></span></td>'.
1.285 raeburn 4548: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4549: '<span class="LC_nobreak">'.
4550: &mt('Internal name:').
4551: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4552: '</span>'.(' 'x4).
4553: '<span class="LC_nobreak">'.
4554: &mt('Name shown to users:').
4555: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4556: '</span></fieldset>'.
4557: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4558: $usertypes,$types,\%domhelpdesk).
4559: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4560: &Apache::lonuserutils::custom_role_header($context,$crstype,
4561: \@templateroles,$newcust).
4562: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4563: \%levelscurrent,$newcust).
1.334 raeburn 4564: '</fieldset>'.
4565: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4566: '</td></tr>';
1.282 raeburn 4567: $count ++;
4568: $$rowtotal += $count;
4569: }
1.166 raeburn 4570: return $datatable;
1.121 raeburn 4571: }
4572:
1.285 raeburn 4573: sub adhocbutton {
4574: my ($prefix,$num,$field,$visibility) = @_;
4575: my %lt = &Apache::lonlocal::texthash(
4576: show => 'Show details',
4577: hide => 'Hide details',
4578: );
4579: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4580: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4581: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4582: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4583: }
4584:
4585: sub helpsettings_javascript {
4586: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4587: return unless(ref($roles_by_num) eq 'ARRAY');
4588: my %html_js_lt = &Apache::lonlocal::texthash(
4589: show => 'Show details',
4590: hide => 'Hide details',
4591: );
4592: &html_escape(\%html_js_lt);
4593: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4594: return <<"ENDSCRIPT";
4595: <script type="text/javascript">
4596: // <![CDATA[
4597:
4598: function reorderHelpRoles(form,item) {
4599: var changedVal;
4600: $jstext
4601: var newpos = 'helproles_${total}_pos';
4602: var maxh = 1 + $total;
4603: var current = new Array();
4604: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4605: if (item == newpos) {
4606: changedVal = newitemVal;
4607: } else {
4608: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4609: current[newitemVal] = newpos;
4610: }
4611: for (var i=0; i<helproles.length; i++) {
4612: var elementName = 'helproles_'+helproles[i]+'_pos';
4613: if (elementName != item) {
4614: if (form.elements[elementName]) {
4615: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4616: current[currVal] = elementName;
4617: }
4618: }
4619: }
4620: var oldVal;
4621: for (var j=0; j<maxh; j++) {
4622: if (current[j] == undefined) {
4623: oldVal = j;
4624: }
4625: }
4626: if (oldVal < changedVal) {
4627: for (var k=oldVal+1; k<=changedVal ; k++) {
4628: var elementName = current[k];
4629: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4630: }
4631: } else {
4632: for (var k=changedVal; k<oldVal; k++) {
4633: var elementName = current[k];
4634: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4635: }
4636: }
4637: return;
4638: }
4639:
4640: function helpdeskAccess(num) {
4641: var curraccess = null;
4642: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4643: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4644: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4645: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4646: }
4647: }
4648: }
4649: var shown = Array();
4650: var hidden = Array();
4651: if (curraccess == 'none') {
4652: hidden = Array('$hiddenstr');
4653: } else {
4654: if (curraccess == 'status') {
4655: shown = Array('bystatus');
4656: hidden = Array('notinc','notexc');
4657: } else {
4658: if (curraccess == 'exc') {
4659: shown = Array('notexc');
4660: hidden = Array('notinc','bystatus');
4661: }
4662: if (curraccess == 'inc') {
4663: shown = Array('notinc');
4664: hidden = Array('notexc','bystatus');
4665: }
1.293 raeburn 4666: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4667: hidden = Array('notinc','notexc','bystatus');
4668: }
4669: }
4670: }
4671: if (hidden.length > 0) {
4672: for (var i=0; i<hidden.length; i++) {
4673: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4674: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4675: }
4676: }
4677: }
4678: if (shown.length > 0) {
4679: for (var i=0; i<shown.length; i++) {
4680: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4681: if (shown[i] == 'privs') {
4682: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4683: } else {
4684: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4685: }
4686: }
4687: }
4688: }
4689: return;
4690: }
4691:
4692: function toggleHelpdeskItem(num,field) {
4693: if (document.getElementById('helproles_'+num+'_'+field)) {
4694: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4695: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4696: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4697: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4698: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4699: }
4700: } else {
4701: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4702: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4703: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4704: }
4705: }
4706: }
4707: return;
4708: }
4709:
4710: // ]]>
4711: </script>
4712:
4713: ENDSCRIPT
4714: }
4715:
4716: sub helpdeskroles_access {
4717: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4718: $usertypes,$types,$domhelpdesk) = @_;
4719: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4720: my %lt = &Apache::lonlocal::texthash(
4721: 'rou' => 'Role usage',
4722: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4723: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4724: 'dh' => 'All with domain helpdesk role',
4725: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4726: 'none' => 'None',
4727: 'status' => 'Determined based on institutional status',
4728: 'inc' => 'Include all, but exclude specific personnel',
4729: 'exc' => 'Exclude all, but include specific personnel',
4730: );
4731: my %usecheck = (
4732: all => ' checked="checked"',
4733: );
4734: my %displaydiv = (
4735: status => 'none',
4736: inc => 'none',
4737: exc => 'none',
4738: priv => 'block',
4739: );
4740: my $output;
4741: if (ref($current) eq 'HASH') {
4742: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4743: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4744: $usecheck{$current->{access}} = $usecheck{'all'};
4745: delete($usecheck{'all'});
4746: if ($current->{access} =~ /^(status|inc|exc)$/) {
4747: my $access = $1;
4748: $displaydiv{$access} = 'inline';
4749: } elsif ($current->{access} eq 'none') {
4750: $displaydiv{'priv'} = 'none';
4751: }
4752: }
4753: }
4754: }
4755: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4756: '<p>'.$lt{'whi'}.'</p>';
4757: foreach my $access (@{$accesstypes}) {
4758: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4759: ' onclick="helpdeskAccess('."'$num'".');" />'.
4760: $lt{$access}.'</label>';
4761: if ($access eq 'status') {
4762: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4763: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4764: $othertitle,$usertypes,$types).
4765: '</div>';
4766: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4767: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4768: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4769: '</div>';
4770: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4771: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4772: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4773: '</div>';
4774: }
4775: $output .= '</p>';
4776: }
4777: $output .= '</fieldset>';
4778: return $output;
4779: }
4780:
1.121 raeburn 4781: sub radiobutton_prefs {
1.192 raeburn 4782: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 4783: $additional,$align,$firstval) = @_;
1.121 raeburn 4784: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4785: (ref($choices) eq 'HASH'));
4786:
1.170 raeburn 4787: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4788:
4789: foreach my $item (@{$toggles}) {
4790: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4791: $checkedon{$item} = ' checked="checked" ';
4792: $checkedoff{$item} = ' ';
1.121 raeburn 4793: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4794: $checkedoff{$item} = ' checked="checked" ';
4795: $checkedon{$item} = ' ';
4796: }
4797: }
4798: if (ref($settings) eq 'HASH') {
1.121 raeburn 4799: foreach my $item (@{$toggles}) {
1.118 jms 4800: if ($settings->{$item} eq '1') {
4801: $checkedon{$item} = ' checked="checked" ';
4802: $checkedoff{$item} = ' ';
4803: } elsif ($settings->{$item} eq '0') {
4804: $checkedoff{$item} = ' checked="checked" ';
4805: $checkedon{$item} = ' ';
4806: }
4807: }
1.121 raeburn 4808: }
1.192 raeburn 4809: if ($onclick) {
4810: $onclick = ' onclick="'.$onclick.'"';
4811: }
1.121 raeburn 4812: foreach my $item (@{$toggles}) {
1.118 jms 4813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4814: $datatable .=
1.306 raeburn 4815: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4816: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4817: '</span></td>';
4818: if ($align eq 'left') {
4819: $datatable .= '<td class="LC_left_item">';
4820: } else {
4821: $datatable .= '<td class="LC_right_item">';
4822: }
1.385 raeburn 4823: $datatable .= '<span class="LC_nobreak">';
4824: if ($firstval eq 'no') {
4825: $datatable .=
4826: '<label><input type="radio" name="'.
4827: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4828: '</label> <label><input type="radio" name="'.$item.'" '.
4829: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4830: } else {
4831: $datatable .=
4832: '<label><input type="radio" name="'.
4833: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
4834: '</label> <label><input type="radio" name="'.$item.'" '.
4835: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4836: }
4837: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4838: $itemcount ++;
1.121 raeburn 4839: }
4840: return ($datatable,$itemcount);
4841: }
4842:
1.267 raeburn 4843: sub print_ltitools {
4844: my ($dom,$settings,$rowtotal) = @_;
4845: my $rownum = 0;
4846: my $css_class;
4847: my $itemcount = 1;
4848: my $maxnum = 0;
4849: my %ordered;
4850: if (ref($settings) eq 'HASH') {
4851: foreach my $item (keys(%{$settings})) {
4852: if (ref($settings->{$item}) eq 'HASH') {
4853: my $num = $settings->{$item}{'order'};
4854: $ordered{$num} = $item;
4855: }
4856: }
4857: }
4858: my $confname = $dom.'-domainconfig';
4859: my $switchserver = &check_switchserver($dom,$confname);
4860: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4861: my $datatable;
1.267 raeburn 4862: my %lt = <itools_names();
4863: my @courseroles = ('cc','in','ta','ep','st');
4864: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4865: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4866: if (keys(%ordered)) {
4867: my @items = sort { $a <=> $b } keys(%ordered);
4868: for (my $i=0; $i<@items; $i++) {
4869: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4870: my $item = $ordered{$items[$i]};
1.323 raeburn 4871: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4872: if (ref($settings->{$item}) eq 'HASH') {
4873: $title = $settings->{$item}->{'title'};
4874: $url = $settings->{$item}->{'url'};
4875: $key = $settings->{$item}->{'key'};
4876: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4877: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4878: my $image = $settings->{$item}->{'image'};
4879: if ($image ne '') {
4880: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4881: }
1.323 raeburn 4882: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4883: $sigsel{'HMAC-256'} = ' selected="selected"';
4884: } else {
4885: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4886: }
1.267 raeburn 4887: }
1.319 raeburn 4888: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4889: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4890: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4891: for (my $k=0; $k<=$maxnum; $k++) {
4892: my $vpos = $k+1;
4893: my $selstr;
4894: if ($k == $i) {
4895: $selstr = ' selected="selected" ';
4896: }
4897: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4898: }
4899: $datatable .= '</select>'.(' 'x2).
4900: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4901: &mt('Delete?').'</label></span></td>'.
4902: '<td colspan="2">'.
4903: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4904: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4905: (' 'x2).
4906: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4907: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4908: (' 'x2).
4909: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4910: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4911: (' 'x2).
4912: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4913: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4914: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4915: '<br /><br />'.
1.323 raeburn 4916: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4917: ' value="'.$url.'" /></span>'.
4918: (' 'x2).
1.319 raeburn 4919: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4920: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4921: (' 'x2).
1.322 raeburn 4922: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4923: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4924: (' 'x2).
1.267 raeburn 4925: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4926: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4927: '<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>'.
4928: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4929: '</fieldset>'.
4930: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4931: '<span class="LC_nobreak">'.&mt('Display target:');
4932: my %currdisp;
4933: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4934: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4935: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4936: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4937: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4938: } else {
4939: $currdisp{'iframe'} = ' checked="checked"';
4940: }
4941: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4942: $currdisp{'width'} = $1;
4943: }
4944: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4945: $currdisp{'height'} = $1;
4946: }
1.296 raeburn 4947: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4948: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4949: } else {
4950: $currdisp{'iframe'} = ' checked="checked"';
4951: }
1.298 raeburn 4952: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4953: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4954: $lt{$disp}.'</label>'.(' 'x2);
4955: }
4956: $datatable .= (' 'x4);
4957: foreach my $dimen ('width','height') {
4958: $datatable .= '<label>'.$lt{$dimen}.' '.
4959: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4960: (' 'x2);
4961: }
1.334 raeburn 4962: $datatable .= '</span><br />'.
1.296 raeburn 4963: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4964: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4965: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4966: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4967: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4968: my %units = (
4969: 'passback' => 'days',
4970: 'roster' => 'seconds',
4971: );
1.267 raeburn 4972: foreach my $extra ('passback','roster') {
1.319 raeburn 4973: my $validsty = 'none';
4974: my $currvalid;
1.267 raeburn 4975: my $checkedon = '';
4976: my $checkedoff = ' checked="checked"';
4977: if ($settings->{$item}->{$extra}) {
4978: $checkedon = $checkedoff;
4979: $checkedoff = '';
1.319 raeburn 4980: $validsty = 'inline-block';
4981: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4982: $currvalid = $settings->{$item}->{$extra.'valid'};
4983: }
4984: }
4985: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4986: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4987: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4988: &mt('No').'</label>'.(' 'x2).
4989: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4990: &mt('Yes').'</label></span></div>'.
4991: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4992: '<span class="LC_nobreak">'.
4993: &mt("at least [_1] $units{$extra} after launch",
4994: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4995: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4996: }
1.319 raeburn 4997: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4998: if ($imgsrc) {
4999: $datatable .= $imgsrc.
5000: '<label><input type="checkbox" name="ltitools_image_del"'.
5001: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5002: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5003: } else {
5004: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5005: }
5006: if ($switchserver) {
5007: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5008: } else {
5009: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5010: }
5011: $datatable .= '</span></fieldset>';
1.324 raeburn 5012: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5013: if (ref($settings->{$item}) eq 'HASH') {
5014: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5015: %checkedfields = %{$settings->{$item}->{'fields'}};
5016: }
1.324 raeburn 5017: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5018: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5019: %rolemaps = %{$settings->{$item}->{'roles'}};
5020: $checkedfields{'roles'} = 1;
5021: }
5022: }
5023: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5024: '<span class="LC_nobreak">';
1.324 raeburn 5025: my $userfieldstyle = 'display:none;';
5026: my $seluserdom = '';
5027: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5028: foreach my $field (@fields) {
1.324 raeburn 5029: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5030: if ($checkedfields{$field}) {
5031: $checked = ' checked="checked"';
5032: }
1.324 raeburn 5033: if ($field eq 'user') {
5034: $id = ' id="ltitools_user_field_'.$i.'"';
5035: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5036: if ($checked) {
5037: $userfieldstyle = 'display:inline-block';
5038: if ($userincdom) {
5039: $seluserdom = $unseluserdom;
5040: $unseluserdom = '';
5041: }
5042: }
5043: } else {
5044: $spacer = (' ' x2);
5045: }
1.267 raeburn 5046: $datatable .= '<label>'.
1.324 raeburn 5047: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5048: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5049: }
1.324 raeburn 5050: $datatable .= '</span>';
5051: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5052: '<span class="LC_nobreak"> : '.
5053: '<select name="ltitools_userincdom_'.$i.'">'.
5054: '<option value="">'.&mt('Select').'</option>'.
5055: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5056: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5057: '</select></span></div>';
5058: $datatable .= '</fieldset>'.
1.267 raeburn 5059: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5060: foreach my $role (@courseroles) {
5061: my ($selected,$selectnone);
5062: if (!$rolemaps{$role}) {
5063: $selectnone = ' selected="selected"';
5064: }
1.306 raeburn 5065: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5066: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5067: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5068: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5069: foreach my $ltirole (@ltiroles) {
5070: unless ($selectnone) {
5071: if ($rolemaps{$role} eq $ltirole) {
5072: $selected = ' selected="selected"';
5073: } else {
5074: $selected = '';
5075: }
5076: }
5077: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5078: }
5079: $datatable .= '</select></td>';
5080: }
1.273 raeburn 5081: $datatable .= '</tr></table></fieldset>';
5082: my %courseconfig;
5083: if (ref($settings->{$item}) eq 'HASH') {
5084: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5085: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5086: }
5087: }
5088: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5089: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5090: my $checked;
5091: if ($courseconfig{$item}) {
5092: $checked = ' checked="checked"';
5093: }
5094: $datatable .= '<label>'.
5095: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5096: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5097: }
5098: $datatable .= '</span></fieldset>'.
1.267 raeburn 5099: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5100: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5101: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5102: my %custom = %{$settings->{$item}->{'custom'}};
5103: if (keys(%custom) > 0) {
5104: foreach my $key (sort(keys(%custom))) {
5105: $datatable .= '<tr><td><span class="LC_nobreak">'.
5106: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5107: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5108: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5109: ' value="'.$custom{$key}.'" /></td></tr>';
5110: }
5111: }
5112: }
5113: $datatable .= '<tr><td><span class="LC_nobreak">'.
5114: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5115: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5116: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5117: $datatable .= '</table></fieldset></td></tr>'."\n";
5118: $itemcount ++;
5119: }
5120: }
5121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5122: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5123: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5124: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5125: '<select name="ltitools_add_pos"'.$chgstr.'>';
5126: for (my $k=0; $k<$maxnum+1; $k++) {
5127: my $vpos = $k+1;
5128: my $selstr;
5129: if ($k == $maxnum) {
5130: $selstr = ' selected="selected" ';
5131: }
5132: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5133: }
5134: $datatable .= '</select> '."\n".
1.334 raeburn 5135: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5136: '<td colspan="2">'.
5137: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5138: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5139: (' 'x2).
5140: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5141: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5142: (' 'x2).
5143: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5144: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5145: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5146: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5147: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5148: '<br />'.
1.323 raeburn 5149: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5150: (' 'x2).
5151: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5152: (' 'x2).
1.322 raeburn 5153: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5154: (' 'x2).
1.267 raeburn 5155: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5156: '<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".
5157: '</fieldset>'.
5158: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5159: '<span class="LC_nobreak">'.&mt('Display target:');
5160: my %defaultdisp;
5161: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5162: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5163: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5164: $lt{$disp}.'</label>'.(' 'x2);
5165: }
5166: $datatable .= (' 'x4);
5167: foreach my $dimen ('width','height') {
5168: $datatable .= '<label>'.$lt{$dimen}.' '.
5169: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5170: (' 'x2);
5171: }
1.334 raeburn 5172: $datatable .= '</span><br />'.
1.296 raeburn 5173: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5174: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5175: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5176: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5177: '</div><div style=""></div><br />';
1.319 raeburn 5178: my %units = (
5179: 'passback' => 'days',
5180: 'roster' => 'seconds',
5181: );
5182: my %defaulttimes = (
5183: 'passback' => '7',
1.322 raeburn 5184: 'roster' => '300',
1.319 raeburn 5185: );
1.267 raeburn 5186: foreach my $extra ('passback','roster') {
1.319 raeburn 5187: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5188: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5189: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5190: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5191: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5192: &mt('Yes').'</label></span></div>'.
5193: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5194: '<span class="LC_nobreak">'.
5195: &mt("at least [_1] $units{$extra} after launch",
5196: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5197: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5198: }
1.319 raeburn 5199: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5200: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5201: if ($switchserver) {
5202: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5203: } else {
5204: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5205: }
5206: $datatable .= '</span></fieldset>'.
5207: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5208: '<span class="LC_nobreak">';
5209: foreach my $field (@fields) {
1.324 raeburn 5210: my ($id,$onclick,$spacer);
5211: if ($field eq 'user') {
5212: $id = ' id="ltitools_user_field_add"';
5213: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5214: } else {
5215: $spacer = (' ' x2);
5216: }
1.267 raeburn 5217: $datatable .= '<label>'.
1.324 raeburn 5218: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5219: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5220: }
1.324 raeburn 5221: $datatable .= '</span>'.
5222: '<div style="display:none;" id="ltitools_user_div_add">'.
5223: '<span class="LC_nobreak"> : '.
5224: '<select name="ltitools_userincdom_add">'.
5225: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5226: '<option value="0">'.&mt('username').'</option>'.
5227: '<option value="1">'.&mt('username:domain').'</option>'.
5228: '</select></span></div></fieldset>';
5229: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5230: foreach my $role (@courseroles) {
5231: my ($checked,$checkednone);
1.306 raeburn 5232: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5233: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5234: '<select name="ltitools_add_roles_'.$role.'">'.
5235: '<option value="" selected="selected">'.&mt('Select').'</option>';
5236: foreach my $ltirole (@ltiroles) {
5237: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5238: }
5239: $datatable .= '</select></td>';
5240: }
5241: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5242: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5243: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5244: $datatable .= '<label>'.
5245: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5246: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5247: }
5248: $datatable .= '</span></fieldset>'.
1.267 raeburn 5249: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5250: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5251: '<tr><td><span class="LC_nobreak">'.
5252: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5253: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5254: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5255: '</table></fieldset>'."\n".
1.267 raeburn 5256: '</td>'."\n".
5257: '</tr>'."\n";
5258: $itemcount ++;
5259: return $datatable;
5260: }
5261:
5262: sub ltitools_names {
5263: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5264: 'title' => 'Title',
5265: 'version' => 'Version',
5266: 'msgtype' => 'Message Type',
1.323 raeburn 5267: 'sigmethod' => 'Signature Method',
1.296 raeburn 5268: 'url' => 'URL',
5269: 'key' => 'Key',
1.322 raeburn 5270: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5271: 'secret' => 'Secret',
5272: 'icon' => 'Icon',
1.324 raeburn 5273: 'user' => 'User',
1.296 raeburn 5274: 'fullname' => 'Full Name',
5275: 'firstname' => 'First Name',
5276: 'lastname' => 'Last Name',
5277: 'email' => 'E-mail',
5278: 'roles' => 'Role',
1.298 raeburn 5279: 'window' => 'Window',
5280: 'tab' => 'Tab',
1.296 raeburn 5281: 'iframe' => 'iFrame',
5282: 'height' => 'Height',
5283: 'width' => 'Width',
5284: 'linktext' => 'Default Link Text',
5285: 'explanation' => 'Default Explanation',
5286: 'passback' => 'Tool can return grades:',
5287: 'roster' => 'Tool can retrieve roster:',
5288: 'crstarget' => 'Display target',
5289: 'crslabel' => 'Course label',
5290: 'crstitle' => 'Course title',
5291: 'crslinktext' => 'Link Text',
5292: 'crsexplanation' => 'Explanation',
1.318 raeburn 5293: 'crsappend' => 'Provider URL',
1.267 raeburn 5294: );
5295: return %lt;
5296: }
5297:
1.372 raeburn 5298: sub print_proctoring {
5299: my ($dom,$settings,$rowtotal) = @_;
5300: my $itemcount = 1;
5301: my (%ordered,%providernames,%current,%currentdef);
5302: my $confname = $dom.'-domainconfig';
5303: my $switchserver = &check_switchserver($dom,$confname);
5304: if (ref($settings) eq 'HASH') {
5305: foreach my $item (keys(%{$settings})) {
5306: if (ref($settings->{$item}) eq 'HASH') {
5307: my $num = $settings->{$item}{'order'};
5308: $ordered{$num} = $item;
5309: }
5310: }
5311: } else {
5312: %ordered = (
5313: 1 => 'proctorio',
5314: 2 => 'examity',
5315: );
5316: }
5317: %providernames = &proctoring_providernames();
5318: my $maxnum = scalar(keys(%ordered));
5319: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5320: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5321: if (ref($requref) eq 'HASH') {
5322: %requserfields = %{$requref};
5323: }
5324: if (ref($opturef) eq 'HASH') {
5325: %optuserfields = %{$opturef};
5326: }
5327: if (ref($defref) eq 'HASH') {
5328: %defaults = %{$defref};
5329: }
5330: if (ref($extref) eq 'HASH') {
5331: %extended = %{$extref};
5332: }
5333: if (ref($crsref) eq 'HASH') {
5334: %crsconf = %{$crsref};
5335: }
5336: if (ref($rolesref) eq 'ARRAY') {
5337: @courseroles = @{$rolesref};
5338: }
5339: if (ref($ltiref) eq 'ARRAY') {
5340: @ltiroles = @{$ltiref};
5341: }
5342: my $datatable;
5343: my $css_class;
5344: if (keys(%ordered)) {
5345: my @items = sort { $a <=> $b } keys(%ordered);
5346: for (my $i=0; $i<@items; $i++) {
5347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5348: my $provider = $ordered{$items[$i]};
5349: my $optionsty = 'none';
5350: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5351: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5352: if (ref($settings) eq 'HASH') {
5353: if (ref($settings->{$provider}) eq 'HASH') {
5354: %current = %{$settings->{$provider}};
5355: if ($current{'available'}) {
5356: $optionsty = 'block';
5357: $available = 1;
5358: }
5359: if ($current{'lifetime'} =~ /^\d+$/) {
5360: $lifetime = $current{'lifetime'};
5361: }
5362: if ($current{'version'} =~ /^\d+\.\d+$/) {
5363: $version = $current{'version'};
5364: }
5365: if ($current{'image'} ne '') {
5366: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5367: }
5368: if (ref($current{'fields'}) eq 'ARRAY') {
5369: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5370: }
5371: $userincdom = $current{'incdom'};
5372: if (ref($current{'roles'}) eq 'HASH') {
5373: %rolemaps = %{$current{'roles'}};
5374: $checkedfields{'roles'} = 1;
5375: }
5376: if (ref($current{'defaults'}) eq 'ARRAY') {
5377: foreach my $val (@{$current{'defaults'}}) {
5378: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5379: $inuse{$val} = 1;
5380: } else {
5381: foreach my $poss (keys(%{$extended{$provider}})) {
5382: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5383: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5384: $inuse{$poss} = $val;
5385: last;
5386: }
5387: }
5388: }
5389: }
5390: }
5391: } elsif (ref($current{'defaults'}) eq 'HASH') {
5392: foreach my $key (keys(%{$current{'defaults'}})) {
5393: my $currval = $current{'defaults'}{$key};
5394: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5395: $inuse{$key} = 1;
5396: } else {
5397: my $match;
5398: foreach my $poss (keys(%{$extended{$provider}})) {
5399: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5400: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5401: $inuse{$poss} = $key;
5402: last;
5403: }
5404: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5405: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5406: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5407: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5408: $currentdef{$inner} = $currval;
5409: $match = 1;
5410: last;
5411: }
5412: } elsif ($inner eq $key) {
5413: $currentdef{$key} = $currval;
5414: $match = 1;
5415: last;
5416: }
5417: }
5418: }
5419: last if ($match);
5420: }
5421: }
5422: }
5423: }
5424: if (ref($current{'crsconf'}) eq 'ARRAY') {
5425: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5426: }
5427: }
5428: }
5429: my %lt = &proctoring_titles($provider);
5430: my %fieldtitles = &proctoring_fieldtitles($provider);
5431: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5432: my %checkedavailable = (
5433: yes => '',
5434: no => ' checked="checked"',
5435: );
5436: if ($available) {
5437: $checkedavailable{'yes'} = $checkedavailable{'no'};
5438: $checkedavailable{'no'} = '';
5439: }
5440: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5441: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5442: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5443: for (my $k=0; $k<$maxnum; $k++) {
5444: my $vpos = $k+1;
5445: my $selstr;
5446: if ($k == $i) {
5447: $selstr = ' selected="selected" ';
5448: }
5449: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5450: }
5451: if ($version eq '') {
5452: if ($provider eq 'proctorio') {
5453: $version = '1.0';
5454: } elsif ($provider eq 'examity') {
5455: $version = '1.1';
5456: }
5457: }
5458: if ($lifetime eq '') {
5459: $lifetime = '300';
5460: }
5461: $datatable .=
5462: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5463: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5464: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5465: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5466: '</td>'.
5467: '<td colspan="2">'.
5468: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5469: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5470: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5471: (' 'x2).
5472: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5473: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5474: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5475: (' 'x2).
5476: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5477: '<br />'.
5478: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5479: '<br />'.
5480: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5481: (' 'x2).
5482: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5483: '<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";
5484: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5485: if ($imgsrc) {
5486: $datatable .= $imgsrc.
5487: '<label><input type="checkbox" name="proctoring_image_del"'.
5488: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5489: '<span class="LC_nobreak"> '.&mt('Replace:');
5490: }
5491: $datatable .= ' ';
5492: if ($switchserver) {
5493: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5494: } else {
5495: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5496: }
5497: unless ($imgsrc) {
5498: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5499: }
5500: $datatable .= '</fieldset>'."\n";
5501: if (ref($requserfields{$provider}) eq 'ARRAY') {
5502: if (@{$requserfields{$provider}} > 0) {
5503: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5504: foreach my $field (@{$requserfields{$provider}}) {
5505: $datatable .= '<span class="LC_nobreak">'.
5506: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5507: $lt{$field}.'</label>';
5508: if ($field eq 'user') {
5509: my $seluserdom = '';
5510: my $unseluserdom = ' selected="selected"';
5511: if ($userincdom) {
5512: $seluserdom = $unseluserdom;
5513: $unseluserdom = '';
5514: }
5515: $datatable .= ': '.
5516: '<select name="proctoring_userincdom_'.$provider.'">'.
5517: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5518: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5519: '</select> ';
5520: } else {
5521: $datatable .= ' ';
5522: if ($field eq 'roles') {
5523: $showroles = 1;
5524: }
5525: }
5526: $datatable .= '</span> ';
5527: }
5528: }
5529: $datatable .= '</fieldset>'."\n";
5530: }
5531: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5532: if (@{$optuserfields{$provider}} > 0) {
5533: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5534: foreach my $field (@{$optuserfields{$provider}}) {
5535: my $checked;
5536: if ($checkedfields{$field}) {
5537: $checked = ' checked="checked"';
5538: }
5539: $datatable .= '<span class="LC_nobreak">'.
5540: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5541: }
5542: $datatable .= '</fieldset>'."\n";
5543: }
5544: }
5545: if (ref($defaults{$provider}) eq 'ARRAY') {
5546: if (@{$defaults{$provider}}) {
5547: my (%options,@selectboxes);
5548: if (ref($extended{$provider}) eq 'HASH') {
5549: %options = %{$extended{$provider}};
5550: }
5551: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5552: my ($rem,$numinrow,$dropdowns);
5553: if ($provider eq 'proctorio') {
5554: $datatable .= '<table>';
5555: $numinrow = 4;
5556: }
5557: my $i = 0;
5558: foreach my $field (@{$defaults{$provider}}) {
5559: my $checked;
5560: if ($inuse{$field}) {
5561: $checked = ' checked="checked"';
5562: }
5563: if ($provider eq 'examity') {
5564: if ($field eq 'display') {
5565: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5566: foreach my $option ('iframe','tab','window') {
5567: my $checkdisp;
5568: if ($currentdef{'target'} eq $option) {
5569: $checkdisp = ' checked="checked"';
5570: }
5571: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5572: $fieldtitles{$option}.'</label>'.(' 'x2);
5573: }
5574: $datatable .= (' 'x4);
5575: foreach my $dimen ('width','height') {
5576: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5577: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5578: 'value="'.$currentdef{$dimen}.'" /></label>'.
5579: (' 'x2);
5580: }
5581: $datatable .= '</span><br />'.
5582: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5583: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5584: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5585: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5586: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5587: $currentdef{'explanation'}.
5588: '</textarea></div><div style=""></div><br />';
5589: }
5590: } else {
5591: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5592: my ($output,$selnone);
5593: unless ($checked) {
5594: $selnone = ' selected="selected"';
5595: }
5596: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5597: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5598: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5599: foreach my $option (@{$options{$field}}) {
5600: my $sel;
5601: if ($inuse{$field} eq $option) {
5602: $sel = ' selected="selected"';
5603: }
5604: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5605: }
5606: $output .= '</select></span>';
5607: push(@selectboxes,$output);
5608: } else {
5609: $rem = $i%($numinrow);
5610: if ($rem == 0) {
5611: if ($i > 0) {
5612: $datatable .= '</tr>';
5613: }
5614: $datatable .= '<tr>';
5615: }
5616: $datatable .= '<td class="LC_left_item">'.
5617: '<span class="LC_nobreak">'.
5618: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5619: $fieldtitles{$field}.'</label></span></td>';
5620: $i++;
5621: }
5622: }
5623: }
5624: if ($provider eq 'proctorio') {
5625: if ($numinrow) {
5626: $rem = $i%$numinrow;
5627: }
5628: my $colsleft = $numinrow - $rem;
5629: if ($colsleft > 1) {
5630: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5631: } else {
5632: $datatable .= '<td class="LC_left_item">';
5633: }
5634: $datatable .= ' '.
5635: '</td></tr></table>';
5636: if (@selectboxes) {
5637: $datatable .= '<hr /><table>';
5638: $numinrow = 2;
5639: for (my $i=0; $i<@selectboxes; $i++) {
5640: $rem = $i%($numinrow);
5641: if ($rem == 0) {
5642: if ($i > 0) {
5643: $datatable .= '</tr>';
5644: }
5645: $datatable .= '<tr>';
5646: }
5647: $datatable .= '<td class="LC_left_item">'.
5648: $selectboxes[$i].'</td>';
5649: }
5650: if ($numinrow) {
5651: $rem = $i%$numinrow;
5652: }
5653: $colsleft = $numinrow - $rem;
5654: if ($colsleft > 1) {
5655: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5656: } else {
5657: $datatable .= '<td class="LC_left_item">';
5658: }
5659: $datatable .= ' '.
5660: '</td></tr></table>';
5661: }
5662: }
5663: $datatable .= '</fieldset>';
5664: }
5665: if (ref($crsconf{$provider}) eq 'ARRAY') {
5666: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5667: '<legend>'.&mt('Configurable in course').'</legend>';
5668: my ($rem,$numinrow);
5669: if ($provider eq 'proctorio') {
5670: $datatable .= '<table>';
5671: $numinrow = 4;
5672: }
5673: my $i = 0;
5674: foreach my $item (@{$crsconf{$provider}}) {
5675: my $name;
5676: if ($provider eq 'examity') {
5677: $name = $lt{'crs'.$item};
5678: } elsif ($provider eq 'proctorio') {
5679: $name = $fieldtitles{$item};
5680: $rem = $i%($numinrow);
5681: if ($rem == 0) {
5682: if ($i > 0) {
5683: $datatable .= '</tr>';
5684: }
5685: $datatable .= '<tr>';
5686: }
5687: $datatable .= '<td class="LC_left_item>';
5688: }
5689: my $checked;
5690: if ($crsconfig{$item}) {
5691: $checked = ' checked="checked"';
5692: }
5693: $datatable .= '<span class="LC_nobreak"><label>'.
5694: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5695: $name.'</label></span>';
5696: if ($provider eq 'examity') {
5697: $datatable .= ' ';
5698: }
5699: $datatable .= "\n";
5700: $i++;
5701: }
5702: if ($provider eq 'proctorio') {
5703: if ($numinrow) {
5704: $rem = $i%$numinrow;
5705: }
5706: my $colsleft = $numinrow - $rem;
5707: if ($colsleft > 1) {
5708: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5709: } else {
5710: $datatable .= '<td class="LC_left_item">';
5711: }
5712: $datatable .= ' '.
5713: '</td></tr></table>';
5714: }
5715: $datatable .= '</fieldset>';
5716: }
5717: if ($showroles) {
5718: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5719: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5720: foreach my $role (@courseroles) {
5721: my ($selected,$selectnone);
5722: if (!$rolemaps{$role}) {
5723: $selectnone = ' selected="selected"';
5724: }
5725: $datatable .= '<td style="text-align: center">'.
5726: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5727: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5728: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5729: foreach my $ltirole (@ltiroles) {
5730: unless ($selectnone) {
5731: if ($rolemaps{$role} eq $ltirole) {
5732: $selected = ' selected="selected"';
5733: } else {
5734: $selected = '';
5735: }
5736: }
5737: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5738: }
5739: $datatable .= '</select></td>';
5740: }
5741: $datatable .= '</tr></table></fieldset>'.
5742: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5743: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5744: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5745: '<tr><td></td><td>lms</td>'.
5746: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5747: ' value="Loncapa" disabled="disabled"/></td></tr>';
5748: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5749: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5750: my %custom = %{$settings->{$provider}->{'custom'}};
5751: if (keys(%custom) > 0) {
5752: foreach my $key (sort(keys(%custom))) {
5753: next if ($key eq 'lms');
5754: $datatable .= '<tr><td><span class="LC_nobreak">'.
5755: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5756: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5757: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5758: ' value="'.$custom{$key}.'" /></td></tr>';
5759: }
5760: }
5761: }
5762: $datatable .= '<tr><td><span class="LC_nobreak">'.
5763: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5764: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5765: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5766: '</table></fieldset></td></tr>'."\n";
5767: }
5768: $datatable .= '</td></tr>';
5769: }
5770: $itemcount ++;
5771: }
5772: }
5773: return $datatable;
5774: }
5775:
5776: sub proctoring_data {
5777: my $requserfields = {
5778: proctorio => ['user'],
5779: examity => ['roles','user'],
5780: };
5781: my $optuserfields = {
5782: proctorio => ['fullname'],
5783: examity => ['fullname','firstname','lastname','email'],
5784: };
5785: my $defaults = {
5786: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5787: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5788: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5789: 'closetabs','onescreen','print','downloads','cache','rightclick',
5790: 'reentry','calculator','whiteboard'],
5791: examity => ['display'],
5792: };
5793: my $extended = {
5794: proctorio => {
5795: verifyid => ['verifyidauto','verifyidlive'],
5796: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5797: tabslinks => ['notabs','linksonly'],
5798: reentry => ['noreentry','agentreentry'],
5799: calculator => ['calculatorbasic','calculatorsci'],
5800: },
5801: examity => {
5802: display => {
5803: target => ['iframe','tab','window'],
5804: width => '',
5805: height => '',
5806: linktext => '',
5807: explanation => '',
5808: },
5809: },
5810: };
5811: my $crsconf = {
5812: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5813: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5814: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5815: 'closetabs','onescreen','print','downloads','cache','rightclick',
5816: 'reentry','calculator','whiteboard'],
5817: examity => ['label','title','target','linktext','explanation','append'],
5818: };
5819: my $courseroles = ['cc','in','ta','ep','st'];
5820: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5821: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5822: }
5823:
5824: sub proctoring_titles {
5825: my ($item) = @_;
5826: my (%common_lt,%custom_lt);
5827: %common_lt = &Apache::lonlocal::texthash (
5828: 'avai' => 'Available?',
5829: 'base' => 'Basic Settings',
5830: 'requ' => 'User data required to be sent on launch',
5831: 'optu' => 'User data optionally sent on launch',
5832: 'udsl' => 'User data sent on launch',
5833: 'defa' => 'Defaults for items configurable in course',
5834: 'sigmethod' => 'Signature Method',
5835: 'key' => 'Key',
5836: 'lifetime' => 'Nonce lifetime (s)',
5837: 'secret' => 'Secret',
5838: 'icon' => 'Icon',
5839: 'fullname' => 'Full Name',
5840: 'visible' => 'Visible input',
5841: 'username' => 'username',
5842: 'user' => 'User',
5843: );
5844: if ($item eq 'proctorio') {
5845: %custom_lt = &Apache::lonlocal::texthash (
5846: 'version' => 'OAuth version',
5847: 'url' => 'API URL',
5848: 'uname:dom' => 'username-domain',
5849: );
5850: } elsif ($item eq 'examity') {
5851: %custom_lt = &Apache::lonlocal::texthash (
5852: 'version' => 'LTI Version',
5853: 'url' => 'URL',
5854: 'uname:dom' => 'username:domain',
5855: 'msgtype' => 'Message Type',
5856: 'firstname' => 'First Name',
5857: 'lastname' => 'Last Name',
5858: 'email' => 'E-mail',
5859: 'roles' => 'Role',
5860: 'crstarget' => 'Display target',
5861: 'crslabel' => 'Course label',
5862: 'crstitle' => 'Course title',
5863: 'crslinktext' => 'Link Text',
5864: 'crsexplanation' => 'Explanation',
5865: 'crsappend' => 'Provider URL',
5866: );
5867: }
5868: my %lt = (%common_lt,%custom_lt);
5869: return %lt;
5870: }
5871:
5872: sub proctoring_fieldtitles {
5873: my ($item) = @_;
5874: if ($item eq 'proctorio') {
5875: return &Apache::lonlocal::texthash (
5876: 'recordvideo' => 'Record video',
5877: 'recordaudio' => 'Record audio',
5878: 'recordscreen' => 'Record screen',
5879: 'recordwebtraffic' => 'Record web traffic',
5880: 'recordroomstart' => 'Record room scan',
5881: 'verifyvideo' => 'Verify webcam',
5882: 'verifyaudio' => 'Verify microphone',
5883: 'verifydesktop' => 'Verify desktop recording',
5884: 'verifyid' => 'Photo ID verification',
5885: 'verifysignature' => 'Require signature',
5886: 'fullscreen' => 'Fullscreen',
5887: 'clipboard' => 'Disable copy/paste',
5888: 'tabslinks' => 'New tabs/windows',
5889: 'closetabs' => 'Close other tabs',
5890: 'onescreen' => 'Limit to single screen',
5891: 'print' => 'Disable Printing',
5892: 'downloads' => 'Disable Downloads',
5893: 'cache' => 'Empty cache after exam',
5894: 'rightclick' => 'Disable right click',
5895: 'reentry' => 'Re-entry to exam',
5896: 'calculator' => 'Onscreen calculator',
5897: 'whiteboard' => 'Onscreen whiteboard',
5898: 'verifyidauto' => 'Automated verification',
5899: 'verifyidlive' => 'Live agent verification',
5900: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5901: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5902: 'fullscreensever' => 'Forced, navigation away ends exam',
5903: 'notabs' => 'Disaallowed',
5904: 'linksonly' => 'Allowed from links in exam',
5905: 'noreentry' => 'Disallowed',
5906: 'agentreentry' => 'Agent required for re-entry',
5907: 'calculatorbasic' => 'Basic',
5908: 'calculatorsci' => 'Scientific',
5909: );
5910: } elsif ($item eq 'examity') {
5911: return &Apache::lonlocal::texthash (
5912: 'target' => 'Display target',
5913: 'window' => 'Window',
5914: 'tab' => 'Tab',
5915: 'iframe' => 'iFrame',
5916: 'height' => 'Height (pixels)',
5917: 'width' => 'Width (pixels)',
5918: 'linktext' => 'Default Link Text',
5919: 'explanation' => 'Default Explanation',
5920: 'append' => 'Provider URL',
5921: );
5922: }
5923: }
5924:
5925: sub proctoring_providernames {
5926: return (
5927: proctorio => 'Proctorio',
5928: examity => 'Examity',
5929: );
5930: }
5931:
1.320 raeburn 5932: sub print_lti {
5933: my ($dom,$settings,$rowtotal) = @_;
5934: my $itemcount = 1;
5935: my $maxnum = 0;
5936: my $css_class;
5937: my %ordered;
5938: if (ref($settings) eq 'HASH') {
5939: foreach my $item (keys(%{$settings})) {
5940: if (ref($settings->{$item}) eq 'HASH') {
5941: my $num = $settings->{$item}{'order'};
1.390 ! raeburn 5942: if ($num eq '') {
! 5943: $num = scalar(keys(%{$settings}));
! 5944: }
1.320 raeburn 5945: $ordered{$num} = $item;
5946: }
5947: }
5948: }
5949: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5950: my $datatable;
1.320 raeburn 5951: my %lt = <i_names();
5952: if (keys(%ordered)) {
5953: my @items = sort { $a <=> $b } keys(%ordered);
5954: for (my $i=0; $i<@items; $i++) {
5955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5956: my $item = $ordered{$items[$i]};
1.345 raeburn 5957: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 5958: if (ref($settings->{$item}) eq 'HASH') {
5959: $key = $settings->{$item}->{'key'};
5960: $secret = $settings->{$item}->{'secret'};
5961: $lifetime = $settings->{$item}->{'lifetime'};
5962: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5963: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 5964: $current = $settings->{$item};
5965: }
1.345 raeburn 5966: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5967: my %checkedrequser = (
5968: yes => ' checked="checked"',
5969: no => '',
5970: );
5971: if (!$requser) {
5972: $checkedrequser{'no'} = $checkedrequser{'yes'};
5973: $checkedrequser{'yes'} = '';
1.352 raeburn 5974: }
1.320 raeburn 5975: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5976: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5977: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5978: for (my $k=0; $k<=$maxnum; $k++) {
5979: my $vpos = $k+1;
5980: my $selstr;
5981: if ($k == $i) {
5982: $selstr = ' selected="selected" ';
5983: }
5984: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5985: }
5986: $datatable .= '</select>'.(' 'x2).
5987: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5988: &mt('Delete?').'</label></span></td>'.
5989: '<td colspan="2">'.
5990: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5991: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5992: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 5993: (' 'x2).
5994: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5995: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5996: (' 'x2).
5997: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 5998: 'value="'.$lifetime.'" size="3" /></span>'.
5999: (' 'x2).
6000: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6001: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6002: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6003: '<br /><br />'.
6004: '<span class="LC_nobreak">'.$lt{'key'}.
6005: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6006: (' 'x2).
6007: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6008: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6009: '<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>'.
6010: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 6011: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 6012: $itemcount ++;
6013: }
6014: }
6015: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6016: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6017: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6018: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6019: '<select name="lti_pos_add"'.$chgstr.'>';
6020: for (my $k=0; $k<$maxnum+1; $k++) {
6021: my $vpos = $k+1;
6022: my $selstr;
6023: if ($k == $maxnum) {
6024: $selstr = ' selected="selected" ';
6025: }
6026: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6027: }
6028: $datatable .= '</select> '."\n".
1.334 raeburn 6029: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 6030: '<td colspan="2">'.
6031: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6032: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6033: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 6034: (' 'x2).
6035: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6036: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6037: (' 'x2).
1.345 raeburn 6038: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6039: (' 'x2).
6040: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6041: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6042: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6043: '<br /><br />'.
6044: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6045: (' 'x2).
6046: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6047: '<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 6048: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 6049: '</td>'."\n".
6050: '</tr>'."\n";
6051: $$rowtotal ++;
6052: return $datatable;;
6053: }
6054:
6055: sub lti_names {
6056: my %lt = &Apache::lonlocal::texthash(
6057: 'version' => 'LTI Version',
6058: 'url' => 'URL',
6059: 'key' => 'Key',
1.322 raeburn 6060: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6061: 'consumer' => 'Consumer',
1.320 raeburn 6062: 'secret' => 'Secret',
1.345 raeburn 6063: 'requser' => "User's identity sent",
1.320 raeburn 6064: 'email' => 'Email address',
6065: 'sourcedid' => 'User ID',
6066: 'other' => 'Other',
6067: 'passback' => 'Can return grades to Consumer:',
6068: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6069: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6070: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6071: );
6072: return %lt;
6073: }
6074:
6075: sub lti_options {
1.325 raeburn 6076: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6077: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6078: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6079: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
6080: $checked{'makecrs'}{'N'} = ' checked="checked"';
6081: $checked{'mapcrstype'} = {};
6082: $checked{'makeuser'} = {};
6083: $checked{'selfenroll'} = {};
6084: $checked{'crssec'} = {};
6085: $checked{'crssecsrc'} = {};
1.325 raeburn 6086: $checked{'lcauth'} = {};
1.326 raeburn 6087: $checked{'menuitem'} = {};
1.325 raeburn 6088: if ($num eq 'add') {
6089: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6090: }
1.320 raeburn 6091: my $userfieldsty = 'none';
6092: my $crsfieldsty = 'none';
6093: my $crssecfieldsty = 'none';
6094: my $secsrcfieldsty = 'none';
1.363 raeburn 6095: my $callbacksty = 'none';
1.337 raeburn 6096: my $passbacksty = 'none';
1.345 raeburn 6097: my $optionsty = 'block';
1.325 raeburn 6098: my $lcauthparm;
6099: my $lcauthparmstyle = 'display:none';
6100: my $lcauthparmtext;
1.326 raeburn 6101: my $menusty;
1.325 raeburn 6102: my $numinrow = 4;
1.326 raeburn 6103: my %menutitles = <imenu_titles();
1.320 raeburn 6104:
6105: if (ref($current) eq 'HASH') {
1.345 raeburn 6106: if (!$current->{'requser'}) {
6107: $optionsty = 'none';
6108: }
1.320 raeburn 6109: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6110: $checked{'mapuser'}{'sourcedid'} = '';
6111: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6112: $checked{'mapuser'}{'email'} = ' checked="checked"';
6113: } else {
6114: $checked{'mapuser'}{'other'} = ' checked="checked"';
6115: $userfield = $current->{'mapuser'};
6116: $userfieldsty = 'inline-block';
6117: }
6118: }
6119: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6120: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6121: if ($current->{'mapcrs'} eq 'context_id') {
6122: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6123: } else {
6124: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6125: $cidfield = $current->{'mapcrs'};
6126: $crsfieldsty = 'inline-block';
6127: }
6128: }
6129: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6130: foreach my $type (@{$current->{'mapcrstype'}}) {
6131: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6132: }
6133: }
1.345 raeburn 6134: if ($current->{'makecrs'}) {
1.320 raeburn 6135: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6136: }
1.320 raeburn 6137: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6138: foreach my $role (@{$current->{'makeuser'}}) {
6139: $checked{'makeuser'}{$role} = ' checked="checked"';
6140: }
6141: }
1.325 raeburn 6142: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6143: $checked{'lcauth'}{$1} = ' checked="checked"';
6144: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6145: $lcauthparm = $current->{'lcauthparm'};
6146: $lcauthparmstyle = 'display:table-row';
6147: if ($current->{'lcauth'} eq 'localauth') {
6148: $lcauthparmtext = &mt('Local auth argument');
6149: } else {
6150: $lcauthparmtext = &mt('Kerberos domain');
6151: }
6152: }
6153: }
1.320 raeburn 6154: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6155: foreach my $role (@{$current->{'selfenroll'}}) {
6156: $checked{'selfenroll'}{$role} = ' checked="checked"';
6157: }
6158: }
6159: if (ref($current->{'maproles'}) eq 'HASH') {
6160: %rolemaps = %{$current->{'maproles'}};
6161: }
6162: if ($current->{'section'} ne '') {
6163: $checked{'crssec'}{'Y'} = ' checked="checked"';
6164: $crssecfieldsty = 'inline-block';
6165: if ($current->{'section'} eq 'course_section_sourcedid') {
6166: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6167: } else {
6168: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6169: $crssecsrc = $current->{'section'};
6170: $secsrcfieldsty = 'inline-block';
6171: }
6172: } else {
6173: $checked{'crssec'}{'N'} = ' checked="checked"';
6174: }
1.363 raeburn 6175: if ($current->{'callback'} ne '') {
6176: $callback = $current->{'callback'};
6177: $checked{'callback'}{'Y'} = ' checked="checked"';
6178: $callbacksty = 'inline-block';
6179: } else {
6180: $checked{'callback'}{'N'} = ' checked="checked"';
6181: }
1.326 raeburn 6182: if ($current->{'topmenu'}) {
6183: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6184: } else {
6185: $checked{'topmenu'}{'N'} = ' checked="checked"';
6186: }
6187: if ($current->{'inlinemenu'}) {
6188: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6189: } else {
6190: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6191: }
6192: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6193: $menusty = 'inline-block';
6194: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6195: foreach my $item (@{$current->{'lcmenu'}}) {
6196: if (exists($menutitles{$item})) {
6197: $checked{'menuitem'}{$item} = ' checked="checked"';
6198: }
6199: }
6200: }
6201: } else {
6202: $menusty = 'none';
6203: }
1.320 raeburn 6204: } else {
6205: $checked{'makecrs'}{'N'} = ' checked="checked"';
6206: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6207: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6208: $checked{'topmenu'}{'N'} = ' checked="checked"';
6209: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6210: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6211: $menusty = 'inline-block';
1.320 raeburn 6212: }
1.325 raeburn 6213: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6214: my %coursetypetitles = &Apache::lonlocal::texthash (
6215: official => 'Official',
6216: unofficial => 'Unofficial',
6217: community => 'Community',
6218: textbook => 'Textbook',
6219: placement => 'Placement Test',
1.325 raeburn 6220: lti => 'LTI Provider',
1.320 raeburn 6221: );
1.325 raeburn 6222: my @authtypes = ('internal','krb4','krb5','localauth');
6223: my %shortauth = (
6224: internal => 'int',
6225: krb4 => 'krb4',
6226: krb5 => 'krb5',
6227: localauth => 'loc'
6228: );
6229: my %authnames = &authtype_names();
1.320 raeburn 6230: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6231: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6232: my @courseroles = ('cc','in','ta','ep','st');
6233: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6234: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6235: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6236: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6237: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6238: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6239: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 6240: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6241: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6242: foreach my $option ('sourcedid','email','other') {
6243: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6244: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6245: ($option eq 'other' ? '' : (' 'x2) );
6246: }
6247: $output .= '</span></div>'.
6248: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6249: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6250: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 6251: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 6252: foreach my $ltirole (@lticourseroles) {
6253: my ($selected,$selectnone);
6254: if ($rolemaps{$ltirole} eq '') {
6255: $selectnone = ' selected="selected"';
6256: }
6257: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6258: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6259: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6260: foreach my $role (@courseroles) {
6261: unless ($selectnone) {
6262: if ($rolemaps{$ltirole} eq $role) {
6263: $selected = ' selected="selected"';
6264: } else {
6265: $selected = '';
6266: }
6267: }
6268: $output .= '<option value="'.$role.'"'.$selected.'>'.
6269: &Apache::lonnet::plaintext($role,'Course').
6270: '</option>';
6271: }
6272: $output .= '</select></td>';
6273: }
6274: $output .= '</tr></table></fieldset>'.
1.345 raeburn 6275: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6276: foreach my $ltirole (@ltiroles) {
6277: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6278: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6279: }
6280: $output .= '</fieldset>'.
1.345 raeburn 6281: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6282: '<table>'.
6283: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6284: '</table>'.
6285: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6286: '<td class="LC_left_item">';
6287: foreach my $auth ('lti',@authtypes) {
6288: my $authtext;
6289: if ($auth eq 'lti') {
6290: $authtext = &mt('None');
6291: } else {
6292: $authtext = $authnames{$shortauth{$auth}};
6293: }
6294: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6295: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6296: $authtext.'</label></span> ';
6297: }
6298: $output .= '</td></tr>'.
6299: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6300: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6301: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6302: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6303: '</table></fieldset>'.
1.345 raeburn 6304: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6305: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6306: &mt('Unique course identifier').': ';
6307: foreach my $option ('course_offering_sourcedid','context_id','other') {
6308: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6309: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6310: ($option eq 'other' ? '' : (' 'x2) );
6311: }
1.334 raeburn 6312: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6313: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6314: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6315: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6316: foreach my $type (@coursetypes) {
6317: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6318: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6319: (' 'x2);
6320: }
6321: $output .= '</span></fieldset>'.
1.345 raeburn 6322: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6323: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6324: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6325: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6326: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6327: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6328: '</fieldset>'.
1.345 raeburn 6329: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6330: foreach my $lticrsrole (@lticourseroles) {
6331: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6332: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6333: }
6334: $output .= '</fieldset>'.
1.345 raeburn 6335: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6336: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6337: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6338: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6339: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6340: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6341: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6342: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6343: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6344: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6345: &mt('Standard field').'</label>'.(' 'x2).
6346: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6347: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6348: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6349: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6350: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6351: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6352: foreach my $extra ('roster','passback') {
1.320 raeburn 6353: my $checkedon = '';
6354: my $checkedoff = ' checked="checked"';
1.337 raeburn 6355: if ($extra eq 'passback') {
6356: $pb1p1chk = ' checked="checked"';
6357: $pb1p0chk = '';
6358: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6359: } else {
6360: $onclickpb = '';
6361: }
1.320 raeburn 6362: if (ref($current) eq 'HASH') {
6363: if (($current->{$extra})) {
6364: $checkedon = $checkedoff;
6365: $checkedoff = '';
1.337 raeburn 6366: if ($extra eq 'passback') {
6367: $passbacksty = 'inline-block';
6368: }
6369: if ($current->{'passbackformat'} eq '1.0') {
6370: $pb1p0chk = ' checked="checked"';
6371: $pb1p1chk = '';
6372: }
1.320 raeburn 6373: }
6374: }
6375: $output .= $lt{$extra}.' '.
1.337 raeburn 6376: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6377: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6378: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6379: &mt('Yes').'</label><br />';
6380: }
1.337 raeburn 6381: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6382: '<span class="LC_nobreak">'.&mt('Grade format').
6383: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6384: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6385: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6386: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
6387: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6388: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
6389: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6390: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6391: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6392: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6393: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6394: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6395: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6396: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 6397: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 6398: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6399: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6400: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6401: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 6402: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 6403: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6404: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6405: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6406: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6407: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 6408: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 6409: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6410: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6411: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6412: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6413: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6414: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6415: (' 'x2);
6416: }
1.334 raeburn 6417: $output .= '</span></div></fieldset>';
1.320 raeburn 6418: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6419: #
6420: # $output .= '</fieldset>'.
6421: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6422: return $output;
6423: }
6424:
1.326 raeburn 6425: sub ltimenu_titles {
6426: return &Apache::lonlocal::texthash(
6427: fullname => 'Full name',
6428: coursetitle => 'Course title',
6429: role => 'Role',
6430: logout => 'Logout',
6431: grades => 'Grades',
6432: );
6433: }
6434:
1.121 raeburn 6435: sub print_coursedefaults {
1.139 raeburn 6436: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6437: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6438: my $itemcount = 1;
1.192 raeburn 6439: my %choices = &Apache::lonlocal::texthash (
6440: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6441: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6442: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6443: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6444: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6445: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6446: texengine => 'Default method to display mathematics',
1.257 raeburn 6447: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6448: canclone => "People who may clone a course (besides course's owner and coordinators)",
6449: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6450: );
1.198 raeburn 6451: my %staticdefaults = (
6452: anonsurvey_threshold => 10,
6453: uploadquota => 500,
1.257 raeburn 6454: postsubmit => 60,
1.276 raeburn 6455: mysqltables => 172800,
1.198 raeburn 6456: );
1.139 raeburn 6457: if ($position eq 'top') {
1.257 raeburn 6458: %defaultchecked = (
6459: 'canuse_pdfforms' => 'off',
6460: 'uselcmath' => 'on',
6461: 'usejsme' => 'on',
1.289 raeburn 6462: 'canclone' => 'none',
1.257 raeburn 6463: );
6464: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6465: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6466: if (ref($settings) eq 'HASH') {
6467: if ($settings->{'texengine'}) {
6468: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6469: $deftex = $settings->{'texengine'};
6470: }
6471: }
6472: }
6473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6474: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6475: '<span class="LC_nobreak">'.$choices{'texengine'}.
6476: '</span></td><td class="LC_right_item">'.
6477: '<select name="texengine">'."\n";
6478: my %texoptions = (
6479: MathJax => 'MathJax',
6480: mimetex => &mt('Convert to Images'),
6481: tth => &mt('TeX to HTML'),
6482: );
6483: foreach my $renderer ('MathJax','mimetex','tth') {
6484: my $selected = '';
6485: if ($renderer eq $deftex) {
6486: $selected = ' selected="selected"';
6487: }
6488: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6489: }
6490: $mathdisp .= '</select></td></tr>'."\n";
6491: $itemcount ++;
1.139 raeburn 6492: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6493: \%choices,$itemcount);
1.314 raeburn 6494: $datatable = $mathdisp.$datatable;
1.264 raeburn 6495: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6496: $datatable .=
1.306 raeburn 6497: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6498: '<span class="LC_nobreak">'.$choices{'canclone'}.
6499: '</span></td><td class="LC_left_item">';
6500: my $currcanclone = 'none';
6501: my $onclick;
6502: my @cloneoptions = ('none','domain');
1.380 raeburn 6503: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6504: none => 'No additional course requesters',
6505: domain => "Any course requester in course's domain",
6506: instcode => 'Course requests for official courses ...',
6507: );
6508: my (%codedefaults,@code_order,@posscodes);
6509: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6510: \@code_order) eq 'ok') {
6511: if (@code_order > 0) {
6512: push(@cloneoptions,'instcode');
6513: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6514: }
6515: }
6516: if (ref($settings) eq 'HASH') {
6517: if ($settings->{'canclone'}) {
6518: if (ref($settings->{'canclone'}) eq 'HASH') {
6519: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6520: if (@code_order > 0) {
6521: $currcanclone = 'instcode';
6522: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6523: }
6524: }
6525: } elsif ($settings->{'canclone'} eq 'domain') {
6526: $currcanclone = $settings->{'canclone'};
6527: }
6528: }
1.289 raeburn 6529: }
1.264 raeburn 6530: foreach my $option (@cloneoptions) {
6531: my ($checked,$additional);
6532: if ($currcanclone eq $option) {
6533: $checked = ' checked="checked"';
6534: }
6535: if ($option eq 'instcode') {
6536: if (@code_order) {
6537: my $show = 'none';
6538: if ($checked) {
6539: $show = 'block';
6540: }
1.317 raeburn 6541: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6542: &mt('Institutional codes for new and cloned course have identical:').
6543: '<br />';
6544: foreach my $item (@code_order) {
6545: my $codechk;
6546: if ($checked) {
6547: if (grep(/^\Q$item\E$/,@posscodes)) {
6548: $codechk = ' checked="checked"';
6549: }
6550: }
6551: $additional .= '<label>'.
6552: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6553: $item.'</label>';
6554: }
6555: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6556: }
6557: }
6558: $datatable .=
6559: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6560: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6561: '</label> '.$additional.'</span><br />';
6562: }
6563: $datatable .= '</td>'.
6564: '</tr>';
6565: $itemcount ++;
1.139 raeburn 6566: } else {
6567: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6568: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6569: my $currusecredits = 0;
1.257 raeburn 6570: my $postsubmitclient = 1;
1.271 raeburn 6571: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6572: if (ref($settings) eq 'HASH') {
6573: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6574: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6575: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6576: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6577: }
6578: }
1.192 raeburn 6579: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6580: foreach my $type (@types) {
6581: next if ($type eq 'community');
6582: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6583: if ($defcredits{$type} ne '') {
6584: $currusecredits = 1;
6585: }
6586: }
6587: }
6588: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6589: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6590: $postsubmitclient = 0;
6591: foreach my $type (@types) {
6592: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6593: }
6594: } else {
6595: foreach my $type (@types) {
6596: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6597: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6598: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6599: } else {
6600: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6601: }
6602: } else {
6603: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6604: }
6605: }
6606: }
6607: } else {
6608: foreach my $type (@types) {
6609: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6610: }
6611: }
1.276 raeburn 6612: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6613: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6614: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6615: }
6616: } else {
6617: foreach my $type (@types) {
6618: $currmysql{$type} = $staticdefaults{'mysqltables'};
6619: }
6620: }
1.258 raeburn 6621: } else {
6622: foreach my $type (@types) {
6623: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6624: }
1.139 raeburn 6625: }
6626: if (!$currdefresponder) {
1.198 raeburn 6627: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6628: } elsif ($currdefresponder < 1) {
6629: $currdefresponder = 1;
6630: }
1.198 raeburn 6631: foreach my $type (@types) {
6632: if ($curruploadquota{$type} eq '') {
6633: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6634: }
6635: }
1.139 raeburn 6636: $datatable .=
1.192 raeburn 6637: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6638: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6639: '</span></td>'.
6640: '<td class="LC_right_item"><span class="LC_nobreak">'.
6641: '<input type="text" name="anonsurvey_threshold"'.
6642: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6643: '</td></tr>'."\n";
6644: $itemcount ++;
6645: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6646: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6647: $choices{'uploadquota'}.
6648: '</span></td>'.
1.306 raeburn 6649: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6650: '<table><tr>';
1.198 raeburn 6651: foreach my $type (@types) {
1.306 raeburn 6652: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6653: '<input type="text" name="uploadquota_'.$type.'"'.
6654: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6655: }
6656: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6657: $itemcount ++;
1.236 raeburn 6658: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6659: my $display = 'none';
1.192 raeburn 6660: if ($currusecredits) {
6661: $display = 'block';
6662: }
6663: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6664: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6665: foreach my $type (@types) {
6666: next if ($type eq 'community');
1.306 raeburn 6667: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6668: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6669: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6670: }
6671: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6672: %defaultchecked = ('coursecredits' => 'off');
6673: @toggles = ('coursecredits');
6674: my $current = {
6675: 'coursecredits' => $currusecredits,
6676: };
6677: (my $table,$itemcount) =
6678: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6679: \%choices,$itemcount,$onclick,$additional,'left');
6680: $datatable .= $table;
6681: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6682: my $display = 'none';
6683: if ($postsubmitclient) {
6684: $display = 'block';
6685: }
6686: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6687: &mt('Number of seconds submit is disabled').'<br />'.
6688: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6689: '<table><tr>';
1.257 raeburn 6690: foreach my $type (@types) {
1.306 raeburn 6691: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6692: '<input type="text" name="'.$type.'_timeout" value="'.
6693: $deftimeout{$type}.'" size="5" /></td>';
6694: }
6695: $additional .= '</tr></table></div>'."\n";
6696: %defaultchecked = ('postsubmit' => 'on');
6697: @toggles = ('postsubmit');
1.280 raeburn 6698: $current = {
6699: 'postsubmit' => $postsubmitclient,
6700: };
1.257 raeburn 6701: ($table,$itemcount) =
6702: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6703: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6704: $datatable .= $table;
1.276 raeburn 6705: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6706: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6707: $choices{'mysqltables'}.
6708: '</span></td>'.
1.306 raeburn 6709: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6710: '<table><tr>';
6711: foreach my $type (@types) {
1.306 raeburn 6712: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6713: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6714: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6715: }
6716: $datatable .= '</tr></table></td></tr>'."\n";
6717: $itemcount ++;
6718:
1.139 raeburn 6719: }
1.192 raeburn 6720: $$rowtotal += $itemcount;
1.121 raeburn 6721: return $datatable;
1.118 jms 6722: }
6723:
1.231 raeburn 6724: sub print_selfenrollment {
6725: my ($position,$dom,$settings,$rowtotal) = @_;
6726: my ($css_class,$datatable);
6727: my $itemcount = 1;
1.271 raeburn 6728: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6729: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6730: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6731: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6732: my @rows;
6733: my $key;
6734: if ($position eq 'top') {
6735: $key = 'admin';
6736: if (ref($rowsref) eq 'ARRAY') {
6737: @rows = @{$rowsref};
6738: }
6739: } elsif ($position eq 'middle') {
6740: $key = 'default';
6741: @rows = ('types','registered','approval','limit');
6742: }
6743: foreach my $row (@rows) {
6744: if (defined($titlesref->{$row})) {
6745: $itemcount ++;
6746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6747: $datatable .= '<tr'.$css_class.'>'.
6748: '<td>'.$titlesref->{$row}.'</td>'.
6749: '<td class="LC_left_item">'.
6750: '<table><tr>';
6751: my (%current,%currentcap);
6752: if (ref($settings) eq 'HASH') {
6753: if (ref($settings->{$key}) eq 'HASH') {
6754: foreach my $type (@types) {
6755: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6756: $current{$type} = $settings->{$key}->{$type}->{$row};
6757: }
6758: if (($row eq 'limit') && ($key eq 'default')) {
6759: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6760: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6761: }
6762: }
6763: }
6764: }
6765: }
6766: my %roles = (
6767: '0' => &Apache::lonnet::plaintext('dc'),
6768: );
6769:
6770: foreach my $type (@types) {
6771: unless (($row eq 'registered') && ($key eq 'default')) {
6772: $datatable .= '<th>'.&mt($type).'</th>';
6773: }
6774: }
6775: unless (($row eq 'registered') && ($key eq 'default')) {
6776: $datatable .= '</tr><tr>';
6777: }
6778: foreach my $type (@types) {
6779: if ($type eq 'community') {
6780: $roles{'1'} = &mt('Community personnel');
6781: } else {
6782: $roles{'1'} = &mt('Course personnel');
6783: }
6784: $datatable .= '<td style="vertical-align: top">';
6785: if ($position eq 'top') {
6786: my %checked;
6787: if ($current{$type} eq '0') {
6788: $checked{'0'} = ' checked="checked"';
6789: } else {
6790: $checked{'1'} = ' checked="checked"';
6791: }
6792: foreach my $role ('1','0') {
6793: $datatable .= '<span class="LC_nobreak"><label>'.
6794: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6795: 'value="'.$role.'"'.$checked{$role}.' />'.
6796: $roles{$role}.'</label></span> ';
6797: }
6798: } else {
6799: if ($row eq 'types') {
6800: my %checked;
6801: if ($current{$type} =~ /^(all|dom)$/) {
6802: $checked{$1} = ' checked="checked"';
6803: } else {
6804: $checked{''} = ' checked="checked"';
6805: }
6806: foreach my $val ('','dom','all') {
6807: $datatable .= '<span class="LC_nobreak"><label>'.
6808: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6809: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6810: }
6811: } elsif ($row eq 'registered') {
6812: my %checked;
6813: if ($current{$type} eq '1') {
6814: $checked{'1'} = ' checked="checked"';
6815: } else {
6816: $checked{'0'} = ' checked="checked"';
6817: }
6818: foreach my $val ('0','1') {
6819: $datatable .= '<span class="LC_nobreak"><label>'.
6820: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6821: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6822: }
6823: } elsif ($row eq 'approval') {
6824: my %checked;
6825: if ($current{$type} =~ /^([12])$/) {
6826: $checked{$1} = ' checked="checked"';
6827: } else {
6828: $checked{'0'} = ' checked="checked"';
6829: }
6830: for my $val (0..2) {
6831: $datatable .= '<span class="LC_nobreak"><label>'.
6832: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6833: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6834: }
6835: } elsif ($row eq 'limit') {
6836: my %checked;
6837: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6838: $checked{$1} = ' checked="checked"';
6839: } else {
6840: $checked{'none'} = ' checked="checked"';
6841: }
6842: my $cap;
6843: if ($currentcap{$type} =~ /^\d+$/) {
6844: $cap = $currentcap{$type};
6845: }
6846: foreach my $val ('none','allstudents','selfenrolled') {
6847: $datatable .= '<span class="LC_nobreak"><label>'.
6848: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6849: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6850: }
6851: $datatable .= '<br />'.
6852: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6853: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6854: '</span>';
6855: }
6856: }
6857: $datatable .= '</td>';
6858: }
6859: $datatable .= '</tr>';
6860: }
6861: $datatable .= '</table></td></tr>';
6862: }
6863: } elsif ($position eq 'bottom') {
1.235 raeburn 6864: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6865: }
6866: $$rowtotal += $itemcount;
6867: return $datatable;
6868: }
6869:
6870: sub print_validation_rows {
6871: my ($caller,$dom,$settings,$rowtotal) = @_;
6872: my ($itemsref,$namesref,$fieldsref);
6873: if ($caller eq 'selfenroll') {
6874: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6875: } elsif ($caller eq 'requestcourses') {
6876: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6877: }
6878: my %currvalidation;
6879: if (ref($settings) eq 'HASH') {
6880: if (ref($settings->{'validation'}) eq 'HASH') {
6881: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6882: }
1.235 raeburn 6883: }
6884: my $datatable;
6885: my $itemcount = 0;
6886: foreach my $item (@{$itemsref}) {
6887: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6888: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6889: $namesref->{$item}.
6890: '</span></td>'.
6891: '<td class="LC_left_item">';
6892: if (($item eq 'url') || ($item eq 'button')) {
6893: $datatable .= '<span class="LC_nobreak">'.
6894: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6895: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6896: } elsif ($item eq 'fields') {
6897: my @currfields;
6898: if (ref($currvalidation{$item}) eq 'ARRAY') {
6899: @currfields = @{$currvalidation{$item}};
6900: }
6901: foreach my $field (@{$fieldsref}) {
6902: my $check = '';
6903: if (grep(/^\Q$field\E$/,@currfields)) {
6904: $check = ' checked="checked"';
6905: }
6906: $datatable .= '<span class="LC_nobreak"><label>'.
6907: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6908: ' value="'.$field.'"'.$check.' />'.$field.
6909: '</label></span> ';
6910: }
6911: } elsif ($item eq 'markup') {
1.334 raeburn 6912: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6913: $currvalidation{$item}.
1.231 raeburn 6914: '</textarea>';
1.235 raeburn 6915: }
6916: $datatable .= '</td></tr>'."\n";
6917: if (ref($rowtotal)) {
1.231 raeburn 6918: $itemcount ++;
6919: }
6920: }
1.235 raeburn 6921: if ($caller eq 'requestcourses') {
6922: my %currhash;
1.248 raeburn 6923: if (ref($settings) eq 'HASH') {
6924: if (ref($settings->{'validation'}) eq 'HASH') {
6925: if ($settings->{'validation'}{'dc'} ne '') {
6926: $currhash{$settings->{'validation'}{'dc'}} = 1;
6927: }
1.235 raeburn 6928: }
6929: }
6930: my $numinrow = 2;
6931: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6932: 'validationdc',%currhash);
1.247 raeburn 6933: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6934: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6935: if ($numdc > 1) {
1.247 raeburn 6936: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6937: } else {
1.247 raeburn 6938: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6939: }
1.247 raeburn 6940: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 6941: $itemcount ++;
6942: }
6943: if (ref($rowtotal)) {
6944: $$rowtotal += $itemcount;
6945: }
1.231 raeburn 6946: return $datatable;
6947: }
6948:
1.357 raeburn 6949: sub print_privacy {
6950: my ($position,$dom,$settings,$rowtotal) = @_;
6951: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
6952: my $itemcount = 0;
6953: unless ($position eq 'top') {
6954: @items = ('domain','author','course','community');
6955: %names = &Apache::lonlocal::texthash (
6956: domain => 'Assigned domain role(s)',
6957: author => 'Assigned co-author role(s)',
6958: course => 'Assigned course role(s)',
6959: community => 'Assigned community role',
6960: );
6961: $numinrow = 4;
6962: ($othertitle,$usertypes,$types) =
6963: &Apache::loncommon::sorted_inst_types($dom);
6964: }
6965: if (($position eq 'top') || ($position eq 'middle')) {
6966: my (%by_ip,%by_location,@intdoms,@instdoms);
6967: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6968: if ($position eq 'top') {
6969: my %curr;
6970: my @options = ('none','user','domain','auto');
6971: my %titles = &Apache::lonlocal::texthash (
6972: none => 'Not allowed',
6973: user => 'User authorizes',
6974: domain => 'DC authorizes',
6975: auto => 'Unrestricted',
6976: instdom => 'Other domain shares institution/provider',
6977: extdom => 'Other domain has different institution/provider',
6978: );
6979: my %names = &Apache::lonlocal::texthash (
6980: domain => 'Domain role',
6981: author => 'Co-author role',
6982: course => 'Course role',
6983: community => 'Community role',
6984: );
6985: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6986: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6987: foreach my $domtype ('instdom','extdom') {
6988: my (%checked,$skip);
6989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6990: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
6991: '<td class="LC_left_item">';
6992: if ($domtype eq 'instdom') {
6993: unless (@instdoms > 1) {
6994: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
6995: $skip = 1;
6996: }
6997: } elsif ($domtype eq 'extdom') {
6998: if (keys(%by_location) == 0) {
6999: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7000: $skip = 1;
7001: }
7002: }
7003: unless ($skip) {
7004: foreach my $roletype ('domain','author','course','community') {
7005: $checked{'auto'} = ' checked="checked"';
7006: if (ref($settings) eq 'HASH') {
7007: if (ref($settings->{approval}) eq 'HASH') {
7008: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7009: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7010: $checked{$1} = ' checked="checked"';
7011: $checked{'auto'} = '';
7012: }
7013: }
7014: }
7015: }
7016: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7017: foreach my $option (@options) {
7018: $datatable .= '<span class="LC_nobreak"><label>'.
7019: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7020: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7021: '</label></span> ';
7022: }
7023: $datatable .= '</fieldset>';
7024: }
7025: }
7026: $datatable .= '</td></tr>';
7027: $itemcount ++;
7028: }
7029: } elsif ($position eq 'middle') {
7030: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7031: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7032: foreach my $item (@{$types}) {
7033: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7034: $numinrow,$itemcount,'','','','','',
7035: '',$usertypes->{$item});
7036: $itemcount ++;
7037: }
7038: }
7039: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7040: $numinrow,$itemcount,'','','','','',
7041: '',$othertitle);
7042: $itemcount ++;
7043: } else {
1.360 raeburn 7044: my (@insttypes,%insttitles);
7045: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7046: @insttypes = @{$types};
7047: %insttitles = %{$usertypes};
7048: }
7049: foreach my $item (@insttypes,'default') {
7050: my $title;
7051: if ($item eq 'default') {
7052: $title = $othertitle;
7053: } else {
7054: $title = $insttitles{$item};
7055: }
7056: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7057: $datatable .= '<tr'.$css_class.'>'.
7058: '<td class="LC_left_item">'.$title.'</td>'.
7059: '<td class="LC_left_item">'.
7060: &mt('Nothing to set here, as there are no other domains').
7061: '</td></tr>';
7062: $itemcount ++;
7063: }
1.357 raeburn 7064: }
7065: }
7066: } else {
7067: my $prefix;
7068: if ($position eq 'lower') {
7069: $prefix = 'priv';
7070: } else {
7071: $prefix = 'unpriv';
7072: }
7073: foreach my $item (@items) {
7074: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7075: $numinrow,$itemcount,'','','','','',
7076: '',$names{$item});
7077: $itemcount ++;
7078: }
7079: }
7080: if (ref($rowtotal)) {
7081: $$rowtotal += $itemcount;
7082: }
7083: return $datatable;
7084: }
7085:
1.354 raeburn 7086: sub print_passwords {
7087: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7088: my ($datatable,$css_class);
7089: my $itemcount = 0;
7090: my %titles = &Apache::lonlocal::texthash (
7091: captcha => '"Forgot Password" CAPTCHA validation',
7092: link => 'Reset link expiration (hours)',
7093: case => 'Case-sensitive usernames/e-mail',
7094: prelink => 'Information required (form 1)',
7095: postlink => 'Information required (form 2)',
7096: emailsrc => 'LON-CAPA e-mail address type(s)',
7097: customtext => 'Domain specific text (HTML)',
7098: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7099: intauth_check => 'Check bcrypt cost if authenticated',
7100: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7101: permanent => 'Permanent e-mail address',
7102: critical => 'Critical notification address',
7103: notify => 'Notification address',
7104: min => 'Minimum password length',
7105: max => 'Maximum password length',
7106: chars => 'Required characters',
7107: expire => 'Password expiration (days)',
1.356 raeburn 7108: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7109: );
7110: if ($position eq 'top') {
7111: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7112: my $shownlinklife = 2;
7113: my $prelink = 'both';
7114: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7115: if (ref($settings) eq 'HASH') {
7116: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7117: $shownlinklife = $settings->{resetlink};
7118: }
7119: if (ref($settings->{resetcase}) eq 'ARRAY') {
7120: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7121: }
7122: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7123: $prelink = $settings->{resetprelink};
7124: }
7125: if (ref($settings->{resetpostlink}) eq 'HASH') {
7126: %postlink = %{$settings->{resetpostlink}};
7127: }
7128: if (ref($settings->{resetemail}) eq 'ARRAY') {
7129: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7130: }
7131: if ($settings->{resetremove}) {
7132: $nostdtext = 1;
7133: }
7134: if ($settings->{resetcustom}) {
7135: $customurl = $settings->{resetcustom};
7136: }
7137: } else {
7138: if (ref($types) eq 'ARRAY') {
7139: foreach my $item (@{$types}) {
7140: $casesens{$item} = 1;
7141: $postlink{$item} = ['username','email'];
7142: }
7143: }
7144: $casesens{'default'} = 1;
7145: $postlink{'default'} = ['username','email'];
7146: $prelink = 'both';
7147: %emailsrc = (
7148: permanent => 1,
7149: critical => 1,
7150: notify => 1,
7151: );
7152: }
7153: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7154: $itemcount ++;
7155: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7156: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7157: '<td class="LC_left_item">'.
7158: '<input type="textbox" value="'.$shownlinklife.'" '.
7159: 'name="passwords_link" size="3" /></td></tr>';
7160: $itemcount ++;
7161: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7162: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7163: '<td class="LC_left_item">';
7164: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7165: foreach my $item (@{$types}) {
7166: my $checkedcase;
7167: if ($casesens{$item}) {
7168: $checkedcase = ' checked="checked"';
7169: }
7170: $datatable .= '<span class="LC_nobreak"><label>'.
7171: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7172: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7173: '</span> ';
1.354 raeburn 7174: }
7175: }
7176: my $checkedcase;
7177: if ($casesens{'default'}) {
7178: $checkedcase = ' checked="checked"';
7179: }
7180: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7181: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7182: $othertitle.'</label></span></td>';
7183: $itemcount ++;
7184: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7185: my %checkedpre = (
7186: both => ' checked="checked"',
7187: either => '',
7188: );
7189: if ($prelink eq 'either') {
7190: $checkedpre{either} = ' checked="checked"';
7191: $checkedpre{both} = '';
7192: }
7193: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7194: '<td class="LC_left_item"><span class="LC_nobreak">'.
7195: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7196: &mt('Both username and e-mail address').'</label></span> '.
7197: '<span class="LC_nobreak"><label>'.
7198: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7199: &mt('Either username or e-mail address').'</label></span></td></tr>';
7200: $itemcount ++;
7201: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7202: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7203: '<td class="LC_left_item">';
7204: my %postlinked;
7205: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7206: foreach my $item (@{$types}) {
7207: undef(%postlinked);
7208: $datatable .= '<fieldset style="display: inline-block;">'.
7209: '<legend>'.$usertypes->{$item}.'</legend>';
7210: if (ref($postlink{$item}) eq 'ARRAY') {
7211: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7212: }
7213: foreach my $field ('email','username') {
7214: my $checked;
7215: if ($postlinked{$field}) {
7216: $checked = ' checked="checked"';
7217: }
7218: $datatable .= '<span class="LC_nobreak"><label>'.
7219: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7220: $field.'"'.$checked.' />'.$field.'</label>'.
7221: '<span> ';
7222: }
7223: $datatable .= '</fieldset>';
7224: }
7225: }
7226: if (ref($postlink{'default'}) eq 'ARRAY') {
7227: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7228: }
7229: $datatable .= '<fieldset style="display: inline-block;">'.
7230: '<legend>'.$othertitle.'</legend>';
7231: foreach my $field ('email','username') {
7232: my $checked;
7233: if ($postlinked{$field}) {
7234: $checked = ' checked="checked"';
7235: }
7236: $datatable .= '<span class="LC_nobreak"><label>'.
7237: '<input type="checkbox" name="passwords_postlink_default" value="'.
7238: $field.'"'.$checked.' />'.$field.'</label>'.
7239: '<span> ';
7240: }
7241: $datatable .= '</fieldset></td></tr>';
7242: $itemcount ++;
7243: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7244: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7245: '<td class="LC_left_item">';
7246: foreach my $type ('permanent','critical','notify') {
7247: my $checkedemail;
7248: if ($emailsrc{$type}) {
7249: $checkedemail = ' checked="checked"';
7250: }
7251: $datatable .= '<span class="LC_nobreak"><label>'.
7252: '<input type="checkbox" name="passwords_emailsrc" value="'.
7253: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7254: '<span> ';
7255: }
7256: $datatable .= '</td></tr>';
7257: $itemcount ++;
7258: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7259: my $switchserver = &check_switchserver($dom,$confname);
7260: my ($showstd,$noshowstd);
7261: if ($nostdtext) {
7262: $noshowstd = ' checked="checked"';
7263: } else {
7264: $showstd = ' checked="checked"';
7265: }
7266: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7267: '<td class="LC_left_item"><span class="LC_nobreak">'.
7268: &mt('Retain standard text:').
7269: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7270: &mt('Yes').'</label>'.' '.
7271: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7272: &mt('No').'</label></span><br />'.
7273: '<span class="LC_fontsize_small">'.
7274: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7275: &mt('Include custom text:');
7276: if ($customurl) {
1.369 raeburn 7277: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7278: undef,undef,undef,undef,'background-color:#ffffff');
7279: $datatable .= '<span class="LC_nobreak"> '.$link.
7280: '<label><input type="checkbox" name="passwords_custom_del"'.
7281: ' value="1" />'.&mt('Delete?').'</label></span>'.
7282: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7283: }
7284: if ($switchserver) {
7285: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7286: } else {
7287: $datatable .='<span class="LC_nobreak"> '.
7288: '<input type="file" name="passwords_customfile" /></span>';
7289: }
7290: $datatable .= '</td></tr>';
7291: } elsif ($position eq 'middle') {
7292: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7293: my @items = ('intauth_cost','intauth_check','intauth_switch');
7294: my %defaults;
7295: if (ref($domconf{'defaults'}) eq 'HASH') {
7296: %defaults = %{$domconf{'defaults'}};
7297: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7298: $defaults{'intauth_cost'} = 10;
7299: }
7300: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7301: $defaults{'intauth_check'} = 0;
7302: }
7303: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7304: $defaults{'intauth_switch'} = 0;
7305: }
7306: } else {
7307: %defaults = (
7308: 'intauth_cost' => 10,
7309: 'intauth_check' => 0,
7310: 'intauth_switch' => 0,
7311: );
7312: }
7313: foreach my $item (@items) {
7314: if ($itemcount%2) {
7315: $css_class = '';
7316: } else {
7317: $css_class = ' class="LC_odd_row" ';
7318: }
7319: $datatable .= '<tr'.$css_class.'>'.
7320: '<td><span class="LC_nobreak">'.$titles{$item}.
7321: '</span></td><td class="LC_left_item" colspan="3">';
7322: if ($item eq 'intauth_switch') {
7323: my @options = (0,1,2);
7324: my %optiondesc = &Apache::lonlocal::texthash (
7325: 0 => 'No',
7326: 1 => 'Yes',
7327: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7328: );
7329: $datatable .= '<table width="100%">';
7330: foreach my $option (@options) {
7331: my $checked = ' ';
7332: if ($defaults{$item} eq $option) {
7333: $checked = ' checked="checked"';
7334: }
7335: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7336: '<label><input type="radio" name="'.$item.
7337: '" value="'.$option.'"'.$checked.' />'.
7338: $optiondesc{$option}.'</label></span></td></tr>';
7339: }
7340: $datatable .= '</table>';
7341: } elsif ($item eq 'intauth_check') {
7342: my @options = (0,1,2);
7343: my %optiondesc = &Apache::lonlocal::texthash (
7344: 0 => 'No',
7345: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7346: 2 => 'Yes, disallow login if stored cost is less than domain default',
7347: );
7348: $datatable .= '<table width="100%">';
7349: foreach my $option (@options) {
7350: my $checked = ' ';
7351: my $onclick;
7352: if ($defaults{$item} eq $option) {
7353: $checked = ' checked="checked"';
7354: }
7355: if ($option == 2) {
7356: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7357: }
7358: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7359: '<label><input type="radio" name="'.$item.
7360: '" value="'.$option.'"'.$checked.$onclick.' />'.
7361: $optiondesc{$option}.'</label></span></td></tr>';
7362: }
7363: $datatable .= '</table>';
7364: } else {
7365: $datatable .= '<input type="text" name="'.$item.'" value="'.
7366: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7367: }
7368: $datatable .= '</td></tr>';
7369: $itemcount ++;
7370: }
7371: } elsif ($position eq 'lower') {
1.356 raeburn 7372: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7373: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7374: if (ref($settings) eq 'HASH') {
7375: if ($settings->{min}) {
7376: $min = $settings->{min};
7377: }
7378: if ($settings->{max}) {
7379: $max = $settings->{max};
7380: }
7381: if (ref($settings->{chars}) eq 'ARRAY') {
7382: map { $chars{$_} = 1; } (@{$settings->{chars}});
7383: }
7384: if ($settings->{expire}) {
7385: $expire = $settings->{expire};
7386: }
1.358 raeburn 7387: if ($settings->{numsaved}) {
7388: $numsaved = $settings->{numsaved};
1.356 raeburn 7389: }
1.354 raeburn 7390: }
7391: my %rulenames = &Apache::lonlocal::texthash(
7392: uc => 'At least one upper case letter',
7393: lc => 'At least one lower case letter',
7394: num => 'At least one number',
7395: spec => 'At least one non-alphanumeric',
7396: );
7397: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7398: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7399: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7400: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7401: 'onblur="javascript:warnIntPass(this);" />'.
7402: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7403: '</span></td></tr>';
7404: $itemcount ++;
7405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7406: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7407: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7408: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7409: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7410: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7411: '</span></td></tr>';
7412: $itemcount ++;
7413: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7414: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7415: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7416: '</span></td>';
7417: my $numinrow = 2;
7418: my @possrules = ('uc','lc','num','spec');
7419: $datatable .= '<td class="LC_left_item"><table>';
7420: for (my $i=0; $i<@possrules; $i++) {
7421: my ($rem,$checked);
7422: if ($chars{$possrules[$i]}) {
7423: $checked = ' checked="checked"';
7424: }
7425: $rem = $i%($numinrow);
7426: if ($rem == 0) {
7427: if ($i > 0) {
7428: $datatable .= '</tr>';
7429: }
7430: $datatable .= '<tr>';
7431: }
7432: $datatable .= '<td><span class="LC_nobreak"><label>'.
7433: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7434: $rulenames{$possrules[$i]}.'</label></span></td>';
7435: }
7436: my $rem = @possrules%($numinrow);
7437: my $colsleft = $numinrow - $rem;
7438: if ($colsleft > 1 ) {
7439: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7440: ' </td>';
7441: } elsif ($colsleft == 1) {
7442: $datatable .= '<td class="LC_left_item"> </td>';
7443: }
7444: $datatable .='</table></td></tr>';
7445: $itemcount ++;
7446: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7447: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7448: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7449: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7450: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7451: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7452: '</span></td></tr>';
1.356 raeburn 7453: $itemcount ++;
7454: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7455: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7456: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7457: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7458: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7459: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7460: '</span></td></tr>';
1.354 raeburn 7461: } else {
1.359 raeburn 7462: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7463: my %ownerchg = (
7464: by => {},
7465: for => {},
7466: );
7467: my %ownertitles = &Apache::lonlocal::texthash (
7468: by => 'Course owner status(es) allowed',
7469: for => 'Student status(es) allowed',
7470: );
1.354 raeburn 7471: if (ref($settings) eq 'HASH') {
1.359 raeburn 7472: if (ref($settings->{crsownerchg}) eq 'HASH') {
7473: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7474: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7475: }
7476: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7477: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7478: }
1.354 raeburn 7479: }
7480: }
7481: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7482: $datatable .= '<tr '.$css_class.'>'.
7483: '<td>'.
7484: &mt('Requirements').'<ul>'.
1.359 raeburn 7485: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7486: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7487: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7488: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7489: '</ul>'.
7490: '</td>'.
1.359 raeburn 7491: '<td class="LC_left_item">';
7492: foreach my $item ('by','for') {
7493: $datatable .= '<fieldset style="display: inline-block;">'.
7494: '<legend>'.$ownertitles{$item}.'</legend>';
7495: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7496: foreach my $type (@{$types}) {
7497: my $checked;
7498: if ($ownerchg{$item}{$type}) {
7499: $checked = ' checked="checked"';
7500: }
7501: $datatable .= '<span class="LC_nobreak"><label>'.
7502: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7503: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7504: '</span> ';
1.359 raeburn 7505: }
7506: }
7507: my $checked;
7508: if ($ownerchg{$item}{'default'}) {
7509: $checked = ' checked="checked"';
7510: }
7511: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7512: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7513: $othertitle.'</label></span></fieldset>';
7514: }
7515: $datatable .= '</td></tr>';
1.354 raeburn 7516: }
7517: return $datatable;
7518: }
7519:
1.373 raeburn 7520: sub print_wafproxy {
7521: my ($position,$dom,$settings,$rowtotal) = @_;
7522: my $css_class;
7523: my $itemcount = 0;
7524: my $datatable;
7525: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7526: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7527: my %lt = &wafproxy_titles();
1.373 raeburn 7528: foreach my $server (sort(keys(%servers))) {
7529: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7530: next if ($serverhome eq '');
1.373 raeburn 7531: my $serverdom;
7532: if ($serverhome ne $server) {
7533: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7534: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7535: $othercontrol{$server} = $serverdom;
7536: }
1.373 raeburn 7537: } else {
7538: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7539: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7540: if ($serverdom ne $dom) {
7541: $othercontrol{$server} = $serverdom;
7542: } else {
7543: $setdom = 1;
7544: if (ref($settings) eq 'HASH') {
7545: if (ref($settings->{'alias'}) eq 'HASH') {
7546: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7547: if ($aliases{$dom} ne '') {
7548: $showdom = 1;
7549: }
1.373 raeburn 7550: }
1.388 raeburn 7551: if (ref($settings->{'saml'}) eq 'HASH') {
7552: $saml{$dom} = $settings->{'saml'};
7553: }
1.373 raeburn 7554: }
7555: }
7556: }
7557: }
1.381 raeburn 7558: if ($setdom) {
7559: %{$values{$dom}} = ();
7560: if (ref($settings) eq 'HASH') {
7561: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7562: $values{$dom}{$item} = $settings->{$item};
7563: }
7564: }
7565: }
1.373 raeburn 7566: if (keys(%othercontrol)) {
7567: %otherdoms = reverse(%othercontrol);
7568: foreach my $domain (keys(%otherdoms)) {
7569: %{$values{$domain}} = ();
7570: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 7571: if (ref($config{'wafproxy'}) eq 'HASH') {
7572: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 7573: if (exists($config{'wafproxy'}{'saml'})) {
7574: $saml{$domain} = $config{'wafproxy'}{'saml'};
7575: }
1.383 raeburn 7576: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7577: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 7578: }
7579: }
7580: }
7581: }
7582: if ($position eq 'top') {
7583: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7584: my %aliasinfo;
1.373 raeburn 7585: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7586: $itemcount ++;
7587: my $dom_in_effect;
7588: my $aliasrows = '<tr>'.
1.383 raeburn 7589: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7590: &mt('Hostname').': '.
7591: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 7592: if ($othercontrol{$server}) {
1.381 raeburn 7593: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 7594: my ($current,$forsaml);
1.383 raeburn 7595: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7596: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 7597: }
1.388 raeburn 7598: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7599: if ($saml{$dom_in_effect}{$server}) {
7600: $forsaml = 1;
7601: }
7602: }
1.383 raeburn 7603: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7604: &mt('Alias').': ';
1.373 raeburn 7605: if ($current) {
1.381 raeburn 7606: $aliasrows .= $current;
1.388 raeburn 7607: if ($forsaml) {
7608: $aliasrows .= ' ('.&mt('also for Shibboleth').')';
7609: }
1.373 raeburn 7610: } else {
1.383 raeburn 7611: $aliasrows .= &mt('None');
1.373 raeburn 7612: }
1.383 raeburn 7613: $aliasrows .= ' <span class="LC_small">('.
7614: &mt('controlled by domain: [_1]',
7615: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 7616: } else {
1.381 raeburn 7617: $dom_in_effect = $dom;
1.388 raeburn 7618: my ($current,$samlon,$samloff);
7619: $samloff = ' checked="checked"';
1.373 raeburn 7620: if (ref($aliases{$dom}) eq 'HASH') {
7621: if ($aliases{$dom}{$server}) {
7622: $current = $aliases{$dom}{$server};
7623: }
7624: }
1.388 raeburn 7625: if (ref($saml{$dom}) eq 'HASH') {
7626: if ($saml{$dom}{$server}) {
7627: $samlon = $samloff;
7628: undef($samloff);
7629: }
7630: }
1.383 raeburn 7631: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7632: &mt('Alias').': '.
1.381 raeburn 7633: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 7634: 'value="'.$current.'" size="30" />'.
7635: (' 'x2).'<span class="LC_nobreak">'.
7636: &mt('Alias used for Shibboleth').': <label>'.
7637: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7638: &mt('No').'</label> <label>'.
7639: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7640: &mt('Yes').'</label></span>'.
7641: '</td>';
1.381 raeburn 7642: }
7643: $aliasrows .= '</tr>';
7644: $aliasinfo{$dom_in_effect} .= $aliasrows;
7645: }
7646: if ($aliasinfo{$dom}) {
7647: my ($onclick,$wafon,$wafoff,$showtable);
7648: $onclick = ' onclick="javascript:toggleWAF();"';
7649: $wafoff = ' checked="checked"';
7650: $showtable = ' style="display:none";';
7651: if ($showdom) {
7652: $wafon = $wafoff;
7653: $wafoff = '';
7654: $showtable = ' style="display:inline;"';
7655: }
7656: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7657: $datatable = '<tr'.$css_class.'>'.
7658: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7659: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7660: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7661: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7662: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7663: &mt('No').'</label></span></td>'.
7664: '<td class="LC_left_item">'.
7665: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7666: '</table></td></tr>';
7667: $itemcount++;
7668: }
1.383 raeburn 7669: if (keys(%otherdoms)) {
7670: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 7671: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 7672: $datatable .= '<tr'.$css_class.'>'.
7673: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7674: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7675: '</table></td></tr>';
1.381 raeburn 7676: $itemcount++;
1.373 raeburn 7677: }
7678: }
7679: } else {
1.383 raeburn 7680: my %ip_methods = &remoteip_methods();
1.373 raeburn 7681: if ($setdom) {
7682: $itemcount ++;
7683: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 7684: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 7685: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 7686: $wafstyle = ' style="display:none;"';
7687: $nowafstyle = ' style="display:table-row;"';
7688: $currwafdisplay = ' style="display: none"';
7689: $wafrangestyle = ' style="display: none"';
7690: $curr_remotip = 'n';
1.382 raeburn 7691: $ssltossl = ' checked="checked"';
1.381 raeburn 7692: if ($showdom) {
7693: $wafstyle = ' style="display:table-row;"';
7694: $nowafstyle = ' style="display:none;"';
7695: if (keys(%{$values{$dom}})) {
7696: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7697: $curr_remotip = $values{$dom}{remoteip};
7698: }
7699: if ($curr_remotip eq 'h') {
7700: $currwafdisplay = ' style="display:table-row"';
7701: $wafrangestyle = ' style="display:inline-block;"';
7702: }
1.382 raeburn 7703: if ($values{$dom}{'sslopt'}) {
7704: $alltossl = ' checked="checked"';
7705: $ssltossl = '';
7706: }
1.381 raeburn 7707: }
7708: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7709: $vpndircheck = ' checked="checked"';
7710: $currwafvpn = ' style="display:table-row;"';
7711: $wafrangestyle = ' style="display:inline-block;"';
7712: } else {
7713: $vpnaliascheck = ' checked="checked"';
7714: $currwafvpn = ' style="display:none;"';
7715: }
7716: }
7717: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7718: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7719: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7720: '</tr>'.
7721: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 7722: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 7723: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7724: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'</div></td>'.
7725: '<td class="LC_left_item"><table>'.
7726: '<tr>'.
7727: '<td valign="top">'.$lt{'remoteip'}.': '.
7728: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7729: foreach my $option ('m','h','n') {
7730: my $sel;
7731: if ($option eq $curr_remotip) {
7732: $sel = ' selected="selected"';
7733: }
7734: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7735: $ip_methods{$option}.'</option>';
7736: }
7737: $datatable .= '</select></td></tr>'."\n".
7738: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7739: $lt{'ipheader'}.': '.
7740: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7741: 'name="wafproxy_ipheader" />'.
7742: '</td></tr>'."\n".
7743: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 7744: $lt{'trusted'}.':<br />'.
1.381 raeburn 7745: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7746: $values{$dom}{'trusted'}.'</textarea>'.
7747: '</td></tr>'."\n".
7748: '<tr><td><hr /></td></tr>'."\n".
7749: '<tr>'.
7750: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7751: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7752: $lt{'vpndirect'}.'</label>'.(' 'x2).
7753: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7754: $lt{'vpnaliased'}.'</label></span></td></tr>';
7755: foreach my $item ('vpnint','vpnext') {
7756: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 7757: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 7758: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7759: $values{$dom}{$item}.'</textarea>'.
7760: '</td></tr>'."\n";
1.373 raeburn 7761: }
1.382 raeburn 7762: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7763: '<tr>'.
7764: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7765: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7766: $lt{'alltossl'}.'</label>'.(' 'x2).
7767: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7768: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7769: '</table></td></tr>';
1.373 raeburn 7770: }
7771: if (keys(%otherdoms)) {
7772: foreach my $domain (sort(keys(%otherdoms))) {
7773: $itemcount ++;
7774: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7775: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 7776: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 7777: '<td class="LC_left_item"><table>';
1.382 raeburn 7778: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 7779: my $showval = &mt('None');
1.382 raeburn 7780: if ($item eq 'ssl') {
7781: $showval = $lt{'ssltossl'};
7782: }
1.373 raeburn 7783: if ($values{$domain}{$item}) {
1.381 raeburn 7784: $showval = $values{$domain}{$item};
1.382 raeburn 7785: if ($item eq 'ssl') {
7786: $showval = $lt{'alltossl'};
1.383 raeburn 7787: } elsif ($item eq 'remoteip') {
7788: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 7789: }
1.373 raeburn 7790: }
7791: $datatable .= '<tr>'.
7792: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7793: }
1.381 raeburn 7794: $datatable .= '</table></td></tr>';
1.373 raeburn 7795: }
7796: }
7797: }
7798: $$rowtotal += $itemcount;
7799: return $datatable;
7800: }
7801:
7802: sub wafproxy_titles {
7803: return &Apache::lonlocal::texthash(
1.381 raeburn 7804: remoteip => "Method for determining user's IP",
7805: ipheader => 'Request header containing remote IP',
7806: trusted => 'Trusted IP range(s)',
7807: vpnaccess => 'Access from institutional VPN',
7808: vpndirect => 'via regular hostname (no WAF)',
7809: vpnaliased => 'via aliased hostname (WAF)',
7810: vpnint => 'Internal IP Range(s) for VPN sessions',
7811: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 7812: sslopt => 'Forwarding http/https',
1.381 raeburn 7813: alltossl => 'WAF forwards both http and https requests to https',
7814: ssltossl => 'WAF forwards http requests to http and https to https',
7815: );
7816: }
7817:
7818: sub remoteip_methods {
7819: return &Apache::lonlocal::texthash(
7820: m => 'Use Apache mod_remoteip',
7821: h => 'Use headers parsed by LON-CAPA',
7822: n => 'Not in use',
1.373 raeburn 7823: );
7824: }
7825:
1.137 raeburn 7826: sub print_usersessions {
7827: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7828: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7829: my (%by_ip,%by_location,@intdoms,@instdoms);
7830: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7831:
7832: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7833: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7834: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7835: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7836: if ($position eq 'top') {
1.152 raeburn 7837: if (keys(%serverhomes) > 1) {
1.145 raeburn 7838: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7839: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7840: if (ref($settings) eq 'HASH') {
7841: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7842: $curroffloadnow = $settings->{'offloadnow'};
7843: }
1.371 raeburn 7844: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7845: $curroffloadoth = $settings->{'offloadoth'};
7846: }
1.261 raeburn 7847: }
1.371 raeburn 7848: my $other_insts = scalar(keys(%by_location));
7849: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7850: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7851: } else {
1.140 raeburn 7852: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7853: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7854: '</td></tr>';
1.140 raeburn 7855: }
1.137 raeburn 7856: } else {
1.279 raeburn 7857: my %titles = &usersession_titles();
7858: my ($prefix,@types);
7859: if ($position eq 'bottom') {
7860: $prefix = 'remote';
7861: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7862: } else {
1.279 raeburn 7863: $prefix = 'hosted';
7864: @types = ('excludedomain','includedomain');
7865: }
7866: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7867: }
7868: $$rowtotal += $itemcount;
7869: return $datatable;
7870: }
7871:
7872: sub rules_by_location {
7873: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7874: my ($datatable,$itemcount,$css_class);
7875: if (keys(%{$by_location}) == 0) {
7876: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7877: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7878: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7879: '</td></tr>';
7880: $itemcount = 1;
7881: } else {
7882: $itemcount = 0;
7883: my $numinrow = 5;
7884: my (%current,%checkedon,%checkedoff);
7885: my @locations = sort(keys(%{$by_location}));
7886: foreach my $type (@{$types}) {
7887: $checkedon{$type} = '';
7888: $checkedoff{$type} = ' checked="checked"';
7889: }
7890: if (ref($settings) eq 'HASH') {
7891: if (ref($settings->{$prefix}) eq 'HASH') {
7892: foreach my $key (keys(%{$settings->{$prefix}})) {
7893: $current{$key} = $settings->{$prefix}{$key};
7894: if ($key eq 'version') {
7895: if ($current{$key} ne '') {
1.145 raeburn 7896: $checkedon{$key} = ' checked="checked"';
7897: $checkedoff{$key} = '';
7898: }
1.279 raeburn 7899: } elsif (ref($current{$key}) eq 'ARRAY') {
7900: $checkedon{$key} = ' checked="checked"';
7901: $checkedoff{$key} = '';
1.137 raeburn 7902: }
7903: }
7904: }
1.279 raeburn 7905: }
7906: foreach my $type (@{$types}) {
7907: next if ($type ne 'version' && !@locations);
7908: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7909: $datatable .= '<tr'.$css_class.'>
7910: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7911: <span class="LC_nobreak">
7912: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7913: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7914: if ($type eq 'version') {
7915: my @lcversions = &Apache::lonnet::all_loncaparevs();
7916: my $selector = '<select name="'.$prefix.'_version">';
7917: foreach my $version (@lcversions) {
7918: my $selected = '';
7919: if ($current{'version'} eq $version) {
7920: $selected = ' selected="selected"';
1.145 raeburn 7921: }
1.279 raeburn 7922: $selector .= ' <option value="'.$version.'"'.
7923: $selected.'>'.$version.'</option>';
7924: }
7925: $selector .= '</select> ';
7926: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7927: } else {
7928: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7929: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7930: ' />'.(' 'x2).
7931: '<input type="button" value="'.&mt('uncheck all').'" '.
7932: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7933: "\n".
7934: '</div><div><table>';
7935: my $rem;
7936: for (my $i=0; $i<@locations; $i++) {
7937: my ($showloc,$value,$checkedtype);
7938: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7939: my $ip = $by_location->{$locations[$i]}->[0];
7940: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7941: $value = join(':',@{$by_ip->{$ip}});
7942: $showloc = join(', ',@{$by_ip->{$ip}});
7943: if (ref($current{$type}) eq 'ARRAY') {
7944: foreach my $loc (@{$by_ip->{$ip}}) {
7945: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7946: $checkedtype = ' checked="checked"';
7947: last;
1.145 raeburn 7948: }
1.138 raeburn 7949: }
7950: }
7951: }
1.137 raeburn 7952: }
1.279 raeburn 7953: $rem = $i%($numinrow);
7954: if ($rem == 0) {
7955: if ($i > 0) {
7956: $datatable .= '</tr>';
7957: }
7958: $datatable .= '<tr>';
7959: }
7960: $datatable .= '<td class="LC_left_item">'.
7961: '<span class="LC_nobreak"><label>'.
7962: '<input type="checkbox" name="'.$prefix.'_'.$type.
7963: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7964: '</label></span></td>';
7965: }
7966: $rem = @locations%($numinrow);
7967: my $colsleft = $numinrow - $rem;
7968: if ($colsleft > 1 ) {
7969: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7970: ' </td>';
7971: } elsif ($colsleft == 1) {
7972: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7973: }
1.279 raeburn 7974: $datatable .= '</tr></table>';
1.137 raeburn 7975: }
1.279 raeburn 7976: $datatable .= '</td></tr>';
7977: $itemcount ++;
1.137 raeburn 7978: }
7979: }
1.279 raeburn 7980: return ($datatable,$itemcount);
1.137 raeburn 7981: }
7982:
1.275 raeburn 7983: sub print_ssl {
7984: my ($position,$dom,$settings,$rowtotal) = @_;
7985: my ($css_class,$datatable);
7986: my $itemcount = 1;
7987: if ($position eq 'top') {
1.281 raeburn 7988: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7989: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7990: my $same_institution;
7991: if ($intdom ne '') {
7992: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
7993: if (ref($internet_names) eq 'ARRAY') {
7994: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
7995: $same_institution = 1;
7996: }
7997: }
7998: }
1.275 raeburn 7999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8000: $datatable = '<tr'.$css_class.'><td colspan="2">';
8001: if ($same_institution) {
8002: my %domservers = &Apache::lonnet::get_servers($dom);
8003: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8004: } else {
8005: $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.");
8006: }
8007: $datatable .= '</td></tr>';
1.275 raeburn 8008: $itemcount ++;
8009: } else {
8010: my %titles = &ssl_titles();
8011: my (%by_ip,%by_location,@intdoms,@instdoms);
8012: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8013: my @alldoms = &Apache::lonnet::all_domains();
8014: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8015: my @domservers = &Apache::lonnet::get_servers($dom);
8016: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8017: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8018: if (($position eq 'connto') || ($position eq 'connfrom')) {
8019: my $legacy;
8020: unless (ref($settings) eq 'HASH') {
8021: my $name;
8022: if ($position eq 'connto') {
8023: $name = 'loncAllowInsecure';
8024: } else {
8025: $name = 'londAllowInsecure';
8026: }
8027: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8028: my @ids=&Apache::lonnet::current_machine_ids();
8029: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8030: my %what = (
8031: $name => 1,
8032: );
8033: my ($result,$returnhash) =
8034: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8035: if ($result eq 'ok') {
8036: if (ref($returnhash) eq 'HASH') {
8037: $legacy = $returnhash->{$name};
8038: }
8039: }
8040: } else {
8041: $legacy = $Apache::lonnet::perlvar{$name};
8042: }
8043: }
1.275 raeburn 8044: foreach my $type ('dom','intdom','other') {
8045: my %checked;
8046: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8047: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8048: '<td class="LC_right_item">';
8049: my $skip;
8050: if ($type eq 'dom') {
8051: unless (keys(%servers) > 1) {
8052: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8053: $skip = 1;
8054: }
8055: }
8056: if ($type eq 'intdom') {
8057: unless (@instdoms > 1) {
8058: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8059: $skip = 1;
8060: }
8061: } elsif ($type eq 'other') {
8062: if (keys(%by_location) == 0) {
8063: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8064: $skip = 1;
8065: }
8066: }
8067: unless ($skip) {
8068: $checked{'yes'} = ' checked="checked"';
8069: if (ref($settings) eq 'HASH') {
1.293 raeburn 8070: if (ref($settings->{$position}) eq 'HASH') {
8071: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8072: $checked{$1} = $checked{'yes'};
8073: delete($checked{'yes'});
8074: }
8075: }
1.293 raeburn 8076: } else {
8077: if ($legacy == 0) {
8078: $checked{'req'} = $checked{'yes'};
8079: delete($checked{'yes'});
8080: }
1.275 raeburn 8081: }
8082: foreach my $option ('no','yes','req') {
8083: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8084: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8085: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8086: '</label></span>'.(' 'x2);
8087: }
8088: }
8089: $datatable .= '</td></tr>';
8090: $itemcount ++;
8091: }
8092: } else {
8093: my $prefix = 'replication';
8094: my @types = ('certreq','nocertreq');
1.279 raeburn 8095: if (keys(%by_location) == 0) {
8096: $datatable .= '<tr'.$css_class.'><td>'.
8097: &mt('Nothing to set here, as there are no other institutions').
8098: '</td></tr>';
8099: $itemcount ++;
1.275 raeburn 8100: } else {
1.279 raeburn 8101: ($datatable,$itemcount) =
8102: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8103: }
8104: }
8105: }
8106: $$rowtotal += $itemcount;
8107: return $datatable;
8108: }
8109:
8110: sub ssl_titles {
8111: return &Apache::lonlocal::texthash (
8112: dom => 'LON-CAPA servers/VMs from same domain',
8113: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8114: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8115: connto => 'Connections to other servers',
8116: connfrom => 'Connections from other servers',
1.275 raeburn 8117: replication => 'Replicating content to other institutions',
8118: certreq => 'Client certificate required, but specific domains exempt',
8119: nocertreq => 'No client certificate required, except for specific domains',
8120: no => 'SSL not used',
8121: yes => 'SSL Optional (used if available)',
8122: req => 'SSL Required',
8123: );
1.279 raeburn 8124: }
8125:
8126: sub print_trust {
8127: my ($prefix,$dom,$settings,$rowtotal) = @_;
8128: my ($css_class,$datatable,%checked,%choices);
8129: my (%by_ip,%by_location,@intdoms,@instdoms);
8130: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8131: my $itemcount = 1;
8132: my %titles = &trust_titles();
8133: my @types = ('exc','inc');
8134: if ($prefix eq 'top') {
8135: $prefix = 'content';
8136: } elsif ($prefix eq 'bottom') {
8137: $prefix = 'msg';
8138: }
8139: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8140: $$rowtotal += $itemcount;
8141: return $datatable;
8142: }
8143:
8144: sub trust_titles {
8145: return &Apache::lonlocal::texthash(
8146: content => "Access to this domain's content by others",
8147: shared => "Access to other domain's content by this domain",
8148: enroll => "Enrollment in this domain's courses by others",
8149: othcoau => "Co-author roles in this domain for others",
8150: coaurem => "Co-author roles for this domain's users elsewhere",
8151: domroles => "Domain roles in this domain assignable to others",
8152: catalog => "Course Catalog for this domain displayed elsewhere",
8153: reqcrs => "Requests for creation of courses in this domain by others",
8154: msg => "Users in other domains can send messages to this domain",
8155: exc => "Allow all, but exclude specific domains",
8156: inc => "Deny all, but include specific domains",
8157: );
1.275 raeburn 8158: }
8159:
1.138 raeburn 8160: sub build_location_hashes {
1.275 raeburn 8161: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8162: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8163: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8164: my %iphost = &Apache::lonnet::get_iphost();
8165: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8166: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8167: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8168: foreach my $id (@{$iphost{$primary_ip}}) {
8169: my $intdom = &Apache::lonnet::internet_dom($id);
8170: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8171: push(@{$intdoms},$intdom);
8172: }
8173: }
8174: }
8175: foreach my $ip (keys(%iphost)) {
8176: if (ref($iphost{$ip}) eq 'ARRAY') {
8177: foreach my $id (@{$iphost{$ip}}) {
8178: my $location = &Apache::lonnet::internet_dom($id);
8179: if ($location) {
1.275 raeburn 8180: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8181: my $dom = &Apache::lonnet::host_domain($id);
8182: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8183: push(@{$instdoms},$dom);
8184: }
8185: next;
8186: }
1.138 raeburn 8187: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8188: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8189: push(@{$by_ip->{$ip}},$location);
8190: }
8191: } else {
8192: $by_ip->{$ip} = [$location];
8193: }
8194: }
8195: }
8196: }
8197: }
8198: foreach my $ip (sort(keys(%{$by_ip}))) {
8199: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8200: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8201: my $first = $by_ip->{$ip}->[0];
8202: if (ref($by_location->{$first}) eq 'ARRAY') {
8203: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8204: push(@{$by_location->{$first}},$ip);
8205: }
8206: } else {
8207: $by_location->{$first} = [$ip];
8208: }
8209: }
8210: }
8211: return;
8212: }
8213:
1.145 raeburn 8214: sub current_offloads_to {
8215: my ($dom,$settings,$servers) = @_;
8216: my (%spareid,%otherdomconfigs);
1.152 raeburn 8217: if (ref($servers) eq 'HASH') {
1.145 raeburn 8218: foreach my $lonhost (sort(keys(%{$servers}))) {
8219: my $gotspares;
1.152 raeburn 8220: if (ref($settings) eq 'HASH') {
8221: if (ref($settings->{'spares'}) eq 'HASH') {
8222: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8223: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8224: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8225: $gotspares = 1;
8226: }
1.145 raeburn 8227: }
8228: }
8229: unless ($gotspares) {
8230: my $gotspares;
8231: my $serverhomeID =
8232: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8233: my $serverhomedom =
8234: &Apache::lonnet::host_domain($serverhomeID);
8235: if ($serverhomedom ne $dom) {
8236: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8237: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8238: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8239: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8240: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8241: $gotspares = 1;
8242: }
8243: }
8244: } else {
8245: $otherdomconfigs{$serverhomedom} =
8246: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8247: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8248: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8249: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8250: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8251: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8252: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8253: $gotspares = 1;
8254: }
8255: }
8256: }
8257: }
8258: }
8259: }
8260: }
8261: unless ($gotspares) {
8262: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8263: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8264: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8265: } else {
8266: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8267: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8268: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8269: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8270: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8271: } else {
1.150 raeburn 8272: my %what = (
8273: spareid => 1,
8274: );
8275: my ($result,$returnhash) =
8276: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8277: if ($result eq 'ok') {
8278: if (ref($returnhash) eq 'HASH') {
8279: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8280: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8281: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8282: }
8283: }
1.145 raeburn 8284: }
8285: }
8286: }
8287: }
8288: }
8289: }
8290: return %spareid;
8291: }
8292:
8293: sub spares_row {
1.371 raeburn 8294: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8295: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8296: my $css_class;
8297: my $numinrow = 4;
8298: my $itemcount = 1;
8299: my $datatable;
1.152 raeburn 8300: my %typetitles = &sparestype_titles();
8301: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8302: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8303: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8304: my ($othercontrol,$serverdom);
8305: if ($serverhome ne $server) {
8306: $serverdom = &Apache::lonnet::host_domain($serverhome);
8307: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8308: } else {
8309: $serverdom = &Apache::lonnet::host_domain($server);
8310: if ($serverdom ne $dom) {
8311: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8312: }
8313: }
8314: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8315: my ($checkednow,$checkedoth);
1.261 raeburn 8316: if (ref($curroffloadnow) eq 'HASH') {
8317: if ($curroffloadnow->{$server}) {
8318: $checkednow = ' checked="checked"';
8319: }
8320: }
1.371 raeburn 8321: if (ref($curroffloadoth) eq 'HASH') {
8322: if ($curroffloadoth->{$server}) {
8323: $checkedoth = ' checked="checked"';
8324: }
8325: }
1.145 raeburn 8326: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8327: $datatable .= '<tr'.$css_class.'>
8328: <td rowspan="2">
1.183 bisitz 8329: <span class="LC_nobreak">'.
8330: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8331: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8332: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8333: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8334: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8335: "\n";
1.371 raeburn 8336: if ($other_insts) {
8337: $datatable .= '<br />'.
8338: '<span class="LC_nobreak">'."\n".
8339: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8340: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8341: "\n";
8342: }
1.145 raeburn 8343: my (%current,%canselect);
1.152 raeburn 8344: my @choices =
8345: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8346: foreach my $type ('primary','default') {
8347: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8348: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8349: my @spares = @{$spareid->{$server}{$type}};
8350: if (@spares > 0) {
1.152 raeburn 8351: if ($othercontrol) {
8352: $current{$type} = join(', ',@spares);
8353: } else {
8354: $current{$type} .= '<table>';
8355: my $numspares = scalar(@spares);
8356: for (my $i=0; $i<@spares; $i++) {
8357: my $rem = $i%($numinrow);
8358: if ($rem == 0) {
8359: if ($i > 0) {
8360: $current{$type} .= '</tr>';
8361: }
8362: $current{$type} .= '<tr>';
1.145 raeburn 8363: }
1.152 raeburn 8364: $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'".');" /> '.
8365: $spareid->{$server}{$type}[$i].
8366: '</label></td>'."\n";
8367: }
8368: my $rem = @spares%($numinrow);
8369: my $colsleft = $numinrow - $rem;
8370: if ($colsleft > 1 ) {
8371: $current{$type} .= '<td colspan="'.$colsleft.
8372: '" class="LC_left_item">'.
8373: ' </td>';
8374: } elsif ($colsleft == 1) {
8375: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8376: }
1.152 raeburn 8377: $current{$type} .= '</tr></table>';
1.150 raeburn 8378: }
1.145 raeburn 8379: }
8380: }
8381: if ($current{$type} eq '') {
8382: $current{$type} = &mt('None specified');
8383: }
1.152 raeburn 8384: if ($othercontrol) {
8385: if ($type eq 'primary') {
8386: $canselect{$type} = $othercontrol;
8387: }
8388: } else {
8389: $canselect{$type} =
8390: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8391: '<select name="newspare_'.$type.'_'.$server.'" '.
8392: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8393: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8394: if (@choices > 0) {
8395: foreach my $lonhost (@choices) {
8396: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8397: }
8398: }
8399: $canselect{$type} .= '</select>'."\n";
8400: }
8401: } else {
8402: $current{$type} = &mt('Could not be determined');
8403: if ($type eq 'primary') {
8404: $canselect{$type} = $othercontrol;
8405: }
1.145 raeburn 8406: }
1.152 raeburn 8407: if ($type eq 'default') {
8408: $datatable .= '<tr'.$css_class.'>';
8409: }
8410: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8411: '<td>'.$current{$type}.'</td>'."\n".
8412: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8413: }
8414: $itemcount ++;
8415: }
8416: }
8417: $$rowtotal += $itemcount;
8418: return $datatable;
8419: }
8420:
1.152 raeburn 8421: sub possible_newspares {
8422: my ($server,$currspares,$serverhomes,$altids) = @_;
8423: my $serverhostname = &Apache::lonnet::hostname($server);
8424: my %excluded;
8425: if ($serverhostname ne '') {
8426: %excluded = (
8427: $serverhostname => 1,
8428: );
8429: }
8430: if (ref($currspares) eq 'HASH') {
8431: foreach my $type (keys(%{$currspares})) {
8432: if (ref($currspares->{$type}) eq 'ARRAY') {
8433: if (@{$currspares->{$type}} > 0) {
8434: foreach my $curr (@{$currspares->{$type}}) {
8435: my $hostname = &Apache::lonnet::hostname($curr);
8436: $excluded{$hostname} = 1;
8437: }
8438: }
8439: }
8440: }
8441: }
8442: my @choices;
8443: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8444: if (keys(%{$serverhomes}) > 1) {
8445: foreach my $name (sort(keys(%{$serverhomes}))) {
8446: unless ($excluded{$name}) {
8447: if (exists($altids->{$serverhomes->{$name}})) {
8448: push(@choices,$altids->{$serverhomes->{$name}});
8449: } else {
8450: push(@choices,$serverhomes->{$name});
1.145 raeburn 8451: }
8452: }
8453: }
8454: }
8455: }
1.152 raeburn 8456: return sort(@choices);
1.145 raeburn 8457: }
8458:
1.150 raeburn 8459: sub print_loadbalancing {
8460: my ($dom,$settings,$rowtotal) = @_;
8461: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8462: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8463: my $numinrow = 1;
8464: my $datatable;
8465: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8466: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8467: if (ref($settings) eq 'HASH') {
8468: %existing = %{$settings};
8469: }
8470: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8471: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8472: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8473: } else {
8474: return;
8475: }
8476: my ($othertitle,$usertypes,$types) =
8477: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8478: my $rownum = 8;
1.150 raeburn 8479: if (ref($types) eq 'ARRAY') {
8480: $rownum += scalar(@{$types});
8481: }
1.171 raeburn 8482: my @css_class = ('LC_odd_row','LC_even_row');
8483: my $balnum = 0;
8484: my $islast;
8485: my (@toshow,$disabledtext);
8486: if (keys(%currbalancer) > 0) {
8487: @toshow = sort(keys(%currbalancer));
8488: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8489: push(@toshow,'');
8490: }
8491: } else {
8492: @toshow = ('');
8493: $disabledtext = &mt('No existing load balancer');
8494: }
8495: foreach my $lonhost (@toshow) {
8496: if ($balnum == scalar(@toshow)-1) {
8497: $islast = 1;
8498: } else {
8499: $islast = 0;
8500: }
8501: my $cssidx = $balnum%2;
8502: my $targets_div_style = 'display: none';
8503: my $disabled_div_style = 'display: block';
8504: my $homedom_div_style = 'display: none';
8505: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8506: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8507: '<p>';
8508: if ($lonhost eq '') {
1.210 raeburn 8509: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8510: if (keys(%currbalancer) > 0) {
8511: $datatable .= &mt('Add balancer:');
8512: } else {
8513: $datatable .= &mt('Enable balancer:');
8514: }
8515: $datatable .= ' '.
8516: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8517: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8518: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8519: '<option value="" selected="selected">'.&mt('None').
8520: '</option>'."\n";
8521: foreach my $server (sort(keys(%servers))) {
8522: next if ($currbalancer{$server});
8523: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8524: }
1.210 raeburn 8525: $datatable .=
1.171 raeburn 8526: '</select>'."\n".
8527: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8528: } else {
8529: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8530: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8531: &mt('Stop balancing').'</label>'.
8532: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8533: $targets_div_style = 'display: block';
8534: $disabled_div_style = 'display: none';
8535: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8536: $homedom_div_style = 'display: block';
8537: }
8538: }
1.306 raeburn 8539: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8540: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8541: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8542: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8543: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8544: my @sparestypes = ('primary','default');
8545: my %typetitles = &sparestype_titles();
1.284 raeburn 8546: my %hostherechecked = (
8547: no => ' checked="checked"',
8548: );
1.342 raeburn 8549: my %balcookiechecked = (
8550: no => ' checked="checked"',
8551: );
1.171 raeburn 8552: foreach my $sparetype (@sparestypes) {
8553: my $targettable;
8554: for (my $i=0; $i<$numspares; $i++) {
8555: my $checked;
8556: if (ref($currtargets{$lonhost}) eq 'HASH') {
8557: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8558: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8559: $checked = ' checked="checked"';
8560: }
8561: }
8562: }
8563: my ($chkboxval,$disabled);
8564: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8565: $chkboxval = $spares[$i];
8566: }
8567: if (exists($currbalancer{$spares[$i]})) {
8568: $disabled = ' disabled="disabled"';
8569: }
1.210 raeburn 8570: $targettable .=
1.253 raeburn 8571: '<td><span class="LC_nobreak"><label>'.
8572: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8573: $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 8574: '</span></label></span></td>';
1.171 raeburn 8575: my $rem = $i%($numinrow);
8576: if ($rem == 0) {
8577: if (($i > 0) && ($i < $numspares-1)) {
8578: $targettable .= '</tr>';
8579: }
8580: if ($i < $numspares-1) {
8581: $targettable .= '<tr>';
1.150 raeburn 8582: }
8583: }
8584: }
1.171 raeburn 8585: if ($targettable ne '') {
8586: my $rem = $numspares%($numinrow);
8587: my $colsleft = $numinrow - $rem;
8588: if ($colsleft > 1 ) {
8589: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8590: ' </td>';
8591: } elsif ($colsleft == 1) {
8592: $targettable .= '<td class="LC_left_item"> </td>';
8593: }
8594: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8595: '<table><tr>'.$targettable.'</tr></table><br />';
8596: }
1.284 raeburn 8597: $hostherechecked{$sparetype} = '';
8598: if (ref($currtargets{$lonhost}) eq 'HASH') {
8599: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8600: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8601: $hostherechecked{$sparetype} = ' checked="checked"';
8602: $hostherechecked{'no'} = '';
8603: }
8604: }
8605: }
8606: }
1.342 raeburn 8607: if ($currcookies{$lonhost}) {
8608: %balcookiechecked = (
8609: yes => ' checked="checked"',
8610: );
8611: }
1.284 raeburn 8612: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8613: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8614: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8615: foreach my $sparetype (@sparestypes) {
8616: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8617: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8618: '</i></label><br />';
1.171 raeburn 8619: }
1.342 raeburn 8620: $datatable .= &mt('Use balancer cookie').'<br />'.
8621: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8622: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8623: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8624: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8625: '</div></td></tr>'.
1.171 raeburn 8626: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8627: $othertitle,$usertypes,$types,\%servers,
8628: \%currbalancer,$lonhost,
8629: $targets_div_style,$homedom_div_style,
8630: $css_class[$cssidx],$balnum,$islast);
8631: $$rowtotal += $rownum;
8632: $balnum ++;
8633: }
8634: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8635: return $datatable;
8636: }
8637:
8638: sub get_loadbalancers_config {
1.342 raeburn 8639: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8640: return unless ((ref($servers) eq 'HASH') &&
8641: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8642: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8643: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8644: if (keys(%{$existing}) > 0) {
8645: my $oldlonhost;
8646: foreach my $key (sort(keys(%{$existing}))) {
8647: if ($key eq 'lonhost') {
8648: $oldlonhost = $existing->{'lonhost'};
8649: $currbalancer->{$oldlonhost} = 1;
8650: } elsif ($key eq 'targets') {
8651: if ($oldlonhost) {
8652: $currtargets->{$oldlonhost} = $existing->{'targets'};
8653: }
8654: } elsif ($key eq 'rules') {
8655: if ($oldlonhost) {
8656: $currrules->{$oldlonhost} = $existing->{'rules'};
8657: }
8658: } elsif (ref($existing->{$key}) eq 'HASH') {
8659: $currbalancer->{$key} = 1;
8660: $currtargets->{$key} = $existing->{$key}{'targets'};
8661: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8662: if ($existing->{$key}{'cookie'}) {
8663: $currcookies->{$key} = 1;
8664: }
1.150 raeburn 8665: }
8666: }
1.171 raeburn 8667: } else {
8668: my ($balancerref,$targetsref) =
8669: &Apache::lonnet::get_lonbalancer_config($servers);
8670: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8671: foreach my $server (sort(keys(%{$balancerref}))) {
8672: $currbalancer->{$server} = 1;
8673: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8674: }
8675: }
8676: }
1.171 raeburn 8677: return;
1.150 raeburn 8678: }
8679:
8680: sub loadbalancing_rules {
8681: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8682: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8683: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8684: my $output;
1.171 raeburn 8685: my $num = 0;
1.210 raeburn 8686: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8687: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8688: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8689: foreach my $type (@{$alltypes}) {
1.171 raeburn 8690: $num ++;
1.150 raeburn 8691: my $current;
8692: if (ref($currrules) eq 'HASH') {
8693: $current = $currrules->{$type};
8694: }
1.253 raeburn 8695: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8696: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8697: $current = '';
8698: }
8699: }
8700: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8701: $servers,$currbalancer,$lonhost,$dom,
8702: $targets_div_style,$homedom_div_style,
8703: $css_class,$balnum,$num,$islast);
1.150 raeburn 8704: }
8705: }
8706: return $output;
8707: }
8708:
8709: sub loadbalancing_titles {
8710: my ($dom,$intdom,$usertypes,$types) = @_;
8711: my %othertypes = (
8712: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8713: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8714: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8715: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8716: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8717: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8718: );
1.209 raeburn 8719: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8720: my @available;
1.150 raeburn 8721: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8722: @available = @{$types};
1.150 raeburn 8723: }
1.302 raeburn 8724: unless (grep(/^default$/,@available)) {
8725: push(@available,'default');
8726: }
8727: unshift(@alltypes,@available);
1.150 raeburn 8728: my %titles;
8729: foreach my $type (@alltypes) {
8730: if ($type =~ /^_LC_/) {
8731: $titles{$type} = $othertypes{$type};
8732: } elsif ($type eq 'default') {
8733: $titles{$type} = &mt('All users from [_1]',$dom);
8734: if (ref($types) eq 'ARRAY') {
8735: if (@{$types} > 0) {
8736: $titles{$type} = &mt('Other users from [_1]',$dom);
8737: }
8738: }
8739: } elsif (ref($usertypes) eq 'HASH') {
8740: $titles{$type} = $usertypes->{$type};
8741: }
8742: }
8743: return (\@alltypes,\%othertypes,\%titles);
8744: }
8745:
8746: sub loadbalance_rule_row {
1.171 raeburn 8747: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8748: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8749: my @rulenames;
1.150 raeburn 8750: my %ruletitles = &offloadtype_text();
1.209 raeburn 8751: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8752: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8753: } else {
1.209 raeburn 8754: @rulenames = ('default','homeserver');
8755: if ($type eq '_LC_external') {
8756: push(@rulenames,'externalbalancer');
8757: } else {
8758: push(@rulenames,'specific');
8759: }
8760: push(@rulenames,'none');
1.150 raeburn 8761: }
8762: my $style = $targets_div_style;
1.253 raeburn 8763: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8764: $style = $homedom_div_style;
8765: }
1.171 raeburn 8766: my $space;
8767: if ($islast && $num == 1) {
1.317 raeburn 8768: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8769: }
1.210 raeburn 8770: my $output =
1.306 raeburn 8771: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8772: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8773: '<td valaign="top">'.$space.
8774: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8775: for (my $i=0; $i<@rulenames; $i++) {
8776: my $rule = $rulenames[$i];
8777: my ($checked,$extra);
8778: if ($rulenames[$i] eq 'default') {
8779: $rule = '';
8780: }
8781: if ($rulenames[$i] eq 'specific') {
8782: if (ref($servers) eq 'HASH') {
8783: my $default;
8784: if (($current ne '') && (exists($servers->{$current}))) {
8785: $checked = ' checked="checked"';
8786: }
8787: unless ($checked) {
8788: $default = ' selected="selected"';
8789: }
1.210 raeburn 8790: $extra =
1.171 raeburn 8791: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8792: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8793: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8794: '<option value=""'.$default.'></option>'."\n";
8795: foreach my $server (sort(keys(%{$servers}))) {
8796: if (ref($currbalancer) eq 'HASH') {
8797: next if (exists($currbalancer->{$server}));
8798: }
1.150 raeburn 8799: my $selected;
1.171 raeburn 8800: if ($server eq $current) {
1.150 raeburn 8801: $selected = ' selected="selected"';
8802: }
1.171 raeburn 8803: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8804: }
8805: $extra .= '</select>';
8806: }
8807: } elsif ($rule eq $current) {
8808: $checked = ' checked="checked"';
8809: }
8810: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8811: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8812: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8813: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8814: ')"'.$checked.' /> ';
8815: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8816: $output .= $ruletitles{'particular'};
8817: } else {
8818: $output .= $ruletitles{$rulenames[$i]};
8819: }
8820: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8821: }
8822: $output .= '</div></td></tr>'."\n";
8823: return $output;
8824: }
8825:
8826: sub offloadtype_text {
8827: my %ruletitles = &Apache::lonlocal::texthash (
8828: 'default' => 'Offloads to default destinations',
8829: 'homeserver' => "Offloads to user's home server",
8830: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8831: 'specific' => 'Offloads to specific server',
1.161 raeburn 8832: 'none' => 'No offload',
1.209 raeburn 8833: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8834: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8835: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8836: );
8837: return %ruletitles;
8838: }
8839:
8840: sub sparestype_titles {
8841: my %typestitles = &Apache::lonlocal::texthash (
8842: 'primary' => 'primary',
8843: 'default' => 'default',
8844: );
8845: return %typestitles;
8846: }
8847:
1.28 raeburn 8848: sub contact_titles {
8849: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8850: 'supportemail' => 'Support E-mail address',
8851: 'adminemail' => 'Default Server Admin E-mail address',
8852: 'errormail' => 'Error reports to be e-mailed to',
8853: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8854: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8855: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8856: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8857: 'requestsmail' => 'E-mail from course requests requiring approval',
8858: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8859: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8860: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 8861: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8862: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 8863: 'errorweights' => 'Weights used to compute error count',
8864: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8865: );
8866: my %short_titles = &Apache::lonlocal::texthash (
8867: adminemail => 'Admin E-mail address',
8868: supportemail => 'Support E-mail',
8869: );
8870: return (\%titles,\%short_titles);
8871: }
8872:
1.286 raeburn 8873: sub helpform_fields {
8874: my %titles = &Apache::lonlocal::texthash (
8875: 'username' => 'Name',
8876: 'user' => 'Username/domain',
8877: 'phone' => 'Phone',
8878: 'cc' => 'Cc e-mail',
8879: 'course' => 'Course Details',
8880: 'section' => 'Sections',
1.289 raeburn 8881: 'screenshot' => 'File upload',
1.286 raeburn 8882: );
8883: my @fields = ('username','phone','user','course','section','cc','screenshot');
8884: my %possoptions = (
8885: username => ['yes','no','req'],
1.289 raeburn 8886: phone => ['yes','no','req'],
1.286 raeburn 8887: user => ['yes','no'],
1.289 raeburn 8888: cc => ['yes','no'],
1.286 raeburn 8889: course => ['yes','no'],
8890: section => ['yes','no'],
8891: screenshot => ['yes','no'],
8892: );
8893: my %fieldoptions = &Apache::lonlocal::texthash (
8894: 'yes' => 'Optional',
8895: 'req' => 'Required',
8896: 'no' => "Not shown",
8897: );
8898: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8899: }
8900:
1.72 raeburn 8901: sub tool_titles {
8902: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8903: aboutme => 'Personal web page',
1.86 raeburn 8904: blog => 'Blog',
1.162 raeburn 8905: webdav => 'WebDAV',
1.86 raeburn 8906: portfolio => 'Portfolio',
1.88 bisitz 8907: official => 'Official courses (with institutional codes)',
8908: unofficial => 'Unofficial courses',
1.98 raeburn 8909: community => 'Communities',
1.216 raeburn 8910: textbook => 'Textbook courses',
1.271 raeburn 8911: placement => 'Placement tests',
1.86 raeburn 8912: );
1.72 raeburn 8913: return %titles;
8914: }
8915:
1.101 raeburn 8916: sub courserequest_titles {
8917: my %titles = &Apache::lonlocal::texthash (
8918: official => 'Official',
8919: unofficial => 'Unofficial',
8920: community => 'Communities',
1.216 raeburn 8921: textbook => 'Textbook',
1.271 raeburn 8922: placement => 'Placement tests',
1.325 raeburn 8923: lti => 'LTI Provider',
1.101 raeburn 8924: norequest => 'Not allowed',
1.325 raeburn 8925: approval => 'Approval by DC',
1.101 raeburn 8926: validate => 'With validation',
8927: autolimit => 'Numerical limit',
1.103 raeburn 8928: unlimited => '(blank for unlimited)',
1.101 raeburn 8929: );
8930: return %titles;
8931: }
8932:
1.163 raeburn 8933: sub authorrequest_titles {
8934: my %titles = &Apache::lonlocal::texthash (
8935: norequest => 'Not allowed',
8936: approval => 'Approval by Dom. Coord.',
8937: automatic => 'Automatic approval',
8938: );
8939: return %titles;
1.210 raeburn 8940: }
1.163 raeburn 8941:
1.101 raeburn 8942: sub courserequest_conditions {
8943: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8944: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 8945: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8946: );
8947: return %conditions;
8948: }
8949:
8950:
1.27 raeburn 8951: sub print_usercreation {
1.30 raeburn 8952: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8953: my $numinrow = 4;
1.28 raeburn 8954: my $datatable;
8955: if ($position eq 'top') {
1.30 raeburn 8956: $$rowtotal ++;
1.34 raeburn 8957: my $rowcount = 0;
1.32 raeburn 8958: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8959: if (ref($rules) eq 'HASH') {
8960: if (keys(%{$rules}) > 0) {
1.32 raeburn 8961: $datatable .= &user_formats_row('username',$settings,$rules,
8962: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8963: $$rowtotal ++;
1.32 raeburn 8964: $rowcount ++;
8965: }
8966: }
8967: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8968: if (ref($idrules) eq 'HASH') {
8969: if (keys(%{$idrules}) > 0) {
8970: $datatable .= &user_formats_row('id',$settings,$idrules,
8971: $idruleorder,$numinrow,$rowcount);
8972: $$rowtotal ++;
8973: $rowcount ++;
1.28 raeburn 8974: }
8975: }
1.39 raeburn 8976: if ($rowcount == 0) {
8977: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8978: $$rowtotal ++;
8979: $rowcount ++;
8980: }
1.34 raeburn 8981: } elsif ($position eq 'middle') {
1.224 raeburn 8982: my @creators = ('author','course','requestcrs');
1.37 raeburn 8983: my ($rules,$ruleorder) =
8984: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8985: my %lt = &usercreation_types();
8986: my %checked;
8987: if (ref($settings) eq 'HASH') {
8988: if (ref($settings->{'cancreate'}) eq 'HASH') {
8989: foreach my $item (@creators) {
8990: $checked{$item} = $settings->{'cancreate'}{$item};
8991: }
8992: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8993: foreach my $item (@creators) {
8994: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8995: $checked{$item} = 'none';
8996: }
8997: }
8998: }
8999: }
9000: my $rownum = 0;
9001: foreach my $item (@creators) {
9002: $rownum ++;
1.224 raeburn 9003: if ($checked{$item} eq '') {
9004: $checked{$item} = 'any';
1.34 raeburn 9005: }
9006: my $css_class;
9007: if ($rownum%2) {
9008: $css_class = '';
9009: } else {
9010: $css_class = ' class="LC_odd_row" ';
9011: }
9012: $datatable .= '<tr'.$css_class.'>'.
9013: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9014: '</span></td><td style="text-align: right">';
1.224 raeburn 9015: my @options = ('any');
9016: if (ref($rules) eq 'HASH') {
9017: if (keys(%{$rules}) > 0) {
9018: push(@options,('official','unofficial'));
1.37 raeburn 9019: }
9020: }
1.224 raeburn 9021: push(@options,'none');
1.37 raeburn 9022: foreach my $option (@options) {
1.50 raeburn 9023: my $type = 'radio';
1.34 raeburn 9024: my $check = ' ';
1.224 raeburn 9025: if ($checked{$item} eq $option) {
9026: $check = ' checked="checked" ';
1.34 raeburn 9027: }
9028: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9029: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9030: $item.'" value="'.$option.'"'.$check.'/> '.
9031: $lt{$option}.'</label> </span>';
9032: }
9033: $datatable .= '</td></tr>';
9034: }
1.28 raeburn 9035: } else {
9036: my @contexts = ('author','course','domain');
1.325 raeburn 9037: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9038: my %checked;
9039: if (ref($settings) eq 'HASH') {
9040: if (ref($settings->{'authtypes'}) eq 'HASH') {
9041: foreach my $item (@contexts) {
9042: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9043: foreach my $auth (@authtypes) {
9044: if ($settings->{'authtypes'}{$item}{$auth}) {
9045: $checked{$item}{$auth} = ' checked="checked" ';
9046: }
9047: }
9048: }
9049: }
1.27 raeburn 9050: }
1.35 raeburn 9051: } else {
9052: foreach my $item (@contexts) {
1.36 raeburn 9053: foreach my $auth (@authtypes) {
1.35 raeburn 9054: $checked{$item}{$auth} = ' checked="checked" ';
9055: }
9056: }
1.27 raeburn 9057: }
1.28 raeburn 9058: my %title = &context_names();
9059: my %authname = &authtype_names();
9060: my $rownum = 0;
9061: my $css_class;
9062: foreach my $item (@contexts) {
9063: if ($rownum%2) {
9064: $css_class = '';
9065: } else {
9066: $css_class = ' class="LC_odd_row" ';
9067: }
1.30 raeburn 9068: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9069: '<td>'.$title{$item}.
9070: '</td><td class="LC_left_item">'.
9071: '<span class="LC_nobreak">';
9072: foreach my $auth (@authtypes) {
9073: $datatable .= '<label>'.
9074: '<input type="checkbox" name="'.$item.'_auth" '.
9075: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9076: $authname{$auth}.'</label> ';
9077: }
9078: $datatable .= '</span></td></tr>';
9079: $rownum ++;
1.27 raeburn 9080: }
1.30 raeburn 9081: $$rowtotal += $rownum;
1.27 raeburn 9082: }
9083: return $datatable;
9084: }
9085:
1.224 raeburn 9086: sub print_selfcreation {
9087: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9088: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9089: $emaildomain,$datatable);
1.224 raeburn 9090: if (ref($settings) eq 'HASH') {
9091: if (ref($settings->{'cancreate'}) eq 'HASH') {
9092: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9093: if (ref($createsettings) eq 'HASH') {
9094: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9095: @selfcreate = @{$createsettings->{'selfcreate'}};
9096: } elsif ($createsettings->{'selfcreate'} ne '') {
9097: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9098: @selfcreate = ('email','login','sso');
9099: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9100: @selfcreate = ($createsettings->{'selfcreate'});
9101: }
9102: }
9103: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9104: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9105: }
1.305 raeburn 9106: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9107: $emailoptions = $createsettings->{'emailoptions'};
9108: }
1.303 raeburn 9109: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9110: $emailverified = $createsettings->{'emailverified'};
9111: }
9112: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9113: $emaildomain = $createsettings->{'emaildomain'};
9114: }
1.224 raeburn 9115: }
9116: }
9117: }
9118: my %radiohash;
9119: my $numinrow = 4;
9120: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9121: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9122: if ($position eq 'top') {
9123: my %choices = &Apache::lonlocal::texthash (
9124: cancreate_login => 'Institutional Login',
9125: cancreate_sso => 'Institutional Single Sign On',
9126: );
9127: my @toggles = sort(keys(%choices));
9128: my %defaultchecked = (
9129: 'cancreate_login' => 'off',
9130: 'cancreate_sso' => 'off',
9131: );
1.228 raeburn 9132: my ($onclick,$itemcount);
1.224 raeburn 9133: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9134: \%choices,$itemcount,$onclick);
1.228 raeburn 9135: $$rowtotal += $itemcount;
9136:
1.224 raeburn 9137: if (ref($usertypes) eq 'HASH') {
9138: if (keys(%{$usertypes}) > 0) {
9139: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9140: $dom,$numinrow,$othertitle,
1.305 raeburn 9141: 'statustocreate',$rowtotal);
1.224 raeburn 9142: $$rowtotal ++;
9143: }
9144: }
1.240 raeburn 9145: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9146: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9147: $fieldtitles{'inststatus'} = &mt('Institutional status');
9148: my $rem;
9149: my $numperrow = 2;
9150: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9151: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9152: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9153: '<td class="LC_left_item">'."\n".
1.334 raeburn 9154: '<table>'."\n";
1.240 raeburn 9155: for (my $i=0; $i<@fields; $i++) {
9156: $rem = $i%($numperrow);
9157: if ($rem == 0) {
9158: if ($i > 0) {
9159: $datatable .= '</tr>';
9160: }
9161: $datatable .= '<tr>';
9162: }
9163: my $currval;
1.248 raeburn 9164: if (ref($createsettings) eq 'HASH') {
9165: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9166: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9167: }
1.240 raeburn 9168: }
9169: $datatable .= '<td class="LC_left_item">'.
9170: '<span class="LC_nobreak">'.
9171: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9172: 'value="'.$currval.'" size="10" /> '.
9173: $fieldtitles{$fields[$i]}.'</span></td>';
9174: }
9175: my $colsleft = $numperrow - $rem;
9176: if ($colsleft > 1 ) {
9177: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9178: ' </td>';
9179: } elsif ($colsleft == 1) {
9180: $datatable .= '<td class="LC_left_item"> </td>';
9181: }
9182: $datatable .= '</tr></table></td></tr>';
9183: $$rowtotal ++;
1.224 raeburn 9184: } elsif ($position eq 'middle') {
9185: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9186: my @posstypes;
1.224 raeburn 9187: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9188: @posstypes = @{$types};
9189: }
9190: unless (grep(/^default$/,@posstypes)) {
9191: push(@posstypes,'default');
9192: }
9193: my %usertypeshash;
9194: if (ref($usertypes) eq 'HASH') {
9195: %usertypeshash = %{$usertypes};
9196: }
9197: $usertypeshash{'default'} = $othertitle;
9198: foreach my $status (@posstypes) {
9199: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9200: $numinrow,$$rowtotal,\%usertypeshash);
9201: $$rowtotal ++;
1.224 raeburn 9202: }
9203: } else {
1.236 raeburn 9204: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9205: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9206: );
9207: my @toggles = sort(keys(%choices));
9208: my %defaultchecked = (
9209: 'cancreate_email' => 'off',
9210: );
1.305 raeburn 9211: my $customclass = 'LC_selfcreate_email';
9212: my $classprefix = 'LC_canmodify_emailusername_';
9213: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9214: my $display = 'none';
1.305 raeburn 9215: my $rowstyle = 'display:none';
1.236 raeburn 9216: if (grep(/^\Qemail\E$/,@selfcreate)) {
9217: $display = 'block';
1.305 raeburn 9218: $rowstyle = 'display:table-row';
1.236 raeburn 9219: }
1.305 raeburn 9220: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9221: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9222: \%choices,$$rowtotal,$onclick);
9223: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9224: $rowstyle);
9225: $$rowtotal ++;
9226: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9227: $rowstyle);
9228: $$rowtotal ++;
9229: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9230: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9231: my ($emailrules,$emailruleorder) =
9232: &Apache::lonnet::inst_userrules($dom,'email');
9233: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9234: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9235: if (ref($types) eq 'ARRAY') {
9236: @posstypes = @{$types};
9237: }
9238: if (@posstypes) {
9239: unless (grep(/^default$/,@posstypes)) {
9240: push(@posstypes,'default');
1.302 raeburn 9241: }
9242: if (ref($usertypes) eq 'HASH') {
9243: %usertypeshash = %{$usertypes};
9244: }
1.305 raeburn 9245: my $currassign;
9246: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9247: $currassign = {
9248: selfassign => $domdefaults{'inststatusguest'},
9249: };
9250: @ordered = @{$domdefaults{'inststatusguest'}};
9251: } else {
9252: $currassign = { selfassign => [] };
9253: }
9254: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9255: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9256: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9257: $numinrow,$othertitle,'selfassign',
9258: $rowtotal,$onclicktypes,$customclass,
9259: $rowstyle);
9260: $$rowtotal ++;
1.302 raeburn 9261: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9262: foreach my $status (@posstypes) {
9263: my $css_class;
9264: if ($$rowtotal%2) {
9265: $css_class = 'LC_odd_row ';
9266: }
9267: $css_class .= $customclass;
9268: my $rowid = $optionsprefix.$status;
9269: my $hidden = 1;
9270: my $currstyle = 'display:none';
9271: if (grep(/^\Q$status\E$/,@ordered)) {
9272: $currstyle = $rowstyle;
9273: $hidden = 0;
9274: }
9275: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9276: $emailrules,$emailruleorder,$settings,$status,$rowid,
9277: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9278: unless ($hidden) {
9279: $$rowtotal ++;
9280: }
1.224 raeburn 9281: }
1.302 raeburn 9282: } else {
1.305 raeburn 9283: my $css_class;
9284: if ($$rowtotal%2) {
9285: $css_class = 'LC_odd_row ';
9286: }
9287: $css_class .= $customclass;
1.302 raeburn 9288: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9289: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9290: $emailrules,$emailruleorder,$settings,'default','',
9291: $othertitle,$css_class,$rowstyle,$intdom);
9292: $$rowtotal ++;
1.224 raeburn 9293: }
9294: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9295: $numinrow = 1;
1.305 raeburn 9296: if (@posstypes) {
9297: foreach my $status (@posstypes) {
9298: my $rowid = $classprefix.$status;
9299: my $datarowstyle = 'display:none';
9300: if (grep(/^\Q$status\E$/,@ordered)) {
9301: $datarowstyle = $rowstyle;
9302: }
9303: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9304: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9305: $infotitles,$rowid,$customclass,$datarowstyle);
9306: unless ($datarowstyle eq 'display:none') {
9307: $$rowtotal ++;
9308: }
1.224 raeburn 9309: }
1.305 raeburn 9310: } else {
9311: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9312: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9313: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9314: }
9315: }
9316: return $datatable;
9317: }
9318:
1.305 raeburn 9319: sub selfcreate_javascript {
9320: return <<"ENDSCRIPT";
9321:
9322: <script type="text/javascript">
9323: // <![CDATA[
9324:
9325: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9326: var x = document.getElementsByClassName(target);
9327: var insttypes = 0;
9328: var insttypeRegExp = new RegExp(prefix);
9329: if ((x.length != undefined) && (x.length > 0)) {
9330: if (form.elements[radio].length != undefined) {
9331: for (var i=0; i<form.elements[radio].length; i++) {
9332: if (form.elements[radio][i].checked) {
9333: if (form.elements[radio][i].value == 1) {
9334: for (var j=0; j<x.length; j++) {
9335: if (x[j].id == 'undefined') {
9336: x[j].style.display = 'table-row';
9337: } else if (insttypeRegExp.test(x[j].id)) {
9338: insttypes ++;
9339: } else {
9340: x[j].style.display = 'table-row';
9341: }
9342: }
9343: } else {
9344: for (var j=0; j<x.length; j++) {
9345: x[j].style.display = 'none';
9346: }
1.236 raeburn 9347: }
1.305 raeburn 9348: break;
9349: }
9350: }
9351: if (insttypes > 0) {
9352: toggleDataRow(form,checkbox,target,altprefix);
9353: toggleDataRow(form,checkbox,target,prefix,1);
9354: }
9355: }
9356: }
9357: return;
9358: }
9359:
9360: function toggleDataRow(form,checkbox,target,prefix,docount) {
9361: if (form.elements[checkbox].length != undefined) {
9362: var count = 0;
9363: if (docount) {
9364: for (var i=0; i<form.elements[checkbox].length; i++) {
9365: if (form.elements[checkbox][i].checked) {
9366: count ++;
1.236 raeburn 9367: }
1.305 raeburn 9368: }
9369: }
9370: for (var i=0; i<form.elements[checkbox].length; i++) {
9371: var type = form.elements[checkbox][i].value;
9372: if (document.getElementById(prefix+type)) {
9373: if (form.elements[checkbox][i].checked) {
9374: document.getElementById(prefix+type).style.display = 'table-row';
9375: if (count % 2 == 1) {
9376: document.getElementById(prefix+type).className = target+' LC_odd_row';
9377: } else {
9378: document.getElementById(prefix+type).className = target;
1.236 raeburn 9379: }
1.305 raeburn 9380: count ++;
1.236 raeburn 9381: } else {
1.305 raeburn 9382: document.getElementById(prefix+type).style.display = 'none';
9383: }
9384: }
9385: }
9386: }
9387: return;
9388: }
9389:
9390: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9391: var caller = radio+'_'+status;
9392: if (form.elements[caller].length != undefined) {
9393: for (var i=0; i<form.elements[caller].length; i++) {
9394: if (form.elements[caller][i].checked) {
9395: if (document.getElementById(altprefix+'_inst_'+status)) {
9396: var curr = form.elements[caller][i].value;
9397: if (prefix) {
9398: document.getElementById(prefix+'_'+status).style.display = 'none';
9399: }
9400: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9401: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9402: if (curr == 'custom') {
9403: if (prefix) {
9404: document.getElementById(prefix+'_'+status).style.display = 'inline';
9405: }
9406: } else if (curr == 'inst') {
9407: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9408: } else if (curr == 'noninst') {
9409: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9410: }
1.305 raeburn 9411: break;
1.236 raeburn 9412: }
9413: }
9414: }
9415: }
9416: }
9417:
1.305 raeburn 9418: // ]]>
9419: </script>
9420:
9421: ENDSCRIPT
9422: }
9423:
9424: sub noninst_users {
9425: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9426: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9427: my $class = 'LC_left_item';
9428: if ($css_class) {
9429: $css_class = ' class="'.$css_class.'"';
9430: }
9431: if ($rowid) {
9432: $rowid = ' id="'.$rowid.'"';
9433: }
9434: if ($rowstyle) {
9435: $rowstyle = ' style="'.$rowstyle.'"';
9436: }
9437: my ($output,$description);
9438: if ($type eq 'default') {
9439: $description = &mt('Requests for: [_1]',$typetitle);
9440: } else {
9441: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9442: }
9443: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9444: "<td>$description</td>\n".
9445: '<td class="'.$class.'" colspan="2">'.
9446: '<table><tr>';
9447: my %headers = &Apache::lonlocal::texthash(
9448: approve => 'Processing',
9449: email => 'E-mail',
9450: username => 'Username',
9451: );
9452: foreach my $item ('approve','email','username') {
9453: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9454: }
1.305 raeburn 9455: $output .= '</tr><tr>';
9456: foreach my $item ('approve','email','username') {
1.306 raeburn 9457: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9458: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9459: if ($item eq 'approve') {
9460: %choices = &Apache::lonlocal::texthash (
9461: automatic => 'Automatically approved',
9462: approval => 'Queued for approval',
9463: );
9464: @options = ('automatic','approval');
9465: $hashref = $processing;
9466: $defoption = 'automatic';
9467: $name = 'cancreate_emailprocess_'.$type;
9468: } elsif ($item eq 'email') {
9469: %choices = &Apache::lonlocal::texthash (
9470: any => 'Any e-mail',
9471: inst => 'Institutional only',
9472: noninst => 'Non-institutional only',
9473: custom => 'Custom restrictions',
9474: );
9475: @options = ('any','inst','noninst');
9476: my $showcustom;
9477: if (ref($emailrules) eq 'HASH') {
9478: if (keys(%{$emailrules}) > 0) {
9479: push(@options,'custom');
9480: $showcustom = 'cancreate_emailrule';
9481: if (ref($settings) eq 'HASH') {
9482: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9483: foreach my $rule (@{$settings->{'email_rule'}}) {
9484: if (exists($emailrules->{$rule})) {
9485: $hascustom ++;
9486: }
9487: }
9488: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9489: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9490: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9491: if (exists($emailrules->{$rule})) {
9492: $hascustom ++;
9493: }
9494: }
9495: }
9496: }
9497: }
9498: }
9499: }
9500: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9501: "'cancreate_emaildomain','$type'".');"';
9502: $hashref = $emailoptions;
9503: $defoption = 'any';
9504: $name = 'cancreate_emailoptions_'.$type;
9505: } elsif ($item eq 'username') {
9506: %choices = &Apache::lonlocal::texthash (
9507: all => 'Same as e-mail',
9508: first => 'Omit @domain',
9509: free => 'Free to choose',
9510: );
9511: @options = ('all','first','free');
9512: $hashref = $emailverified;
9513: $defoption = 'all';
9514: $name = 'cancreate_usernameoptions_'.$type;
9515: }
9516: foreach my $option (@options) {
9517: my $checked;
9518: if (ref($hashref) eq 'HASH') {
9519: if ($type eq '') {
9520: if (!exists($hashref->{'default'})) {
9521: if ($option eq $defoption) {
9522: $checked = ' checked="checked"';
9523: }
9524: } else {
9525: if ($hashref->{'default'} eq $option) {
9526: $checked = ' checked="checked"';
9527: }
1.303 raeburn 9528: }
9529: } else {
1.305 raeburn 9530: if (!exists($hashref->{$type})) {
9531: if ($option eq $defoption) {
9532: $checked = ' checked="checked"';
9533: }
9534: } else {
9535: if ($hashref->{$type} eq $option) {
9536: $checked = ' checked="checked"';
9537: }
1.303 raeburn 9538: }
9539: }
1.305 raeburn 9540: } elsif (($item eq 'email') && ($hascustom)) {
9541: if ($option eq 'custom') {
9542: $checked = ' checked="checked"';
9543: }
9544: } elsif ($option eq $defoption) {
9545: $checked = ' checked="checked"';
9546: }
9547: $output .= '<span class="LC_nobreak"><label>'.
9548: '<input type="radio" name="'.$name.'"'.
9549: $checked.' value="'.$option.'"'.$onclick.' />'.
9550: $choices{$option}.'</label></span><br />';
9551: if ($item eq 'email') {
9552: if ($option eq 'custom') {
9553: my $id = 'cancreate_emailrule_'.$type;
9554: my $display = 'none';
9555: if ($checked) {
9556: $display = 'inline';
1.303 raeburn 9557: }
1.305 raeburn 9558: my $numinrow = 2;
9559: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9560: '<legend>'.&mt('Disallow').'</legend><table>'.
9561: &user_formats_row('email',$settings,$emailrules,
9562: $emailruleorder,$numinrow,'',$type);
9563: '</table></fieldset>';
9564: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9565: my %text = &Apache::lonlocal::texthash (
9566: inst => 'must end:',
9567: noninst => 'cannot end:',
9568: );
9569: my $value;
9570: if (ref($emaildomain) eq 'HASH') {
9571: if (ref($emaildomain->{$type}) eq 'HASH') {
9572: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9573: }
9574: }
1.305 raeburn 9575: if ($value eq '') {
9576: $value = '@'.$intdom;
9577: }
9578: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9579: my $display = 'none';
9580: if ($checked) {
9581: $display = 'inline';
9582: }
9583: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9584: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9585: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9586: '</div>';
1.303 raeburn 9587: }
9588: }
9589: }
1.305 raeburn 9590: $output .= '</td>'."\n";
1.303 raeburn 9591: }
1.305 raeburn 9592: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9593: return $output;
9594: }
9595:
1.165 raeburn 9596: sub captcha_choice {
1.305 raeburn 9597: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9598: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9599: $vertext,$currver);
1.165 raeburn 9600: my %lt = &captcha_phrases();
9601: $keyentry = 'hidden';
1.354 raeburn 9602: my $colspan=2;
1.165 raeburn 9603: if ($context eq 'cancreate') {
1.224 raeburn 9604: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9605: } elsif ($context eq 'login') {
9606: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9607: } elsif ($context eq 'passwords') {
9608: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9609: $colspan=1;
1.165 raeburn 9610: }
9611: if (ref($settings) eq 'HASH') {
9612: if ($settings->{'captcha'}) {
9613: $checked{$settings->{'captcha'}} = ' checked="checked"';
9614: } else {
9615: $checked{'original'} = ' checked="checked"';
9616: }
9617: if ($settings->{'captcha'} eq 'recaptcha') {
9618: $pubtext = $lt{'pub'};
9619: $privtext = $lt{'priv'};
9620: $keyentry = 'text';
1.269 raeburn 9621: $vertext = $lt{'ver'};
9622: $currver = $settings->{'recaptchaversion'};
9623: if ($currver ne '2') {
9624: $currver = 1;
9625: }
1.165 raeburn 9626: }
9627: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9628: $currpub = $settings->{'recaptchakeys'}{'public'};
9629: $currpriv = $settings->{'recaptchakeys'}{'private'};
9630: }
9631: } else {
9632: $checked{'original'} = ' checked="checked"';
9633: }
1.305 raeburn 9634: my $css_class;
9635: if ($itemcount%2) {
9636: $css_class = 'LC_odd_row';
9637: }
9638: if ($customcss) {
9639: $css_class .= " $customcss";
9640: }
9641: $css_class =~ s/^\s+//;
9642: if ($css_class) {
9643: $css_class = ' class="'.$css_class.'"';
9644: }
9645: if ($rowstyle) {
9646: $css_class .= ' style="'.$rowstyle.'"';
9647: }
1.169 raeburn 9648: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9649: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9650: '<table><tr><td>'."\n";
9651: foreach my $option ('original','recaptcha','notused') {
9652: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9653: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9654: $lt{$option}.'</label></span>';
9655: unless ($option eq 'notused') {
9656: $output .= (' 'x2)."\n";
9657: }
9658: }
9659: #
9660: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9661: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9662: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9663: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9664: #
1.165 raeburn 9665: $output .= '</td></tr>'."\n".
1.305 raeburn 9666: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9667: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9668: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9669: $currpub.'" size="40" /></span><br />'."\n".
9670: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9671: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9672: $currpriv.'" size="40" /></span><br />'.
9673: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9674: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9675: $currver.'" size="3" /></span><br />'.
9676: '</td></tr></table>'."\n".
1.165 raeburn 9677: '</td></tr>';
9678: return $output;
9679: }
9680:
1.32 raeburn 9681: sub user_formats_row {
1.305 raeburn 9682: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9683: my $output;
9684: my %text = (
9685: 'username' => 'new usernames',
9686: 'id' => 'IDs',
9687: );
1.305 raeburn 9688: unless ($type eq 'email') {
9689: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9690: $output = '<tr '.$css_class.'>'.
9691: '<td><span class="LC_nobreak">'.
9692: &mt("Format rules to check for $text{$type}: ").
9693: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9694: }
1.27 raeburn 9695: my $rem;
9696: if (ref($ruleorder) eq 'ARRAY') {
9697: for (my $i=0; $i<@{$ruleorder}; $i++) {
9698: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9699: my $rem = $i%($numinrow);
9700: if ($rem == 0) {
9701: if ($i > 0) {
9702: $output .= '</tr>';
9703: }
9704: $output .= '<tr>';
9705: }
9706: my $check = ' ';
1.39 raeburn 9707: if (ref($settings) eq 'HASH') {
9708: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9709: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9710: $check = ' checked="checked" ';
9711: }
1.305 raeburn 9712: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9713: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9714: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9715: $check = ' checked="checked" ';
9716: }
9717: }
1.27 raeburn 9718: }
9719: }
1.305 raeburn 9720: my $name = $type.'_rule';
9721: if ($type eq 'email') {
9722: $name .= '_'.$status;
9723: }
1.27 raeburn 9724: $output .= '<td class="LC_left_item">'.
9725: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9726: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9727: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9728: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9729: }
9730: }
9731: $rem = @{$ruleorder}%($numinrow);
9732: }
1.305 raeburn 9733: my $colsleft;
9734: if ($rem) {
9735: $colsleft = $numinrow - $rem;
9736: }
1.27 raeburn 9737: if ($colsleft > 1 ) {
9738: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9739: ' </td>';
9740: } elsif ($colsleft == 1) {
9741: $output .= '<td class="LC_left_item"> </td>';
9742: }
1.305 raeburn 9743: $output .= '</tr></table>';
9744: unless ($type eq 'email') {
9745: $output .= '</td></tr>';
9746: }
1.27 raeburn 9747: return $output;
9748: }
9749:
1.34 raeburn 9750: sub usercreation_types {
9751: my %lt = &Apache::lonlocal::texthash (
9752: author => 'When adding a co-author',
9753: course => 'When adding a user to a course',
1.100 raeburn 9754: requestcrs => 'When requesting a course',
1.34 raeburn 9755: any => 'Any',
9756: official => 'Institutional only ',
9757: unofficial => 'Non-institutional only',
9758: none => 'None',
9759: );
9760: return %lt;
1.48 raeburn 9761: }
1.34 raeburn 9762:
1.224 raeburn 9763: sub selfcreation_types {
9764: my %lt = &Apache::lonlocal::texthash (
9765: selfcreate => 'User creates own account',
9766: any => 'Any',
9767: official => 'Institutional only ',
9768: unofficial => 'Non-institutional only',
9769: email => 'E-mail address',
9770: login => 'Institutional Login',
9771: sso => 'SSO',
9772: );
9773: }
9774:
1.28 raeburn 9775: sub authtype_names {
9776: my %lt = &Apache::lonlocal::texthash(
9777: int => 'Internal',
9778: krb4 => 'Kerberos 4',
9779: krb5 => 'Kerberos 5',
9780: loc => 'Local',
1.325 raeburn 9781: lti => 'LTI',
1.28 raeburn 9782: );
9783: return %lt;
9784: }
9785:
9786: sub context_names {
9787: my %context_title = &Apache::lonlocal::texthash(
9788: author => 'Creating users when an Author',
9789: course => 'Creating users when in a course',
9790: domain => 'Creating users when a Domain Coordinator',
9791: );
9792: return %context_title;
9793: }
9794:
1.33 raeburn 9795: sub print_usermodification {
9796: my ($position,$dom,$settings,$rowtotal) = @_;
9797: my $numinrow = 4;
9798: my ($context,$datatable,$rowcount);
9799: if ($position eq 'top') {
9800: $rowcount = 0;
9801: $context = 'author';
9802: foreach my $role ('ca','aa') {
9803: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9804: $numinrow,$rowcount);
9805: $$rowtotal ++;
9806: $rowcount ++;
9807: }
1.230 raeburn 9808: } elsif ($position eq 'bottom') {
1.33 raeburn 9809: $context = 'course';
9810: $rowcount = 0;
9811: foreach my $role ('st','ep','ta','in','cr') {
9812: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9813: $numinrow,$rowcount);
9814: $$rowtotal ++;
9815: $rowcount ++;
9816: }
9817: }
9818: return $datatable;
9819: }
9820:
1.43 raeburn 9821: sub print_defaults {
1.236 raeburn 9822: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9823: my $rownum = 0;
1.294 raeburn 9824: my ($datatable,$css_class,$titles);
9825: unless ($position eq 'bottom') {
9826: $titles = &defaults_titles($dom);
9827: }
1.236 raeburn 9828: if ($position eq 'top') {
9829: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9830: 'datelocale_def','portal_def');
9831: my %defaults;
9832: if (ref($settings) eq 'HASH') {
9833: %defaults = %{$settings};
1.43 raeburn 9834: } else {
1.236 raeburn 9835: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9836: foreach my $item (@items) {
9837: $defaults{$item} = $domdefaults{$item};
9838: }
1.43 raeburn 9839: }
1.236 raeburn 9840: foreach my $item (@items) {
9841: if ($rownum%2) {
9842: $css_class = '';
9843: } else {
9844: $css_class = ' class="LC_odd_row" ';
9845: }
9846: $datatable .= '<tr'.$css_class.'>'.
9847: '<td><span class="LC_nobreak">'.$titles->{$item}.
9848: '</span></td><td class="LC_right_item" colspan="3">';
9849: if ($item eq 'auth_def') {
1.325 raeburn 9850: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9851: my %shortauth = (
9852: internal => 'int',
9853: krb4 => 'krb4',
9854: krb5 => 'krb5',
1.325 raeburn 9855: localauth => 'loc',
9856: lti => 'lti',
1.236 raeburn 9857: );
9858: my %authnames = &authtype_names();
9859: foreach my $auth (@authtypes) {
9860: my $checked = ' ';
9861: if ($defaults{$item} eq $auth) {
9862: $checked = ' checked="checked" ';
9863: }
9864: $datatable .= '<label><input type="radio" name="'.$item.
9865: '" value="'.$auth.'"'.$checked.'/>'.
9866: $authnames{$shortauth{$auth}}.'</label> ';
9867: }
9868: } elsif ($item eq 'timezone_def') {
9869: my $includeempty = 1;
9870: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9871: } elsif ($item eq 'datelocale_def') {
9872: my $includeempty = 1;
9873: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9874: } elsif ($item eq 'lang_def') {
1.263 raeburn 9875: my $includeempty = 1;
9876: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9877: } else {
9878: my $size;
9879: if ($item eq 'portal_def') {
9880: $size = ' size="25"';
9881: }
9882: $datatable .= '<input type="text" name="'.$item.'" value="'.
9883: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9884: }
1.236 raeburn 9885: $datatable .= '</td></tr>';
9886: $rownum ++;
9887: }
1.354 raeburn 9888: } else {
1.294 raeburn 9889: my %defaults;
9890: if (ref($settings) eq 'HASH') {
1.354 raeburn 9891: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9892: my $maxnum = @{$settings->{'inststatusorder'}};
9893: for (my $i=0; $i<$maxnum; $i++) {
9894: $css_class = $rownum%2?' class="LC_odd_row"':'';
9895: my $item = $settings->{'inststatusorder'}->[$i];
9896: my $title = $settings->{'inststatustypes'}->{$item};
9897: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9898: $datatable .= '<tr'.$css_class.'>'.
9899: '<td><span class="LC_nobreak">'.
9900: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9901: for (my $k=0; $k<=$maxnum; $k++) {
9902: my $vpos = $k+1;
9903: my $selstr;
9904: if ($k == $i) {
9905: $selstr = ' selected="selected" ';
9906: }
9907: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9908: }
9909: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9910: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9911: &mt('delete').'</span></td>'.
1.380 raeburn 9912: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 9913: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9914: '</span></td></tr>';
9915: }
9916: $css_class = $rownum%2?' class="LC_odd_row"':'';
9917: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9918: $datatable .= '<tr '.$css_class.'>'.
9919: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9920: for (my $k=0; $k<=$maxnum; $k++) {
9921: my $vpos = $k+1;
9922: my $selstr;
9923: if ($k == $maxnum) {
9924: $selstr = ' selected="selected" ';
9925: }
9926: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9927: }
9928: $datatable .= '</select> '.&mt('Internal ID:').
9929: '<input type="text" size="10" name="addinststatus" value="" />'.
9930: ' '.&mt('(new)').
9931: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 9932: &mt('Name displayed').':'.
1.354 raeburn 9933: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9934: '</tr>'."\n";
9935: $rownum ++;
1.294 raeburn 9936: }
1.354 raeburn 9937: }
9938: }
9939: $$rowtotal += $rownum;
1.43 raeburn 9940: return $datatable;
9941: }
9942:
1.168 raeburn 9943: sub get_languages_hash {
9944: my %langchoices;
9945: foreach my $id (&Apache::loncommon::languageids()) {
9946: my $code = &Apache::loncommon::supportedlanguagecode($id);
9947: if ($code ne '') {
9948: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9949: }
9950: }
9951: return %langchoices;
9952: }
9953:
1.43 raeburn 9954: sub defaults_titles {
1.141 raeburn 9955: my ($dom) = @_;
1.43 raeburn 9956: my %titles = &Apache::lonlocal::texthash (
9957: 'auth_def' => 'Default authentication type',
9958: 'auth_arg_def' => 'Default authentication argument',
9959: 'lang_def' => 'Default language',
1.54 raeburn 9960: 'timezone_def' => 'Default timezone',
1.68 raeburn 9961: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9962: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 9963: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9964: 'intauth_check' => 'Check bcrypt cost if authenticated',
9965: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9966: );
1.141 raeburn 9967: if ($dom) {
9968: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9969: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9970: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9971: $protocol = 'http' if ($protocol ne 'https');
9972: if ($uint_dom) {
9973: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9974: $uint_dom);
9975: }
9976: }
1.43 raeburn 9977: return (\%titles);
9978: }
9979:
1.346 raeburn 9980: sub print_scantron {
9981: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9982: if ($position eq 'top') {
9983: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9984: } else {
9985: return &print_scantronconfig($dom,$settings,\$rowtotal);
9986: }
9987: }
9988:
9989: sub scantron_javascript {
9990: return <<"ENDSCRIPT";
9991:
9992: <script type="text/javascript">
9993: // <![CDATA[
9994:
9995: function toggleScantron(form) {
1.347 raeburn 9996: var csvfieldset = new Array();
1.346 raeburn 9997: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 9998: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9999: }
10000: if (document.getElementById('scantroncsv_options')) {
10001: csvfieldset.push(document.getElementById('scantroncsv_options'));
10002: }
10003: if (csvfieldset.length) {
1.346 raeburn 10004: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10005: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10006: if (scantroncsv.checked) {
1.347 raeburn 10007: for (var i=0; i<csvfieldset.length; i++) {
10008: csvfieldset[i].style.display = 'block';
10009: }
1.346 raeburn 10010: } else {
1.347 raeburn 10011: for (var i=0; i<csvfieldset.length; i++) {
10012: csvfieldset[i].style.display = 'none';
10013: }
1.346 raeburn 10014: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10015: if (csvselects.length) {
10016: for (var j=0; j<csvselects.length; j++) {
10017: csvselects[j].selectedIndex = 0;
10018: }
10019: }
10020: }
10021: }
10022: }
10023: return;
10024: }
10025: // ]]>
10026: </script>
10027:
10028: ENDSCRIPT
10029:
10030: }
10031:
1.46 raeburn 10032: sub print_scantronformat {
10033: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10034: my $itemcount = 1;
1.60 raeburn 10035: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10036: %confhash);
1.46 raeburn 10037: my $switchserver = &check_switchserver($dom,$confname);
10038: my %lt = &Apache::lonlocal::texthash (
1.95 www 10039: default => 'Default bubblesheet format file error',
10040: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10041: );
10042: my %scantronfiles = (
10043: default => 'default.tab',
10044: custom => 'custom.tab',
10045: );
10046: foreach my $key (keys(%scantronfiles)) {
10047: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10048: .$scantronfiles{$key};
10049: }
10050: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10051: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10052: if (!$switchserver) {
10053: my $servadm = $r->dir_config('lonAdmEMail');
10054: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10055: if ($configuserok eq 'ok') {
10056: if ($author_ok eq 'ok') {
10057: my %legacyfile = (
1.346 raeburn 10058: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10059: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10060: );
10061: my %md5chk;
10062: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10063: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10064: chomp($md5chk{$type});
1.46 raeburn 10065: }
10066: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10067: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10068: ($scantronurls{$type},my $error) =
1.46 raeburn 10069: &legacy_scantronformat($r,$dom,$confname,
10070: $type,$legacyfile{$type},
10071: $scantronurls{$type},
10072: $scantronfiles{$type});
1.60 raeburn 10073: if ($error ne '') {
10074: $error{$type} = $error;
10075: }
10076: }
10077: if (keys(%error) == 0) {
10078: $is_custom = 1;
1.346 raeburn 10079: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10080: $scantronurls{'custom'};
1.346 raeburn 10081: my $putresult =
1.60 raeburn 10082: &Apache::lonnet::put_dom('configuration',
10083: \%confhash,$dom);
10084: if ($putresult ne 'ok') {
1.346 raeburn 10085: $error{'custom'} =
1.60 raeburn 10086: '<span class="LC_error">'.
10087: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10088: }
1.46 raeburn 10089: }
10090: } else {
1.60 raeburn 10091: ($scantronurls{'default'},my $error) =
1.46 raeburn 10092: &legacy_scantronformat($r,$dom,$confname,
10093: 'default',$legacyfile{'default'},
10094: $scantronurls{'default'},
10095: $scantronfiles{'default'});
1.60 raeburn 10096: if ($error eq '') {
10097: $confhash{'scantron'}{'scantronformat'} = '';
10098: my $putresult =
10099: &Apache::lonnet::put_dom('configuration',
10100: \%confhash,$dom);
10101: if ($putresult ne 'ok') {
10102: $error{'default'} =
10103: '<span class="LC_error">'.
10104: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10105: }
10106: } else {
10107: $error{'default'} = $error;
10108: }
1.46 raeburn 10109: }
10110: }
10111: }
10112: } else {
1.95 www 10113: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10114: }
10115: }
10116: if (ref($settings) eq 'HASH') {
10117: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10118: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10119: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10120: $scantronurl = '';
10121: } else {
10122: $scantronurl = $settings->{'scantronformat'};
10123: }
10124: $is_custom = 1;
10125: } else {
10126: $scantronurl = $scantronurls{'default'};
10127: }
10128: } else {
1.60 raeburn 10129: if ($is_custom) {
10130: $scantronurl = $scantronurls{'custom'};
10131: } else {
10132: $scantronurl = $scantronurls{'default'};
10133: }
1.46 raeburn 10134: }
10135: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10136: $datatable .= '<tr'.$css_class.'>';
10137: if (!$is_custom) {
1.65 raeburn 10138: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10139: '<span class="LC_nobreak">';
1.46 raeburn 10140: if ($scantronurl) {
1.199 raeburn 10141: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10142: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10143: } else {
10144: $datatable = &mt('File unavailable for display');
10145: }
1.65 raeburn 10146: $datatable .= '</span></td>';
1.60 raeburn 10147: if (keys(%error) == 0) {
1.306 raeburn 10148: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10149: if (!$switchserver) {
10150: $datatable .= &mt('Upload:').'<br />';
10151: }
10152: } else {
10153: my $errorstr;
10154: foreach my $key (sort(keys(%error))) {
10155: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10156: }
10157: $datatable .= '<td>'.$errorstr;
10158: }
1.46 raeburn 10159: } else {
10160: if (keys(%error) > 0) {
10161: my $errorstr;
10162: foreach my $key (sort(keys(%error))) {
10163: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10164: }
1.60 raeburn 10165: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10166: } elsif ($scantronurl) {
1.199 raeburn 10167: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10168: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10169: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10170: $link.
10171: '<label><input type="checkbox" name="scantronformat_del"'.
10172: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10173: '<td><span class="LC_nobreak"> '.
10174: &mt('Replace:').'</span><br />';
1.46 raeburn 10175: }
10176: }
10177: if (keys(%error) == 0) {
10178: if ($switchserver) {
10179: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10180: } else {
1.65 raeburn 10181: $datatable .='<span class="LC_nobreak"> '.
10182: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10183: }
10184: }
10185: $datatable .= '</td></tr>';
10186: $$rowtotal ++;
10187: return $datatable;
10188: }
10189:
10190: sub legacy_scantronformat {
10191: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10192: my ($url,$error);
10193: my @statinfo = &Apache::lonnet::stat_file($newurl);
10194: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
10195: (my $result,$url) =
10196: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
10197: '','',$newfile);
10198: if ($result ne 'ok') {
1.130 raeburn 10199: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10200: }
10201: }
10202: return ($url,$error);
10203: }
1.43 raeburn 10204:
1.346 raeburn 10205: sub print_scantronconfig {
10206: my ($dom,$settings,$rowtotal) = @_;
10207: my $itemcount = 2;
10208: my $is_checked = ' checked="checked"';
1.347 raeburn 10209: my %optionson = (
10210: hdr => ' checked="checked"',
10211: pad => ' checked="checked"',
10212: rem => ' checked="checked"',
10213: );
10214: my %optionsoff = (
10215: hdr => '',
10216: pad => '',
10217: rem => '',
10218: );
1.346 raeburn 10219: my $currcsvsty = 'none';
1.347 raeburn 10220: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10221: my @fields = &scantroncsv_fields();
10222: my %titles = &scantronconfig_titles();
10223: if (ref($settings) eq 'HASH') {
10224: if (ref($settings->{config}) eq 'HASH') {
10225: if ($settings->{config}->{dat}) {
10226: $checked{'dat'} = $is_checked;
10227: }
10228: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10229: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10230: %csvfields = %{$settings->{config}->{csv}->{fields}};
10231: if (keys(%csvfields) > 0) {
10232: $checked{'csv'} = $is_checked;
10233: $currcsvsty = 'block';
10234: }
10235: }
10236: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10237: %csvoptions = %{$settings->{config}->{csv}->{options}};
10238: foreach my $option (keys(%optionson)) {
10239: unless ($csvoptions{$option}) {
10240: $optionsoff{$option} = $optionson{$option};
10241: $optionson{$option} = '';
10242: }
10243: }
1.346 raeburn 10244: }
10245: }
10246: } else {
10247: $checked{'dat'} = $is_checked;
10248: }
10249: } else {
10250: $checked{'dat'} = $is_checked;
10251: }
10252: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10253: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10254: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10255: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10256: foreach my $item ('dat','csv') {
10257: my $id;
10258: if ($item eq 'csv') {
10259: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10260: }
1.346 raeburn 10261: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10262: $titles{$item}.'</label>'.(' 'x3);
10263: if ($item eq 'csv') {
10264: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10265: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10266: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10267: foreach my $col (@fields) {
10268: my $selnone;
10269: if ($csvfields{$col} eq '') {
10270: $selnone = ' selected="selected"';
10271: }
10272: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10273: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10274: '<option value=""'.$selnone.'></option>';
10275: for (my $i=0; $i<20; $i++) {
10276: my $shown = $i+1;
10277: my $sel;
10278: unless ($selnone) {
10279: if (exists($csvfields{$col})) {
10280: if ($csvfields{$col} == $i) {
10281: $sel = ' selected="selected"';
10282: }
10283: }
10284: }
10285: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10286: }
10287: $datatable .= '</select></td></tr>';
10288: }
1.347 raeburn 10289: $datatable .= '</table></fieldset>'.
10290: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10291: '<legend>'.&mt('CSV Options').'</legend>';
10292: foreach my $option ('hdr','pad','rem') {
10293: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10294: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10295: &mt('Yes').'</label>'.(' 'x2)."\n".
10296: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10297: }
10298: $datatable .= '</fieldset>';
1.346 raeburn 10299: $itemcount ++;
10300: }
10301: }
10302: $datatable .= '</td></tr>';
10303: $$rowtotal ++;
10304: return $datatable;
10305: }
10306:
10307: sub scantronconfig_titles {
10308: return &Apache::lonlocal::texthash(
10309: dat => 'Standard format (.dat)',
10310: csv => 'Comma separated values (.csv)',
1.347 raeburn 10311: hdr => 'Remove first line in file (contains column titles)',
10312: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10313: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10314: CODE => 'CODE',
10315: ID => 'Student ID',
10316: PaperID => 'Paper ID',
10317: FirstName => 'First Name',
10318: LastName => 'Last Name',
10319: FirstQuestion => 'First Question Response',
10320: Section => 'Section',
10321: );
10322: }
10323:
10324: sub scantroncsv_fields {
10325: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10326: }
10327:
1.49 raeburn 10328: sub print_coursecategories {
1.57 raeburn 10329: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10330: my $datatable;
10331: if ($position eq 'top') {
1.238 raeburn 10332: my (%checked);
10333: my @catitems = ('unauth','auth');
10334: my @cattypes = ('std','domonly','codesrch','none');
10335: $checked{'unauth'} = 'std';
10336: $checked{'auth'} = 'std';
10337: if (ref($settings) eq 'HASH') {
10338: foreach my $type (@cattypes) {
10339: if ($type eq $settings->{'unauth'}) {
10340: $checked{'unauth'} = $type;
10341: }
10342: if ($type eq $settings->{'auth'}) {
10343: $checked{'auth'} = $type;
10344: }
10345: }
10346: }
10347: my %lt = &Apache::lonlocal::texthash (
10348: unauth => 'Catalog type for unauthenticated users',
10349: auth => 'Catalog type for authenticated users',
10350: none => 'No catalog',
10351: std => 'Standard catalog',
10352: domonly => 'Domain-only catalog',
10353: codesrch => "Code search form",
10354: );
10355: my $itemcount = 0;
10356: foreach my $item (@catitems) {
10357: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10358: $datatable .= '<tr '.$css_class.'>'.
10359: '<td>'.$lt{$item}.'</td>'.
10360: '<td class="LC_right_item"><span class="LC_nobreak">';
10361: foreach my $type (@cattypes) {
10362: my $ischecked;
10363: if ($checked{$item} eq $type) {
10364: $ischecked=' checked="checked"';
10365: }
10366: $datatable .= '<label>'.
10367: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10368: ' />'.$lt{$type}.'</label> ';
10369: }
1.327 raeburn 10370: $datatable .= '</span></td></tr>';
1.238 raeburn 10371: $itemcount ++;
10372: }
10373: $$rowtotal += $itemcount;
10374: } elsif ($position eq 'middle') {
1.57 raeburn 10375: my $toggle_cats_crs = ' ';
10376: my $toggle_cats_dom = ' checked="checked" ';
10377: my $can_cat_crs = ' ';
10378: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10379: my $toggle_catscomm_comm = ' ';
10380: my $toggle_catscomm_dom = ' checked="checked" ';
10381: my $can_catcomm_comm = ' ';
10382: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10383: my $toggle_catsplace_place = ' ';
10384: my $toggle_catsplace_dom = ' checked="checked" ';
10385: my $can_catplace_place = ' ';
10386: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10387:
1.57 raeburn 10388: if (ref($settings) eq 'HASH') {
10389: if ($settings->{'togglecats'} eq 'crs') {
10390: $toggle_cats_crs = $toggle_cats_dom;
10391: $toggle_cats_dom = ' ';
10392: }
10393: if ($settings->{'categorize'} eq 'crs') {
10394: $can_cat_crs = $can_cat_dom;
10395: $can_cat_dom = ' ';
10396: }
1.120 raeburn 10397: if ($settings->{'togglecatscomm'} eq 'comm') {
10398: $toggle_catscomm_comm = $toggle_catscomm_dom;
10399: $toggle_catscomm_dom = ' ';
10400: }
10401: if ($settings->{'categorizecomm'} eq 'comm') {
10402: $can_catcomm_comm = $can_catcomm_dom;
10403: $can_catcomm_dom = ' ';
10404: }
1.272 raeburn 10405: if ($settings->{'togglecatsplace'} eq 'place') {
10406: $toggle_catsplace_place = $toggle_catsplace_dom;
10407: $toggle_catsplace_dom = ' ';
10408: }
10409: if ($settings->{'categorizeplace'} eq 'place') {
10410: $can_catplace_place = $can_catplace_dom;
10411: $can_catplace_dom = ' ';
10412: }
1.57 raeburn 10413: }
10414: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10415: togglecats => 'Show/Hide a course in catalog',
10416: togglecatscomm => 'Show/Hide a community in catalog',
10417: togglecatsplace => 'Show/Hide a placement test in catalog',
10418: categorize => 'Assign a category to a course',
10419: categorizecomm => 'Assign a category to a community',
10420: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10421: );
10422: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10423: dom => 'Set in Domain',
10424: crs => 'Set in Course',
10425: comm => 'Set in Community',
10426: place => 'Set in Placement Test',
1.57 raeburn 10427: );
10428: $datatable = '<tr class="LC_odd_row">'.
10429: '<td>'.$title{'togglecats'}.'</td>'.
10430: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10431: '<input type="radio" name="togglecats"'.
10432: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10433: '<label><input type="radio" name="togglecats"'.
10434: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10435: '</tr><tr>'.
10436: '<td>'.$title{'categorize'}.'</td>'.
10437: '<td class="LC_right_item"><span class="LC_nobreak">'.
10438: '<label><input type="radio" name="categorize"'.
10439: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10440: '<label><input type="radio" name="categorize"'.
10441: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10442: '</tr><tr class="LC_odd_row">'.
10443: '<td>'.$title{'togglecatscomm'}.'</td>'.
10444: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10445: '<input type="radio" name="togglecatscomm"'.
10446: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10447: '<label><input type="radio" name="togglecatscomm"'.
10448: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10449: '</tr><tr>'.
10450: '<td>'.$title{'categorizecomm'}.'</td>'.
10451: '<td class="LC_right_item"><span class="LC_nobreak">'.
10452: '<label><input type="radio" name="categorizecomm"'.
10453: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10454: '<label><input type="radio" name="categorizecomm"'.
10455: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10456: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10457: '<td>'.$title{'togglecatsplace'}.'</td>'.
10458: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10459: '<input type="radio" name="togglecatsplace"'.
10460: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10461: '<label><input type="radio" name="togglecatscomm"'.
10462: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10463: '</tr><tr>'.
10464: '<td>'.$title{'categorizeplace'}.'</td>'.
10465: '<td class="LC_right_item"><span class="LC_nobreak">'.
10466: '<label><input type="radio" name="categorizeplace"'.
10467: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10468: '<label><input type="radio" name="categorizeplace"'.
10469: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10470: '</tr>';
1.272 raeburn 10471: $$rowtotal += 6;
1.57 raeburn 10472: } else {
10473: my $css_class;
10474: my $itemcount = 1;
10475: my $cathash;
10476: if (ref($settings) eq 'HASH') {
10477: $cathash = $settings->{'cats'};
10478: }
10479: if (ref($cathash) eq 'HASH') {
10480: my (@cats,@trails,%allitems,%idx,@jsarray);
10481: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10482: \%allitems,\%idx,\@jsarray);
10483: my $maxdepth = scalar(@cats);
10484: my $colattrib = '';
10485: if ($maxdepth > 2) {
10486: $colattrib = ' colspan="2" ';
10487: }
10488: my @path;
10489: if (@cats > 0) {
10490: if (ref($cats[0]) eq 'ARRAY') {
10491: my $numtop = @{$cats[0]};
10492: my $maxnum = $numtop;
1.120 raeburn 10493: my %default_names = (
10494: instcode => &mt('Official courses'),
10495: communities => &mt('Communities'),
1.272 raeburn 10496: placement => &mt('Placement Tests'),
1.120 raeburn 10497: );
10498:
10499: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10500: ($cathash->{'instcode::0'} eq '') ||
10501: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10502: ($cathash->{'communities::0'} eq '') ||
10503: (!grep(/^placement$/,@{$cats[0]})) ||
10504: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10505: $maxnum ++;
10506: }
10507: my $lastidx;
10508: for (my $i=0; $i<$numtop; $i++) {
10509: my $parent = $cats[0][$i];
10510: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10511: my $item = &escape($parent).'::0';
10512: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10513: $lastidx = $idx{$item};
10514: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10515: .'<select name="'.$item.'"'.$chgstr.'>';
10516: for (my $k=0; $k<=$maxnum; $k++) {
10517: my $vpos = $k+1;
10518: my $selstr;
10519: if ($k == $i) {
10520: $selstr = ' selected="selected" ';
10521: }
10522: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10523: }
1.214 raeburn 10524: $datatable .= '</select></span></td><td>';
1.272 raeburn 10525: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10526: $datatable .= '<span class="LC_nobreak">'
10527: .$default_names{$parent}.'</span>';
10528: if ($parent eq 'instcode') {
10529: $datatable .= '<br /><span class="LC_nobreak">('
10530: .&mt('with institutional codes')
10531: .')</span></td><td'.$colattrib.'>';
10532: } else {
10533: $datatable .= '<table><tr><td>';
10534: }
10535: $datatable .= '<span class="LC_nobreak">'
10536: .'<label><input type="radio" name="'
10537: .$parent.'" value="1" checked="checked" />'
10538: .&mt('Display').'</label>';
10539: if ($parent eq 'instcode') {
10540: $datatable .= ' ';
10541: } else {
10542: $datatable .= '</span></td></tr><tr><td>'
10543: .'<span class="LC_nobreak">';
10544: }
10545: $datatable .= '<label><input type="radio" name="'
10546: .$parent.'" value="0" />'
10547: .&mt('Do not display').'</label></span>';
1.272 raeburn 10548: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10549: $datatable .= '</td></tr></table>';
10550: }
10551: $datatable .= '</td>';
1.57 raeburn 10552: } else {
10553: $datatable .= $parent
1.214 raeburn 10554: .' <span class="LC_nobreak"><label>'
10555: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10556: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10557: }
10558: my $depth = 1;
10559: push(@path,$parent);
10560: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10561: pop(@path);
10562: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10563: $itemcount ++;
10564: }
1.48 raeburn 10565: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10566: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10567: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10568: for (my $k=0; $k<=$maxnum; $k++) {
10569: my $vpos = $k+1;
10570: my $selstr;
1.57 raeburn 10571: if ($k == $numtop) {
1.48 raeburn 10572: $selstr = ' selected="selected" ';
10573: }
10574: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10575: }
1.59 bisitz 10576: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10577: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10578: .'</tr>'."\n";
1.48 raeburn 10579: $itemcount ++;
1.272 raeburn 10580: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10581: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10582: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10583: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10584: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10585: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10586: for (my $k=0; $k<=$maxnum; $k++) {
10587: my $vpos = $k+1;
10588: my $selstr;
10589: if ($k == $maxnum) {
10590: $selstr = ' selected="selected" ';
10591: }
10592: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10593: }
1.120 raeburn 10594: $datatable .= '</select></span></td>'.
10595: '<td><span class="LC_nobreak">'.
10596: $default_names{$default}.'</span>';
10597: if ($default eq 'instcode') {
10598: $datatable .= '<br /><span class="LC_nobreak">('
10599: .&mt('with institutional codes').')</span>';
10600: }
10601: $datatable .= '</td>'
10602: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10603: .&mt('Display').'</label> '
10604: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10605: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10606: }
10607: }
10608: }
1.57 raeburn 10609: } else {
10610: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10611: }
10612: } else {
1.327 raeburn 10613: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10614: .&initialize_categories($itemcount);
1.48 raeburn 10615: }
1.57 raeburn 10616: $$rowtotal += $itemcount;
1.48 raeburn 10617: }
10618: return $datatable;
10619: }
10620:
1.69 raeburn 10621: sub print_serverstatuses {
10622: my ($dom,$settings,$rowtotal) = @_;
10623: my $datatable;
10624: my @pages = &serverstatus_pages();
10625: my (%namedaccess,%machineaccess);
10626: foreach my $type (@pages) {
10627: $namedaccess{$type} = '';
10628: $machineaccess{$type}= '';
10629: }
10630: if (ref($settings) eq 'HASH') {
10631: foreach my $type (@pages) {
10632: if (exists($settings->{$type})) {
10633: if (ref($settings->{$type}) eq 'HASH') {
10634: foreach my $key (keys(%{$settings->{$type}})) {
10635: if ($key eq 'namedusers') {
10636: $namedaccess{$type} = $settings->{$type}->{$key};
10637: } elsif ($key eq 'machines') {
10638: $machineaccess{$type} = $settings->{$type}->{$key};
10639: }
10640: }
10641: }
10642: }
10643: }
10644: }
1.81 raeburn 10645: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10646: my $rownum = 0;
10647: my $css_class;
10648: foreach my $type (@pages) {
10649: $rownum ++;
10650: $css_class = $rownum%2?' class="LC_odd_row"':'';
10651: $datatable .= '<tr'.$css_class.'>'.
10652: '<td><span class="LC_nobreak">'.
10653: $titles->{$type}.'</span></td>'.
10654: '<td class="LC_left_item">'.
10655: '<input type="text" name="'.$type.'_namedusers" '.
10656: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10657: '<td class="LC_right_item">'.
10658: '<span class="LC_nobreak">'.
10659: '<input type="text" name="'.$type.'_machines" '.
10660: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10661: '</span></td></tr>'."\n";
1.69 raeburn 10662: }
10663: $$rowtotal += $rownum;
10664: return $datatable;
10665: }
10666:
10667: sub serverstatus_pages {
10668: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10669: 'checksums','clusterstatus','certstatus','metadata_keywords',
10670: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10671: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10672: }
10673:
1.236 raeburn 10674: sub defaults_javascript {
10675: my ($settings) = @_;
1.354 raeburn 10676: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10677: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10678: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10679: if ($maxnum eq '') {
10680: $maxnum = 0;
10681: }
10682: $maxnum ++;
1.249 raeburn 10683: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10684: return <<"ENDSCRIPT";
10685: <script type="text/javascript">
10686: // <![CDATA[
10687: function reorderTypes(form,caller) {
10688: var changedVal;
10689: $jstext
10690: var newpos = 'addinststatus_pos';
10691: var current = new Array;
10692: var maxh = $maxnum;
10693: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10694: var oldVal;
10695: if (caller == newpos) {
10696: changedVal = newitemVal;
10697: } else {
10698: var curritem = 'inststatus_pos_'+caller;
10699: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10700: current[newitemVal] = newpos;
10701: }
10702: for (var i=0; i<inststatuses.length; i++) {
10703: if (inststatuses[i] != caller) {
10704: var elementName = 'inststatus_pos_'+inststatuses[i];
10705: if (form.elements[elementName]) {
10706: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10707: current[currVal] = elementName;
10708: }
10709: }
10710: }
10711: for (var j=0; j<maxh; j++) {
10712: if (current[j] == undefined) {
10713: oldVal = j;
10714: }
10715: }
10716: if (oldVal < changedVal) {
10717: for (var k=oldVal+1; k<=changedVal ; k++) {
10718: var elementName = current[k];
10719: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10720: }
10721: } else {
10722: for (var k=changedVal; k<oldVal; k++) {
10723: var elementName = current[k];
10724: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10725: }
10726: }
10727: return;
10728: }
10729:
10730: // ]]>
10731: </script>
10732:
10733: ENDSCRIPT
10734: }
1.354 raeburn 10735: return;
10736: }
10737:
10738: sub passwords_javascript {
1.365 raeburn 10739: my %intalert = &Apache::lonlocal::texthash (
10740: 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.',
10741: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10742: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10743: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10744: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10745: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10746: );
10747: &js_escape(\%intalert);
10748: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10749: my $intauthjs = <<"ENDSCRIPT";
10750:
10751: function warnIntAuth(field) {
10752: if (field.name == 'intauth_check') {
10753: if (field.value == '2') {
1.365 raeburn 10754: alert('$intalert{authcheck}');
1.354 raeburn 10755: }
10756: }
10757: if (field.name == 'intauth_cost') {
10758: field.value.replace(/\s/g,'');
10759: if (field.value != '') {
10760: var regexdigit=/^\\d+\$/;
10761: if (!regexdigit.test(field.value)) {
1.365 raeburn 10762: alert('$intalert{authcost}');
10763: }
10764: }
10765: }
10766: return;
10767: }
10768:
10769: function warnIntPass(field) {
10770: field.value.replace(/^\s+/,'');
10771: field.value.replace(/\s+\$/,'');
10772: var regexdigit=/^\\d+\$/;
10773: if (field.name == 'passwords_min') {
10774: if (field.value == '') {
10775: alert('$intalert{passmin}');
10776: field.value = '$defmin';
10777: } else {
10778: if (!regexdigit.test(field.value)) {
10779: alert('$intalert{passmin}');
10780: field.value = '$defmin';
10781: }
1.366 raeburn 10782: var minval = parseInt(field.value,10);
1.365 raeburn 10783: if (minval < $defmin) {
10784: alert('$intalert{passmin}');
10785: field.value = '$defmin';
10786: }
10787: }
10788: } else {
10789: if (field.value == '0') {
10790: field.value = '';
10791: }
10792: if (field.value != '') {
10793: if (field.name == 'passwords_expire') {
10794: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10795: if (!regexpposnum.test(field.value)) {
10796: alert('$intalert{passexp}');
10797: field.value = '';
10798: } else {
10799: var expval = parseFloat(field.value);
10800: if (expval == 0) {
10801: alert('$intalert{passexp}');
10802: field.value = '';
10803: }
10804: }
10805: } else {
10806: if (!regexdigit.test(field.value)) {
10807: if (field.name == 'passwords_max') {
10808: alert('$intalert{passmax}');
10809: } else {
10810: if (field.name == 'passwords_numsaved') {
10811: alert('$intalert{passnum}');
10812: }
10813: }
1.370 raeburn 10814: field.value = '';
1.365 raeburn 10815: }
1.354 raeburn 10816: }
10817: }
10818: }
10819: return;
10820: }
10821:
10822: ENDSCRIPT
10823: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10824: }
10825:
1.49 raeburn 10826: sub coursecategories_javascript {
10827: my ($settings) = @_;
1.57 raeburn 10828: my ($output,$jstext,$cathash);
1.49 raeburn 10829: if (ref($settings) eq 'HASH') {
1.57 raeburn 10830: $cathash = $settings->{'cats'};
10831: }
10832: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10833: my (@cats,@jsarray,%idx);
1.57 raeburn 10834: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10835: if (@jsarray > 0) {
10836: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10837: for (my $i=0; $i<@jsarray; $i++) {
10838: if (ref($jsarray[$i]) eq 'ARRAY') {
10839: my $catstr = join('","',@{$jsarray[$i]});
10840: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10841: }
10842: }
10843: }
10844: } else {
10845: $jstext = ' var categories = Array(1);'."\n".
10846: ' categories[0] = Array("instcode_pos");'."\n";
10847: }
1.237 bisitz 10848: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10849: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10850: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10851: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10852: &js_escape(\$instcode_reserved);
10853: &js_escape(\$communities_reserved);
1.272 raeburn 10854: &js_escape(\$placement_reserved);
1.265 damieng 10855: &js_escape(\$choose_again);
1.49 raeburn 10856: $output = <<"ENDSCRIPT";
10857: <script type="text/javascript">
1.109 raeburn 10858: // <![CDATA[
1.49 raeburn 10859: function reorderCats(form,parent,item,idx) {
10860: var changedVal;
10861: $jstext
10862: var newpos = 'addcategory_pos';
10863: if (parent == '') {
10864: var has_instcode = 0;
10865: var maxtop = categories[idx].length;
10866: for (var j=0; j<maxtop; j++) {
10867: if (categories[idx][j] == 'instcode::0') {
10868: has_instcode == 1;
10869: }
10870: }
10871: if (has_instcode == 0) {
10872: categories[idx][maxtop] = 'instcode_pos';
10873: }
10874: } else {
10875: newpos += '_'+parent;
10876: }
10877: var maxh = 1 + categories[idx].length;
10878: var current = new Array;
10879: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10880: if (item == newpos) {
10881: changedVal = newitemVal;
10882: } else {
10883: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10884: current[newitemVal] = newpos;
10885: }
10886: for (var i=0; i<categories[idx].length; i++) {
10887: var elementName = categories[idx][i];
10888: if (elementName != item) {
10889: if (form.elements[elementName]) {
10890: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10891: current[currVal] = elementName;
10892: }
10893: }
10894: }
10895: var oldVal;
10896: for (var j=0; j<maxh; j++) {
10897: if (current[j] == undefined) {
10898: oldVal = j;
10899: }
10900: }
10901: if (oldVal < changedVal) {
10902: for (var k=oldVal+1; k<=changedVal ; k++) {
10903: var elementName = current[k];
10904: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10905: }
10906: } else {
10907: for (var k=changedVal; k<oldVal; k++) {
10908: var elementName = current[k];
10909: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10910: }
10911: }
10912: return;
10913: }
1.120 raeburn 10914:
10915: function categoryCheck(form) {
10916: if (form.elements['addcategory_name'].value == 'instcode') {
10917: alert('$instcode_reserved\\n$choose_again');
10918: return false;
10919: }
10920: if (form.elements['addcategory_name'].value == 'communities') {
10921: alert('$communities_reserved\\n$choose_again');
10922: return false;
10923: }
1.272 raeburn 10924: if (form.elements['addcategory_name'].value == 'placement') {
10925: alert('$placement_reserved\\n$choose_again');
10926: return false;
10927: }
1.120 raeburn 10928: return true;
10929: }
10930:
1.109 raeburn 10931: // ]]>
1.49 raeburn 10932: </script>
10933:
10934: ENDSCRIPT
10935: return $output;
10936: }
10937:
1.48 raeburn 10938: sub initialize_categories {
10939: my ($itemcount) = @_;
1.120 raeburn 10940: my ($datatable,$css_class,$chgstr);
1.380 raeburn 10941: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10942: instcode => 'Official courses (with institutional codes)',
10943: communities => 'Communities',
1.272 raeburn 10944: placement => 'Placement Tests',
1.120 raeburn 10945: );
1.328 raeburn 10946: my %selnum = (
10947: instcode => '0',
10948: communities => '1',
10949: placement => '2',
10950: );
10951: my %selected;
1.272 raeburn 10952: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10953: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 10954: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 10955: map { $selected{$selnum{$_}} = '' } keys(%selnum);
10956: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 10957: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 10958: .'<select name="'.$default.'_pos"'.$chgstr.'>'
10959: .'<option value="0"'.$selected{'0'}.'>1</option>'
10960: .'<option value="1"'.$selected{'1'}.'>2</option>'
10961: .'<option value="2"'.$selected{'2'}.'>3</option>'
10962: .'<option value="3">4</option></select> '
1.120 raeburn 10963: .$default_names{$default}
10964: .'</span></td><td><span class="LC_nobreak">'
10965: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10966: .&mt('Display').'</label> <label>'
10967: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10968: .'</label></span></td></tr>';
1.120 raeburn 10969: $itemcount ++;
10970: }
1.48 raeburn 10971: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10972: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10973: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10974: .'<select name="addcategory_pos"'.$chgstr.'>'
10975: .'<option value="0">1</option>'
10976: .'<option value="1">2</option>'
1.328 raeburn 10977: .'<option value="2">3</option>'
10978: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 10979: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10980: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10981: .'</td></tr>';
1.48 raeburn 10982: return $datatable;
10983: }
10984:
10985: sub build_category_rows {
1.49 raeburn 10986: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10987: my ($text,$name,$item,$chgstr);
1.48 raeburn 10988: if (ref($cats) eq 'ARRAY') {
10989: my $maxdepth = scalar(@{$cats});
10990: if (ref($cats->[$depth]) eq 'HASH') {
10991: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10992: my $numchildren = @{$cats->[$depth]{$parent}};
10993: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 10994: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10995: my ($idxnum,$parent_name,$parent_item);
10996: my $higher = $depth - 1;
10997: if ($higher == 0) {
10998: $parent_name = &escape($parent).'::'.$higher;
10999: } else {
11000: if (ref($path) eq 'ARRAY') {
11001: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11002: }
11003: }
11004: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11005: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11006: if ($j < $numchildren) {
1.48 raeburn 11007: $name = $cats->[$depth]{$parent}[$j];
11008: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11009: $idxnum = $idx->{$item};
11010: } else {
11011: $name = $parent_name;
11012: $item = $parent_item;
1.48 raeburn 11013: }
1.49 raeburn 11014: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11015: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11016: for (my $i=0; $i<=$numchildren; $i++) {
11017: my $vpos = $i+1;
11018: my $selstr;
11019: if ($j == $i) {
11020: $selstr = ' selected="selected" ';
11021: }
11022: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11023: }
11024: $text .= '</select> ';
11025: if ($j < $numchildren) {
11026: my $deeper = $depth+1;
11027: $text .= $name.' '
11028: .'<label><input type="checkbox" name="deletecategory" value="'
11029: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11030: if(ref($path) eq 'ARRAY') {
11031: push(@{$path},$name);
1.49 raeburn 11032: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11033: pop(@{$path});
11034: }
11035: } else {
1.330 raeburn 11036: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11037: if ($j == $numchildren) {
11038: $text .= $name;
11039: } else {
11040: $text .= $item;
11041: }
11042: $text .= '" value="" />';
11043: }
11044: $text .= '</td></tr>';
11045: }
11046: $text .= '</table></td>';
11047: } else {
11048: my $higher = $depth-1;
11049: if ($higher == 0) {
11050: $name = &escape($parent).'::'.$higher;
11051: } else {
11052: if (ref($path) eq 'ARRAY') {
11053: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11054: }
11055: }
11056: my $colspan;
11057: if ($parent ne 'instcode') {
11058: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11059: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11060: }
11061: }
11062: }
11063: }
11064: return $text;
11065: }
11066:
1.33 raeburn 11067: sub modifiable_userdata_row {
1.305 raeburn 11068: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11069: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11070: my ($role,$rolename,$statustype);
11071: $role = $item;
1.224 raeburn 11072: if ($context eq 'cancreate') {
1.305 raeburn 11073: if ($item =~ /^(emailusername)_(.+)$/) {
11074: $role = $1;
11075: $statustype = $2;
1.228 raeburn 11076: if (ref($usertypes) eq 'HASH') {
11077: if ($usertypes->{$statustype}) {
11078: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11079: } else {
11080: $rolename = &mt('Data provided by user');
11081: }
11082: }
1.224 raeburn 11083: }
11084: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11085: if (ref($usertypes) eq 'HASH') {
11086: $rolename = $usertypes->{$role};
11087: } else {
11088: $rolename = $role;
11089: }
1.325 raeburn 11090: } elsif ($context eq 'lti') {
11091: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11092: } elsif ($context eq 'privacy') {
11093: $rolename = $itemdesc;
1.33 raeburn 11094: } else {
1.63 raeburn 11095: if ($role eq 'cr') {
11096: $rolename = &mt('Custom role');
11097: } else {
11098: $rolename = &Apache::lonnet::plaintext($role);
11099: }
1.33 raeburn 11100: }
1.224 raeburn 11101: my (@fields,%fieldtitles);
11102: if (ref($fieldsref) eq 'ARRAY') {
11103: @fields = @{$fieldsref};
11104: } else {
11105: @fields = ('lastname','firstname','middlename','generation',
11106: 'permanentemail','id');
11107: }
11108: if ((ref($titlesref) eq 'HASH')) {
11109: %fieldtitles = %{$titlesref};
11110: } else {
11111: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11112: }
1.33 raeburn 11113: my $output;
1.305 raeburn 11114: my $css_class;
11115: if ($rowcount%2) {
11116: $css_class = 'LC_odd_row';
11117: }
11118: if ($customcss) {
11119: $css_class .= " $customcss";
11120: }
11121: $css_class =~ s/^\s+//;
11122: if ($css_class) {
11123: $css_class = ' class="'.$css_class.'"';
11124: }
11125: if ($rowstyle) {
11126: $css_class .= ' style="'.$rowstyle.'"';
11127: }
11128: if ($rowid) {
11129: $rowid = ' id="'.$rowid.'"';
11130: }
11131: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11132: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11133: '<td class="LC_left_item" colspan="2"><table>';
11134: my $rem;
11135: my %checks;
1.325 raeburn 11136: my %current;
1.33 raeburn 11137: if (ref($settings) eq 'HASH') {
1.325 raeburn 11138: my $hashref;
11139: if ($context eq 'lti') {
11140: if (ref($settings) eq 'HASH') {
11141: $hashref = $settings->{'instdata'};
11142: }
1.357 raeburn 11143: } elsif ($context eq 'privacy') {
11144: my ($key,$inner) = split(/_/,$role);
11145: if (ref($settings) eq 'HASH') {
11146: if (ref($settings->{$key}) eq 'HASH') {
11147: $hashref = $settings->{$key}->{$inner};
11148: }
11149: }
1.325 raeburn 11150: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11151: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11152: $hashref = $settings->{'lti_instdata'};
11153: }
11154: if ($role eq 'emailusername') {
11155: if ($statustype) {
11156: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11157: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11158: }
1.325 raeburn 11159: }
11160: }
11161: }
11162: if (ref($hashref) eq 'HASH') {
11163: foreach my $field (@fields) {
11164: if ($hashref->{$field}) {
11165: if ($role eq 'emailusername') {
11166: $checks{$field} = $hashref->{$field};
11167: } else {
11168: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11169: }
11170: }
11171: }
11172: }
11173: }
1.305 raeburn 11174:
11175: my $total = scalar(@fields);
11176: for (my $i=0; $i<$total; $i++) {
11177: $rem = $i%($numinrow);
1.33 raeburn 11178: if ($rem == 0) {
11179: if ($i > 0) {
11180: $output .= '</tr>';
11181: }
11182: $output .= '<tr>';
11183: }
11184: my $check = ' ';
1.228 raeburn 11185: unless ($role eq 'emailusername') {
11186: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11187: $check = $checks{$fields[$i]};
1.357 raeburn 11188: } elsif ($context eq 'privacy') {
11189: if ($role =~ /^priv_(domain|course)$/) {
11190: if (ref($settings) ne 'HASH') {
11191: $check = ' checked="checked" ';
11192: }
11193: } elsif ($role =~ /^priv_(author|community)$/) {
11194: if (ref($settings) ne 'HASH') {
11195: unless ($fields[$i] eq 'id') {
11196: $check = ' checked="checked" ';
11197: }
11198: }
11199: } elsif ($role =~ /^(unpriv|othdom)_/) {
11200: if (ref($settings) ne 'HASH') {
11201: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11202: $check = ' checked="checked" ';
11203: }
11204: }
11205: }
1.325 raeburn 11206: } elsif ($context ne 'lti') {
1.228 raeburn 11207: if ($role eq 'st') {
11208: if (ref($settings) ne 'HASH') {
11209: $check = ' checked="checked" ';
11210: }
1.33 raeburn 11211: }
11212: }
11213: }
11214: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11215: '<span class="LC_nobreak">';
1.325 raeburn 11216: my $prefix = 'canmodify';
1.228 raeburn 11217: if ($role eq 'emailusername') {
11218: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11219: $checks{$fields[$i]} = 'omit';
11220: }
11221: foreach my $option ('required','optional','omit') {
11222: my $checked='';
11223: if ($checks{$fields[$i]} eq $option) {
11224: $checked='checked="checked" ';
11225: }
11226: $output .= '<label>'.
1.325 raeburn 11227: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11228: &mt($option).'</label>'.(' ' x2);
11229: }
11230: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11231: } else {
1.325 raeburn 11232: if ($context eq 'lti') {
11233: $prefix = 'lti';
1.357 raeburn 11234: } elsif ($context eq 'privacy') {
11235: $prefix = 'privacy';
1.325 raeburn 11236: }
1.228 raeburn 11237: $output .= '<label>'.
1.325 raeburn 11238: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11239: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11240: '</label>';
11241: }
11242: $output .= '</span></td>';
1.33 raeburn 11243: }
1.305 raeburn 11244: $rem = $total%$numinrow;
11245: my $colsleft;
11246: if ($rem) {
11247: $colsleft = $numinrow - $rem;
11248: }
11249: if ($colsleft > 1) {
1.33 raeburn 11250: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11251: ' </td>';
11252: } elsif ($colsleft == 1) {
11253: $output .= '<td class="LC_left_item"> </td>';
11254: }
11255: $output .= '</tr></table></td></tr>';
11256: return $output;
11257: }
1.28 raeburn 11258:
1.93 raeburn 11259: sub insttypes_row {
1.305 raeburn 11260: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11261: $customcss,$rowstyle) = @_;
1.93 raeburn 11262: my %lt = &Apache::lonlocal::texthash (
11263: cansearch => 'Users allowed to search',
11264: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11265: lockablenames => 'User preference to lock name',
1.305 raeburn 11266: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11267: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11268: );
11269: my $showdom;
11270: if ($context eq 'cansearch') {
11271: $showdom = ' ('.$dom.')';
11272: }
1.165 raeburn 11273: my $class = 'LC_left_item';
11274: if ($context eq 'statustocreate') {
11275: $class = 'LC_right_item';
11276: }
1.305 raeburn 11277: my $css_class;
11278: if ($$rowtotal%2) {
11279: $css_class = 'LC_odd_row';
11280: }
11281: if ($customcss) {
11282: $css_class .= ' '.$customcss;
11283: }
11284: $css_class =~ s/^\s+//;
11285: if ($css_class) {
11286: $css_class = ' class="'.$css_class.'"';
11287: }
11288: if ($rowstyle) {
11289: $css_class .= ' style="'.$rowstyle.'"';
11290: }
11291: if ($onclick) {
11292: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11293: }
11294: my $output = '<tr'.$css_class.'>'.
11295: '<td>'.$lt{$context}.$showdom.
11296: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11297: my $rem;
11298: if (ref($types) eq 'ARRAY') {
11299: for (my $i=0; $i<@{$types}; $i++) {
11300: if (defined($usertypes->{$types->[$i]})) {
11301: my $rem = $i%($numinrow);
11302: if ($rem == 0) {
11303: if ($i > 0) {
11304: $output .= '</tr>';
11305: }
11306: $output .= '<tr>';
1.23 raeburn 11307: }
1.26 raeburn 11308: my $check = ' ';
1.99 raeburn 11309: if (ref($settings) eq 'HASH') {
11310: if (ref($settings->{$context}) eq 'ARRAY') {
11311: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11312: $check = ' checked="checked" ';
11313: }
1.315 raeburn 11314: } elsif (ref($settings->{$context}) eq 'HASH') {
11315: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11316: $check = ' checked="checked" ';
11317: }
1.99 raeburn 11318: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11319: $check = ' checked="checked" ';
11320: }
1.23 raeburn 11321: }
1.26 raeburn 11322: $output .= '<td class="LC_left_item">'.
11323: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11324: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11325: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11326: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11327: }
11328: }
1.26 raeburn 11329: $rem = @{$types}%($numinrow);
1.23 raeburn 11330: }
11331: my $colsleft = $numinrow - $rem;
1.315 raeburn 11332: if ($context eq 'overrides') {
11333: if ($colsleft > 1) {
11334: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11335: } else {
11336: $output .= '<td class="LC_left_item">';
11337: }
11338: $output .= ' ';
1.23 raeburn 11339: } else {
1.334 raeburn 11340: if ($rem == 0) {
1.315 raeburn 11341: $output .= '<tr>';
11342: }
11343: if ($colsleft > 1) {
11344: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11345: } else {
11346: $output .= '<td class="LC_left_item">';
11347: }
11348: my $defcheck = ' ';
11349: if (ref($settings) eq 'HASH') {
11350: if (ref($settings->{$context}) eq 'ARRAY') {
11351: if (grep(/^default$/,@{$settings->{$context}})) {
11352: $defcheck = ' checked="checked" ';
11353: }
11354: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11355: $defcheck = ' checked="checked" ';
11356: }
1.26 raeburn 11357: }
1.315 raeburn 11358: $output .= '<span class="LC_nobreak"><label>'.
11359: '<input type="checkbox" name="'.$context.'" '.
11360: 'value="default"'.$defcheck.$onclick.' />'.
11361: $othertitle.'</label></span>';
1.23 raeburn 11362: }
1.315 raeburn 11363: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11364: return $output;
1.23 raeburn 11365: }
11366:
11367: sub sorted_searchtitles {
11368: my %searchtitles = &Apache::lonlocal::texthash(
11369: 'uname' => 'username',
11370: 'lastname' => 'last name',
11371: 'lastfirst' => 'last name, first name',
11372: );
11373: my @titleorder = ('uname','lastname','lastfirst');
11374: return (\%searchtitles,\@titleorder);
11375: }
11376:
1.25 raeburn 11377: sub sorted_searchtypes {
11378: my %srchtypes_desc = (
11379: exact => 'is exact match',
11380: contains => 'contains ..',
11381: begins => 'begins with ..',
11382: );
11383: my @srchtypeorder = ('exact','begins','contains');
11384: return (\%srchtypes_desc,\@srchtypeorder);
11385: }
11386:
1.3 raeburn 11387: sub usertype_update_row {
11388: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11389: my $datatable;
11390: my $numinrow = 4;
11391: foreach my $type (@{$types}) {
11392: if (defined($usertypes->{$type})) {
11393: $$rownums ++;
11394: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11395: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11396: '</td><td class="LC_left_item"><table>';
11397: for (my $i=0; $i<@{$fields}; $i++) {
11398: my $rem = $i%($numinrow);
11399: if ($rem == 0) {
11400: if ($i > 0) {
11401: $datatable .= '</tr>';
11402: }
11403: $datatable .= '<tr>';
11404: }
11405: my $check = ' ';
1.39 raeburn 11406: if (ref($settings) eq 'HASH') {
11407: if (ref($settings->{'fields'}) eq 'HASH') {
11408: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11409: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11410: $check = ' checked="checked" ';
11411: }
1.3 raeburn 11412: }
11413: }
11414: }
11415:
11416: if ($i == @{$fields}-1) {
11417: my $colsleft = $numinrow - $rem;
11418: if ($colsleft > 1) {
11419: $datatable .= '<td colspan="'.$colsleft.'">';
11420: } else {
11421: $datatable .= '<td>';
11422: }
11423: } else {
11424: $datatable .= '<td>';
11425: }
1.8 raeburn 11426: $datatable .= '<span class="LC_nobreak"><label>'.
11427: '<input type="checkbox" name="updateable_'.$type.
11428: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11429: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11430: }
11431: $datatable .= '</tr></table></td></tr>';
11432: }
11433: }
11434: return $datatable;
1.1 raeburn 11435: }
11436:
11437: sub modify_login {
1.205 raeburn 11438: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11439: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11440: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
11441: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168 raeburn 11442: %title = ( coursecatalog => 'Display course catalog',
11443: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11444: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11445: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11446: loginheader => 'Log-in box header',
11447: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11448: @offon = ('off','on');
1.112 raeburn 11449: if (ref($domconfig{login}) eq 'HASH') {
11450: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11451: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11452: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11453: }
11454: }
1.386 raeburn 11455: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11456: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11457: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11458: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11459: $saml{$lonhost} = 1;
11460: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11461: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11462: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11463: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11464: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
11465: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11466: }
11467: }
11468: }
1.112 raeburn 11469: }
1.9 raeburn 11470: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11471: \%domconfig,\%loginhash);
1.188 raeburn 11472: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11473: foreach my $item (@toggles) {
11474: $loginhash{login}{$item} = $env{'form.'.$item};
11475: }
1.41 raeburn 11476: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11477: if (ref($colchanges{'login'}) eq 'HASH') {
11478: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11479: \%loginhash);
11480: }
1.110 raeburn 11481:
1.149 raeburn 11482: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11483: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11484: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11485: if (keys(%servers) > 1) {
11486: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11487: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11488: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11489: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11490: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11491: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11492: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11493: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11494: $changes{'loginvia'}{$lonhost} = 1;
11495: } else {
11496: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11497: $changes{'loginvia'}{$lonhost} = 1;
11498: }
11499: } else {
11500: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11501: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11502: $changes{'loginvia'}{$lonhost} = 1;
11503: }
11504: }
11505: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11506: foreach my $item (@loginvia_attribs) {
11507: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11508: }
11509: } else {
11510: foreach my $item (@loginvia_attribs) {
11511: my $new = $env{'form.'.$lonhost.'_'.$item};
11512: if (($item eq 'serverpath') && ($new eq 'custom')) {
11513: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11514: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11515: $new = '/';
11516: }
11517: }
11518: if (($item eq 'custompath') &&
11519: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11520: $new = '';
11521: }
11522: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11523: $changes{'loginvia'}{$lonhost} = 1;
11524: }
11525: if ($item eq 'exempt') {
1.256 raeburn 11526: $new = &check_exempt_addresses($new);
1.128 raeburn 11527: }
11528: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11529: }
11530: }
1.112 raeburn 11531: } else {
1.128 raeburn 11532: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11533: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11534: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11535: foreach my $item (@loginvia_attribs) {
11536: my $new = $env{'form.'.$lonhost.'_'.$item};
11537: if (($item eq 'serverpath') && ($new eq 'custom')) {
11538: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11539: $new = '/';
11540: }
11541: }
11542: if (($item eq 'custompath') &&
11543: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11544: $new = '';
11545: }
11546: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11547: }
1.110 raeburn 11548: }
11549: }
11550: }
11551: }
1.119 raeburn 11552:
1.168 raeburn 11553: my $servadm = $r->dir_config('lonAdmEMail');
11554: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11555: if (ref($domconfig{'login'}) eq 'HASH') {
11556: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11557: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11558: if ($lang eq 'nolang') {
11559: push(@currlangs,$lang);
11560: } elsif (defined($langchoices{$lang})) {
11561: push(@currlangs,$lang);
11562: } else {
11563: next;
11564: }
11565: }
11566: }
11567: }
11568: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11569: if (@currlangs > 0) {
11570: foreach my $lang (@currlangs) {
11571: if (grep(/^\Q$lang\E$/,@delurls)) {
11572: $changes{'helpurl'}{$lang} = 1;
11573: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11574: $changes{'helpurl'}{$lang} = 1;
11575: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11576: push(@newlangs,$lang);
11577: } else {
11578: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11579: }
11580: }
11581: }
11582: unless (grep(/^nolang$/,@currlangs)) {
11583: if ($env{'form.loginhelpurl_nolang.filename'}) {
11584: $changes{'helpurl'}{'nolang'} = 1;
11585: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11586: push(@newlangs,'nolang');
11587: }
11588: }
11589: if ($env{'form.loginhelpurl_add_lang'}) {
11590: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11591: ($env{'form.loginhelpurl_add_file.filename'})) {
11592: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11593: $addedfile = $env{'form.loginhelpurl_add_lang'};
11594: }
11595: }
11596: if ((@newlangs > 0) || ($addedfile)) {
11597: my $error;
11598: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11599: if ($configuserok eq 'ok') {
11600: if ($switchserver) {
11601: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11602: } elsif ($author_ok eq 'ok') {
11603: my @allnew = @newlangs;
11604: if ($addedfile ne '') {
11605: push(@allnew,$addedfile);
11606: }
11607: foreach my $lang (@allnew) {
11608: my $formelem = 'loginhelpurl_'.$lang;
11609: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11610: $formelem = 'loginhelpurl_add_file';
11611: }
11612: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11613: "help/$lang",'','',$newfile{$lang});
11614: if ($result eq 'ok') {
11615: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11616: $changes{'helpurl'}{$lang} = 1;
11617: } else {
11618: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11619: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11620: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11621: (!grep(/^\Q$lang\E$/,@delurls))) {
11622: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11623: }
11624: }
11625: }
11626: } else {
11627: $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);
11628: }
11629: } else {
11630: $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);
11631: }
11632: if ($error) {
11633: &Apache::lonnet::logthis($error);
11634: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11635: }
11636: }
1.256 raeburn 11637:
11638: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11639: if (ref($domconfig{'login'}) eq 'HASH') {
11640: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11641: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11642: if ($domservers{$lonhost}) {
11643: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11644: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11645: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11646: }
11647: }
11648: }
11649: }
11650: }
11651: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11652: foreach my $lonhost (sort(keys(%domservers))) {
11653: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11654: $changes{'headtag'}{$lonhost} = 1;
11655: } else {
11656: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11657: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11658: }
11659: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11660: push(@newhosts,$lonhost);
11661: } elsif ($currheadtagurls{$lonhost}) {
11662: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11663: if ($currexempt{$lonhost}) {
1.289 raeburn 11664: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11665: $changes{'headtag'}{$lonhost} = 1;
11666: }
11667: } elsif ($possexempt{$lonhost}) {
11668: $changes{'headtag'}{$lonhost} = 1;
11669: }
11670: if ($possexempt{$lonhost}) {
11671: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11672: }
11673: }
11674: }
11675: }
11676: if (@newhosts) {
11677: my $error;
11678: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11679: if ($configuserok eq 'ok') {
11680: if ($switchserver) {
11681: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11682: } elsif ($author_ok eq 'ok') {
11683: foreach my $lonhost (@newhosts) {
11684: my $formelem = 'loginheadtag_'.$lonhost;
11685: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11686: "login/headtag/$lonhost",'','',
11687: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11688: if ($result eq 'ok') {
11689: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11690: $changes{'headtag'}{$lonhost} = 1;
11691: if ($possexempt{$lonhost}) {
11692: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11693: }
11694: } else {
11695: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11696: $newheadtagurls{$lonhost},$result);
11697: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11698: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11699: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11700: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11701: }
11702: }
11703: }
11704: } else {
11705: $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);
11706: }
11707: } else {
11708: $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);
11709: }
11710: if ($error) {
11711: &Apache::lonnet::logthis($error);
11712: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11713: }
11714: }
1.386 raeburn 11715: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11716: my @newsamlimgs;
11717: foreach my $lonhost (keys(%domservers)) {
11718: if ($env{'form.saml_'.$lonhost}) {
11719: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11720: push(@newsamlimgs,$lonhost);
11721: }
11722: foreach my $item ('text','alt','url','title','notsso') {
11723: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11724: }
11725: if ($saml{$lonhost}) {
11726: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11727: #FIXME Need to obsolete published image
11728: delete($currsaml{$lonhost}{'img'});
11729: $changes{'saml'}{$lonhost} = 1;
11730: }
11731: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11732: $changes{'saml'}{$lonhost} = 1;
11733: }
11734: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11735: $changes{'saml'}{$lonhost} = 1;
11736: }
11737: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11738: $changes{'saml'}{$lonhost} = 1;
11739: }
11740: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11741: $changes{'saml'}{$lonhost} = 1;
11742: }
11743: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11744: $changes{'saml'}{$lonhost} = 1;
11745: }
11746: } else {
11747: $changes{'saml'}{$lonhost} = 1;
11748: }
11749: foreach my $item ('text','alt','url','title','notsso') {
11750: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11751: }
11752: } else {
1.389 raeburn 11753: if ($saml{$lonhost}) {
11754: $changes{'saml'}{$lonhost} = 1;
11755: delete($currsaml{$lonhost});
11756: }
1.386 raeburn 11757: }
11758: }
11759: foreach my $posshost (keys(%currsaml)) {
11760: unless (exists($domservers{$posshost})) {
11761: delete($currsaml{$posshost});
11762: }
11763: }
11764: %{$loginhash{'login'}{'saml'}} = %currsaml;
11765: if (@newsamlimgs) {
11766: my $error;
11767: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11768: if ($configuserok eq 'ok') {
11769: if ($switchserver) {
11770: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11771: } elsif ($author_ok eq 'ok') {
11772: foreach my $lonhost (@newsamlimgs) {
11773: my $formelem = 'saml_img_'.$lonhost;
11774: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11775: "login/saml/$lonhost",'','',
11776: $env{'form.saml_img_'.$lonhost.'.filename'});
11777: if ($result eq 'ok') {
11778: $currsaml{$lonhost}{'img'} = $imgurl;
11779: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11780: $changes{'saml'}{$lonhost} = 1;
11781: } else {
11782: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11783: $lonhost,$result);
11784: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11785: }
11786: }
11787: } else {
11788: $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);
11789: }
11790: } else {
11791: $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);
11792: }
11793: if ($error) {
11794: &Apache::lonnet::logthis($error);
11795: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11796: }
11797: }
1.169 raeburn 11798: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11799:
11800: my $defaulthelpfile = '/adm/loginproblems.html';
11801: my $defaulttext = &mt('Default in use');
11802:
1.1 raeburn 11803: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11804: $dom);
11805: if ($putresult eq 'ok') {
1.188 raeburn 11806: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11807: my %defaultchecked = (
11808: 'coursecatalog' => 'on',
1.188 raeburn 11809: 'helpdesk' => 'on',
1.42 raeburn 11810: 'adminmail' => 'off',
1.43 raeburn 11811: 'newuser' => 'off',
1.42 raeburn 11812: );
1.55 raeburn 11813: if (ref($domconfig{'login'}) eq 'HASH') {
11814: foreach my $item (@toggles) {
11815: if ($defaultchecked{$item} eq 'on') {
11816: if (($domconfig{'login'}{$item} eq '0') &&
11817: ($env{'form.'.$item} eq '1')) {
11818: $changes{$item} = 1;
11819: } elsif (($domconfig{'login'}{$item} eq '' ||
11820: $domconfig{'login'}{$item} eq '1') &&
11821: ($env{'form.'.$item} eq '0')) {
11822: $changes{$item} = 1;
11823: }
11824: } elsif ($defaultchecked{$item} eq 'off') {
11825: if (($domconfig{'login'}{$item} eq '1') &&
11826: ($env{'form.'.$item} eq '0')) {
11827: $changes{$item} = 1;
11828: } elsif (($domconfig{'login'}{$item} eq '' ||
11829: $domconfig{'login'}{$item} eq '0') &&
11830: ($env{'form.'.$item} eq '1')) {
11831: $changes{$item} = 1;
11832: }
1.42 raeburn 11833: }
11834: }
1.41 raeburn 11835: }
1.6 raeburn 11836: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11837: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 11838: if (exists($changes{'saml'})) {
11839: my $hostid_in_use;
11840: my @hosts = &Apache::lonnet::current_machine_ids();
11841: if (@hosts > 1) {
11842: foreach my $hostid (@hosts) {
11843: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11844: $hostid_in_use = $hostid;
11845: last;
11846: }
11847: }
11848: } else {
11849: $hostid_in_use = $r->dir_config('lonHostID');
11850: }
11851: if (($hostid_in_use) &&
11852: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 11853: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 11854: }
11855: if (ref($lastactref) eq 'HASH') {
11856: if (ref($changes{'saml'}) eq 'HASH') {
11857: my %updates;
11858: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11859: $lastactref->{'samllanding'} = \%updates;
11860: }
11861: }
11862: }
1.212 raeburn 11863: if (ref($lastactref) eq 'HASH') {
11864: $lastactref->{'domainconfig'} = 1;
11865: }
1.1 raeburn 11866: $resulttext = &mt('Changes made:').'<ul>';
11867: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11868: if ($item eq 'loginvia') {
1.112 raeburn 11869: if (ref($changes{$item}) eq 'HASH') {
11870: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11871: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11872: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11873: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11874: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11875: $protocol = 'http' if ($protocol ne 'https');
11876: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11877:
11878: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11879: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11880: } else {
11881: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11882: }
11883: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11884: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11885: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11886: }
11887: $resulttext .= '</li>';
11888: } else {
11889: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11890: }
1.112 raeburn 11891: } else {
1.128 raeburn 11892: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11893: }
11894: }
1.128 raeburn 11895: $resulttext .= '</ul></li>';
1.112 raeburn 11896: }
1.168 raeburn 11897: } elsif ($item eq 'helpurl') {
11898: if (ref($changes{$item}) eq 'HASH') {
11899: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11900: if (grep(/^\Q$lang\E$/,@delurls)) {
11901: my ($chg,$link);
11902: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11903: if ($lang eq 'nolang') {
11904: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11905: } else {
11906: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11907: }
11908: $resulttext .= '<li>'.$chg.'</li>';
11909: } else {
11910: my $chg;
11911: if ($lang eq 'nolang') {
11912: $chg = &mt('custom log-in help file for no preferred language');
11913: } else {
11914: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11915: }
11916: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11917: $loginhash{'login'}{'helpurl'}{$lang}.
11918: '?inhibitmenu=yes',$chg,600,500).
11919: '</li>';
11920: }
11921: }
11922: }
1.256 raeburn 11923: } elsif ($item eq 'headtag') {
11924: if (ref($changes{$item}) eq 'HASH') {
11925: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11926: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11927: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11928: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11929: $resulttext .= '<li><a href="'.
11930: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11931: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11932: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11933: if ($possexempt{$lonhost}) {
11934: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11935: } else {
11936: $resulttext .= &mt('included for any client IP');
11937: }
11938: $resulttext .= '</li>';
11939: }
11940: }
11941: }
1.386 raeburn 11942: } elsif ($item eq 'saml') {
11943: if (ref($changes{$item}) eq 'HASH') {
11944: my %notlt = (
11945: text => 'Text for log-in by SSO',
11946: img => 'SSO button image',
11947: alt => 'Alt text for button image',
11948: url => 'SSO URL',
11949: title => 'Tooltip for SSO link',
11950: notsso => 'Text for non-SSO log-in',
11951: );
11952: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11953: if (ref($currsaml{$lonhost}) eq 'HASH') {
11954: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11955: '<ul>';
11956: foreach my $key ('text','img','alt','url','title','notsso') {
11957: if ($currsaml{$lonhost}{$key} eq '') {
11958: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11959: } else {
11960: my $value = "'$currsaml{$lonhost}{$key}'";
11961: if ($key eq 'img') {
11962: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
11963: }
11964: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11965: $value).'</li>';
11966: }
11967: }
11968: $resulttext .= '</ul></li>';
11969: } else {
11970: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11971: }
11972: }
11973: }
1.169 raeburn 11974: } elsif ($item eq 'captcha') {
11975: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 11976: my $chgtxt;
1.169 raeburn 11977: if ($loginhash{'login'}{$item} eq 'notused') {
11978: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11979: } else {
11980: my %captchas = &captcha_phrases();
11981: if ($captchas{$loginhash{'login'}{$item}}) {
11982: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11983: } else {
11984: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11985: }
11986: }
11987: $resulttext .= '<li>'.$chgtxt.'</li>';
11988: }
11989: } elsif ($item eq 'recaptchakeys') {
11990: if (ref($loginhash{'login'}) eq 'HASH') {
11991: my ($privkey,$pubkey);
11992: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11993: $pubkey = $loginhash{'login'}{$item}{'public'};
11994: $privkey = $loginhash{'login'}{$item}{'private'};
11995: }
11996: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11997: if (!$pubkey) {
11998: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11999: } else {
12000: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12001: }
12002: if (!$privkey) {
12003: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12004: } else {
1.251 raeburn 12005: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12006: }
12007: $chgtxt .= '</ul>';
12008: $resulttext .= '<li>'.$chgtxt.'</li>';
12009: }
1.269 raeburn 12010: } elsif ($item eq 'recaptchaversion') {
12011: if (ref($loginhash{'login'}) eq 'HASH') {
12012: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12013: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12014: '</li>';
12015: }
12016: }
1.41 raeburn 12017: } else {
12018: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12019: }
1.1 raeburn 12020: }
1.6 raeburn 12021: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12022: } else {
12023: $resulttext = &mt('No changes made to log-in page settings');
12024: }
12025: } else {
1.11 albertel 12026: $resulttext = '<span class="LC_error">'.
12027: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12028: }
1.6 raeburn 12029: if ($errors) {
1.9 raeburn 12030: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12031: $errors.'</ul>';
12032: }
12033: return $resulttext;
12034: }
12035:
1.256 raeburn 12036: sub check_exempt_addresses {
12037: my ($iplist) = @_;
12038: $iplist =~ s/^\s+//;
12039: $iplist =~ s/\s+$//;
12040: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12041: my (@okips,$new);
12042: foreach my $ip (@poss_ips) {
12043: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12044: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12045: push(@okips,$ip);
12046: }
12047: }
12048: }
12049: if (@okips > 0) {
12050: $new = join(',',@okips);
12051: } else {
12052: $new = '';
12053: }
12054: return $new;
12055: }
12056:
1.6 raeburn 12057: sub color_font_choices {
12058: my %choices =
12059: &Apache::lonlocal::texthash (
12060: img => "Header",
12061: bgs => "Background colors",
12062: links => "Link colors",
1.55 raeburn 12063: images => "Images",
1.6 raeburn 12064: font => "Font color",
1.201 raeburn 12065: fontmenu => "Font menu",
1.76 raeburn 12066: pgbg => "Page",
1.6 raeburn 12067: tabbg => "Header",
12068: sidebg => "Border",
12069: link => "Link",
12070: alink => "Active link",
12071: vlink => "Visited link",
12072: );
12073: return %choices;
12074: }
12075:
12076: sub modify_rolecolors {
1.205 raeburn 12077: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12078: my ($resulttext,%rolehash);
12079: $rolehash{'rolecolors'} = {};
1.55 raeburn 12080: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12081: if ($domconfig{'rolecolors'} eq '') {
12082: $domconfig{'rolecolors'} = {};
12083: }
12084: }
1.9 raeburn 12085: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12086: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12087: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12088: $dom);
12089: if ($putresult eq 'ok') {
12090: if (keys(%changes) > 0) {
1.41 raeburn 12091: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12092: if (ref($lastactref) eq 'HASH') {
12093: $lastactref->{'domainconfig'} = 1;
12094: }
1.6 raeburn 12095: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12096: $rolehash{'rolecolors'});
12097: } else {
12098: $resulttext = &mt('No changes made to default color schemes');
12099: }
12100: } else {
1.11 albertel 12101: $resulttext = '<span class="LC_error">'.
12102: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12103: }
12104: if ($errors) {
12105: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12106: $errors.'</ul>';
12107: }
12108: return $resulttext;
12109: }
12110:
12111: sub modify_colors {
1.9 raeburn 12112: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12113: my (%changes,%choices);
1.51 raeburn 12114: my @bgs;
1.6 raeburn 12115: my @links = ('link','alink','vlink');
1.41 raeburn 12116: my @logintext;
1.6 raeburn 12117: my @images;
12118: my $servadm = $r->dir_config('lonAdmEMail');
12119: my $errors;
1.200 raeburn 12120: my %defaults;
1.6 raeburn 12121: foreach my $role (@{$roles}) {
12122: if ($role eq 'login') {
1.12 raeburn 12123: %choices = &login_choices();
1.41 raeburn 12124: @logintext = ('textcol','bgcol');
1.12 raeburn 12125: } else {
12126: %choices = &color_font_choices();
12127: }
12128: if ($role eq 'login') {
1.41 raeburn 12129: @images = ('img','logo','domlogo','login');
1.51 raeburn 12130: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12131: } else {
12132: @images = ('img');
1.200 raeburn 12133: @bgs = ('pgbg','tabbg','sidebg');
12134: }
12135: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12136: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12137: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12138: }
12139: if ($role eq 'login') {
12140: foreach my $item (@logintext) {
1.234 raeburn 12141: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12142: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12143: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12144: }
12145: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12146: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12147: }
12148: }
12149: } else {
1.234 raeburn 12150: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12151: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12152: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12153: }
12154: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12155: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12156: }
1.6 raeburn 12157: }
1.200 raeburn 12158: foreach my $item (@bgs) {
1.234 raeburn 12159: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12160: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12161: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12162: }
12163: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12164: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12165: }
12166: }
12167: foreach my $item (@links) {
1.234 raeburn 12168: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12169: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12170: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12171: }
12172: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12173: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12174: }
1.6 raeburn 12175: }
1.46 raeburn 12176: my ($configuserok,$author_ok,$switchserver) =
12177: &config_check($dom,$confname,$servadm);
1.9 raeburn 12178: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12179: if (ref($domconfig->{$role}) ne 'HASH') {
12180: $domconfig->{$role} = {};
12181: }
1.8 raeburn 12182: foreach my $img (@images) {
1.70 raeburn 12183: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
12184: if (defined($env{'form.login_showlogo_'.$img})) {
12185: $confhash->{$role}{'showlogo'}{$img} = 1;
12186: } else {
12187: $confhash->{$role}{'showlogo'}{$img} = 0;
12188: }
12189: }
1.18 albertel 12190: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12191: && !defined($domconfig->{$role}{$img})
12192: && !$env{'form.'.$role.'_del_'.$img}
12193: && $env{'form.'.$role.'_import_'.$img}) {
12194: # import the old configured image from the .tab setting
12195: # if they haven't provided a new one
12196: $domconfig->{$role}{$img} =
12197: $env{'form.'.$role.'_import_'.$img};
12198: }
1.6 raeburn 12199: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12200: my $error;
1.6 raeburn 12201: if ($configuserok eq 'ok') {
1.9 raeburn 12202: if ($switchserver) {
1.12 raeburn 12203: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12204: } else {
12205: if ($author_ok eq 'ok') {
12206: my ($result,$logourl) =
12207: &publishlogo($r,'upload',$role.'_'.$img,
12208: $dom,$confname,$img,$width,$height);
12209: if ($result eq 'ok') {
12210: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12211: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12212: } else {
1.12 raeburn 12213: $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 12214: }
12215: } else {
1.46 raeburn 12216: $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 12217: }
12218: }
12219: } else {
1.46 raeburn 12220: $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 12221: }
12222: if ($error) {
1.8 raeburn 12223: &Apache::lonnet::logthis($error);
1.11 albertel 12224: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12225: }
12226: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12227: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12228: my $error;
12229: if ($configuserok eq 'ok') {
12230: # is confname an author?
12231: if ($switchserver eq '') {
12232: if ($author_ok eq 'ok') {
12233: my ($result,$logourl) =
12234: &publishlogo($r,'copy',$domconfig->{$role}{$img},
12235: $dom,$confname,$img,$width,$height);
12236: if ($result eq 'ok') {
12237: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12238: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12239: }
12240: }
12241: }
12242: }
1.6 raeburn 12243: }
12244: }
12245: }
12246: if (ref($domconfig) eq 'HASH') {
12247: if (ref($domconfig->{$role}) eq 'HASH') {
12248: foreach my $img (@images) {
12249: if ($domconfig->{$role}{$img} ne '') {
12250: if ($env{'form.'.$role.'_del_'.$img}) {
12251: $confhash->{$role}{$img} = '';
1.12 raeburn 12252: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12253: } else {
1.9 raeburn 12254: if ($confhash->{$role}{$img} eq '') {
12255: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12256: }
1.6 raeburn 12257: }
12258: } else {
12259: if ($env{'form.'.$role.'_del_'.$img}) {
12260: $confhash->{$role}{$img} = '';
1.12 raeburn 12261: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12262: }
12263: }
1.70 raeburn 12264: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
12265: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12266: if ($confhash->{$role}{'showlogo'}{$img} ne
12267: $domconfig->{$role}{'showlogo'}{$img}) {
12268: $changes{$role}{'showlogo'}{$img} = 1;
12269: }
12270: } else {
12271: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12272: $changes{$role}{'showlogo'}{$img} = 1;
12273: }
12274: }
12275: }
12276: }
1.6 raeburn 12277: if ($domconfig->{$role}{'font'} ne '') {
12278: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12279: $changes{$role}{'font'} = 1;
12280: }
12281: } else {
12282: if ($confhash->{$role}{'font'}) {
12283: $changes{$role}{'font'} = 1;
12284: }
12285: }
1.107 raeburn 12286: if ($role ne 'login') {
12287: if ($domconfig->{$role}{'fontmenu'} ne '') {
12288: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12289: $changes{$role}{'fontmenu'} = 1;
12290: }
12291: } else {
12292: if ($confhash->{$role}{'fontmenu'}) {
12293: $changes{$role}{'fontmenu'} = 1;
12294: }
1.97 tempelho 12295: }
12296: }
1.6 raeburn 12297: foreach my $item (@bgs) {
12298: if ($domconfig->{$role}{$item} ne '') {
12299: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12300: $changes{$role}{'bgs'}{$item} = 1;
12301: }
12302: } else {
12303: if ($confhash->{$role}{$item}) {
12304: $changes{$role}{'bgs'}{$item} = 1;
12305: }
12306: }
12307: }
12308: foreach my $item (@links) {
12309: if ($domconfig->{$role}{$item} ne '') {
12310: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12311: $changes{$role}{'links'}{$item} = 1;
12312: }
12313: } else {
12314: if ($confhash->{$role}{$item}) {
12315: $changes{$role}{'links'}{$item} = 1;
12316: }
12317: }
12318: }
1.41 raeburn 12319: foreach my $item (@logintext) {
12320: if ($domconfig->{$role}{$item} ne '') {
12321: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12322: $changes{$role}{'logintext'}{$item} = 1;
12323: }
12324: } else {
12325: if ($confhash->{$role}{$item}) {
12326: $changes{$role}{'logintext'}{$item} = 1;
12327: }
12328: }
12329: }
1.6 raeburn 12330: } else {
12331: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12332: \@logintext,$confhash,\%changes);
1.6 raeburn 12333: }
12334: } else {
12335: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12336: \@logintext,$confhash,\%changes);
1.6 raeburn 12337: }
12338: }
12339: return ($errors,%changes);
12340: }
12341:
1.46 raeburn 12342: sub config_check {
12343: my ($dom,$confname,$servadm) = @_;
12344: my ($configuserok,$author_ok,$switchserver,%currroles);
12345: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12346: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12347: $confname,$servadm);
12348: if ($configuserok eq 'ok') {
12349: $switchserver = &check_switchserver($dom,$confname);
12350: if ($switchserver eq '') {
12351: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12352: }
12353: }
12354: return ($configuserok,$author_ok,$switchserver);
12355: }
12356:
1.6 raeburn 12357: sub default_change_checker {
1.41 raeburn 12358: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12359: foreach my $item (@{$links}) {
12360: if ($confhash->{$role}{$item}) {
12361: $changes->{$role}{'links'}{$item} = 1;
12362: }
12363: }
12364: foreach my $item (@{$bgs}) {
12365: if ($confhash->{$role}{$item}) {
12366: $changes->{$role}{'bgs'}{$item} = 1;
12367: }
12368: }
1.41 raeburn 12369: foreach my $item (@{$logintext}) {
12370: if ($confhash->{$role}{$item}) {
12371: $changes->{$role}{'logintext'}{$item} = 1;
12372: }
12373: }
1.6 raeburn 12374: foreach my $img (@{$images}) {
12375: if ($env{'form.'.$role.'_del_'.$img}) {
12376: $confhash->{$role}{$img} = '';
1.12 raeburn 12377: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12378: }
1.70 raeburn 12379: if ($role eq 'login') {
12380: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12381: $changes->{$role}{'showlogo'}{$img} = 1;
12382: }
12383: }
1.6 raeburn 12384: }
12385: if ($confhash->{$role}{'font'}) {
12386: $changes->{$role}{'font'} = 1;
12387: }
1.48 raeburn 12388: }
1.6 raeburn 12389:
12390: sub display_colorchgs {
12391: my ($dom,$changes,$roles,$confhash) = @_;
12392: my (%choices,$resulttext);
12393: if (!grep(/^login$/,@{$roles})) {
12394: $resulttext = &mt('Changes made:').'<br />';
12395: }
12396: foreach my $role (@{$roles}) {
12397: if ($role eq 'login') {
12398: %choices = &login_choices();
12399: } else {
12400: %choices = &color_font_choices();
12401: }
12402: if (ref($changes->{$role}) eq 'HASH') {
12403: if ($role ne 'login') {
12404: $resulttext .= '<h4>'.&mt($role).'</h4>';
12405: }
12406: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12407: if ($role ne 'login') {
12408: $resulttext .= '<ul>';
12409: }
12410: if (ref($changes->{$role}{$key}) eq 'HASH') {
12411: if ($role ne 'login') {
12412: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12413: }
12414: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12415: if (($role eq 'login') && ($key eq 'showlogo')) {
12416: if ($confhash->{$role}{$key}{$item}) {
12417: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12418: } else {
12419: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12420: }
12421: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12422: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12423: } else {
1.12 raeburn 12424: my $newitem = $confhash->{$role}{$item};
12425: if ($key eq 'images') {
1.306 raeburn 12426: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 12427: }
12428: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12429: }
12430: }
12431: if ($role ne 'login') {
12432: $resulttext .= '</ul></li>';
12433: }
12434: } else {
12435: if ($confhash->{$role}{$key} eq '') {
12436: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12437: } else {
12438: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12439: }
12440: }
12441: if ($role ne 'login') {
12442: $resulttext .= '</ul>';
12443: }
12444: }
12445: }
12446: }
1.3 raeburn 12447: return $resulttext;
1.1 raeburn 12448: }
12449:
1.9 raeburn 12450: sub thumb_dimensions {
12451: return ('200','50');
12452: }
12453:
1.16 raeburn 12454: sub check_dimensions {
12455: my ($inputfile) = @_;
12456: my ($fullwidth,$fullheight);
12457: if ($inputfile =~ m|^[/\w.\-]+$|) {
12458: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12459: my $imageinfo = <PIPE>;
12460: if (!close(PIPE)) {
12461: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12462: }
12463: chomp($imageinfo);
12464: my ($fullsize) =
1.21 raeburn 12465: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12466: if ($fullsize) {
12467: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12468: }
12469: }
12470: }
12471: return ($fullwidth,$fullheight);
12472: }
12473:
1.9 raeburn 12474: sub check_configuser {
12475: my ($uhome,$dom,$confname,$servadm) = @_;
12476: my ($configuserok,%currroles);
12477: if ($uhome eq 'no_host') {
12478: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 12479: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12480: $configuserok =
12481: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12482: $configpass,'','','','','',undef,$servadm);
12483: } else {
12484: $configuserok = 'ok';
12485: %currroles =
12486: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12487: }
12488: return ($configuserok,%currroles);
12489: }
12490:
12491: sub check_authorstatus {
12492: my ($dom,$confname,%currroles) = @_;
12493: my $author_ok;
1.40 raeburn 12494: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12495: my $start = time;
12496: my $end = 0;
12497: $author_ok =
12498: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12499: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12500: } else {
12501: $author_ok = 'ok';
12502: }
12503: return $author_ok;
12504: }
12505:
12506: sub publishlogo {
1.46 raeburn 12507: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 12508: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 12509: if ($action eq 'upload') {
12510: $fname=$env{'form.'.$formname.'.filename'};
12511: chop($env{'form.'.$formname});
12512: } else {
12513: ($fname) = ($formname =~ /([^\/]+)$/);
12514: }
1.46 raeburn 12515: if ($savefileas ne '') {
12516: $fname = $savefileas;
12517: }
1.9 raeburn 12518: $fname=&Apache::lonnet::clean_filename($fname);
12519: # See if there is anything left
12520: unless ($fname) { return ('error: no uploaded file'); }
12521: $fname="$subdir/$fname";
1.210 raeburn 12522: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 12523: my $filepath="$docroot/priv";
12524: my $relpath = "$dom/$confname";
1.9 raeburn 12525: my ($fnamepath,$file,$fetchthumb);
12526: $file=$fname;
12527: if ($fname=~m|/|) {
12528: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
12529: }
1.164 raeburn 12530: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 12531: my $count;
1.164 raeburn 12532: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 12533: $filepath.="/$parts[$count]";
12534: if ((-e $filepath)!=1) {
12535: mkdir($filepath,02770);
12536: }
12537: }
12538: # Check for bad extension and disallow upload
12539: if ($file=~/\.(\w+)$/ &&
12540: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
12541: $output =
1.207 bisitz 12542: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 12543: } elsif ($file=~/\.(\w+)$/ &&
12544: !defined(&Apache::loncommon::fileembstyle($1))) {
12545: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
12546: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 12547: $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 12548: } elsif (-d "$filepath/$file") {
1.195 bisitz 12549: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 12550: } else {
12551: my $source = $filepath.'/'.$file;
12552: my $logfile;
1.316 raeburn 12553: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 12554: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 12555: }
12556: print $logfile
12557: "\n================= Publish ".localtime()." ================\n".
12558: $env{'user.name'}.':'.$env{'user.domain'}."\n";
12559: # Save the file
1.316 raeburn 12560: if (!open(FH,">",$source)) {
1.9 raeburn 12561: &Apache::lonnet::logthis('Failed to create '.$source);
12562: return (&mt('Failed to create file'));
12563: }
12564: if ($action eq 'upload') {
12565: if (!print FH ($env{'form.'.$formname})) {
12566: &Apache::lonnet::logthis('Failed to write to '.$source);
12567: return (&mt('Failed to write file'));
12568: }
12569: } else {
12570: my $original = &Apache::lonnet::filelocation('',$formname);
12571: if(!copy($original,$source)) {
12572: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
12573: return (&mt('Failed to write file'));
12574: }
12575: }
12576: close(FH);
12577: chmod(0660, $source); # Permissions to rw-rw---.
12578:
12579: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
12580: my $copyfile=$targetdir.'/'.$file;
12581:
12582: my @parts=split(/\//,$targetdir);
12583: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
12584: for (my $count=5;$count<=$#parts;$count++) {
12585: $path.="/$parts[$count]";
12586: if (!-e $path) {
12587: print $logfile "\nCreating directory ".$path;
12588: mkdir($path,02770);
12589: }
12590: }
12591: my $versionresult;
12592: if (-e $copyfile) {
12593: $versionresult = &logo_versioning($targetdir,$file,$logfile);
12594: } else {
12595: $versionresult = 'ok';
12596: }
12597: if ($versionresult eq 'ok') {
12598: if (copy($source,$copyfile)) {
12599: print $logfile "\nCopied original source to ".$copyfile."\n";
12600: $output = 'ok';
12601: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 12602: push(@{$modified_urls},[$copyfile,$source]);
12603: my $metaoutput =
12604: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
12605: unless ($registered_cleanup) {
12606: my $handlers = $r->get_handlers('PerlCleanupHandler');
12607: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12608: $registered_cleanup=1;
12609: }
1.9 raeburn 12610: } else {
12611: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
12612: $output = &mt('Failed to copy file to RES space').", $!";
12613: }
12614: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
12615: my $inputfile = $filepath.'/'.$file;
12616: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 12617: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
12618: if ($fullwidth ne '' && $fullheight ne '') {
12619: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
12620: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 12621: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
12622: system({$args[0]} @args);
1.16 raeburn 12623: chmod(0660, $filepath.'/tn-'.$file);
12624: if (-e $outfile) {
12625: my $copyfile=$targetdir.'/tn-'.$file;
12626: if (copy($outfile,$copyfile)) {
12627: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 12628: my $thumb_metaoutput =
12629: &write_metadata($dom,$confname,$formname,
12630: $targetdir,'tn-'.$file,$logfile);
12631: push(@{$modified_urls},[$copyfile,$outfile]);
12632: unless ($registered_cleanup) {
12633: my $handlers = $r->get_handlers('PerlCleanupHandler');
12634: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12635: $registered_cleanup=1;
12636: }
1.267 raeburn 12637: $madethumb = 1;
1.16 raeburn 12638: } else {
12639: print $logfile "\nUnable to write ".$copyfile.
12640: ':'.$!."\n";
12641: }
12642: }
1.9 raeburn 12643: }
12644: }
12645: }
12646: } else {
12647: $output = $versionresult;
12648: }
12649: }
1.267 raeburn 12650: return ($output,$logourl,$madethumb);
1.9 raeburn 12651: }
12652:
12653: sub logo_versioning {
12654: my ($targetdir,$file,$logfile) = @_;
12655: my $target = $targetdir.'/'.$file;
12656: my ($maxversion,$fn,$extn,$output);
12657: $maxversion = 0;
12658: if ($file =~ /^(.+)\.(\w+)$/) {
12659: $fn=$1;
12660: $extn=$2;
12661: }
12662: opendir(DIR,$targetdir);
12663: while (my $filename=readdir(DIR)) {
12664: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
12665: $maxversion=($1>$maxversion)?$1:$maxversion;
12666: }
12667: }
12668: $maxversion++;
12669: print $logfile "\nCreating old version ".$maxversion."\n";
12670: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12671: if (copy($target,$copyfile)) {
12672: print $logfile "Copied old target to ".$copyfile."\n";
12673: $copyfile=$copyfile.'.meta';
12674: if (copy($target.'.meta',$copyfile)) {
12675: print $logfile "Copied old target metadata to ".$copyfile."\n";
12676: $output = 'ok';
12677: } else {
12678: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12679: $output = &mt('Failed to copy old meta').", $!, ";
12680: }
12681: } else {
12682: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12683: $output = &mt('Failed to copy old target').", $!, ";
12684: }
12685: return $output;
12686: }
12687:
12688: sub write_metadata {
12689: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12690: my (%metadatafields,%metadatakeys,$output);
12691: $metadatafields{'title'}=$formname;
12692: $metadatafields{'creationdate'}=time;
12693: $metadatafields{'lastrevisiondate'}=time;
12694: $metadatafields{'copyright'}='public';
12695: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12696: $env{'user.domain'};
12697: $metadatafields{'authorspace'}=$confname.':'.$dom;
12698: $metadatafields{'domain'}=$dom;
12699: {
12700: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12701: my $mfh;
1.316 raeburn 12702: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12703: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12704: unless ($_=~/\./) {
12705: my $unikey=$_;
12706: $unikey=~/^([A-Za-z]+)/;
12707: my $tag=$1;
12708: $tag=~tr/A-Z/a-z/;
12709: print $mfh "\n\<$tag";
12710: foreach (split(/\,/,$metadatakeys{$unikey})) {
12711: my $value=$metadatafields{$unikey.'.'.$_};
12712: $value=~s/\"/\'\'/g;
12713: print $mfh ' '.$_.'="'.$value.'"';
12714: }
12715: print $mfh '>'.
12716: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12717: .'</'.$tag.'>';
12718: }
12719: }
12720: $output = 'ok';
12721: print $logfile "\nWrote metadata";
12722: close($mfh);
12723: } else {
12724: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12725: $output = &mt('Could not write metadata');
12726: }
12727: }
1.155 raeburn 12728: return $output;
12729: }
12730:
12731: sub notifysubscribed {
12732: foreach my $targetsource (@{$modified_urls}){
12733: next unless (ref($targetsource) eq 'ARRAY');
12734: my ($target,$source)=@{$targetsource};
12735: if ($source ne '') {
1.316 raeburn 12736: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12737: print $logfh "\nCleanup phase: Notifications\n";
12738: my @subscribed=&subscribed_hosts($target);
12739: foreach my $subhost (@subscribed) {
12740: print $logfh "\nNotifying host ".$subhost.':';
12741: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12742: print $logfh $reply;
12743: }
12744: my @subscribedmeta=&subscribed_hosts("$target.meta");
12745: foreach my $subhost (@subscribedmeta) {
12746: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12747: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12748: $subhost);
12749: print $logfh $reply;
12750: }
12751: print $logfh "\n============ Done ============\n";
1.160 raeburn 12752: close($logfh);
1.155 raeburn 12753: }
12754: }
12755: }
12756: return OK;
12757: }
12758:
12759: sub subscribed_hosts {
12760: my ($target) = @_;
12761: my @subscribed;
1.316 raeburn 12762: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12763: while (my $subline=<$fh>) {
12764: if ($subline =~ /^($match_lonid):/) {
12765: my $host = $1;
12766: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12767: unless (grep(/^\Q$host\E$/,@subscribed)) {
12768: push(@subscribed,$host);
12769: }
12770: }
12771: }
12772: }
12773: }
12774: return @subscribed;
1.9 raeburn 12775: }
12776:
12777: sub check_switchserver {
12778: my ($dom,$confname) = @_;
12779: my ($allowed,$switchserver);
12780: my $home = &Apache::lonnet::homeserver($confname,$dom);
12781: if ($home eq 'no_host') {
12782: $home = &Apache::lonnet::domain($dom,'primary');
12783: }
12784: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12785: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12786: if (!$allowed) {
1.180 raeburn 12787: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12788: }
12789: return $switchserver;
12790: }
12791:
1.1 raeburn 12792: sub modify_quotas {
1.216 raeburn 12793: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12794: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12795: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12796: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12797: $validationfieldsref);
1.86 raeburn 12798: if ($action eq 'quotas') {
12799: $context = 'tools';
1.163 raeburn 12800: } else {
1.86 raeburn 12801: $context = $action;
12802: }
12803: if ($context eq 'requestcourses') {
1.325 raeburn 12804: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12805: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12806: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12807: %titles = &courserequest_titles();
12808: $toolregexp = join('|',@usertools);
12809: %conditions = &courserequest_conditions();
1.216 raeburn 12810: $confname = $dom.'-domainconfig';
12811: my $servadm = $r->dir_config('lonAdmEMail');
12812: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12813: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12814: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12815: } elsif ($context eq 'requestauthor') {
12816: @usertools = ('author');
12817: %titles = &authorrequest_titles();
1.86 raeburn 12818: } else {
1.162 raeburn 12819: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12820: %titles = &tool_titles();
1.86 raeburn 12821: }
1.212 raeburn 12822: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12823: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12824: foreach my $key (keys(%env)) {
1.101 raeburn 12825: if ($context eq 'requestcourses') {
12826: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12827: my $item = $1;
12828: my $type = $2;
12829: if ($type =~ /^limit_(.+)/) {
12830: $limithash{$item}{$1} = $env{$key};
12831: } else {
12832: $confhash{$item}{$type} = $env{$key};
12833: }
12834: }
1.163 raeburn 12835: } elsif ($context eq 'requestauthor') {
12836: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12837: $confhash{$1} = $env{$key};
12838: }
1.101 raeburn 12839: } else {
1.86 raeburn 12840: if ($key =~ /^form\.quota_(.+)$/) {
12841: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12842: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12843: $confhash{'authorquota'}{$1} = $env{$key};
12844: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12845: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12846: }
1.72 raeburn 12847: }
12848: }
1.163 raeburn 12849: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12850: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12851: @approvalnotify = sort(@approvalnotify);
12852: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12853: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12854: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12855: foreach my $type (@hasuniquecode) {
12856: if (grep(/^\Q$type\E$/,@crstypes)) {
12857: $confhash{'uniquecode'}{$type} = 1;
12858: }
1.216 raeburn 12859: }
1.242 raeburn 12860: my (%newbook,%allpos);
1.216 raeburn 12861: if ($context eq 'requestcourses') {
1.242 raeburn 12862: foreach my $type ('textbooks','templates') {
12863: @{$allpos{$type}} = ();
12864: my $invalid;
12865: if ($type eq 'textbooks') {
12866: $invalid = &mt('Invalid LON-CAPA course for textbook');
12867: } else {
12868: $invalid = &mt('Invalid LON-CAPA course for template');
12869: }
12870: if ($env{'form.'.$type.'_addbook'}) {
12871: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12872: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12873: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12874: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12875: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12876: } else {
12877: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12878: my $position = $env{'form.'.$type.'_addbook_pos'};
12879: $position =~ s/\D+//g;
12880: if ($position ne '') {
12881: $allpos{$type}[$position] = $newbook{$type};
12882: }
1.216 raeburn 12883: }
1.242 raeburn 12884: } else {
12885: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12886: }
12887: }
1.242 raeburn 12888: }
1.216 raeburn 12889: }
1.102 raeburn 12890: if (ref($domconfig{$action}) eq 'HASH') {
12891: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12892: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12893: $changes{'notify'}{'approval'} = 1;
12894: }
12895: } else {
1.144 raeburn 12896: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12897: $changes{'notify'}{'approval'} = 1;
12898: }
12899: }
1.218 raeburn 12900: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12901: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12902: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12903: unless ($confhash{'uniquecode'}{$crstype}) {
12904: $changes{'uniquecode'} = 1;
12905: }
12906: }
12907: unless ($changes{'uniquecode'}) {
12908: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12909: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12910: $changes{'uniquecode'} = 1;
12911: }
12912: }
12913: }
12914: } else {
12915: $changes{'uniquecode'} = 1;
12916: }
12917: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12918: $changes{'uniquecode'} = 1;
1.216 raeburn 12919: }
12920: if ($context eq 'requestcourses') {
1.242 raeburn 12921: foreach my $type ('textbooks','templates') {
12922: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12923: my %deletions;
12924: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12925: if (@todelete) {
12926: map { $deletions{$_} = 1; } @todelete;
12927: }
12928: my %imgdeletions;
12929: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12930: if (@todeleteimages) {
12931: map { $imgdeletions{$_} = 1; } @todeleteimages;
12932: }
12933: my $maxnum = $env{'form.'.$type.'_maxnum'};
12934: for (my $i=0; $i<=$maxnum; $i++) {
12935: my $itemid = $env{'form.'.$type.'_id_'.$i};
12936: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12937: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12938: if ($deletions{$key}) {
12939: if ($domconfig{$action}{$type}{$key}{'image'}) {
12940: #FIXME need to obsolete item in RES space
12941: }
12942: next;
12943: } else {
12944: my $newpos = $env{'form.'.$itemid};
12945: $newpos =~ s/\D+//g;
1.243 raeburn 12946: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 12947: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 12948: ($type eq 'templates'));
1.242 raeburn 12949: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12950: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12951: $changes{$type}{$key} = 1;
12952: }
12953: }
12954: $allpos{$type}[$newpos] = $key;
12955: }
12956: if ($imgdeletions{$key}) {
12957: $changes{$type}{$key} = 1;
1.216 raeburn 12958: #FIXME need to obsolete item in RES space
1.242 raeburn 12959: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12960: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 12961: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12962: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12963: } else {
12964: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12965: $cdom,$cnum,$type,$configuserok,
12966: $switchserver,$author_ok);
12967: if ($imgurl) {
12968: $confhash{$type}{$key}{'image'} = $imgurl;
12969: $changes{$type}{$key} = 1;
12970: }
12971: if ($error) {
12972: &Apache::lonnet::logthis($error);
12973: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12974: }
12975: }
1.242 raeburn 12976: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12977: $confhash{$type}{$key}{'image'} =
12978: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 12979: }
12980: }
12981: }
12982: }
12983: }
12984: }
1.102 raeburn 12985: } else {
1.144 raeburn 12986: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12987: $changes{'notify'}{'approval'} = 1;
12988: }
1.218 raeburn 12989: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 12990: $changes{'uniquecode'} = 1;
12991: }
12992: }
12993: if ($context eq 'requestcourses') {
1.242 raeburn 12994: foreach my $type ('textbooks','templates') {
12995: if ($newbook{$type}) {
12996: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 12997: foreach my $item ('subject','title','publisher','author') {
12998: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12999: ($type eq 'template'));
1.242 raeburn 13000: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13001: if ($env{'form.'.$type.'_addbook_'.$item}) {
13002: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13003: }
13004: }
13005: if ($type eq 'textbooks') {
13006: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13007: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13008: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13009: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13010: } else {
13011: my ($imageurl,$error) =
13012: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13013: $configuserok,$switchserver,$author_ok);
13014: if ($imageurl) {
13015: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13016: }
13017: if ($error) {
13018: &Apache::lonnet::logthis($error);
13019: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13020: }
1.242 raeburn 13021: }
13022: }
1.216 raeburn 13023: }
13024: }
1.242 raeburn 13025: if (@{$allpos{$type}} > 0) {
13026: my $idx = 0;
13027: foreach my $item (@{$allpos{$type}}) {
13028: if ($item ne '') {
13029: $confhash{$type}{$item}{'order'} = $idx;
13030: if (ref($domconfig{$action}) eq 'HASH') {
13031: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13032: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13033: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13034: $changes{$type}{$item} = 1;
13035: }
1.216 raeburn 13036: }
13037: }
13038: }
1.242 raeburn 13039: $idx ++;
1.216 raeburn 13040: }
13041: }
13042: }
13043: }
1.235 raeburn 13044: if (ref($validationitemsref) eq 'ARRAY') {
13045: foreach my $item (@{$validationitemsref}) {
13046: if ($item eq 'fields') {
13047: my @changed;
13048: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13049: if (@{$confhash{'validation'}{$item}} > 0) {
13050: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13051: }
1.266 raeburn 13052: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13053: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13054: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13055: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13056: $domconfig{'requestcourses'}{'validation'}{$item});
13057: } else {
13058: @changed = @{$confhash{'validation'}{$item}};
13059: }
1.235 raeburn 13060: } else {
13061: @changed = @{$confhash{'validation'}{$item}};
13062: }
13063: } else {
13064: @changed = @{$confhash{'validation'}{$item}};
13065: }
13066: if (@changed) {
13067: if ($confhash{'validation'}{$item}) {
13068: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13069: } else {
13070: $changes{'validation'}{$item} = &mt('None');
13071: }
13072: }
13073: } else {
13074: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13075: if ($item eq 'markup') {
13076: if ($env{'form.requestcourses_validation_'.$item}) {
13077: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13078: }
13079: }
1.266 raeburn 13080: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13081: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13082: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13083: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13084: }
13085: } else {
13086: if ($confhash{'validation'}{$item} ne '') {
13087: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13088: }
1.235 raeburn 13089: }
13090: } else {
13091: if ($confhash{'validation'}{$item} ne '') {
13092: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13093: }
13094: }
13095: }
13096: }
13097: }
13098: if ($env{'form.validationdc'}) {
13099: my $newval = $env{'form.validationdc'};
1.285 raeburn 13100: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13101: if (exists($domcoords{$newval})) {
13102: $confhash{'validation'}{'dc'} = $newval;
13103: }
13104: }
13105: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13106: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13107: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13108: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13109: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13110: if ($confhash{'validation'}{'dc'} eq '') {
13111: $changes{'validation'}{'dc'} = &mt('None');
13112: } else {
13113: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13114: }
1.235 raeburn 13115: }
1.266 raeburn 13116: } elsif ($confhash{'validation'}{'dc'} ne '') {
13117: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13118: }
13119: } elsif ($confhash{'validation'}{'dc'} ne '') {
13120: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13121: }
13122: } elsif ($confhash{'validation'}{'dc'} ne '') {
13123: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13124: }
1.266 raeburn 13125: } else {
13126: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13127: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13128: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13129: $changes{'validation'}{'dc'} = &mt('None');
13130: }
13131: }
1.235 raeburn 13132: }
13133: }
1.102 raeburn 13134: }
13135: } else {
1.86 raeburn 13136: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13137: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13138: }
1.72 raeburn 13139: foreach my $item (@usertools) {
13140: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13141: my $unset;
1.101 raeburn 13142: if ($context eq 'requestcourses') {
1.104 raeburn 13143: $unset = '0';
13144: if ($type eq '_LC_adv') {
13145: $unset = '';
13146: }
1.101 raeburn 13147: if ($confhash{$item}{$type} eq 'autolimit') {
13148: $confhash{$item}{$type} .= '=';
13149: unless ($limithash{$item}{$type} =~ /\D/) {
13150: $confhash{$item}{$type} .= $limithash{$item}{$type};
13151: }
13152: }
1.163 raeburn 13153: } elsif ($context eq 'requestauthor') {
13154: $unset = '0';
13155: if ($type eq '_LC_adv') {
13156: $unset = '';
13157: }
1.72 raeburn 13158: } else {
1.101 raeburn 13159: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13160: $confhash{$item}{$type} = 1;
13161: } else {
13162: $confhash{$item}{$type} = 0;
13163: }
1.72 raeburn 13164: }
1.86 raeburn 13165: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13166: if ($action eq 'requestauthor') {
13167: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13168: $changes{$type} = 1;
13169: }
13170: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13171: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13172: $changes{$item}{$type} = 1;
13173: }
13174: } else {
13175: if ($context eq 'requestcourses') {
1.104 raeburn 13176: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13177: $changes{$item}{$type} = 1;
13178: }
13179: } else {
13180: if (!$confhash{$item}{$type}) {
13181: $changes{$item}{$type} = 1;
13182: }
13183: }
13184: }
13185: } else {
13186: if ($context eq 'requestcourses') {
1.104 raeburn 13187: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13188: $changes{$item}{$type} = 1;
13189: }
1.163 raeburn 13190: } elsif ($context eq 'requestauthor') {
13191: if ($confhash{$type} ne $unset) {
13192: $changes{$type} = 1;
13193: }
1.72 raeburn 13194: } else {
13195: if (!$confhash{$item}{$type}) {
13196: $changes{$item}{$type} = 1;
13197: }
13198: }
13199: }
1.1 raeburn 13200: }
13201: }
1.163 raeburn 13202: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13203: if (ref($domconfig{'quotas'}) eq 'HASH') {
13204: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13205: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13206: if (exists($confhash{'defaultquota'}{$key})) {
13207: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13208: $changes{'defaultquota'}{$key} = 1;
13209: }
13210: } else {
13211: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13212: }
13213: }
1.86 raeburn 13214: } else {
13215: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13216: if (exists($confhash{'defaultquota'}{$key})) {
13217: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13218: $changes{'defaultquota'}{$key} = 1;
13219: }
13220: } else {
13221: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13222: }
1.1 raeburn 13223: }
13224: }
1.197 raeburn 13225: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13226: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13227: if (exists($confhash{'authorquota'}{$key})) {
13228: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13229: $changes{'authorquota'}{$key} = 1;
13230: }
13231: } else {
13232: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13233: }
13234: }
13235: }
1.1 raeburn 13236: }
1.86 raeburn 13237: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13238: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13239: if (ref($domconfig{'quotas'}) eq 'HASH') {
13240: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13241: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13242: $changes{'defaultquota'}{$key} = 1;
13243: }
13244: } else {
13245: if (!exists($domconfig{'quotas'}{$key})) {
13246: $changes{'defaultquota'}{$key} = 1;
13247: }
1.72 raeburn 13248: }
13249: } else {
1.86 raeburn 13250: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13251: }
1.1 raeburn 13252: }
13253: }
1.197 raeburn 13254: if (ref($confhash{'authorquota'}) eq 'HASH') {
13255: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13256: if (ref($domconfig{'quotas'}) eq 'HASH') {
13257: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13258: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13259: $changes{'authorquota'}{$key} = 1;
13260: }
13261: } else {
13262: $changes{'authorquota'}{$key} = 1;
13263: }
13264: } else {
13265: $changes{'authorquota'}{$key} = 1;
13266: }
13267: }
13268: }
1.1 raeburn 13269: }
1.72 raeburn 13270:
1.163 raeburn 13271: if ($context eq 'requestauthor') {
13272: $domdefaults{'requestauthor'} = \%confhash;
13273: } else {
13274: foreach my $key (keys(%confhash)) {
1.242 raeburn 13275: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13276: $domdefaults{$key} = $confhash{$key};
13277: }
1.163 raeburn 13278: }
1.72 raeburn 13279: }
1.163 raeburn 13280:
1.1 raeburn 13281: my %quotahash = (
1.86 raeburn 13282: $action => { %confhash }
1.1 raeburn 13283: );
13284: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13285: $dom);
13286: if ($putresult eq 'ok') {
13287: if (keys(%changes) > 0) {
1.72 raeburn 13288: my $cachetime = 24*60*60;
13289: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13290: if (ref($lastactref) eq 'HASH') {
13291: $lastactref->{'domdefaults'} = 1;
13292: }
1.1 raeburn 13293: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13294: unless (($context eq 'requestcourses') ||
1.163 raeburn 13295: ($context eq 'requestauthor')) {
1.86 raeburn 13296: if (ref($changes{'defaultquota'}) eq 'HASH') {
13297: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13298: foreach my $type (@{$types},'default') {
13299: if (defined($changes{'defaultquota'}{$type})) {
13300: my $typetitle = $usertypes->{$type};
13301: if ($type eq 'default') {
13302: $typetitle = $othertitle;
13303: }
1.213 raeburn 13304: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13305: }
13306: }
1.86 raeburn 13307: $resulttext .= '</ul></li>';
1.72 raeburn 13308: }
1.197 raeburn 13309: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13310: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13311: foreach my $type (@{$types},'default') {
13312: if (defined($changes{'authorquota'}{$type})) {
13313: my $typetitle = $usertypes->{$type};
13314: if ($type eq 'default') {
13315: $typetitle = $othertitle;
13316: }
1.213 raeburn 13317: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13318: }
13319: }
13320: $resulttext .= '</ul></li>';
13321: }
1.72 raeburn 13322: }
1.80 raeburn 13323: my %newenv;
1.72 raeburn 13324: foreach my $item (@usertools) {
1.163 raeburn 13325: my (%haschgs,%inconf);
13326: if ($context eq 'requestauthor') {
13327: %haschgs = %changes;
1.210 raeburn 13328: %inconf = %confhash;
1.163 raeburn 13329: } else {
13330: if (ref($changes{$item}) eq 'HASH') {
13331: %haschgs = %{$changes{$item}};
13332: }
13333: if (ref($confhash{$item}) eq 'HASH') {
13334: %inconf = %{$confhash{$item}};
13335: }
13336: }
13337: if (keys(%haschgs) > 0) {
1.80 raeburn 13338: my $newacc =
13339: &Apache::lonnet::usertools_access($env{'user.name'},
13340: $env{'user.domain'},
1.86 raeburn 13341: $item,'reload',$context);
1.210 raeburn 13342: if (($context eq 'requestcourses') ||
1.163 raeburn 13343: ($context eq 'requestauthor')) {
1.108 raeburn 13344: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13345: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13346: }
13347: } else {
13348: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13349: $newenv{'environment.availabletools.'.$item} = $newacc;
13350: }
1.80 raeburn 13351: }
1.163 raeburn 13352: unless ($context eq 'requestauthor') {
13353: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13354: }
1.72 raeburn 13355: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 13356: if ($haschgs{$type}) {
1.72 raeburn 13357: my $typetitle = $usertypes->{$type};
13358: if ($type eq 'default') {
13359: $typetitle = $othertitle;
13360: } elsif ($type eq '_LC_adv') {
13361: $typetitle = 'LON-CAPA Advanced Users';
13362: }
1.163 raeburn 13363: if ($inconf{$type}) {
1.101 raeburn 13364: if ($context eq 'requestcourses') {
13365: my $cond;
1.163 raeburn 13366: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13367: if ($1 eq '') {
13368: $cond = &mt('(Automatic processing of any request).');
13369: } else {
13370: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13371: }
13372: } else {
1.163 raeburn 13373: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13374: }
13375: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 13376: } elsif ($context eq 'requestauthor') {
13377: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13378: $titles{$inconf{$type}},$typetitle);
13379:
1.101 raeburn 13380: } else {
13381: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13382: }
1.72 raeburn 13383: } else {
1.104 raeburn 13384: if ($type eq '_LC_adv') {
1.163 raeburn 13385: if ($inconf{$type} eq '0') {
1.104 raeburn 13386: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13387: } else {
13388: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13389: }
13390: } else {
13391: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13392: }
1.72 raeburn 13393: }
13394: }
1.26 raeburn 13395: }
1.163 raeburn 13396: unless ($context eq 'requestauthor') {
13397: $resulttext .= '</ul></li>';
13398: }
1.26 raeburn 13399: }
1.1 raeburn 13400: }
1.163 raeburn 13401: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13402: if (ref($changes{'notify'}) eq 'HASH') {
13403: if ($changes{'notify'}{'approval'}) {
13404: if (ref($confhash{'notify'}) eq 'HASH') {
13405: if ($confhash{'notify'}{'approval'}) {
13406: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13407: } else {
1.163 raeburn 13408: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13409: }
13410: }
13411: }
13412: }
13413: }
1.216 raeburn 13414: if ($action eq 'requestcourses') {
13415: my @offon = ('off','on');
13416: if ($changes{'uniquecode'}) {
1.218 raeburn 13417: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13418: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13419: $resulttext .= '<li>'.
13420: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13421: '</li>';
13422: } else {
13423: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13424: '</li>';
13425: }
1.216 raeburn 13426: }
1.242 raeburn 13427: foreach my $type ('textbooks','templates') {
13428: if (ref($changes{$type}) eq 'HASH') {
13429: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13430: foreach my $key (sort(keys(%{$changes{$type}}))) {
13431: my %coursehash = &Apache::lonnet::coursedescription($key);
13432: my $coursetitle = $coursehash{'description'};
13433: my $position = $confhash{$type}{$key}{'order'} + 1;
13434: $resulttext .= '<li>';
1.243 raeburn 13435: foreach my $item ('subject','title','publisher','author') {
13436: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13437: ($type eq 'templates'));
1.242 raeburn 13438: my $name = $item.':';
13439: $name =~ s/^(\w)/\U$1/;
13440: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13441: }
13442: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13443: if ($type eq 'textbooks') {
13444: if ($confhash{$type}{$key}{'image'}) {
13445: $resulttext .= ' '.&mt('Image: [_1]',
13446: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13447: ' alt="Textbook cover" />').'<br />';
13448: }
13449: }
13450: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 13451: }
1.242 raeburn 13452: $resulttext .= '</ul></li>';
1.216 raeburn 13453: }
13454: }
1.235 raeburn 13455: if (ref($changes{'validation'}) eq 'HASH') {
13456: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13457: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13458: foreach my $item (@{$validationitemsref}) {
13459: if (exists($changes{'validation'}{$item})) {
13460: if ($item eq 'markup') {
13461: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13462: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13463: } else {
13464: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13465: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13466: }
13467: }
13468: }
13469: if (exists($changes{'validation'}{'dc'})) {
13470: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13471: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13472: }
13473: }
13474: }
1.216 raeburn 13475: }
1.1 raeburn 13476: $resulttext .= '</ul>';
1.80 raeburn 13477: if (keys(%newenv)) {
13478: &Apache::lonnet::appenv(\%newenv);
13479: }
1.1 raeburn 13480: } else {
1.86 raeburn 13481: if ($context eq 'requestcourses') {
13482: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 13483: } elsif ($context eq 'requestauthor') {
13484: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13485: } else {
1.90 weissno 13486: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13487: }
1.1 raeburn 13488: }
13489: } else {
1.11 albertel 13490: $resulttext = '<span class="LC_error">'.
13491: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13492: }
1.216 raeburn 13493: if ($errors) {
13494: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13495: '<ul>'.$errors.'</ul></p>';
13496: }
1.3 raeburn 13497: return $resulttext;
1.1 raeburn 13498: }
13499:
1.216 raeburn 13500: sub process_textbook_image {
1.242 raeburn 13501: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 13502: my $filename = $env{'form.'.$caller.'.filename'};
13503: my ($error,$url);
13504: my ($width,$height) = (50,50);
13505: if ($configuserok eq 'ok') {
13506: if ($switchserver) {
13507: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13508: $switchserver);
13509: } elsif ($author_ok eq 'ok') {
13510: my ($result,$imageurl) =
13511: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 13512: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 13513: if ($result eq 'ok') {
13514: $url = $imageurl;
13515: } else {
13516: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13517: }
13518: } else {
13519: $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);
13520: }
13521: } else {
13522: $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);
13523: }
13524: return ($url,$error);
13525: }
13526:
1.267 raeburn 13527: sub modify_ltitools {
13528: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13529: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 13530: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 13531: my $confname = $dom.'-domainconfig';
13532: my $servadm = $r->dir_config('lonAdmEMail');
13533: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13534: my (%posslti,%possfield);
13535: my @courseroles = ('cc','in','ta','ep','st');
13536: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
13537: map { $posslti{$_} = 1; } @ltiroles;
13538: my @allfields = ('fullname','firstname','lastname','email','user','roles');
13539: map { $possfield{$_} = 1; } @allfields;
13540: my %lt = <itools_names();
13541: if ($env{'form.ltitools_add'}) {
13542: my $title = $env{'form.ltitools_add_title'};
13543: $title =~ s/(`)/'/g;
13544: ($newid,my $error) = &get_ltitools_id($dom,$title);
13545: if ($newid) {
13546: my $position = $env{'form.ltitools_add_pos'};
13547: $position =~ s/\D+//g;
13548: if ($position ne '') {
13549: $allpos[$position] = $newid;
13550: }
13551: $changes{$newid} = 1;
1.322 raeburn 13552: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 13553: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 13554: if ($item eq 'lifetime') {
13555: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
13556: }
1.267 raeburn 13557: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 13558: if (($item eq 'key') || ($item eq 'secret')) {
13559: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13560: } else {
13561: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13562: }
1.267 raeburn 13563: }
13564: }
13565: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
13566: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
13567: }
13568: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
13569: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
13570: }
1.323 raeburn 13571: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
13572: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
13573: } else {
13574: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
13575: }
1.296 raeburn 13576: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 13577: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
13578: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 13579: if (($item eq 'width') || ($item eq 'height')) {
13580: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
13581: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13582: }
13583: } else {
13584: if ($env{'form.ltitools_add_'.$item} ne '') {
13585: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13586: }
1.267 raeburn 13587: }
13588: }
13589: if ($env{'form.ltitools_add_target'} eq 'window') {
13590: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 13591: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
13592: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 13593: } else {
13594: $confhash{$newid}{'display'}{'target'} = 'iframe';
13595: }
13596: foreach my $item ('passback','roster') {
1.319 raeburn 13597: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 13598: $confhash{$newid}{$item} = 1;
1.319 raeburn 13599: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
13600: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
13601: $lifetime =~ s/^\s+|\s+$//g;
13602: if ($lifetime =~ /^\d+\.?\d*$/) {
13603: $confhash{$newid}{$item.'valid'} = $lifetime;
13604: }
13605: }
1.267 raeburn 13606: }
13607: }
13608: if ($env{'form.ltitools_add_image.filename'} ne '') {
13609: my ($imageurl,$error) =
1.307 raeburn 13610: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 13611: $configuserok,$switchserver,$author_ok);
13612: if ($imageurl) {
13613: $confhash{$newid}{'image'} = $imageurl;
13614: }
13615: if ($error) {
13616: &Apache::lonnet::logthis($error);
13617: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13618: }
13619: }
13620: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
13621: foreach my $field (@fields) {
13622: if ($possfield{$field}) {
13623: if ($field eq 'roles') {
13624: foreach my $role (@courseroles) {
13625: my $choice = $env{'form.ltitools_add_roles_'.$role};
13626: if (($choice ne '') && ($posslti{$choice})) {
13627: $confhash{$newid}{'roles'}{$role} = $choice;
13628: if ($role eq 'cc') {
13629: $confhash{$newid}{'roles'}{'co'} = $choice;
13630: }
13631: }
13632: }
13633: } else {
13634: $confhash{$newid}{'fields'}{$field} = 1;
13635: }
13636: }
13637: }
1.324 raeburn 13638: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
13639: if ($confhash{$newid}{'fields'}{'user'}) {
13640: if ($env{'form.ltitools_userincdom_add'}) {
13641: $confhash{$newid}{'incdom'} = 1;
13642: }
13643: }
13644: }
1.273 raeburn 13645: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
13646: foreach my $item (@courseconfig) {
13647: $confhash{$newid}{'crsconf'}{$item} = 1;
13648: }
1.267 raeburn 13649: if ($env{'form.ltitools_add_custom'}) {
13650: my $name = $env{'form.ltitools_add_custom_name'};
13651: my $value = $env{'form.ltitools_add_custom_value'};
13652: $value =~ s/(`)/'/g;
13653: $name =~ s/(`)/'/g;
13654: $confhash{$newid}{'custom'}{$name} = $value;
13655: }
13656: } else {
13657: my $error = &mt('Failed to acquire unique ID for new external tool');
13658: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13659: }
13660: }
13661: if (ref($domconfig{$action}) eq 'HASH') {
13662: my %deletions;
13663: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
13664: if (@todelete) {
13665: map { $deletions{$_} = 1; } @todelete;
13666: }
13667: my %customadds;
13668: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
13669: if (@newcustom) {
13670: map { $customadds{$_} = 1; } @newcustom;
13671: }
13672: my %imgdeletions;
13673: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13674: if (@todeleteimages) {
13675: map { $imgdeletions{$_} = 1; } @todeleteimages;
13676: }
13677: my $maxnum = $env{'form.ltitools_maxnum'};
13678: for (my $i=0; $i<=$maxnum; $i++) {
13679: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13680: $itemid =~ s/\D+//g;
1.267 raeburn 13681: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13682: if ($deletions{$itemid}) {
13683: if ($domconfig{$action}{$itemid}{'image'}) {
13684: #FIXME need to obsolete item in RES space
13685: }
13686: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13687: next;
13688: } else {
13689: my $newpos = $env{'form.ltitools_'.$itemid};
13690: $newpos =~ s/\D+//g;
1.322 raeburn 13691: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13692: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13693: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13694: $changes{$itemid} = 1;
13695: }
13696: }
1.297 raeburn 13697: foreach my $item ('key','secret') {
13698: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13699: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13700: $changes{$itemid} = 1;
13701: }
13702: }
1.267 raeburn 13703: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13704: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13705: }
13706: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13707: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13708: }
1.323 raeburn 13709: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13710: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13711: } else {
13712: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13713: }
13714: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13715: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13716: $changes{$itemid} = 1;
13717: }
13718: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13719: $changes{$itemid} = 1;
13720: }
1.267 raeburn 13721: foreach my $size ('width','height') {
13722: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13723: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13724: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13725: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13726: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13727: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13728: $changes{$itemid} = 1;
13729: }
13730: } else {
13731: $changes{$itemid} = 1;
13732: }
1.296 raeburn 13733: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13734: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13735: $changes{$itemid} = 1;
13736: }
13737: }
13738: }
13739: foreach my $item ('linktext','explanation') {
13740: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13741: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13742: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13743: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13744: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13745: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13746: $changes{$itemid} = 1;
13747: }
13748: } else {
13749: $changes{$itemid} = 1;
13750: }
13751: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13752: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13753: $changes{$itemid} = 1;
13754: }
1.267 raeburn 13755: }
13756: }
13757: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13758: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13759: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13760: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13761: } else {
13762: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13763: }
13764: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13765: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13766: $changes{$itemid} = 1;
13767: }
13768: } else {
13769: $changes{$itemid} = 1;
13770: }
13771: foreach my $extra ('passback','roster') {
13772: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13773: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13774: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13775: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13776: $lifetime =~ s/^\s+|\s+$//g;
13777: if ($lifetime =~ /^\d+\.?\d*$/) {
13778: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13779: }
13780: }
1.267 raeburn 13781: }
13782: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13783: $changes{$itemid} = 1;
13784: }
1.319 raeburn 13785: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13786: $changes{$itemid} = 1;
13787: }
1.267 raeburn 13788: }
1.273 raeburn 13789: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13790: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13791: if (grep(/^\Q$item\E$/,@courseconfig)) {
13792: $confhash{$itemid}{'crsconf'}{$item} = 1;
13793: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13794: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13795: $changes{$itemid} = 1;
13796: }
13797: } else {
13798: $changes{$itemid} = 1;
13799: }
13800: }
13801: }
1.267 raeburn 13802: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13803: foreach my $field (@fields) {
13804: if ($possfield{$field}) {
13805: if ($field eq 'roles') {
13806: foreach my $role (@courseroles) {
13807: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13808: if (($choice ne '') && ($posslti{$choice})) {
13809: $confhash{$itemid}{'roles'}{$role} = $choice;
13810: if ($role eq 'cc') {
13811: $confhash{$itemid}{'roles'}{'co'} = $choice;
13812: }
13813: }
13814: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13815: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13816: $changes{$itemid} = 1;
13817: }
13818: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13819: $changes{$itemid} = 1;
13820: }
13821: }
13822: } else {
13823: $confhash{$itemid}{'fields'}{$field} = 1;
13824: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13825: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13826: $changes{$itemid} = 1;
13827: }
13828: } else {
13829: $changes{$itemid} = 1;
13830: }
13831: }
13832: }
13833: }
1.324 raeburn 13834: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13835: if ($confhash{$itemid}{'fields'}{'user'}) {
13836: if ($env{'form.ltitools_userincdom_'.$i}) {
13837: $confhash{$itemid}{'incdom'} = 1;
13838: }
13839: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13840: $changes{$itemid} = 1;
13841: }
13842: }
13843: }
1.267 raeburn 13844: $allpos[$newpos] = $itemid;
13845: }
13846: if ($imgdeletions{$itemid}) {
13847: $changes{$itemid} = 1;
13848: #FIXME need to obsolete item in RES space
13849: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13850: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13851: $itemid,$configuserok,$switchserver,
13852: $author_ok);
13853: if ($imgurl) {
13854: $confhash{$itemid}{'image'} = $imgurl;
13855: $changes{$itemid} = 1;
13856: }
13857: if ($error) {
13858: &Apache::lonnet::logthis($error);
13859: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13860: }
13861: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13862: $confhash{$itemid}{'image'} =
13863: $domconfig{$action}{$itemid}{'image'};
13864: }
13865: if ($customadds{$i}) {
13866: my $name = $env{'form.ltitools_custom_name_'.$i};
13867: $name =~ s/(`)/'/g;
13868: $name =~ s/^\s+//;
13869: $name =~ s/\s+$//;
13870: my $value = $env{'form.ltitools_custom_value_'.$i};
13871: $value =~ s/(`)/'/g;
13872: $value =~ s/^\s+//;
13873: $value =~ s/\s+$//;
13874: if ($name ne '') {
13875: $confhash{$itemid}{'custom'}{$name} = $value;
13876: $changes{$itemid} = 1;
13877: }
13878: }
13879: my %customdels;
13880: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13881: if (@customdeletions) {
13882: $changes{$itemid} = 1;
13883: }
13884: map { $customdels{$_} = 1; } @customdeletions;
13885: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13886: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13887: unless ($customdels{$key}) {
13888: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13889: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13890: }
13891: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13892: $changes{$itemid} = 1;
13893: }
13894: }
13895: }
13896: }
13897: unless ($changes{$itemid}) {
13898: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13899: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13900: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13901: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13902: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13903: $changes{$itemid} = 1;
13904: last;
13905: }
13906: }
13907: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13908: $changes{$itemid} = 1;
13909: }
13910: }
13911: last if ($changes{$itemid});
13912: }
13913: }
13914: }
13915: }
13916: }
13917: if (@allpos > 0) {
13918: my $idx = 0;
13919: foreach my $itemid (@allpos) {
13920: if ($itemid ne '') {
13921: $confhash{$itemid}{'order'} = $idx;
13922: if (ref($domconfig{$action}) eq 'HASH') {
13923: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13924: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13925: $changes{$itemid} = 1;
13926: }
13927: }
13928: }
13929: $idx ++;
13930: }
13931: }
13932: }
13933: my %ltitoolshash = (
13934: $action => { %confhash }
13935: );
13936: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13937: $dom);
13938: if ($putresult eq 'ok') {
1.297 raeburn 13939: my %ltienchash = (
13940: $action => { %encconfig }
13941: );
1.384 raeburn 13942: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 13943: if (keys(%changes) > 0) {
13944: my $cachetime = 24*60*60;
1.297 raeburn 13945: my %ltiall = %confhash;
13946: foreach my $id (keys(%ltiall)) {
13947: if (ref($encconfig{$id}) eq 'HASH') {
13948: foreach my $item ('key','secret') {
13949: $ltiall{$id}{$item} = $encconfig{$id}{$item};
13950: }
13951: }
13952: }
13953: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 13954: if (ref($lastactref) eq 'HASH') {
13955: $lastactref->{'ltitools'} = 1;
13956: }
13957: $resulttext = &mt('Changes made:').'<ul>';
13958: my %bynum;
13959: foreach my $itemid (sort(keys(%changes))) {
13960: my $position = $confhash{$itemid}{'order'};
13961: $bynum{$position} = $itemid;
13962: }
13963: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13964: my $itemid = $bynum{$pos};
13965: if (ref($confhash{$itemid}) ne 'HASH') {
13966: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13967: } else {
13968: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
13969: if ($confhash{$itemid}{'image'}) {
13970: $resulttext .= ' '.
13971: '<img src="'.$confhash{$itemid}{'image'}.'"'.
13972: ' alt="'.&mt('Tool Provider icon').'" />';
13973: }
13974: $resulttext .= '</li><ul>';
13975: my $position = $pos + 1;
13976: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 13977: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 13978: if ($confhash{$itemid}{$item} ne '') {
13979: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13980: }
13981: }
1.297 raeburn 13982: if ($encconfig{$itemid}{'key'} ne '') {
13983: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
13984: }
13985: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 13986: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 13987: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 13988: $resulttext .= ('*'x$num).'</li>';
13989: }
1.273 raeburn 13990: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 13991: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 13992: my $numconfig = 0;
13993: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
13994: foreach my $item (@possconfig) {
13995: if ($confhash{$itemid}{'crsconf'}{$item}) {
13996: $numconfig ++;
1.296 raeburn 13997: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 13998: }
13999: }
14000: }
14001: if (!$numconfig) {
1.372 raeburn 14002: $resulttext .= ' '.&mt('None');
1.273 raeburn 14003: }
14004: $resulttext .= '</li>';
1.267 raeburn 14005: foreach my $item ('passback','roster') {
14006: $resulttext .= '<li>'.$lt{$item}.' ';
14007: if ($confhash{$itemid}{$item}) {
14008: $resulttext .= &mt('Yes');
1.319 raeburn 14009: if ($confhash{$itemid}{$item.'valid'}) {
14010: if ($item eq 'passback') {
14011: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
14012: $confhash{$itemid}{$item.'valid'});
14013: } else {
14014: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
14015: $confhash{$itemid}{$item.'valid'});
14016: }
14017: }
1.267 raeburn 14018: } else {
14019: $resulttext .= &mt('No');
14020: }
14021: $resulttext .= '</li>';
14022: }
14023: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
14024: my $displaylist;
14025: if ($confhash{$itemid}{'display'}{'target'}) {
14026: $displaylist = &mt('Display target').': '.
14027: $confhash{$itemid}{'display'}{'target'}.',';
14028: }
14029: foreach my $size ('width','height') {
14030: if ($confhash{$itemid}{'display'}{$size}) {
14031: $displaylist .= (' 'x2).$lt{$size}.': '.
14032: $confhash{$itemid}{'display'}{$size}.',';
14033: }
14034: }
14035: if ($displaylist) {
14036: $displaylist =~ s/,$//;
14037: $resulttext .= '<li>'.$displaylist.'</li>';
14038: }
1.296 raeburn 14039: foreach my $item ('linktext','explanation') {
14040: if ($confhash{$itemid}{'display'}{$item}) {
14041: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
14042: }
14043: }
14044: }
1.267 raeburn 14045: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14046: my $fieldlist;
14047: foreach my $field (@allfields) {
14048: if ($confhash{$itemid}{'fields'}{$field}) {
14049: $fieldlist .= (' 'x2).$lt{$field}.',';
14050: }
14051: }
14052: if ($fieldlist) {
14053: $fieldlist =~ s/,$//;
1.324 raeburn 14054: if ($confhash{$itemid}{'fields'}{'user'}) {
14055: if ($confhash{$itemid}{'incdom'}) {
14056: $fieldlist .= ' ('.&mt('username:domain').')';
14057: } else {
14058: $fieldlist .= ' ('.&mt('username').')';
14059: }
14060: }
1.267 raeburn 14061: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
14062: }
14063: }
14064: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
14065: my $rolemaps;
14066: foreach my $role (@courseroles) {
14067: if ($confhash{$itemid}{'roles'}{$role}) {
14068: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14069: $confhash{$itemid}{'roles'}{$role}.',';
14070: }
14071: }
14072: if ($rolemaps) {
14073: $rolemaps =~ s/,$//;
14074: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14075: }
14076: }
14077: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
14078: my $customlist;
14079: if (keys(%{$confhash{$itemid}{'custom'}})) {
14080: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
14081: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
14082: }
14083: }
14084: if ($customlist) {
1.317 raeburn 14085: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 14086: }
14087: }
14088: $resulttext .= '</ul></li>';
14089: }
14090: }
14091: $resulttext .= '</ul>';
14092: } else {
14093: $resulttext = &mt('No changes made.');
14094: }
14095: } else {
14096: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14097: }
14098: if ($errors) {
14099: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14100: $errors.'</ul>';
14101: }
14102: return $resulttext;
14103: }
14104:
14105: sub process_ltitools_image {
14106: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
14107: my $filename = $env{'form.'.$caller.'.filename'};
14108: my ($error,$url);
14109: my ($width,$height) = (21,21);
14110: if ($configuserok eq 'ok') {
14111: if ($switchserver) {
14112: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
14113: $switchserver);
14114: } elsif ($author_ok eq 'ok') {
14115: my ($result,$imageurl,$madethumb) =
14116: &publishlogo($r,'upload',$caller,$dom,$confname,
14117: "ltitools/$itemid/icon",$width,$height);
14118: if ($result eq 'ok') {
14119: if ($madethumb) {
14120: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14121: my $imagethumb = "$path/tn-".$imagefile;
14122: $url = $imagethumb;
14123: } else {
14124: $url = $imageurl;
14125: }
14126: } else {
14127: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14128: }
14129: } else {
14130: $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);
14131: }
14132: } else {
14133: $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);
14134: }
14135: return ($url,$error);
14136: }
14137:
14138: sub get_ltitools_id {
14139: my ($cdom,$title) = @_;
14140: # get lock on ltitools db
14141: my $lockhash = {
14142: lock => $env{'user.name'}.
14143: ':'.$env{'user.domain'},
14144: };
14145: my $tries = 0;
14146: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14147: my ($id,$error);
14148:
14149: while (($gotlock ne 'ok') && ($tries<10)) {
14150: $tries ++;
14151: sleep (0.1);
14152: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14153: }
14154: if ($gotlock eq 'ok') {
14155: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
14156: if ($currids{'lock'}) {
14157: delete($currids{'lock'});
14158: if (keys(%currids)) {
14159: my @curr = sort { $a <=> $b } keys(%currids);
14160: if ($curr[-1] =~ /^\d+$/) {
14161: $id = 1 + $curr[-1];
14162: }
14163: } else {
14164: $id = 1;
14165: }
14166: if ($id) {
14167: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
14168: $error = 'nostore';
14169: }
14170: } else {
14171: $error = 'nonumber';
14172: }
14173: }
14174: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
14175: } else {
14176: $error = 'nolock';
14177: }
14178: return ($id,$error);
14179: }
14180:
1.372 raeburn 14181: sub modify_proctoring {
14182: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14183: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14184: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14185: my $confname = $dom.'-domainconfig';
14186: my $servadm = $r->dir_config('lonAdmEMail');
14187: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14188: my %providernames = &proctoring_providernames();
14189: my $maxnum = scalar(keys(%providernames));
14190:
14191: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14192: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14193: if (ref($requref) eq 'HASH') {
14194: %requserfields = %{$requref};
14195: }
14196: if (ref($opturef) eq 'HASH') {
14197: %optuserfields = %{$opturef};
14198: }
14199: if (ref($defref) eq 'HASH') {
14200: %defaults = %{$defref};
14201: }
14202: if (ref($extref) eq 'HASH') {
14203: %extended = %{$extref};
14204: }
14205: if (ref($crsref) eq 'HASH') {
14206: %crsconf = %{$crsref};
14207: }
14208: if (ref($rolesref) eq 'ARRAY') {
14209: @courseroles = @{$rolesref};
14210: }
14211: if (ref($ltiref) eq 'ARRAY') {
14212: @ltiroles = @{$ltiref};
14213: }
14214:
14215: if (ref($domconfig{$action}) eq 'HASH') {
14216: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14217: if (@todeleteimages) {
14218: map { $imgdeletions{$_} = 1; } @todeleteimages;
14219: }
14220: }
14221: my %customadds;
14222: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14223: if (@newcustom) {
14224: map { $customadds{$_} = 1; } @newcustom;
14225: }
14226: foreach my $provider (sort(keys(%providernames))) {
14227: $confhash{$provider} = {};
14228: my $pos = $env{'form.proctoring_pos_'.$provider};
14229: $pos =~ s/\D+//g;
14230: $allpos[$pos] = $provider;
14231: my (%current,%currentenc);
14232: my $showroles = 0;
14233: if (ref($domconfig{$action}) eq 'HASH') {
14234: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14235: %current = %{$domconfig{$action}{$provider}};
14236: foreach my $item ('key','secret') {
14237: $currentenc{$item} = $current{$item};
14238: delete($current{$item});
14239: }
14240: }
14241: }
14242: if ($env{'form.proctoring_available_'.$provider}) {
14243: $confhash{$provider}{'available'} = 1;
14244: unless ($current{'available'}) {
14245: $changes{$provider} = 1;
14246: }
14247: } else {
14248: %{$confhash{$provider}} = %current;
14249: %{$encconfhash{$provider}} = %currentenc;
14250: $confhash{$provider}{'available'} = 0;
14251: if ($current{'available'}) {
14252: $changes{$provider} = 1;
14253: }
14254: }
14255: if ($confhash{$provider}{'available'}) {
14256: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14257: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14258: if ($field eq 'lifetime') {
14259: if ($possval =~ /^\d+$/) {
14260: $confhash{$provider}{$field} = $possval;
14261: }
14262: } elsif ($field eq 'version') {
14263: if ($possval =~ /^\d+\.\d+$/) {
14264: $confhash{$provider}{$field} = $possval;
14265: }
14266: } elsif ($field eq 'sigmethod') {
14267: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14268: $confhash{$provider}{$field} = $possval;
14269: }
14270: } elsif ($field eq 'url') {
14271: $confhash{$provider}{$field} = $possval;
14272: } elsif (($field eq 'key') || ($field eq 'secret')) {
14273: $encconfhash{$provider}{$field} = $possval;
14274: unless ($currentenc{$field} eq $possval) {
14275: $changes{$provider} = 1;
14276: }
14277: }
14278: unless (($field eq 'key') || ($field eq 'secret')) {
14279: unless ($current{$field} eq $confhash{$provider}{$field}) {
14280: $changes{$provider} = 1;
14281: }
14282: }
14283: }
14284: if ($imgdeletions{$provider}) {
14285: $changes{$provider} = 1;
14286: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14287: my ($imageurl,$error) =
14288: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14289: $configuserok,$switchserver,$author_ok);
14290: if ($imageurl) {
14291: $confhash{$provider}{'image'} = $imageurl;
14292: $changes{$provider} = 1;
14293: }
14294: if ($error) {
14295: &Apache::lonnet::logthis($error);
14296: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14297: }
14298: } elsif (exists($current{'image'})) {
14299: $confhash{$provider}{'image'} = $current{'image'};
14300: }
14301: if (ref($requserfields{$provider}) eq 'ARRAY') {
14302: if (@{$requserfields{$provider}} > 0) {
14303: if (grep(/^user$/,@{$requserfields{$provider}})) {
14304: if ($env{'form.proctoring_userincdom_'.$provider}) {
14305: $confhash{$provider}{'incdom'} = 1;
14306: }
14307: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14308: $changes{$provider} = 1;
14309: }
14310: }
14311: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14312: $showroles = 1;
14313: }
14314: }
14315: }
14316: $confhash{$provider}{'fields'} = [];
14317: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14318: if (@{$optuserfields{$provider}} > 0) {
14319: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14320: foreach my $field (@{$optuserfields{$provider}}) {
14321: if (grep(/^\Q$field\E$/,@optfields)) {
14322: push(@{$confhash{$provider}{'fields'}},$field);
14323: }
14324: }
14325: }
14326: if (ref($current{'fields'}) eq 'ARRAY') {
14327: unless ($changes{$provider}) {
14328: my @new = sort(@{$confhash{$provider}{'fields'}});
14329: my @old = sort(@{$current{'fields'}});
14330: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14331: if (@diffs) {
14332: $changes{$provider} = 1;
14333: }
14334: }
14335: } elsif (@{$confhash{$provider}{'fields'}}) {
14336: $changes{$provider} = 1;
14337: }
14338: }
14339: if (ref($defaults{$provider}) eq 'ARRAY') {
14340: if (@{$defaults{$provider}} > 0) {
14341: my %options;
14342: if (ref($extended{$provider}) eq 'HASH') {
14343: %options = %{$extended{$provider}};
14344: }
14345: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14346: foreach my $field (@{$defaults{$provider}}) {
14347: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14348: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14349: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14350: push(@{$confhash{$provider}{'defaults'}},$poss);
14351: }
14352: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14353: foreach my $inner (keys(%{$options{$field}})) {
14354: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14355: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14356: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14357: $confhash{$provider}{'defaults'}{$inner} = $poss;
14358: }
14359: } else {
14360: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14361: }
14362: }
14363: } else {
14364: if (grep(/^\Q$field\E$/,@checked)) {
14365: push(@{$confhash{$provider}{'defaults'}},$field);
14366: }
14367: }
14368: }
14369: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14370: if (ref($current{'defaults'}) eq 'ARRAY') {
14371: unless ($changes{$provider}) {
14372: my @new = sort(@{$confhash{$provider}{'defaults'}});
14373: my @old = sort(@{$current{'defaults'}});
14374: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14375: if (@diffs) {
14376: $changes{$provider} = 1;
14377: }
14378: }
14379: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14380: if (@{$current{'defaults'}}) {
14381: $changes{$provider} = 1;
14382: }
14383: }
14384: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14385: if (ref($current{'defaults'}) eq 'HASH') {
14386: unless ($changes{$provider}) {
14387: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14388: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14389: $changes{$provider} = 1;
14390: last;
14391: }
14392: }
14393: }
14394: unless ($changes{$provider}) {
14395: foreach my $key (keys(%{$current{'defaults'}})) {
14396: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14397: $changes{$provider} = 1;
14398: last;
14399: }
14400: }
14401: }
14402: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14403: $changes{$provider} = 1;
14404: }
14405: }
14406: }
14407: }
14408: if (ref($crsconf{$provider}) eq 'ARRAY') {
14409: if (@{$crsconf{$provider}} > 0) {
14410: $confhash{$provider}{'crsconf'} = [];
14411: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14412: foreach my $crsfield (@{$crsconf{$provider}}) {
14413: if (grep(/^\Q$crsfield\E$/,@checked)) {
14414: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14415: }
14416: }
14417: if (ref($current{'crsconf'}) eq 'ARRAY') {
14418: unless ($changes{$provider}) {
14419: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14420: my @old = sort(@{$current{'crsconf'}});
14421: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14422: if (@diffs) {
14423: $changes{$provider} = 1;
14424: }
14425: }
14426: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14427: $changes{$provider} = 1;
14428: }
14429: }
14430: }
14431: if ($showroles) {
14432: $confhash{$provider}{'roles'} = {};
14433: foreach my $role (@courseroles) {
14434: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14435: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14436: $confhash{$provider}{'roles'}{$role} = $poss;
14437: }
14438: }
14439: unless ($changes{$provider}) {
14440: if (ref($current{'roles'}) eq 'HASH') {
14441: foreach my $role (keys(%{$current{'roles'}})) {
14442: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14443: $changes{$provider} = 1;
14444: last
14445: }
14446: }
14447: unless ($changes{$provider}) {
14448: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14449: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14450: $changes{$provider} = 1;
14451: last;
14452: }
14453: }
14454: }
14455: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14456: $changes{$provider} = 1;
14457: }
14458: }
14459: }
14460: if (ref($current{'custom'}) eq 'HASH') {
14461: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14462: foreach my $key (keys(%{$current{'custom'}})) {
14463: if (grep(/^\Q$key\E$/,@customdels)) {
14464: $changes{$provider} = 1;
14465: } else {
14466: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14467: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14468: $changes{$provider} = 1;
14469: }
14470: }
14471: }
14472: }
14473: if ($customadds{$provider}) {
14474: my $name = $env{'form.proctoring_custom_name_'.$provider};
14475: $name =~ s/(`)/'/g;
14476: $name =~ s/^\s+//;
14477: $name =~ s/\s+$//;
14478: my $value = $env{'form.proctoring_custom_value_'.$provider};
14479: $value =~ s/(`)/'/g;
14480: $value =~ s/^\s+//;
14481: $value =~ s/\s+$//;
14482: if ($name ne '') {
14483: $confhash{$provider}{'custom'}{$name} = $value;
14484: $changes{$provider} = 1;
14485: }
14486: }
14487: }
14488: }
14489: if (@allpos > 0) {
14490: my $idx = 0;
14491: foreach my $provider (@allpos) {
14492: if ($provider ne '') {
14493: $confhash{$provider}{'order'} = $idx;
14494: unless ($changes{$provider}) {
14495: if (ref($domconfig{$action}) eq 'HASH') {
14496: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14497: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14498: $changes{$provider} = 1;
14499: }
14500: }
14501: }
14502: }
14503: $idx ++;
14504: }
14505: }
14506: }
14507: my %proc_hash = (
14508: $action => { %confhash }
14509: );
14510: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14511: $dom);
14512: if ($putresult eq 'ok') {
14513: my %proc_enchash = (
14514: $action => { %encconfhash }
14515: );
1.384 raeburn 14516: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14517: if (keys(%changes) > 0) {
14518: my $cachetime = 24*60*60;
14519: my %procall = %confhash;
14520: foreach my $provider (keys(%procall)) {
14521: if (ref($encconfhash{$provider}) eq 'HASH') {
14522: foreach my $key ('key','secret') {
14523: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14524: }
14525: }
14526: }
14527: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14528: if (ref($lastactref) eq 'HASH') {
14529: $lastactref->{'proctoring'} = 1;
14530: }
14531: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14532: my %bynum;
14533: foreach my $provider (sort(keys(%changes))) {
14534: my $position = $confhash{$provider}{'order'};
14535: $bynum{$position} = $provider;
14536: }
14537: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14538: my $provider = $bynum{$pos};
14539: my %lt = &proctoring_titles($provider);
14540: my %fieldtitles = &proctoring_fieldtitles($provider);
14541: if (!$confhash{$provider}{'available'}) {
14542: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14543: } else {
14544: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14545: if ($confhash{$provider}{'image'}) {
14546: $resulttext .= ' '.
14547: '<img src="'.$confhash{$provider}{'image'}.'"'.
14548: ' alt="'.&mt('Proctoring icon').'" />';
14549: }
14550: $resulttext .= '<ul>';
14551: my $position = $pos + 1;
14552: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14553: foreach my $key ('version','sigmethod','url','lifetime') {
14554: if ($confhash{$provider}{$key} ne '') {
14555: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14556: }
14557: }
14558: if ($encconfhash{$provider}{'key'} ne '') {
14559: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14560: }
14561: if ($encconfhash{$provider}{'secret'} ne '') {
14562: $resulttext .= '<li>'.$lt{'secret'}.': ';
14563: my $num = length($encconfhash{$provider}{'secret'});
14564: $resulttext .= ('*'x$num).'</li>';
14565: }
14566: my (@fields,$showroles);
14567: if (ref($requserfields{$provider}) eq 'ARRAY') {
14568: push(@fields,@{$requserfields{$provider}});
14569: }
14570: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14571: push(@fields,@{$confhash{$provider}{'fields'}});
14572: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14573: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14574: }
14575: if (@fields) {
14576: if (grep(/^roles$/,@fields)) {
14577: $showroles = 1;
14578: }
14579: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14580: join('", "', map { $lt{$_}; } @fields).'"</li>';
14581: }
14582: if (ref($requserfields{$provider}) eq 'ARRAY') {
14583: if (grep(/^user$/,@{$requserfields{$provider}})) {
14584: if ($confhash{$provider}{'incdom'}) {
14585: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14586: } else {
14587: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14588: }
14589: }
14590: }
14591: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14592: if (@{$confhash{$provider}{'defaults'}} > 0) {
14593: $resulttext .= '<li>'.$lt{'defa'};
14594: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14595: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14596: }
14597: $resulttext =~ s/,$//;
14598: $resulttext .= '</li>';
14599: }
14600: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14601: if (keys(%{$confhash{$provider}{'defaults'}})) {
14602: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14603: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14604: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14605: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14606: }
14607: }
14608: $resulttext .= '</ul></li>';
14609: }
14610: }
14611: if (ref($crsconf{$provider}) eq 'ARRAY') {
14612: if (@{$crsconf{$provider}} > 0) {
14613: $resulttext .= '<li>'.&mt('Configurable in course:');
14614: my $numconfig = 0;
14615: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14616: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14617: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14618: $numconfig ++;
14619: if ($provider eq 'examity') {
14620: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14621: } else {
14622: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14623: }
14624: }
14625: $resulttext =~ s/,$//;
14626: }
14627: }
14628: if (!$numconfig) {
14629: $resulttext .= ' '.&mt('None');
14630: }
14631: $resulttext .= '</li>';
14632: }
14633: }
14634: if ($showroles) {
14635: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14636: my $rolemaps;
14637: foreach my $role (@courseroles) {
14638: if ($confhash{$provider}{'roles'}{$role}) {
14639: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14640: $confhash{$provider}{'roles'}{$role}.',';
14641: }
14642: }
14643: if ($rolemaps) {
14644: $rolemaps =~ s/,$//;
14645: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14646: }
14647: }
14648: }
14649: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
14650: my $customlist;
14651: if (keys(%{$confhash{$provider}{'custom'}})) {
14652: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
14653: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
14654: }
14655: $customlist =~ s/,$//;
14656: }
14657: if ($customlist) {
14658: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
14659: }
14660: }
14661: $resulttext .= '</ul></li>';
14662: }
14663: }
14664: $resulttext .= '</ul>';
14665: } else {
14666: $resulttext = &mt('No changes made.');
14667: }
14668: } else {
14669: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14670: }
14671: if ($errors) {
14672: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14673: $errors.'</ul>';
14674: }
14675: return $resulttext;
14676: }
14677:
14678: sub process_proctoring_image {
14679: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14680: my $filename = $env{'form.'.$caller.'.filename'};
14681: my ($error,$url);
14682: my ($width,$height) = (21,21);
14683: if ($configuserok eq 'ok') {
14684: if ($switchserver) {
14685: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14686: $switchserver);
14687: } elsif ($author_ok eq 'ok') {
14688: my ($result,$imageurl,$madethumb) =
14689: &publishlogo($r,'upload',$caller,$dom,$confname,
14690: "proctoring/$provider/icon",$width,$height);
14691: if ($result eq 'ok') {
14692: if ($madethumb) {
14693: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14694: my $imagethumb = "$path/tn-".$imagefile;
14695: $url = $imagethumb;
14696: } else {
14697: $url = $imageurl;
14698: }
14699: } else {
14700: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14701: }
14702: } else {
14703: $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);
14704: }
14705: } else {
14706: $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);
14707: }
14708: return ($url,$error);
14709: }
14710:
1.320 raeburn 14711: sub modify_lti {
14712: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14713: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14714: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14715: my (%posslti,%posslticrs,%posscrstype);
14716: my @courseroles = ('cc','in','ta','ep','st');
14717: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14718: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14719: my @coursetypes = ('official','unofficial','community','textbook','placement');
14720: my %coursetypetitles = &Apache::lonlocal::texthash (
14721: official => 'Official',
14722: unofficial => 'Unofficial',
14723: community => 'Community',
14724: textbook => 'Textbook',
14725: placement => 'Placement Test',
14726: );
1.325 raeburn 14727: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14728: my %lt = <i_names();
14729: map { $posslti{$_} = 1; } @ltiroles;
14730: map { $posslticrs{$_} = 1; } @lticourseroles;
14731: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14732:
1.326 raeburn 14733: my %menutitles = <imenu_titles();
14734:
1.320 raeburn 14735: my (@items,%deletions,%itemids);
14736: if ($env{'form.lti_add'}) {
14737: my $consumer = $env{'form.lti_consumer_add'};
14738: $consumer =~ s/(`)/'/g;
14739: ($newid,my $error) = &get_lti_id($dom,$consumer);
14740: if ($newid) {
14741: $itemids{'add'} = $newid;
14742: push(@items,'add');
14743: $changes{$newid} = 1;
14744: } else {
14745: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14746: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14747: }
14748: }
14749: if (ref($domconfig{$action}) eq 'HASH') {
14750: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14751: if (@todelete) {
14752: map { $deletions{$_} = 1; } @todelete;
14753: }
14754: my $maxnum = $env{'form.lti_maxnum'};
1.390 ! raeburn 14755: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 14756: my $itemid = $env{'form.lti_id_'.$i};
14757: $itemid =~ s/\D+//g;
14758: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14759: if ($deletions{$itemid}) {
14760: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14761: } else {
1.390 ! raeburn 14762: push(@items,$i);
! 14763: $itemids{$i} = $itemid;
1.320 raeburn 14764: }
14765: }
14766: }
14767: }
14768: foreach my $idx (@items) {
14769: my $itemid = $itemids{$idx};
14770: next unless ($itemid);
1.390 ! raeburn 14771: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 14772: $position =~ s/\D+//g;
14773: if ($position ne '') {
14774: $allpos[$position] = $itemid;
14775: }
1.345 raeburn 14776: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 14777: my $formitem = 'form.lti_'.$item.'_'.$idx;
14778: $env{$formitem} =~ s/(`)/'/g;
14779: if ($item eq 'lifetime') {
14780: $env{$formitem} =~ s/[^\d.]//g;
14781: }
14782: if ($env{$formitem} ne '') {
14783: if (($item eq 'key') || ($item eq 'secret')) {
14784: $encconfig{$itemid}{$item} = $env{$formitem};
14785: } else {
14786: $confhash{$itemid}{$item} = $env{$formitem};
14787: unless (($idx eq 'add') || ($changes{$itemid})) {
14788: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14789: $changes{$itemid} = 1;
14790: }
14791: }
14792: }
14793: }
14794: }
14795: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14796: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14797: }
1.345 raeburn 14798: if ($confhash{$itemid}{'requser'}) {
14799: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14800: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14801: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14802: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14803: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14804: my $mapuser = $env{'form.lti_customuser_'.$idx};
14805: $mapuser =~ s/(`)/'/g;
14806: $mapuser =~ s/^\s+|\s+$//g;
14807: $confhash{$itemid}{'mapuser'} = $mapuser;
14808: }
14809: foreach my $ltirole (@lticourseroles) {
14810: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14811: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14812: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14813: }
14814: }
14815: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14816: my @makeuser;
14817: foreach my $ltirole (sort(@possmakeuser)) {
14818: if ($posslti{$ltirole}) {
14819: push(@makeuser,$ltirole);
14820: }
14821: }
14822: $confhash{$itemid}{'makeuser'} = \@makeuser;
14823: if (@makeuser) {
14824: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14825: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14826: $confhash{$itemid}{'lcauth'} = $lcauth;
14827: if ($lcauth ne 'internal') {
14828: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14829: $lcauthparm =~ s/^(\s+|\s+)$//g;
14830: $lcauthparm =~ s/`//g;
14831: if ($lcauthparm ne '') {
14832: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14833: }
14834: }
14835: } else {
14836: $confhash{$itemid}{'lcauth'} = 'lti';
14837: }
1.320 raeburn 14838: }
1.345 raeburn 14839: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14840: if (@possinstdata) {
14841: foreach my $field (@possinstdata) {
14842: if (exists($fieldtitles{$field})) {
14843: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14844: }
14845: }
14846: }
1.345 raeburn 14847: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14848: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14849: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14850: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14851: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14852: $mapcrs =~ s/(`)/'/g;
14853: $mapcrs =~ s/^\s+|\s+$//g;
14854: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14855: }
14856: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14857: my @crstypes;
14858: foreach my $type (sort(@posstypes)) {
14859: if ($posscrstype{$type}) {
14860: push(@crstypes,$type);
1.325 raeburn 14861: }
14862: }
1.345 raeburn 14863: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14864: if ($env{'form.lti_makecrs_'.$idx}) {
14865: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 14866: }
1.345 raeburn 14867: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14868: my @selfenroll;
14869: foreach my $type (sort(@possenroll)) {
14870: if ($posslticrs{$type}) {
14871: push(@selfenroll,$type);
14872: }
1.320 raeburn 14873: }
1.345 raeburn 14874: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14875: if ($env{'form.lti_crssec_'.$idx}) {
14876: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14877: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14878: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14879: my $section = $env{'form.lti_customsection_'.$idx};
14880: $section =~ s/(`)/'/g;
14881: $section =~ s/^\s+|\s+$//g;
14882: if ($section ne '') {
14883: $confhash{$itemid}{'section'} = $section;
14884: }
1.320 raeburn 14885: }
14886: }
1.363 raeburn 14887: if ($env{'form.lti_callback_'.$idx}) {
14888: if ($env{'form.lti_callbackparam_'.$idx}) {
14889: my $callback = $env{'form.lti_callbackparam_'.$idx};
14890: $callback =~ s/^\s+|\s+$//g;
14891: $confhash{$itemid}{'callback'} = $callback;
14892: }
14893: }
1.345 raeburn 14894: foreach my $field ('passback','roster','topmenu','inlinemenu') {
14895: if ($env{'form.lti_'.$field.'_'.$idx}) {
14896: $confhash{$itemid}{$field} = 1;
14897: }
1.320 raeburn 14898: }
1.345 raeburn 14899: if ($env{'form.lti_passback_'.$idx}) {
14900: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14901: $confhash{$itemid}{'passbackformat'} = '1.0';
14902: } else {
14903: $confhash{$itemid}{'passbackformat'} = '1.1';
14904: }
1.337 raeburn 14905: }
1.345 raeburn 14906: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14907: $confhash{$itemid}{lcmenu} = [];
14908: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14909: foreach my $field (@possmenu) {
14910: if (exists($menutitles{$field})) {
14911: if ($field eq 'grades') {
14912: next unless ($env{'form.lti_inlinemenu_'.$idx});
14913: }
14914: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14915: }
14916: }
14917: }
1.345 raeburn 14918: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 14919: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 14920: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 14921: $changes{$itemid} = 1;
14922: }
14923: }
1.320 raeburn 14924: unless ($changes{$itemid}) {
1.345 raeburn 14925: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
14926: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14927: $changes{$itemid} = 1;
14928: }
1.345 raeburn 14929: }
1.320 raeburn 14930: }
1.345 raeburn 14931: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
14932: unless ($changes{$itemid}) {
14933: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
14934: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14935: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
14936: $confhash{$itemid}{$field});
14937: if (@diffs) {
14938: $changes{$itemid} = 1;
14939: }
14940: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
14941: $changes{$itemid} = 1;
14942: }
14943: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14944: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 14945: $changes{$itemid} = 1;
14946: }
14947: }
1.345 raeburn 14948: }
14949: }
14950: unless ($changes{$itemid}) {
14951: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
14952: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14953: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
14954: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
14955: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 14956: $changes{$itemid} = 1;
14957: last;
14958: }
14959: }
1.345 raeburn 14960: unless ($changes{$itemid}) {
14961: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14962: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14963: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
14964: $changes{$itemid} = 1;
14965: last;
14966: }
14967: }
14968: }
14969: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
14970: $changes{$itemid} = 1;
1.320 raeburn 14971: }
1.345 raeburn 14972: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14973: unless ($changes{$itemid}) {
14974: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
14975: $changes{$itemid} = 1;
14976: }
1.320 raeburn 14977: }
14978: }
14979: }
14980: }
14981: }
14982: }
14983: if (@allpos > 0) {
14984: my $idx = 0;
14985: foreach my $itemid (@allpos) {
14986: if ($itemid ne '') {
14987: $confhash{$itemid}{'order'} = $idx;
14988: if (ref($domconfig{$action}) eq 'HASH') {
14989: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14990: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14991: $changes{$itemid} = 1;
14992: }
14993: }
14994: }
14995: $idx ++;
14996: }
14997: }
14998: }
14999: my %ltihash = (
15000: $action => { %confhash }
15001: );
15002: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
15003: $dom);
15004: if ($putresult eq 'ok') {
15005: my %ltienchash = (
15006: $action => { %encconfig }
15007: );
1.384 raeburn 15008: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320 raeburn 15009: if (keys(%changes) > 0) {
15010: my $cachetime = 24*60*60;
15011: my %ltiall = %confhash;
15012: foreach my $id (keys(%ltiall)) {
15013: if (ref($encconfig{$id}) eq 'HASH') {
15014: foreach my $item ('key','secret') {
15015: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15016: }
15017: }
15018: }
15019: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15020: if (ref($lastactref) eq 'HASH') {
15021: $lastactref->{'lti'} = 1;
15022: }
15023: $resulttext = &mt('Changes made:').'<ul>';
15024: my %bynum;
15025: foreach my $itemid (sort(keys(%changes))) {
15026: my $position = $confhash{$itemid}{'order'};
15027: $bynum{$position} = $itemid;
15028: }
15029: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15030: my $itemid = $bynum{$pos};
15031: if (ref($confhash{$itemid}) ne 'HASH') {
15032: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15033: } else {
1.390 ! raeburn 15034: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15035: my $position = $pos + 1;
15036: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15037: foreach my $item ('version','lifetime') {
15038: if ($confhash{$itemid}{$item} ne '') {
15039: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15040: }
15041: }
15042: if ($encconfig{$itemid}{'key'} ne '') {
15043: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15044: }
15045: if ($encconfig{$itemid}{'secret'} ne '') {
15046: $resulttext .= '<li>'.$lt{'secret'}.': ';
15047: my $num = length($encconfig{$itemid}{'secret'});
15048: $resulttext .= ('*'x$num).'</li>';
15049: }
1.345 raeburn 15050: if ($confhash{$itemid}{'requser'}) {
15051: if ($confhash{$itemid}{'mapuser'}) {
15052: my $shownmapuser;
15053: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15054: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15055: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15056: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15057: } else {
15058: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15059: }
1.345 raeburn 15060: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15061: }
1.345 raeburn 15062: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15063: my $rolemaps;
15064: foreach my $role (@ltiroles) {
15065: if ($confhash{$itemid}{'maproles'}{$role}) {
15066: $rolemaps .= (' 'x2).$role.'='.
15067: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15068: 'Course').',';
15069: }
15070: }
15071: if ($rolemaps) {
15072: $rolemaps =~ s/,$//;
15073: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15074: }
15075: }
15076: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15077: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15078: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15079: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15080: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15081: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15082: } else {
15083: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15084: $confhash{$itemid}{'lcauth'});
15085: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15086: $resulttext .= '; '.&mt('a randomly generated password will be created');
15087: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15088: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15089: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15090: }
15091: } else {
15092: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15093: }
15094: }
15095: $resulttext .= '</li>';
15096: } else {
15097: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15098: }
1.320 raeburn 15099: }
1.345 raeburn 15100: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15101: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15102: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15103: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15104: } else {
1.345 raeburn 15105: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15106: }
1.320 raeburn 15107: }
1.345 raeburn 15108: if ($confhash{$itemid}{'mapcrs'}) {
15109: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15110: }
15111: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15112: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15113: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15114: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15115: '</li>';
15116: } else {
15117: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15118: }
1.325 raeburn 15119: }
1.345 raeburn 15120: if ($confhash{$itemid}{'makecrs'}) {
15121: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 15122: } else {
1.345 raeburn 15123: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 15124: }
1.345 raeburn 15125: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15126: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15127: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15128: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15129: '</li>';
15130: } else {
15131: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15132: }
1.320 raeburn 15133: }
1.345 raeburn 15134: if ($confhash{$itemid}{'section'}) {
15135: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15136: $resulttext .= '<li>'.&mt('User section from standard field:').
15137: ' (course_section_sourcedid)'.'</li>';
15138: } else {
15139: $resulttext .= '<li>'.&mt('User section from:').' '.
15140: $confhash{$itemid}{'section'}.'</li>';
15141: }
1.320 raeburn 15142: } else {
1.345 raeburn 15143: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 15144: }
1.363 raeburn 15145: if ($confhash{$itemid}{'callback'}) {
15146: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15147: } else {
15148: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
15149: }
1.345 raeburn 15150: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15151: $resulttext .= '<li>'.$lt{$item}.': ';
15152: if ($confhash{$itemid}{$item}) {
15153: $resulttext .= &mt('Yes');
15154: if ($item eq 'passback') {
15155: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15156: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15157: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15158: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15159: }
1.337 raeburn 15160: }
1.345 raeburn 15161: } else {
15162: $resulttext .= &mt('No');
1.337 raeburn 15163: }
1.345 raeburn 15164: $resulttext .= '</li>';
1.320 raeburn 15165: }
1.345 raeburn 15166: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15167: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15168: $resulttext .= '<li>'.&mt('Menu items:').' '.
15169: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15170: } else {
15171: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15172: }
1.326 raeburn 15173: }
15174: }
1.320 raeburn 15175: $resulttext .= '</ul></li>';
15176: }
15177: }
15178: $resulttext .= '</ul>';
15179: } else {
15180: $resulttext = &mt('No changes made.');
15181: }
15182: } else {
15183: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15184: }
15185: if ($errors) {
15186: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15187: $errors.'</ul>';
15188: }
15189: return $resulttext;
15190: }
15191:
15192: sub get_lti_id {
15193: my ($domain,$consumer) = @_;
15194: # get lock on lti db
15195: my $lockhash = {
15196: lock => $env{'user.name'}.
15197: ':'.$env{'user.domain'},
15198: };
15199: my $tries = 0;
15200: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15201: my ($id,$error);
15202:
15203: while (($gotlock ne 'ok') && ($tries<10)) {
15204: $tries ++;
15205: sleep (0.1);
15206: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15207: }
15208: if ($gotlock eq 'ok') {
15209: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15210: if ($currids{'lock'}) {
15211: delete($currids{'lock'});
15212: if (keys(%currids)) {
15213: my @curr = sort { $a <=> $b } keys(%currids);
15214: if ($curr[-1] =~ /^\d+$/) {
15215: $id = 1 + $curr[-1];
15216: }
15217: } else {
15218: $id = 1;
15219: }
15220: if ($id) {
15221: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15222: $error = 'nostore';
15223: }
15224: } else {
15225: $error = 'nonumber';
15226: }
15227: }
15228: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15229: } else {
15230: $error = 'nolock';
15231: }
15232: return ($id,$error);
15233: }
15234:
1.3 raeburn 15235: sub modify_autoenroll {
1.205 raeburn 15236: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15237: my ($resulttext,%changes);
15238: my %currautoenroll;
15239: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15240: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15241: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15242: }
15243: }
15244: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15245: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15246: sender => 'Sender for notification messages',
1.274 raeburn 15247: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
15248: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15249: my @offon = ('off','on');
1.17 raeburn 15250: my $sender_uname = $env{'form.sender_uname'};
15251: my $sender_domain = $env{'form.sender_domain'};
15252: if ($sender_domain eq '') {
15253: $sender_uname = '';
15254: } elsif ($sender_uname eq '') {
15255: $sender_domain = '';
15256: }
1.129 raeburn 15257: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 15258: my $failsafe = $env{'form.autoenroll_failsafe'};
15259: $failsafe =~ s{^\s+|\s+$}{}g;
15260: if ($failsafe =~ /\D/) {
15261: undef($failsafe);
15262: }
1.1 raeburn 15263: my %autoenrollhash = (
1.129 raeburn 15264: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15265: 'sender_uname' => $sender_uname,
15266: 'sender_domain' => $sender_domain,
15267: 'co-owners' => $coowners,
1.274 raeburn 15268: 'autofailsafe' => $failsafe,
1.1 raeburn 15269: }
15270: );
1.4 raeburn 15271: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15272: $dom);
1.1 raeburn 15273: if ($putresult eq 'ok') {
15274: if (exists($currautoenroll{'run'})) {
15275: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15276: $changes{'run'} = 1;
15277: }
15278: } elsif ($autorun) {
15279: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15280: $changes{'run'} = 1;
1.1 raeburn 15281: }
15282: }
1.17 raeburn 15283: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15284: $changes{'sender'} = 1;
15285: }
1.17 raeburn 15286: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15287: $changes{'sender'} = 1;
15288: }
1.129 raeburn 15289: if ($currautoenroll{'co-owners'} ne '') {
15290: if ($currautoenroll{'co-owners'} ne $coowners) {
15291: $changes{'coowners'} = 1;
15292: }
15293: } elsif ($coowners) {
15294: $changes{'coowners'} = 1;
1.274 raeburn 15295: }
15296: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
15297: $changes{'autofailsafe'} = 1;
15298: }
1.1 raeburn 15299: if (keys(%changes) > 0) {
15300: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15301: if ($changes{'run'}) {
1.1 raeburn 15302: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15303: }
15304: if ($changes{'sender'}) {
1.17 raeburn 15305: if ($sender_uname eq '' || $sender_domain eq '') {
15306: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15307: } else {
15308: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15309: }
1.1 raeburn 15310: }
1.129 raeburn 15311: if ($changes{'coowners'}) {
15312: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15313: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15314: if (ref($lastactref) eq 'HASH') {
15315: $lastactref->{'domainconfig'} = 1;
15316: }
1.129 raeburn 15317: }
1.274 raeburn 15318: if ($changes{'autofailsafe'}) {
15319: if ($failsafe ne '') {
1.299 raeburn 15320: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 15321: } else {
1.299 raeburn 15322: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 15323: }
15324: &Apache::lonnet::get_domain_defaults($dom,1);
15325: if (ref($lastactref) eq 'HASH') {
15326: $lastactref->{'domdefaults'} = 1;
15327: }
15328: }
1.1 raeburn 15329: $resulttext .= '</ul>';
15330: } else {
15331: $resulttext = &mt('No changes made to auto-enrollment settings');
15332: }
15333: } else {
1.11 albertel 15334: $resulttext = '<span class="LC_error">'.
15335: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15336: }
1.3 raeburn 15337: return $resulttext;
1.1 raeburn 15338: }
15339:
15340: sub modify_autoupdate {
1.3 raeburn 15341: my ($dom,%domconfig) = @_;
1.1 raeburn 15342: my ($resulttext,%currautoupdate,%fields,%changes);
15343: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
15344: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
15345: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
15346: }
15347: }
15348: my @offon = ('off','on');
15349: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 15350: run => 'Auto-update:',
15351: classlists => 'Updates to user information in classlists?',
15352: unexpired => 'Skip updates for users without active or future roles?',
15353: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 15354: );
1.44 raeburn 15355: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 15356: my %fieldtitles = &Apache::lonlocal::texthash (
15357: id => 'Student/Employee ID',
1.20 raeburn 15358: permanentemail => 'E-mail address',
1.1 raeburn 15359: lastname => 'Last Name',
15360: firstname => 'First Name',
15361: middlename => 'Middle Name',
1.132 raeburn 15362: generation => 'Generation',
1.1 raeburn 15363: );
1.142 raeburn 15364: $othertitle = &mt('All users');
1.1 raeburn 15365: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 15366: $othertitle = &mt('Other users');
1.1 raeburn 15367: }
15368: foreach my $key (keys(%env)) {
15369: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 15370: my ($usertype,$item) = ($1,$2);
15371: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
15372: if ($usertype eq 'default') {
15373: push(@{$fields{$1}},$2);
15374: } elsif (ref($types) eq 'ARRAY') {
15375: if (grep(/^\Q$usertype\E$/,@{$types})) {
15376: push(@{$fields{$1}},$2);
15377: }
15378: }
15379: }
1.1 raeburn 15380: }
15381: }
1.131 raeburn 15382: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
15383: @lockablenames = sort(@lockablenames);
15384: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
15385: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15386: if (@changed) {
15387: $changes{'lockablenames'} = 1;
15388: }
15389: } else {
15390: if (@lockablenames) {
15391: $changes{'lockablenames'} = 1;
15392: }
15393: }
1.1 raeburn 15394: my %updatehash = (
15395: autoupdate => { run => $env{'form.autoupdate_run'},
15396: classlists => $env{'form.classlists'},
1.385 raeburn 15397: unexpired => $env{'form.unexpired'},
1.1 raeburn 15398: fields => {%fields},
1.131 raeburn 15399: lockablenames => \@lockablenames,
1.1 raeburn 15400: }
15401: );
1.385 raeburn 15402: my $lastactivedays;
15403: if ($env{'form.lastactive'}) {
15404: $lastactivedays = $env{'form.lastactivedays'};
15405: $lastactivedays =~ s/^\s+|\s+$//g;
15406: unless ($lastactivedays =~ /^\d+$/) {
15407: undef($lastactivedays);
15408: $env{'form.lastactive'} = 0;
15409: }
15410: }
15411: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 15412: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 15413: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 15414: if (exists($updatehash{autoupdate}{$key})) {
15415: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
15416: $changes{$key} = 1;
15417: }
15418: }
15419: } elsif ($key eq 'fields') {
15420: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 15421: foreach my $item (@{$types},'default') {
1.1 raeburn 15422: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
15423: my $change = 0;
15424: foreach my $type (@{$currautoupdate{$key}{$item}}) {
15425: if (!exists($fields{$item})) {
15426: $change = 1;
1.132 raeburn 15427: last;
1.1 raeburn 15428: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15429: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15430: $change = 1;
1.132 raeburn 15431: last;
1.1 raeburn 15432: }
15433: }
15434: }
15435: if ($change) {
15436: push(@{$changes{$key}},$item);
15437: }
1.26 raeburn 15438: }
1.1 raeburn 15439: }
15440: }
1.131 raeburn 15441: } elsif ($key eq 'lockablenames') {
15442: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15443: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15444: if (@changed) {
15445: $changes{'lockablenames'} = 1;
15446: }
15447: } else {
15448: if (@lockablenames) {
15449: $changes{'lockablenames'} = 1;
15450: }
15451: }
15452: }
15453: }
15454: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15455: if (@lockablenames) {
15456: $changes{'lockablenames'} = 1;
1.1 raeburn 15457: }
15458: }
1.385 raeburn 15459: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15460: if ($updatehash{'autoupdate'}{'unexpired'}) {
15461: $changes{'unexpired'} = 1;
15462: }
15463: }
15464: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15465: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15466: $changes{'lastactive'} = 1;
15467: }
15468: }
1.26 raeburn 15469: foreach my $item (@{$types},'default') {
15470: if (defined($fields{$item})) {
15471: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15472: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15473: my $change = 0;
15474: if (ref($fields{$item}) eq 'ARRAY') {
15475: foreach my $type (@{$fields{$item}}) {
15476: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15477: $change = 1;
15478: last;
15479: }
15480: }
15481: }
15482: if ($change) {
15483: push(@{$changes{'fields'}},$item);
15484: }
15485: } else {
1.26 raeburn 15486: push(@{$changes{'fields'}},$item);
15487: }
15488: } else {
15489: push(@{$changes{'fields'}},$item);
1.1 raeburn 15490: }
15491: }
15492: }
15493: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15494: $dom);
15495: if ($putresult eq 'ok') {
15496: if (keys(%changes) > 0) {
15497: $resulttext = &mt('Changes made:').'<ul>';
15498: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15499: if ($key eq 'lockablenames') {
15500: $resulttext .= '<li>';
15501: if (@lockablenames) {
15502: $usertypes->{'default'} = $othertitle;
15503: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15504: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15505: } else {
15506: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15507: }
15508: $resulttext .= '</li>';
15509: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15510: foreach my $item (@{$changes{$key}}) {
15511: my @newvalues;
15512: foreach my $type (@{$fields{$item}}) {
15513: push(@newvalues,$fieldtitles{$type});
15514: }
1.3 raeburn 15515: my $newvaluestr;
15516: if (@newvalues > 0) {
15517: $newvaluestr = join(', ',@newvalues);
15518: } else {
15519: $newvaluestr = &mt('none');
1.6 raeburn 15520: }
1.1 raeburn 15521: if ($item eq 'default') {
1.26 raeburn 15522: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15523: } else {
1.26 raeburn 15524: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15525: }
15526: }
15527: } else {
15528: my $newvalue;
15529: if ($key eq 'run') {
15530: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 15531: } elsif ($key eq 'lastactive') {
15532: $newvalue = $offon[$env{'form.lastactive'}];
15533: unless ($lastactivedays eq '') {
15534: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15535: }
1.1 raeburn 15536: } else {
15537: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15538: }
1.1 raeburn 15539: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15540: }
15541: }
15542: $resulttext .= '</ul>';
15543: } else {
1.3 raeburn 15544: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15545: }
15546: } else {
1.11 albertel 15547: $resulttext = '<span class="LC_error">'.
15548: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15549: }
1.3 raeburn 15550: return $resulttext;
1.1 raeburn 15551: }
15552:
1.125 raeburn 15553: sub modify_autocreate {
15554: my ($dom,%domconfig) = @_;
15555: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15556: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15557: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15558: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15559: }
15560: }
15561: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15562: req => 'Auto-creation of validated requests for official courses',
15563: xmldc => 'Identity of course creator of courses from XML files',
15564: );
15565: my @types = ('xml','req');
15566: foreach my $item (@types) {
15567: $newvals{$item} = $env{'form.autocreate_'.$item};
15568: $newvals{$item} =~ s/\D//g;
15569: $newvals{$item} = 0 if ($newvals{$item} eq '');
15570: }
15571: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 15572: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15573: unless (exists($domcoords{$newvals{'xmldc'}})) {
15574: $newvals{'xmldc'} = '';
15575: }
15576: %autocreatehash = (
15577: autocreate => { xml => $newvals{'xml'},
15578: req => $newvals{'req'},
15579: }
15580: );
15581: if ($newvals{'xmldc'} ne '') {
15582: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15583: }
15584: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15585: $dom);
15586: if ($putresult eq 'ok') {
15587: my @items = @types;
15588: if ($newvals{'xml'}) {
15589: push(@items,'xmldc');
15590: }
15591: foreach my $item (@items) {
15592: if (exists($currautocreate{$item})) {
15593: if ($currautocreate{$item} ne $newvals{$item}) {
15594: $changes{$item} = 1;
15595: }
15596: } elsif ($newvals{$item}) {
15597: $changes{$item} = 1;
15598: }
15599: }
15600: if (keys(%changes) > 0) {
15601: my @offon = ('off','on');
15602: $resulttext = &mt('Changes made:').'<ul>';
15603: foreach my $item (@types) {
15604: if ($changes{$item}) {
15605: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 15606: $resulttext .= '<li>'.
15607: &mt("$title{$item} set to [_1]$newtxt [_2]",
15608: '<b>','</b>').
15609: '</li>';
1.125 raeburn 15610: }
15611: }
15612: if ($changes{'xmldc'}) {
15613: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15614: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 15615: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15616: }
15617: $resulttext .= '</ul>';
15618: } else {
15619: $resulttext = &mt('No changes made to auto-creation settings');
15620: }
15621: } else {
15622: $resulttext = '<span class="LC_error">'.
15623: &mt('An error occurred: [_1]',$putresult).'</span>';
15624: }
15625: return $resulttext;
15626: }
15627:
1.23 raeburn 15628: sub modify_directorysrch {
1.295 raeburn 15629: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15630: my ($resulttext,%changes);
15631: my %currdirsrch;
15632: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15633: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15634: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15635: }
15636: }
1.277 raeburn 15637: my %title = ( available => 'Institutional directory search available',
15638: localonly => 'Other domains can search institution',
15639: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 15640: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15641: searchby => 'Search types',
15642: searchtypes => 'Search latitude');
15643: my @offon = ('off','on');
1.24 raeburn 15644: my @otherdoms = ('Yes','No');
1.23 raeburn 15645:
1.25 raeburn 15646: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15647: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15648: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15649:
1.44 raeburn 15650: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15651: if (keys(%{$usertypes}) == 0) {
15652: @cansearch = ('default');
15653: } else {
15654: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15655: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15656: if (!grep(/^\Q$type\E$/,@cansearch)) {
15657: push(@{$changes{'cansearch'}},$type);
15658: }
1.23 raeburn 15659: }
1.26 raeburn 15660: foreach my $type (@cansearch) {
15661: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15662: push(@{$changes{'cansearch'}},$type);
15663: }
1.23 raeburn 15664: }
1.26 raeburn 15665: } else {
15666: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15667: }
15668: }
15669:
15670: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15671: foreach my $by (@{$currdirsrch{'searchby'}}) {
15672: if (!grep(/^\Q$by\E$/,@searchby)) {
15673: push(@{$changes{'searchby'}},$by);
15674: }
15675: }
15676: foreach my $by (@searchby) {
15677: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15678: push(@{$changes{'searchby'}},$by);
15679: }
15680: }
15681: } else {
15682: push(@{$changes{'searchby'}},@searchby);
15683: }
1.25 raeburn 15684:
15685: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15686: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15687: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15688: push(@{$changes{'searchtypes'}},$type);
15689: }
15690: }
15691: foreach my $type (@searchtypes) {
15692: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15693: push(@{$changes{'searchtypes'}},$type);
15694: }
15695: }
15696: } else {
15697: if (exists($currdirsrch{'searchtypes'})) {
15698: foreach my $type (@searchtypes) {
15699: if ($type ne $currdirsrch{'searchtypes'}) {
15700: push(@{$changes{'searchtypes'}},$type);
15701: }
15702: }
15703: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15704: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15705: }
15706: } else {
15707: push(@{$changes{'searchtypes'}},@searchtypes);
15708: }
15709: }
15710:
1.23 raeburn 15711: my %dirsrch_hash = (
15712: directorysrch => { available => $env{'form.dirsrch_available'},
15713: cansearch => \@cansearch,
1.277 raeburn 15714: localonly => $env{'form.dirsrch_instlocalonly'},
15715: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15716: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15717: searchby => \@searchby,
1.25 raeburn 15718: searchtypes => \@searchtypes,
1.23 raeburn 15719: }
15720: );
15721: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15722: $dom);
15723: if ($putresult eq 'ok') {
15724: if (exists($currdirsrch{'available'})) {
15725: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15726: $changes{'available'} = 1;
15727: }
15728: } else {
15729: if ($env{'form.dirsrch_available'} eq '1') {
15730: $changes{'available'} = 1;
15731: }
15732: }
1.277 raeburn 15733: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15734: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15735: $changes{'lcavailable'} = 1;
15736: }
1.277 raeburn 15737: } else {
15738: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15739: $changes{'lcavailable'} = 1;
15740: }
15741: }
1.24 raeburn 15742: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15743: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15744: $changes{'localonly'} = 1;
15745: }
1.24 raeburn 15746: } else {
1.277 raeburn 15747: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15748: $changes{'localonly'} = 1;
15749: }
15750: }
1.277 raeburn 15751: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15752: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15753: $changes{'lclocalonly'} = 1;
15754: }
1.277 raeburn 15755: } else {
15756: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15757: $changes{'lclocalonly'} = 1;
15758: }
15759: }
1.23 raeburn 15760: if (keys(%changes) > 0) {
15761: $resulttext = &mt('Changes made:').'<ul>';
15762: if ($changes{'available'}) {
15763: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15764: }
1.277 raeburn 15765: if ($changes{'lcavailable'}) {
15766: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15767: }
1.24 raeburn 15768: if ($changes{'localonly'}) {
1.277 raeburn 15769: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15770: }
1.277 raeburn 15771: if ($changes{'lclocalonly'}) {
15772: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15773: }
1.23 raeburn 15774: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15775: my $chgtext;
1.26 raeburn 15776: if (ref($usertypes) eq 'HASH') {
15777: if (keys(%{$usertypes}) > 0) {
15778: foreach my $type (@{$types}) {
15779: if (grep(/^\Q$type\E$/,@cansearch)) {
15780: $chgtext .= $usertypes->{$type}.'; ';
15781: }
15782: }
15783: if (grep(/^default$/,@cansearch)) {
15784: $chgtext .= $othertitle;
15785: } else {
15786: $chgtext =~ s/\; $//;
15787: }
1.210 raeburn 15788: $resulttext .=
1.178 raeburn 15789: '<li>'.
15790: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15791: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15792: '</li>';
1.23 raeburn 15793: }
15794: }
15795: }
15796: if (ref($changes{'searchby'}) eq 'ARRAY') {
15797: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15798: my $chgtext;
15799: foreach my $type (@{$titleorder}) {
15800: if (grep(/^\Q$type\E$/,@searchby)) {
15801: if (defined($searchtitles->{$type})) {
15802: $chgtext .= $searchtitles->{$type}.'; ';
15803: }
15804: }
15805: }
15806: $chgtext =~ s/\; $//;
15807: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15808: }
1.25 raeburn 15809: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15810: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15811: my $chgtext;
15812: foreach my $type (@{$srchtypeorder}) {
15813: if (grep(/^\Q$type\E$/,@searchtypes)) {
15814: if (defined($srchtypes_desc->{$type})) {
15815: $chgtext .= $srchtypes_desc->{$type}.'; ';
15816: }
15817: }
15818: }
15819: $chgtext =~ s/\; $//;
1.178 raeburn 15820: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15821: }
15822: $resulttext .= '</ul>';
1.295 raeburn 15823: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15824: if (ref($lastactref) eq 'HASH') {
15825: $lastactref->{'directorysrch'} = 1;
15826: }
1.23 raeburn 15827: } else {
1.277 raeburn 15828: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15829: }
15830: } else {
15831: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15832: &mt('An error occurred: [_1]',$putresult).'</span>';
15833: }
15834: return $resulttext;
15835: }
15836:
1.28 raeburn 15837: sub modify_contacts {
1.205 raeburn 15838: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15839: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15840: if (ref($domconfig{'contacts'}) eq 'HASH') {
15841: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15842: $currsetting{$key} = $domconfig{'contacts'}{$key};
15843: }
15844: }
1.286 raeburn 15845: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15846: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15847: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15848: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15849: my @toggles = ('reporterrors','reportupdates','reportstatus');
15850: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15851: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15852: foreach my $type (@mailings) {
15853: @{$newsetting{$type}} =
15854: &Apache::loncommon::get_env_multiple('form.'.$type);
15855: foreach my $item (@contacts) {
15856: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15857: $contacts_hash{contacts}{$type}{$item} = 1;
15858: } else {
15859: $contacts_hash{contacts}{$type}{$item} = 0;
15860: }
1.289 raeburn 15861: }
1.28 raeburn 15862: $others{$type} = $env{'form.'.$type.'_others'};
15863: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15864: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15865: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15866: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15867: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15868: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15869: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15870: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15871: }
1.134 raeburn 15872: }
1.28 raeburn 15873: }
15874: foreach my $item (@contacts) {
15875: $to{$item} = $env{'form.'.$item};
15876: $contacts_hash{'contacts'}{$item} = $to{$item};
15877: }
1.203 raeburn 15878: foreach my $item (@toggles) {
15879: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15880: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15881: }
15882: }
1.340 raeburn 15883: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15884: foreach my $item (@lonstatus) {
15885: if ($item eq 'excluded') {
15886: my (%serverhomes,@excluded);
15887: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15888: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15889: if (@possexcluded) {
15890: foreach my $id (sort(@possexcluded)) {
15891: if ($serverhomes{$id}) {
15892: push(@excluded,$id);
15893: }
15894: }
15895: }
15896: if (@excluded) {
15897: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15898: }
15899: } elsif ($item eq 'weights') {
1.377 raeburn 15900: foreach my $type ('E','W','N','U') {
1.340 raeburn 15901: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15902: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15903: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15904: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15905: $env{'form.error'.$item.'_'.$type};
15906: }
15907: }
15908: }
15909: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15910: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15911: if ($env{'form.error'.$item} =~ /^\d+$/) {
15912: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15913: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15914: }
15915: }
15916: }
15917: }
1.286 raeburn 15918: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15919: foreach my $field (@{$fields}) {
15920: if (ref($possoptions->{$field}) eq 'ARRAY') {
15921: my $value = $env{'form.helpform_'.$field};
15922: $value =~ s/^\s+|\s+$//g;
15923: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 15924: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 15925: if ($field eq 'screenshot') {
15926: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15927: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 15928: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 15929: }
15930: }
15931: }
15932: }
15933: }
15934: }
1.315 raeburn 15935: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15936: my (@statuses,%usertypeshash,@overrides);
15937: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15938: @statuses = @{$types};
15939: if (ref($usertypes) eq 'HASH') {
15940: %usertypeshash = %{$usertypes};
15941: }
15942: }
15943: if (@statuses) {
15944: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15945: foreach my $type (@possoverrides) {
15946: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15947: push(@overrides,$type);
15948: }
15949: }
15950: if (@overrides) {
15951: foreach my $type (@overrides) {
15952: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15953: foreach my $item (@contacts) {
15954: if (grep(/^\Q$item\E$/,@standard)) {
15955: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15956: $newsetting{'override_'.$type}{$item} = 1;
15957: } else {
15958: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15959: $newsetting{'override_'.$type}{$item} = 0;
15960: }
15961: }
15962: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15963: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15964: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15965: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15966: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15967: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15968: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15969: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15970: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15971: }
15972: }
15973: }
15974: }
1.28 raeburn 15975: if (keys(%currsetting) > 0) {
15976: foreach my $item (@contacts) {
15977: if ($to{$item} ne $currsetting{$item}) {
15978: $changes{$item} = 1;
15979: }
15980: }
15981: foreach my $type (@mailings) {
15982: foreach my $item (@contacts) {
15983: if (ref($currsetting{$type}) eq 'HASH') {
15984: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15985: push(@{$changes{$type}},$item);
15986: }
15987: } else {
15988: push(@{$changes{$type}},@{$newsetting{$type}});
15989: }
15990: }
15991: if ($others{$type} ne $currsetting{$type}{'others'}) {
15992: push(@{$changes{$type}},'others');
15993: }
1.289 raeburn 15994: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15995: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15996: push(@{$changes{$type}},'bcc');
15997: }
1.286 raeburn 15998: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15999: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16000: push(@{$changes{$type}},'include');
16001: }
16002: }
16003: }
16004: if (ref($fields) eq 'ARRAY') {
16005: if (ref($currsetting{'helpform'}) eq 'HASH') {
16006: foreach my $field (@{$fields}) {
16007: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16008: push(@{$changes{'helpform'}},$field);
16009: }
16010: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16011: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16012: push(@{$changes{'helpform'}},'maxsize');
16013: }
16014: }
16015: }
16016: } else {
16017: foreach my $field (@{$fields}) {
16018: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16019: push(@{$changes{'helpform'}},$field);
16020: }
16021: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16022: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16023: push(@{$changes{'helpform'}},'maxsize');
16024: }
16025: }
16026: }
1.134 raeburn 16027: }
1.28 raeburn 16028: }
1.315 raeburn 16029: if (@statuses) {
16030: if (ref($currsetting{'overrides'}) eq 'HASH') {
16031: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16032: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16033: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16034: foreach my $item (@contacts,'bcc','others','include') {
16035: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16036: push(@{$changes{'overrides'}},$key);
16037: last;
16038: }
16039: }
16040: } else {
16041: push(@{$changes{'overrides'}},$key);
16042: }
16043: }
16044: }
16045: foreach my $key (@overrides) {
16046: unless (exists($currsetting{'overrides'}{$key})) {
16047: push(@{$changes{'overrides'}},$key);
16048: }
16049: }
16050: } else {
16051: foreach my $key (@overrides) {
16052: push(@{$changes{'overrides'}},$key);
16053: }
16054: }
16055: }
1.340 raeburn 16056: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16057: foreach my $key ('excluded','weights','threshold','sysmail') {
16058: if ($key eq 'excluded') {
16059: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16060: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16061: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16062: (@{$currsetting{'lonstatus'}{$key}})) {
16063: my @diffs =
16064: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16065: $currsetting{'lonstatus'}{$key});
16066: if (@diffs) {
16067: push(@{$changes{'lonstatus'}},$key);
16068: }
16069: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16070: push(@{$changes{'lonstatus'}},$key);
16071: }
16072: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16073: (@{$currsetting{'lonstatus'}{$key}})) {
16074: push(@{$changes{'lonstatus'}},$key);
16075: }
16076: } elsif ($key eq 'weights') {
16077: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16078: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16079: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16080: foreach my $type ('E','W','N','U') {
1.340 raeburn 16081: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16082: $currsetting{'lonstatus'}{$key}{$type}) {
16083: push(@{$changes{'lonstatus'}},$key);
16084: last;
16085: }
16086: }
16087: } else {
1.341 raeburn 16088: foreach my $type ('E','W','N','U') {
1.340 raeburn 16089: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16090: push(@{$changes{'lonstatus'}},$key);
16091: last;
16092: }
16093: }
16094: }
16095: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16096: foreach my $type ('E','W','N','U') {
1.340 raeburn 16097: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16098: push(@{$changes{'lonstatus'}},$key);
16099: last;
16100: }
16101: }
16102: }
16103: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16104: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16105: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16106: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16107: push(@{$changes{'lonstatus'}},$key);
16108: }
16109: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16110: push(@{$changes{'lonstatus'}},$key);
16111: }
16112: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16113: push(@{$changes{'lonstatus'}},$key);
16114: }
16115: }
16116: }
16117: } else {
16118: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16119: foreach my $key ('excluded','weights','threshold','sysmail') {
16120: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16121: push(@{$changes{'lonstatus'}},$key);
16122: }
16123: }
16124: }
16125: }
1.28 raeburn 16126: } else {
16127: my %default;
16128: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16129: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16130: $default{'errormail'} = 'adminemail';
16131: $default{'packagesmail'} = 'adminemail';
16132: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16133: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16134: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16135: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16136: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16137: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16138: foreach my $item (@contacts) {
16139: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16140: $changes{$item} = 1;
1.203 raeburn 16141: }
1.28 raeburn 16142: }
16143: foreach my $type (@mailings) {
16144: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16145: push(@{$changes{$type}},@{$newsetting{$type}});
16146: }
16147: if ($others{$type} ne '') {
16148: push(@{$changes{$type}},'others');
1.134 raeburn 16149: }
1.286 raeburn 16150: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16151: if ($bcc{$type} ne '') {
16152: push(@{$changes{$type}},'bcc');
16153: }
1.286 raeburn 16154: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16155: push(@{$changes{$type}},'include');
16156: }
1.134 raeburn 16157: }
1.28 raeburn 16158: }
1.286 raeburn 16159: if (ref($fields) eq 'ARRAY') {
16160: foreach my $field (@{$fields}) {
16161: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16162: push(@{$changes{'helpform'}},$field);
16163: }
16164: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16165: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16166: push(@{$changes{'helpform'}},'maxsize');
16167: }
16168: }
16169: }
1.289 raeburn 16170: }
1.340 raeburn 16171: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16172: foreach my $key ('excluded','weights','threshold','sysmail') {
16173: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16174: push(@{$changes{'lonstatus'}},$key);
16175: }
16176: }
16177: }
1.28 raeburn 16178: }
1.203 raeburn 16179: foreach my $item (@toggles) {
16180: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16181: $changes{$item} = 1;
16182: } elsif ((!$env{'form.'.$item}) &&
16183: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16184: $changes{$item} = 1;
16185: }
16186: }
1.28 raeburn 16187: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16188: $dom);
16189: if ($putresult eq 'ok') {
16190: if (keys(%changes) > 0) {
1.205 raeburn 16191: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16192: if (ref($lastactref) eq 'HASH') {
16193: $lastactref->{'domainconfig'} = 1;
16194: }
1.28 raeburn 16195: my ($titles,$short_titles) = &contact_titles();
16196: $resulttext = &mt('Changes made:').'<ul>';
16197: foreach my $item (@contacts) {
16198: if ($changes{$item}) {
16199: $resulttext .= '<li>'.$titles->{$item}.
16200: &mt(' set to: ').
16201: '<span class="LC_cusr_emph">'.
16202: $to{$item}.'</span></li>';
16203: }
16204: }
16205: foreach my $type (@mailings) {
16206: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16207: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16208: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16209: } else {
16210: $resulttext .= '<li>'.$titles->{$type}.': ';
16211: }
1.28 raeburn 16212: my @text;
16213: foreach my $item (@{$newsetting{$type}}) {
16214: push(@text,$short_titles->{$item});
16215: }
16216: if ($others{$type} ne '') {
16217: push(@text,$others{$type});
16218: }
1.286 raeburn 16219: if (@text) {
16220: $resulttext .= '<span class="LC_cusr_emph">'.
16221: join(', ',@text).'</span>';
16222: }
16223: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16224: if ($bcc{$type} ne '') {
1.286 raeburn 16225: my $bcctext;
16226: if (@text) {
1.289 raeburn 16227: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16228: } else {
16229: $bcctext = '(Bcc)';
16230: }
16231: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16232: } elsif (!@text) {
16233: $resulttext .= &mt('No one');
16234: }
1.289 raeburn 16235: if ($includestr{$type} ne '') {
1.286 raeburn 16236: if ($includeloc{$type} eq 'b') {
16237: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16238: } elsif ($includeloc{$type} eq 's') {
16239: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16240: }
1.134 raeburn 16241: }
1.286 raeburn 16242: } elsif (!@text) {
16243: $resulttext .= &mt('No recipients');
1.134 raeburn 16244: }
16245: $resulttext .= '</li>';
1.28 raeburn 16246: }
16247: }
1.315 raeburn 16248: if (ref($changes{'overrides'}) eq 'ARRAY') {
16249: my @deletions;
16250: foreach my $type (@{$changes{'overrides'}}) {
16251: if ($usertypeshash{$type}) {
16252: if (grep(/^\Q$type\E/,@overrides)) {
16253: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16254: $usertypeshash{$type}).'<ul><li>';
16255: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16256: my @text;
16257: foreach my $item (@contacts) {
16258: if ($newsetting{'override_'.$type}{$item}) {
16259: push(@text,$short_titles->{$item});
16260: }
16261: }
16262: if ($newsetting{'override_'.$type}{'others'} ne '') {
16263: push(@text,$newsetting{'override_'.$type}{'others'});
16264: }
16265:
16266: if (@text) {
16267: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16268: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16269: }
16270: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16271: my $bcctext;
16272: if (@text) {
16273: $bcctext = ' '.&mt('with Bcc to');
16274: } else {
16275: $bcctext = '(Bcc)';
16276: }
16277: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16278: } elsif (!@text) {
16279: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16280: }
16281: $resulttext .= '</li>';
16282: if ($newsetting{'override_'.$type}{'include'} ne '') {
16283: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16284: if ($loc eq 'b') {
16285: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16286: } elsif ($loc eq 's') {
16287: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16288: }
16289: }
16290: }
16291: $resulttext .= '</li></ul></li>';
16292: } else {
16293: push(@deletions,$usertypeshash{$type});
16294: }
16295: }
16296: }
16297: if (@deletions) {
16298: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16299: join(', ',@deletions)).'</li>';
16300: }
16301: }
1.203 raeburn 16302: my @offon = ('off','on');
1.340 raeburn 16303: my $corelink = &core_link_msu();
1.203 raeburn 16304: if ($changes{'reporterrors'}) {
16305: $resulttext .= '<li>'.
16306: &mt('E-mail error reports to [_1] set to "'.
16307: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16308: $corelink).
1.203 raeburn 16309: '</li>';
16310: }
16311: if ($changes{'reportupdates'}) {
16312: $resulttext .= '<li>'.
16313: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16314: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16315: $corelink).
1.203 raeburn 16316: '</li>';
16317: }
1.340 raeburn 16318: if ($changes{'reportstatus'}) {
16319: $resulttext .= '<li>'.
16320: &mt('E-mail status if errors above threshold to [_1] set to "'.
16321: $offon[$env{'form.reportstatus'}].'".',
16322: $corelink).
16323: '</li>';
16324: }
16325: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16326: $resulttext .= '<li>'.
16327: &mt('Nightly status check e-mail settings').':<ul>';
16328: my (%defval,%use_def,%shown);
16329: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
16330: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
16331: $defval{'weights'} =
1.341 raeburn 16332: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 16333: $defval{'excluded'} = &mt('None');
16334: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
16335: foreach my $item ('threshold','sysmail','weights','excluded') {
16336: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
16337: if (($item eq 'threshold') || ($item eq 'sysmail')) {
16338: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
16339: } elsif ($item eq 'weights') {
16340: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 16341: foreach my $type ('E','W','N','U') {
1.340 raeburn 16342: $shown{$item} .= $lonstatus_names->{$type}.'=';
16343: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
16344: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
16345: } else {
16346: $shown{$item} .= $lonstatus_defs->{$type};
16347: }
16348: $shown{$item} .= ', ';
16349: }
16350: $shown{$item} =~ s/, $//;
16351: } else {
16352: $shown{$item} = $defval{$item};
16353: }
16354: } elsif ($item eq 'excluded') {
16355: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
16356: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
16357: } else {
16358: $shown{$item} = $defval{$item};
16359: }
16360: }
16361: } else {
16362: $shown{$item} = $defval{$item};
16363: }
16364: }
16365: } else {
16366: foreach my $item ('threshold','weights','excluded','sysmail') {
16367: $shown{$item} = $defval{$item};
16368: }
16369: }
16370: foreach my $item ('threshold','weights','excluded','sysmail') {
16371: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
16372: $shown{$item}).'</li>';
16373: }
16374: $resulttext .= '</ul></li>';
16375: }
1.286 raeburn 16376: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
16377: my (@optional,@required,@unused,$maxsizechg);
16378: foreach my $field (@{$changes{'helpform'}}) {
16379: if ($field eq 'maxsize') {
16380: $maxsizechg = 1;
16381: next;
16382: }
16383: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 16384: push(@optional,$field);
1.286 raeburn 16385: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
16386: push(@unused,$field);
16387: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 16388: push(@required,$field);
1.286 raeburn 16389: }
16390: }
16391: if (@optional) {
16392: $resulttext .= '<li>'.
16393: &mt('Help form fields changed to "Optional": [_1].',
16394: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
16395: '</li>';
16396: }
16397: if (@required) {
16398: $resulttext .= '<li>'.
16399: &mt('Help form fields changed to "Required": [_1].',
16400: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
16401: '</li>';
16402: }
16403: if (@unused) {
16404: $resulttext .= '<li>'.
16405: &mt('Help form fields changed to "Not shown": [_1].',
16406: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
16407: '</li>';
16408: }
16409: if ($maxsizechg) {
16410: $resulttext .= '<li>'.
16411: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
16412: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
16413: '</li>';
16414: }
16415: }
1.28 raeburn 16416: $resulttext .= '</ul>';
16417: } else {
1.288 raeburn 16418: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 16419: }
16420: } else {
16421: $resulttext = '<span class="LC_error">'.
16422: &mt('An error occurred: [_1].',$putresult).'</span>';
16423: }
16424: return $resulttext;
16425: }
16426:
1.357 raeburn 16427: sub modify_privacy {
16428: my ($dom,%domconfig) = @_;
16429: my ($resulttext,%current,%changes);
16430: if (ref($domconfig{'privacy'}) eq 'HASH') {
16431: %current = %{$domconfig{'privacy'}};
16432: }
16433: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
16434: my @items = ('domain','author','course','community');
16435: my %names = &Apache::lonlocal::texthash (
16436: domain => 'Assigned domain role(s)',
16437: author => 'Assigned co-author role(s)',
16438: course => 'Assigned course role(s)',
16439: community => 'Assigned community role',
16440: );
16441: my %roles = &Apache::lonlocal::texthash (
16442: domain => 'Domain role',
16443: author => 'Co-author role',
16444: course => 'Course role',
16445: community => 'Community role',
16446: );
16447: my %titles = &Apache::lonlocal::texthash (
16448: approval => 'Approval for role in different domain',
16449: othdom => 'User information available in other domain',
16450: priv => 'Information viewable by privileged user in same domain',
16451: unpriv => 'Information viewable by unprivileged user in same domain',
16452: instdom => 'Other domain shares institution/provider',
16453: extdom => 'Other domain has different institution/provider',
16454: none => 'Not allowed',
16455: user => 'User authorizes',
16456: domain => 'Domain Coordinator authorizes',
16457: auto => 'Unrestricted',
16458: );
16459: my %fieldnames = &Apache::lonlocal::texthash (
16460: id => 'Student/Employee ID',
16461: permanentemail => 'E-mail address',
16462: lastname => 'Last Name',
16463: firstname => 'First Name',
16464: middlename => 'Middle Name',
16465: generation => 'Generation',
16466: );
16467: my ($othertitle,$usertypes,$types) =
16468: &Apache::loncommon::sorted_inst_types($dom);
16469: my (%by_ip,%by_location,@intdoms,@instdoms);
16470: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16471:
16472: my %privacyhash = (
16473: 'approval' => {
16474: instdom => {},
16475: extdom => {},
16476: },
16477: 'othdom' => {},
16478: 'priv' => {},
16479: 'unpriv' => {},
16480: );
16481: foreach my $item (@items) {
16482: if (@instdoms > 1) {
16483: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
16484: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
16485: }
16486: if (ref($current{'approval'}) eq 'HASH') {
16487: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
16488: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
16489: $changes{'approval'} = 1;
16490: }
16491: }
16492: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
16493: $changes{'approval'} = 1;
16494: }
16495: }
16496: if (keys(%by_location) > 0) {
16497: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
16498: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
16499: }
16500: if (ref($current{'approval'}) eq 'HASH') {
16501: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
16502: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
16503: $changes{'approval'} = 1;
16504: }
16505: }
16506: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
16507: $changes{'approval'} = 1;
16508: }
16509: }
16510: foreach my $status ('priv','unpriv') {
16511: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
16512: my @newvalues;
16513: foreach my $field (@possibles) {
16514: if (grep(/^\Q$field\E$/,@fields)) {
16515: $privacyhash{$status}{$item}{$field} = 1;
16516: push(@newvalues,$field);
16517: }
16518: }
16519: @newvalues = sort(@newvalues);
16520: if (ref($current{$status}) eq 'HASH') {
16521: if (ref($current{$status}{$item}) eq 'HASH') {
16522: my @currvalues = sort(keys(%{$current{$status}{$item}}));
16523: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16524: if (@diffs > 0) {
16525: $changes{$status} = 1;
16526: }
16527: }
16528: } else {
16529: my @stdfields;
16530: foreach my $field (@fields) {
16531: if ($field eq 'id') {
16532: next if ($status eq 'unpriv');
16533: next if (($status eq 'priv') && ($item eq 'community'));
16534: }
16535: push(@stdfields,$field);
16536: }
16537: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16538: if (@diffs > 0) {
16539: $changes{$status} = 1;
16540: }
16541: }
16542: }
16543: }
16544: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
16545: my @statuses;
16546: if (ref($types) eq 'ARRAY') {
16547: @statuses = @{$types};
16548: }
16549: foreach my $type (@statuses,'default') {
16550: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
16551: my @newvalues;
16552: foreach my $field (sort(@possfields)) {
16553: if (grep(/^\Q$field\E$/,@fields)) {
16554: $privacyhash{'othdom'}{$type}{$field} = 1;
16555: push(@newvalues,$field);
16556: }
16557: }
16558: @newvalues = sort(@newvalues);
16559: if (ref($current{'othdom'}) eq 'HASH') {
16560: if (ref($current{'othdom'}{$type}) eq 'HASH') {
16561: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
16562: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16563: if (@diffs > 0) {
16564: $changes{'othdom'} = 1;
16565: }
16566: }
16567: } else {
16568: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
16569: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16570: if (@diffs > 0) {
16571: $changes{'othdom'} = 1;
16572: }
16573: }
16574: }
16575: }
16576: my %confighash = (
16577: privacy => \%privacyhash,
16578: );
16579: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16580: if ($putresult eq 'ok') {
16581: if (keys(%changes) > 0) {
16582: $resulttext = &mt('Changes made: ').'<ul>';
16583: foreach my $key ('approval','othdom','priv','unpriv') {
16584: if ($changes{$key}) {
16585: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16586: if ($key eq 'approval') {
16587: if (keys(%{$privacyhash{$key}{instdom}})) {
16588: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
16589: foreach my $item (@items) {
16590: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
16591: }
16592: $resulttext .= '</ul></li>';
16593: }
16594: if (keys(%{$privacyhash{$key}{extdom}})) {
16595: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
16596: foreach my $item (@items) {
16597: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
16598: }
16599: $resulttext .= '</ul></li>';
16600: }
16601: } elsif ($key eq 'othdom') {
16602: my @statuses;
16603: if (ref($types) eq 'ARRAY') {
16604: @statuses = @{$types};
16605: }
16606: if (ref($privacyhash{$key}) eq 'HASH') {
16607: foreach my $status (@statuses,'default') {
16608: if ($status eq 'default') {
16609: $resulttext .= '<li>'.$othertitle.': ';
16610: } elsif (ref($usertypes) eq 'HASH') {
16611: $resulttext .= '<li>'.$usertypes->{$status}.': ';
16612: } else {
16613: next;
16614: }
16615: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
16616: if (keys(%{$privacyhash{$key}{$status}})) {
16617: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
16618: } else {
16619: $resulttext .= &mt('none');
16620: }
16621: }
16622: $resulttext .= '</li>';
16623: }
16624: }
16625: } else {
16626: foreach my $item (@items) {
16627: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
16628: $resulttext .= '<li>'.$names{$item}.': ';
16629: if (keys(%{$privacyhash{$key}{$item}})) {
16630: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
16631: } else {
16632: $resulttext .= &mt('none');
16633: }
16634: $resulttext .= '</li>';
16635: }
16636: }
16637: }
16638: $resulttext .= '</ul></li>';
16639: }
16640: }
16641: } else {
16642: $resulttext = &mt('No changes made to user information settings');
16643: }
16644: } else {
16645: $resulttext = '<span class="LC_error">'.
16646: &mt('An error occurred: [_1]',$putresult).'</span>';
16647: }
16648: return $resulttext;
16649: }
16650:
1.354 raeburn 16651: sub modify_passwords {
16652: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 16653: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
16654: $updatedefaults,$updateconf);
1.354 raeburn 16655: my $customfn = 'resetpw.html';
16656: if (ref($domconfig{'passwords'}) eq 'HASH') {
16657: %current = %{$domconfig{'passwords'}};
16658: }
16659: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16660: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16661: if (ref($types) eq 'ARRAY') {
16662: @oktypes = @{$types};
16663: }
16664: push(@oktypes,'default');
16665:
16666: my %titles = &Apache::lonlocal::texthash (
16667: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
16668: intauth_check => 'Check bcrypt cost if authenticated',
16669: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16670: permanent => 'Permanent e-mail address',
16671: critical => 'Critical notification address',
16672: notify => 'Notification address',
16673: min => 'Minimum password length',
16674: max => 'Maximum password length',
16675: chars => 'Required characters',
16676: expire => 'Password expiration (days)',
1.356 raeburn 16677: numsaved => 'Number of previous passwords to save',
1.354 raeburn 16678: reset => 'Resetting Forgotten Password',
16679: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16680: rules => 'Rules for LON-CAPA Passwords',
16681: crsownerchg => 'Course Owner Changing Student Passwords',
16682: username => 'Username',
16683: email => 'E-mail address',
16684: );
16685:
16686: #
16687: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16688: #
16689: my (%curr_defaults,%save_defaults);
16690: if (ref($domconfig{'defaults'}) eq 'HASH') {
16691: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16692: if ($key =~ /^intauth_(cost|check|switch)$/) {
16693: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16694: } else {
16695: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16696: }
16697: }
16698: }
16699: my %staticdefaults = (
16700: 'resetlink' => 2,
16701: 'resetcase' => \@oktypes,
16702: 'resetprelink' => 'both',
16703: 'resetemail' => ['critical','notify','permanent'],
16704: 'intauth_cost' => 10,
16705: 'intauth_check' => 0,
16706: 'intauth_switch' => 0,
16707: );
1.365 raeburn 16708: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16709: foreach my $type (@oktypes) {
16710: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16711: }
16712: my $linklife = $env{'form.passwords_link'};
16713: $linklife =~ s/^\s+|\s+$//g;
16714: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16715: $newvalues{'resetlink'} = $linklife;
16716: if ($current{'resetlink'}) {
16717: if ($current{'resetlink'} ne $linklife) {
16718: $changes{'reset'} = 1;
16719: }
1.368 raeburn 16720: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16721: if ($staticdefaults{'resetlink'} ne $linklife) {
16722: $changes{'reset'} = 1;
16723: }
16724: }
16725: } elsif ($current{'resetlink'}) {
16726: $changes{'reset'} = 1;
16727: }
16728: my @casesens;
16729: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16730: foreach my $case (sort(@posscase)) {
16731: if (grep(/^\Q$case\E$/,@oktypes)) {
16732: push(@casesens,$case);
16733: }
16734: }
16735: $newvalues{'resetcase'} = \@casesens;
16736: if (ref($current{'resetcase'}) eq 'ARRAY') {
16737: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16738: if (@diffs > 0) {
16739: $changes{'reset'} = 1;
16740: }
1.368 raeburn 16741: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16742: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16743: if (@diffs > 0) {
16744: $changes{'reset'} = 1;
16745: }
16746: }
16747: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16748: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16749: if (exists($current{'resetprelink'})) {
16750: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16751: $changes{'reset'} = 1;
16752: }
1.368 raeburn 16753: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16754: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16755: $changes{'reset'} = 1;
16756: }
16757: }
16758: } elsif ($current{'resetprelink'}) {
16759: $changes{'reset'} = 1;
16760: }
16761: foreach my $type (@oktypes) {
16762: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16763: my @postlink;
16764: foreach my $item (sort(@possplink)) {
16765: if ($item =~ /^(email|username)$/) {
16766: push(@postlink,$item);
16767: }
16768: }
16769: $newvalues{'resetpostlink'}{$type} = \@postlink;
16770: unless ($changes{'reset'}) {
16771: if (ref($current{'resetpostlink'}) eq 'HASH') {
16772: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16773: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16774: if (@diffs > 0) {
16775: $changes{'reset'} = 1;
16776: }
16777: } else {
16778: $changes{'reset'} = 1;
16779: }
1.368 raeburn 16780: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16781: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16782: if (@diffs > 0) {
16783: $changes{'reset'} = 1;
16784: }
16785: }
16786: }
16787: }
16788: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16789: my @resetemail;
16790: foreach my $item (sort(@possemailsrc)) {
16791: if ($item =~ /^(permanent|critical|notify)$/) {
16792: push(@resetemail,$item);
16793: }
16794: }
16795: $newvalues{'resetemail'} = \@resetemail;
16796: unless ($changes{'reset'}) {
16797: if (ref($current{'resetemail'}) eq 'ARRAY') {
16798: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16799: if (@diffs > 0) {
16800: $changes{'reset'} = 1;
16801: }
1.368 raeburn 16802: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16803: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16804: if (@diffs > 0) {
16805: $changes{'reset'} = 1;
16806: }
16807: }
16808: }
16809: if ($env{'form.passwords_stdtext'} == 0) {
16810: $newvalues{'resetremove'} = 1;
16811: unless ($current{'resetremove'}) {
16812: $changes{'reset'} = 1;
16813: }
16814: } elsif ($current{'resetremove'}) {
16815: $changes{'reset'} = 1;
16816: }
16817: if ($env{'form.passwords_customfile.filename'} ne '') {
16818: my $servadm = $r->dir_config('lonAdmEMail');
16819: my ($configuserok,$author_ok,$switchserver) =
16820: &config_check($dom,$confname,$servadm);
16821: my $error;
16822: if ($configuserok eq 'ok') {
16823: if ($switchserver) {
16824: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16825: } else {
16826: if ($author_ok eq 'ok') {
16827: my ($result,$customurl) =
16828: &publishlogo($r,'upload','passwords_customfile',$dom,
16829: $confname,'customtext/resetpw','','',$customfn);
16830: if ($result eq 'ok') {
16831: $newvalues{'resetcustom'} = $customurl;
16832: $changes{'reset'} = 1;
16833: } else {
16834: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16835: }
16836: } else {
16837: $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);
16838: }
16839: }
16840: } else {
16841: $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);
16842: }
16843: if ($error) {
16844: &Apache::lonnet::logthis($error);
16845: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16846: }
16847: } elsif ($current{'resetcustom'}) {
16848: if ($env{'form.passwords_custom_del'}) {
16849: $changes{'reset'} = 1;
16850: } else {
16851: $newvalues{'resetcustom'} = $current{'resetcustom'};
16852: }
16853: }
16854: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16855: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16856: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16857: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16858: $changes{'intauth'} = 1;
16859: }
16860: } else {
16861: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16862: }
16863: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16864: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16865: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16866: $changes{'intauth'} = 1;
16867: }
16868: } else {
16869: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16870: }
16871: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16872: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16873: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16874: $changes{'intauth'} = 1;
16875: }
16876: } else {
16877: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16878: }
16879: foreach my $item ('cost','check','switch') {
16880: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16881: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16882: $updatedefaults = 1;
16883: }
16884: }
1.356 raeburn 16885: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16886: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 16887: my $ruleok;
16888: if ($rule eq 'expire') {
1.365 raeburn 16889: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
16890: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 16891: $ruleok = 1;
1.356 raeburn 16892: }
1.365 raeburn 16893: } elsif ($rule eq 'min') {
16894: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
16895: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
16896: $ruleok = 1;
16897: }
16898: }
16899: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
16900: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 16901: $ruleok = 1;
16902: }
16903: if ($ruleok) {
1.354 raeburn 16904: $newvalues{$rule} = $env{'form.passwords_'.$rule};
16905: if (exists($current{$rule})) {
16906: if ($newvalues{$rule} ne $current{$rule}) {
16907: $changes{'rules'} = 1;
16908: }
16909: } elsif ($rule eq 'min') {
16910: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
16911: $changes{'rules'} = 1;
16912: }
1.370 raeburn 16913: } else {
16914: $changes{'rules'} = 1;
1.354 raeburn 16915: }
16916: } elsif (exists($current{$rule})) {
16917: $changes{'rules'} = 1;
16918: }
16919: }
16920: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
16921: my @chars;
16922: foreach my $item (sort(@posschars)) {
16923: if ($item =~ /^(uc|lc|num|spec)$/) {
16924: push(@chars,$item);
16925: }
16926: }
16927: $newvalues{'chars'} = \@chars;
16928: unless ($changes{'rules'}) {
16929: if (ref($current{'chars'}) eq 'ARRAY') {
16930: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
16931: if (@diffs > 0) {
16932: $changes{'rules'} = 1;
16933: }
16934: } else {
16935: if (@chars > 0) {
16936: $changes{'rules'} = 1;
16937: }
16938: }
16939: }
1.359 raeburn 16940: my %crsownerchg = (
16941: by => [],
16942: for => [],
16943: );
16944: foreach my $item ('by','for') {
16945: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16946: foreach my $type (sort(@posstypes)) {
16947: if (grep(/^\Q$type\E$/,@oktypes)) {
16948: push(@{$crsownerchg{$item}},$type);
16949: }
16950: }
16951: }
16952: $newvalues{'crsownerchg'} = \%crsownerchg;
16953: if (ref($current{'crsownerchg'}) eq 'HASH') {
16954: foreach my $item ('by','for') {
16955: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16956: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16957: if (@diffs > 0) {
16958: $changes{'crsownerchg'} = 1;
16959: last;
16960: }
16961: }
16962: }
1.368 raeburn 16963: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 16964: foreach my $item ('by','for') {
16965: if (@{$crsownerchg{$item}} > 0) {
16966: $changes{'crsownerchg'} = 1;
16967: last;
16968: }
1.354 raeburn 16969: }
16970: }
16971:
16972: my %confighash = (
16973: defaults => \%save_defaults,
16974: passwords => \%newvalues,
16975: );
16976: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16977:
16978: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16979: if ($putresult eq 'ok') {
16980: if (keys(%changes) > 0) {
16981: $resulttext = &mt('Changes made: ').'<ul>';
16982: foreach my $key ('reset','intauth','rules','crsownerchg') {
16983: if ($changes{$key}) {
1.355 raeburn 16984: unless ($key eq 'intauth') {
16985: $updateconf = 1;
16986: }
1.354 raeburn 16987: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16988: if ($key eq 'reset') {
16989: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16990: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16991: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16992: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 16993: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16994: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16995: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16996: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16997: }
1.354 raeburn 16998: } else {
16999: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17000: }
17001: if ($confighash{'passwords'}{'resetlink'}) {
17002: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17003: } else {
17004: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17005: &mt('Will default to 2 hours').'</li>';
17006: }
17007: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17008: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17009: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17010: } else {
17011: my $casesens;
17012: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17013: if ($type eq 'default') {
17014: $casesens .= $othertitle.', ';
17015: } elsif ($usertypes->{$type} ne '') {
17016: $casesens .= $usertypes->{$type}.', ';
17017: }
17018: }
17019: $casesens =~ s/\Q, \E$//;
17020: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17021: }
17022: } else {
17023: $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>';
17024: }
17025: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17026: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17027: } else {
17028: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17029: }
17030: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17031: my $output;
17032: if (ref($types) eq 'ARRAY') {
17033: foreach my $type (@{$types}) {
17034: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17035: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17036: $output .= $usertypes->{$type}.' -- '.&mt('none');
17037: } else {
17038: $output .= $usertypes->{$type}.' -- '.
17039: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17040: }
17041: }
17042: }
17043: }
17044: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17045: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17046: $output .= $othertitle.' -- '.&mt('none');
17047: } else {
17048: $output .= $othertitle.' -- '.
17049: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17050: }
17051: }
17052: if ($output) {
17053: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17054: } else {
17055: $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>';
17056: }
17057: } else {
17058: $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>';
17059: }
17060: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17061: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17062: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17063: } else {
17064: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17065: }
17066: } else {
1.379 raeburn 17067: $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 17068: }
17069: if ($confighash{'passwords'}{'resetremove'}) {
17070: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17071: } else {
17072: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17073: }
17074: if ($confighash{'passwords'}{'resetcustom'}) {
17075: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17076: &mt('custom text'),600,500,undef,undef,
17077: undef,undef,'background-color:#ffffff');
17078: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17079: } else {
17080: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17081: }
17082: } elsif ($key eq 'intauth') {
17083: foreach my $item ('cost','switch','check') {
17084: my $value = $save_defaults{$key.'_'.$item};
17085: if ($item eq 'switch') {
17086: my %optiondesc = &Apache::lonlocal::texthash (
17087: 0 => 'No',
17088: 1 => 'Yes',
17089: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17090: );
17091: if ($value =~ /^(0|1|2)$/) {
17092: $value = $optiondesc{$value};
17093: } else {
17094: $value = &mt('none -- defaults to No');
17095: }
17096: } elsif ($item eq 'check') {
17097: my %optiondesc = &Apache::lonlocal::texthash (
17098: 0 => 'No',
17099: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17100: 2 => 'Yes, disallow login if stored cost is less than domain default',
17101: );
17102: if ($value =~ /^(0|1|2)$/) {
17103: $value = $optiondesc{$value};
17104: } else {
17105: $value = &mt('none -- defaults to No');
17106: }
17107: }
17108: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17109: }
17110: } elsif ($key eq 'rules') {
1.356 raeburn 17111: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17112: if ($confighash{'passwords'}{$rule} eq '') {
17113: if ($rule eq 'min') {
1.356 raeburn 17114: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17115: ' '.&mt('Default of [_1] will be used',
17116: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17117: } else {
17118: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17119: }
17120: } else {
17121: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17122: }
17123: }
1.370 raeburn 17124: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17125: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17126: my %rulenames = &Apache::lonlocal::texthash(
17127: uc => 'At least one upper case letter',
17128: lc => 'At least one lower case letter',
17129: num => 'At least one number',
17130: spec => 'At least one non-alphanumeric',
17131: );
17132: my $needed = '<ul><li>'.
17133: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17134: '</li></ul>';
17135: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17136: } else {
17137: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17138: }
17139: } else {
17140: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17141: }
1.354 raeburn 17142: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17143: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17144: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17145: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17146: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17147: } else {
17148: my %crsownerstr;
17149: foreach my $item ('by','for') {
17150: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17151: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17152: if ($type eq 'default') {
17153: $crsownerstr{$item} .= $othertitle.', ';
17154: } elsif ($usertypes->{$type} ne '') {
17155: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17156: }
17157: }
17158: $crsownerstr{$item} =~ s/\Q, \E$//;
17159: }
17160: }
17161: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17162: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17163: }
1.354 raeburn 17164: } else {
1.359 raeburn 17165: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17166: }
17167: }
17168: $resulttext .= '</ul></li>';
17169: }
17170: }
17171: $resulttext .= '</ul>';
17172: } else {
17173: $resulttext = &mt('No changes made to password settings');
17174: }
1.355 raeburn 17175: my $cachetime = 24*60*60;
1.354 raeburn 17176: if ($updatedefaults) {
17177: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17178: if (ref($lastactref) eq 'HASH') {
17179: $lastactref->{'domdefaults'} = 1;
17180: }
17181: }
1.355 raeburn 17182: if ($updateconf) {
17183: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17184: if (ref($lastactref) eq 'HASH') {
17185: $lastactref->{'passwdconf'} = 1;
17186: }
17187: }
1.354 raeburn 17188: } else {
17189: $resulttext = '<span class="LC_error">'.
17190: &mt('An error occurred: [_1]',$putresult).'</span>';
17191: }
17192: if ($errors) {
17193: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17194: $errors.'</ul></p>';
17195: }
17196: return $resulttext;
17197: }
17198:
1.28 raeburn 17199: sub modify_usercreation {
1.27 raeburn 17200: my ($dom,%domconfig) = @_;
1.224 raeburn 17201: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17202: my $warningmsg;
1.27 raeburn 17203: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17204: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17205: if ($key eq 'cancreate') {
17206: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17207: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17208: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17209: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17210: } else {
1.224 raeburn 17211: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17212: }
17213: }
17214: }
17215: } elsif ($key eq 'email_rule') {
17216: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17217: } else {
17218: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17219: }
1.27 raeburn 17220: }
17221: }
17222: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17223: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17224: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17225: foreach my $item(@contexts) {
1.224 raeburn 17226: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17227: }
1.34 raeburn 17228: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17229: foreach my $item (@contexts) {
1.224 raeburn 17230: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17231: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17232: }
1.27 raeburn 17233: }
1.34 raeburn 17234: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17235: foreach my $item (@contexts) {
1.43 raeburn 17236: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17237: if ($cancreate{$item} ne 'any') {
17238: push(@{$changes{'cancreate'}},$item);
17239: }
17240: } else {
17241: if ($cancreate{$item} ne 'none') {
17242: push(@{$changes{'cancreate'}},$item);
17243: }
1.27 raeburn 17244: }
17245: }
17246: } else {
1.43 raeburn 17247: foreach my $item (@contexts) {
1.34 raeburn 17248: push(@{$changes{'cancreate'}},$item);
17249: }
1.27 raeburn 17250: }
1.34 raeburn 17251:
1.27 raeburn 17252: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17253: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17254: if (!grep(/^\Q$type\E$/,@username_rule)) {
17255: push(@{$changes{'username_rule'}},$type);
17256: }
17257: }
17258: foreach my $type (@username_rule) {
17259: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17260: push(@{$changes{'username_rule'}},$type);
17261: }
17262: }
17263: } else {
17264: push(@{$changes{'username_rule'}},@username_rule);
17265: }
17266:
1.32 raeburn 17267: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17268: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17269: if (!grep(/^\Q$type\E$/,@id_rule)) {
17270: push(@{$changes{'id_rule'}},$type);
17271: }
17272: }
17273: foreach my $type (@id_rule) {
17274: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17275: push(@{$changes{'id_rule'}},$type);
17276: }
17277: }
17278: } else {
17279: push(@{$changes{'id_rule'}},@id_rule);
17280: }
17281:
1.43 raeburn 17282: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17283: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17284: my %authhash;
1.43 raeburn 17285: foreach my $item (@authen_contexts) {
1.28 raeburn 17286: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17287: foreach my $auth (@authtypes) {
17288: if (grep(/^\Q$auth\E$/,@authallowed)) {
17289: $authhash{$item}{$auth} = 1;
17290: } else {
17291: $authhash{$item}{$auth} = 0;
17292: }
17293: }
17294: }
17295: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17296: foreach my $item (@authen_contexts) {
1.28 raeburn 17297: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17298: foreach my $auth (@authtypes) {
17299: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17300: push(@{$changes{'authtypes'}},$item);
17301: last;
17302: }
17303: }
17304: }
17305: }
17306: } else {
1.43 raeburn 17307: foreach my $item (@authen_contexts) {
1.28 raeburn 17308: push(@{$changes{'authtypes'}},$item);
17309: }
17310: }
17311:
1.224 raeburn 17312: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17313: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17314: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17315: $save_usercreate{'id_rule'} = \@id_rule;
17316: $save_usercreate{'username_rule'} = \@username_rule,
17317: $save_usercreate{'authtypes'} = \%authhash;
17318:
1.27 raeburn 17319: my %usercreation_hash = (
1.224 raeburn 17320: usercreation => \%save_usercreate,
17321: );
1.27 raeburn 17322:
17323: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17324: $dom);
1.50 raeburn 17325:
1.224 raeburn 17326: if ($putresult eq 'ok') {
17327: if (keys(%changes) > 0) {
17328: $resulttext = &mt('Changes made:').'<ul>';
17329: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17330: my %lt = &usercreation_types();
17331: foreach my $type (@{$changes{'cancreate'}}) {
17332: my $chgtext = $lt{$type}.', ';
17333: if ($cancreate{$type} eq 'none') {
17334: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
17335: } elsif ($cancreate{$type} eq 'any') {
17336: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
17337: } elsif ($cancreate{$type} eq 'official') {
17338: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
17339: } elsif ($cancreate{$type} eq 'unofficial') {
17340: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
17341: }
17342: $resulttext .= '<li>'.$chgtext.'</li>';
17343: }
17344: }
17345: if (ref($changes{'username_rule'}) eq 'ARRAY') {
17346: my ($rules,$ruleorder) =
17347: &Apache::lonnet::inst_userrules($dom,'username');
17348: my $chgtext = '<ul>';
17349: foreach my $type (@username_rule) {
17350: if (ref($rules->{$type}) eq 'HASH') {
17351: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
17352: }
17353: }
17354: $chgtext .= '</ul>';
17355: if (@username_rule > 0) {
17356: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17357: } else {
17358: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
17359: }
17360: }
17361: if (ref($changes{'id_rule'}) eq 'ARRAY') {
17362: my ($idrules,$idruleorder) =
17363: &Apache::lonnet::inst_userrules($dom,'id');
17364: my $chgtext = '<ul>';
17365: foreach my $type (@id_rule) {
17366: if (ref($idrules->{$type}) eq 'HASH') {
17367: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
17368: }
17369: }
17370: $chgtext .= '</ul>';
17371: if (@id_rule > 0) {
17372: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17373: } else {
17374: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
17375: }
17376: }
17377: my %authname = &authtype_names();
17378: my %context_title = &context_names();
17379: if (ref($changes{'authtypes'}) eq 'ARRAY') {
17380: my $chgtext = '<ul>';
17381: foreach my $type (@{$changes{'authtypes'}}) {
17382: my @allowed;
17383: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
17384: foreach my $auth (@authtypes) {
17385: if ($authhash{$type}{$auth}) {
17386: push(@allowed,$authname{$auth});
17387: }
17388: }
17389: if (@allowed > 0) {
17390: $chgtext .= join(', ',@allowed).'</li>';
17391: } else {
17392: $chgtext .= &mt('none').'</li>';
17393: }
17394: }
17395: $chgtext .= '</ul>';
17396: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
17397: $resulttext .= '</li>';
17398: }
17399: $resulttext .= '</ul>';
17400: } else {
17401: $resulttext = &mt('No changes made to user creation settings');
17402: }
17403: } else {
17404: $resulttext = '<span class="LC_error">'.
17405: &mt('An error occurred: [_1]',$putresult).'</span>';
17406: }
17407: if ($warningmsg ne '') {
17408: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17409: }
17410: return $resulttext;
17411: }
17412:
17413: sub modify_selfcreation {
1.305 raeburn 17414: my ($dom,$lastactref,%domconfig) = @_;
17415: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
17416: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
17417: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 17418: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
17419: if (ref($typesref) eq 'ARRAY') {
17420: @types = @{$typesref};
17421: }
17422: if (ref($usertypesref) eq 'HASH') {
17423: %usertypes = %{$usertypesref};
1.228 raeburn 17424: }
1.303 raeburn 17425: $usertypes{'default'} = $othertitle;
1.224 raeburn 17426: #
17427: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
17428: #
17429: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17430: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
17431: if ($key eq 'cancreate') {
17432: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17433: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
17434: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 17435: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
17436: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
17437: ($item eq 'emailusername') || ($item eq 'shibenv') ||
17438: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 17439: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 17440: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17441: } else {
17442: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17443: }
17444: }
17445: }
17446: } elsif ($key eq 'email_rule') {
17447: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17448: } else {
17449: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17450: }
17451: }
17452: }
17453: #
17454: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
17455: #
17456: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17457: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
17458: if ($key eq 'selfcreate') {
17459: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
17460: } else {
17461: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
17462: }
17463: }
17464: }
1.305 raeburn 17465: #
17466: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
17467: #
17468: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17469: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
17470: if ($key eq 'inststatusguest') {
17471: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
17472: } else {
17473: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
17474: }
17475: }
17476: }
1.224 raeburn 17477:
17478: my @contexts = ('selfcreate');
17479: @{$cancreate{'selfcreate'}} = ();
17480: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 17481: if (@types) {
17482: @{$cancreate{'statustocreate'}} = ();
17483: }
1.236 raeburn 17484: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 17485: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 17486: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 17487: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 17488: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 17489: my %selfcreatetypes = (
17490: sso => 'users authenticated by institutional single sign on',
17491: login => 'users authenticated by institutional log-in',
1.303 raeburn 17492: email => 'users verified by e-mail',
1.50 raeburn 17493: );
1.224 raeburn 17494: #
17495: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
17496: # is permitted.
17497: #
1.305 raeburn 17498: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 17499:
1.305 raeburn 17500: my (@statuses,%email_rule);
1.228 raeburn 17501: foreach my $item ('login','sso','email') {
1.224 raeburn 17502: if ($item eq 'email') {
1.236 raeburn 17503: if ($env{'form.cancreate_email'}) {
1.305 raeburn 17504: if (@types) {
17505: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
17506: foreach my $status (@poss_statuses) {
17507: if (grep(/^\Q$status\E$/,(@types,'default'))) {
17508: push(@statuses,$status);
17509: }
17510: }
17511: $save_inststatus{'inststatusguest'} = \@statuses;
17512: } else {
17513: push(@statuses,'default');
17514: }
17515: if (@statuses) {
17516: my %curr_rule;
17517: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
17518: foreach my $type (@statuses) {
17519: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 17520: }
1.305 raeburn 17521: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
17522: foreach my $type (@statuses) {
17523: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
17524: }
17525: }
17526: push(@{$cancreate{'selfcreate'}},'email');
17527: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
17528: my %curremaildom;
17529: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
17530: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
17531: }
17532: foreach my $type (@statuses) {
17533: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
17534: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
17535: }
17536: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
17537: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
17538: }
17539: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
17540: #
17541: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
17542: #
17543: my $chosen = $1;
17544: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
17545: my $emaildom;
17546: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
17547: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
17548: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
17549: if (ref($curremaildom{$type}) eq 'HASH') {
17550: if (exists($curremaildom{$type}{$chosen})) {
17551: if ($curremaildom{$type}{$chosen} ne $emaildom) {
17552: push(@{$changes{'cancreate'}},'emaildomain');
17553: }
17554: } elsif ($emaildom ne '') {
17555: push(@{$changes{'cancreate'}},'emaildomain');
17556: }
17557: } elsif ($emaildom ne '') {
17558: push(@{$changes{'cancreate'}},'emaildomain');
17559: }
17560: }
17561: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17562: } elsif ($chosen eq 'custom') {
17563: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
17564: $email_rule{$type} = [];
17565: if (ref($emailrules) eq 'HASH') {
17566: foreach my $rule (@possemail_rules) {
17567: if (exists($emailrules->{$rule})) {
17568: push(@{$email_rule{$type}},$rule);
17569: }
17570: }
17571: }
17572: if (@{$email_rule{$type}}) {
17573: $cancreate{'emailoptions'}{$type} = 'custom';
17574: if (ref($curr_rule{$type}) eq 'ARRAY') {
17575: if (@{$curr_rule{$type}} > 0) {
17576: foreach my $rule (@{$curr_rule{$type}}) {
17577: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
17578: push(@{$changes{'email_rule'}},$type);
17579: }
17580: }
17581: }
17582: foreach my $type (@{$email_rule{$type}}) {
17583: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
17584: push(@{$changes{'email_rule'}},$type);
17585: }
17586: }
17587: } else {
17588: push(@{$changes{'email_rule'}},$type);
17589: }
17590: }
17591: } else {
17592: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17593: }
17594: }
17595: }
17596: if (@types) {
17597: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17598: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
17599: if (@changed) {
17600: push(@{$changes{'inststatus'}},'inststatusguest');
17601: }
17602: } else {
17603: push(@{$changes{'inststatus'}},'inststatusguest');
17604: }
17605: }
17606: } else {
17607: delete($env{'form.cancreate_email'});
17608: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17609: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17610: push(@{$changes{'inststatus'}},'inststatusguest');
17611: }
17612: }
17613: }
17614: } else {
17615: $save_inststatus{'inststatusguest'} = [];
17616: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17617: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17618: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 17619: }
17620: }
1.224 raeburn 17621: }
17622: } else {
17623: if ($env{'form.cancreate_'.$item}) {
17624: push(@{$cancreate{'selfcreate'}},$item);
17625: }
17626: }
17627: }
1.305 raeburn 17628: my (%userinfo,%savecaptcha);
1.224 raeburn 17629: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
17630: #
1.228 raeburn 17631: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
17632: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 17633: #
1.236 raeburn 17634:
1.244 raeburn 17635: if ($env{'form.cancreate_email'}) {
1.228 raeburn 17636: push(@contexts,'emailusername');
1.305 raeburn 17637: if (@statuses) {
17638: foreach my $type (@statuses) {
1.228 raeburn 17639: if (ref($infofields) eq 'ARRAY') {
17640: foreach my $field (@{$infofields}) {
17641: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
17642: $cancreate{'emailusername'}{$type}{$field} = $1;
17643: }
17644: }
1.224 raeburn 17645: }
17646: }
17647: }
17648: #
17649: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 17650: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 17651: #
17652:
17653: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
17654: @approvalnotify = sort(@approvalnotify);
17655: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
17656: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17657: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17658: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17659: push(@{$changes{'cancreate'}},'notify');
17660: }
17661: } else {
17662: if ($cancreate{'notify'}{'approval'}) {
17663: push(@{$changes{'cancreate'}},'notify');
17664: }
17665: }
17666: } elsif ($cancreate{'notify'}{'approval'}) {
17667: push(@{$changes{'cancreate'}},'notify');
17668: }
17669:
17670: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17671: }
17672: #
1.236 raeburn 17673: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 17674: # institutional log-in.
17675: #
17676: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17677: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17678: ($domdefaults{'auth_def'} eq 'localauth'))) {
17679: $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.').' '.
17680: &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.');
17681: }
17682: }
17683: my @fields = ('lastname','firstname','middlename','generation',
17684: 'permanentemail','id');
1.240 raeburn 17685: my @shibfields = (@fields,'inststatus');
1.224 raeburn 17686: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17687: #
17688: # Where usernames may created for institutional log-in and/or institutional single sign on:
17689: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17690: # may self-create accounts
17691: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17692: # which the user may supply, if institutional data is unavailable.
17693: #
17694: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 17695: if (@types) {
1.305 raeburn 17696: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17697: push(@contexts,'statustocreate');
1.303 raeburn 17698: foreach my $type (@types) {
1.224 raeburn 17699: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17700: foreach my $field (@fields) {
17701: if (grep(/^\Q$field\E$/,@modifiable)) {
17702: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17703: } else {
17704: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17705: }
17706: }
17707: }
17708: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17709: foreach my $type (@types) {
1.224 raeburn 17710: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17711: foreach my $field (@fields) {
17712: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17713: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17714: push(@{$changes{'selfcreate'}},$type);
17715: last;
17716: }
17717: }
17718: }
17719: }
17720: } else {
1.303 raeburn 17721: foreach my $type (@types) {
1.224 raeburn 17722: push(@{$changes{'selfcreate'}},$type);
17723: }
17724: }
17725: }
1.240 raeburn 17726: foreach my $field (@shibfields) {
17727: if ($env{'form.shibenv_'.$field} ne '') {
17728: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17729: }
17730: }
17731: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17732: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17733: foreach my $field (@shibfields) {
17734: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17735: push(@{$changes{'cancreate'}},'shibenv');
17736: }
17737: }
17738: } else {
17739: foreach my $field (@shibfields) {
17740: if ($env{'form.shibenv_'.$field}) {
17741: push(@{$changes{'cancreate'}},'shibenv');
17742: last;
17743: }
17744: }
17745: }
17746: }
1.224 raeburn 17747: }
17748: foreach my $item (@contexts) {
17749: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17750: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17751: if (ref($cancreate{$item}) eq 'ARRAY') {
17752: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17753: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17754: push(@{$changes{'cancreate'}},$item);
17755: }
17756: }
17757: }
17758: }
17759: if (ref($cancreate{$item}) eq 'ARRAY') {
17760: foreach my $type (@{$cancreate{$item}}) {
17761: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17762: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17763: push(@{$changes{'cancreate'}},$item);
17764: }
17765: }
17766: }
17767: }
17768: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17769: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17770: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17771: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17772: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17773: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17774: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17775: push(@{$changes{'cancreate'}},$item);
17776: }
17777: }
17778: }
1.305 raeburn 17779: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17780: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17781: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17782: push(@{$changes{'cancreate'}},$item);
17783: }
1.224 raeburn 17784: }
17785: }
17786: }
1.305 raeburn 17787: foreach my $type (keys(%{$cancreate{$item}})) {
17788: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17789: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17790: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17791: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17792: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17793: push(@{$changes{'cancreate'}},$item);
17794: }
17795: }
17796: } else {
17797: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17798: push(@{$changes{'cancreate'}},$item);
17799: }
17800: }
17801: }
1.305 raeburn 17802: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17803: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17804: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17805: push(@{$changes{'cancreate'}},$item);
17806: }
1.224 raeburn 17807: }
17808: }
17809: }
17810: }
17811: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17812: if (ref($cancreate{$item}) eq 'ARRAY') {
17813: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17814: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17815: push(@{$changes{'cancreate'}},$item);
17816: }
17817: }
1.305 raeburn 17818: }
17819: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17820: if (ref($cancreate{$item}) eq 'HASH') {
17821: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17822: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17823: }
17824: }
17825: } elsif ($item eq 'emailusername') {
1.228 raeburn 17826: if (ref($cancreate{$item}) eq 'HASH') {
17827: foreach my $type (keys(%{$cancreate{$item}})) {
17828: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17829: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17830: if ($cancreate{$item}{$type}{$field}) {
17831: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17832: push(@{$changes{'cancreate'}},$item);
17833: }
17834: last;
17835: }
17836: }
17837: }
17838: }
1.224 raeburn 17839: }
17840: }
17841: }
17842: #
17843: # Populate %save_usercreate hash with updates to self-creation configuration.
17844: #
17845: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17846: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17847: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17848: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17849: if (ref($cancreate{'notify'}) eq 'HASH') {
17850: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17851: }
1.236 raeburn 17852: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17853: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17854: }
1.303 raeburn 17855: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17856: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17857: }
1.305 raeburn 17858: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17859: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17860: }
1.303 raeburn 17861: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17862: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17863: }
1.224 raeburn 17864: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17865: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17866: }
1.240 raeburn 17867: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17868: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17869: }
1.224 raeburn 17870: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17871: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17872:
17873: my %userconfig_hash = (
17874: usercreation => \%save_usercreate,
17875: usermodification => \%save_usermodify,
1.305 raeburn 17876: inststatus => \%save_inststatus,
1.224 raeburn 17877: );
1.305 raeburn 17878:
1.224 raeburn 17879: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17880: $dom);
17881: #
1.305 raeburn 17882: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17883: #
1.27 raeburn 17884: if ($putresult eq 'ok') {
17885: if (keys(%changes) > 0) {
17886: $resulttext = &mt('Changes made:').'<ul>';
17887: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 17888: my %lt = &selfcreation_types();
1.34 raeburn 17889: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 17890: my $chgtext = '';
1.45 raeburn 17891: if ($type eq 'selfcreate') {
1.50 raeburn 17892: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 17893: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17894: } else {
1.224 raeburn 17895: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17896: '<ul>';
1.50 raeburn 17897: foreach my $case (@{$cancreate{$type}}) {
17898: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17899: }
17900: $chgtext .= '</ul>';
1.100 raeburn 17901: if (ref($cancreate{$type}) eq 'ARRAY') {
17902: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17903: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17904: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 17905: $chgtext .= '<span class="LC_warning">'.
17906: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17907: '</span><br />';
17908: }
17909: }
17910: }
17911: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 17912: if (!@statuses) {
17913: $chgtext .= '<span class="LC_warning">'.
17914: &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.").
17915: '</span><br />';
1.303 raeburn 17916:
1.100 raeburn 17917: }
17918: }
17919: }
1.43 raeburn 17920: }
1.240 raeburn 17921: } elsif ($type eq 'shibenv') {
17922: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 17923: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 17924: } else {
17925: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17926: '<ul>';
17927: foreach my $field (@shibfields) {
17928: next if ($cancreate{$type}{$field} eq '');
17929: if ($field eq 'inststatus') {
17930: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17931: } else {
17932: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17933: }
17934: }
17935: $chgtext .= '</ul>';
1.303 raeburn 17936: }
1.93 raeburn 17937: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17938: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17939: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17940: if (@{$cancreate{'selfcreate'}} > 0) {
17941: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17942: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17943: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 17944: $chgtext .= '<br />'.
17945: '<span class="LC_warning">'.
17946: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17947: '</span>';
17948: }
1.303 raeburn 17949: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17950: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17951: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17952: } else {
17953: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17954: }
17955: $chgtext .= '<ul>';
17956: foreach my $case (@{$cancreate{$type}}) {
17957: if ($case eq 'default') {
17958: $chgtext .= '<li>'.$othertitle.'</li>';
17959: } else {
1.303 raeburn 17960: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17961: }
17962: }
1.100 raeburn 17963: $chgtext .= '</ul>';
17964: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 17965: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 17966: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17967: '</span>';
1.100 raeburn 17968: }
17969: }
17970: } else {
17971: if (@{$cancreate{$type}} == 0) {
17972: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17973: } else {
17974: $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 17975: }
17976: }
1.303 raeburn 17977: $chgtext .= '<br />';
1.93 raeburn 17978: }
1.236 raeburn 17979: } elsif ($type eq 'selfcreateprocessing') {
17980: my %choices = &Apache::lonlocal::texthash (
17981: automatic => 'Automatic approval',
17982: approval => 'Queued for approval',
17983: );
1.305 raeburn 17984: if (@types) {
17985: if (@statuses) {
1.303 raeburn 17986: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 17987: '<ul>';
1.305 raeburn 17988: foreach my $status (@statuses) {
17989: if ($status eq 'default') {
17990: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17991: } else {
1.305 raeburn 17992: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17993: }
17994: }
17995: $chgtext .= '</ul>';
17996: }
17997: } else {
17998: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17999: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18000: }
18001: } elsif ($type eq 'emailverified') {
18002: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18003: all => 'Same as e-mail',
18004: first => 'Omit @domain',
18005: free => 'Free to choose',
1.303 raeburn 18006: );
1.305 raeburn 18007: if (@types) {
18008: if (@statuses) {
1.303 raeburn 18009: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18010: '<ul>';
1.305 raeburn 18011: foreach my $status (@statuses) {
1.362 raeburn 18012: if ($status eq 'default') {
1.305 raeburn 18013: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18014: } else {
1.305 raeburn 18015: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18016: }
18017: }
18018: $chgtext .= '</ul>';
18019: }
18020: } else {
1.305 raeburn 18021: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18022: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18023: }
1.305 raeburn 18024: } elsif ($type eq 'emailoptions') {
18025: my %options = &Apache::lonlocal::texthash (
18026: any => 'Any e-mail',
18027: inst => 'Institutional only',
18028: noninst => 'Non-institutional only',
18029: custom => 'Custom restrictions',
18030: );
18031: if (@types) {
18032: if (@statuses) {
18033: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18034: '<ul>';
18035: foreach my $status (@statuses) {
18036: if ($type eq 'default') {
18037: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18038: } else {
18039: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18040: }
18041: }
1.305 raeburn 18042: $chgtext .= '</ul>';
18043: }
18044: } else {
18045: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18046: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18047: } else {
18048: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18049: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18050: }
1.305 raeburn 18051: }
18052: } elsif ($type eq 'emaildomain') {
18053: my $output;
18054: if (@statuses) {
18055: foreach my $type (@statuses) {
18056: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18057: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18058: if ($type eq 'default') {
18059: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18060: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18061: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18062: } else {
18063: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18064: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18065: }
1.303 raeburn 18066: } else {
1.305 raeburn 18067: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18068: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18069: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18070: } else {
18071: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
18072: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18073: }
1.303 raeburn 18074: }
1.305 raeburn 18075: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18076: if ($type eq 'default') {
18077: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18078: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18079: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18080: } else {
18081: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18082: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18083: }
1.303 raeburn 18084: } else {
1.305 raeburn 18085: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18086: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18087: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18088: } else {
18089: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
18090: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18091: }
1.303 raeburn 18092: }
18093: }
18094: }
18095: }
1.305 raeburn 18096: }
18097: if ($output ne '') {
18098: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18099: '<ul>'.$output.'</ul>';
1.236 raeburn 18100: }
1.165 raeburn 18101: } elsif ($type eq 'captcha') {
1.224 raeburn 18102: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18103: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18104: } else {
18105: my %captchas = &captcha_phrases();
1.224 raeburn 18106: if ($captchas{$savecaptcha{$type}}) {
18107: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18108: } else {
1.210 raeburn 18109: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18110: }
18111: }
18112: } elsif ($type eq 'recaptchakeys') {
18113: my ($privkey,$pubkey);
1.224 raeburn 18114: if (ref($savecaptcha{$type}) eq 'HASH') {
18115: $pubkey = $savecaptcha{$type}{'public'};
18116: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18117: }
18118: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18119: if (!$pubkey) {
18120: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18121: } else {
18122: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18123: }
18124: if (!$privkey) {
18125: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18126: } else {
18127: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18128: }
18129: $chgtext .= '</ul>';
1.269 raeburn 18130: } elsif ($type eq 'recaptchaversion') {
18131: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18132: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18133: }
1.224 raeburn 18134: } elsif ($type eq 'emailusername') {
18135: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18136: if (@statuses) {
18137: foreach my $type (@statuses) {
1.228 raeburn 18138: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18139: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18140: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18141: '<ul>';
18142: foreach my $field (@{$infofields}) {
18143: if ($cancreate{'emailusername'}{$type}{$field}) {
18144: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18145: }
18146: }
1.245 raeburn 18147: $chgtext .= '</ul>';
18148: } else {
1.303 raeburn 18149: $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 18150: }
18151: } else {
1.303 raeburn 18152: $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 18153: }
18154: }
18155: }
18156: }
18157: } elsif ($type eq 'notify') {
1.303 raeburn 18158: my $numapprove = 0;
1.224 raeburn 18159: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18160: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18161: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18162: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18163: $numapprove ++;
1.224 raeburn 18164: }
18165: }
1.43 raeburn 18166: }
1.303 raeburn 18167: unless ($numapprove) {
18168: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18169: }
1.34 raeburn 18170: }
1.224 raeburn 18171: if ($chgtext) {
18172: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18173: }
18174: }
18175: }
1.305 raeburn 18176: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18177: my ($emailrules,$emailruleorder) =
18178: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18179: foreach my $type (@{$changes{'email_rule'}}) {
18180: if (ref($email_rule{$type}) eq 'ARRAY') {
18181: my $chgtext = '<ul>';
18182: foreach my $rule (@{$email_rule{$type}}) {
18183: if (ref($emailrules->{$rule}) eq 'HASH') {
18184: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18185: }
18186: }
18187: $chgtext .= '</ul>';
1.310 raeburn 18188: my $typename;
1.305 raeburn 18189: if (@types) {
18190: if ($type eq 'default') {
18191: $typename = $othertitle;
18192: } else {
18193: $typename = $usertypes{$type};
18194: }
18195: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18196: }
18197: if (@{$email_rule{$type}} > 0) {
18198: $resulttext .= '<li>'.
18199: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18200: $usertypes{$type}).
18201: $chgtext.
18202: '</li>';
18203: } else {
18204: $resulttext .= '<li>'.
1.310 raeburn 18205: &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 18206: '</li>'.
1.310 raeburn 18207: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18208: }
1.43 raeburn 18209: }
18210: }
1.305 raeburn 18211: }
18212: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18213: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18214: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18215: my $chgtext = '<ul>';
18216: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18217: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18218: }
18219: $chgtext .= '</ul>';
18220: $resulttext .= '<li>'.
18221: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18222: $chgtext.
18223: '</li>';
18224: } else {
18225: $resulttext .= '<li>'.
18226: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18227: '</li>';
18228: }
1.43 raeburn 18229: }
18230: }
1.224 raeburn 18231: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18232: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18233: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18234: foreach my $type (@{$changes{'selfcreate'}}) {
18235: my $typename = $type;
1.303 raeburn 18236: if (keys(%usertypes) > 0) {
18237: if ($usertypes{$type} ne '') {
18238: $typename = $usertypes{$type};
1.224 raeburn 18239: }
18240: }
18241: my @modifiable;
18242: $resulttext .= '<li>'.
18243: &mt('Self-creation of account by users with status: [_1]',
18244: '<span class="LC_cusr_emph">'.$typename.'</span>').
18245: ' - '.&mt('modifiable fields (if institutional data blank): ');
18246: foreach my $field (@fields) {
18247: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18248: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18249: }
18250: }
1.224 raeburn 18251: if (@modifiable > 0) {
18252: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18253: } else {
1.224 raeburn 18254: $resulttext .= &mt('none');
1.43 raeburn 18255: }
1.224 raeburn 18256: $resulttext .= '</li>';
1.28 raeburn 18257: }
1.224 raeburn 18258: $resulttext .= '</ul></li>';
1.28 raeburn 18259: }
1.27 raeburn 18260: $resulttext .= '</ul>';
1.305 raeburn 18261: my $cachetime = 24*60*60;
18262: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18263: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18264: if (ref($lastactref) eq 'HASH') {
18265: $lastactref->{'domdefaults'} = 1;
18266: }
1.27 raeburn 18267: } else {
1.224 raeburn 18268: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18269: }
18270: } else {
18271: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18272: &mt('An error occurred: [_1]',$putresult).'</span>';
18273: }
1.43 raeburn 18274: if ($warningmsg ne '') {
18275: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18276: }
1.23 raeburn 18277: return $resulttext;
18278: }
18279:
1.165 raeburn 18280: sub process_captcha {
1.369 raeburn 18281: my ($container,$changes,$newsettings,$currsettings) = @_;
18282: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18283: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18284: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18285: $newsettings->{'captcha'} = 'original';
18286: }
1.369 raeburn 18287: my %current;
18288: if (ref($currsettings) eq 'HASH') {
18289: %current = %{$currsettings};
18290: }
18291: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18292: if ($container eq 'cancreate') {
1.169 raeburn 18293: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18294: push(@{$changes->{'cancreate'}},'captcha');
18295: } elsif (!defined($changes->{'cancreate'})) {
18296: $changes->{'cancreate'} = ['captcha'];
18297: }
1.368 raeburn 18298: } elsif ($container eq 'passwords') {
18299: $changes->{'reset'} = 1;
1.169 raeburn 18300: } else {
18301: $changes->{'captcha'} = 1;
1.165 raeburn 18302: }
18303: }
1.269 raeburn 18304: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18305: if ($newsettings->{'captcha'} eq 'recaptcha') {
18306: $newpub = $env{'form.'.$container.'_recaptchapub'};
18307: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18308: $newpub =~ s/[^\w\-]//g;
18309: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18310: $newsettings->{'recaptchakeys'} = {
18311: public => $newpub,
18312: private => $newpriv,
18313: };
1.269 raeburn 18314: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18315: $newversion =~ s/\D//g;
18316: if ($newversion ne '2') {
18317: $newversion = 1;
18318: }
18319: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18320: }
1.369 raeburn 18321: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18322: $currpub = $current{'recaptchakeys'}{'public'};
18323: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18324: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18325: $newsettings->{'recaptchakeys'} = {
18326: public => '',
18327: private => '',
18328: }
18329: }
1.165 raeburn 18330: }
1.369 raeburn 18331: if ($current{'captcha'} eq 'recaptcha') {
18332: $currversion = $current{'recaptchaversion'};
1.269 raeburn 18333: if ($currversion ne '2') {
18334: $currversion = 1;
18335: }
18336: }
18337: if ($currversion ne $newversion) {
18338: if ($container eq 'cancreate') {
18339: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18340: push(@{$changes->{'cancreate'}},'recaptchaversion');
18341: } elsif (!defined($changes->{'cancreate'})) {
18342: $changes->{'cancreate'} = ['recaptchaversion'];
18343: }
1.368 raeburn 18344: } elsif ($container eq 'passwords') {
18345: $changes->{'reset'} = 1;
1.269 raeburn 18346: } else {
18347: $changes->{'recaptchaversion'} = 1;
18348: }
18349: }
1.165 raeburn 18350: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 18351: if ($container eq 'cancreate') {
18352: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18353: push(@{$changes->{'cancreate'}},'recaptchakeys');
18354: } elsif (!defined($changes->{'cancreate'})) {
18355: $changes->{'cancreate'} = ['recaptchakeys'];
18356: }
1.368 raeburn 18357: } elsif ($container eq 'passwords') {
18358: $changes->{'reset'} = 1;
1.169 raeburn 18359: } else {
1.210 raeburn 18360: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 18361: }
18362: }
18363: return;
18364: }
18365:
1.33 raeburn 18366: sub modify_usermodification {
18367: my ($dom,%domconfig) = @_;
1.224 raeburn 18368: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 18369: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18370: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 18371: if ($key eq 'selfcreate') {
18372: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
18373: } else {
18374: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
18375: }
1.33 raeburn 18376: }
18377: }
1.224 raeburn 18378: my @contexts = ('author','course');
1.33 raeburn 18379: my %context_title = (
18380: author => 'In author context',
18381: course => 'In course context',
18382: );
18383: my @fields = ('lastname','firstname','middlename','generation',
18384: 'permanentemail','id');
18385: my %roles = (
18386: author => ['ca','aa'],
18387: course => ['st','ep','ta','in','cr'],
18388: );
18389: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18390: foreach my $context (@contexts) {
18391: foreach my $role (@{$roles{$context}}) {
18392: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
18393: foreach my $item (@fields) {
18394: if (grep(/^\Q$item\E$/,@modifiable)) {
18395: $modifyhash{$context}{$role}{$item} = 1;
18396: } else {
18397: $modifyhash{$context}{$role}{$item} = 0;
18398: }
18399: }
18400: }
18401: if (ref($curr_usermodification{$context}) eq 'HASH') {
18402: foreach my $role (@{$roles{$context}}) {
18403: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
18404: foreach my $field (@fields) {
18405: if ($modifyhash{$context}{$role}{$field} ne
18406: $curr_usermodification{$context}{$role}{$field}) {
18407: push(@{$changes{$context}},$role);
18408: last;
18409: }
18410: }
18411: }
18412: }
18413: } else {
18414: foreach my $context (@contexts) {
18415: foreach my $role (@{$roles{$context}}) {
18416: push(@{$changes{$context}},$role);
18417: }
18418: }
18419: }
18420: }
18421: my %usermodification_hash = (
18422: usermodification => \%modifyhash,
18423: );
18424: my $putresult = &Apache::lonnet::put_dom('configuration',
18425: \%usermodification_hash,$dom);
18426: if ($putresult eq 'ok') {
18427: if (keys(%changes) > 0) {
18428: $resulttext = &mt('Changes made: ').'<ul>';
18429: foreach my $context (@contexts) {
18430: if (ref($changes{$context}) eq 'ARRAY') {
18431: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
18432: if (ref($changes{$context}) eq 'ARRAY') {
18433: foreach my $role (@{$changes{$context}}) {
18434: my $rolename;
1.224 raeburn 18435: if ($role eq 'cr') {
18436: $rolename = &mt('Custom');
1.33 raeburn 18437: } else {
1.224 raeburn 18438: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 18439: }
18440: my @modifiable;
1.224 raeburn 18441: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 18442: foreach my $field (@fields) {
18443: if ($modifyhash{$context}{$role}{$field}) {
18444: push(@modifiable,$fieldtitles{$field});
18445: }
18446: }
18447: if (@modifiable > 0) {
18448: $resulttext .= join(', ',@modifiable);
18449: } else {
18450: $resulttext .= &mt('none');
18451: }
18452: $resulttext .= '</li>';
18453: }
18454: $resulttext .= '</ul></li>';
18455: }
18456: }
18457: }
18458: $resulttext .= '</ul>';
18459: } else {
18460: $resulttext = &mt('No changes made to user modification settings');
18461: }
18462: } else {
18463: $resulttext = '<span class="LC_error">'.
18464: &mt('An error occurred: [_1]',$putresult).'</span>';
18465: }
18466: return $resulttext;
18467: }
18468:
1.43 raeburn 18469: sub modify_defaults {
1.212 raeburn 18470: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 18471: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 18472: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 18473: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 18474: 'portal_def');
1.325 raeburn 18475: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 18476: foreach my $item (@items) {
18477: $newvalues{$item} = $env{'form.'.$item};
18478: if ($item eq 'auth_def') {
18479: if ($newvalues{$item} ne '') {
18480: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
18481: push(@errors,$item);
18482: }
18483: }
18484: } elsif ($item eq 'lang_def') {
18485: if ($newvalues{$item} ne '') {
18486: if ($newvalues{$item} =~ /^(\w+)/) {
18487: my $langcode = $1;
1.103 raeburn 18488: if ($langcode ne 'x_chef') {
18489: if (code2language($langcode) eq '') {
18490: push(@errors,$item);
18491: }
1.43 raeburn 18492: }
18493: } else {
18494: push(@errors,$item);
18495: }
18496: }
1.54 raeburn 18497: } elsif ($item eq 'timezone_def') {
18498: if ($newvalues{$item} ne '') {
1.62 raeburn 18499: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 18500: push(@errors,$item);
18501: }
18502: }
1.68 raeburn 18503: } elsif ($item eq 'datelocale_def') {
18504: if ($newvalues{$item} ne '') {
18505: my @datelocale_ids = DateTime::Locale->ids();
18506: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
18507: push(@errors,$item);
18508: }
18509: }
1.141 raeburn 18510: } elsif ($item eq 'portal_def') {
18511: if ($newvalues{$item} ne '') {
18512: 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])\/?$/) {
18513: push(@errors,$item);
18514: }
18515: }
1.43 raeburn 18516: }
18517: if (grep(/^\Q$item\E$/,@errors)) {
18518: $newvalues{$item} = $domdefaults{$item};
18519: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
18520: $changes{$item} = 1;
18521: }
1.72 raeburn 18522: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 18523: }
1.354 raeburn 18524: my %staticdefaults = (
18525: 'intauth_cost' => 10,
18526: 'intauth_check' => 0,
18527: 'intauth_switch' => 0,
18528: );
18529: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
18530: if (exists($domdefaults{$item})) {
18531: $newvalues{$item} = $domdefaults{$item};
18532: } else {
18533: $newvalues{$item} = $staticdefaults{$item};
18534: }
18535: }
1.43 raeburn 18536: my %defaults_hash = (
1.72 raeburn 18537: defaults => \%newvalues,
18538: );
1.43 raeburn 18539: my $title = &defaults_titles();
1.236 raeburn 18540:
18541: my $currinststatus;
18542: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18543: $currinststatus = $domconfig{'inststatus'};
18544: } else {
18545: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18546: $currinststatus = {
18547: inststatustypes => $usertypes,
18548: inststatusorder => $types,
18549: inststatusguest => [],
18550: };
18551: }
18552: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
18553: my @allpos;
18554: my %alltypes;
1.305 raeburn 18555: my @inststatusguest;
18556: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
18557: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
18558: unless (grep(/^\Q$type\E$/,@todelete)) {
18559: push(@inststatusguest,$type);
18560: }
18561: }
18562: }
18563: my ($currtitles,$currorder);
1.236 raeburn 18564: if (ref($currinststatus) eq 'HASH') {
18565: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
18566: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
18567: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
18568: if ($currinststatus->{inststatustypes}->{$type} ne '') {
18569: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
18570: }
18571: }
18572: unless (grep(/^\Q$type\E$/,@todelete)) {
18573: my $position = $env{'form.inststatus_pos_'.$type};
18574: $position =~ s/\D+//g;
18575: $allpos[$position] = $type;
18576: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18577: $alltypes{$type} =~ s/`//g;
18578: }
18579: }
18580: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18581: $currtitles =~ s/,$//;
18582: }
18583: }
18584: if ($env{'form.addinststatus'}) {
18585: my $newtype = $env{'form.addinststatus'};
18586: $newtype =~ s/\W//g;
18587: unless (exists($alltypes{$newtype})) {
18588: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18589: $alltypes{$newtype} =~ s/`//g;
18590: my $position = $env{'form.addinststatus_pos'};
18591: $position =~ s/\D+//g;
18592: if ($position ne '') {
18593: $allpos[$position] = $newtype;
18594: }
18595: }
18596: }
1.305 raeburn 18597: my @orderedstatus;
1.236 raeburn 18598: foreach my $type (@allpos) {
18599: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18600: push(@orderedstatus,$type);
18601: }
18602: }
18603: foreach my $type (keys(%alltypes)) {
18604: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18605: delete($alltypes{$type});
18606: }
18607: }
18608: $defaults_hash{'inststatus'} = {
18609: inststatustypes => \%alltypes,
18610: inststatusorder => \@orderedstatus,
1.305 raeburn 18611: inststatusguest => \@inststatusguest,
1.236 raeburn 18612: };
18613: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18614: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18615: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18616: }
18617: }
18618: if ($currorder ne join(',',@orderedstatus)) {
18619: $changes{'inststatus'}{'inststatusorder'} = 1;
18620: }
18621: my $newtitles;
18622: foreach my $item (@orderedstatus) {
18623: $newtitles .= $alltypes{$item}.',';
18624: }
18625: $newtitles =~ s/,$//;
18626: if ($currtitles ne $newtitles) {
18627: $changes{'inststatus'}{'inststatustypes'} = 1;
18628: }
1.43 raeburn 18629: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18630: $dom);
18631: if ($putresult eq 'ok') {
18632: if (keys(%changes) > 0) {
18633: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 18634: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18635: 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";
18636: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 18637: if ($item eq 'inststatus') {
18638: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 18639: if (@orderedstatus) {
1.236 raeburn 18640: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18641: foreach my $type (@orderedstatus) {
18642: $resulttext .= $alltypes{$type}.', ';
18643: }
18644: $resulttext =~ s/, $//;
18645: $resulttext .= '</li>';
1.305 raeburn 18646: } else {
18647: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 18648: }
18649: }
18650: } else {
18651: my $value = $env{'form.'.$item};
18652: if ($value eq '') {
18653: $value = &mt('none');
18654: } elsif ($item eq 'auth_def') {
18655: my %authnames = &authtype_names();
18656: my %shortauth = (
18657: internal => 'int',
18658: krb4 => 'krb4',
18659: krb5 => 'krb5',
18660: localauth => 'loc',
1.325 raeburn 18661: lti => 'lti',
1.236 raeburn 18662: );
18663: $value = $authnames{$shortauth{$value}};
18664: }
18665: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
18666: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 18667: }
18668: }
18669: $resulttext .= '</ul>';
18670: $mailmsgtext .= "\n";
18671: my $cachetime = 24*60*60;
1.72 raeburn 18672: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 18673: if (ref($lastactref) eq 'HASH') {
18674: $lastactref->{'domdefaults'} = 1;
18675: }
1.68 raeburn 18676: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 18677: my $notify = 1;
18678: if (ref($domconfig{'contacts'}) eq 'HASH') {
18679: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18680: $notify = 0;
18681: }
18682: }
18683: if ($notify) {
18684: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18685: "LON-CAPA Domain Settings Change - $dom",
18686: $mailmsgtext);
18687: }
1.54 raeburn 18688: }
1.43 raeburn 18689: } else {
1.54 raeburn 18690: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18691: }
18692: } else {
18693: $resulttext = '<span class="LC_error">'.
18694: &mt('An error occurred: [_1]',$putresult).'</span>';
18695: }
18696: if (@errors > 0) {
18697: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18698: foreach my $item (@errors) {
18699: $resulttext .= ' "'.$title->{$item}.'",';
18700: }
18701: $resulttext =~ s/,$//;
18702: }
18703: return $resulttext;
18704: }
18705:
1.46 raeburn 18706: sub modify_scantron {
1.205 raeburn 18707: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18708: my ($resulttext,%confhash,%changes,$errors);
18709: my $custom = 'custom.tab';
18710: my $default = 'default.tab';
18711: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18712: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18713: &config_check($dom,$confname,$servadm);
18714: if ($env{'form.scantronformat.filename'} ne '') {
18715: my $error;
18716: if ($configuserok eq 'ok') {
18717: if ($switchserver) {
1.130 raeburn 18718: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18719: } else {
18720: if ($author_ok eq 'ok') {
18721: my ($result,$scantronurl) =
18722: &publishlogo($r,'upload','scantronformat',$dom,
18723: $confname,'scantron','','',$custom);
18724: if ($result eq 'ok') {
18725: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18726: $changes{'scantronformat'} = 1;
1.46 raeburn 18727: } else {
18728: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18729: }
18730: } else {
18731: $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);
18732: }
18733: }
18734: } else {
18735: $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);
18736: }
18737: if ($error) {
18738: &Apache::lonnet::logthis($error);
18739: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18740: }
18741: }
1.48 raeburn 18742: if (ref($domconfig{'scantron'}) eq 'HASH') {
18743: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18744: if ($env{'form.scantronformat_del'}) {
18745: $confhash{'scantron'}{'scantronformat'} = '';
18746: $changes{'scantronformat'} = 1;
1.347 raeburn 18747: } else {
18748: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18749: }
18750: }
18751: }
1.347 raeburn 18752: my @options = ('hdr','pad','rem');
1.346 raeburn 18753: my @fields = &scantroncsv_fields();
18754: my %titles = &scantronconfig_titles();
1.347 raeburn 18755: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18756: my ($newdat,$currdat,%newcol,%currcol);
18757: if (grep(/^dat$/,@formats)) {
18758: $confhash{'scantron'}{config}{dat} = 1;
18759: $newdat = 1;
18760: } else {
18761: $newdat = 0;
18762: }
18763: if (grep(/^csv$/,@formats)) {
18764: my %bynum;
18765: foreach my $field (@fields) {
18766: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18767: my $posscol = $1;
18768: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18769: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18770: $bynum{$posscol} = $field;
18771: $newcol{$field} = $posscol;
18772: }
18773: }
18774: }
1.347 raeburn 18775: if (keys(%newcol)) {
18776: foreach my $option (@options) {
18777: if ($env{'form.scantroncsv_'.$option}) {
18778: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18779: }
18780: }
18781: }
1.346 raeburn 18782: }
18783: $currdat = 1;
18784: if (ref($domconfig{'scantron'}) eq 'HASH') {
18785: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18786: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18787: $currdat = 0;
18788: }
18789: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18790: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18791: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18792: }
1.346 raeburn 18793: }
18794: }
18795: }
18796: if ($currdat != $newdat) {
18797: $changes{'config'} = 1;
18798: } else {
18799: foreach my $field (@fields) {
18800: if ($currcol{$field} ne '') {
18801: if ($currcol{$field} ne $newcol{$field}) {
18802: $changes{'config'} = 1;
18803: last;
1.347 raeburn 18804: }
1.346 raeburn 18805: } elsif ($newcol{$field} ne '') {
18806: $changes{'config'} = 1;
18807: last;
18808: }
18809: }
18810: }
1.46 raeburn 18811: if (keys(%confhash) > 0) {
18812: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18813: $dom);
18814: if ($putresult eq 'ok') {
18815: if (keys(%changes) > 0) {
1.48 raeburn 18816: if (ref($confhash{'scantron'}) eq 'HASH') {
18817: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18818: if ($changes{'scantronformat'}) {
18819: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18820: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18821: } else {
18822: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18823: }
18824: }
1.347 raeburn 18825: if ($changes{'config'}) {
1.346 raeburn 18826: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18827: if ($confhash{'scantron'}{'config'}{'dat'}) {
18828: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18829: }
18830: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18831: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18832: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18833: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18834: foreach my $field (@fields) {
18835: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18836: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18837: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18838: }
18839: }
18840: $resulttext .= '</ul></li>';
18841: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18842: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18843: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18844: foreach my $option (@options) {
18845: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18846: $resulttext .= '<li>'.$titles{$option}.'</li>';
18847: }
18848: }
18849: $resulttext .= '</ul></li>';
18850: }
1.346 raeburn 18851: }
18852: }
18853: }
18854: }
18855: } else {
18856: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18857: }
1.46 raeburn 18858: }
1.48 raeburn 18859: $resulttext .= '</ul>';
18860: } else {
1.130 raeburn 18861: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18862: }
18863: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18864: if (ref($lastactref) eq 'HASH') {
18865: $lastactref->{'domainconfig'} = 1;
18866: }
1.46 raeburn 18867: } else {
1.346 raeburn 18868: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18869: }
18870: } else {
18871: $resulttext = '<span class="LC_error">'.
18872: &mt('An error occurred: [_1]',$putresult).'</span>';
18873: }
18874: } else {
1.130 raeburn 18875: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18876: }
18877: if ($errors) {
1.353 raeburn 18878: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18879: $errors.'</ul></p>';
1.46 raeburn 18880: }
18881: return $resulttext;
18882: }
18883:
1.48 raeburn 18884: sub modify_coursecategories {
1.239 raeburn 18885: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18886: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18887: $cathash);
1.48 raeburn 18888: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 18889: my @catitems = ('unauth','auth');
18890: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18891: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18892: $cathash = $domconfig{'coursecategories'}{'cats'};
18893: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18894: $changes{'togglecats'} = 1;
18895: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18896: }
18897: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18898: $changes{'categorize'} = 1;
18899: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18900: }
1.120 raeburn 18901: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18902: $changes{'togglecatscomm'} = 1;
18903: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18904: }
18905: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18906: $changes{'categorizecomm'} = 1;
18907: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 18908:
18909: }
18910: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
18911: $changes{'togglecatsplace'} = 1;
18912: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
18913: }
18914: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
18915: $changes{'categorizeplace'} = 1;
18916: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 18917: }
1.238 raeburn 18918: foreach my $item (@catitems) {
18919: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18920: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18921: $changes{$item} = 1;
18922: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18923: }
18924: }
18925: }
1.57 raeburn 18926: } else {
18927: $changes{'togglecats'} = 1;
18928: $changes{'categorize'} = 1;
1.124 raeburn 18929: $changes{'togglecatscomm'} = 1;
18930: $changes{'categorizecomm'} = 1;
1.272 raeburn 18931: $changes{'togglecatsplace'} = 1;
18932: $changes{'categorizeplace'} = 1;
1.87 raeburn 18933: $domconfig{'coursecategories'} = {
18934: togglecats => $env{'form.togglecats'},
18935: categorize => $env{'form.categorize'},
1.124 raeburn 18936: togglecatscomm => $env{'form.togglecatscomm'},
18937: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 18938: togglecatsplace => $env{'form.togglecatsplace'},
18939: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 18940: };
1.238 raeburn 18941: foreach my $item (@catitems) {
18942: if ($env{'form.coursecat_'.$item} ne 'std') {
18943: $changes{$item} = 1;
18944: }
18945: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18946: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18947: }
18948: }
1.57 raeburn 18949: }
18950: if (ref($cathash) eq 'HASH') {
18951: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18952: push (@deletecategory,'instcode::0');
18953: }
1.120 raeburn 18954: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18955: push(@deletecategory,'communities::0');
18956: }
1.272 raeburn 18957: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
18958: push(@deletecategory,'placement::0');
18959: }
1.48 raeburn 18960: }
1.57 raeburn 18961: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18962: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18963: if (@deletecategory > 0) {
18964: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18965: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18966: foreach my $item (@deletecategory) {
1.57 raeburn 18967: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18968: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18969: $deletions{$item} = 1;
1.57 raeburn 18970: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18971: }
18972: }
18973: }
1.57 raeburn 18974: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18975: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18976: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18977: $reorderings{$item} = 1;
1.57 raeburn 18978: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18979: }
18980: if ($env{'form.addcategory_name_'.$item} ne '') {
18981: my $newcat = $env{'form.addcategory_name_'.$item};
18982: my $newdepth = $depth+1;
18983: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18984: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18985: $adds{$newitem} = 1;
18986: }
18987: if ($env{'form.subcat_'.$item} ne '') {
18988: my $newcat = $env{'form.subcat_'.$item};
18989: my $newdepth = $depth+1;
18990: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18991: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18992: $adds{$newitem} = 1;
18993: }
18994: }
18995: }
18996: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18997: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18998: my $newitem = 'instcode::0';
1.57 raeburn 18999: if ($cathash->{$newitem} eq '') {
19000: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19001: $adds{$newitem} = 1;
19002: }
19003: } else {
19004: my $newitem = 'instcode::0';
1.57 raeburn 19005: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19006: $adds{$newitem} = 1;
19007: }
19008: }
1.120 raeburn 19009: if ($env{'form.communities'} eq '1') {
19010: if (ref($cathash) eq 'HASH') {
19011: my $newitem = 'communities::0';
19012: if ($cathash->{$newitem} eq '') {
19013: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19014: $adds{$newitem} = 1;
19015: }
19016: } else {
19017: my $newitem = 'communities::0';
19018: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19019: $adds{$newitem} = 1;
19020: }
19021: }
1.272 raeburn 19022: if ($env{'form.placement'} eq '1') {
19023: if (ref($cathash) eq 'HASH') {
19024: my $newitem = 'placement::0';
19025: if ($cathash->{$newitem} eq '') {
19026: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19027: $adds{$newitem} = 1;
19028: }
19029: } else {
19030: my $newitem = 'placement::0';
19031: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19032: $adds{$newitem} = 1;
19033: }
19034: }
1.48 raeburn 19035: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19036: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19037: ($env{'form.addcategory_name'} ne 'communities') &&
19038: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19039: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19040: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19041: $adds{$newitem} = 1;
19042: }
1.48 raeburn 19043: }
1.57 raeburn 19044: my $putresult;
1.48 raeburn 19045: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19046: if (keys(%deletions) > 0) {
19047: foreach my $key (keys(%deletions)) {
19048: if ($predelallitems{$key} ne '') {
19049: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19050: }
19051: }
19052: }
19053: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19054: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19055: if (ref($chkcats[0]) eq 'ARRAY') {
19056: my $depth = 0;
19057: my $chg = 0;
19058: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19059: my $name = $chkcats[0][$i];
19060: my $item;
19061: if ($name eq '') {
19062: $chg ++;
19063: } else {
19064: $item = &escape($name).'::0';
19065: if ($chg) {
1.57 raeburn 19066: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19067: }
19068: $depth ++;
1.57 raeburn 19069: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19070: $depth --;
19071: }
19072: }
19073: }
1.57 raeburn 19074: }
19075: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19076: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19077: if ($putresult eq 'ok') {
1.57 raeburn 19078: my %title = (
1.120 raeburn 19079: togglecats => 'Show/Hide a course in catalog',
19080: categorize => 'Assign a category to a course',
19081: togglecatscomm => 'Show/Hide a community in catalog',
19082: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19083: );
19084: my %level = (
1.120 raeburn 19085: dom => 'set in Domain ("Modify Course/Community")',
19086: crs => 'set in Course ("Course Configuration")',
19087: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19088: none => 'No catalog',
19089: std => 'Standard catalog',
19090: domonly => 'Domain-only catalog',
19091: codesrch => 'Code search form',
1.57 raeburn 19092: );
1.48 raeburn 19093: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19094: if ($changes{'togglecats'}) {
19095: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19096: }
19097: if ($changes{'categorize'}) {
19098: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19099: }
1.120 raeburn 19100: if ($changes{'togglecatscomm'}) {
19101: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19102: }
19103: if ($changes{'categorizecomm'}) {
19104: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19105: }
1.238 raeburn 19106: if ($changes{'unauth'}) {
19107: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19108: }
19109: if ($changes{'auth'}) {
19110: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19111: }
1.57 raeburn 19112: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19113: my $cathash;
19114: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19115: $cathash = $domconfig{'coursecategories'}{'cats'};
19116: } else {
19117: $cathash = {};
19118: }
19119: my (@cats,@trails,%allitems);
19120: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19121: if (keys(%deletions) > 0) {
19122: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19123: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19124: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19125: }
19126: $resulttext .= '</ul></li>';
19127: }
19128: if (keys(%reorderings) > 0) {
19129: my %sort_by_trail;
19130: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19131: foreach my $key (keys(%reorderings)) {
19132: if ($allitems{$key} ne '') {
19133: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19134: }
1.48 raeburn 19135: }
1.57 raeburn 19136: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19137: $resulttext .= '<li>'.$trails[$trail].'</li>';
19138: }
19139: $resulttext .= '</ul></li>';
1.48 raeburn 19140: }
1.57 raeburn 19141: if (keys(%adds) > 0) {
19142: my %sort_by_trail;
19143: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19144: foreach my $key (keys(%adds)) {
19145: if ($allitems{$key} ne '') {
19146: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19147: }
19148: }
19149: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19150: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19151: }
1.57 raeburn 19152: $resulttext .= '</ul></li>';
1.48 raeburn 19153: }
1.364 raeburn 19154: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19155: if (ref($lastactref) eq 'HASH') {
19156: $lastactref->{'cats'} = 1;
19157: }
1.48 raeburn 19158: }
19159: $resulttext .= '</ul>';
1.239 raeburn 19160: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19161: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19162: if ($changes{'auth'}) {
19163: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19164: }
19165: if ($changes{'unauth'}) {
19166: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19167: }
19168: my $cachetime = 24*60*60;
19169: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19170: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19171: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19172: }
19173: }
1.48 raeburn 19174: } else {
19175: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19176: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19177: }
19178: } else {
1.120 raeburn 19179: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19180: }
19181: return $resulttext;
19182: }
19183:
1.69 raeburn 19184: sub modify_serverstatuses {
19185: my ($dom,%domconfig) = @_;
19186: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19187: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19188: %currserverstatus = %{$domconfig{'serverstatuses'}};
19189: }
19190: my @pages = &serverstatus_pages();
19191: foreach my $type (@pages) {
19192: $newserverstatus{$type}{'namedusers'} = '';
19193: $newserverstatus{$type}{'machines'} = '';
19194: if (defined($env{'form.'.$type.'_namedusers'})) {
19195: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19196: my @okusers;
19197: foreach my $user (@users) {
19198: my ($uname,$udom) = split(/:/,$user);
19199: if (($udom =~ /^$match_domain$/) &&
19200: (&Apache::lonnet::domain($udom)) &&
19201: ($uname =~ /^$match_username$/)) {
19202: if (!grep(/^\Q$user\E/,@okusers)) {
19203: push(@okusers,$user);
19204: }
19205: }
19206: }
19207: if (@okusers > 0) {
19208: @okusers = sort(@okusers);
19209: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19210: }
19211: }
19212: if (defined($env{'form.'.$type.'_machines'})) {
19213: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19214: my @okmachines;
19215: foreach my $ip (@machines) {
19216: my @parts = split(/\./,$ip);
19217: next if (@parts < 4);
19218: my $badip = 0;
19219: for (my $i=0; $i<4; $i++) {
19220: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19221: $badip = 1;
19222: last;
19223: }
19224: }
19225: if (!$badip) {
19226: push(@okmachines,$ip);
19227: }
19228: }
19229: @okmachines = sort(@okmachines);
19230: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19231: }
19232: }
19233: my %serverstatushash = (
19234: serverstatuses => \%newserverstatus,
19235: );
19236: foreach my $type (@pages) {
1.83 raeburn 19237: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19238: my (@current,@new);
1.83 raeburn 19239: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19240: if ($currserverstatus{$type}{$setting} ne '') {
19241: @current = split(/,/,$currserverstatus{$type}{$setting});
19242: }
19243: }
19244: if ($newserverstatus{$type}{$setting} ne '') {
19245: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19246: }
19247: if (@current > 0) {
19248: if (@new > 0) {
19249: foreach my $item (@current) {
19250: if (!grep(/^\Q$item\E$/,@new)) {
19251: $changes{$type}{$setting} = 1;
1.82 raeburn 19252: last;
19253: }
19254: }
1.84 raeburn 19255: foreach my $item (@new) {
19256: if (!grep(/^\Q$item\E$/,@current)) {
19257: $changes{$type}{$setting} = 1;
19258: last;
1.82 raeburn 19259: }
19260: }
19261: } else {
1.83 raeburn 19262: $changes{$type}{$setting} = 1;
1.69 raeburn 19263: }
1.83 raeburn 19264: } elsif (@new > 0) {
19265: $changes{$type}{$setting} = 1;
1.69 raeburn 19266: }
19267: }
19268: }
19269: if (keys(%changes) > 0) {
1.81 raeburn 19270: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19271: my $putresult = &Apache::lonnet::put_dom('configuration',
19272: \%serverstatushash,$dom);
19273: if ($putresult eq 'ok') {
19274: $resulttext .= &mt('Changes made:').'<ul>';
19275: foreach my $type (@pages) {
1.84 raeburn 19276: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19277: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19278: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19279: if ($newserverstatus{$type}{'namedusers'} eq '') {
19280: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19281: } else {
19282: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19283: }
1.84 raeburn 19284: }
19285: if ($changes{$type}{'machines'}) {
1.69 raeburn 19286: if ($newserverstatus{$type}{'machines'} eq '') {
19287: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19288: } else {
19289: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19290: }
19291:
19292: }
19293: $resulttext .= '</ul></li>';
19294: }
19295: }
19296: $resulttext .= '</ul>';
19297: } else {
19298: $resulttext = '<span class="LC_error">'.
19299: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19300:
19301: }
19302: } else {
19303: $resulttext = &mt('No changes made to access to server status pages');
19304: }
19305: return $resulttext;
19306: }
19307:
1.118 jms 19308: sub modify_helpsettings {
1.285 raeburn 19309: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19310: my ($resulttext,$errors,%changes,%helphash);
19311: my %defaultchecked = ('submitbugs' => 'on');
19312: my @offon = ('off','on');
1.118 jms 19313: my @toggles = ('submitbugs');
1.285 raeburn 19314: my %current = ('submitbugs' => '',
19315: 'adhoc' => {},
19316: );
1.118 jms 19317: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19318: %current = %{$domconfig{'helpsettings'}};
19319: }
1.285 raeburn 19320: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19321: foreach my $item (@toggles) {
19322: if ($defaultchecked{$item} eq 'on') {
19323: if ($current{$item} eq '') {
19324: if ($env{'form.'.$item} eq '0') {
19325: $changes{$item} = 1;
19326: }
19327: } elsif ($current{$item} ne $env{'form.'.$item}) {
19328: $changes{$item} = 1;
19329: }
19330: } elsif ($defaultchecked{$item} eq 'off') {
19331: if ($current{$item} eq '') {
19332: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 19333: $changes{$item} = 1;
19334: }
1.282 raeburn 19335: } elsif ($current{$item} ne $env{'form.'.$item}) {
19336: $changes{$item} = 1;
19337: }
19338: }
19339: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
19340: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
19341: }
19342: }
1.285 raeburn 19343: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 19344: my $confname = $dom.'-domainconfig';
19345: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 19346: my (@allpos,%newsettings,%changedprivs,$newrole);
19347: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 19348: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 19349: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 19350: my %lt = &Apache::lonlocal::texthash(
19351: s => 'system',
19352: d => 'domain',
19353: order => 'Display order',
19354: access => 'Role usage',
1.291 raeburn 19355: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 19356: dh => 'All with domain helpdesk role',
19357: da => 'All with domain helpdesk assistant role',
1.285 raeburn 19358: none => 'None',
19359: status => 'Determined based on institutional status',
19360: inc => 'Include all, but exclude specific personnel',
19361: exc => 'Exclude all, but include specific personnel',
19362: );
19363: for (my $num=0; $num<=$maxnum; $num++) {
19364: my ($prefix,$identifier,$rolename,%curr);
19365: if ($num == $maxnum) {
19366: next unless ($env{'form.newcusthelp'} == $maxnum);
19367: $identifier = 'custhelp'.$num;
19368: $prefix = 'helproles_'.$num;
19369: $rolename = $env{'form.custhelpname'.$num};
19370: $rolename=~s/[^A-Za-z0-9]//gs;
19371: next if ($rolename eq '');
19372: next if (exists($existing{'rolesdef_'.$rolename}));
19373: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19374: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19375: $newprivs{'c'},$confname,$dom);
19376: if ($result ne 'ok') {
19377: $errors .= '<li><span class="LC_error">'.
19378: &mt('An error occurred storing the new custom role: [_1]',
19379: $result).'</span></li>';
19380: next;
19381: } else {
19382: $changedprivs{$rolename} = \%newprivs;
19383: $newrole = $rolename;
19384: }
19385: } else {
19386: $prefix = 'helproles_'.$num;
19387: $rolename = $env{'form.'.$prefix};
19388: next if ($rolename eq '');
19389: next unless (exists($existing{'rolesdef_'.$rolename}));
19390: $identifier = 'custhelp'.$num;
19391: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19392: my %currprivs;
1.289 raeburn 19393: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 19394: split(/\_/,$existing{'rolesdef_'.$rolename});
19395: foreach my $level ('c','d','s') {
19396: if ($newprivs{$level} ne $currprivs{$level}) {
19397: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19398: $newprivs{'c'},$confname,$dom);
19399: if ($result ne 'ok') {
19400: $errors .= '<li><span class="LC_error">'.
19401: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
19402: $rolename,$result).'</span></li>';
19403: } else {
19404: $changedprivs{$rolename} = \%newprivs;
19405: }
19406: last;
19407: }
19408: }
19409: if (ref($current{'adhoc'}) eq 'HASH') {
19410: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19411: %curr = %{$current{'adhoc'}{$rolename}};
19412: }
19413: }
19414: }
19415: my $newpos = $env{'form.'.$prefix.'_pos'};
19416: $newpos =~ s/\D+//g;
19417: $allpos[$newpos] = $rolename;
19418: my $newdesc = $env{'form.'.$prefix.'_desc'};
19419: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
19420: if ($curr{'desc'}) {
19421: if ($curr{'desc'} ne $newdesc) {
19422: $changes{'customrole'}{$rolename}{'desc'} = 1;
19423: $newsettings{$rolename}{'desc'} = $newdesc;
19424: }
19425: } elsif ($newdesc ne '') {
19426: $changes{'customrole'}{$rolename}{'desc'} = 1;
19427: $newsettings{$rolename}{'desc'} = $newdesc;
19428: }
19429: my $access = $env{'form.'.$prefix.'_access'};
19430: if (grep(/^\Q$access\E$/,@accesstypes)) {
19431: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
19432: if ($access eq 'status') {
19433: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
19434: if (scalar(@statuses) == 0) {
1.289 raeburn 19435: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 19436: } else {
19437: my (@shownstatus,$numtypes);
19438: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19439: if (ref($types) eq 'ARRAY') {
19440: $numtypes = scalar(@{$types});
19441: foreach my $type (sort(@statuses)) {
19442: if ($type eq 'default') {
19443: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19444: } elsif (grep(/^\Q$type\E$/,@{$types})) {
19445: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19446: push(@shownstatus,$usertypes->{$type});
19447: }
19448: }
19449: }
19450: if (grep(/^default$/,@statuses)) {
19451: push(@shownstatus,$othertitle);
19452: }
19453: if (scalar(@shownstatus) == 1+$numtypes) {
19454: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
19455: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
19456: } else {
19457: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
19458: if (ref($curr{'status'}) eq 'ARRAY') {
19459: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19460: if (@diffs) {
19461: $changes{'customrole'}{$rolename}{$access} = 1;
19462: }
19463: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19464: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 19465: }
1.166 raeburn 19466: }
19467: }
1.285 raeburn 19468: } elsif (($access eq 'inc') || ($access eq 'exc')) {
19469: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
19470: my @newspecstaff;
19471: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19472: foreach my $person (sort(@personnel)) {
19473: if ($domhelpdesk{$person}) {
19474: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
19475: }
19476: }
19477: if (ref($curr{$access}) eq 'ARRAY') {
19478: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19479: if (@diffs) {
19480: $changes{'customrole'}{$rolename}{$access} = 1;
19481: }
19482: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19483: $changes{'customrole'}{$rolename}{$access} = 1;
19484: }
19485: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19486: my ($uname,$udom) = split(/:/,$person);
19487: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
19488: }
19489: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 19490: }
1.285 raeburn 19491: } else {
19492: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
19493: }
19494: unless ($curr{'access'} eq $access) {
19495: $changes{'customrole'}{$rolename}{'access'} = 1;
19496: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 19497: }
19498: }
1.285 raeburn 19499: if (@allpos > 0) {
19500: my $idx = 0;
19501: foreach my $rolename (@allpos) {
19502: if ($rolename ne '') {
19503: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
19504: if (ref($current{'adhoc'}) eq 'HASH') {
19505: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19506: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
19507: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 19508: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 19509: }
19510: }
1.282 raeburn 19511: }
1.285 raeburn 19512: $idx ++;
1.166 raeburn 19513: }
19514: }
1.118 jms 19515: }
1.123 jms 19516: my $putresult;
19517: if (keys(%changes) > 0) {
1.166 raeburn 19518: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 19519: if ($putresult eq 'ok') {
1.285 raeburn 19520: if (ref($helphash{'helpsettings'}) eq 'HASH') {
19521: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
19522: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
19523: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
19524: }
19525: }
19526: my $cachetime = 24*60*60;
19527: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19528: if (ref($lastactref) eq 'HASH') {
19529: $lastactref->{'domdefaults'} = 1;
19530: }
19531: } else {
19532: $errors .= '<li><span class="LC_error">'.
19533: &mt('An error occurred storing the settings: [_1]',
19534: $putresult).'</span></li>';
19535: }
19536: }
19537: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
19538: $resulttext = &mt('Changes made:').'<ul>';
19539: my (%shownprivs,@levelorder);
19540: @levelorder = ('c','d','s');
19541: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 19542: foreach my $item (sort(keys(%changes))) {
19543: if ($item eq 'submitbugs') {
19544: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
19545: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
19546: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 19547: } elsif ($item eq 'customrole') {
19548: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 19549: my @keyorder = ('order','desc','access','status','exc','inc');
19550: my %keytext = &Apache::lonlocal::texthash(
19551: order => 'Order',
19552: desc => 'Role description',
19553: access => 'Role usage',
1.300 droeschl 19554: status => 'Allowed institutional types',
1.285 raeburn 19555: exc => 'Allowed personnel',
19556: inc => 'Disallowed personnel',
19557: );
1.282 raeburn 19558: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 19559: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
19560: if ($role eq $newrole) {
19561: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
19562: $role).'<ul>';
19563: } else {
19564: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19565: $role).'<ul>';
19566: }
19567: foreach my $key (@keyorder) {
19568: if ($changes{'customrole'}{$role}{$key}) {
19569: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19570: $keytext{$key},$newsettings{$role}{$key}).
19571: '</li>';
19572: }
19573: }
19574: if (ref($changedprivs{$role}) eq 'HASH') {
19575: $shownprivs{$role} = 1;
19576: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19577: foreach my $level (@levelorder) {
19578: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19579: next if ($item eq '');
19580: my ($priv) = split(/\&/,$item,2);
19581: if (&Apache::lonnet::plaintext($priv)) {
19582: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19583: unless ($level eq 'c') {
19584: $resulttext .= ' ('.$lt{$level}.')';
19585: }
19586: $resulttext .= '</li>';
19587: }
19588: }
19589: }
19590: $resulttext .= '</ul>';
19591: }
19592: $resulttext .= '</ul></li>';
19593: }
19594: }
19595: }
19596: }
19597: }
19598: }
19599: if (keys(%changedprivs)) {
19600: foreach my $role (sort(keys(%changedprivs))) {
19601: unless ($shownprivs{$role}) {
19602: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19603: $role).'<ul>'.
19604: '<li>'.&mt('Privileges set to :').'<ul>';
19605: foreach my $level (@levelorder) {
19606: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19607: next if ($item eq '');
19608: my ($priv) = split(/\&/,$item,2);
19609: if (&Apache::lonnet::plaintext($priv)) {
19610: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19611: unless ($level eq 'c') {
19612: $resulttext .= ' ('.$lt{$level}.')';
19613: }
19614: $resulttext .= '</li>';
19615: }
1.282 raeburn 19616: }
19617: }
1.285 raeburn 19618: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 19619: }
19620: }
19621: }
1.285 raeburn 19622: $resulttext .= '</ul>';
19623: } else {
19624: $resulttext = &mt('No changes made to help settings');
1.118 jms 19625: }
19626: if ($errors) {
1.168 raeburn 19627: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 19628: $errors.'</ul>';
1.118 jms 19629: }
19630: return $resulttext;
19631: }
19632:
1.121 raeburn 19633: sub modify_coursedefaults {
1.212 raeburn 19634: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19635: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 19636: my %defaultchecked = (
19637: 'canuse_pdfforms' => 'off',
19638: 'uselcmath' => 'on',
19639: 'usejsme' => 'on'
19640: );
19641: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 19642: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 19643: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
19644: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19645: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 19646: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 19647: my %staticdefaults = (
19648: anonsurvey_threshold => 10,
19649: uploadquota => 500,
1.257 raeburn 19650: postsubmit => 60,
1.276 raeburn 19651: mysqltables => 172800,
1.198 raeburn 19652: );
1.314 raeburn 19653: my %texoptions = (
19654: MathJax => 'MathJax',
19655: mimetex => &mt('Convert to Images'),
19656: tth => &mt('TeX to HTML'),
19657: );
1.121 raeburn 19658: $defaultshash{'coursedefaults'} = {};
19659:
19660: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19661: if ($domconfig{'coursedefaults'} eq '') {
19662: $domconfig{'coursedefaults'} = {};
19663: }
19664: }
19665:
19666: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19667: foreach my $item (@toggles) {
19668: if ($defaultchecked{$item} eq 'on') {
19669: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19670: ($env{'form.'.$item} eq '0')) {
19671: $changes{$item} = 1;
1.192 raeburn 19672: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19673: $changes{$item} = 1;
19674: }
19675: } elsif ($defaultchecked{$item} eq 'off') {
19676: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19677: ($env{'form.'.$item} eq '1')) {
19678: $changes{$item} = 1;
19679: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19680: $changes{$item} = 1;
19681: }
19682: }
19683: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19684: }
1.198 raeburn 19685: foreach my $item (@numbers) {
19686: my ($currdef,$newdef);
1.208 raeburn 19687: $newdef = $env{'form.'.$item};
1.198 raeburn 19688: if ($item eq 'anonsurvey_threshold') {
19689: $currdef = $domconfig{'coursedefaults'}{$item};
19690: $newdef =~ s/\D//g;
19691: if ($newdef eq '' || $newdef < 1) {
19692: $newdef = 1;
19693: }
19694: $defaultshash{'coursedefaults'}{$item} = $newdef;
19695: } else {
1.276 raeburn 19696: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
19697: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19698: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19699: }
19700: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19701: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19702: }
19703: if ($currdef ne $newdef) {
19704: if ($item eq 'anonsurvey_threshold') {
19705: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19706: $changes{$item} = 1;
19707: }
1.276 raeburn 19708: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19709: my $setting = $1;
1.276 raeburn 19710: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19711: $changes{$setting} = 1;
1.198 raeburn 19712: }
19713: }
1.139 raeburn 19714: }
19715: }
1.314 raeburn 19716: my $texengine;
19717: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19718: $texengine = $env{'form.texengine'};
1.349 raeburn 19719: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19720: if ($currdef eq '') {
19721: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19722: $changes{'texengine'} = 1;
19723: }
1.349 raeburn 19724: } elsif ($currdef ne $texengine) {
1.314 raeburn 19725: $changes{'texengine'} = 1;
19726: }
19727: }
19728: if ($texengine ne '') {
19729: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19730: }
1.264 raeburn 19731: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19732: my @currclonecode;
19733: if (ref($currclone) eq 'HASH') {
19734: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19735: @currclonecode = @{$currclone->{'instcode'}};
19736: }
19737: }
19738: my $newclone;
1.289 raeburn 19739: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19740: $newclone = $env{'form.canclone'};
19741: }
19742: if ($newclone eq 'instcode') {
19743: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19744: my (%codedefaults,@code_order,@clonecode);
19745: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19746: \@code_order);
19747: foreach my $item (@code_order) {
19748: if (grep(/^\Q$item\E$/,@newcodes)) {
19749: push(@clonecode,$item);
19750: }
19751: }
19752: if (@clonecode) {
19753: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19754: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19755: if (@diffs) {
19756: $changes{'canclone'} = 1;
19757: }
19758: } else {
19759: $newclone eq '';
19760: }
19761: } elsif ($newclone ne '') {
1.289 raeburn 19762: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19763: }
1.264 raeburn 19764: if ($newclone ne $currclone) {
19765: $changes{'canclone'} = 1;
19766: }
1.257 raeburn 19767: my %credits;
19768: foreach my $type (@types) {
19769: unless ($type eq 'community') {
19770: $credits{$type} = $env{'form.'.$type.'_credits'};
19771: $credits{$type} =~ s/[^\d.]+//g;
19772: }
19773: }
19774: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19775: ($env{'form.coursecredits'} eq '1')) {
19776: $changes{'coursecredits'} = 1;
19777: foreach my $type (keys(%credits)) {
19778: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19779: }
19780: } else {
1.289 raeburn 19781: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19782: foreach my $type (@types) {
19783: unless ($type eq 'community') {
1.289 raeburn 19784: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19785: $changes{'coursecredits'} = 1;
19786: }
19787: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19788: }
19789: }
19790: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19791: foreach my $type (@types) {
19792: unless ($type eq 'community') {
19793: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19794: $changes{'coursecredits'} = 1;
19795: last;
19796: }
19797: }
19798: }
19799: }
19800: }
19801: if ($env{'form.postsubmit'} eq '1') {
19802: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19803: my %currtimeout;
19804: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19805: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19806: $changes{'postsubmit'} = 1;
19807: }
19808: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19809: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19810: }
19811: } else {
19812: $changes{'postsubmit'} = 1;
19813: }
19814: foreach my $type (@types) {
19815: my $timeout = $env{'form.'.$type.'_timeout'};
19816: $timeout =~ s/\D//g;
19817: if ($timeout == $staticdefaults{'postsubmit'}) {
19818: $timeout = '';
19819: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19820: $timeout = '0';
19821: }
19822: unless ($timeout eq '') {
19823: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19824: }
19825: if (exists($currtimeout{$type})) {
19826: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19827: $changes{'postsubmit'} = 1;
1.257 raeburn 19828: }
19829: } elsif ($timeout ne '') {
19830: $changes{'postsubmit'} = 1;
19831: }
19832: }
19833: } else {
19834: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19835: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19836: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19837: $changes{'postsubmit'} = 1;
19838: }
19839: } else {
19840: $changes{'postsubmit'} = 1;
19841: }
1.192 raeburn 19842: }
1.121 raeburn 19843: }
19844: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19845: $dom);
19846: if ($putresult eq 'ok') {
19847: if (keys(%changes) > 0) {
1.213 raeburn 19848: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19849: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19850: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19851: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19852: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19853: if ($changes{$item}) {
19854: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19855: }
1.289 raeburn 19856: }
1.192 raeburn 19857: if ($changes{'coursecredits'}) {
19858: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19859: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19860: $domdefaults{$type.'credits'} =
19861: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19862: }
19863: }
19864: }
19865: if ($changes{'postsubmit'}) {
19866: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19867: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19868: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19869: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19870: $domdefaults{$type.'postsubtimeout'} =
19871: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19872: }
19873: }
1.192 raeburn 19874: }
19875: }
1.198 raeburn 19876: if ($changes{'uploadquota'}) {
19877: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19878: foreach my $type (@types) {
19879: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19880: }
19881: }
19882: }
1.264 raeburn 19883: if ($changes{'canclone'}) {
19884: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19885: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19886: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19887: if (@clonecodes) {
19888: $domdefaults{'canclone'} = join('+',@clonecodes);
19889: }
19890: }
19891: } else {
19892: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19893: }
19894: }
1.121 raeburn 19895: my $cachetime = 24*60*60;
19896: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19897: if (ref($lastactref) eq 'HASH') {
19898: $lastactref->{'domdefaults'} = 1;
19899: }
1.121 raeburn 19900: }
19901: $resulttext = &mt('Changes made:').'<ul>';
19902: foreach my $item (sort(keys(%changes))) {
19903: if ($item eq 'canuse_pdfforms') {
19904: if ($env{'form.'.$item} eq '1') {
19905: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
19906: } else {
19907: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
19908: }
1.257 raeburn 19909: } elsif ($item eq 'uselcmath') {
19910: if ($env{'form.'.$item} eq '1') {
19911: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
19912: } else {
19913: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19914: }
19915: } elsif ($item eq 'usejsme') {
19916: if ($env{'form.'.$item} eq '1') {
19917: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19918: } else {
1.289 raeburn 19919: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 19920: }
1.314 raeburn 19921: } elsif ($item eq 'texengine') {
19922: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19923: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19924: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19925: }
1.139 raeburn 19926: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 19927: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 19928: } elsif ($item eq 'uploadquota') {
19929: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19930: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19931: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19932: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 19933: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 19934: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 19935: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19936: '</ul>'.
19937: '</li>';
19938: } else {
19939: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19940: }
1.276 raeburn 19941: } elsif ($item eq 'mysqltables') {
19942: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19943: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19944: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19945: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19946: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19947: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
19948: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19949: '</ul>'.
19950: '</li>';
19951: } else {
19952: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19953: }
1.257 raeburn 19954: } elsif ($item eq 'postsubmit') {
19955: if ($domdefaults{'postsubmit'} eq 'off') {
19956: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19957: } else {
19958: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 19959: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 19960: $resulttext .= &mt('durations:').'<ul>';
19961: foreach my $type (@types) {
19962: $resulttext .= '<li>';
19963: my $timeout;
19964: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19965: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19966: }
19967: my $display;
19968: if ($timeout eq '0') {
19969: $display = &mt('unlimited');
19970: } elsif ($timeout eq '') {
19971: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19972: } else {
19973: $display = &mt('[quant,_1,second]',$timeout);
19974: }
19975: if ($type eq 'community') {
19976: $resulttext .= &mt('Communities');
19977: } elsif ($type eq 'official') {
19978: $resulttext .= &mt('Official courses');
19979: } elsif ($type eq 'unofficial') {
19980: $resulttext .= &mt('Unofficial courses');
19981: } elsif ($type eq 'textbook') {
19982: $resulttext .= &mt('Textbook courses');
1.271 raeburn 19983: } elsif ($type eq 'placement') {
19984: $resulttext .= &mt('Placement tests');
1.257 raeburn 19985: }
19986: $resulttext .= ' -- '.$display.'</li>';
19987: }
19988: $resulttext .= '</ul>';
19989: }
1.289 raeburn 19990: $resulttext .= '</li>';
1.257 raeburn 19991: }
1.192 raeburn 19992: } elsif ($item eq 'coursecredits') {
19993: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19994: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 19995: ($domdefaults{'unofficialcredits'} eq '') &&
19996: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 19997: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19998: } else {
19999: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20000: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20001: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20002: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20003: '</ul>'.
20004: '</li>';
20005: }
20006: } else {
20007: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20008: }
1.264 raeburn 20009: } elsif ($item eq 'canclone') {
20010: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20011: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20012: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20013: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20014: }
20015: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20016: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20017: } else {
1.289 raeburn 20018: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20019: }
1.140 raeburn 20020: }
1.121 raeburn 20021: }
20022: $resulttext .= '</ul>';
20023: } else {
20024: $resulttext = &mt('No changes made to course defaults');
20025: }
20026: } else {
20027: $resulttext = '<span class="LC_error">'.
20028: &mt('An error occurred: [_1]',$putresult).'</span>';
20029: }
20030: return $resulttext;
20031: }
20032:
1.231 raeburn 20033: sub modify_selfenrollment {
20034: my ($dom,$lastactref,%domconfig) = @_;
20035: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20036: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20037: my %titles = &tool_titles();
1.232 raeburn 20038: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20039: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20040: $ordered{'default'} = ['types','registered','approval','limit'];
20041:
20042: my (%roles,%shown,%toplevel);
20043: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20044:
20045: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20046: if ($domconfig{'selfenrollment'} eq '') {
20047: $domconfig{'selfenrollment'} = {};
20048: }
20049: }
20050: %toplevel = (
20051: admin => 'Configuration Rights',
20052: default => 'Default settings',
20053: validation => 'Validation of self-enrollment requests',
20054: );
1.233 raeburn 20055: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20056:
20057: if (ref($ordered{'admin'}) eq 'ARRAY') {
20058: foreach my $item (@{$ordered{'admin'}}) {
20059: foreach my $type (@types) {
20060: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20061: $selfenrollhash{'admin'}{$type}{$item} = 1;
20062: } else {
20063: $selfenrollhash{'admin'}{$type}{$item} = 0;
20064: }
20065: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20066: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20067: if ($selfenrollhash{'admin'}{$type}{$item} ne
20068: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20069: push(@{$changes{'admin'}{$type}},$item);
20070: }
20071: } else {
20072: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20073: push(@{$changes{'admin'}{$type}},$item);
20074: }
20075: }
20076: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20077: push(@{$changes{'admin'}{$type}},$item);
20078: }
20079: }
20080: }
20081: }
20082:
20083: foreach my $item (@{$ordered{'default'}}) {
20084: foreach my $type (@types) {
20085: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20086: if ($item eq 'types') {
20087: unless (($value eq 'all') || ($value eq 'dom')) {
20088: $value = '';
20089: }
20090: } elsif ($item eq 'registered') {
20091: unless ($value eq '1') {
20092: $value = 0;
20093: }
20094: } elsif ($item eq 'approval') {
20095: unless ($value =~ /^[012]$/) {
20096: $value = 0;
20097: }
20098: } else {
20099: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20100: $value = 'none';
20101: }
20102: }
20103: $selfenrollhash{'default'}{$type}{$item} = $value;
20104: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20105: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20106: if ($selfenrollhash{'default'}{$type}{$item} ne
20107: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20108: push(@{$changes{'default'}{$type}},$item);
20109: }
20110: } else {
20111: push(@{$changes{'default'}{$type}},$item);
20112: }
20113: } else {
20114: push(@{$changes{'default'}{$type}},$item);
20115: }
20116: if ($item eq 'limit') {
20117: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20118: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20119: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20120: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20121: }
20122: } else {
20123: $selfenrollhash{'default'}{$type}{'cap'} = '';
20124: }
20125: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20126: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20127: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20128: push(@{$changes{'default'}{$type}},'cap');
20129: }
20130: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20131: push(@{$changes{'default'}{$type}},'cap');
20132: }
20133: }
20134: }
20135: }
20136:
20137: foreach my $item (@{$itemsref}) {
20138: if ($item eq 'fields') {
20139: my @changed;
20140: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20141: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20142: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20143: }
20144: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20145: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20146: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20147: $domconfig{'selfenrollment'}{'validation'}{$item});
20148: } else {
20149: @changed = @{$selfenrollhash{'validation'}{$item}};
20150: }
20151: } else {
20152: @changed = @{$selfenrollhash{'validation'}{$item}};
20153: }
20154: if (@changed) {
20155: if ($selfenrollhash{'validation'}{$item}) {
20156: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20157: } else {
20158: $changes{'validation'}{$item} = &mt('None');
20159: }
20160: }
20161: } else {
20162: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20163: if ($item eq 'markup') {
20164: if ($env{'form.selfenroll_validation_'.$item}) {
20165: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20166: }
20167: }
20168: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20169: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20170: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20171: }
20172: }
20173: }
20174: }
20175:
20176: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20177: $dom);
20178: if ($putresult eq 'ok') {
20179: if (keys(%changes) > 0) {
20180: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20181: $resulttext = &mt('Changes made:').'<ul>';
20182: foreach my $key ('admin','default','validation') {
20183: if (ref($changes{$key}) eq 'HASH') {
20184: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20185: if ($key eq 'validation') {
20186: foreach my $item (@{$itemsref}) {
20187: if (exists($changes{$key}{$item})) {
20188: if ($item eq 'markup') {
20189: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20190: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20191: } else {
20192: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20193: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20194: }
20195: }
20196: }
20197: } else {
20198: foreach my $type (@types) {
20199: if ($type eq 'community') {
20200: $roles{'1'} = &mt('Community personnel');
20201: } else {
20202: $roles{'1'} = &mt('Course personnel');
20203: }
20204: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20205: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20206: if ($key eq 'admin') {
20207: my @mgrdc = ();
20208: if (ref($ordered{$key}) eq 'ARRAY') {
20209: foreach my $item (@{$ordered{'admin'}}) {
20210: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20211: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20212: push(@mgrdc,$item);
20213: }
20214: }
20215: }
20216: if (@mgrdc) {
20217: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20218: } else {
20219: delete($domdefaults{$type.'selfenrolladmdc'});
20220: }
20221: }
20222: } else {
20223: if (ref($ordered{$key}) eq 'ARRAY') {
20224: foreach my $item (@{$ordered{$key}}) {
20225: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20226: $domdefaults{$type.'selfenroll'.$item} =
20227: $selfenrollhash{$key}{$type}{$item};
20228: }
20229: }
20230: }
20231: }
20232: }
1.231 raeburn 20233: $resulttext .= '<li>'.$titles{$type}.'<ul>';
20234: foreach my $item (@{$ordered{$key}}) {
20235: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20236: $resulttext .= '<li>';
20237: if ($key eq 'admin') {
20238: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
20239: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
20240: } else {
20241: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
20242: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
20243: }
20244: $resulttext .= '</li>';
20245: }
20246: }
20247: $resulttext .= '</ul></li>';
20248: }
20249: }
20250: $resulttext .= '</ul></li>';
20251: }
20252: }
1.305 raeburn 20253: }
20254: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
20255: my $cachetime = 24*60*60;
20256: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20257: if (ref($lastactref) eq 'HASH') {
20258: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 20259: }
1.231 raeburn 20260: }
20261: $resulttext .= '</ul>';
20262: } else {
20263: $resulttext = &mt('No changes made to self-enrollment settings');
20264: }
20265: } else {
20266: $resulttext = '<span class="LC_error">'.
20267: &mt('An error occurred: [_1]',$putresult).'</span>';
20268: }
20269: return $resulttext;
20270: }
20271:
1.373 raeburn 20272: sub modify_wafproxy {
20273: my ($dom,$action,$lastactref,%domconfig) = @_;
20274: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 20275: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
20276: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 20277: foreach my $server (sort(keys(%servers))) {
20278: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20279: if ($serverhome eq $server) {
20280: my $serverdom = &Apache::lonnet::host_domain($server);
20281: if ($serverdom eq $dom) {
20282: $canset{$server} = 1;
20283: }
20284: }
20285: }
1.381 raeburn 20286: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
20287: %{$values{$dom}} = ();
20288: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
20289: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
20290: }
1.388 raeburn 20291: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
20292: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
20293: }
1.382 raeburn 20294: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 20295: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
20296: }
20297: }
1.373 raeburn 20298: my $output;
20299: if (keys(%canset)) {
20300: %{$wafproxy{'alias'}} = ();
1.388 raeburn 20301: %{$wafproxy{'saml'}} = ();
1.373 raeburn 20302: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 20303: if ($env{'form.wafproxy_'.$dom}) {
20304: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
20305: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
20306: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
20307: $changes{'alias'} = 1;
20308: }
1.388 raeburn 20309: if ($env{'form.wafproxy_alias_saml_'.$key}) {
20310: $wafproxy{'saml'}{$key} = 1;
20311: }
20312: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
20313: $changes{'saml'} = 1;
20314: }
1.381 raeburn 20315: } else {
20316: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 20317: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 20318: if ($curralias{$key}) {
20319: $changes{'alias'} = 1;
20320: }
1.388 raeburn 20321: if ($currsaml{$key}) {
20322: $changes{'saml'} = 1;
20323: }
1.373 raeburn 20324: }
20325: if ($wafproxy{'alias'}{$key} eq '') {
20326: if ($curralias{$key}) {
20327: $expirecache{$key} = 1;
20328: }
20329: delete($wafproxy{'alias'}{$key});
20330: }
1.388 raeburn 20331: if ($wafproxy{'saml'}{$key} eq '') {
20332: if ($currsaml{$key}) {
20333: $expiresaml{$key} = 1;
20334: }
20335: delete($wafproxy{'saml'}{$key});
20336: }
1.373 raeburn 20337: }
20338: unless (keys(%{$wafproxy{'alias'}})) {
20339: delete($wafproxy{'alias'});
20340: }
1.388 raeburn 20341: unless (keys(%{$wafproxy{'saml'}})) {
20342: delete($wafproxy{'saml'});
20343: }
20344: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 20345: my %warn = (
20346: trusted => 'trusted IP range(s)',
1.381 raeburn 20347: vpnint => 'internal IP range(s) for VPN sessions(s)',
20348: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 20349: );
1.382 raeburn 20350: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20351: my $possible = $env{'form.wafproxy_'.$item};
20352: $possible =~ s/^\s+|\s+$//g;
20353: if ($possible ne '') {
1.381 raeburn 20354: if ($item eq 'remoteip') {
20355: if ($possible =~ /^[mhn]$/) {
20356: $wafproxy{$item} = $possible;
20357: }
20358: } elsif ($item eq 'ipheader') {
20359: if ($wafproxy{'remoteip'} eq 'h') {
20360: $wafproxy{$item} = $possible;
20361: }
1.382 raeburn 20362: } elsif ($item eq 'sslopt') {
20363: if ($possible =~ /^0|1$/) {
20364: $wafproxy{$item} = $possible;
20365: }
1.373 raeburn 20366: } else {
20367: my (@ok,$count);
1.381 raeburn 20368: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
20369: unless ($env{'form.wafproxy_vpnaccess'}) {
20370: $possible = '';
20371: }
20372: } elsif ($item eq 'trusted') {
20373: unless ($wafproxy{'remoteip'} eq 'h') {
20374: $possible = '';
20375: }
20376: }
20377: unless ($possible eq '') {
20378: $possible =~ s/[\r\n]+/\s/g;
20379: $possible =~ s/\s*-\s*/-/g;
20380: $possible =~ s/\s+/,/g;
20381: }
1.373 raeburn 20382: $count = 0;
1.381 raeburn 20383: if ($possible ne '') {
1.373 raeburn 20384: foreach my $poss (split(/\,/,$possible)) {
20385: $count ++;
20386: if (&validate_ip_pattern($poss)) {
20387: push(@ok,$poss);
20388: }
20389: }
20390: if (@ok) {
20391: $wafproxy{$item} = join(',',@ok);
20392: }
20393: my $diff = $count - scalar(@ok);
20394: if ($diff) {
20395: push(@warnings,'<li>'.
20396: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
20397: $diff,$warn{$item}).
20398: '</li>');
20399: }
20400: }
20401: }
1.381 raeburn 20402: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 20403: $changes{$item} = 1;
20404: }
1.381 raeburn 20405: } elsif ($currvalue{$item}) {
20406: $changes{$item} = 1;
20407: }
20408: }
20409: } else {
20410: if (keys(%curralias)) {
20411: $changes{'alias'} = 1;
1.388 raeburn 20412: }
20413: if (keys(%currsaml)) {
20414: $changes{'saml'} = 1;
1.381 raeburn 20415: }
20416: if (keys(%currvalue)) {
20417: foreach my $key (keys(%currvalue)) {
20418: $changes{$key} = 1;
1.373 raeburn 20419: }
20420: }
20421: }
20422: if (keys(%changes)) {
20423: my %defaultshash = (
20424: wafproxy => \%wafproxy,
20425: );
20426: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20427: $dom);
20428: if ($putresult eq 'ok') {
20429: my $cachetime = 24*60*60;
20430: my (%domdefaults,$updatedomdefs);
1.382 raeburn 20431: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20432: if ($changes{$item}) {
20433: unless ($updatedomdefs) {
20434: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20435: $updatedomdefs = 1;
20436: }
20437: if ($wafproxy{$item}) {
20438: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20439: } elsif (exists($domdefaults{'waf_'.$item})) {
20440: delete($domdefaults{'waf_'.$item});
20441: }
20442: }
20443: }
20444: if ($updatedomdefs) {
20445: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20446: if (ref($lastactref) eq 'HASH') {
20447: $lastactref->{'domdefaults'} = 1;
20448: }
20449: }
20450: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20451: my %updates = %expirecache;
20452: foreach my $key (keys(%expirecache)) {
20453: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20454: }
20455: if (ref($wafproxy{'alias'}) eq 'HASH') {
20456: my $cachetime = 24*60*60;
20457: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20458: $updates{$key} = 1;
20459: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20460: $cachetime);
20461: }
20462: }
20463: if (ref($lastactref) eq 'HASH') {
20464: $lastactref->{'proxyalias'} = \%updates;
20465: }
20466: }
1.388 raeburn 20467: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20468: my %samlupdates = %expiresaml;
20469: foreach my $key (keys(%expiresaml)) {
20470: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20471: }
20472: if (ref($wafproxy{'saml'}) eq 'HASH') {
20473: my $cachetime = 24*60*60;
20474: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20475: $samlupdates{$key} = 1;
20476: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20477: $cachetime);
20478: }
20479: }
20480: if (ref($lastactref) eq 'HASH') {
20481: $lastactref->{'proxysaml'} = \%samlupdates;
20482: }
20483: }
1.373 raeburn 20484: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382 raeburn 20485: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20486: if ($changes{$item}) {
20487: if ($item eq 'alias') {
20488: my $numaliased = 0;
20489: if (ref($wafproxy{'alias'}) eq 'HASH') {
20490: my $shown;
20491: if (keys(%{$wafproxy{'alias'}})) {
20492: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20493: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20494: &Apache::lonnet::hostname($server),
20495: $wafproxy{'alias'}{$server}).'</li>';
20496: $numaliased ++;
20497: }
20498: if ($numaliased) {
20499: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20500: '<ul>'.$shown.'</ul>').'</li>';
20501: }
20502: }
20503: }
20504: unless ($numaliased) {
20505: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20506: }
1.388 raeburn 20507: } elsif ($item eq 'saml') {
20508: my $shown;
20509: if (ref($wafproxy{'saml'}) eq 'HASH') {
20510: if (keys(%{$wafproxy{'saml'}})) {
20511: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20512: }
20513: }
20514: if ($shown) {
20515: $output .= '<li>'.&mt('Alias used by Shibboleth for: [_1]',
20516: $shown).'</li>';
20517: } else {
20518: $output .= '<li>'.&mt('No alias used for Shibboleth').'</li>';
20519: }
1.373 raeburn 20520: } else {
1.381 raeburn 20521: if ($item eq 'remoteip') {
20522: my %ip_methods = &remoteip_methods();
20523: if ($wafproxy{$item} =~ /^[mh]$/) {
20524: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20525: $ip_methods{$wafproxy{$item}}).'</li>';
20526: } else {
20527: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20528: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20529: '</li>';
20530: } else {
20531: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20532: }
20533: }
20534: } elsif ($item eq 'ipheader') {
1.373 raeburn 20535: if ($wafproxy{$item}) {
1.381 raeburn 20536: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 20537: $wafproxy{$item}).'</li>';
20538: } else {
1.381 raeburn 20539: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 20540: }
20541: } elsif ($item eq 'trusted') {
20542: if ($wafproxy{$item}) {
1.381 raeburn 20543: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 20544: $wafproxy{$item}).'</li>';
20545: } else {
20546: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20547: }
1.381 raeburn 20548: } elsif ($item eq 'vpnint') {
20549: if ($wafproxy{$item}) {
20550: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20551: $wafproxy{$item}).'</li>';
20552: } else {
20553: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20554: }
20555: } elsif ($item eq 'vpnext') {
1.373 raeburn 20556: if ($wafproxy{$item}) {
1.381 raeburn 20557: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 20558: $wafproxy{$item}).'</li>';
20559: } else {
1.381 raeburn 20560: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 20561: }
1.382 raeburn 20562: } elsif ($item eq 'sslopt') {
20563: if ($wafproxy{$item}) {
20564: $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>';
20565: } else {
20566: $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>';
20567: }
1.373 raeburn 20568: }
20569: }
20570: }
20571: }
20572: } else {
20573: $output = '<span class="LC_error">'.
20574: &mt('An error occurred: [_1]',$putresult).'</span>';
20575: }
20576: } elsif (keys(%canset)) {
20577: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20578: }
20579: if (@warnings) {
20580: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20581: join("\n",@warnings).'</ul>';
20582: }
20583: return $output;
20584: }
20585:
20586: sub validate_ip_pattern {
20587: my ($pattern) = @_;
20588: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20589: my ($start,$end) = ($1,$2);
20590: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20591: return 1;
20592: }
20593: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
20594: return 1;
20595: }
20596: return
20597: }
20598:
1.137 raeburn 20599: sub modify_usersessions {
1.212 raeburn 20600: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20601: my @hostingtypes = ('version','excludedomain','includedomain');
20602: my @offloadtypes = ('primary','default');
20603: my %types = (
20604: remote => \@hostingtypes,
20605: hosted => \@hostingtypes,
20606: spares => \@offloadtypes,
20607: );
20608: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20609: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 20610: my (%by_ip,%by_location,@intdoms,@instdoms);
20611: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 20612: my @locations = sort(keys(%by_location));
1.137 raeburn 20613: my (%defaultshash,%changes);
20614: foreach my $prefix (@prefixes) {
20615: $defaultshash{'usersessions'}{$prefix} = {};
20616: }
1.212 raeburn 20617: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20618: my $resulttext;
1.138 raeburn 20619: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20620: foreach my $prefix (@prefixes) {
1.145 raeburn 20621: next if ($prefix eq 'spares');
20622: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20623: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20624: if ($type eq 'version') {
20625: my $value = $env{'form.'.$prefix.'_'.$type};
20626: my $okvalue;
20627: if ($value ne '') {
20628: if (grep(/^\Q$value\E$/,@lcversions)) {
20629: $okvalue = $value;
20630: }
20631: }
20632: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20633: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20634: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20635: if ($inuse == 0) {
20636: $changes{$prefix}{$type} = 1;
20637: } else {
20638: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20639: $changes{$prefix}{$type} = 1;
20640: }
20641: if ($okvalue ne '') {
20642: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20643: }
20644: }
20645: } else {
20646: if (($inuse == 1) && ($okvalue ne '')) {
20647: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20648: $changes{$prefix}{$type} = 1;
20649: }
20650: }
20651: } else {
20652: if (($inuse == 1) && ($okvalue ne '')) {
20653: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20654: $changes{$prefix}{$type} = 1;
20655: }
20656: }
20657: } else {
20658: if (($inuse == 1) && ($okvalue ne '')) {
20659: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20660: $changes{$prefix}{$type} = 1;
20661: }
20662: }
20663: } else {
20664: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20665: my @okvals;
20666: foreach my $val (@vals) {
1.138 raeburn 20667: if ($val =~ /:/) {
20668: my @items = split(/:/,$val);
20669: foreach my $item (@items) {
20670: if (ref($by_location{$item}) eq 'ARRAY') {
20671: push(@okvals,$item);
20672: }
20673: }
20674: } else {
20675: if (ref($by_location{$val}) eq 'ARRAY') {
20676: push(@okvals,$val);
20677: }
1.137 raeburn 20678: }
20679: }
20680: @okvals = sort(@okvals);
20681: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20682: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20683: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20684: if ($inuse == 0) {
20685: $changes{$prefix}{$type} = 1;
20686: } else {
20687: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20688: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20689: if (@changed > 0) {
20690: $changes{$prefix}{$type} = 1;
20691: }
20692: }
20693: } else {
20694: if ($inuse == 1) {
20695: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20696: $changes{$prefix}{$type} = 1;
20697: }
20698: }
20699: } else {
20700: if ($inuse == 1) {
20701: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20702: $changes{$prefix}{$type} = 1;
20703: }
20704: }
20705: } else {
20706: if ($inuse == 1) {
20707: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20708: $changes{$prefix}{$type} = 1;
20709: }
20710: }
20711: }
20712: }
20713: }
1.145 raeburn 20714:
20715: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20716: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20717: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20718: my $savespares;
20719:
20720: foreach my $lonhost (sort(keys(%servers))) {
20721: my $serverhomeID =
20722: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20723: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20724: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20725: my %spareschg;
20726: foreach my $type (@{$types{'spares'}}) {
20727: my @okspares;
20728: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20729: foreach my $server (@checked) {
1.152 raeburn 20730: if (&Apache::lonnet::hostname($server) ne '') {
20731: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20732: unless (grep(/^\Q$server\E$/,@okspares)) {
20733: push(@okspares,$server);
20734: }
1.145 raeburn 20735: }
20736: }
20737: }
20738: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20739: my $newspare;
1.152 raeburn 20740: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20741: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20742: $newspare = $new;
20743: }
20744: }
1.152 raeburn 20745: my @spares;
20746: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20747: @spares = sort(@okspares,$newspare);
20748: } else {
20749: @spares = sort(@okspares);
20750: }
20751: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20752: if (ref($spareid{$lonhost}) eq 'HASH') {
20753: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20754: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20755: if (@diffs > 0) {
20756: $spareschg{$type} = 1;
20757: }
20758: }
20759: }
20760: }
20761: if (keys(%spareschg) > 0) {
20762: $changes{'spares'}{$lonhost} = \%spareschg;
20763: }
20764: }
1.261 raeburn 20765: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 20766: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 20767: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20768: my @okoffload;
20769: if (@offloadnow) {
20770: foreach my $server (@offloadnow) {
20771: if (&Apache::lonnet::hostname($server) ne '') {
20772: unless (grep(/^\Q$server\E$/,@okoffload)) {
20773: push(@okoffload,$server);
20774: }
20775: }
20776: }
20777: if (@okoffload) {
20778: foreach my $lonhost (@okoffload) {
20779: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20780: }
20781: }
20782: }
1.371 raeburn 20783: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20784: my @okoffloadoth;
20785: if (@offloadoth) {
20786: foreach my $server (@offloadoth) {
20787: if (&Apache::lonnet::hostname($server) ne '') {
20788: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20789: push(@okoffloadoth,$server);
20790: }
20791: }
20792: }
20793: if (@okoffloadoth) {
20794: foreach my $lonhost (@okoffloadoth) {
20795: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20796: }
20797: }
20798: }
1.145 raeburn 20799: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20800: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20801: if (ref($changes{'spares'}) eq 'HASH') {
20802: if (keys(%{$changes{'spares'}}) > 0) {
20803: $savespares = 1;
20804: }
20805: }
20806: } else {
20807: $savespares = 1;
20808: }
1.371 raeburn 20809: foreach my $offload ('offloadnow','offloadoth') {
20810: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20811: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20812: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20813: $changes{$offload} = 1;
20814: last;
20815: }
1.261 raeburn 20816: }
1.371 raeburn 20817: unless ($changes{$offload}) {
20818: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20819: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20820: $changes{$offload} = 1;
20821: last;
20822: }
1.261 raeburn 20823: }
20824: }
1.371 raeburn 20825: } else {
20826: if (($offload eq 'offloadnow') && (@okoffload)) {
20827: $changes{'offloadnow'} = 1;
20828: }
20829: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20830: $changes{'offloadoth'} = 1;
20831: }
20832: }
20833: }
20834: } else {
20835: if (@okoffload) {
1.261 raeburn 20836: $changes{'offloadnow'} = 1;
20837: }
1.371 raeburn 20838: if (@okoffloadoth) {
20839: $changes{'offloadoth'} = 1;
20840: }
1.145 raeburn 20841: }
1.147 raeburn 20842: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20843: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20844: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20845: $dom);
20846: if ($putresult eq 'ok') {
20847: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20848: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20849: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20850: }
20851: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20852: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20853: }
1.261 raeburn 20854: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20855: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20856: }
1.371 raeburn 20857: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20858: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20859: }
1.137 raeburn 20860: }
20861: my $cachetime = 24*60*60;
20862: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20863: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20864: if (ref($lastactref) eq 'HASH') {
20865: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20866: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20867: }
1.147 raeburn 20868: if (keys(%changes) > 0) {
20869: my %lt = &usersession_titles();
20870: $resulttext = &mt('Changes made:').'<ul>';
20871: foreach my $prefix (@prefixes) {
20872: if (ref($changes{$prefix}) eq 'HASH') {
20873: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20874: if ($prefix eq 'spares') {
20875: if (ref($changes{$prefix}) eq 'HASH') {
20876: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20877: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20878: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20879: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20880: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20881: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20882: foreach my $type (@{$types{$prefix}}) {
20883: if ($changes{$prefix}{$lonhost}{$type}) {
20884: my $offloadto = &mt('None');
20885: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20886: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20887: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20888: }
1.145 raeburn 20889: }
1.147 raeburn 20890: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20891: }
1.137 raeburn 20892: }
20893: }
1.147 raeburn 20894: $resulttext .= '</li>';
1.137 raeburn 20895: }
20896: }
1.147 raeburn 20897: } else {
20898: foreach my $type (@{$types{$prefix}}) {
20899: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20900: my ($newvalue,$notinuse);
1.147 raeburn 20901: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20902: if (ref($defaultshash{'usersessions'}{$prefix})) {
20903: if ($type eq 'version') {
20904: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 20905: } else {
20906: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20907: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20908: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20909: }
20910: } else {
20911: $notinuse = 1;
1.147 raeburn 20912: }
1.145 raeburn 20913: }
20914: }
20915: }
1.147 raeburn 20916: if ($newvalue eq '') {
20917: if ($type eq 'version') {
20918: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 20919: } elsif ($notinuse) {
20920: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 20921: } else {
20922: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20923: }
1.145 raeburn 20924: } else {
1.147 raeburn 20925: if ($type eq 'version') {
1.344 raeburn 20926: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20927: }
20928: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20929: }
1.137 raeburn 20930: }
20931: }
20932: }
1.147 raeburn 20933: $resulttext .= '</ul>';
1.137 raeburn 20934: }
20935: }
1.261 raeburn 20936: if ($changes{'offloadnow'}) {
20937: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20938: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 20939: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 20940: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20941: $resulttext .= '<li>'.$lonhost.'</li>';
20942: }
20943: $resulttext .= '</ul>';
20944: } else {
1.371 raeburn 20945: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20946: }
20947: } else {
20948: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20949: }
20950: }
20951: if ($changes{'offloadoth'}) {
20952: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20953: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20954: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20955: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20956: $resulttext .= '<li>'.$lonhost.'</li>';
20957: }
20958: $resulttext .= '</ul>';
20959: } else {
20960: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 20961: }
20962: } else {
1.371 raeburn 20963: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 20964: }
20965: }
1.147 raeburn 20966: $resulttext .= '</ul>';
20967: } else {
20968: $resulttext = $nochgmsg;
1.137 raeburn 20969: }
20970: } else {
20971: $resulttext = '<span class="LC_error">'.
20972: &mt('An error occurred: [_1]',$putresult).'</span>';
20973: }
20974: } else {
1.147 raeburn 20975: $resulttext = $nochgmsg;
1.137 raeburn 20976: }
20977: return $resulttext;
20978: }
20979:
1.275 raeburn 20980: sub modify_ssl {
20981: my ($dom,$lastactref,%domconfig) = @_;
20982: my (%by_ip,%by_location,@intdoms,@instdoms);
20983: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20984: my @locations = sort(keys(%by_location));
20985: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20986: my (%defaultshash,%changes);
20987: my $action = 'ssl';
1.293 raeburn 20988: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 20989: foreach my $prefix (@prefixes) {
20990: $defaultshash{$action}{$prefix} = {};
20991: }
20992: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20993: my $resulttext;
20994: my %iphost = &Apache::lonnet::get_iphost();
20995: my @reptypes = ('certreq','nocertreq');
20996: my @connecttypes = ('dom','intdom','other');
20997: my %types = (
1.293 raeburn 20998: connto => \@connecttypes,
20999: connfrom => \@connecttypes,
21000: replication => \@reptypes,
1.275 raeburn 21001: );
21002: foreach my $prefix (sort(keys(%types))) {
21003: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21004: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21005: my $value = 'yes';
21006: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21007: $value = $env{'form.'.$prefix.'_'.$type};
21008: }
1.335 raeburn 21009: if (ref($domconfig{$action}) eq 'HASH') {
21010: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21011: if ($domconfig{$action}{$prefix}{$type} ne '') {
21012: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21013: $changes{$prefix}{$type} = 1;
21014: }
21015: $defaultshash{$action}{$prefix}{$type} = $value;
21016: } else {
21017: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21018: $changes{$prefix}{$type} = 1;
21019: }
21020: } else {
21021: $defaultshash{$action}{$prefix}{$type} = $value;
21022: $changes{$prefix}{$type} = 1;
21023: }
21024: } else {
21025: $defaultshash{$action}{$prefix}{$type} = $value;
21026: $changes{$prefix}{$type} = 1;
21027: }
21028: if (($type eq 'dom') && (keys(%servers) == 1)) {
21029: delete($changes{$prefix}{$type});
21030: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21031: delete($changes{$prefix}{$type});
21032: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21033: delete($changes{$prefix}{$type});
21034: }
21035: } elsif ($prefix eq 'replication') {
21036: if (@locations > 0) {
21037: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21038: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21039: my @okvals;
21040: foreach my $val (@vals) {
21041: if ($val =~ /:/) {
21042: my @items = split(/:/,$val);
21043: foreach my $item (@items) {
21044: if (ref($by_location{$item}) eq 'ARRAY') {
21045: push(@okvals,$item);
21046: }
21047: }
21048: } else {
21049: if (ref($by_location{$val}) eq 'ARRAY') {
21050: push(@okvals,$val);
21051: }
21052: }
21053: }
21054: @okvals = sort(@okvals);
21055: if (ref($domconfig{$action}) eq 'HASH') {
21056: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21057: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21058: if ($inuse == 0) {
21059: $changes{$prefix}{$type} = 1;
21060: } else {
21061: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21062: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21063: if (@changed > 0) {
21064: $changes{$prefix}{$type} = 1;
21065: }
21066: }
21067: } else {
21068: if ($inuse == 1) {
21069: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21070: $changes{$prefix}{$type} = 1;
21071: }
21072: }
21073: } else {
21074: if ($inuse == 1) {
21075: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21076: $changes{$prefix}{$type} = 1;
21077: }
21078: }
21079: } else {
21080: if ($inuse == 1) {
21081: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21082: $changes{$prefix}{$type} = 1;
21083: }
21084: }
21085: }
21086: }
21087: }
21088: }
1.336 raeburn 21089: if (keys(%changes)) {
21090: foreach my $prefix (keys(%changes)) {
21091: if (ref($changes{$prefix}) eq 'HASH') {
21092: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21093: delete($changes{$prefix});
21094: }
21095: } else {
21096: delete($changes{$prefix});
21097: }
21098: }
21099: }
1.275 raeburn 21100: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21101: if (keys(%changes) > 0) {
21102: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21103: $dom);
21104: if ($putresult eq 'ok') {
21105: if (ref($defaultshash{$action}) eq 'HASH') {
21106: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21107: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21108: }
1.293 raeburn 21109: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21110: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21111: }
21112: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21113: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21114: }
21115: }
21116: my $cachetime = 24*60*60;
21117: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21118: if (ref($lastactref) eq 'HASH') {
21119: $lastactref->{'domdefaults'} = 1;
21120: }
21121: if (keys(%changes) > 0) {
21122: my %titles = &ssl_titles();
21123: $resulttext = &mt('Changes made:').'<ul>';
21124: foreach my $prefix (@prefixes) {
21125: if (ref($changes{$prefix}) eq 'HASH') {
21126: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21127: foreach my $type (@{$types{$prefix}}) {
21128: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21129: my ($newvalue,$notinuse);
1.275 raeburn 21130: if (ref($defaultshash{$action}) eq 'HASH') {
21131: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21132: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21133: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21134: } else {
21135: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21136: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21137: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21138: }
21139: } else {
21140: $notinuse = 1;
1.275 raeburn 21141: }
21142: }
21143: }
1.344 raeburn 21144: if ($notinuse) {
21145: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21146: } elsif ($newvalue eq '') {
1.275 raeburn 21147: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21148: } else {
21149: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21150: }
21151: }
21152: }
21153: }
21154: $resulttext .= '</ul>';
21155: }
21156: }
21157: } else {
21158: $resulttext = $nochgmsg;
21159: }
21160: } else {
21161: $resulttext = '<span class="LC_error">'.
21162: &mt('An error occurred: [_1]',$putresult).'</span>';
21163: }
21164: } else {
21165: $resulttext = $nochgmsg;
21166: }
21167: return $resulttext;
21168: }
21169:
1.279 raeburn 21170: sub modify_trust {
21171: my ($dom,$lastactref,%domconfig) = @_;
21172: my (%by_ip,%by_location,@intdoms,@instdoms);
21173: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21174: my @locations = sort(keys(%by_location));
21175: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21176: my @types = ('exc','inc');
21177: my (%defaultshash,%changes);
21178: foreach my $prefix (@prefixes) {
21179: $defaultshash{'trust'}{$prefix} = {};
21180: }
21181: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21182: my $resulttext;
21183: foreach my $prefix (@prefixes) {
21184: foreach my $type (@types) {
21185: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21186: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21187: my @okvals;
21188: foreach my $val (@vals) {
21189: if ($val =~ /:/) {
21190: my @items = split(/:/,$val);
21191: foreach my $item (@items) {
21192: if (ref($by_location{$item}) eq 'ARRAY') {
21193: push(@okvals,$item);
21194: }
21195: }
21196: } else {
21197: if (ref($by_location{$val}) eq 'ARRAY') {
21198: push(@okvals,$val);
21199: }
21200: }
21201: }
21202: @okvals = sort(@okvals);
21203: if (ref($domconfig{'trust'}) eq 'HASH') {
21204: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21205: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21206: if ($inuse == 0) {
21207: $changes{$prefix}{$type} = 1;
21208: } else {
21209: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21210: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
21211: if (@changed > 0) {
21212: $changes{$prefix}{$type} = 1;
21213: }
21214: }
21215: } else {
21216: if ($inuse == 1) {
21217: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21218: $changes{$prefix}{$type} = 1;
21219: }
21220: }
21221: } else {
21222: if ($inuse == 1) {
21223: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21224: $changes{$prefix}{$type} = 1;
21225: }
21226: }
21227: } else {
21228: if ($inuse == 1) {
21229: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21230: $changes{$prefix}{$type} = 1;
21231: }
21232: }
21233: }
21234: }
21235: my $nochgmsg = &mt('No changes made to trust settings.');
21236: if (keys(%changes) > 0) {
21237: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21238: $dom);
21239: if ($putresult eq 'ok') {
21240: if (ref($defaultshash{'trust'}) eq 'HASH') {
21241: foreach my $prefix (@prefixes) {
21242: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
21243: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
21244: }
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 %lt = &trust_titles();
21254: $resulttext = &mt('Changes made:').'<ul>';
21255: foreach my $prefix (@prefixes) {
21256: if (ref($changes{$prefix}) eq 'HASH') {
21257: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21258: foreach my $type (@types) {
21259: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21260: my ($newvalue,$notinuse);
1.279 raeburn 21261: if (ref($defaultshash{'trust'}) eq 'HASH') {
21262: if (ref($defaultshash{'trust'}{$prefix})) {
21263: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21264: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
21265: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
21266: }
1.344 raeburn 21267: } else {
21268: $notinuse = 1;
1.279 raeburn 21269: }
21270: }
21271: }
1.344 raeburn 21272: if ($notinuse) {
21273: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
21274: } elsif ($newvalue eq '') {
1.279 raeburn 21275: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21276: } else {
21277: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
21278: }
21279: }
21280: }
21281: $resulttext .= '</ul>';
21282: }
21283: }
21284: $resulttext .= '</ul>';
21285: } else {
21286: $resulttext = $nochgmsg;
21287: }
21288: } else {
21289: $resulttext = '<span class="LC_error">'.
21290: &mt('An error occurred: [_1]',$putresult).'</span>';
21291: }
21292: } else {
21293: $resulttext = $nochgmsg;
21294: }
21295: return $resulttext;
21296: }
21297:
1.150 raeburn 21298: sub modify_loadbalancing {
21299: my ($dom,%domconfig) = @_;
21300: my $primary_id = &Apache::lonnet::domain($dom,'primary');
21301: my $intdom = &Apache::lonnet::internet_dom($primary_id);
21302: my ($othertitle,$usertypes,$types) =
21303: &Apache::loncommon::sorted_inst_types($dom);
21304: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 21305: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 21306: my @sparestypes = ('primary','default');
21307: my %typetitles = &sparestype_titles();
21308: my $resulttext;
1.342 raeburn 21309: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21310: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21311: %existing = %{$domconfig{'loadbalancing'}};
21312: }
21313: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 21314: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 21315: my ($saveloadbalancing,%defaultshash,%changes);
21316: my ($alltypes,$othertypes,$titles) =
21317: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
21318: my %ruletitles = &offloadtype_text();
21319: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
21320: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
21321: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
21322: if ($balancer eq '') {
21323: next;
21324: }
1.210 raeburn 21325: if (!exists($servers{$balancer})) {
1.171 raeburn 21326: if (exists($currbalancer{$balancer})) {
21327: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 21328: }
1.171 raeburn 21329: next;
21330: }
21331: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
21332: push(@{$changes{'delete'}},$balancer);
21333: next;
21334: }
21335: if (!exists($currbalancer{$balancer})) {
21336: push(@{$changes{'add'}},$balancer);
21337: }
21338: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
21339: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
21340: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
21341: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21342: $saveloadbalancing = 1;
21343: }
21344: foreach my $sparetype (@sparestypes) {
21345: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
21346: my @offloadto;
21347: foreach my $target (@targets) {
21348: if (($servers{$target}) && ($target ne $balancer)) {
21349: if ($sparetype eq 'default') {
21350: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
21351: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 21352: }
21353: }
1.171 raeburn 21354: unless(grep(/^\Q$target\E$/,@offloadto)) {
21355: push(@offloadto,$target);
21356: }
1.150 raeburn 21357: }
21358: }
1.284 raeburn 21359: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
21360: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
21361: push(@offloadto,$balancer);
21362: }
21363: }
21364: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 21365: }
1.342 raeburn 21366: if ($env{'form.loadbalancing_cookie_'.$i}) {
21367: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
21368: if (exists($currbalancer{$balancer})) {
21369: unless ($currcookies{$balancer}) {
21370: $changes{'curr'}{$balancer}{'cookie'} = 1;
21371: }
21372: }
21373: } elsif (exists($currbalancer{$balancer})) {
21374: if ($currcookies{$balancer}) {
21375: $changes{'curr'}{$balancer}{'cookie'} = 1;
21376: }
21377: }
1.171 raeburn 21378: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 21379: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21380: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
21381: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 21382: if (@targetdiffs > 0) {
1.171 raeburn 21383: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21384: }
1.171 raeburn 21385: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21386: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21387: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21388: }
21389: }
21390: }
21391: } else {
1.171 raeburn 21392: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 21393: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21394: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21395: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21396: $changes{'curr'}{$balancer}{'targets'} = 1;
21397: }
1.150 raeburn 21398: }
21399: }
1.210 raeburn 21400: }
1.150 raeburn 21401: }
21402: my $ishomedom;
1.171 raeburn 21403: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
21404: $ishomedom = 1;
1.150 raeburn 21405: }
21406: if (ref($alltypes) eq 'ARRAY') {
21407: foreach my $type (@{$alltypes}) {
21408: my $rule;
1.210 raeburn 21409: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 21410: (!$ishomedom)) {
1.171 raeburn 21411: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
21412: }
21413: if ($rule eq 'specific') {
1.255 raeburn 21414: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 21415: if (exists($servers{$specifiedhost})) {
1.255 raeburn 21416: $rule = $specifiedhost;
21417: }
1.150 raeburn 21418: }
1.171 raeburn 21419: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
21420: if (ref($currrules{$balancer}) eq 'HASH') {
21421: if ($rule ne $currrules{$balancer}{$type}) {
21422: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21423: }
21424: } elsif ($rule ne '') {
1.171 raeburn 21425: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21426: }
21427: }
21428: }
1.171 raeburn 21429: }
21430: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
21431: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
21432: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
21433: $defaultshash{'loadbalancing'} = {};
21434: }
21435: my $putresult = &Apache::lonnet::put_dom('configuration',
21436: \%defaultshash,$dom);
21437: if ($putresult eq 'ok') {
21438: if (keys(%changes) > 0) {
1.252 raeburn 21439: my %toupdate;
1.171 raeburn 21440: if (ref($changes{'delete'}) eq 'ARRAY') {
21441: foreach my $balancer (sort(@{$changes{'delete'}})) {
21442: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 21443: $toupdate{$balancer} = 1;
1.150 raeburn 21444: }
1.171 raeburn 21445: }
21446: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 21447: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 21448: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 21449: $toupdate{$balancer} = 1;
1.171 raeburn 21450: }
21451: }
21452: if (ref($changes{'curr'}) eq 'HASH') {
21453: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 21454: $toupdate{$balancer} = 1;
1.171 raeburn 21455: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
21456: if ($changes{'curr'}{$balancer}{'targets'}) {
21457: my %offloadstr;
21458: foreach my $sparetype (@sparestypes) {
21459: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21460: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21461: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21462: }
21463: }
1.150 raeburn 21464: }
1.171 raeburn 21465: if (keys(%offloadstr) == 0) {
21466: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 21467: } else {
1.171 raeburn 21468: my $showoffload;
21469: foreach my $sparetype (@sparestypes) {
21470: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
21471: if (defined($offloadstr{$sparetype})) {
21472: $showoffload .= $offloadstr{$sparetype};
21473: } else {
21474: $showoffload .= &mt('None');
21475: }
21476: $showoffload .= (' 'x3);
21477: }
21478: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 21479: }
21480: }
21481: }
1.171 raeburn 21482: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
21483: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
21484: foreach my $type (@{$alltypes}) {
21485: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
21486: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21487: my $balancetext;
21488: if ($rule eq '') {
21489: $balancetext = $ruletitles{'default'};
1.209 raeburn 21490: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 21491: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 21492: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 21493: foreach my $sparetype (@sparestypes) {
21494: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21495: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21496: }
21497: }
1.253 raeburn 21498: foreach my $item (@{$alltypes}) {
21499: next if ($item =~ /^_LC_ipchange/);
21500: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
21501: if ($hasrule eq 'homeserver') {
21502: map { $toupdate{$_} = 1; } (keys(%libraryservers));
21503: } else {
21504: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
21505: if ($servers{$hasrule}) {
21506: $toupdate{$hasrule} = 1;
21507: }
21508: }
21509: }
21510: }
1.254 raeburn 21511: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
21512: $balancetext = $ruletitles{$rule};
21513: } else {
21514: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21515: $balancetext = $ruletitles{'particular'}.' '.$receiver;
21516: if ($receiver) {
21517: $toupdate{$receiver};
21518: }
21519: }
21520: } else {
21521: $balancetext = $ruletitles{$rule};
1.252 raeburn 21522: }
1.171 raeburn 21523: } else {
21524: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
21525: }
1.210 raeburn 21526: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 21527: }
21528: }
21529: }
21530: }
1.342 raeburn 21531: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 21532: if ($currcookies{$balancer}) {
21533: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
21534: $balancer).'</li>';
21535: } else {
21536: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
21537: $balancer).'</li>';
21538: }
1.342 raeburn 21539: }
1.375 raeburn 21540: }
21541: }
21542: if (keys(%toupdate)) {
21543: my %thismachine;
21544: my $updatedhere;
21545: my $cachetime = 60*60*24;
21546: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
21547: foreach my $lonhost (keys(%toupdate)) {
21548: if ($thismachine{$lonhost}) {
21549: unless ($updatedhere) {
21550: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
21551: $defaultshash{'loadbalancing'},
21552: $cachetime);
21553: $updatedhere = 1;
1.252 raeburn 21554: }
1.375 raeburn 21555: } else {
21556: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
21557: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 21558: }
1.150 raeburn 21559: }
1.171 raeburn 21560: }
21561: if ($resulttext ne '') {
21562: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 21563: } else {
21564: $resulttext = $nochgmsg;
21565: }
21566: } else {
1.171 raeburn 21567: $resulttext = $nochgmsg;
1.150 raeburn 21568: }
21569: } else {
1.171 raeburn 21570: $resulttext = '<span class="LC_error">'.
21571: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 21572: }
21573: } else {
1.171 raeburn 21574: $resulttext = $nochgmsg;
1.150 raeburn 21575: }
21576: return $resulttext;
21577: }
21578:
1.48 raeburn 21579: sub recurse_check {
21580: my ($chkcats,$categories,$depth,$name) = @_;
21581: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
21582: my $chg = 0;
21583: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
21584: my $category = $chkcats->[$depth]{$name}[$j];
21585: my $item;
21586: if ($category eq '') {
21587: $chg ++;
21588: } else {
21589: my $deeper = $depth + 1;
21590: $item = &escape($category).':'.&escape($name).':'.$depth;
21591: if ($chg) {
21592: $categories->{$item} -= $chg;
21593: }
21594: &recurse_check($chkcats,$categories,$deeper,$category);
21595: $deeper --;
21596: }
21597: }
21598: }
21599: return;
21600: }
21601:
21602: sub recurse_cat_deletes {
21603: my ($item,$coursecategories,$deletions) = @_;
21604: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
21605: my $subdepth = $depth + 1;
21606: if (ref($coursecategories) eq 'HASH') {
21607: foreach my $subitem (keys(%{$coursecategories})) {
21608: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
21609: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
21610: delete($coursecategories->{$subitem});
21611: $deletions->{$subitem} = 1;
21612: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 21613: }
1.48 raeburn 21614: }
21615: }
21616: return;
21617: }
21618:
1.125 raeburn 21619: sub active_dc_picker {
1.191 raeburn 21620: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 21621: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 21622: my @domcoord = keys(%domcoords);
21623: if (keys(%currhash)) {
21624: foreach my $dc (keys(%currhash)) {
21625: unless (exists($domcoords{$dc})) {
21626: push(@domcoord,$dc);
21627: }
21628: }
21629: }
21630: @domcoord = sort(@domcoord);
1.210 raeburn 21631: my $numdcs = scalar(@domcoord);
1.191 raeburn 21632: my $rows = 0;
21633: my $table;
1.125 raeburn 21634: if ($numdcs > 1) {
1.191 raeburn 21635: $table = '<table>';
21636: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 21637: my $rem = $i%($numinrow);
21638: if ($rem == 0) {
21639: if ($i > 0) {
1.191 raeburn 21640: $table .= '</tr>';
1.125 raeburn 21641: }
1.191 raeburn 21642: $table .= '<tr>';
21643: $rows ++;
1.125 raeburn 21644: }
1.191 raeburn 21645: my $check = '';
21646: if ($inputtype eq 'radio') {
21647: if (keys(%currhash) == 0) {
21648: if (!$i) {
21649: $check = ' checked="checked"';
21650: }
21651: } elsif (exists($currhash{$domcoord[$i]})) {
21652: $check = ' checked="checked"';
21653: }
21654: } else {
21655: if (exists($currhash{$domcoord[$i]})) {
21656: $check = ' checked="checked"';
1.125 raeburn 21657: }
21658: }
1.191 raeburn 21659: if ($i == @domcoord - 1) {
1.125 raeburn 21660: my $colsleft = $numinrow - $rem;
21661: if ($colsleft > 1) {
1.191 raeburn 21662: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 21663: } else {
1.191 raeburn 21664: $table .= '<td class="LC_left_item">';
1.125 raeburn 21665: }
21666: } else {
1.191 raeburn 21667: $table .= '<td class="LC_left_item">';
21668: }
21669: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
21670: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
21671: $table .= '<span class="LC_nobreak"><label>'.
21672: '<input type="'.$inputtype.'" name="'.$name.'"'.
21673: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
21674: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 21675: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 21676: }
1.219 raeburn 21677: $table .= '</label></span></td>';
1.191 raeburn 21678: }
21679: $table .= '</tr></table>';
21680: } elsif ($numdcs == 1) {
1.219 raeburn 21681: my ($dcname,$dcdom) = split(':',$domcoord[0]);
21682: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 21683: if ($inputtype eq 'radio') {
1.247 raeburn 21684: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 21685: if ($user ne $dcname.':'.$dcdom) {
21686: $table .= ' ('.$dcname.':'.$dcdom.')';
21687: }
1.191 raeburn 21688: } else {
21689: my $check;
21690: if (exists($currhash{$domcoord[0]})) {
21691: $check = ' checked="checked"';
1.125 raeburn 21692: }
1.247 raeburn 21693: $table = '<span class="LC_nobreak"><label>'.
21694: '<input type="checkbox" name="'.$name.'" '.
21695: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 21696: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 21697: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 21698: }
1.220 raeburn 21699: $table .= '</label></span>';
1.191 raeburn 21700: $rows ++;
1.125 raeburn 21701: }
21702: }
1.191 raeburn 21703: return ($numdcs,$table,$rows);
1.125 raeburn 21704: }
21705:
1.137 raeburn 21706: sub usersession_titles {
21707: return &Apache::lonlocal::texthash(
21708: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
21709: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 21710: spares => 'Servers offloaded to, when busy',
1.137 raeburn 21711: version => 'LON-CAPA version requirement',
1.138 raeburn 21712: excludedomain => 'Allow all, but exclude specific domains',
21713: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 21714: primary => 'Primary (checked first)',
1.154 raeburn 21715: default => 'Default',
1.137 raeburn 21716: );
21717: }
21718:
1.152 raeburn 21719: sub id_for_thisdom {
21720: my (%servers) = @_;
21721: my %altids;
21722: foreach my $server (keys(%servers)) {
21723: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21724: if ($serverhome ne $server) {
21725: $altids{$serverhome} = $server;
21726: }
21727: }
21728: return %altids;
21729: }
21730:
1.150 raeburn 21731: sub count_servers {
21732: my ($currbalancer,%servers) = @_;
21733: my (@spares,$numspares);
21734: foreach my $lonhost (sort(keys(%servers))) {
21735: next if ($currbalancer eq $lonhost);
21736: push(@spares,$lonhost);
21737: }
21738: if ($currbalancer) {
21739: $numspares = scalar(@spares);
21740: } else {
21741: $numspares = scalar(@spares) - 1;
21742: }
21743: return ($numspares,@spares);
21744: }
21745:
21746: sub lonbalance_targets_js {
1.171 raeburn 21747: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21748: my $select = &mt('Select');
21749: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21750: if (ref($servers) eq 'HASH') {
21751: $alltargets = join("','",sort(keys(%{$servers})));
21752: my @homedoms;
21753: foreach my $server (sort(keys(%{$servers}))) {
21754: if (&Apache::lonnet::host_domain($server) eq $dom) {
21755: push(@homedoms,'1');
21756: } else {
21757: push(@homedoms,'0');
21758: }
21759: }
21760: $allishome = join("','",@homedoms);
21761: }
21762: if (ref($types) eq 'ARRAY') {
21763: if (@{$types} > 0) {
21764: @alltypes = @{$types};
21765: }
21766: }
21767: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21768: $allinsttypes = join("','",@alltypes);
1.342 raeburn 21769: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21770: if (ref($settings) eq 'HASH') {
21771: %existing = %{$settings};
21772: }
21773: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 21774: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 21775: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21776: return <<"END";
21777:
21778: <script type="text/javascript">
21779: // <![CDATA[
21780:
1.171 raeburn 21781: currBalancers = new Array('$balancers');
21782:
21783: function toggleTargets(balnum) {
21784: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21785: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21786: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21787: var prevbalancer = prevhostitem.value;
21788: var baltotal = document.getElementById('loadbalancing_total').value;
21789: prevhostitem.value = balancer;
21790: if (prevbalancer != '') {
21791: var prevIdx = currBalancers.indexOf(prevbalancer);
21792: if (prevIdx != -1) {
21793: currBalancers.splice(prevIdx,1);
21794: }
21795: }
1.150 raeburn 21796: if (balancer == '') {
1.171 raeburn 21797: hideSpares(balnum);
1.150 raeburn 21798: } else {
1.171 raeburn 21799: var currIdx = currBalancers.indexOf(balancer);
21800: if (currIdx == -1) {
21801: currBalancers.push(balancer);
21802: }
1.150 raeburn 21803: var homedoms = new Array('$allishome');
1.171 raeburn 21804: var ishomedom = homedoms[lonhostitem.selectedIndex];
21805: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21806: }
1.171 raeburn 21807: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21808: return;
21809: }
21810:
1.171 raeburn 21811: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21812: var alltargets = new Array('$alltargets');
21813: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21814: var offloadtypes = new Array('primary','default');
21815:
1.171 raeburn 21816: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21817: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21818:
1.151 raeburn 21819: for (var i=0; i<offloadtypes.length; i++) {
21820: var count = 0;
21821: for (var j=0; j<alltargets.length; j++) {
21822: if (alltargets[j] != balancer) {
1.171 raeburn 21823: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21824: item.value = alltargets[j];
21825: item.style.textAlign='left';
21826: item.style.textFace='normal';
21827: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21828: if (currBalancers.indexOf(alltargets[j]) == -1) {
21829: item.disabled = '';
21830: } else {
21831: item.disabled = 'disabled';
21832: item.checked = false;
21833: }
1.151 raeburn 21834: count ++;
21835: }
1.150 raeburn 21836: }
21837: }
1.151 raeburn 21838: for (var k=0; k<insttypes.length; k++) {
21839: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21840: if (ishomedom == 1) {
1.171 raeburn 21841: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21842: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21843: } else {
1.171 raeburn 21844: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21845: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21846: }
21847: } else {
1.171 raeburn 21848: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21849: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21850: }
1.151 raeburn 21851: if ((insttypes[k] != '_LC_external') &&
21852: ((insttypes[k] != '_LC_internetdom') ||
21853: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21854: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21855: item.options.length = 0;
21856: item.options[0] = new Option("","",true,true);
1.210 raeburn 21857: var idx = 0;
1.151 raeburn 21858: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21859: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21860: idx ++;
21861: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21862: }
21863: }
21864: }
21865: }
21866: return;
21867: }
21868:
1.171 raeburn 21869: function hideSpares(balnum) {
1.150 raeburn 21870: var alltargets = new Array('$alltargets');
21871: var insttypes = new Array('$allinsttypes');
21872: var offloadtypes = new Array('primary','default');
21873:
1.171 raeburn 21874: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21875: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21876:
21877: var total = alltargets.length - 1;
21878: for (var i=0; i<offloadtypes; i++) {
21879: for (var j=0; j<total; j++) {
1.171 raeburn 21880: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21881: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21882: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21883: }
1.150 raeburn 21884: }
21885: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21886: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21887: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21888: if (insttypes[k] != '_LC_external') {
1.171 raeburn 21889: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21890: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21891: }
21892: }
21893: return;
21894: }
21895:
1.171 raeburn 21896: function checkOffloads(item,balnum,type) {
1.150 raeburn 21897: var alltargets = new Array('$alltargets');
21898: var offloadtypes = new Array('primary','default');
21899: if (item.checked) {
21900: var total = alltargets.length - 1;
21901: var other;
21902: if (type == offloadtypes[0]) {
1.151 raeburn 21903: other = offloadtypes[1];
1.150 raeburn 21904: } else {
1.151 raeburn 21905: other = offloadtypes[0];
1.150 raeburn 21906: }
21907: for (var i=0; i<total; i++) {
1.171 raeburn 21908: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21909: if (server == item.value) {
1.171 raeburn 21910: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21911: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21912: }
21913: }
21914: }
21915: }
21916: return;
21917: }
21918:
1.171 raeburn 21919: function singleServerToggle(balnum,type) {
21920: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21921: if (offloadtoSelIdx == 0) {
1.171 raeburn 21922: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21923: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21924:
21925: } else {
1.171 raeburn 21926: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21927: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21928: }
21929: return;
21930: }
21931:
1.171 raeburn 21932: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21933: if (type == '_LC_external') {
1.171 raeburn 21934: return;
1.150 raeburn 21935: }
1.171 raeburn 21936: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21937: for (var i=0; i<typesRules.length; i++) {
21938: if (formname.elements[typesRules[i]].checked) {
21939: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 21940: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21941: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21942: } else {
1.171 raeburn 21943: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21944: }
21945: }
21946: }
21947: return;
21948: }
21949:
21950: function balancerDeleteChange(balnum) {
21951: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21952: var baltotal = document.getElementById('loadbalancing_total').value;
21953: var addtarget;
21954: var removetarget;
21955: var action = 'delete';
21956: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21957: var lonhost = hostitem.value;
21958: var currIdx = currBalancers.indexOf(lonhost);
21959: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21960: if (currIdx != -1) {
21961: currBalancers.splice(currIdx,1);
21962: }
21963: addtarget = lonhost;
21964: } else {
21965: if (currIdx == -1) {
21966: currBalancers.push(lonhost);
21967: }
21968: removetarget = lonhost;
21969: action = 'undelete';
21970: }
21971: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21972: }
21973: return;
21974: }
21975:
21976: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21977: if (baltotal > 1) {
21978: var offloadtypes = new Array('primary','default');
21979: var alltargets = new Array('$alltargets');
21980: var insttypes = new Array('$allinsttypes');
21981: for (var i=0; i<baltotal; i++) {
21982: if (i != balnum) {
21983: for (var j=0; j<offloadtypes.length; j++) {
21984: var total = alltargets.length - 1;
21985: for (var k=0; k<total; k++) {
21986: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21987: var server = serveritem.value;
21988: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21989: if (server == addtarget) {
21990: serveritem.disabled = '';
21991: }
21992: }
21993: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21994: if (server == removetarget) {
21995: serveritem.disabled = 'disabled';
21996: serveritem.checked = false;
21997: }
21998: }
21999: }
22000: }
22001: for (var j=0; j<insttypes.length; j++) {
22002: if (insttypes[j] != '_LC_external') {
22003: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22004: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22005: var currSel = singleserver.selectedIndex;
22006: var currVal = singleserver.options[currSel].value;
22007: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22008: var numoptions = singleserver.options.length;
22009: var needsnew = 1;
22010: for (var k=0; k<numoptions; k++) {
22011: if (singleserver.options[k] == addtarget) {
22012: needsnew = 0;
22013: break;
22014: }
22015: }
22016: if (needsnew == 1) {
22017: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22018: }
22019: }
22020: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22021: singleserver.options.length = 0;
22022: if ((currVal) && (currVal != removetarget)) {
22023: singleserver.options[0] = new Option("","",false,false);
22024: } else {
22025: singleserver.options[0] = new Option("","",true,true);
22026: }
22027: var idx = 0;
22028: for (var m=0; m<alltargets.length; m++) {
22029: if (currBalancers.indexOf(alltargets[m]) == -1) {
22030: idx ++;
22031: if (currVal == alltargets[m]) {
22032: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22033: } else {
22034: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22035: }
22036: }
22037: }
22038: }
22039: }
22040: }
22041: }
1.150 raeburn 22042: }
22043: }
22044: }
22045: return;
22046: }
22047:
1.152 raeburn 22048: // ]]>
22049: </script>
22050:
22051: END
22052: }
22053:
1.372 raeburn 22054:
1.152 raeburn 22055: sub new_spares_js {
22056: my @sparestypes = ('primary','default');
22057: my $types = join("','",@sparestypes);
22058: my $select = &mt('Select');
22059: return <<"END";
22060:
22061: <script type="text/javascript">
22062: // <![CDATA[
22063:
22064: function updateNewSpares(formname,lonhost) {
22065: var types = new Array('$types');
22066: var include = new Array();
22067: var exclude = new Array();
22068: for (var i=0; i<types.length; i++) {
22069: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22070: for (var j=0; j<spareboxes.length; j++) {
22071: if (formname.elements[spareboxes[j]].checked) {
22072: exclude.push(formname.elements[spareboxes[j]].value);
22073: } else {
22074: include.push(formname.elements[spareboxes[j]].value);
22075: }
22076: }
22077: }
22078: for (var i=0; i<types.length; i++) {
22079: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22080: var selIdx = newSpare.selectedIndex;
22081: var currnew = newSpare.options[selIdx].value;
22082: var okSpares = new Array();
22083: for (var j=0; j<newSpare.options.length; j++) {
22084: var possible = newSpare.options[j].value;
22085: if (possible != '') {
22086: if (exclude.indexOf(possible) == -1) {
22087: okSpares.push(possible);
22088: } else {
22089: if (currnew == possible) {
22090: selIdx = 0;
22091: }
22092: }
22093: }
22094: }
22095: for (var k=0; k<include.length; k++) {
22096: if (okSpares.indexOf(include[k]) == -1) {
22097: okSpares.push(include[k]);
22098: }
22099: }
22100: okSpares.sort();
22101: newSpare.options.length = 0;
22102: if (selIdx == 0) {
22103: newSpare.options[0] = new Option("$select","",true,true);
22104: } else {
22105: newSpare.options[0] = new Option("$select","",false,false);
22106: }
22107: for (var m=0; m<okSpares.length; m++) {
22108: var idx = m+1;
22109: var selThis = 0;
22110: if (selIdx != 0) {
22111: if (okSpares[m] == currnew) {
22112: selThis = 1;
22113: }
22114: }
22115: if (selThis == 1) {
22116: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22117: } else {
22118: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22119: }
22120: }
22121: }
22122: return;
22123: }
22124:
22125: function checkNewSpares(lonhost,type) {
22126: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22127: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22128: if (chosen != '') {
1.152 raeburn 22129: var othertype;
22130: var othernewSpare;
22131: if (type == 'primary') {
22132: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22133: }
22134: if (type == 'default') {
22135: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22136: }
22137: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22138: othernewSpare.selectedIndex = 0;
22139: }
22140: }
22141: return;
22142: }
22143:
22144: // ]]>
22145: </script>
22146:
22147: END
22148:
22149: }
22150:
22151: sub common_domprefs_js {
22152: return <<"END";
22153:
22154: <script type="text/javascript">
22155: // <![CDATA[
22156:
1.150 raeburn 22157: function getIndicesByName(formname,item) {
1.152 raeburn 22158: var group = new Array();
1.150 raeburn 22159: for (var i=0;i<formname.elements.length;i++) {
22160: if (formname.elements[i].name == item) {
1.152 raeburn 22161: group.push(formname.elements[i].id);
1.150 raeburn 22162: }
22163: }
1.152 raeburn 22164: return group;
1.150 raeburn 22165: }
22166:
22167: // ]]>
22168: </script>
22169:
22170: END
1.152 raeburn 22171:
1.150 raeburn 22172: }
22173:
1.165 raeburn 22174: sub recaptcha_js {
22175: my %lt = &captcha_phrases();
22176: return <<"END";
22177:
22178: <script type="text/javascript">
22179: // <![CDATA[
22180:
22181: function updateCaptcha(caller,context) {
22182: var privitem;
22183: var pubitem;
22184: var privtext;
22185: var pubtext;
1.269 raeburn 22186: var versionitem;
22187: var versiontext;
1.165 raeburn 22188: if (document.getElementById(context+'_recaptchapub')) {
22189: pubitem = document.getElementById(context+'_recaptchapub');
22190: } else {
22191: return;
22192: }
22193: if (document.getElementById(context+'_recaptchapriv')) {
22194: privitem = document.getElementById(context+'_recaptchapriv');
22195: } else {
22196: return;
22197: }
22198: if (document.getElementById(context+'_recaptchapubtxt')) {
22199: pubtext = document.getElementById(context+'_recaptchapubtxt');
22200: } else {
22201: return;
22202: }
22203: if (document.getElementById(context+'_recaptchaprivtxt')) {
22204: privtext = document.getElementById(context+'_recaptchaprivtxt');
22205: } else {
22206: return;
22207: }
1.269 raeburn 22208: if (document.getElementById(context+'_recaptchaversion')) {
22209: versionitem = document.getElementById(context+'_recaptchaversion');
22210: } else {
22211: return;
22212: }
22213: if (document.getElementById(context+'_recaptchavertxt')) {
22214: versiontext = document.getElementById(context+'_recaptchavertxt');
22215: } else {
22216: return;
22217: }
1.165 raeburn 22218: if (caller.checked) {
22219: if (caller.value == 'recaptcha') {
22220: pubitem.type = 'text';
22221: privitem.type = 'text';
22222: pubitem.size = '40';
22223: privitem.size = '40';
22224: pubtext.innerHTML = "$lt{'pub'}";
22225: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 22226: versionitem.type = 'text';
22227: versionitem.size = '3';
1.289 raeburn 22228: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 22229: } else {
22230: pubitem.type = 'hidden';
22231: privitem.type = 'hidden';
1.269 raeburn 22232: versionitem.type = 'hidden';
1.165 raeburn 22233: pubtext.innerHTML = '';
22234: privtext.innerHTML = '';
1.269 raeburn 22235: versiontext.innerHTML = '';
1.165 raeburn 22236: }
22237: }
22238: return;
22239: }
22240:
22241: // ]]>
22242: </script>
22243:
22244: END
22245:
22246: }
22247:
1.236 raeburn 22248: sub toggle_display_js {
1.192 raeburn 22249: return <<"END";
22250:
22251: <script type="text/javascript">
22252: // <![CDATA[
22253:
1.236 raeburn 22254: function toggleDisplay(domForm,caller) {
22255: if (document.getElementById(caller)) {
22256: var divitem = document.getElementById(caller);
22257: var optionsElement = domForm.coursecredits;
1.264 raeburn 22258: var checkval = 1;
22259: var dispval = 'block';
1.303 raeburn 22260: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 22261: if (caller == 'emailoptions') {
1.372 raeburn 22262: optionsElement = domForm.cancreate_email;
1.236 raeburn 22263: }
1.257 raeburn 22264: if (caller == 'studentsubmission') {
22265: optionsElement = domForm.postsubmit;
22266: }
1.264 raeburn 22267: if (caller == 'cloneinstcode') {
22268: optionsElement = domForm.canclone;
22269: checkval = 'instcode';
22270: }
1.303 raeburn 22271: if (selfcreateRegExp.test(caller)) {
22272: optionsElement = domForm.elements[caller];
22273: checkval = 'other';
22274: dispval = 'inline'
22275: }
1.236 raeburn 22276: if (optionsElement.length) {
1.192 raeburn 22277: var currval;
1.236 raeburn 22278: for (var i=0; i<optionsElement.length; i++) {
22279: if (optionsElement[i].checked) {
22280: currval = optionsElement[i].value;
1.192 raeburn 22281: }
22282: }
1.264 raeburn 22283: if (currval == checkval) {
22284: divitem.style.display = dispval;
1.192 raeburn 22285: } else {
1.236 raeburn 22286: divitem.style.display = 'none';
1.192 raeburn 22287: }
22288: }
22289: }
22290: return;
22291: }
22292:
22293: // ]]>
22294: </script>
22295:
22296: END
22297:
22298: }
22299:
1.165 raeburn 22300: sub captcha_phrases {
22301: return &Apache::lonlocal::texthash (
22302: priv => 'Private key',
22303: pub => 'Public key',
22304: original => 'original (CAPTCHA)',
22305: recaptcha => 'successor (ReCAPTCHA)',
22306: notused => 'unused',
1.289 raeburn 22307: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 22308: );
22309: }
22310:
1.205 raeburn 22311: sub devalidate_remote_domconfs {
1.212 raeburn 22312: my ($dom,$cachekeys) = @_;
22313: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 22314: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22315: my %thismachine;
22316: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 22317: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.388 raeburn 22318: 'directorysrch','passwdconf','cats','proxyalias','proxysaml');
1.386 raeburn 22319: my %cache_by_lonhost;
22320: if (exists($cachekeys->{'samllanding'})) {
22321: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
22322: my %landing = %{$cachekeys->{'samllanding'}};
22323: my %domservers = &Apache::lonnet::get_servers($dom);
22324: if (keys(%domservers)) {
22325: foreach my $server (keys(%domservers)) {
22326: my @cached;
22327: next if ($thismachine{$server});
22328: if ($landing{$server}) {
22329: push(@cached,&escape('samllanding').':'.&escape($server));
22330: }
22331: if (@cached) {
22332: $cache_by_lonhost{$server} = \@cached;
22333: }
22334: }
22335: }
22336: }
22337: }
1.260 raeburn 22338: if (keys(%servers)) {
1.205 raeburn 22339: foreach my $server (keys(%servers)) {
22340: next if ($thismachine{$server});
1.212 raeburn 22341: my @cached;
22342: foreach my $name (@posscached) {
22343: if ($cachekeys->{$name}) {
1.388 raeburn 22344: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 22345: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 22346: foreach my $key (keys(%{$cachekeys->{$name}})) {
22347: push(@cached,&escape($name).':'.&escape($key));
22348: }
22349: }
22350: } else {
22351: push(@cached,&escape($name).':'.&escape($dom));
22352: }
1.212 raeburn 22353: }
22354: }
1.386 raeburn 22355: if ((exists($cache_by_lonhost{$server})) &&
22356: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
22357: push(@cached,@{$cache_by_lonhost{$server}});
22358: }
1.212 raeburn 22359: if (@cached) {
22360: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
22361: }
1.205 raeburn 22362: }
22363: }
22364: return;
22365: }
22366:
1.3 raeburn 22367: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>