Annotation of loncom/interface/domainprefs.pm, revision 1.389
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.389 ! raeburn 4: # $Id: domainprefs.pm,v 1.388 2021/10/07 15:51:15 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);
3180: $total = 0;
3181: foreach my $item (keys(%{$settings})) {
3182: if (ref($settings->{$item}) eq 'HASH') {
3183: my $num = $settings->{$item}{'order'};
3184: $ordered{$num} = $item;
3185: }
3186: }
3187: $total = scalar(keys(%{$settings}));
3188: my @jsarray = ();
3189: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3190: push(@jsarray,$ordered{$item});
3191: }
3192: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3193: return <<"ENDSCRIPT";
3194: <script type="text/javascript">
3195: // <![CDATA[
3196: function reorderLTI(form,item) {
3197: var changedVal;
3198: $jstext
3199: var newpos = 'lti_pos_add';
3200: var maxh = 1 + $total;
3201: var current = new Array;
3202: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3203: if (item == newpos) {
3204: changedVal = newitemVal;
3205: } else {
3206: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3207: current[newitemVal] = newpos;
3208: }
3209: for (var i=0; i<lti.length; i++) {
3210: var elementName = 'lti_pos_'+lti[i];
3211: if (elementName != item) {
3212: if (form.elements[elementName]) {
3213: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3214: current[currVal] = elementName;
3215: }
3216: }
3217: }
3218: var oldVal;
3219: for (var j=0; j<maxh; j++) {
3220: if (current[j] == undefined) {
3221: oldVal = j;
3222: }
3223: }
3224: if (oldVal < changedVal) {
3225: for (var k=oldVal+1; k<=changedVal ; k++) {
3226: var elementName = current[k];
3227: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3228: }
3229: } else {
3230: for (var k=changedVal; k<oldVal; k++) {
3231: var elementName = current[k];
3232: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3233: }
3234: }
3235: return;
3236: }
3237: // ]]>
3238: </script>
3239:
3240: $togglejs
3241:
3242: ENDSCRIPT
3243: }
3244:
3245: sub lti_toggle_js {
1.325 raeburn 3246: my %lcauthparmtext = &Apache::lonlocal::texthash (
3247: localauth => 'Local auth argument',
3248: krb => 'Kerberos domain',
3249: );
1.320 raeburn 3250: return <<"ENDSCRIPT";
3251: <script type="text/javascript">
3252: // <![CDATA[
3253:
3254: function toggleLTI(form,setting,item) {
1.345 raeburn 3255: if (setting == 'requser') {
3256: var fieldsets = document.getElementsByClassName('ltioption_'+item);
3257: if (fieldsets.length) {
3258: var radioname = 'lti_'+setting+'_'+item;
3259: var num = form.elements[radioname].length;
3260: if (num) {
3261: var setvis = '';
3262: for (var i=0; i<num; i++) {
3263: if (form.elements[radioname][i].checked) {
3264: if (form.elements[radioname][i].value == '1') {
3265: setvis = 1;
3266: break;
3267: }
3268: }
3269: }
1.352 raeburn 3270: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 3271: if (setvis) {
3272: fieldsets[j].style.display = 'block';
3273: } else {
3274: fieldsets[j].style.display = 'none';
3275: }
3276: }
3277: }
3278: }
1.363 raeburn 3279: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3280: var radioname = '';
3281: var divid = '';
3282: if (setting == 'user') {
3283: radioname = 'lti_mapuser_'+item;
3284: divid = 'lti_userfield_'+item;
1.343 raeburn 3285: } else if (setting == 'crs') {
1.320 raeburn 3286: radioname = 'lti_mapcrs_'+item;
3287: divid = 'lti_crsfield_'+item;
1.363 raeburn 3288: } else if (setting == 'callback') {
3289: radioname = 'lti_callback_'+item;
3290: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3291: } else {
1.351 raeburn 3292: radioname = 'lti_passback_'+item;
1.337 raeburn 3293: divid = 'lti_passback_'+item;
1.320 raeburn 3294: }
3295: var num = form.elements[radioname].length;
3296: if (num) {
3297: var setvis = '';
3298: for (var i=0; i<num; i++) {
3299: if (form.elements[radioname][i].checked) {
1.363 raeburn 3300: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3301: if (form.elements[radioname][i].value == '1') {
3302: if (document.getElementById(divid)) {
3303: document.getElementById(divid).style.display = 'inline-block';
3304: }
3305: setvis = 1;
3306: break;
3307: }
3308: } else {
3309: if (form.elements[radioname][i].value == 'other') {
3310: if (document.getElementById(divid)) {
3311: document.getElementById(divid).style.display = 'inline-block';
3312: }
3313: setvis = 1;
3314: break;
1.320 raeburn 3315: }
3316: }
3317: }
3318: }
3319: if (!setvis) {
3320: if (document.getElementById(divid)) {
3321: document.getElementById(divid).style.display = 'none';
3322: }
3323: }
3324: }
3325: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3326: var numsec = form.elements['lti_crssec_'+item].length;
3327: if (numsec) {
3328: var setvis = '';
3329: for (var i=0; i<numsec; i++) {
3330: if (form.elements['lti_crssec_'+item][i].checked) {
3331: if (form.elements['lti_crssec_'+item][i].value == '1') {
3332: if (document.getElementById('lti_crssecfield_'+item)) {
3333: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3334: setvis = 1;
3335: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3336: if (numsrcsec) {
3337: var setsrcvis = '';
3338: for (var j=0; j<numsrcsec; j++) {
3339: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3340: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3341: if (document.getElementById('lti_secsrcfield_'+item)) {
3342: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3343: setsrcvis = 1;
3344: }
3345: }
3346: }
3347: }
3348: if (!setsrcvis) {
3349: if (document.getElementById('lti_secsrcfield_'+item)) {
3350: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3351: }
3352: }
3353: }
3354: }
3355: }
3356: }
3357: }
3358: if (!setvis) {
3359: if (document.getElementById('lti_crssecfield_'+item)) {
3360: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3361: }
3362: if (document.getElementById('lti_secsrcfield_'+item)) {
3363: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3364: }
3365: }
3366: }
1.325 raeburn 3367: } else if (setting == 'lcauth') {
3368: var numauth = form.elements['lti_lcauth_'+item].length;
3369: if (numauth) {
3370: for (var i=0; i<numauth; i++) {
3371: if (form.elements['lti_lcauth_'+item][i].checked) {
3372: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3373: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3374: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3375: } else {
3376: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3377: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3378: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3379: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3380: } else {
3381: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3382: }
3383: }
3384: }
3385: }
3386: }
3387: }
3388: }
1.326 raeburn 3389: } else if (setting == 'lcmenu') {
3390: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3391: var divid = 'lti_menufield_'+item;
3392: var setvis = '';
3393: for (var i=0; i<menus.length; i++) {
3394: var radioname = menus[i];
3395: var num = form.elements[radioname].length;
3396: if (num) {
3397: for (var j=0; j<num; j++) {
3398: if (form.elements[radioname][j].checked) {
3399: if (form.elements[radioname][j].value == '1') {
3400: if (document.getElementById(divid)) {
3401: document.getElementById(divid).style.display = 'inline-block';
3402: }
3403: setvis = 1;
3404: break;
3405: }
3406: }
3407: }
3408: }
3409: if (setvis == 1) {
3410: break;
3411: }
3412: }
3413: if (!setvis) {
3414: if (document.getElementById(divid)) {
3415: document.getElementById(divid).style.display = 'none';
3416: }
3417: }
1.320 raeburn 3418: }
3419: return;
3420: }
3421: // ]]>
3422: </script>
3423:
3424: ENDSCRIPT
3425: }
3426:
1.385 raeburn 3427: sub autoupdate_javascript {
3428: return <<"ENDSCRIPT";
3429: <script type="text/javascript">
3430: // <![CDATA[
3431: function toggleLastActiveDays(form) {
3432: var radioname = 'lastactive';
3433: var divid = 'lastactive_div';
3434: var num = form.elements[radioname].length;
3435: if (num) {
3436: var setvis = '';
3437: for (var i=0; i<num; i++) {
3438: if (form.elements[radioname][i].checked) {
3439: if (form.elements[radioname][i].value == '1') {
3440: if (document.getElementById(divid)) {
3441: document.getElementById(divid).style.display = 'inline-block';
3442: }
3443: setvis = 1;
3444: }
3445: break;
3446: }
3447: }
3448: if (!setvis) {
3449: if (document.getElementById(divid)) {
3450: document.getElementById(divid).style.display = 'none';
3451: }
3452: }
3453: }
3454: return;
3455: }
3456: // ]]>
3457: </script>
3458:
3459: ENDSCRIPT
3460: }
3461:
1.386 raeburn 3462: sub saml_javascript {
3463: return <<"ENDSCRIPT";
3464: <script type="text/javascript">
3465: // <![CDATA[
3466: function toggleSamlOptions(form,hostid) {
3467: var radioname = 'saml_'+hostid;
3468: var tablecellon = 'samloptionson_'+hostid;
3469: var tablecelloff = 'samloptionsoff_'+hostid;
3470: var num = form.elements[radioname].length;
3471: if (num) {
3472: var setvis = '';
3473: for (var i=0; i<num; i++) {
3474: if (form.elements[radioname][i].checked) {
3475: if (form.elements[radioname][i].value == '1') {
3476: if (document.getElementById(tablecellon)) {
3477: document.getElementById(tablecellon).style.display='';
3478: }
3479: if (document.getElementById(tablecelloff)) {
3480: document.getElementById(tablecelloff).style.display='none';
3481: }
3482: setvis = 1;
3483: }
3484: break;
3485: }
3486: }
3487: if (!setvis) {
3488: if (document.getElementById(tablecellon)) {
3489: document.getElementById(tablecellon).style.display='none';
3490: }
3491: if (document.getElementById(tablecelloff)) {
3492: document.getElementById(tablecelloff).style.display='';
3493: }
3494: }
3495: }
3496: return;
3497: }
3498: // ]]>
3499: </script>
3500:
3501: ENDSCRIPT
3502: }
3503:
1.3 raeburn 3504: sub print_autoenroll {
1.30 raeburn 3505: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3506: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3507: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3508: if (ref($settings) eq 'HASH') {
3509: if (exists($settings->{'run'})) {
3510: if ($settings->{'run'} eq '0') {
3511: $runoff = ' checked="checked" ';
3512: $runon = ' ';
3513: } else {
3514: $runon = ' checked="checked" ';
3515: $runoff = ' ';
3516: }
3517: } else {
3518: if ($autorun) {
3519: $runon = ' checked="checked" ';
3520: $runoff = ' ';
3521: } else {
3522: $runoff = ' checked="checked" ';
3523: $runon = ' ';
3524: }
3525: }
1.129 raeburn 3526: if (exists($settings->{'co-owners'})) {
3527: if ($settings->{'co-owners'} eq '0') {
3528: $coownersoff = ' checked="checked" ';
3529: $coownerson = ' ';
3530: } else {
3531: $coownerson = ' checked="checked" ';
3532: $coownersoff = ' ';
3533: }
3534: } else {
3535: $coownersoff = ' checked="checked" ';
3536: $coownerson = ' ';
3537: }
1.3 raeburn 3538: if (exists($settings->{'sender_domain'})) {
3539: $defdom = $settings->{'sender_domain'};
3540: }
1.274 raeburn 3541: if (exists($settings->{'autofailsafe'})) {
3542: $failsafe = $settings->{'autofailsafe'};
3543: }
1.14 raeburn 3544: } else {
3545: if ($autorun) {
3546: $runon = ' checked="checked" ';
3547: $runoff = ' ';
3548: } else {
3549: $runoff = ' checked="checked" ';
3550: $runon = ' ';
3551: }
1.3 raeburn 3552: }
3553: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3554: my $notif_sender;
3555: if (ref($settings) eq 'HASH') {
3556: $notif_sender = $settings->{'sender_uname'};
3557: }
1.3 raeburn 3558: my $datatable='<tr class="LC_odd_row">'.
3559: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3560: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3561: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3562: $runon.' value="1" />'.&mt('Yes').'</label> '.
3563: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3564: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3565: '</tr><tr>'.
3566: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3567: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3568: &mt('username').': '.
3569: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3570: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3571: ': '.$domform.'</span></td></tr>'.
3572: '<tr class="LC_odd_row">'.
3573: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3574: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3575: '<input type="radio" name="autoassign_coowners"'.
3576: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3577: '<label><input type="radio" name="autoassign_coowners"'.
3578: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3579: '</tr><tr>'.
3580: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3581: '<td class="LC_right_item"><span class="LC_nobreak">'.
3582: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3583: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3584: $$rowtotal += 4;
1.3 raeburn 3585: return $datatable;
3586: }
3587:
3588: sub print_autoupdate {
1.30 raeburn 3589: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 3590: my ($enable,$datatable);
1.3 raeburn 3591: if ($position eq 'top') {
1.385 raeburn 3592: my %choices = &Apache::lonlocal::texthash (
3593: run => 'Auto-update active?',
3594: classlists => 'Update information in classlists?',
3595: unexpired => 'Skip updates for users without active or future roles?',
3596: lastactive => 'Skip updates for inactive users?',
3597: );
3598: my $itemcount = 0;
1.3 raeburn 3599: my $updateon = ' ';
3600: my $updateoff = ' checked="checked" ';
3601: if (ref($settings) eq 'HASH') {
3602: if ($settings->{'run'} eq '1') {
3603: $updateon = $updateoff;
3604: $updateoff = ' ';
3605: }
3606: }
1.385 raeburn 3607: $enable = '<tr class="LC_odd_row">'.
3608: '<td>'.$choices{'run'}.'</td>'.
3609: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3610: '<input type="radio" name="autoupdate_run"'.
1.385 raeburn 3611: $updateoff.' value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3612: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 3613: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3614: '</tr>';
1.385 raeburn 3615: my @toggles = ('classlists','unexpired');
3616: my %defaultchecked = ('classlists' => 'off',
3617: 'unexpired' => 'off'
3618: );
3619: $$rowtotal ++;
3620: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3621: \%choices,$itemcount,'','','left','no');
3622: $datatable = $enable.$datatable;
3623: $$rowtotal += $itemcount;
3624: my $lastactiveon = ' ';
3625: my $lastactiveoff = ' checked="checked" ';
3626: my $lastactivestyle = 'none';
3627: my $lastactivedays;
3628: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3629: if (ref($settings) eq 'HASH') {
3630: if ($settings->{'lastactive'} =~ /^\d+$/) {
3631: $lastactiveon = $lastactiveoff;
3632: $lastactiveoff = ' ';
3633: $lastactivestyle = 'inline-block';
3634: $lastactivedays = $settings->{'lastactive'};
3635: }
3636: }
3637: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3638: $datatable .= '<tr'.$css_class.'>'.
3639: '<td>'.$choices{'lastactive'}.'</td>'.
3640: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3641: '<input type="radio" name="lastactive"'.
3642: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3643: ' <label>'.
3644: '<input type="radio" name="lastactive"'.
3645: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3646: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3647: ': '.&mt('inactive = no activity in last [_1] days',
3648: '<input type="text" size="5" name="lastactivedays" value="'.
3649: $lastactivedays.'" />').
3650: '</span></td>'.
3651: '</tr>';
3652: $$rowtotal ++;
1.131 raeburn 3653: } elsif ($position eq 'middle') {
3654: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3655: my $numinrow = 3;
3656: my $locknamesettings;
3657: $datatable .= &insttypes_row($settings,$types,$usertypes,
3658: $dom,$numinrow,$othertitle,
1.305 raeburn 3659: 'lockablenames',$rowtotal);
1.131 raeburn 3660: $$rowtotal ++;
1.3 raeburn 3661: } else {
1.44 raeburn 3662: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3663: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3664: 'permanentemail','id');
1.33 raeburn 3665: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3666: my $numrows = 0;
1.26 raeburn 3667: if (ref($types) eq 'ARRAY') {
3668: if (@{$types} > 0) {
3669: $datatable =
3670: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3671: \@fields,$types,\$numrows);
1.30 raeburn 3672: $$rowtotal += @{$types};
1.26 raeburn 3673: }
1.3 raeburn 3674: }
3675: $datatable .=
3676: &usertype_update_row($settings,{'default' => $othertitle},
3677: \%fieldtitles,\@fields,['default'],
3678: \$numrows);
1.30 raeburn 3679: $$rowtotal ++;
1.3 raeburn 3680: }
3681: return $datatable;
3682: }
3683:
1.125 raeburn 3684: sub print_autocreate {
3685: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3686: my (%createon,%createoff,%currhash);
1.125 raeburn 3687: my @types = ('xml','req');
3688: if (ref($settings) eq 'HASH') {
3689: foreach my $item (@types) {
3690: $createoff{$item} = ' checked="checked" ';
3691: $createon{$item} = ' ';
3692: if (exists($settings->{$item})) {
3693: if ($settings->{$item}) {
3694: $createon{$item} = ' checked="checked" ';
3695: $createoff{$item} = ' ';
3696: }
3697: }
3698: }
1.210 raeburn 3699: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3700: $currhash{$settings->{'xmldc'}} = 1;
3701: }
1.125 raeburn 3702: } else {
3703: foreach my $item (@types) {
3704: $createoff{$item} = ' checked="checked" ';
3705: $createon{$item} = ' ';
3706: }
3707: }
3708: $$rowtotal += 2;
1.191 raeburn 3709: my $numinrow = 2;
1.125 raeburn 3710: my $datatable='<tr class="LC_odd_row">'.
3711: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3712: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3713: '<input type="radio" name="autocreate_xml"'.
3714: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3715: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3716: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3717: '</td></tr><tr>'.
3718: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3719: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3720: '<input type="radio" name="autocreate_req"'.
3721: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3722: '<label><input type="radio" name="autocreate_req"'.
3723: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3724: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3725: 'autocreate_xmldc',%currhash);
1.247 raeburn 3726: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3727: if ($numdc > 1) {
1.247 raeburn 3728: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3729: '</td><td class="LC_left_item">';
1.125 raeburn 3730: } else {
1.247 raeburn 3731: $datatable .= &mt('Course creation processed as:').
3732: '</td><td class="LC_right_item">';
1.125 raeburn 3733: }
1.247 raeburn 3734: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3735: $$rowtotal += $rows;
1.125 raeburn 3736: return $datatable;
3737: }
3738:
1.23 raeburn 3739: sub print_directorysrch {
1.277 raeburn 3740: my ($position,$dom,$settings,$rowtotal) = @_;
3741: my $datatable;
3742: if ($position eq 'top') {
3743: my $instsrchon = ' ';
3744: my $instsrchoff = ' checked="checked" ';
3745: my ($exacton,$containson,$beginson);
3746: my $instlocalon = ' ';
3747: my $instlocaloff = ' checked="checked" ';
3748: if (ref($settings) eq 'HASH') {
3749: if ($settings->{'available'} eq '1') {
3750: $instsrchon = $instsrchoff;
3751: $instsrchoff = ' ';
3752: }
3753: if ($settings->{'localonly'} eq '1') {
3754: $instlocalon = $instlocaloff;
3755: $instlocaloff = ' ';
3756: }
3757: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3758: foreach my $type (@{$settings->{'searchtypes'}}) {
3759: if ($type eq 'exact') {
3760: $exacton = ' checked="checked" ';
3761: } elsif ($type eq 'contains') {
3762: $containson = ' checked="checked" ';
3763: } elsif ($type eq 'begins') {
3764: $beginson = ' checked="checked" ';
3765: }
3766: }
3767: } else {
3768: if ($settings->{'searchtypes'} eq 'exact') {
3769: $exacton = ' checked="checked" ';
3770: } elsif ($settings->{'searchtypes'} eq 'contains') {
3771: $containson = ' checked="checked" ';
3772: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3773: $exacton = ' checked="checked" ';
3774: $containson = ' checked="checked" ';
3775: }
3776: }
1.277 raeburn 3777: }
3778: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3779: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3780:
3781: my $numinrow = 4;
3782: my $cansrchrow = 0;
3783: $datatable='<tr class="LC_odd_row">'.
3784: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3785: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3786: '<input type="radio" name="dirsrch_available"'.
3787: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3788: '<label><input type="radio" name="dirsrch_available"'.
3789: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3790: '</tr><tr>'.
3791: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3792: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3793: '<input type="radio" name="dirsrch_instlocalonly"'.
3794: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3795: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3796: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3797: '</tr>';
3798: $$rowtotal += 2;
3799: if (ref($usertypes) eq 'HASH') {
3800: if (keys(%{$usertypes}) > 0) {
3801: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3802: $numinrow,$othertitle,'cansearch',
3803: $rowtotal);
1.277 raeburn 3804: $cansrchrow = 1;
1.25 raeburn 3805: }
1.23 raeburn 3806: }
1.277 raeburn 3807: if ($cansrchrow) {
3808: $$rowtotal ++;
3809: $datatable .= '<tr>';
3810: } else {
3811: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3812: }
1.277 raeburn 3813: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3814: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3815: foreach my $title (@{$titleorder}) {
3816: if (defined($searchtitles->{$title})) {
3817: my $check = ' ';
3818: if (ref($settings) eq 'HASH') {
3819: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3820: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3821: $check = ' checked="checked" ';
3822: }
1.39 raeburn 3823: }
1.25 raeburn 3824: }
1.277 raeburn 3825: $datatable .= '<td class="LC_left_item">'.
3826: '<span class="LC_nobreak"><label>'.
3827: '<input type="checkbox" name="searchby" '.
3828: 'value="'.$title.'"'.$check.'/>'.
3829: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3830: }
3831: }
1.277 raeburn 3832: $datatable .= '</tr></table></td></tr>';
3833: $$rowtotal ++;
3834: if ($cansrchrow) {
3835: $datatable .= '<tr class="LC_odd_row">';
3836: } else {
3837: $datatable .= '<tr>';
3838: }
3839: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3840: '<td class="LC_left_item" colspan="2">'.
3841: '<span class="LC_nobreak"><label>'.
3842: '<input type="checkbox" name="searchtypes" '.
3843: $exacton.' value="exact" />'.&mt('Exact match').
3844: '</label> '.
3845: '<label><input type="checkbox" name="searchtypes" '.
3846: $beginson.' value="begins" />'.&mt('Begins with').
3847: '</label> '.
3848: '<label><input type="checkbox" name="searchtypes" '.
3849: $containson.' value="contains" />'.&mt('Contains').
3850: '</label></span></td></tr>';
3851: $$rowtotal ++;
1.26 raeburn 3852: } else {
1.277 raeburn 3853: my $domsrchon = ' checked="checked" ';
3854: my $domsrchoff = ' ';
3855: my $domlocalon = ' ';
3856: my $domlocaloff = ' checked="checked" ';
3857: if (ref($settings) eq 'HASH') {
3858: if ($settings->{'lclocalonly'} eq '1') {
3859: $domlocalon = $domlocaloff;
3860: $domlocaloff = ' ';
3861: }
3862: if ($settings->{'lcavailable'} eq '0') {
3863: $domsrchoff = $domsrchon;
3864: $domsrchon = ' ';
3865: }
3866: }
3867: $datatable='<tr class="LC_odd_row">'.
3868: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3869: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3870: '<input type="radio" name="dirsrch_domavailable"'.
3871: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3872: '<label><input type="radio" name="dirsrch_domavailable"'.
3873: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3874: '</tr><tr>'.
3875: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3876: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3877: '<input type="radio" name="dirsrch_domlocalonly"'.
3878: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3879: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3880: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3881: '</tr>';
3882: $$rowtotal += 2;
1.26 raeburn 3883: }
1.25 raeburn 3884: return $datatable;
3885: }
3886:
1.28 raeburn 3887: sub print_contacts {
1.286 raeburn 3888: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3889: my $datatable;
3890: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3891: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3892: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3893: if ($position eq 'top') {
3894: if (ref($settings) eq 'HASH') {
3895: foreach my $item (@contacts) {
3896: if (exists($settings->{$item})) {
3897: $to{$item} = $settings->{$item};
3898: }
3899: }
3900: }
3901: } elsif ($position eq 'middle') {
3902: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3903: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3904: foreach my $type (@mailings) {
3905: $otheremails{$type} = '';
3906: }
1.340 raeburn 3907: } elsif ($position eq 'lower') {
3908: if (ref($settings) eq 'HASH') {
3909: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3910: %lonstatus = %{$settings->{'lonstatus'}};
3911: }
3912: }
1.286 raeburn 3913: } else {
3914: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3915: foreach my $type (@mailings) {
3916: $otheremails{$type} = '';
3917: }
1.286 raeburn 3918: $bccemails{'helpdeskmail'} = '';
3919: $bccemails{'otherdomsmail'} = '';
3920: $includestr{'helpdeskmail'} = '';
3921: $includestr{'otherdomsmail'} = '';
3922: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3923: }
1.28 raeburn 3924: if (ref($settings) eq 'HASH') {
1.340 raeburn 3925: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3926: foreach my $type (@mailings) {
3927: if (exists($settings->{$type})) {
3928: if (ref($settings->{$type}) eq 'HASH') {
3929: foreach my $item (@contacts) {
3930: if ($settings->{$type}{$item}) {
3931: $checked{$type}{$item} = ' checked="checked" ';
3932: }
3933: }
3934: $otheremails{$type} = $settings->{$type}{'others'};
3935: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3936: $bccemails{$type} = $settings->{$type}{'bcc'};
3937: if ($settings->{$type}{'include'} ne '') {
3938: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3939: $includestr{$type} = &unescape($includestr{$type});
3940: }
3941: }
3942: }
3943: } elsif ($type eq 'lonstatusmail') {
3944: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3945: }
1.28 raeburn 3946: }
3947: }
1.286 raeburn 3948: if ($position eq 'bottom') {
3949: foreach my $type (@mailings) {
3950: $bccemails{$type} = $settings->{$type}{'bcc'};
3951: if ($settings->{$type}{'include'} ne '') {
3952: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3953: $includestr{$type} = &unescape($includestr{$type});
3954: }
3955: }
3956: if (ref($settings->{'helpform'}) eq 'HASH') {
3957: if (ref($fields) eq 'ARRAY') {
3958: foreach my $field (@{$fields}) {
3959: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3960: }
1.286 raeburn 3961: }
3962: if (exists($settings->{'helpform'}{'maxsize'})) {
3963: $maxsize = $settings->{'helpform'}{'maxsize'};
3964: } else {
1.289 raeburn 3965: $maxsize = '1.0';
1.286 raeburn 3966: }
3967: } else {
3968: if (ref($fields) eq 'ARRAY') {
3969: foreach my $field (@{$fields}) {
3970: $currfield{$field} = 'yes';
1.134 raeburn 3971: }
1.28 raeburn 3972: }
1.286 raeburn 3973: $maxsize = '1.0';
1.28 raeburn 3974: }
3975: }
3976: } else {
1.286 raeburn 3977: if ($position eq 'top') {
3978: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3979: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3980: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3981: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3982: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3983: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3984: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3985: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3986: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3987: } elsif ($position eq 'bottom') {
3988: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3989: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3990: if (ref($fields) eq 'ARRAY') {
3991: foreach my $field (@{$fields}) {
3992: $currfield{$field} = 'yes';
3993: }
3994: }
3995: $maxsize = '1.0';
3996: }
1.28 raeburn 3997: }
3998: my ($titles,$short_titles) = &contact_titles();
3999: my $rownum = 0;
4000: my $css_class;
1.286 raeburn 4001: if ($position eq 'top') {
4002: foreach my $item (@contacts) {
4003: $css_class = $rownum%2?' class="LC_odd_row"':'';
4004: $datatable .= '<tr'.$css_class.'>'.
4005: '<td><span class="LC_nobreak">'.$titles->{$item}.
4006: '</span></td><td class="LC_right_item">'.
4007: '<input type="text" name="'.$item.'" value="'.
4008: $to{$item}.'" /></td></tr>';
4009: $rownum ++;
4010: }
1.315 raeburn 4011: } elsif ($position eq 'bottom') {
4012: $css_class = $rownum%2?' class="LC_odd_row"':'';
4013: $datatable .= '<tr'.$css_class.'>'.
4014: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4015: &mt('(e-mail, subject, and description always shown)').
4016: '</td><td class="LC_left_item">';
4017: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4018: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4019: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4020: foreach my $field (@{$fields}) {
4021: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4022: if (($field eq 'screenshot') || ($field eq 'cc')) {
4023: $datatable .= ' '.&mt('(logged-in users)');
4024: }
4025: $datatable .='</td><td>';
4026: my $clickaction;
4027: if ($field eq 'screenshot') {
4028: $clickaction = ' onclick="screenshotSize(this);"';
4029: }
4030: if (ref($possoptions->{$field}) eq 'ARRAY') {
4031: foreach my $option (@{$possoptions->{$field}}) {
4032: my $checked;
4033: if ($currfield{$field} eq $option) {
4034: $checked = ' checked="checked"';
4035: }
4036: $datatable .= '<span class="LC_nobreak"><label>'.
4037: '<input type="radio" name="helpform_'.$field.'" '.
4038: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4039: '</label></span>'.(' 'x2);
4040: }
4041: }
4042: if ($field eq 'screenshot') {
4043: my $display;
4044: if ($currfield{$field} eq 'no') {
4045: $display = ' style="display:none"';
4046: }
1.334 raeburn 4047: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4048: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4049: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4050: }
4051: $datatable .= '</td></tr>';
4052: }
4053: $datatable .= '</table>';
4054: }
4055: $datatable .= '</td></tr>'."\n";
4056: $rownum ++;
4057: }
1.340 raeburn 4058: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4059: foreach my $type (@mailings) {
4060: $css_class = $rownum%2?' class="LC_odd_row"':'';
4061: $datatable .= '<tr'.$css_class.'>'.
4062: '<td><span class="LC_nobreak">'.
4063: $titles->{$type}.': </span></td>'.
4064: '<td class="LC_left_item">';
4065: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4066: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4067: }
4068: $datatable .= '<span class="LC_nobreak">';
4069: foreach my $item (@contacts) {
4070: $datatable .= '<label>'.
4071: '<input type="checkbox" name="'.$type.'"'.
4072: $checked{$type}{$item}.
4073: ' value="'.$item.'" />'.$short_titles->{$item}.
4074: '</label> ';
4075: }
4076: $datatable .= '</span><br />'.&mt('Others').': '.
4077: '<input type="text" name="'.$type.'_others" '.
4078: 'value="'.$otheremails{$type}.'" />';
4079: my %locchecked;
4080: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4081: foreach my $loc ('s','b') {
4082: if ($includeloc{$type} eq $loc) {
4083: $locchecked{$loc} = ' checked="checked"';
4084: last;
4085: }
4086: }
4087: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4088: '<input type="text" name="'.$type.'_bcc" '.
4089: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4090: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4091: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4092: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4093: '<span class="LC_nobreak">'.&mt('Location:').' '.
4094: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4095: (' 'x2).
4096: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4097: '</span></fieldset>';
4098: }
4099: $datatable .= '</td></tr>'."\n";
4100: $rownum ++;
4101: }
1.28 raeburn 4102: }
1.286 raeburn 4103: if ($position eq 'middle') {
4104: my %choices;
1.340 raeburn 4105: my $corelink = &core_link_msu();
4106: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4107: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4108: $corelink);
4109: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4110: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4111: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4112: 'reportupdates' => 'on',
4113: 'reportstatus' => 'on');
1.286 raeburn 4114: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4115: \%choices,$rownum);
4116: $datatable .= $reports;
1.340 raeburn 4117: } elsif ($position eq 'lower') {
1.378 raeburn 4118: my (%current,%excluded,%weights);
1.340 raeburn 4119: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4120: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4121: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4122: } else {
1.378 raeburn 4123: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4124: }
4125: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4126: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4127: } else {
1.378 raeburn 4128: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4129: }
4130: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4131: foreach my $type ('E','W','N','U') {
1.340 raeburn 4132: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4133: $weights{$type} = $lonstatus{'weights'}{$type};
4134: } else {
4135: $weights{$type} = $defaults->{$type};
4136: }
4137: }
4138: } else {
1.341 raeburn 4139: foreach my $type ('E','W','N','U') {
1.340 raeburn 4140: $weights{$type} = $defaults->{$type};
4141: }
4142: }
4143: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4144: if (@{$lonstatus{'excluded'}} > 0) {
4145: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4146: }
4147: }
1.378 raeburn 4148: foreach my $item ('errorthreshold','errorsysmail') {
4149: $css_class = $rownum%2?' class="LC_odd_row"':'';
4150: $datatable .= '<tr'.$css_class.'>'.
4151: '<td class="LC_left_item"><span class="LC_nobreak">'.
4152: $titles->{$item}.
4153: '</span></td><td class="LC_left_item">'.
4154: '<input type="text" name="'.$item.'" value="'.
4155: $current{$item}.'" size="5" /></td></tr>';
4156: $rownum ++;
4157: }
1.340 raeburn 4158: $css_class = $rownum%2?' class="LC_odd_row"':'';
4159: $datatable .= '<tr'.$css_class.'>'.
4160: '<td class="LC_left_item">'.
4161: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4162: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4163: foreach my $type ('E','W','N','U') {
1.340 raeburn 4164: $datatable .= '<td>'.$names->{$type}.'<br />'.
4165: '<input type="text" name="errorweights_'.$type.'" value="'.
4166: $weights{$type}.'" size="5" /></td>';
4167: }
4168: $datatable .= '</tr></table></tr>';
4169: $rownum ++;
4170: $css_class = $rownum%2?' class="LC_odd_row"':'';
4171: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4172: $titles->{'errorexcluded'}.'</td>'.
4173: '<td class="LC_left_item"><table>';
4174: my $numinrow = 4;
4175: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4176: for (my $i=0; $i<@ids; $i++) {
4177: my $rem = $i%($numinrow);
4178: if ($rem == 0) {
4179: if ($i > 0) {
4180: $datatable .= '</tr>';
4181: }
4182: $datatable .= '<tr>';
4183: }
4184: my $check;
4185: if ($excluded{$ids[$i]}) {
4186: $check = ' checked="checked" ';
4187: }
4188: $datatable .= '<td class="LC_left_item">'.
4189: '<span class="LC_nobreak"><label>'.
4190: '<input type="checkbox" name="errorexcluded" '.
4191: 'value="'.$ids[$i].'"'.$check.' />'.
4192: $ids[$i].'</label></span></td>';
4193: }
4194: my $colsleft = $numinrow - @ids%($numinrow);
4195: if ($colsleft > 1 ) {
4196: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4197: ' </td>';
4198: } elsif ($colsleft == 1) {
4199: $datatable .= '<td class="LC_left_item"> </td>';
4200: }
4201: $datatable .= '</tr></table></td></tr>';
4202: $rownum ++;
1.286 raeburn 4203: } elsif ($position eq 'bottom') {
1.315 raeburn 4204: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4205: my (@posstypes,%usertypeshash);
4206: if (ref($types) eq 'ARRAY') {
4207: @posstypes = @{$types};
4208: }
4209: if (@posstypes) {
4210: if (ref($usertypes) eq 'HASH') {
4211: %usertypeshash = %{$usertypes};
4212: }
4213: my @overridden;
4214: my $numinrow = 4;
4215: if (ref($settings) eq 'HASH') {
4216: if (ref($settings->{'overrides'}) eq 'HASH') {
4217: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4218: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4219: push(@overridden,$key);
4220: foreach my $item (@contacts) {
4221: if ($settings->{'overrides'}{$key}{$item}) {
4222: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4223: }
4224: }
4225: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4226: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4227: $includeloc{'override_'.$key} = '';
4228: $includestr{'override_'.$key} = '';
4229: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4230: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4231: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4232: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4233: }
1.286 raeburn 4234: }
4235: }
4236: }
1.315 raeburn 4237: }
4238: my $customclass = 'LC_helpdesk_override';
4239: my $optionsprefix = 'LC_options_helpdesk_';
4240:
4241: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4242:
4243: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4244: $numinrow,$othertitle,'overrides',
4245: \$rownum,$onclicktypes,$customclass);
4246: $rownum ++;
4247: $usertypeshash{'default'} = $othertitle;
4248: foreach my $status (@posstypes) {
4249: my $css_class;
4250: if ($rownum%2) {
4251: $css_class = 'LC_odd_row ';
4252: }
4253: $css_class .= $customclass;
4254: my $rowid = $optionsprefix.$status;
4255: my $hidden = 1;
4256: my $currstyle = 'display:none';
4257: if (grep(/^\Q$status\E$/,@overridden)) {
4258: $currstyle = 'display:table-row';
4259: $hidden = 0;
4260: }
4261: my $key = 'override_'.$status;
4262: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4263: $includeloc{$key},$includestr{$key},$status,$rowid,
4264: $usertypeshash{$status},$css_class,$currstyle,
4265: \@contacts,$short_titles);
4266: unless ($hidden) {
4267: $rownum ++;
1.286 raeburn 4268: }
4269: }
1.134 raeburn 4270: }
1.28 raeburn 4271: }
1.30 raeburn 4272: $$rowtotal += $rownum;
1.28 raeburn 4273: return $datatable;
4274: }
4275:
1.340 raeburn 4276: sub core_link_msu {
4277: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4278: &mt('LON-CAPA core group - MSU'),600,500);
4279: }
4280:
1.315 raeburn 4281: sub overridden_helpdesk {
4282: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4283: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4284: my $class = 'LC_left_item';
4285: if ($css_class) {
4286: $css_class = ' class="'.$css_class.'"';
4287: }
4288: if ($rowid) {
4289: $rowid = ' id="'.$rowid.'"';
4290: }
4291: if ($rowstyle) {
4292: $rowstyle = ' style="'.$rowstyle.'"';
4293: }
4294: my ($output,$description);
4295: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4296: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4297: "<td>$description</td>\n".
4298: '<td class="'.$class.'" colspan="2">'.
4299: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4300: '<span class="LC_nobreak">';
4301: if (ref($contacts) eq 'ARRAY') {
4302: foreach my $item (@{$contacts}) {
4303: my $check;
4304: if (ref($checked) eq 'HASH') {
4305: $check = $checked->{$item};
4306: }
4307: my $title;
4308: if (ref($short_titles) eq 'HASH') {
4309: $title = $short_titles->{$item};
4310: }
4311: $output .= '<label>'.
4312: '<input type="checkbox" name="override_'.$type.'"'.$check.
4313: ' value="'.$item.'" />'.$title.'</label> ';
4314: }
4315: }
4316: $output .= '</span><br />'.&mt('Others').': '.
4317: '<input type="text" name="override_'.$type.'_others" '.
4318: 'value="'.$otheremails.'" />';
4319: my %locchecked;
4320: foreach my $loc ('s','b') {
4321: if ($includeloc eq $loc) {
4322: $locchecked{$loc} = ' checked="checked"';
4323: last;
4324: }
4325: }
4326: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4327: '<input type="text" name="override_'.$type.'_bcc" '.
4328: 'value="'.$bccemails.'" /></fieldset>'.
4329: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4330: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4331: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4332: '<span class="LC_nobreak">'.&mt('Location:').' '.
4333: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4334: (' 'x2).
4335: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4336: '</span></fieldset>'.
4337: '</td></tr>'."\n";
4338: return $output;
4339: }
4340:
1.286 raeburn 4341: sub contacts_javascript {
4342: return <<"ENDSCRIPT";
4343:
4344: <script type="text/javascript">
4345: // <![CDATA[
4346:
4347: function screenshotSize(field) {
4348: if (document.getElementById('help_screenshotsize')) {
4349: if (field.value == 'no') {
1.289 raeburn 4350: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4351: } else {
4352: document.getElementById('help_screenshotsize').style.display="";
4353: }
4354: }
4355: return;
4356: }
4357:
1.315 raeburn 4358: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4359: if (form.elements[checkbox].length != undefined) {
4360: var count = 0;
4361: if (docount) {
4362: for (var i=0; i<form.elements[checkbox].length; i++) {
4363: if (form.elements[checkbox][i].checked) {
4364: count ++;
4365: }
4366: }
4367: }
4368: for (var i=0; i<form.elements[checkbox].length; i++) {
4369: var type = form.elements[checkbox][i].value;
4370: if (document.getElementById(prefix+type)) {
4371: if (form.elements[checkbox][i].checked) {
4372: document.getElementById(prefix+type).style.display = 'table-row';
4373: if (count % 2 == 1) {
4374: document.getElementById(prefix+type).className = target+' LC_odd_row';
4375: } else {
4376: document.getElementById(prefix+type).className = target;
4377: }
4378: count ++;
4379: } else {
4380: document.getElementById(prefix+type).style.display = 'none';
4381: }
4382: }
4383: }
4384: }
4385: return;
4386: }
4387:
4388:
1.286 raeburn 4389: // ]]>
4390: </script>
4391:
4392: ENDSCRIPT
4393: }
4394:
1.118 jms 4395: sub print_helpsettings {
1.282 raeburn 4396: my ($position,$dom,$settings,$rowtotal) = @_;
4397: my $confname = $dom.'-domainconfig';
1.285 raeburn 4398: my $formname = 'display';
1.168 raeburn 4399: my ($datatable,$itemcount);
1.282 raeburn 4400: if ($position eq 'top') {
4401: $itemcount = 1;
4402: my (%choices,%defaultchecked,@toggles);
4403: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4404: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4405: &mt('LON-CAPA bug tracker'),600,500));
4406: %defaultchecked = ('submitbugs' => 'on');
4407: @toggles = ('submitbugs');
4408: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4409: \%choices,$itemcount);
4410: $$rowtotal ++;
4411: } else {
4412: my $css_class;
4413: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4414: my (%customroles,%ordered,%current);
1.301 raeburn 4415: if (ref($settings) eq 'HASH') {
4416: if (ref($settings->{'adhoc'}) eq 'HASH') {
4417: %current = %{$settings->{'adhoc'}};
4418: }
1.285 raeburn 4419: }
4420: my $count = 0;
4421: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4422: if ($key=~/^rolesdef\_(\w+)$/) {
4423: my $rolename = $1;
1.285 raeburn 4424: my (%privs,$order);
1.282 raeburn 4425: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4426: $customroles{$rolename} = \%privs;
1.285 raeburn 4427: if (ref($current{$rolename}) eq 'HASH') {
4428: $order = $current{$rolename}{'order'};
4429: }
4430: if ($order eq '') {
4431: $order = $count;
4432: }
4433: $ordered{$order} = $rolename;
4434: $count++;
4435: }
4436: }
4437: my $maxnum = scalar(keys(%ordered));
4438: my @roles_by_num = ();
4439: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4440: push(@roles_by_num,$item);
4441: }
4442: my $context = 'domprefs';
4443: my $crstype = 'Course';
4444: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4445: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4446: my ($numstatustypes,@jsarray);
4447: if (ref($types) eq 'ARRAY') {
4448: if (@{$types} > 0) {
4449: $numstatustypes = scalar(@{$types});
4450: push(@accesstypes,'status');
4451: @jsarray = ('bystatus');
1.282 raeburn 4452: }
4453: }
1.290 raeburn 4454: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4455: if (keys(%domhelpdesk)) {
4456: push(@accesstypes,('inc','exc'));
4457: push(@jsarray,('notinc','notexc'));
4458: }
4459: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4460: my $context = 'domprefs';
4461: my $crstype = 'Course';
1.285 raeburn 4462: my $prefix = 'helproles_';
4463: my $add_class = 'LC_hidden';
4464: foreach my $num (@roles_by_num) {
4465: my $role = $ordered{$num};
4466: my ($desc,$access,@statuses);
4467: if (ref($current{$role}) eq 'HASH') {
4468: $desc = $current{$role}{'desc'};
4469: $access = $current{$role}{'access'};
4470: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4471: @statuses = @{$current{$role}{'insttypes'}};
4472: }
4473: }
4474: if ($desc eq '') {
4475: $desc = $role;
4476: }
4477: my $identifier = 'custhelp'.$num;
1.282 raeburn 4478: my %full=();
4479: my %levels= (
4480: course => {},
4481: domain => {},
4482: system => {},
4483: );
4484: my %levelscurrent=(
4485: course => {},
4486: domain => {},
4487: system => {},
4488: );
4489: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4490: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4492: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4493: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4494: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4495: for (my $k=0; $k<=$maxnum; $k++) {
4496: my $vpos = $k+1;
4497: my $selstr;
4498: if ($k == $num) {
4499: $selstr = ' selected="selected" ';
4500: }
4501: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4502: }
4503: $datatable .= '</select>'.(' 'x2).
4504: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4505: '</td>'.
4506: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4507: &mt('Name shown to users:').
4508: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4509: '</fieldset>'.
4510: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4511: $othertitle,$usertypes,$types,\%domhelpdesk).
4512: '<fieldset>'.
4513: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4514: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4515: \%levelscurrent,$identifier,
4516: 'LC_hidden',$prefix.$num.'_privs').
4517: '</fieldset></td>';
1.282 raeburn 4518: $itemcount ++;
4519: }
4520: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4521: my $newcust = 'custhelp'.$count;
4522: my (%privs,%levelscurrent);
4523: my %full=();
4524: my %levels= (
4525: course => {},
4526: domain => {},
4527: system => {},
4528: );
4529: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4530: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4531: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4532: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4533: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4534: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4535: for (my $k=0; $k<$maxnum+1; $k++) {
4536: my $vpos = $k+1;
4537: my $selstr;
4538: if ($k == $maxnum) {
4539: $selstr = ' selected="selected" ';
4540: }
4541: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4542: }
4543: $datatable .= '</select> '."\n".
1.282 raeburn 4544: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4545: '</label></span></td>'.
1.285 raeburn 4546: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4547: '<span class="LC_nobreak">'.
4548: &mt('Internal name:').
4549: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4550: '</span>'.(' 'x4).
4551: '<span class="LC_nobreak">'.
4552: &mt('Name shown to users:').
4553: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4554: '</span></fieldset>'.
4555: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4556: $usertypes,$types,\%domhelpdesk).
4557: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4558: &Apache::lonuserutils::custom_role_header($context,$crstype,
4559: \@templateroles,$newcust).
4560: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4561: \%levelscurrent,$newcust).
1.334 raeburn 4562: '</fieldset>'.
4563: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4564: '</td></tr>';
1.282 raeburn 4565: $count ++;
4566: $$rowtotal += $count;
4567: }
1.166 raeburn 4568: return $datatable;
1.121 raeburn 4569: }
4570:
1.285 raeburn 4571: sub adhocbutton {
4572: my ($prefix,$num,$field,$visibility) = @_;
4573: my %lt = &Apache::lonlocal::texthash(
4574: show => 'Show details',
4575: hide => 'Hide details',
4576: );
4577: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4578: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4579: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4580: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4581: }
4582:
4583: sub helpsettings_javascript {
4584: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4585: return unless(ref($roles_by_num) eq 'ARRAY');
4586: my %html_js_lt = &Apache::lonlocal::texthash(
4587: show => 'Show details',
4588: hide => 'Hide details',
4589: );
4590: &html_escape(\%html_js_lt);
4591: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4592: return <<"ENDSCRIPT";
4593: <script type="text/javascript">
4594: // <![CDATA[
4595:
4596: function reorderHelpRoles(form,item) {
4597: var changedVal;
4598: $jstext
4599: var newpos = 'helproles_${total}_pos';
4600: var maxh = 1 + $total;
4601: var current = new Array();
4602: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4603: if (item == newpos) {
4604: changedVal = newitemVal;
4605: } else {
4606: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4607: current[newitemVal] = newpos;
4608: }
4609: for (var i=0; i<helproles.length; i++) {
4610: var elementName = 'helproles_'+helproles[i]+'_pos';
4611: if (elementName != item) {
4612: if (form.elements[elementName]) {
4613: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4614: current[currVal] = elementName;
4615: }
4616: }
4617: }
4618: var oldVal;
4619: for (var j=0; j<maxh; j++) {
4620: if (current[j] == undefined) {
4621: oldVal = j;
4622: }
4623: }
4624: if (oldVal < changedVal) {
4625: for (var k=oldVal+1; k<=changedVal ; k++) {
4626: var elementName = current[k];
4627: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4628: }
4629: } else {
4630: for (var k=changedVal; k<oldVal; k++) {
4631: var elementName = current[k];
4632: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4633: }
4634: }
4635: return;
4636: }
4637:
4638: function helpdeskAccess(num) {
4639: var curraccess = null;
4640: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4641: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4642: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4643: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4644: }
4645: }
4646: }
4647: var shown = Array();
4648: var hidden = Array();
4649: if (curraccess == 'none') {
4650: hidden = Array('$hiddenstr');
4651: } else {
4652: if (curraccess == 'status') {
4653: shown = Array('bystatus');
4654: hidden = Array('notinc','notexc');
4655: } else {
4656: if (curraccess == 'exc') {
4657: shown = Array('notexc');
4658: hidden = Array('notinc','bystatus');
4659: }
4660: if (curraccess == 'inc') {
4661: shown = Array('notinc');
4662: hidden = Array('notexc','bystatus');
4663: }
1.293 raeburn 4664: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4665: hidden = Array('notinc','notexc','bystatus');
4666: }
4667: }
4668: }
4669: if (hidden.length > 0) {
4670: for (var i=0; i<hidden.length; i++) {
4671: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4672: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4673: }
4674: }
4675: }
4676: if (shown.length > 0) {
4677: for (var i=0; i<shown.length; i++) {
4678: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4679: if (shown[i] == 'privs') {
4680: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4681: } else {
4682: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4683: }
4684: }
4685: }
4686: }
4687: return;
4688: }
4689:
4690: function toggleHelpdeskItem(num,field) {
4691: if (document.getElementById('helproles_'+num+'_'+field)) {
4692: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4693: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4694: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4695: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4696: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4697: }
4698: } else {
4699: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4700: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4701: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4702: }
4703: }
4704: }
4705: return;
4706: }
4707:
4708: // ]]>
4709: </script>
4710:
4711: ENDSCRIPT
4712: }
4713:
4714: sub helpdeskroles_access {
4715: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4716: $usertypes,$types,$domhelpdesk) = @_;
4717: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4718: my %lt = &Apache::lonlocal::texthash(
4719: 'rou' => 'Role usage',
4720: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4721: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4722: 'dh' => 'All with domain helpdesk role',
4723: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4724: 'none' => 'None',
4725: 'status' => 'Determined based on institutional status',
4726: 'inc' => 'Include all, but exclude specific personnel',
4727: 'exc' => 'Exclude all, but include specific personnel',
4728: );
4729: my %usecheck = (
4730: all => ' checked="checked"',
4731: );
4732: my %displaydiv = (
4733: status => 'none',
4734: inc => 'none',
4735: exc => 'none',
4736: priv => 'block',
4737: );
4738: my $output;
4739: if (ref($current) eq 'HASH') {
4740: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4741: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4742: $usecheck{$current->{access}} = $usecheck{'all'};
4743: delete($usecheck{'all'});
4744: if ($current->{access} =~ /^(status|inc|exc)$/) {
4745: my $access = $1;
4746: $displaydiv{$access} = 'inline';
4747: } elsif ($current->{access} eq 'none') {
4748: $displaydiv{'priv'} = 'none';
4749: }
4750: }
4751: }
4752: }
4753: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4754: '<p>'.$lt{'whi'}.'</p>';
4755: foreach my $access (@{$accesstypes}) {
4756: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4757: ' onclick="helpdeskAccess('."'$num'".');" />'.
4758: $lt{$access}.'</label>';
4759: if ($access eq 'status') {
4760: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4761: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4762: $othertitle,$usertypes,$types).
4763: '</div>';
4764: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4765: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4766: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4767: '</div>';
4768: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4769: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4770: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4771: '</div>';
4772: }
4773: $output .= '</p>';
4774: }
4775: $output .= '</fieldset>';
4776: return $output;
4777: }
4778:
1.121 raeburn 4779: sub radiobutton_prefs {
1.192 raeburn 4780: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 4781: $additional,$align,$firstval) = @_;
1.121 raeburn 4782: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4783: (ref($choices) eq 'HASH'));
4784:
1.170 raeburn 4785: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4786:
4787: foreach my $item (@{$toggles}) {
4788: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4789: $checkedon{$item} = ' checked="checked" ';
4790: $checkedoff{$item} = ' ';
1.121 raeburn 4791: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4792: $checkedoff{$item} = ' checked="checked" ';
4793: $checkedon{$item} = ' ';
4794: }
4795: }
4796: if (ref($settings) eq 'HASH') {
1.121 raeburn 4797: foreach my $item (@{$toggles}) {
1.118 jms 4798: if ($settings->{$item} eq '1') {
4799: $checkedon{$item} = ' checked="checked" ';
4800: $checkedoff{$item} = ' ';
4801: } elsif ($settings->{$item} eq '0') {
4802: $checkedoff{$item} = ' checked="checked" ';
4803: $checkedon{$item} = ' ';
4804: }
4805: }
1.121 raeburn 4806: }
1.192 raeburn 4807: if ($onclick) {
4808: $onclick = ' onclick="'.$onclick.'"';
4809: }
1.121 raeburn 4810: foreach my $item (@{$toggles}) {
1.118 jms 4811: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4812: $datatable .=
1.306 raeburn 4813: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4814: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4815: '</span></td>';
4816: if ($align eq 'left') {
4817: $datatable .= '<td class="LC_left_item">';
4818: } else {
4819: $datatable .= '<td class="LC_right_item">';
4820: }
1.385 raeburn 4821: $datatable .= '<span class="LC_nobreak">';
4822: if ($firstval eq 'no') {
4823: $datatable .=
4824: '<label><input type="radio" name="'.
4825: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4826: '</label> <label><input type="radio" name="'.$item.'" '.
4827: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4828: } else {
4829: $datatable .=
4830: '<label><input type="radio" name="'.
4831: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
4832: '</label> <label><input type="radio" name="'.$item.'" '.
4833: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4834: }
4835: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4836: $itemcount ++;
1.121 raeburn 4837: }
4838: return ($datatable,$itemcount);
4839: }
4840:
1.267 raeburn 4841: sub print_ltitools {
4842: my ($dom,$settings,$rowtotal) = @_;
4843: my $rownum = 0;
4844: my $css_class;
4845: my $itemcount = 1;
4846: my $maxnum = 0;
4847: my %ordered;
4848: if (ref($settings) eq 'HASH') {
4849: foreach my $item (keys(%{$settings})) {
4850: if (ref($settings->{$item}) eq 'HASH') {
4851: my $num = $settings->{$item}{'order'};
4852: $ordered{$num} = $item;
4853: }
4854: }
4855: }
4856: my $confname = $dom.'-domainconfig';
4857: my $switchserver = &check_switchserver($dom,$confname);
4858: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4859: my $datatable;
1.267 raeburn 4860: my %lt = <itools_names();
4861: my @courseroles = ('cc','in','ta','ep','st');
4862: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4863: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4864: if (keys(%ordered)) {
4865: my @items = sort { $a <=> $b } keys(%ordered);
4866: for (my $i=0; $i<@items; $i++) {
4867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4868: my $item = $ordered{$items[$i]};
1.323 raeburn 4869: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4870: if (ref($settings->{$item}) eq 'HASH') {
4871: $title = $settings->{$item}->{'title'};
4872: $url = $settings->{$item}->{'url'};
4873: $key = $settings->{$item}->{'key'};
4874: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4875: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4876: my $image = $settings->{$item}->{'image'};
4877: if ($image ne '') {
4878: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4879: }
1.323 raeburn 4880: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4881: $sigsel{'HMAC-256'} = ' selected="selected"';
4882: } else {
4883: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4884: }
1.267 raeburn 4885: }
1.319 raeburn 4886: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4887: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4888: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4889: for (my $k=0; $k<=$maxnum; $k++) {
4890: my $vpos = $k+1;
4891: my $selstr;
4892: if ($k == $i) {
4893: $selstr = ' selected="selected" ';
4894: }
4895: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4896: }
4897: $datatable .= '</select>'.(' 'x2).
4898: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4899: &mt('Delete?').'</label></span></td>'.
4900: '<td colspan="2">'.
4901: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4902: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4903: (' 'x2).
4904: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4905: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4906: (' 'x2).
4907: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4908: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4909: (' 'x2).
4910: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4911: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4912: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4913: '<br /><br />'.
1.323 raeburn 4914: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4915: ' value="'.$url.'" /></span>'.
4916: (' 'x2).
1.319 raeburn 4917: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4918: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4919: (' 'x2).
1.322 raeburn 4920: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4921: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4922: (' 'x2).
1.267 raeburn 4923: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4924: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4925: '<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>'.
4926: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4927: '</fieldset>'.
4928: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4929: '<span class="LC_nobreak">'.&mt('Display target:');
4930: my %currdisp;
4931: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4932: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4933: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4934: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4935: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4936: } else {
4937: $currdisp{'iframe'} = ' checked="checked"';
4938: }
4939: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4940: $currdisp{'width'} = $1;
4941: }
4942: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4943: $currdisp{'height'} = $1;
4944: }
1.296 raeburn 4945: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4946: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4947: } else {
4948: $currdisp{'iframe'} = ' checked="checked"';
4949: }
1.298 raeburn 4950: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4951: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4952: $lt{$disp}.'</label>'.(' 'x2);
4953: }
4954: $datatable .= (' 'x4);
4955: foreach my $dimen ('width','height') {
4956: $datatable .= '<label>'.$lt{$dimen}.' '.
4957: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4958: (' 'x2);
4959: }
1.334 raeburn 4960: $datatable .= '</span><br />'.
1.296 raeburn 4961: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4962: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4963: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4964: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4965: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4966: my %units = (
4967: 'passback' => 'days',
4968: 'roster' => 'seconds',
4969: );
1.267 raeburn 4970: foreach my $extra ('passback','roster') {
1.319 raeburn 4971: my $validsty = 'none';
4972: my $currvalid;
1.267 raeburn 4973: my $checkedon = '';
4974: my $checkedoff = ' checked="checked"';
4975: if ($settings->{$item}->{$extra}) {
4976: $checkedon = $checkedoff;
4977: $checkedoff = '';
1.319 raeburn 4978: $validsty = 'inline-block';
4979: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4980: $currvalid = $settings->{$item}->{$extra.'valid'};
4981: }
4982: }
4983: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4984: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4985: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4986: &mt('No').'</label>'.(' 'x2).
4987: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4988: &mt('Yes').'</label></span></div>'.
4989: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4990: '<span class="LC_nobreak">'.
4991: &mt("at least [_1] $units{$extra} after launch",
4992: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4993: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4994: }
1.319 raeburn 4995: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4996: if ($imgsrc) {
4997: $datatable .= $imgsrc.
4998: '<label><input type="checkbox" name="ltitools_image_del"'.
4999: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5000: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5001: } else {
5002: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5003: }
5004: if ($switchserver) {
5005: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5006: } else {
5007: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5008: }
5009: $datatable .= '</span></fieldset>';
1.324 raeburn 5010: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5011: if (ref($settings->{$item}) eq 'HASH') {
5012: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5013: %checkedfields = %{$settings->{$item}->{'fields'}};
5014: }
1.324 raeburn 5015: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5016: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5017: %rolemaps = %{$settings->{$item}->{'roles'}};
5018: $checkedfields{'roles'} = 1;
5019: }
5020: }
5021: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5022: '<span class="LC_nobreak">';
1.324 raeburn 5023: my $userfieldstyle = 'display:none;';
5024: my $seluserdom = '';
5025: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5026: foreach my $field (@fields) {
1.324 raeburn 5027: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5028: if ($checkedfields{$field}) {
5029: $checked = ' checked="checked"';
5030: }
1.324 raeburn 5031: if ($field eq 'user') {
5032: $id = ' id="ltitools_user_field_'.$i.'"';
5033: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5034: if ($checked) {
5035: $userfieldstyle = 'display:inline-block';
5036: if ($userincdom) {
5037: $seluserdom = $unseluserdom;
5038: $unseluserdom = '';
5039: }
5040: }
5041: } else {
5042: $spacer = (' ' x2);
5043: }
1.267 raeburn 5044: $datatable .= '<label>'.
1.324 raeburn 5045: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5046: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5047: }
1.324 raeburn 5048: $datatable .= '</span>';
5049: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5050: '<span class="LC_nobreak"> : '.
5051: '<select name="ltitools_userincdom_'.$i.'">'.
5052: '<option value="">'.&mt('Select').'</option>'.
5053: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5054: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5055: '</select></span></div>';
5056: $datatable .= '</fieldset>'.
1.267 raeburn 5057: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5058: foreach my $role (@courseroles) {
5059: my ($selected,$selectnone);
5060: if (!$rolemaps{$role}) {
5061: $selectnone = ' selected="selected"';
5062: }
1.306 raeburn 5063: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5064: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5065: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5066: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5067: foreach my $ltirole (@ltiroles) {
5068: unless ($selectnone) {
5069: if ($rolemaps{$role} eq $ltirole) {
5070: $selected = ' selected="selected"';
5071: } else {
5072: $selected = '';
5073: }
5074: }
5075: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5076: }
5077: $datatable .= '</select></td>';
5078: }
1.273 raeburn 5079: $datatable .= '</tr></table></fieldset>';
5080: my %courseconfig;
5081: if (ref($settings->{$item}) eq 'HASH') {
5082: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5083: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5084: }
5085: }
5086: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5087: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5088: my $checked;
5089: if ($courseconfig{$item}) {
5090: $checked = ' checked="checked"';
5091: }
5092: $datatable .= '<label>'.
5093: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5094: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5095: }
5096: $datatable .= '</span></fieldset>'.
1.267 raeburn 5097: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5098: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5099: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5100: my %custom = %{$settings->{$item}->{'custom'}};
5101: if (keys(%custom) > 0) {
5102: foreach my $key (sort(keys(%custom))) {
5103: $datatable .= '<tr><td><span class="LC_nobreak">'.
5104: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5105: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5106: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5107: ' value="'.$custom{$key}.'" /></td></tr>';
5108: }
5109: }
5110: }
5111: $datatable .= '<tr><td><span class="LC_nobreak">'.
5112: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5113: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5114: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5115: $datatable .= '</table></fieldset></td></tr>'."\n";
5116: $itemcount ++;
5117: }
5118: }
5119: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5120: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5121: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5122: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5123: '<select name="ltitools_add_pos"'.$chgstr.'>';
5124: for (my $k=0; $k<$maxnum+1; $k++) {
5125: my $vpos = $k+1;
5126: my $selstr;
5127: if ($k == $maxnum) {
5128: $selstr = ' selected="selected" ';
5129: }
5130: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5131: }
5132: $datatable .= '</select> '."\n".
1.334 raeburn 5133: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5134: '<td colspan="2">'.
5135: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5136: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5137: (' 'x2).
5138: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5139: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5140: (' 'x2).
5141: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5142: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5143: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5144: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5145: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5146: '<br />'.
1.323 raeburn 5147: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5148: (' 'x2).
5149: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5150: (' 'x2).
1.322 raeburn 5151: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5152: (' 'x2).
1.267 raeburn 5153: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5154: '<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".
5155: '</fieldset>'.
5156: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5157: '<span class="LC_nobreak">'.&mt('Display target:');
5158: my %defaultdisp;
5159: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5160: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5161: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5162: $lt{$disp}.'</label>'.(' 'x2);
5163: }
5164: $datatable .= (' 'x4);
5165: foreach my $dimen ('width','height') {
5166: $datatable .= '<label>'.$lt{$dimen}.' '.
5167: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5168: (' 'x2);
5169: }
1.334 raeburn 5170: $datatable .= '</span><br />'.
1.296 raeburn 5171: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5172: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5173: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5174: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5175: '</div><div style=""></div><br />';
1.319 raeburn 5176: my %units = (
5177: 'passback' => 'days',
5178: 'roster' => 'seconds',
5179: );
5180: my %defaulttimes = (
5181: 'passback' => '7',
1.322 raeburn 5182: 'roster' => '300',
1.319 raeburn 5183: );
1.267 raeburn 5184: foreach my $extra ('passback','roster') {
1.319 raeburn 5185: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5186: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5187: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5188: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5189: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5190: &mt('Yes').'</label></span></div>'.
5191: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5192: '<span class="LC_nobreak">'.
5193: &mt("at least [_1] $units{$extra} after launch",
5194: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5195: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5196: }
1.319 raeburn 5197: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5198: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5199: if ($switchserver) {
5200: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5201: } else {
5202: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5203: }
5204: $datatable .= '</span></fieldset>'.
5205: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5206: '<span class="LC_nobreak">';
5207: foreach my $field (@fields) {
1.324 raeburn 5208: my ($id,$onclick,$spacer);
5209: if ($field eq 'user') {
5210: $id = ' id="ltitools_user_field_add"';
5211: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5212: } else {
5213: $spacer = (' ' x2);
5214: }
1.267 raeburn 5215: $datatable .= '<label>'.
1.324 raeburn 5216: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5217: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5218: }
1.324 raeburn 5219: $datatable .= '</span>'.
5220: '<div style="display:none;" id="ltitools_user_div_add">'.
5221: '<span class="LC_nobreak"> : '.
5222: '<select name="ltitools_userincdom_add">'.
5223: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5224: '<option value="0">'.&mt('username').'</option>'.
5225: '<option value="1">'.&mt('username:domain').'</option>'.
5226: '</select></span></div></fieldset>';
5227: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5228: foreach my $role (@courseroles) {
5229: my ($checked,$checkednone);
1.306 raeburn 5230: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5231: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5232: '<select name="ltitools_add_roles_'.$role.'">'.
5233: '<option value="" selected="selected">'.&mt('Select').'</option>';
5234: foreach my $ltirole (@ltiroles) {
5235: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5236: }
5237: $datatable .= '</select></td>';
5238: }
5239: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5240: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5241: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5242: $datatable .= '<label>'.
5243: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5244: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5245: }
5246: $datatable .= '</span></fieldset>'.
1.267 raeburn 5247: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5248: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5249: '<tr><td><span class="LC_nobreak">'.
5250: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5251: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5252: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5253: '</table></fieldset>'."\n".
1.267 raeburn 5254: '</td>'."\n".
5255: '</tr>'."\n";
5256: $itemcount ++;
5257: return $datatable;
5258: }
5259:
5260: sub ltitools_names {
5261: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5262: 'title' => 'Title',
5263: 'version' => 'Version',
5264: 'msgtype' => 'Message Type',
1.323 raeburn 5265: 'sigmethod' => 'Signature Method',
1.296 raeburn 5266: 'url' => 'URL',
5267: 'key' => 'Key',
1.322 raeburn 5268: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5269: 'secret' => 'Secret',
5270: 'icon' => 'Icon',
1.324 raeburn 5271: 'user' => 'User',
1.296 raeburn 5272: 'fullname' => 'Full Name',
5273: 'firstname' => 'First Name',
5274: 'lastname' => 'Last Name',
5275: 'email' => 'E-mail',
5276: 'roles' => 'Role',
1.298 raeburn 5277: 'window' => 'Window',
5278: 'tab' => 'Tab',
1.296 raeburn 5279: 'iframe' => 'iFrame',
5280: 'height' => 'Height',
5281: 'width' => 'Width',
5282: 'linktext' => 'Default Link Text',
5283: 'explanation' => 'Default Explanation',
5284: 'passback' => 'Tool can return grades:',
5285: 'roster' => 'Tool can retrieve roster:',
5286: 'crstarget' => 'Display target',
5287: 'crslabel' => 'Course label',
5288: 'crstitle' => 'Course title',
5289: 'crslinktext' => 'Link Text',
5290: 'crsexplanation' => 'Explanation',
1.318 raeburn 5291: 'crsappend' => 'Provider URL',
1.267 raeburn 5292: );
5293: return %lt;
5294: }
5295:
1.372 raeburn 5296: sub print_proctoring {
5297: my ($dom,$settings,$rowtotal) = @_;
5298: my $itemcount = 1;
5299: my (%ordered,%providernames,%current,%currentdef);
5300: my $confname = $dom.'-domainconfig';
5301: my $switchserver = &check_switchserver($dom,$confname);
5302: if (ref($settings) eq 'HASH') {
5303: foreach my $item (keys(%{$settings})) {
5304: if (ref($settings->{$item}) eq 'HASH') {
5305: my $num = $settings->{$item}{'order'};
5306: $ordered{$num} = $item;
5307: }
5308: }
5309: } else {
5310: %ordered = (
5311: 1 => 'proctorio',
5312: 2 => 'examity',
5313: );
5314: }
5315: %providernames = &proctoring_providernames();
5316: my $maxnum = scalar(keys(%ordered));
5317: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5318: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5319: if (ref($requref) eq 'HASH') {
5320: %requserfields = %{$requref};
5321: }
5322: if (ref($opturef) eq 'HASH') {
5323: %optuserfields = %{$opturef};
5324: }
5325: if (ref($defref) eq 'HASH') {
5326: %defaults = %{$defref};
5327: }
5328: if (ref($extref) eq 'HASH') {
5329: %extended = %{$extref};
5330: }
5331: if (ref($crsref) eq 'HASH') {
5332: %crsconf = %{$crsref};
5333: }
5334: if (ref($rolesref) eq 'ARRAY') {
5335: @courseroles = @{$rolesref};
5336: }
5337: if (ref($ltiref) eq 'ARRAY') {
5338: @ltiroles = @{$ltiref};
5339: }
5340: my $datatable;
5341: my $css_class;
5342: if (keys(%ordered)) {
5343: my @items = sort { $a <=> $b } keys(%ordered);
5344: for (my $i=0; $i<@items; $i++) {
5345: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5346: my $provider = $ordered{$items[$i]};
5347: my $optionsty = 'none';
5348: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5349: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5350: if (ref($settings) eq 'HASH') {
5351: if (ref($settings->{$provider}) eq 'HASH') {
5352: %current = %{$settings->{$provider}};
5353: if ($current{'available'}) {
5354: $optionsty = 'block';
5355: $available = 1;
5356: }
5357: if ($current{'lifetime'} =~ /^\d+$/) {
5358: $lifetime = $current{'lifetime'};
5359: }
5360: if ($current{'version'} =~ /^\d+\.\d+$/) {
5361: $version = $current{'version'};
5362: }
5363: if ($current{'image'} ne '') {
5364: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5365: }
5366: if (ref($current{'fields'}) eq 'ARRAY') {
5367: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5368: }
5369: $userincdom = $current{'incdom'};
5370: if (ref($current{'roles'}) eq 'HASH') {
5371: %rolemaps = %{$current{'roles'}};
5372: $checkedfields{'roles'} = 1;
5373: }
5374: if (ref($current{'defaults'}) eq 'ARRAY') {
5375: foreach my $val (@{$current{'defaults'}}) {
5376: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5377: $inuse{$val} = 1;
5378: } else {
5379: foreach my $poss (keys(%{$extended{$provider}})) {
5380: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5381: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5382: $inuse{$poss} = $val;
5383: last;
5384: }
5385: }
5386: }
5387: }
5388: }
5389: } elsif (ref($current{'defaults'}) eq 'HASH') {
5390: foreach my $key (keys(%{$current{'defaults'}})) {
5391: my $currval = $current{'defaults'}{$key};
5392: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5393: $inuse{$key} = 1;
5394: } else {
5395: my $match;
5396: foreach my $poss (keys(%{$extended{$provider}})) {
5397: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5398: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5399: $inuse{$poss} = $key;
5400: last;
5401: }
5402: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5403: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5404: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5405: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5406: $currentdef{$inner} = $currval;
5407: $match = 1;
5408: last;
5409: }
5410: } elsif ($inner eq $key) {
5411: $currentdef{$key} = $currval;
5412: $match = 1;
5413: last;
5414: }
5415: }
5416: }
5417: last if ($match);
5418: }
5419: }
5420: }
5421: }
5422: if (ref($current{'crsconf'}) eq 'ARRAY') {
5423: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5424: }
5425: }
5426: }
5427: my %lt = &proctoring_titles($provider);
5428: my %fieldtitles = &proctoring_fieldtitles($provider);
5429: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5430: my %checkedavailable = (
5431: yes => '',
5432: no => ' checked="checked"',
5433: );
5434: if ($available) {
5435: $checkedavailable{'yes'} = $checkedavailable{'no'};
5436: $checkedavailable{'no'} = '';
5437: }
5438: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5439: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5440: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5441: for (my $k=0; $k<$maxnum; $k++) {
5442: my $vpos = $k+1;
5443: my $selstr;
5444: if ($k == $i) {
5445: $selstr = ' selected="selected" ';
5446: }
5447: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5448: }
5449: if ($version eq '') {
5450: if ($provider eq 'proctorio') {
5451: $version = '1.0';
5452: } elsif ($provider eq 'examity') {
5453: $version = '1.1';
5454: }
5455: }
5456: if ($lifetime eq '') {
5457: $lifetime = '300';
5458: }
5459: $datatable .=
5460: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5461: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5462: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5463: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5464: '</td>'.
5465: '<td colspan="2">'.
5466: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5467: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5468: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5469: (' 'x2).
5470: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5471: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5472: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5473: (' 'x2).
5474: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5475: '<br />'.
5476: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5477: '<br />'.
5478: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5479: (' 'x2).
5480: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5481: '<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";
5482: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5483: if ($imgsrc) {
5484: $datatable .= $imgsrc.
5485: '<label><input type="checkbox" name="proctoring_image_del"'.
5486: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5487: '<span class="LC_nobreak"> '.&mt('Replace:');
5488: }
5489: $datatable .= ' ';
5490: if ($switchserver) {
5491: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5492: } else {
5493: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5494: }
5495: unless ($imgsrc) {
5496: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5497: }
5498: $datatable .= '</fieldset>'."\n";
5499: if (ref($requserfields{$provider}) eq 'ARRAY') {
5500: if (@{$requserfields{$provider}} > 0) {
5501: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5502: foreach my $field (@{$requserfields{$provider}}) {
5503: $datatable .= '<span class="LC_nobreak">'.
5504: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5505: $lt{$field}.'</label>';
5506: if ($field eq 'user') {
5507: my $seluserdom = '';
5508: my $unseluserdom = ' selected="selected"';
5509: if ($userincdom) {
5510: $seluserdom = $unseluserdom;
5511: $unseluserdom = '';
5512: }
5513: $datatable .= ': '.
5514: '<select name="proctoring_userincdom_'.$provider.'">'.
5515: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5516: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5517: '</select> ';
5518: } else {
5519: $datatable .= ' ';
5520: if ($field eq 'roles') {
5521: $showroles = 1;
5522: }
5523: }
5524: $datatable .= '</span> ';
5525: }
5526: }
5527: $datatable .= '</fieldset>'."\n";
5528: }
5529: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5530: if (@{$optuserfields{$provider}} > 0) {
5531: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5532: foreach my $field (@{$optuserfields{$provider}}) {
5533: my $checked;
5534: if ($checkedfields{$field}) {
5535: $checked = ' checked="checked"';
5536: }
5537: $datatable .= '<span class="LC_nobreak">'.
5538: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5539: }
5540: $datatable .= '</fieldset>'."\n";
5541: }
5542: }
5543: if (ref($defaults{$provider}) eq 'ARRAY') {
5544: if (@{$defaults{$provider}}) {
5545: my (%options,@selectboxes);
5546: if (ref($extended{$provider}) eq 'HASH') {
5547: %options = %{$extended{$provider}};
5548: }
5549: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5550: my ($rem,$numinrow,$dropdowns);
5551: if ($provider eq 'proctorio') {
5552: $datatable .= '<table>';
5553: $numinrow = 4;
5554: }
5555: my $i = 0;
5556: foreach my $field (@{$defaults{$provider}}) {
5557: my $checked;
5558: if ($inuse{$field}) {
5559: $checked = ' checked="checked"';
5560: }
5561: if ($provider eq 'examity') {
5562: if ($field eq 'display') {
5563: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5564: foreach my $option ('iframe','tab','window') {
5565: my $checkdisp;
5566: if ($currentdef{'target'} eq $option) {
5567: $checkdisp = ' checked="checked"';
5568: }
5569: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5570: $fieldtitles{$option}.'</label>'.(' 'x2);
5571: }
5572: $datatable .= (' 'x4);
5573: foreach my $dimen ('width','height') {
5574: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5575: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5576: 'value="'.$currentdef{$dimen}.'" /></label>'.
5577: (' 'x2);
5578: }
5579: $datatable .= '</span><br />'.
5580: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5581: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5582: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5583: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5584: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5585: $currentdef{'explanation'}.
5586: '</textarea></div><div style=""></div><br />';
5587: }
5588: } else {
5589: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5590: my ($output,$selnone);
5591: unless ($checked) {
5592: $selnone = ' selected="selected"';
5593: }
5594: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5595: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5596: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5597: foreach my $option (@{$options{$field}}) {
5598: my $sel;
5599: if ($inuse{$field} eq $option) {
5600: $sel = ' selected="selected"';
5601: }
5602: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5603: }
5604: $output .= '</select></span>';
5605: push(@selectboxes,$output);
5606: } else {
5607: $rem = $i%($numinrow);
5608: if ($rem == 0) {
5609: if ($i > 0) {
5610: $datatable .= '</tr>';
5611: }
5612: $datatable .= '<tr>';
5613: }
5614: $datatable .= '<td class="LC_left_item">'.
5615: '<span class="LC_nobreak">'.
5616: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5617: $fieldtitles{$field}.'</label></span></td>';
5618: $i++;
5619: }
5620: }
5621: }
5622: if ($provider eq 'proctorio') {
5623: if ($numinrow) {
5624: $rem = $i%$numinrow;
5625: }
5626: my $colsleft = $numinrow - $rem;
5627: if ($colsleft > 1) {
5628: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5629: } else {
5630: $datatable .= '<td class="LC_left_item">';
5631: }
5632: $datatable .= ' '.
5633: '</td></tr></table>';
5634: if (@selectboxes) {
5635: $datatable .= '<hr /><table>';
5636: $numinrow = 2;
5637: for (my $i=0; $i<@selectboxes; $i++) {
5638: $rem = $i%($numinrow);
5639: if ($rem == 0) {
5640: if ($i > 0) {
5641: $datatable .= '</tr>';
5642: }
5643: $datatable .= '<tr>';
5644: }
5645: $datatable .= '<td class="LC_left_item">'.
5646: $selectboxes[$i].'</td>';
5647: }
5648: if ($numinrow) {
5649: $rem = $i%$numinrow;
5650: }
5651: $colsleft = $numinrow - $rem;
5652: if ($colsleft > 1) {
5653: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5654: } else {
5655: $datatable .= '<td class="LC_left_item">';
5656: }
5657: $datatable .= ' '.
5658: '</td></tr></table>';
5659: }
5660: }
5661: $datatable .= '</fieldset>';
5662: }
5663: if (ref($crsconf{$provider}) eq 'ARRAY') {
5664: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5665: '<legend>'.&mt('Configurable in course').'</legend>';
5666: my ($rem,$numinrow);
5667: if ($provider eq 'proctorio') {
5668: $datatable .= '<table>';
5669: $numinrow = 4;
5670: }
5671: my $i = 0;
5672: foreach my $item (@{$crsconf{$provider}}) {
5673: my $name;
5674: if ($provider eq 'examity') {
5675: $name = $lt{'crs'.$item};
5676: } elsif ($provider eq 'proctorio') {
5677: $name = $fieldtitles{$item};
5678: $rem = $i%($numinrow);
5679: if ($rem == 0) {
5680: if ($i > 0) {
5681: $datatable .= '</tr>';
5682: }
5683: $datatable .= '<tr>';
5684: }
5685: $datatable .= '<td class="LC_left_item>';
5686: }
5687: my $checked;
5688: if ($crsconfig{$item}) {
5689: $checked = ' checked="checked"';
5690: }
5691: $datatable .= '<span class="LC_nobreak"><label>'.
5692: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5693: $name.'</label></span>';
5694: if ($provider eq 'examity') {
5695: $datatable .= ' ';
5696: }
5697: $datatable .= "\n";
5698: $i++;
5699: }
5700: if ($provider eq 'proctorio') {
5701: if ($numinrow) {
5702: $rem = $i%$numinrow;
5703: }
5704: my $colsleft = $numinrow - $rem;
5705: if ($colsleft > 1) {
5706: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5707: } else {
5708: $datatable .= '<td class="LC_left_item">';
5709: }
5710: $datatable .= ' '.
5711: '</td></tr></table>';
5712: }
5713: $datatable .= '</fieldset>';
5714: }
5715: if ($showroles) {
5716: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5717: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5718: foreach my $role (@courseroles) {
5719: my ($selected,$selectnone);
5720: if (!$rolemaps{$role}) {
5721: $selectnone = ' selected="selected"';
5722: }
5723: $datatable .= '<td style="text-align: center">'.
5724: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5725: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5726: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5727: foreach my $ltirole (@ltiroles) {
5728: unless ($selectnone) {
5729: if ($rolemaps{$role} eq $ltirole) {
5730: $selected = ' selected="selected"';
5731: } else {
5732: $selected = '';
5733: }
5734: }
5735: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5736: }
5737: $datatable .= '</select></td>';
5738: }
5739: $datatable .= '</tr></table></fieldset>'.
5740: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5741: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5742: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5743: '<tr><td></td><td>lms</td>'.
5744: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5745: ' value="Loncapa" disabled="disabled"/></td></tr>';
5746: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5747: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5748: my %custom = %{$settings->{$provider}->{'custom'}};
5749: if (keys(%custom) > 0) {
5750: foreach my $key (sort(keys(%custom))) {
5751: next if ($key eq 'lms');
5752: $datatable .= '<tr><td><span class="LC_nobreak">'.
5753: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5754: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5755: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5756: ' value="'.$custom{$key}.'" /></td></tr>';
5757: }
5758: }
5759: }
5760: $datatable .= '<tr><td><span class="LC_nobreak">'.
5761: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5762: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5763: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5764: '</table></fieldset></td></tr>'."\n";
5765: }
5766: $datatable .= '</td></tr>';
5767: }
5768: $itemcount ++;
5769: }
5770: }
5771: return $datatable;
5772: }
5773:
5774: sub proctoring_data {
5775: my $requserfields = {
5776: proctorio => ['user'],
5777: examity => ['roles','user'],
5778: };
5779: my $optuserfields = {
5780: proctorio => ['fullname'],
5781: examity => ['fullname','firstname','lastname','email'],
5782: };
5783: my $defaults = {
5784: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5785: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5786: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5787: 'closetabs','onescreen','print','downloads','cache','rightclick',
5788: 'reentry','calculator','whiteboard'],
5789: examity => ['display'],
5790: };
5791: my $extended = {
5792: proctorio => {
5793: verifyid => ['verifyidauto','verifyidlive'],
5794: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5795: tabslinks => ['notabs','linksonly'],
5796: reentry => ['noreentry','agentreentry'],
5797: calculator => ['calculatorbasic','calculatorsci'],
5798: },
5799: examity => {
5800: display => {
5801: target => ['iframe','tab','window'],
5802: width => '',
5803: height => '',
5804: linktext => '',
5805: explanation => '',
5806: },
5807: },
5808: };
5809: my $crsconf = {
5810: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5811: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5812: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5813: 'closetabs','onescreen','print','downloads','cache','rightclick',
5814: 'reentry','calculator','whiteboard'],
5815: examity => ['label','title','target','linktext','explanation','append'],
5816: };
5817: my $courseroles = ['cc','in','ta','ep','st'];
5818: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5819: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5820: }
5821:
5822: sub proctoring_titles {
5823: my ($item) = @_;
5824: my (%common_lt,%custom_lt);
5825: %common_lt = &Apache::lonlocal::texthash (
5826: 'avai' => 'Available?',
5827: 'base' => 'Basic Settings',
5828: 'requ' => 'User data required to be sent on launch',
5829: 'optu' => 'User data optionally sent on launch',
5830: 'udsl' => 'User data sent on launch',
5831: 'defa' => 'Defaults for items configurable in course',
5832: 'sigmethod' => 'Signature Method',
5833: 'key' => 'Key',
5834: 'lifetime' => 'Nonce lifetime (s)',
5835: 'secret' => 'Secret',
5836: 'icon' => 'Icon',
5837: 'fullname' => 'Full Name',
5838: 'visible' => 'Visible input',
5839: 'username' => 'username',
5840: 'user' => 'User',
5841: );
5842: if ($item eq 'proctorio') {
5843: %custom_lt = &Apache::lonlocal::texthash (
5844: 'version' => 'OAuth version',
5845: 'url' => 'API URL',
5846: 'uname:dom' => 'username-domain',
5847: );
5848: } elsif ($item eq 'examity') {
5849: %custom_lt = &Apache::lonlocal::texthash (
5850: 'version' => 'LTI Version',
5851: 'url' => 'URL',
5852: 'uname:dom' => 'username:domain',
5853: 'msgtype' => 'Message Type',
5854: 'firstname' => 'First Name',
5855: 'lastname' => 'Last Name',
5856: 'email' => 'E-mail',
5857: 'roles' => 'Role',
5858: 'crstarget' => 'Display target',
5859: 'crslabel' => 'Course label',
5860: 'crstitle' => 'Course title',
5861: 'crslinktext' => 'Link Text',
5862: 'crsexplanation' => 'Explanation',
5863: 'crsappend' => 'Provider URL',
5864: );
5865: }
5866: my %lt = (%common_lt,%custom_lt);
5867: return %lt;
5868: }
5869:
5870: sub proctoring_fieldtitles {
5871: my ($item) = @_;
5872: if ($item eq 'proctorio') {
5873: return &Apache::lonlocal::texthash (
5874: 'recordvideo' => 'Record video',
5875: 'recordaudio' => 'Record audio',
5876: 'recordscreen' => 'Record screen',
5877: 'recordwebtraffic' => 'Record web traffic',
5878: 'recordroomstart' => 'Record room scan',
5879: 'verifyvideo' => 'Verify webcam',
5880: 'verifyaudio' => 'Verify microphone',
5881: 'verifydesktop' => 'Verify desktop recording',
5882: 'verifyid' => 'Photo ID verification',
5883: 'verifysignature' => 'Require signature',
5884: 'fullscreen' => 'Fullscreen',
5885: 'clipboard' => 'Disable copy/paste',
5886: 'tabslinks' => 'New tabs/windows',
5887: 'closetabs' => 'Close other tabs',
5888: 'onescreen' => 'Limit to single screen',
5889: 'print' => 'Disable Printing',
5890: 'downloads' => 'Disable Downloads',
5891: 'cache' => 'Empty cache after exam',
5892: 'rightclick' => 'Disable right click',
5893: 'reentry' => 'Re-entry to exam',
5894: 'calculator' => 'Onscreen calculator',
5895: 'whiteboard' => 'Onscreen whiteboard',
5896: 'verifyidauto' => 'Automated verification',
5897: 'verifyidlive' => 'Live agent verification',
5898: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5899: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5900: 'fullscreensever' => 'Forced, navigation away ends exam',
5901: 'notabs' => 'Disaallowed',
5902: 'linksonly' => 'Allowed from links in exam',
5903: 'noreentry' => 'Disallowed',
5904: 'agentreentry' => 'Agent required for re-entry',
5905: 'calculatorbasic' => 'Basic',
5906: 'calculatorsci' => 'Scientific',
5907: );
5908: } elsif ($item eq 'examity') {
5909: return &Apache::lonlocal::texthash (
5910: 'target' => 'Display target',
5911: 'window' => 'Window',
5912: 'tab' => 'Tab',
5913: 'iframe' => 'iFrame',
5914: 'height' => 'Height (pixels)',
5915: 'width' => 'Width (pixels)',
5916: 'linktext' => 'Default Link Text',
5917: 'explanation' => 'Default Explanation',
5918: 'append' => 'Provider URL',
5919: );
5920: }
5921: }
5922:
5923: sub proctoring_providernames {
5924: return (
5925: proctorio => 'Proctorio',
5926: examity => 'Examity',
5927: );
5928: }
5929:
1.320 raeburn 5930: sub print_lti {
5931: my ($dom,$settings,$rowtotal) = @_;
5932: my $itemcount = 1;
5933: my $maxnum = 0;
5934: my $css_class;
5935: my %ordered;
5936: if (ref($settings) eq 'HASH') {
5937: foreach my $item (keys(%{$settings})) {
5938: if (ref($settings->{$item}) eq 'HASH') {
5939: my $num = $settings->{$item}{'order'};
5940: $ordered{$num} = $item;
5941: }
5942: }
5943: }
5944: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5945: my $datatable;
1.320 raeburn 5946: my %lt = <i_names();
5947: if (keys(%ordered)) {
5948: my @items = sort { $a <=> $b } keys(%ordered);
5949: for (my $i=0; $i<@items; $i++) {
5950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5951: my $item = $ordered{$items[$i]};
1.345 raeburn 5952: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 5953: if (ref($settings->{$item}) eq 'HASH') {
5954: $key = $settings->{$item}->{'key'};
5955: $secret = $settings->{$item}->{'secret'};
5956: $lifetime = $settings->{$item}->{'lifetime'};
5957: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5958: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 5959: $current = $settings->{$item};
5960: }
1.345 raeburn 5961: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5962: my %checkedrequser = (
5963: yes => ' checked="checked"',
5964: no => '',
5965: );
5966: if (!$requser) {
5967: $checkedrequser{'no'} = $checkedrequser{'yes'};
5968: $checkedrequser{'yes'} = '';
1.352 raeburn 5969: }
1.320 raeburn 5970: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5971: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5972: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5973: for (my $k=0; $k<=$maxnum; $k++) {
5974: my $vpos = $k+1;
5975: my $selstr;
5976: if ($k == $i) {
5977: $selstr = ' selected="selected" ';
5978: }
5979: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5980: }
5981: $datatable .= '</select>'.(' 'x2).
5982: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5983: &mt('Delete?').'</label></span></td>'.
5984: '<td colspan="2">'.
5985: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5986: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 5987: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 5988: (' 'x2).
5989: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5990: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5991: (' 'x2).
5992: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 5993: 'value="'.$lifetime.'" size="3" /></span>'.
5994: (' 'x2).
5995: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5996: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5997: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 5998: '<br /><br />'.
5999: '<span class="LC_nobreak">'.$lt{'key'}.
6000: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6001: (' 'x2).
6002: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6003: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6004: '<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>'.
6005: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 6006: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 6007: $itemcount ++;
6008: }
6009: }
6010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6011: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6012: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6013: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6014: '<select name="lti_pos_add"'.$chgstr.'>';
6015: for (my $k=0; $k<$maxnum+1; $k++) {
6016: my $vpos = $k+1;
6017: my $selstr;
6018: if ($k == $maxnum) {
6019: $selstr = ' selected="selected" ';
6020: }
6021: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6022: }
6023: $datatable .= '</select> '."\n".
1.334 raeburn 6024: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 6025: '<td colspan="2">'.
6026: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6027: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6028: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 6029: (' 'x2).
6030: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6031: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6032: (' 'x2).
1.345 raeburn 6033: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6034: (' 'x2).
6035: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6036: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6037: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6038: '<br /><br />'.
6039: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6040: (' 'x2).
6041: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6042: '<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 6043: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 6044: '</td>'."\n".
6045: '</tr>'."\n";
6046: $$rowtotal ++;
6047: return $datatable;;
6048: }
6049:
6050: sub lti_names {
6051: my %lt = &Apache::lonlocal::texthash(
6052: 'version' => 'LTI Version',
6053: 'url' => 'URL',
6054: 'key' => 'Key',
1.322 raeburn 6055: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6056: 'consumer' => 'Consumer',
1.320 raeburn 6057: 'secret' => 'Secret',
1.345 raeburn 6058: 'requser' => "User's identity sent",
1.320 raeburn 6059: 'email' => 'Email address',
6060: 'sourcedid' => 'User ID',
6061: 'other' => 'Other',
6062: 'passback' => 'Can return grades to Consumer:',
6063: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6064: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6065: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6066: );
6067: return %lt;
6068: }
6069:
6070: sub lti_options {
1.325 raeburn 6071: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6072: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6073: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6074: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
6075: $checked{'makecrs'}{'N'} = ' checked="checked"';
6076: $checked{'mapcrstype'} = {};
6077: $checked{'makeuser'} = {};
6078: $checked{'selfenroll'} = {};
6079: $checked{'crssec'} = {};
6080: $checked{'crssecsrc'} = {};
1.325 raeburn 6081: $checked{'lcauth'} = {};
1.326 raeburn 6082: $checked{'menuitem'} = {};
1.325 raeburn 6083: if ($num eq 'add') {
6084: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6085: }
1.320 raeburn 6086: my $userfieldsty = 'none';
6087: my $crsfieldsty = 'none';
6088: my $crssecfieldsty = 'none';
6089: my $secsrcfieldsty = 'none';
1.363 raeburn 6090: my $callbacksty = 'none';
1.337 raeburn 6091: my $passbacksty = 'none';
1.345 raeburn 6092: my $optionsty = 'block';
1.325 raeburn 6093: my $lcauthparm;
6094: my $lcauthparmstyle = 'display:none';
6095: my $lcauthparmtext;
1.326 raeburn 6096: my $menusty;
1.325 raeburn 6097: my $numinrow = 4;
1.326 raeburn 6098: my %menutitles = <imenu_titles();
1.320 raeburn 6099:
6100: if (ref($current) eq 'HASH') {
1.345 raeburn 6101: if (!$current->{'requser'}) {
6102: $optionsty = 'none';
6103: }
1.320 raeburn 6104: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6105: $checked{'mapuser'}{'sourcedid'} = '';
6106: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6107: $checked{'mapuser'}{'email'} = ' checked="checked"';
6108: } else {
6109: $checked{'mapuser'}{'other'} = ' checked="checked"';
6110: $userfield = $current->{'mapuser'};
6111: $userfieldsty = 'inline-block';
6112: }
6113: }
6114: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6115: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6116: if ($current->{'mapcrs'} eq 'context_id') {
6117: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6118: } else {
6119: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6120: $cidfield = $current->{'mapcrs'};
6121: $crsfieldsty = 'inline-block';
6122: }
6123: }
6124: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6125: foreach my $type (@{$current->{'mapcrstype'}}) {
6126: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6127: }
6128: }
1.345 raeburn 6129: if ($current->{'makecrs'}) {
1.320 raeburn 6130: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6131: }
1.320 raeburn 6132: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6133: foreach my $role (@{$current->{'makeuser'}}) {
6134: $checked{'makeuser'}{$role} = ' checked="checked"';
6135: }
6136: }
1.325 raeburn 6137: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6138: $checked{'lcauth'}{$1} = ' checked="checked"';
6139: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6140: $lcauthparm = $current->{'lcauthparm'};
6141: $lcauthparmstyle = 'display:table-row';
6142: if ($current->{'lcauth'} eq 'localauth') {
6143: $lcauthparmtext = &mt('Local auth argument');
6144: } else {
6145: $lcauthparmtext = &mt('Kerberos domain');
6146: }
6147: }
6148: }
1.320 raeburn 6149: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6150: foreach my $role (@{$current->{'selfenroll'}}) {
6151: $checked{'selfenroll'}{$role} = ' checked="checked"';
6152: }
6153: }
6154: if (ref($current->{'maproles'}) eq 'HASH') {
6155: %rolemaps = %{$current->{'maproles'}};
6156: }
6157: if ($current->{'section'} ne '') {
6158: $checked{'crssec'}{'Y'} = ' checked="checked"';
6159: $crssecfieldsty = 'inline-block';
6160: if ($current->{'section'} eq 'course_section_sourcedid') {
6161: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6162: } else {
6163: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6164: $crssecsrc = $current->{'section'};
6165: $secsrcfieldsty = 'inline-block';
6166: }
6167: } else {
6168: $checked{'crssec'}{'N'} = ' checked="checked"';
6169: }
1.363 raeburn 6170: if ($current->{'callback'} ne '') {
6171: $callback = $current->{'callback'};
6172: $checked{'callback'}{'Y'} = ' checked="checked"';
6173: $callbacksty = 'inline-block';
6174: } else {
6175: $checked{'callback'}{'N'} = ' checked="checked"';
6176: }
1.326 raeburn 6177: if ($current->{'topmenu'}) {
6178: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6179: } else {
6180: $checked{'topmenu'}{'N'} = ' checked="checked"';
6181: }
6182: if ($current->{'inlinemenu'}) {
6183: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6184: } else {
6185: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6186: }
6187: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6188: $menusty = 'inline-block';
6189: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6190: foreach my $item (@{$current->{'lcmenu'}}) {
6191: if (exists($menutitles{$item})) {
6192: $checked{'menuitem'}{$item} = ' checked="checked"';
6193: }
6194: }
6195: }
6196: } else {
6197: $menusty = 'none';
6198: }
1.320 raeburn 6199: } else {
6200: $checked{'makecrs'}{'N'} = ' checked="checked"';
6201: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6202: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6203: $checked{'topmenu'}{'N'} = ' checked="checked"';
6204: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6205: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6206: $menusty = 'inline-block';
1.320 raeburn 6207: }
1.325 raeburn 6208: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6209: my %coursetypetitles = &Apache::lonlocal::texthash (
6210: official => 'Official',
6211: unofficial => 'Unofficial',
6212: community => 'Community',
6213: textbook => 'Textbook',
6214: placement => 'Placement Test',
1.325 raeburn 6215: lti => 'LTI Provider',
1.320 raeburn 6216: );
1.325 raeburn 6217: my @authtypes = ('internal','krb4','krb5','localauth');
6218: my %shortauth = (
6219: internal => 'int',
6220: krb4 => 'krb4',
6221: krb5 => 'krb5',
6222: localauth => 'loc'
6223: );
6224: my %authnames = &authtype_names();
1.320 raeburn 6225: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6226: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6227: my @courseroles = ('cc','in','ta','ep','st');
6228: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6229: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6230: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6231: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6232: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6233: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6234: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 6235: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6236: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6237: foreach my $option ('sourcedid','email','other') {
6238: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6239: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6240: ($option eq 'other' ? '' : (' 'x2) );
6241: }
6242: $output .= '</span></div>'.
6243: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6244: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6245: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 6246: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 6247: foreach my $ltirole (@lticourseroles) {
6248: my ($selected,$selectnone);
6249: if ($rolemaps{$ltirole} eq '') {
6250: $selectnone = ' selected="selected"';
6251: }
6252: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6253: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6254: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6255: foreach my $role (@courseroles) {
6256: unless ($selectnone) {
6257: if ($rolemaps{$ltirole} eq $role) {
6258: $selected = ' selected="selected"';
6259: } else {
6260: $selected = '';
6261: }
6262: }
6263: $output .= '<option value="'.$role.'"'.$selected.'>'.
6264: &Apache::lonnet::plaintext($role,'Course').
6265: '</option>';
6266: }
6267: $output .= '</select></td>';
6268: }
6269: $output .= '</tr></table></fieldset>'.
1.345 raeburn 6270: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6271: foreach my $ltirole (@ltiroles) {
6272: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6273: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6274: }
6275: $output .= '</fieldset>'.
1.345 raeburn 6276: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6277: '<table>'.
6278: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6279: '</table>'.
6280: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6281: '<td class="LC_left_item">';
6282: foreach my $auth ('lti',@authtypes) {
6283: my $authtext;
6284: if ($auth eq 'lti') {
6285: $authtext = &mt('None');
6286: } else {
6287: $authtext = $authnames{$shortauth{$auth}};
6288: }
6289: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6290: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6291: $authtext.'</label></span> ';
6292: }
6293: $output .= '</td></tr>'.
6294: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6295: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6296: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6297: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6298: '</table></fieldset>'.
1.345 raeburn 6299: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6300: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6301: &mt('Unique course identifier').': ';
6302: foreach my $option ('course_offering_sourcedid','context_id','other') {
6303: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6304: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6305: ($option eq 'other' ? '' : (' 'x2) );
6306: }
1.334 raeburn 6307: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6308: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6309: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6310: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6311: foreach my $type (@coursetypes) {
6312: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6313: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6314: (' 'x2);
6315: }
6316: $output .= '</span></fieldset>'.
1.345 raeburn 6317: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6318: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6319: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6320: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6321: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6322: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6323: '</fieldset>'.
1.345 raeburn 6324: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6325: foreach my $lticrsrole (@lticourseroles) {
6326: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6327: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6328: }
6329: $output .= '</fieldset>'.
1.345 raeburn 6330: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6331: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6332: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6333: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6334: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6335: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6336: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6337: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6338: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6339: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6340: &mt('Standard field').'</label>'.(' 'x2).
6341: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6342: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6343: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6344: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6345: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6346: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6347: foreach my $extra ('roster','passback') {
1.320 raeburn 6348: my $checkedon = '';
6349: my $checkedoff = ' checked="checked"';
1.337 raeburn 6350: if ($extra eq 'passback') {
6351: $pb1p1chk = ' checked="checked"';
6352: $pb1p0chk = '';
6353: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6354: } else {
6355: $onclickpb = '';
6356: }
1.320 raeburn 6357: if (ref($current) eq 'HASH') {
6358: if (($current->{$extra})) {
6359: $checkedon = $checkedoff;
6360: $checkedoff = '';
1.337 raeburn 6361: if ($extra eq 'passback') {
6362: $passbacksty = 'inline-block';
6363: }
6364: if ($current->{'passbackformat'} eq '1.0') {
6365: $pb1p0chk = ' checked="checked"';
6366: $pb1p1chk = '';
6367: }
1.320 raeburn 6368: }
6369: }
6370: $output .= $lt{$extra}.' '.
1.337 raeburn 6371: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6372: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6373: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6374: &mt('Yes').'</label><br />';
6375: }
1.337 raeburn 6376: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6377: '<span class="LC_nobreak">'.&mt('Grade format').
6378: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6379: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6380: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6381: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
6382: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6383: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
6384: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6385: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6386: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6387: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6388: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6389: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6390: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6391: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 6392: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 6393: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6394: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6395: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6396: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 6397: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 6398: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6399: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6400: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6401: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6402: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 6403: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 6404: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6405: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6406: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6407: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6408: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6409: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6410: (' 'x2);
6411: }
1.334 raeburn 6412: $output .= '</span></div></fieldset>';
1.320 raeburn 6413: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6414: #
6415: # $output .= '</fieldset>'.
6416: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6417: return $output;
6418: }
6419:
1.326 raeburn 6420: sub ltimenu_titles {
6421: return &Apache::lonlocal::texthash(
6422: fullname => 'Full name',
6423: coursetitle => 'Course title',
6424: role => 'Role',
6425: logout => 'Logout',
6426: grades => 'Grades',
6427: );
6428: }
6429:
1.121 raeburn 6430: sub print_coursedefaults {
1.139 raeburn 6431: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6432: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6433: my $itemcount = 1;
1.192 raeburn 6434: my %choices = &Apache::lonlocal::texthash (
6435: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6436: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6437: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6438: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6439: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6440: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6441: texengine => 'Default method to display mathematics',
1.257 raeburn 6442: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6443: canclone => "People who may clone a course (besides course's owner and coordinators)",
6444: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6445: );
1.198 raeburn 6446: my %staticdefaults = (
6447: anonsurvey_threshold => 10,
6448: uploadquota => 500,
1.257 raeburn 6449: postsubmit => 60,
1.276 raeburn 6450: mysqltables => 172800,
1.198 raeburn 6451: );
1.139 raeburn 6452: if ($position eq 'top') {
1.257 raeburn 6453: %defaultchecked = (
6454: 'canuse_pdfforms' => 'off',
6455: 'uselcmath' => 'on',
6456: 'usejsme' => 'on',
1.289 raeburn 6457: 'canclone' => 'none',
1.257 raeburn 6458: );
6459: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6460: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6461: if (ref($settings) eq 'HASH') {
6462: if ($settings->{'texengine'}) {
6463: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6464: $deftex = $settings->{'texengine'};
6465: }
6466: }
6467: }
6468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6469: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6470: '<span class="LC_nobreak">'.$choices{'texengine'}.
6471: '</span></td><td class="LC_right_item">'.
6472: '<select name="texengine">'."\n";
6473: my %texoptions = (
6474: MathJax => 'MathJax',
6475: mimetex => &mt('Convert to Images'),
6476: tth => &mt('TeX to HTML'),
6477: );
6478: foreach my $renderer ('MathJax','mimetex','tth') {
6479: my $selected = '';
6480: if ($renderer eq $deftex) {
6481: $selected = ' selected="selected"';
6482: }
6483: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6484: }
6485: $mathdisp .= '</select></td></tr>'."\n";
6486: $itemcount ++;
1.139 raeburn 6487: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6488: \%choices,$itemcount);
1.314 raeburn 6489: $datatable = $mathdisp.$datatable;
1.264 raeburn 6490: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6491: $datatable .=
1.306 raeburn 6492: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6493: '<span class="LC_nobreak">'.$choices{'canclone'}.
6494: '</span></td><td class="LC_left_item">';
6495: my $currcanclone = 'none';
6496: my $onclick;
6497: my @cloneoptions = ('none','domain');
1.380 raeburn 6498: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6499: none => 'No additional course requesters',
6500: domain => "Any course requester in course's domain",
6501: instcode => 'Course requests for official courses ...',
6502: );
6503: my (%codedefaults,@code_order,@posscodes);
6504: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6505: \@code_order) eq 'ok') {
6506: if (@code_order > 0) {
6507: push(@cloneoptions,'instcode');
6508: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6509: }
6510: }
6511: if (ref($settings) eq 'HASH') {
6512: if ($settings->{'canclone'}) {
6513: if (ref($settings->{'canclone'}) eq 'HASH') {
6514: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6515: if (@code_order > 0) {
6516: $currcanclone = 'instcode';
6517: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6518: }
6519: }
6520: } elsif ($settings->{'canclone'} eq 'domain') {
6521: $currcanclone = $settings->{'canclone'};
6522: }
6523: }
1.289 raeburn 6524: }
1.264 raeburn 6525: foreach my $option (@cloneoptions) {
6526: my ($checked,$additional);
6527: if ($currcanclone eq $option) {
6528: $checked = ' checked="checked"';
6529: }
6530: if ($option eq 'instcode') {
6531: if (@code_order) {
6532: my $show = 'none';
6533: if ($checked) {
6534: $show = 'block';
6535: }
1.317 raeburn 6536: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6537: &mt('Institutional codes for new and cloned course have identical:').
6538: '<br />';
6539: foreach my $item (@code_order) {
6540: my $codechk;
6541: if ($checked) {
6542: if (grep(/^\Q$item\E$/,@posscodes)) {
6543: $codechk = ' checked="checked"';
6544: }
6545: }
6546: $additional .= '<label>'.
6547: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6548: $item.'</label>';
6549: }
6550: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6551: }
6552: }
6553: $datatable .=
6554: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6555: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6556: '</label> '.$additional.'</span><br />';
6557: }
6558: $datatable .= '</td>'.
6559: '</tr>';
6560: $itemcount ++;
1.139 raeburn 6561: } else {
6562: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6563: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6564: my $currusecredits = 0;
1.257 raeburn 6565: my $postsubmitclient = 1;
1.271 raeburn 6566: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6567: if (ref($settings) eq 'HASH') {
6568: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6569: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6570: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6571: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6572: }
6573: }
1.192 raeburn 6574: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6575: foreach my $type (@types) {
6576: next if ($type eq 'community');
6577: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6578: if ($defcredits{$type} ne '') {
6579: $currusecredits = 1;
6580: }
6581: }
6582: }
6583: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6584: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6585: $postsubmitclient = 0;
6586: foreach my $type (@types) {
6587: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6588: }
6589: } else {
6590: foreach my $type (@types) {
6591: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6592: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6593: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6594: } else {
6595: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6596: }
6597: } else {
6598: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6599: }
6600: }
6601: }
6602: } else {
6603: foreach my $type (@types) {
6604: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6605: }
6606: }
1.276 raeburn 6607: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6608: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6609: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6610: }
6611: } else {
6612: foreach my $type (@types) {
6613: $currmysql{$type} = $staticdefaults{'mysqltables'};
6614: }
6615: }
1.258 raeburn 6616: } else {
6617: foreach my $type (@types) {
6618: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6619: }
1.139 raeburn 6620: }
6621: if (!$currdefresponder) {
1.198 raeburn 6622: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6623: } elsif ($currdefresponder < 1) {
6624: $currdefresponder = 1;
6625: }
1.198 raeburn 6626: foreach my $type (@types) {
6627: if ($curruploadquota{$type} eq '') {
6628: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6629: }
6630: }
1.139 raeburn 6631: $datatable .=
1.192 raeburn 6632: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6633: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6634: '</span></td>'.
6635: '<td class="LC_right_item"><span class="LC_nobreak">'.
6636: '<input type="text" name="anonsurvey_threshold"'.
6637: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6638: '</td></tr>'."\n";
6639: $itemcount ++;
6640: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6641: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6642: $choices{'uploadquota'}.
6643: '</span></td>'.
1.306 raeburn 6644: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6645: '<table><tr>';
1.198 raeburn 6646: foreach my $type (@types) {
1.306 raeburn 6647: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6648: '<input type="text" name="uploadquota_'.$type.'"'.
6649: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6650: }
6651: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6652: $itemcount ++;
1.236 raeburn 6653: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6654: my $display = 'none';
1.192 raeburn 6655: if ($currusecredits) {
6656: $display = 'block';
6657: }
6658: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6659: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6660: foreach my $type (@types) {
6661: next if ($type eq 'community');
1.306 raeburn 6662: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6663: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6664: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6665: }
6666: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6667: %defaultchecked = ('coursecredits' => 'off');
6668: @toggles = ('coursecredits');
6669: my $current = {
6670: 'coursecredits' => $currusecredits,
6671: };
6672: (my $table,$itemcount) =
6673: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6674: \%choices,$itemcount,$onclick,$additional,'left');
6675: $datatable .= $table;
6676: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6677: my $display = 'none';
6678: if ($postsubmitclient) {
6679: $display = 'block';
6680: }
6681: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6682: &mt('Number of seconds submit is disabled').'<br />'.
6683: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6684: '<table><tr>';
1.257 raeburn 6685: foreach my $type (@types) {
1.306 raeburn 6686: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6687: '<input type="text" name="'.$type.'_timeout" value="'.
6688: $deftimeout{$type}.'" size="5" /></td>';
6689: }
6690: $additional .= '</tr></table></div>'."\n";
6691: %defaultchecked = ('postsubmit' => 'on');
6692: @toggles = ('postsubmit');
1.280 raeburn 6693: $current = {
6694: 'postsubmit' => $postsubmitclient,
6695: };
1.257 raeburn 6696: ($table,$itemcount) =
6697: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6698: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6699: $datatable .= $table;
1.276 raeburn 6700: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6701: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6702: $choices{'mysqltables'}.
6703: '</span></td>'.
1.306 raeburn 6704: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6705: '<table><tr>';
6706: foreach my $type (@types) {
1.306 raeburn 6707: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6708: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6709: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6710: }
6711: $datatable .= '</tr></table></td></tr>'."\n";
6712: $itemcount ++;
6713:
1.139 raeburn 6714: }
1.192 raeburn 6715: $$rowtotal += $itemcount;
1.121 raeburn 6716: return $datatable;
1.118 jms 6717: }
6718:
1.231 raeburn 6719: sub print_selfenrollment {
6720: my ($position,$dom,$settings,$rowtotal) = @_;
6721: my ($css_class,$datatable);
6722: my $itemcount = 1;
1.271 raeburn 6723: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6724: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6725: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6726: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6727: my @rows;
6728: my $key;
6729: if ($position eq 'top') {
6730: $key = 'admin';
6731: if (ref($rowsref) eq 'ARRAY') {
6732: @rows = @{$rowsref};
6733: }
6734: } elsif ($position eq 'middle') {
6735: $key = 'default';
6736: @rows = ('types','registered','approval','limit');
6737: }
6738: foreach my $row (@rows) {
6739: if (defined($titlesref->{$row})) {
6740: $itemcount ++;
6741: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6742: $datatable .= '<tr'.$css_class.'>'.
6743: '<td>'.$titlesref->{$row}.'</td>'.
6744: '<td class="LC_left_item">'.
6745: '<table><tr>';
6746: my (%current,%currentcap);
6747: if (ref($settings) eq 'HASH') {
6748: if (ref($settings->{$key}) eq 'HASH') {
6749: foreach my $type (@types) {
6750: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6751: $current{$type} = $settings->{$key}->{$type}->{$row};
6752: }
6753: if (($row eq 'limit') && ($key eq 'default')) {
6754: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6755: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6756: }
6757: }
6758: }
6759: }
6760: }
6761: my %roles = (
6762: '0' => &Apache::lonnet::plaintext('dc'),
6763: );
6764:
6765: foreach my $type (@types) {
6766: unless (($row eq 'registered') && ($key eq 'default')) {
6767: $datatable .= '<th>'.&mt($type).'</th>';
6768: }
6769: }
6770: unless (($row eq 'registered') && ($key eq 'default')) {
6771: $datatable .= '</tr><tr>';
6772: }
6773: foreach my $type (@types) {
6774: if ($type eq 'community') {
6775: $roles{'1'} = &mt('Community personnel');
6776: } else {
6777: $roles{'1'} = &mt('Course personnel');
6778: }
6779: $datatable .= '<td style="vertical-align: top">';
6780: if ($position eq 'top') {
6781: my %checked;
6782: if ($current{$type} eq '0') {
6783: $checked{'0'} = ' checked="checked"';
6784: } else {
6785: $checked{'1'} = ' checked="checked"';
6786: }
6787: foreach my $role ('1','0') {
6788: $datatable .= '<span class="LC_nobreak"><label>'.
6789: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6790: 'value="'.$role.'"'.$checked{$role}.' />'.
6791: $roles{$role}.'</label></span> ';
6792: }
6793: } else {
6794: if ($row eq 'types') {
6795: my %checked;
6796: if ($current{$type} =~ /^(all|dom)$/) {
6797: $checked{$1} = ' checked="checked"';
6798: } else {
6799: $checked{''} = ' checked="checked"';
6800: }
6801: foreach my $val ('','dom','all') {
6802: $datatable .= '<span class="LC_nobreak"><label>'.
6803: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6804: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6805: }
6806: } elsif ($row eq 'registered') {
6807: my %checked;
6808: if ($current{$type} eq '1') {
6809: $checked{'1'} = ' checked="checked"';
6810: } else {
6811: $checked{'0'} = ' checked="checked"';
6812: }
6813: foreach my $val ('0','1') {
6814: $datatable .= '<span class="LC_nobreak"><label>'.
6815: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6816: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6817: }
6818: } elsif ($row eq 'approval') {
6819: my %checked;
6820: if ($current{$type} =~ /^([12])$/) {
6821: $checked{$1} = ' checked="checked"';
6822: } else {
6823: $checked{'0'} = ' checked="checked"';
6824: }
6825: for my $val (0..2) {
6826: $datatable .= '<span class="LC_nobreak"><label>'.
6827: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6828: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6829: }
6830: } elsif ($row eq 'limit') {
6831: my %checked;
6832: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6833: $checked{$1} = ' checked="checked"';
6834: } else {
6835: $checked{'none'} = ' checked="checked"';
6836: }
6837: my $cap;
6838: if ($currentcap{$type} =~ /^\d+$/) {
6839: $cap = $currentcap{$type};
6840: }
6841: foreach my $val ('none','allstudents','selfenrolled') {
6842: $datatable .= '<span class="LC_nobreak"><label>'.
6843: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6844: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6845: }
6846: $datatable .= '<br />'.
6847: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6848: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6849: '</span>';
6850: }
6851: }
6852: $datatable .= '</td>';
6853: }
6854: $datatable .= '</tr>';
6855: }
6856: $datatable .= '</table></td></tr>';
6857: }
6858: } elsif ($position eq 'bottom') {
1.235 raeburn 6859: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6860: }
6861: $$rowtotal += $itemcount;
6862: return $datatable;
6863: }
6864:
6865: sub print_validation_rows {
6866: my ($caller,$dom,$settings,$rowtotal) = @_;
6867: my ($itemsref,$namesref,$fieldsref);
6868: if ($caller eq 'selfenroll') {
6869: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6870: } elsif ($caller eq 'requestcourses') {
6871: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6872: }
6873: my %currvalidation;
6874: if (ref($settings) eq 'HASH') {
6875: if (ref($settings->{'validation'}) eq 'HASH') {
6876: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6877: }
1.235 raeburn 6878: }
6879: my $datatable;
6880: my $itemcount = 0;
6881: foreach my $item (@{$itemsref}) {
6882: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6883: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6884: $namesref->{$item}.
6885: '</span></td>'.
6886: '<td class="LC_left_item">';
6887: if (($item eq 'url') || ($item eq 'button')) {
6888: $datatable .= '<span class="LC_nobreak">'.
6889: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6890: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6891: } elsif ($item eq 'fields') {
6892: my @currfields;
6893: if (ref($currvalidation{$item}) eq 'ARRAY') {
6894: @currfields = @{$currvalidation{$item}};
6895: }
6896: foreach my $field (@{$fieldsref}) {
6897: my $check = '';
6898: if (grep(/^\Q$field\E$/,@currfields)) {
6899: $check = ' checked="checked"';
6900: }
6901: $datatable .= '<span class="LC_nobreak"><label>'.
6902: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6903: ' value="'.$field.'"'.$check.' />'.$field.
6904: '</label></span> ';
6905: }
6906: } elsif ($item eq 'markup') {
1.334 raeburn 6907: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6908: $currvalidation{$item}.
1.231 raeburn 6909: '</textarea>';
1.235 raeburn 6910: }
6911: $datatable .= '</td></tr>'."\n";
6912: if (ref($rowtotal)) {
1.231 raeburn 6913: $itemcount ++;
6914: }
6915: }
1.235 raeburn 6916: if ($caller eq 'requestcourses') {
6917: my %currhash;
1.248 raeburn 6918: if (ref($settings) eq 'HASH') {
6919: if (ref($settings->{'validation'}) eq 'HASH') {
6920: if ($settings->{'validation'}{'dc'} ne '') {
6921: $currhash{$settings->{'validation'}{'dc'}} = 1;
6922: }
1.235 raeburn 6923: }
6924: }
6925: my $numinrow = 2;
6926: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6927: 'validationdc',%currhash);
1.247 raeburn 6928: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6929: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6930: if ($numdc > 1) {
1.247 raeburn 6931: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6932: } else {
1.247 raeburn 6933: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6934: }
1.247 raeburn 6935: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 6936: $itemcount ++;
6937: }
6938: if (ref($rowtotal)) {
6939: $$rowtotal += $itemcount;
6940: }
1.231 raeburn 6941: return $datatable;
6942: }
6943:
1.357 raeburn 6944: sub print_privacy {
6945: my ($position,$dom,$settings,$rowtotal) = @_;
6946: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
6947: my $itemcount = 0;
6948: unless ($position eq 'top') {
6949: @items = ('domain','author','course','community');
6950: %names = &Apache::lonlocal::texthash (
6951: domain => 'Assigned domain role(s)',
6952: author => 'Assigned co-author role(s)',
6953: course => 'Assigned course role(s)',
6954: community => 'Assigned community role',
6955: );
6956: $numinrow = 4;
6957: ($othertitle,$usertypes,$types) =
6958: &Apache::loncommon::sorted_inst_types($dom);
6959: }
6960: if (($position eq 'top') || ($position eq 'middle')) {
6961: my (%by_ip,%by_location,@intdoms,@instdoms);
6962: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6963: if ($position eq 'top') {
6964: my %curr;
6965: my @options = ('none','user','domain','auto');
6966: my %titles = &Apache::lonlocal::texthash (
6967: none => 'Not allowed',
6968: user => 'User authorizes',
6969: domain => 'DC authorizes',
6970: auto => 'Unrestricted',
6971: instdom => 'Other domain shares institution/provider',
6972: extdom => 'Other domain has different institution/provider',
6973: );
6974: my %names = &Apache::lonlocal::texthash (
6975: domain => 'Domain role',
6976: author => 'Co-author role',
6977: course => 'Course role',
6978: community => 'Community role',
6979: );
6980: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6981: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6982: foreach my $domtype ('instdom','extdom') {
6983: my (%checked,$skip);
6984: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6985: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
6986: '<td class="LC_left_item">';
6987: if ($domtype eq 'instdom') {
6988: unless (@instdoms > 1) {
6989: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
6990: $skip = 1;
6991: }
6992: } elsif ($domtype eq 'extdom') {
6993: if (keys(%by_location) == 0) {
6994: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
6995: $skip = 1;
6996: }
6997: }
6998: unless ($skip) {
6999: foreach my $roletype ('domain','author','course','community') {
7000: $checked{'auto'} = ' checked="checked"';
7001: if (ref($settings) eq 'HASH') {
7002: if (ref($settings->{approval}) eq 'HASH') {
7003: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7004: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7005: $checked{$1} = ' checked="checked"';
7006: $checked{'auto'} = '';
7007: }
7008: }
7009: }
7010: }
7011: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7012: foreach my $option (@options) {
7013: $datatable .= '<span class="LC_nobreak"><label>'.
7014: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7015: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7016: '</label></span> ';
7017: }
7018: $datatable .= '</fieldset>';
7019: }
7020: }
7021: $datatable .= '</td></tr>';
7022: $itemcount ++;
7023: }
7024: } elsif ($position eq 'middle') {
7025: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7026: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7027: foreach my $item (@{$types}) {
7028: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7029: $numinrow,$itemcount,'','','','','',
7030: '',$usertypes->{$item});
7031: $itemcount ++;
7032: }
7033: }
7034: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7035: $numinrow,$itemcount,'','','','','',
7036: '',$othertitle);
7037: $itemcount ++;
7038: } else {
1.360 raeburn 7039: my (@insttypes,%insttitles);
7040: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7041: @insttypes = @{$types};
7042: %insttitles = %{$usertypes};
7043: }
7044: foreach my $item (@insttypes,'default') {
7045: my $title;
7046: if ($item eq 'default') {
7047: $title = $othertitle;
7048: } else {
7049: $title = $insttitles{$item};
7050: }
7051: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7052: $datatable .= '<tr'.$css_class.'>'.
7053: '<td class="LC_left_item">'.$title.'</td>'.
7054: '<td class="LC_left_item">'.
7055: &mt('Nothing to set here, as there are no other domains').
7056: '</td></tr>';
7057: $itemcount ++;
7058: }
1.357 raeburn 7059: }
7060: }
7061: } else {
7062: my $prefix;
7063: if ($position eq 'lower') {
7064: $prefix = 'priv';
7065: } else {
7066: $prefix = 'unpriv';
7067: }
7068: foreach my $item (@items) {
7069: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7070: $numinrow,$itemcount,'','','','','',
7071: '',$names{$item});
7072: $itemcount ++;
7073: }
7074: }
7075: if (ref($rowtotal)) {
7076: $$rowtotal += $itemcount;
7077: }
7078: return $datatable;
7079: }
7080:
1.354 raeburn 7081: sub print_passwords {
7082: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7083: my ($datatable,$css_class);
7084: my $itemcount = 0;
7085: my %titles = &Apache::lonlocal::texthash (
7086: captcha => '"Forgot Password" CAPTCHA validation',
7087: link => 'Reset link expiration (hours)',
7088: case => 'Case-sensitive usernames/e-mail',
7089: prelink => 'Information required (form 1)',
7090: postlink => 'Information required (form 2)',
7091: emailsrc => 'LON-CAPA e-mail address type(s)',
7092: customtext => 'Domain specific text (HTML)',
7093: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7094: intauth_check => 'Check bcrypt cost if authenticated',
7095: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7096: permanent => 'Permanent e-mail address',
7097: critical => 'Critical notification address',
7098: notify => 'Notification address',
7099: min => 'Minimum password length',
7100: max => 'Maximum password length',
7101: chars => 'Required characters',
7102: expire => 'Password expiration (days)',
1.356 raeburn 7103: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7104: );
7105: if ($position eq 'top') {
7106: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7107: my $shownlinklife = 2;
7108: my $prelink = 'both';
7109: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7110: if (ref($settings) eq 'HASH') {
7111: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7112: $shownlinklife = $settings->{resetlink};
7113: }
7114: if (ref($settings->{resetcase}) eq 'ARRAY') {
7115: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7116: }
7117: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7118: $prelink = $settings->{resetprelink};
7119: }
7120: if (ref($settings->{resetpostlink}) eq 'HASH') {
7121: %postlink = %{$settings->{resetpostlink}};
7122: }
7123: if (ref($settings->{resetemail}) eq 'ARRAY') {
7124: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7125: }
7126: if ($settings->{resetremove}) {
7127: $nostdtext = 1;
7128: }
7129: if ($settings->{resetcustom}) {
7130: $customurl = $settings->{resetcustom};
7131: }
7132: } else {
7133: if (ref($types) eq 'ARRAY') {
7134: foreach my $item (@{$types}) {
7135: $casesens{$item} = 1;
7136: $postlink{$item} = ['username','email'];
7137: }
7138: }
7139: $casesens{'default'} = 1;
7140: $postlink{'default'} = ['username','email'];
7141: $prelink = 'both';
7142: %emailsrc = (
7143: permanent => 1,
7144: critical => 1,
7145: notify => 1,
7146: );
7147: }
7148: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7149: $itemcount ++;
7150: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7151: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7152: '<td class="LC_left_item">'.
7153: '<input type="textbox" value="'.$shownlinklife.'" '.
7154: 'name="passwords_link" size="3" /></td></tr>';
7155: $itemcount ++;
7156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7157: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7158: '<td class="LC_left_item">';
7159: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7160: foreach my $item (@{$types}) {
7161: my $checkedcase;
7162: if ($casesens{$item}) {
7163: $checkedcase = ' checked="checked"';
7164: }
7165: $datatable .= '<span class="LC_nobreak"><label>'.
7166: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7167: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7168: '</span> ';
1.354 raeburn 7169: }
7170: }
7171: my $checkedcase;
7172: if ($casesens{'default'}) {
7173: $checkedcase = ' checked="checked"';
7174: }
7175: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7176: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7177: $othertitle.'</label></span></td>';
7178: $itemcount ++;
7179: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7180: my %checkedpre = (
7181: both => ' checked="checked"',
7182: either => '',
7183: );
7184: if ($prelink eq 'either') {
7185: $checkedpre{either} = ' checked="checked"';
7186: $checkedpre{both} = '';
7187: }
7188: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7189: '<td class="LC_left_item"><span class="LC_nobreak">'.
7190: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7191: &mt('Both username and e-mail address').'</label></span> '.
7192: '<span class="LC_nobreak"><label>'.
7193: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7194: &mt('Either username or e-mail address').'</label></span></td></tr>';
7195: $itemcount ++;
7196: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7197: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7198: '<td class="LC_left_item">';
7199: my %postlinked;
7200: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7201: foreach my $item (@{$types}) {
7202: undef(%postlinked);
7203: $datatable .= '<fieldset style="display: inline-block;">'.
7204: '<legend>'.$usertypes->{$item}.'</legend>';
7205: if (ref($postlink{$item}) eq 'ARRAY') {
7206: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7207: }
7208: foreach my $field ('email','username') {
7209: my $checked;
7210: if ($postlinked{$field}) {
7211: $checked = ' checked="checked"';
7212: }
7213: $datatable .= '<span class="LC_nobreak"><label>'.
7214: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7215: $field.'"'.$checked.' />'.$field.'</label>'.
7216: '<span> ';
7217: }
7218: $datatable .= '</fieldset>';
7219: }
7220: }
7221: if (ref($postlink{'default'}) eq 'ARRAY') {
7222: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7223: }
7224: $datatable .= '<fieldset style="display: inline-block;">'.
7225: '<legend>'.$othertitle.'</legend>';
7226: foreach my $field ('email','username') {
7227: my $checked;
7228: if ($postlinked{$field}) {
7229: $checked = ' checked="checked"';
7230: }
7231: $datatable .= '<span class="LC_nobreak"><label>'.
7232: '<input type="checkbox" name="passwords_postlink_default" value="'.
7233: $field.'"'.$checked.' />'.$field.'</label>'.
7234: '<span> ';
7235: }
7236: $datatable .= '</fieldset></td></tr>';
7237: $itemcount ++;
7238: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7239: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7240: '<td class="LC_left_item">';
7241: foreach my $type ('permanent','critical','notify') {
7242: my $checkedemail;
7243: if ($emailsrc{$type}) {
7244: $checkedemail = ' checked="checked"';
7245: }
7246: $datatable .= '<span class="LC_nobreak"><label>'.
7247: '<input type="checkbox" name="passwords_emailsrc" value="'.
7248: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7249: '<span> ';
7250: }
7251: $datatable .= '</td></tr>';
7252: $itemcount ++;
7253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7254: my $switchserver = &check_switchserver($dom,$confname);
7255: my ($showstd,$noshowstd);
7256: if ($nostdtext) {
7257: $noshowstd = ' checked="checked"';
7258: } else {
7259: $showstd = ' checked="checked"';
7260: }
7261: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7262: '<td class="LC_left_item"><span class="LC_nobreak">'.
7263: &mt('Retain standard text:').
7264: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7265: &mt('Yes').'</label>'.' '.
7266: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7267: &mt('No').'</label></span><br />'.
7268: '<span class="LC_fontsize_small">'.
7269: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7270: &mt('Include custom text:');
7271: if ($customurl) {
1.369 raeburn 7272: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7273: undef,undef,undef,undef,'background-color:#ffffff');
7274: $datatable .= '<span class="LC_nobreak"> '.$link.
7275: '<label><input type="checkbox" name="passwords_custom_del"'.
7276: ' value="1" />'.&mt('Delete?').'</label></span>'.
7277: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7278: }
7279: if ($switchserver) {
7280: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7281: } else {
7282: $datatable .='<span class="LC_nobreak"> '.
7283: '<input type="file" name="passwords_customfile" /></span>';
7284: }
7285: $datatable .= '</td></tr>';
7286: } elsif ($position eq 'middle') {
7287: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7288: my @items = ('intauth_cost','intauth_check','intauth_switch');
7289: my %defaults;
7290: if (ref($domconf{'defaults'}) eq 'HASH') {
7291: %defaults = %{$domconf{'defaults'}};
7292: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7293: $defaults{'intauth_cost'} = 10;
7294: }
7295: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7296: $defaults{'intauth_check'} = 0;
7297: }
7298: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7299: $defaults{'intauth_switch'} = 0;
7300: }
7301: } else {
7302: %defaults = (
7303: 'intauth_cost' => 10,
7304: 'intauth_check' => 0,
7305: 'intauth_switch' => 0,
7306: );
7307: }
7308: foreach my $item (@items) {
7309: if ($itemcount%2) {
7310: $css_class = '';
7311: } else {
7312: $css_class = ' class="LC_odd_row" ';
7313: }
7314: $datatable .= '<tr'.$css_class.'>'.
7315: '<td><span class="LC_nobreak">'.$titles{$item}.
7316: '</span></td><td class="LC_left_item" colspan="3">';
7317: if ($item eq 'intauth_switch') {
7318: my @options = (0,1,2);
7319: my %optiondesc = &Apache::lonlocal::texthash (
7320: 0 => 'No',
7321: 1 => 'Yes',
7322: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7323: );
7324: $datatable .= '<table width="100%">';
7325: foreach my $option (@options) {
7326: my $checked = ' ';
7327: if ($defaults{$item} eq $option) {
7328: $checked = ' checked="checked"';
7329: }
7330: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7331: '<label><input type="radio" name="'.$item.
7332: '" value="'.$option.'"'.$checked.' />'.
7333: $optiondesc{$option}.'</label></span></td></tr>';
7334: }
7335: $datatable .= '</table>';
7336: } elsif ($item eq 'intauth_check') {
7337: my @options = (0,1,2);
7338: my %optiondesc = &Apache::lonlocal::texthash (
7339: 0 => 'No',
7340: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7341: 2 => 'Yes, disallow login if stored cost is less than domain default',
7342: );
7343: $datatable .= '<table width="100%">';
7344: foreach my $option (@options) {
7345: my $checked = ' ';
7346: my $onclick;
7347: if ($defaults{$item} eq $option) {
7348: $checked = ' checked="checked"';
7349: }
7350: if ($option == 2) {
7351: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7352: }
7353: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7354: '<label><input type="radio" name="'.$item.
7355: '" value="'.$option.'"'.$checked.$onclick.' />'.
7356: $optiondesc{$option}.'</label></span></td></tr>';
7357: }
7358: $datatable .= '</table>';
7359: } else {
7360: $datatable .= '<input type="text" name="'.$item.'" value="'.
7361: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7362: }
7363: $datatable .= '</td></tr>';
7364: $itemcount ++;
7365: }
7366: } elsif ($position eq 'lower') {
1.356 raeburn 7367: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7368: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7369: if (ref($settings) eq 'HASH') {
7370: if ($settings->{min}) {
7371: $min = $settings->{min};
7372: }
7373: if ($settings->{max}) {
7374: $max = $settings->{max};
7375: }
7376: if (ref($settings->{chars}) eq 'ARRAY') {
7377: map { $chars{$_} = 1; } (@{$settings->{chars}});
7378: }
7379: if ($settings->{expire}) {
7380: $expire = $settings->{expire};
7381: }
1.358 raeburn 7382: if ($settings->{numsaved}) {
7383: $numsaved = $settings->{numsaved};
1.356 raeburn 7384: }
1.354 raeburn 7385: }
7386: my %rulenames = &Apache::lonlocal::texthash(
7387: uc => 'At least one upper case letter',
7388: lc => 'At least one lower case letter',
7389: num => 'At least one number',
7390: spec => 'At least one non-alphanumeric',
7391: );
7392: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7393: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7394: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7395: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7396: 'onblur="javascript:warnIntPass(this);" />'.
7397: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7398: '</span></td></tr>';
7399: $itemcount ++;
7400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7401: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7402: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7403: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7404: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7405: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7406: '</span></td></tr>';
7407: $itemcount ++;
7408: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7409: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7410: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7411: '</span></td>';
7412: my $numinrow = 2;
7413: my @possrules = ('uc','lc','num','spec');
7414: $datatable .= '<td class="LC_left_item"><table>';
7415: for (my $i=0; $i<@possrules; $i++) {
7416: my ($rem,$checked);
7417: if ($chars{$possrules[$i]}) {
7418: $checked = ' checked="checked"';
7419: }
7420: $rem = $i%($numinrow);
7421: if ($rem == 0) {
7422: if ($i > 0) {
7423: $datatable .= '</tr>';
7424: }
7425: $datatable .= '<tr>';
7426: }
7427: $datatable .= '<td><span class="LC_nobreak"><label>'.
7428: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7429: $rulenames{$possrules[$i]}.'</label></span></td>';
7430: }
7431: my $rem = @possrules%($numinrow);
7432: my $colsleft = $numinrow - $rem;
7433: if ($colsleft > 1 ) {
7434: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7435: ' </td>';
7436: } elsif ($colsleft == 1) {
7437: $datatable .= '<td class="LC_left_item"> </td>';
7438: }
7439: $datatable .='</table></td></tr>';
7440: $itemcount ++;
7441: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7442: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7443: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7444: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7445: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7446: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7447: '</span></td></tr>';
1.356 raeburn 7448: $itemcount ++;
7449: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7450: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7451: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7452: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7453: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7454: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7455: '</span></td></tr>';
1.354 raeburn 7456: } else {
1.359 raeburn 7457: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7458: my %ownerchg = (
7459: by => {},
7460: for => {},
7461: );
7462: my %ownertitles = &Apache::lonlocal::texthash (
7463: by => 'Course owner status(es) allowed',
7464: for => 'Student status(es) allowed',
7465: );
1.354 raeburn 7466: if (ref($settings) eq 'HASH') {
1.359 raeburn 7467: if (ref($settings->{crsownerchg}) eq 'HASH') {
7468: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7469: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7470: }
7471: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7472: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7473: }
1.354 raeburn 7474: }
7475: }
7476: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7477: $datatable .= '<tr '.$css_class.'>'.
7478: '<td>'.
7479: &mt('Requirements').'<ul>'.
1.359 raeburn 7480: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7481: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7482: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7483: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7484: '</ul>'.
7485: '</td>'.
1.359 raeburn 7486: '<td class="LC_left_item">';
7487: foreach my $item ('by','for') {
7488: $datatable .= '<fieldset style="display: inline-block;">'.
7489: '<legend>'.$ownertitles{$item}.'</legend>';
7490: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7491: foreach my $type (@{$types}) {
7492: my $checked;
7493: if ($ownerchg{$item}{$type}) {
7494: $checked = ' checked="checked"';
7495: }
7496: $datatable .= '<span class="LC_nobreak"><label>'.
7497: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7498: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7499: '</span> ';
1.359 raeburn 7500: }
7501: }
7502: my $checked;
7503: if ($ownerchg{$item}{'default'}) {
7504: $checked = ' checked="checked"';
7505: }
7506: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7507: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7508: $othertitle.'</label></span></fieldset>';
7509: }
7510: $datatable .= '</td></tr>';
1.354 raeburn 7511: }
7512: return $datatable;
7513: }
7514:
1.373 raeburn 7515: sub print_wafproxy {
7516: my ($position,$dom,$settings,$rowtotal) = @_;
7517: my $css_class;
7518: my $itemcount = 0;
7519: my $datatable;
7520: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7521: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7522: my %lt = &wafproxy_titles();
1.373 raeburn 7523: foreach my $server (sort(keys(%servers))) {
7524: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7525: next if ($serverhome eq '');
1.373 raeburn 7526: my $serverdom;
7527: if ($serverhome ne $server) {
7528: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7529: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7530: $othercontrol{$server} = $serverdom;
7531: }
1.373 raeburn 7532: } else {
7533: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7534: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7535: if ($serverdom ne $dom) {
7536: $othercontrol{$server} = $serverdom;
7537: } else {
7538: $setdom = 1;
7539: if (ref($settings) eq 'HASH') {
7540: if (ref($settings->{'alias'}) eq 'HASH') {
7541: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7542: if ($aliases{$dom} ne '') {
7543: $showdom = 1;
7544: }
1.373 raeburn 7545: }
1.388 raeburn 7546: if (ref($settings->{'saml'}) eq 'HASH') {
7547: $saml{$dom} = $settings->{'saml'};
7548: }
1.373 raeburn 7549: }
7550: }
7551: }
7552: }
1.381 raeburn 7553: if ($setdom) {
7554: %{$values{$dom}} = ();
7555: if (ref($settings) eq 'HASH') {
7556: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7557: $values{$dom}{$item} = $settings->{$item};
7558: }
7559: }
7560: }
1.373 raeburn 7561: if (keys(%othercontrol)) {
7562: %otherdoms = reverse(%othercontrol);
7563: foreach my $domain (keys(%otherdoms)) {
7564: %{$values{$domain}} = ();
7565: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 7566: if (ref($config{'wafproxy'}) eq 'HASH') {
7567: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 7568: if (exists($config{'wafproxy'}{'saml'})) {
7569: $saml{$domain} = $config{'wafproxy'}{'saml'};
7570: }
1.383 raeburn 7571: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7572: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 7573: }
7574: }
7575: }
7576: }
7577: if ($position eq 'top') {
7578: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7579: my %aliasinfo;
1.373 raeburn 7580: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7581: $itemcount ++;
7582: my $dom_in_effect;
7583: my $aliasrows = '<tr>'.
1.383 raeburn 7584: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7585: &mt('Hostname').': '.
7586: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 7587: if ($othercontrol{$server}) {
1.381 raeburn 7588: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 7589: my ($current,$forsaml);
1.383 raeburn 7590: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7591: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 7592: }
1.388 raeburn 7593: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7594: if ($saml{$dom_in_effect}{$server}) {
7595: $forsaml = 1;
7596: }
7597: }
1.383 raeburn 7598: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7599: &mt('Alias').': ';
1.373 raeburn 7600: if ($current) {
1.381 raeburn 7601: $aliasrows .= $current;
1.388 raeburn 7602: if ($forsaml) {
7603: $aliasrows .= ' ('.&mt('also for Shibboleth').')';
7604: }
1.373 raeburn 7605: } else {
1.383 raeburn 7606: $aliasrows .= &mt('None');
1.373 raeburn 7607: }
1.383 raeburn 7608: $aliasrows .= ' <span class="LC_small">('.
7609: &mt('controlled by domain: [_1]',
7610: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 7611: } else {
1.381 raeburn 7612: $dom_in_effect = $dom;
1.388 raeburn 7613: my ($current,$samlon,$samloff);
7614: $samloff = ' checked="checked"';
1.373 raeburn 7615: if (ref($aliases{$dom}) eq 'HASH') {
7616: if ($aliases{$dom}{$server}) {
7617: $current = $aliases{$dom}{$server};
7618: }
7619: }
1.388 raeburn 7620: if (ref($saml{$dom}) eq 'HASH') {
7621: if ($saml{$dom}{$server}) {
7622: $samlon = $samloff;
7623: undef($samloff);
7624: }
7625: }
1.383 raeburn 7626: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7627: &mt('Alias').': '.
1.381 raeburn 7628: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 7629: 'value="'.$current.'" size="30" />'.
7630: (' 'x2).'<span class="LC_nobreak">'.
7631: &mt('Alias used for Shibboleth').': <label>'.
7632: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7633: &mt('No').'</label> <label>'.
7634: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7635: &mt('Yes').'</label></span>'.
7636: '</td>';
1.381 raeburn 7637: }
7638: $aliasrows .= '</tr>';
7639: $aliasinfo{$dom_in_effect} .= $aliasrows;
7640: }
7641: if ($aliasinfo{$dom}) {
7642: my ($onclick,$wafon,$wafoff,$showtable);
7643: $onclick = ' onclick="javascript:toggleWAF();"';
7644: $wafoff = ' checked="checked"';
7645: $showtable = ' style="display:none";';
7646: if ($showdom) {
7647: $wafon = $wafoff;
7648: $wafoff = '';
7649: $showtable = ' style="display:inline;"';
7650: }
7651: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7652: $datatable = '<tr'.$css_class.'>'.
7653: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7654: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7655: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7656: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7657: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7658: &mt('No').'</label></span></td>'.
7659: '<td class="LC_left_item">'.
7660: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7661: '</table></td></tr>';
7662: $itemcount++;
7663: }
1.383 raeburn 7664: if (keys(%otherdoms)) {
7665: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 7666: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 7667: $datatable .= '<tr'.$css_class.'>'.
7668: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7669: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7670: '</table></td></tr>';
1.381 raeburn 7671: $itemcount++;
1.373 raeburn 7672: }
7673: }
7674: } else {
1.383 raeburn 7675: my %ip_methods = &remoteip_methods();
1.373 raeburn 7676: if ($setdom) {
7677: $itemcount ++;
7678: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 7679: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 7680: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 7681: $wafstyle = ' style="display:none;"';
7682: $nowafstyle = ' style="display:table-row;"';
7683: $currwafdisplay = ' style="display: none"';
7684: $wafrangestyle = ' style="display: none"';
7685: $curr_remotip = 'n';
1.382 raeburn 7686: $ssltossl = ' checked="checked"';
1.381 raeburn 7687: if ($showdom) {
7688: $wafstyle = ' style="display:table-row;"';
7689: $nowafstyle = ' style="display:none;"';
7690: if (keys(%{$values{$dom}})) {
7691: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7692: $curr_remotip = $values{$dom}{remoteip};
7693: }
7694: if ($curr_remotip eq 'h') {
7695: $currwafdisplay = ' style="display:table-row"';
7696: $wafrangestyle = ' style="display:inline-block;"';
7697: }
1.382 raeburn 7698: if ($values{$dom}{'sslopt'}) {
7699: $alltossl = ' checked="checked"';
7700: $ssltossl = '';
7701: }
1.381 raeburn 7702: }
7703: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7704: $vpndircheck = ' checked="checked"';
7705: $currwafvpn = ' style="display:table-row;"';
7706: $wafrangestyle = ' style="display:inline-block;"';
7707: } else {
7708: $vpnaliascheck = ' checked="checked"';
7709: $currwafvpn = ' style="display:none;"';
7710: }
7711: }
7712: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7713: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7714: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7715: '</tr>'.
7716: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 7717: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 7718: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7719: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'</div></td>'.
7720: '<td class="LC_left_item"><table>'.
7721: '<tr>'.
7722: '<td valign="top">'.$lt{'remoteip'}.': '.
7723: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7724: foreach my $option ('m','h','n') {
7725: my $sel;
7726: if ($option eq $curr_remotip) {
7727: $sel = ' selected="selected"';
7728: }
7729: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7730: $ip_methods{$option}.'</option>';
7731: }
7732: $datatable .= '</select></td></tr>'."\n".
7733: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7734: $lt{'ipheader'}.': '.
7735: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7736: 'name="wafproxy_ipheader" />'.
7737: '</td></tr>'."\n".
7738: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 7739: $lt{'trusted'}.':<br />'.
1.381 raeburn 7740: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7741: $values{$dom}{'trusted'}.'</textarea>'.
7742: '</td></tr>'."\n".
7743: '<tr><td><hr /></td></tr>'."\n".
7744: '<tr>'.
7745: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7746: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7747: $lt{'vpndirect'}.'</label>'.(' 'x2).
7748: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7749: $lt{'vpnaliased'}.'</label></span></td></tr>';
7750: foreach my $item ('vpnint','vpnext') {
7751: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 7752: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 7753: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7754: $values{$dom}{$item}.'</textarea>'.
7755: '</td></tr>'."\n";
1.373 raeburn 7756: }
1.382 raeburn 7757: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7758: '<tr>'.
7759: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7760: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7761: $lt{'alltossl'}.'</label>'.(' 'x2).
7762: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7763: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7764: '</table></td></tr>';
1.373 raeburn 7765: }
7766: if (keys(%otherdoms)) {
7767: foreach my $domain (sort(keys(%otherdoms))) {
7768: $itemcount ++;
7769: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7770: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 7771: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 7772: '<td class="LC_left_item"><table>';
1.382 raeburn 7773: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 7774: my $showval = &mt('None');
1.382 raeburn 7775: if ($item eq 'ssl') {
7776: $showval = $lt{'ssltossl'};
7777: }
1.373 raeburn 7778: if ($values{$domain}{$item}) {
1.381 raeburn 7779: $showval = $values{$domain}{$item};
1.382 raeburn 7780: if ($item eq 'ssl') {
7781: $showval = $lt{'alltossl'};
1.383 raeburn 7782: } elsif ($item eq 'remoteip') {
7783: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 7784: }
1.373 raeburn 7785: }
7786: $datatable .= '<tr>'.
7787: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7788: }
1.381 raeburn 7789: $datatable .= '</table></td></tr>';
1.373 raeburn 7790: }
7791: }
7792: }
7793: $$rowtotal += $itemcount;
7794: return $datatable;
7795: }
7796:
7797: sub wafproxy_titles {
7798: return &Apache::lonlocal::texthash(
1.381 raeburn 7799: remoteip => "Method for determining user's IP",
7800: ipheader => 'Request header containing remote IP',
7801: trusted => 'Trusted IP range(s)',
7802: vpnaccess => 'Access from institutional VPN',
7803: vpndirect => 'via regular hostname (no WAF)',
7804: vpnaliased => 'via aliased hostname (WAF)',
7805: vpnint => 'Internal IP Range(s) for VPN sessions',
7806: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 7807: sslopt => 'Forwarding http/https',
1.381 raeburn 7808: alltossl => 'WAF forwards both http and https requests to https',
7809: ssltossl => 'WAF forwards http requests to http and https to https',
7810: );
7811: }
7812:
7813: sub remoteip_methods {
7814: return &Apache::lonlocal::texthash(
7815: m => 'Use Apache mod_remoteip',
7816: h => 'Use headers parsed by LON-CAPA',
7817: n => 'Not in use',
1.373 raeburn 7818: );
7819: }
7820:
1.137 raeburn 7821: sub print_usersessions {
7822: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7823: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7824: my (%by_ip,%by_location,@intdoms,@instdoms);
7825: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7826:
7827: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7828: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7829: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7830: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7831: if ($position eq 'top') {
1.152 raeburn 7832: if (keys(%serverhomes) > 1) {
1.145 raeburn 7833: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7834: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7835: if (ref($settings) eq 'HASH') {
7836: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7837: $curroffloadnow = $settings->{'offloadnow'};
7838: }
1.371 raeburn 7839: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7840: $curroffloadoth = $settings->{'offloadoth'};
7841: }
1.261 raeburn 7842: }
1.371 raeburn 7843: my $other_insts = scalar(keys(%by_location));
7844: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7845: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7846: } else {
1.140 raeburn 7847: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7848: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7849: '</td></tr>';
1.140 raeburn 7850: }
1.137 raeburn 7851: } else {
1.279 raeburn 7852: my %titles = &usersession_titles();
7853: my ($prefix,@types);
7854: if ($position eq 'bottom') {
7855: $prefix = 'remote';
7856: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7857: } else {
1.279 raeburn 7858: $prefix = 'hosted';
7859: @types = ('excludedomain','includedomain');
7860: }
7861: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7862: }
7863: $$rowtotal += $itemcount;
7864: return $datatable;
7865: }
7866:
7867: sub rules_by_location {
7868: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7869: my ($datatable,$itemcount,$css_class);
7870: if (keys(%{$by_location}) == 0) {
7871: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7872: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7873: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7874: '</td></tr>';
7875: $itemcount = 1;
7876: } else {
7877: $itemcount = 0;
7878: my $numinrow = 5;
7879: my (%current,%checkedon,%checkedoff);
7880: my @locations = sort(keys(%{$by_location}));
7881: foreach my $type (@{$types}) {
7882: $checkedon{$type} = '';
7883: $checkedoff{$type} = ' checked="checked"';
7884: }
7885: if (ref($settings) eq 'HASH') {
7886: if (ref($settings->{$prefix}) eq 'HASH') {
7887: foreach my $key (keys(%{$settings->{$prefix}})) {
7888: $current{$key} = $settings->{$prefix}{$key};
7889: if ($key eq 'version') {
7890: if ($current{$key} ne '') {
1.145 raeburn 7891: $checkedon{$key} = ' checked="checked"';
7892: $checkedoff{$key} = '';
7893: }
1.279 raeburn 7894: } elsif (ref($current{$key}) eq 'ARRAY') {
7895: $checkedon{$key} = ' checked="checked"';
7896: $checkedoff{$key} = '';
1.137 raeburn 7897: }
7898: }
7899: }
1.279 raeburn 7900: }
7901: foreach my $type (@{$types}) {
7902: next if ($type ne 'version' && !@locations);
7903: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7904: $datatable .= '<tr'.$css_class.'>
7905: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7906: <span class="LC_nobreak">
7907: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7908: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7909: if ($type eq 'version') {
7910: my @lcversions = &Apache::lonnet::all_loncaparevs();
7911: my $selector = '<select name="'.$prefix.'_version">';
7912: foreach my $version (@lcversions) {
7913: my $selected = '';
7914: if ($current{'version'} eq $version) {
7915: $selected = ' selected="selected"';
1.145 raeburn 7916: }
1.279 raeburn 7917: $selector .= ' <option value="'.$version.'"'.
7918: $selected.'>'.$version.'</option>';
7919: }
7920: $selector .= '</select> ';
7921: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7922: } else {
7923: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7924: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7925: ' />'.(' 'x2).
7926: '<input type="button" value="'.&mt('uncheck all').'" '.
7927: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7928: "\n".
7929: '</div><div><table>';
7930: my $rem;
7931: for (my $i=0; $i<@locations; $i++) {
7932: my ($showloc,$value,$checkedtype);
7933: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7934: my $ip = $by_location->{$locations[$i]}->[0];
7935: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7936: $value = join(':',@{$by_ip->{$ip}});
7937: $showloc = join(', ',@{$by_ip->{$ip}});
7938: if (ref($current{$type}) eq 'ARRAY') {
7939: foreach my $loc (@{$by_ip->{$ip}}) {
7940: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7941: $checkedtype = ' checked="checked"';
7942: last;
1.145 raeburn 7943: }
1.138 raeburn 7944: }
7945: }
7946: }
1.137 raeburn 7947: }
1.279 raeburn 7948: $rem = $i%($numinrow);
7949: if ($rem == 0) {
7950: if ($i > 0) {
7951: $datatable .= '</tr>';
7952: }
7953: $datatable .= '<tr>';
7954: }
7955: $datatable .= '<td class="LC_left_item">'.
7956: '<span class="LC_nobreak"><label>'.
7957: '<input type="checkbox" name="'.$prefix.'_'.$type.
7958: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7959: '</label></span></td>';
7960: }
7961: $rem = @locations%($numinrow);
7962: my $colsleft = $numinrow - $rem;
7963: if ($colsleft > 1 ) {
7964: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7965: ' </td>';
7966: } elsif ($colsleft == 1) {
7967: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7968: }
1.279 raeburn 7969: $datatable .= '</tr></table>';
1.137 raeburn 7970: }
1.279 raeburn 7971: $datatable .= '</td></tr>';
7972: $itemcount ++;
1.137 raeburn 7973: }
7974: }
1.279 raeburn 7975: return ($datatable,$itemcount);
1.137 raeburn 7976: }
7977:
1.275 raeburn 7978: sub print_ssl {
7979: my ($position,$dom,$settings,$rowtotal) = @_;
7980: my ($css_class,$datatable);
7981: my $itemcount = 1;
7982: if ($position eq 'top') {
1.281 raeburn 7983: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7984: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7985: my $same_institution;
7986: if ($intdom ne '') {
7987: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
7988: if (ref($internet_names) eq 'ARRAY') {
7989: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
7990: $same_institution = 1;
7991: }
7992: }
7993: }
1.275 raeburn 7994: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 7995: $datatable = '<tr'.$css_class.'><td colspan="2">';
7996: if ($same_institution) {
7997: my %domservers = &Apache::lonnet::get_servers($dom);
7998: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
7999: } else {
8000: $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.");
8001: }
8002: $datatable .= '</td></tr>';
1.275 raeburn 8003: $itemcount ++;
8004: } else {
8005: my %titles = &ssl_titles();
8006: my (%by_ip,%by_location,@intdoms,@instdoms);
8007: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8008: my @alldoms = &Apache::lonnet::all_domains();
8009: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8010: my @domservers = &Apache::lonnet::get_servers($dom);
8011: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8012: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8013: if (($position eq 'connto') || ($position eq 'connfrom')) {
8014: my $legacy;
8015: unless (ref($settings) eq 'HASH') {
8016: my $name;
8017: if ($position eq 'connto') {
8018: $name = 'loncAllowInsecure';
8019: } else {
8020: $name = 'londAllowInsecure';
8021: }
8022: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8023: my @ids=&Apache::lonnet::current_machine_ids();
8024: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8025: my %what = (
8026: $name => 1,
8027: );
8028: my ($result,$returnhash) =
8029: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8030: if ($result eq 'ok') {
8031: if (ref($returnhash) eq 'HASH') {
8032: $legacy = $returnhash->{$name};
8033: }
8034: }
8035: } else {
8036: $legacy = $Apache::lonnet::perlvar{$name};
8037: }
8038: }
1.275 raeburn 8039: foreach my $type ('dom','intdom','other') {
8040: my %checked;
8041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8042: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8043: '<td class="LC_right_item">';
8044: my $skip;
8045: if ($type eq 'dom') {
8046: unless (keys(%servers) > 1) {
8047: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8048: $skip = 1;
8049: }
8050: }
8051: if ($type eq 'intdom') {
8052: unless (@instdoms > 1) {
8053: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8054: $skip = 1;
8055: }
8056: } elsif ($type eq 'other') {
8057: if (keys(%by_location) == 0) {
8058: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8059: $skip = 1;
8060: }
8061: }
8062: unless ($skip) {
8063: $checked{'yes'} = ' checked="checked"';
8064: if (ref($settings) eq 'HASH') {
1.293 raeburn 8065: if (ref($settings->{$position}) eq 'HASH') {
8066: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8067: $checked{$1} = $checked{'yes'};
8068: delete($checked{'yes'});
8069: }
8070: }
1.293 raeburn 8071: } else {
8072: if ($legacy == 0) {
8073: $checked{'req'} = $checked{'yes'};
8074: delete($checked{'yes'});
8075: }
1.275 raeburn 8076: }
8077: foreach my $option ('no','yes','req') {
8078: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8079: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8080: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8081: '</label></span>'.(' 'x2);
8082: }
8083: }
8084: $datatable .= '</td></tr>';
8085: $itemcount ++;
8086: }
8087: } else {
8088: my $prefix = 'replication';
8089: my @types = ('certreq','nocertreq');
1.279 raeburn 8090: if (keys(%by_location) == 0) {
8091: $datatable .= '<tr'.$css_class.'><td>'.
8092: &mt('Nothing to set here, as there are no other institutions').
8093: '</td></tr>';
8094: $itemcount ++;
1.275 raeburn 8095: } else {
1.279 raeburn 8096: ($datatable,$itemcount) =
8097: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8098: }
8099: }
8100: }
8101: $$rowtotal += $itemcount;
8102: return $datatable;
8103: }
8104:
8105: sub ssl_titles {
8106: return &Apache::lonlocal::texthash (
8107: dom => 'LON-CAPA servers/VMs from same domain',
8108: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8109: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8110: connto => 'Connections to other servers',
8111: connfrom => 'Connections from other servers',
1.275 raeburn 8112: replication => 'Replicating content to other institutions',
8113: certreq => 'Client certificate required, but specific domains exempt',
8114: nocertreq => 'No client certificate required, except for specific domains',
8115: no => 'SSL not used',
8116: yes => 'SSL Optional (used if available)',
8117: req => 'SSL Required',
8118: );
1.279 raeburn 8119: }
8120:
8121: sub print_trust {
8122: my ($prefix,$dom,$settings,$rowtotal) = @_;
8123: my ($css_class,$datatable,%checked,%choices);
8124: my (%by_ip,%by_location,@intdoms,@instdoms);
8125: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8126: my $itemcount = 1;
8127: my %titles = &trust_titles();
8128: my @types = ('exc','inc');
8129: if ($prefix eq 'top') {
8130: $prefix = 'content';
8131: } elsif ($prefix eq 'bottom') {
8132: $prefix = 'msg';
8133: }
8134: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8135: $$rowtotal += $itemcount;
8136: return $datatable;
8137: }
8138:
8139: sub trust_titles {
8140: return &Apache::lonlocal::texthash(
8141: content => "Access to this domain's content by others",
8142: shared => "Access to other domain's content by this domain",
8143: enroll => "Enrollment in this domain's courses by others",
8144: othcoau => "Co-author roles in this domain for others",
8145: coaurem => "Co-author roles for this domain's users elsewhere",
8146: domroles => "Domain roles in this domain assignable to others",
8147: catalog => "Course Catalog for this domain displayed elsewhere",
8148: reqcrs => "Requests for creation of courses in this domain by others",
8149: msg => "Users in other domains can send messages to this domain",
8150: exc => "Allow all, but exclude specific domains",
8151: inc => "Deny all, but include specific domains",
8152: );
1.275 raeburn 8153: }
8154:
1.138 raeburn 8155: sub build_location_hashes {
1.275 raeburn 8156: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8157: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8158: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8159: my %iphost = &Apache::lonnet::get_iphost();
8160: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8161: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8162: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8163: foreach my $id (@{$iphost{$primary_ip}}) {
8164: my $intdom = &Apache::lonnet::internet_dom($id);
8165: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8166: push(@{$intdoms},$intdom);
8167: }
8168: }
8169: }
8170: foreach my $ip (keys(%iphost)) {
8171: if (ref($iphost{$ip}) eq 'ARRAY') {
8172: foreach my $id (@{$iphost{$ip}}) {
8173: my $location = &Apache::lonnet::internet_dom($id);
8174: if ($location) {
1.275 raeburn 8175: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8176: my $dom = &Apache::lonnet::host_domain($id);
8177: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8178: push(@{$instdoms},$dom);
8179: }
8180: next;
8181: }
1.138 raeburn 8182: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8183: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8184: push(@{$by_ip->{$ip}},$location);
8185: }
8186: } else {
8187: $by_ip->{$ip} = [$location];
8188: }
8189: }
8190: }
8191: }
8192: }
8193: foreach my $ip (sort(keys(%{$by_ip}))) {
8194: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8195: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8196: my $first = $by_ip->{$ip}->[0];
8197: if (ref($by_location->{$first}) eq 'ARRAY') {
8198: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8199: push(@{$by_location->{$first}},$ip);
8200: }
8201: } else {
8202: $by_location->{$first} = [$ip];
8203: }
8204: }
8205: }
8206: return;
8207: }
8208:
1.145 raeburn 8209: sub current_offloads_to {
8210: my ($dom,$settings,$servers) = @_;
8211: my (%spareid,%otherdomconfigs);
1.152 raeburn 8212: if (ref($servers) eq 'HASH') {
1.145 raeburn 8213: foreach my $lonhost (sort(keys(%{$servers}))) {
8214: my $gotspares;
1.152 raeburn 8215: if (ref($settings) eq 'HASH') {
8216: if (ref($settings->{'spares'}) eq 'HASH') {
8217: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8218: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8219: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8220: $gotspares = 1;
8221: }
1.145 raeburn 8222: }
8223: }
8224: unless ($gotspares) {
8225: my $gotspares;
8226: my $serverhomeID =
8227: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8228: my $serverhomedom =
8229: &Apache::lonnet::host_domain($serverhomeID);
8230: if ($serverhomedom ne $dom) {
8231: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8232: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8233: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8234: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8235: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8236: $gotspares = 1;
8237: }
8238: }
8239: } else {
8240: $otherdomconfigs{$serverhomedom} =
8241: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8242: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8243: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8244: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8245: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8246: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8247: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8248: $gotspares = 1;
8249: }
8250: }
8251: }
8252: }
8253: }
8254: }
8255: }
8256: unless ($gotspares) {
8257: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8258: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8259: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8260: } else {
8261: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8262: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8263: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8264: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8265: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8266: } else {
1.150 raeburn 8267: my %what = (
8268: spareid => 1,
8269: );
8270: my ($result,$returnhash) =
8271: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8272: if ($result eq 'ok') {
8273: if (ref($returnhash) eq 'HASH') {
8274: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8275: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8276: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8277: }
8278: }
1.145 raeburn 8279: }
8280: }
8281: }
8282: }
8283: }
8284: }
8285: return %spareid;
8286: }
8287:
8288: sub spares_row {
1.371 raeburn 8289: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8290: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8291: my $css_class;
8292: my $numinrow = 4;
8293: my $itemcount = 1;
8294: my $datatable;
1.152 raeburn 8295: my %typetitles = &sparestype_titles();
8296: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8297: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8298: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8299: my ($othercontrol,$serverdom);
8300: if ($serverhome ne $server) {
8301: $serverdom = &Apache::lonnet::host_domain($serverhome);
8302: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8303: } else {
8304: $serverdom = &Apache::lonnet::host_domain($server);
8305: if ($serverdom ne $dom) {
8306: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8307: }
8308: }
8309: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8310: my ($checkednow,$checkedoth);
1.261 raeburn 8311: if (ref($curroffloadnow) eq 'HASH') {
8312: if ($curroffloadnow->{$server}) {
8313: $checkednow = ' checked="checked"';
8314: }
8315: }
1.371 raeburn 8316: if (ref($curroffloadoth) eq 'HASH') {
8317: if ($curroffloadoth->{$server}) {
8318: $checkedoth = ' checked="checked"';
8319: }
8320: }
1.145 raeburn 8321: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8322: $datatable .= '<tr'.$css_class.'>
8323: <td rowspan="2">
1.183 bisitz 8324: <span class="LC_nobreak">'.
8325: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8326: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8327: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8328: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8329: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8330: "\n";
1.371 raeburn 8331: if ($other_insts) {
8332: $datatable .= '<br />'.
8333: '<span class="LC_nobreak">'."\n".
8334: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8335: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8336: "\n";
8337: }
1.145 raeburn 8338: my (%current,%canselect);
1.152 raeburn 8339: my @choices =
8340: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8341: foreach my $type ('primary','default') {
8342: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8343: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8344: my @spares = @{$spareid->{$server}{$type}};
8345: if (@spares > 0) {
1.152 raeburn 8346: if ($othercontrol) {
8347: $current{$type} = join(', ',@spares);
8348: } else {
8349: $current{$type} .= '<table>';
8350: my $numspares = scalar(@spares);
8351: for (my $i=0; $i<@spares; $i++) {
8352: my $rem = $i%($numinrow);
8353: if ($rem == 0) {
8354: if ($i > 0) {
8355: $current{$type} .= '</tr>';
8356: }
8357: $current{$type} .= '<tr>';
1.145 raeburn 8358: }
1.152 raeburn 8359: $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'".');" /> '.
8360: $spareid->{$server}{$type}[$i].
8361: '</label></td>'."\n";
8362: }
8363: my $rem = @spares%($numinrow);
8364: my $colsleft = $numinrow - $rem;
8365: if ($colsleft > 1 ) {
8366: $current{$type} .= '<td colspan="'.$colsleft.
8367: '" class="LC_left_item">'.
8368: ' </td>';
8369: } elsif ($colsleft == 1) {
8370: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8371: }
1.152 raeburn 8372: $current{$type} .= '</tr></table>';
1.150 raeburn 8373: }
1.145 raeburn 8374: }
8375: }
8376: if ($current{$type} eq '') {
8377: $current{$type} = &mt('None specified');
8378: }
1.152 raeburn 8379: if ($othercontrol) {
8380: if ($type eq 'primary') {
8381: $canselect{$type} = $othercontrol;
8382: }
8383: } else {
8384: $canselect{$type} =
8385: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8386: '<select name="newspare_'.$type.'_'.$server.'" '.
8387: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8388: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8389: if (@choices > 0) {
8390: foreach my $lonhost (@choices) {
8391: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8392: }
8393: }
8394: $canselect{$type} .= '</select>'."\n";
8395: }
8396: } else {
8397: $current{$type} = &mt('Could not be determined');
8398: if ($type eq 'primary') {
8399: $canselect{$type} = $othercontrol;
8400: }
1.145 raeburn 8401: }
1.152 raeburn 8402: if ($type eq 'default') {
8403: $datatable .= '<tr'.$css_class.'>';
8404: }
8405: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8406: '<td>'.$current{$type}.'</td>'."\n".
8407: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8408: }
8409: $itemcount ++;
8410: }
8411: }
8412: $$rowtotal += $itemcount;
8413: return $datatable;
8414: }
8415:
1.152 raeburn 8416: sub possible_newspares {
8417: my ($server,$currspares,$serverhomes,$altids) = @_;
8418: my $serverhostname = &Apache::lonnet::hostname($server);
8419: my %excluded;
8420: if ($serverhostname ne '') {
8421: %excluded = (
8422: $serverhostname => 1,
8423: );
8424: }
8425: if (ref($currspares) eq 'HASH') {
8426: foreach my $type (keys(%{$currspares})) {
8427: if (ref($currspares->{$type}) eq 'ARRAY') {
8428: if (@{$currspares->{$type}} > 0) {
8429: foreach my $curr (@{$currspares->{$type}}) {
8430: my $hostname = &Apache::lonnet::hostname($curr);
8431: $excluded{$hostname} = 1;
8432: }
8433: }
8434: }
8435: }
8436: }
8437: my @choices;
8438: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8439: if (keys(%{$serverhomes}) > 1) {
8440: foreach my $name (sort(keys(%{$serverhomes}))) {
8441: unless ($excluded{$name}) {
8442: if (exists($altids->{$serverhomes->{$name}})) {
8443: push(@choices,$altids->{$serverhomes->{$name}});
8444: } else {
8445: push(@choices,$serverhomes->{$name});
1.145 raeburn 8446: }
8447: }
8448: }
8449: }
8450: }
1.152 raeburn 8451: return sort(@choices);
1.145 raeburn 8452: }
8453:
1.150 raeburn 8454: sub print_loadbalancing {
8455: my ($dom,$settings,$rowtotal) = @_;
8456: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8457: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8458: my $numinrow = 1;
8459: my $datatable;
8460: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8461: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8462: if (ref($settings) eq 'HASH') {
8463: %existing = %{$settings};
8464: }
8465: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8466: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8467: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8468: } else {
8469: return;
8470: }
8471: my ($othertitle,$usertypes,$types) =
8472: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8473: my $rownum = 8;
1.150 raeburn 8474: if (ref($types) eq 'ARRAY') {
8475: $rownum += scalar(@{$types});
8476: }
1.171 raeburn 8477: my @css_class = ('LC_odd_row','LC_even_row');
8478: my $balnum = 0;
8479: my $islast;
8480: my (@toshow,$disabledtext);
8481: if (keys(%currbalancer) > 0) {
8482: @toshow = sort(keys(%currbalancer));
8483: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8484: push(@toshow,'');
8485: }
8486: } else {
8487: @toshow = ('');
8488: $disabledtext = &mt('No existing load balancer');
8489: }
8490: foreach my $lonhost (@toshow) {
8491: if ($balnum == scalar(@toshow)-1) {
8492: $islast = 1;
8493: } else {
8494: $islast = 0;
8495: }
8496: my $cssidx = $balnum%2;
8497: my $targets_div_style = 'display: none';
8498: my $disabled_div_style = 'display: block';
8499: my $homedom_div_style = 'display: none';
8500: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8501: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8502: '<p>';
8503: if ($lonhost eq '') {
1.210 raeburn 8504: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8505: if (keys(%currbalancer) > 0) {
8506: $datatable .= &mt('Add balancer:');
8507: } else {
8508: $datatable .= &mt('Enable balancer:');
8509: }
8510: $datatable .= ' '.
8511: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8512: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8513: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8514: '<option value="" selected="selected">'.&mt('None').
8515: '</option>'."\n";
8516: foreach my $server (sort(keys(%servers))) {
8517: next if ($currbalancer{$server});
8518: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8519: }
1.210 raeburn 8520: $datatable .=
1.171 raeburn 8521: '</select>'."\n".
8522: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8523: } else {
8524: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8525: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8526: &mt('Stop balancing').'</label>'.
8527: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8528: $targets_div_style = 'display: block';
8529: $disabled_div_style = 'display: none';
8530: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8531: $homedom_div_style = 'display: block';
8532: }
8533: }
1.306 raeburn 8534: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8535: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8536: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8537: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8538: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8539: my @sparestypes = ('primary','default');
8540: my %typetitles = &sparestype_titles();
1.284 raeburn 8541: my %hostherechecked = (
8542: no => ' checked="checked"',
8543: );
1.342 raeburn 8544: my %balcookiechecked = (
8545: no => ' checked="checked"',
8546: );
1.171 raeburn 8547: foreach my $sparetype (@sparestypes) {
8548: my $targettable;
8549: for (my $i=0; $i<$numspares; $i++) {
8550: my $checked;
8551: if (ref($currtargets{$lonhost}) eq 'HASH') {
8552: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8553: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8554: $checked = ' checked="checked"';
8555: }
8556: }
8557: }
8558: my ($chkboxval,$disabled);
8559: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8560: $chkboxval = $spares[$i];
8561: }
8562: if (exists($currbalancer{$spares[$i]})) {
8563: $disabled = ' disabled="disabled"';
8564: }
1.210 raeburn 8565: $targettable .=
1.253 raeburn 8566: '<td><span class="LC_nobreak"><label>'.
8567: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8568: $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 8569: '</span></label></span></td>';
1.171 raeburn 8570: my $rem = $i%($numinrow);
8571: if ($rem == 0) {
8572: if (($i > 0) && ($i < $numspares-1)) {
8573: $targettable .= '</tr>';
8574: }
8575: if ($i < $numspares-1) {
8576: $targettable .= '<tr>';
1.150 raeburn 8577: }
8578: }
8579: }
1.171 raeburn 8580: if ($targettable ne '') {
8581: my $rem = $numspares%($numinrow);
8582: my $colsleft = $numinrow - $rem;
8583: if ($colsleft > 1 ) {
8584: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8585: ' </td>';
8586: } elsif ($colsleft == 1) {
8587: $targettable .= '<td class="LC_left_item"> </td>';
8588: }
8589: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8590: '<table><tr>'.$targettable.'</tr></table><br />';
8591: }
1.284 raeburn 8592: $hostherechecked{$sparetype} = '';
8593: if (ref($currtargets{$lonhost}) eq 'HASH') {
8594: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8595: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8596: $hostherechecked{$sparetype} = ' checked="checked"';
8597: $hostherechecked{'no'} = '';
8598: }
8599: }
8600: }
8601: }
1.342 raeburn 8602: if ($currcookies{$lonhost}) {
8603: %balcookiechecked = (
8604: yes => ' checked="checked"',
8605: );
8606: }
1.284 raeburn 8607: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8608: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8609: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8610: foreach my $sparetype (@sparestypes) {
8611: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8612: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8613: '</i></label><br />';
1.171 raeburn 8614: }
1.342 raeburn 8615: $datatable .= &mt('Use balancer cookie').'<br />'.
8616: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8617: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8618: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8619: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8620: '</div></td></tr>'.
1.171 raeburn 8621: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8622: $othertitle,$usertypes,$types,\%servers,
8623: \%currbalancer,$lonhost,
8624: $targets_div_style,$homedom_div_style,
8625: $css_class[$cssidx],$balnum,$islast);
8626: $$rowtotal += $rownum;
8627: $balnum ++;
8628: }
8629: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8630: return $datatable;
8631: }
8632:
8633: sub get_loadbalancers_config {
1.342 raeburn 8634: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8635: return unless ((ref($servers) eq 'HASH') &&
8636: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8637: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8638: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8639: if (keys(%{$existing}) > 0) {
8640: my $oldlonhost;
8641: foreach my $key (sort(keys(%{$existing}))) {
8642: if ($key eq 'lonhost') {
8643: $oldlonhost = $existing->{'lonhost'};
8644: $currbalancer->{$oldlonhost} = 1;
8645: } elsif ($key eq 'targets') {
8646: if ($oldlonhost) {
8647: $currtargets->{$oldlonhost} = $existing->{'targets'};
8648: }
8649: } elsif ($key eq 'rules') {
8650: if ($oldlonhost) {
8651: $currrules->{$oldlonhost} = $existing->{'rules'};
8652: }
8653: } elsif (ref($existing->{$key}) eq 'HASH') {
8654: $currbalancer->{$key} = 1;
8655: $currtargets->{$key} = $existing->{$key}{'targets'};
8656: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8657: if ($existing->{$key}{'cookie'}) {
8658: $currcookies->{$key} = 1;
8659: }
1.150 raeburn 8660: }
8661: }
1.171 raeburn 8662: } else {
8663: my ($balancerref,$targetsref) =
8664: &Apache::lonnet::get_lonbalancer_config($servers);
8665: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8666: foreach my $server (sort(keys(%{$balancerref}))) {
8667: $currbalancer->{$server} = 1;
8668: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8669: }
8670: }
8671: }
1.171 raeburn 8672: return;
1.150 raeburn 8673: }
8674:
8675: sub loadbalancing_rules {
8676: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8677: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8678: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8679: my $output;
1.171 raeburn 8680: my $num = 0;
1.210 raeburn 8681: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8682: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8683: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8684: foreach my $type (@{$alltypes}) {
1.171 raeburn 8685: $num ++;
1.150 raeburn 8686: my $current;
8687: if (ref($currrules) eq 'HASH') {
8688: $current = $currrules->{$type};
8689: }
1.253 raeburn 8690: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8691: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8692: $current = '';
8693: }
8694: }
8695: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8696: $servers,$currbalancer,$lonhost,$dom,
8697: $targets_div_style,$homedom_div_style,
8698: $css_class,$balnum,$num,$islast);
1.150 raeburn 8699: }
8700: }
8701: return $output;
8702: }
8703:
8704: sub loadbalancing_titles {
8705: my ($dom,$intdom,$usertypes,$types) = @_;
8706: my %othertypes = (
8707: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8708: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8709: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8710: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8711: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8712: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8713: );
1.209 raeburn 8714: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8715: my @available;
1.150 raeburn 8716: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8717: @available = @{$types};
1.150 raeburn 8718: }
1.302 raeburn 8719: unless (grep(/^default$/,@available)) {
8720: push(@available,'default');
8721: }
8722: unshift(@alltypes,@available);
1.150 raeburn 8723: my %titles;
8724: foreach my $type (@alltypes) {
8725: if ($type =~ /^_LC_/) {
8726: $titles{$type} = $othertypes{$type};
8727: } elsif ($type eq 'default') {
8728: $titles{$type} = &mt('All users from [_1]',$dom);
8729: if (ref($types) eq 'ARRAY') {
8730: if (@{$types} > 0) {
8731: $titles{$type} = &mt('Other users from [_1]',$dom);
8732: }
8733: }
8734: } elsif (ref($usertypes) eq 'HASH') {
8735: $titles{$type} = $usertypes->{$type};
8736: }
8737: }
8738: return (\@alltypes,\%othertypes,\%titles);
8739: }
8740:
8741: sub loadbalance_rule_row {
1.171 raeburn 8742: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8743: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8744: my @rulenames;
1.150 raeburn 8745: my %ruletitles = &offloadtype_text();
1.209 raeburn 8746: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8747: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8748: } else {
1.209 raeburn 8749: @rulenames = ('default','homeserver');
8750: if ($type eq '_LC_external') {
8751: push(@rulenames,'externalbalancer');
8752: } else {
8753: push(@rulenames,'specific');
8754: }
8755: push(@rulenames,'none');
1.150 raeburn 8756: }
8757: my $style = $targets_div_style;
1.253 raeburn 8758: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8759: $style = $homedom_div_style;
8760: }
1.171 raeburn 8761: my $space;
8762: if ($islast && $num == 1) {
1.317 raeburn 8763: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8764: }
1.210 raeburn 8765: my $output =
1.306 raeburn 8766: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8767: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8768: '<td valaign="top">'.$space.
8769: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8770: for (my $i=0; $i<@rulenames; $i++) {
8771: my $rule = $rulenames[$i];
8772: my ($checked,$extra);
8773: if ($rulenames[$i] eq 'default') {
8774: $rule = '';
8775: }
8776: if ($rulenames[$i] eq 'specific') {
8777: if (ref($servers) eq 'HASH') {
8778: my $default;
8779: if (($current ne '') && (exists($servers->{$current}))) {
8780: $checked = ' checked="checked"';
8781: }
8782: unless ($checked) {
8783: $default = ' selected="selected"';
8784: }
1.210 raeburn 8785: $extra =
1.171 raeburn 8786: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8787: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8788: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8789: '<option value=""'.$default.'></option>'."\n";
8790: foreach my $server (sort(keys(%{$servers}))) {
8791: if (ref($currbalancer) eq 'HASH') {
8792: next if (exists($currbalancer->{$server}));
8793: }
1.150 raeburn 8794: my $selected;
1.171 raeburn 8795: if ($server eq $current) {
1.150 raeburn 8796: $selected = ' selected="selected"';
8797: }
1.171 raeburn 8798: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8799: }
8800: $extra .= '</select>';
8801: }
8802: } elsif ($rule eq $current) {
8803: $checked = ' checked="checked"';
8804: }
8805: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8806: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8807: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8808: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8809: ')"'.$checked.' /> ';
8810: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8811: $output .= $ruletitles{'particular'};
8812: } else {
8813: $output .= $ruletitles{$rulenames[$i]};
8814: }
8815: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8816: }
8817: $output .= '</div></td></tr>'."\n";
8818: return $output;
8819: }
8820:
8821: sub offloadtype_text {
8822: my %ruletitles = &Apache::lonlocal::texthash (
8823: 'default' => 'Offloads to default destinations',
8824: 'homeserver' => "Offloads to user's home server",
8825: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8826: 'specific' => 'Offloads to specific server',
1.161 raeburn 8827: 'none' => 'No offload',
1.209 raeburn 8828: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8829: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8830: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8831: );
8832: return %ruletitles;
8833: }
8834:
8835: sub sparestype_titles {
8836: my %typestitles = &Apache::lonlocal::texthash (
8837: 'primary' => 'primary',
8838: 'default' => 'default',
8839: );
8840: return %typestitles;
8841: }
8842:
1.28 raeburn 8843: sub contact_titles {
8844: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8845: 'supportemail' => 'Support E-mail address',
8846: 'adminemail' => 'Default Server Admin E-mail address',
8847: 'errormail' => 'Error reports to be e-mailed to',
8848: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8849: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8850: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8851: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8852: 'requestsmail' => 'E-mail from course requests requiring approval',
8853: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8854: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8855: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 8856: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8857: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 8858: 'errorweights' => 'Weights used to compute error count',
8859: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8860: );
8861: my %short_titles = &Apache::lonlocal::texthash (
8862: adminemail => 'Admin E-mail address',
8863: supportemail => 'Support E-mail',
8864: );
8865: return (\%titles,\%short_titles);
8866: }
8867:
1.286 raeburn 8868: sub helpform_fields {
8869: my %titles = &Apache::lonlocal::texthash (
8870: 'username' => 'Name',
8871: 'user' => 'Username/domain',
8872: 'phone' => 'Phone',
8873: 'cc' => 'Cc e-mail',
8874: 'course' => 'Course Details',
8875: 'section' => 'Sections',
1.289 raeburn 8876: 'screenshot' => 'File upload',
1.286 raeburn 8877: );
8878: my @fields = ('username','phone','user','course','section','cc','screenshot');
8879: my %possoptions = (
8880: username => ['yes','no','req'],
1.289 raeburn 8881: phone => ['yes','no','req'],
1.286 raeburn 8882: user => ['yes','no'],
1.289 raeburn 8883: cc => ['yes','no'],
1.286 raeburn 8884: course => ['yes','no'],
8885: section => ['yes','no'],
8886: screenshot => ['yes','no'],
8887: );
8888: my %fieldoptions = &Apache::lonlocal::texthash (
8889: 'yes' => 'Optional',
8890: 'req' => 'Required',
8891: 'no' => "Not shown",
8892: );
8893: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8894: }
8895:
1.72 raeburn 8896: sub tool_titles {
8897: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8898: aboutme => 'Personal web page',
1.86 raeburn 8899: blog => 'Blog',
1.162 raeburn 8900: webdav => 'WebDAV',
1.86 raeburn 8901: portfolio => 'Portfolio',
1.88 bisitz 8902: official => 'Official courses (with institutional codes)',
8903: unofficial => 'Unofficial courses',
1.98 raeburn 8904: community => 'Communities',
1.216 raeburn 8905: textbook => 'Textbook courses',
1.271 raeburn 8906: placement => 'Placement tests',
1.86 raeburn 8907: );
1.72 raeburn 8908: return %titles;
8909: }
8910:
1.101 raeburn 8911: sub courserequest_titles {
8912: my %titles = &Apache::lonlocal::texthash (
8913: official => 'Official',
8914: unofficial => 'Unofficial',
8915: community => 'Communities',
1.216 raeburn 8916: textbook => 'Textbook',
1.271 raeburn 8917: placement => 'Placement tests',
1.325 raeburn 8918: lti => 'LTI Provider',
1.101 raeburn 8919: norequest => 'Not allowed',
1.325 raeburn 8920: approval => 'Approval by DC',
1.101 raeburn 8921: validate => 'With validation',
8922: autolimit => 'Numerical limit',
1.103 raeburn 8923: unlimited => '(blank for unlimited)',
1.101 raeburn 8924: );
8925: return %titles;
8926: }
8927:
1.163 raeburn 8928: sub authorrequest_titles {
8929: my %titles = &Apache::lonlocal::texthash (
8930: norequest => 'Not allowed',
8931: approval => 'Approval by Dom. Coord.',
8932: automatic => 'Automatic approval',
8933: );
8934: return %titles;
1.210 raeburn 8935: }
1.163 raeburn 8936:
1.101 raeburn 8937: sub courserequest_conditions {
8938: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8939: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 8940: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8941: );
8942: return %conditions;
8943: }
8944:
8945:
1.27 raeburn 8946: sub print_usercreation {
1.30 raeburn 8947: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8948: my $numinrow = 4;
1.28 raeburn 8949: my $datatable;
8950: if ($position eq 'top') {
1.30 raeburn 8951: $$rowtotal ++;
1.34 raeburn 8952: my $rowcount = 0;
1.32 raeburn 8953: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8954: if (ref($rules) eq 'HASH') {
8955: if (keys(%{$rules}) > 0) {
1.32 raeburn 8956: $datatable .= &user_formats_row('username',$settings,$rules,
8957: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8958: $$rowtotal ++;
1.32 raeburn 8959: $rowcount ++;
8960: }
8961: }
8962: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8963: if (ref($idrules) eq 'HASH') {
8964: if (keys(%{$idrules}) > 0) {
8965: $datatable .= &user_formats_row('id',$settings,$idrules,
8966: $idruleorder,$numinrow,$rowcount);
8967: $$rowtotal ++;
8968: $rowcount ++;
1.28 raeburn 8969: }
8970: }
1.39 raeburn 8971: if ($rowcount == 0) {
8972: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8973: $$rowtotal ++;
8974: $rowcount ++;
8975: }
1.34 raeburn 8976: } elsif ($position eq 'middle') {
1.224 raeburn 8977: my @creators = ('author','course','requestcrs');
1.37 raeburn 8978: my ($rules,$ruleorder) =
8979: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8980: my %lt = &usercreation_types();
8981: my %checked;
8982: if (ref($settings) eq 'HASH') {
8983: if (ref($settings->{'cancreate'}) eq 'HASH') {
8984: foreach my $item (@creators) {
8985: $checked{$item} = $settings->{'cancreate'}{$item};
8986: }
8987: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8988: foreach my $item (@creators) {
8989: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8990: $checked{$item} = 'none';
8991: }
8992: }
8993: }
8994: }
8995: my $rownum = 0;
8996: foreach my $item (@creators) {
8997: $rownum ++;
1.224 raeburn 8998: if ($checked{$item} eq '') {
8999: $checked{$item} = 'any';
1.34 raeburn 9000: }
9001: my $css_class;
9002: if ($rownum%2) {
9003: $css_class = '';
9004: } else {
9005: $css_class = ' class="LC_odd_row" ';
9006: }
9007: $datatable .= '<tr'.$css_class.'>'.
9008: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9009: '</span></td><td style="text-align: right">';
1.224 raeburn 9010: my @options = ('any');
9011: if (ref($rules) eq 'HASH') {
9012: if (keys(%{$rules}) > 0) {
9013: push(@options,('official','unofficial'));
1.37 raeburn 9014: }
9015: }
1.224 raeburn 9016: push(@options,'none');
1.37 raeburn 9017: foreach my $option (@options) {
1.50 raeburn 9018: my $type = 'radio';
1.34 raeburn 9019: my $check = ' ';
1.224 raeburn 9020: if ($checked{$item} eq $option) {
9021: $check = ' checked="checked" ';
1.34 raeburn 9022: }
9023: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9024: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9025: $item.'" value="'.$option.'"'.$check.'/> '.
9026: $lt{$option}.'</label> </span>';
9027: }
9028: $datatable .= '</td></tr>';
9029: }
1.28 raeburn 9030: } else {
9031: my @contexts = ('author','course','domain');
1.325 raeburn 9032: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9033: my %checked;
9034: if (ref($settings) eq 'HASH') {
9035: if (ref($settings->{'authtypes'}) eq 'HASH') {
9036: foreach my $item (@contexts) {
9037: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9038: foreach my $auth (@authtypes) {
9039: if ($settings->{'authtypes'}{$item}{$auth}) {
9040: $checked{$item}{$auth} = ' checked="checked" ';
9041: }
9042: }
9043: }
9044: }
1.27 raeburn 9045: }
1.35 raeburn 9046: } else {
9047: foreach my $item (@contexts) {
1.36 raeburn 9048: foreach my $auth (@authtypes) {
1.35 raeburn 9049: $checked{$item}{$auth} = ' checked="checked" ';
9050: }
9051: }
1.27 raeburn 9052: }
1.28 raeburn 9053: my %title = &context_names();
9054: my %authname = &authtype_names();
9055: my $rownum = 0;
9056: my $css_class;
9057: foreach my $item (@contexts) {
9058: if ($rownum%2) {
9059: $css_class = '';
9060: } else {
9061: $css_class = ' class="LC_odd_row" ';
9062: }
1.30 raeburn 9063: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9064: '<td>'.$title{$item}.
9065: '</td><td class="LC_left_item">'.
9066: '<span class="LC_nobreak">';
9067: foreach my $auth (@authtypes) {
9068: $datatable .= '<label>'.
9069: '<input type="checkbox" name="'.$item.'_auth" '.
9070: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9071: $authname{$auth}.'</label> ';
9072: }
9073: $datatable .= '</span></td></tr>';
9074: $rownum ++;
1.27 raeburn 9075: }
1.30 raeburn 9076: $$rowtotal += $rownum;
1.27 raeburn 9077: }
9078: return $datatable;
9079: }
9080:
1.224 raeburn 9081: sub print_selfcreation {
9082: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9083: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9084: $emaildomain,$datatable);
1.224 raeburn 9085: if (ref($settings) eq 'HASH') {
9086: if (ref($settings->{'cancreate'}) eq 'HASH') {
9087: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9088: if (ref($createsettings) eq 'HASH') {
9089: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9090: @selfcreate = @{$createsettings->{'selfcreate'}};
9091: } elsif ($createsettings->{'selfcreate'} ne '') {
9092: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9093: @selfcreate = ('email','login','sso');
9094: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9095: @selfcreate = ($createsettings->{'selfcreate'});
9096: }
9097: }
9098: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9099: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9100: }
1.305 raeburn 9101: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9102: $emailoptions = $createsettings->{'emailoptions'};
9103: }
1.303 raeburn 9104: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9105: $emailverified = $createsettings->{'emailverified'};
9106: }
9107: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9108: $emaildomain = $createsettings->{'emaildomain'};
9109: }
1.224 raeburn 9110: }
9111: }
9112: }
9113: my %radiohash;
9114: my $numinrow = 4;
9115: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9116: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9117: if ($position eq 'top') {
9118: my %choices = &Apache::lonlocal::texthash (
9119: cancreate_login => 'Institutional Login',
9120: cancreate_sso => 'Institutional Single Sign On',
9121: );
9122: my @toggles = sort(keys(%choices));
9123: my %defaultchecked = (
9124: 'cancreate_login' => 'off',
9125: 'cancreate_sso' => 'off',
9126: );
1.228 raeburn 9127: my ($onclick,$itemcount);
1.224 raeburn 9128: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9129: \%choices,$itemcount,$onclick);
1.228 raeburn 9130: $$rowtotal += $itemcount;
9131:
1.224 raeburn 9132: if (ref($usertypes) eq 'HASH') {
9133: if (keys(%{$usertypes}) > 0) {
9134: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9135: $dom,$numinrow,$othertitle,
1.305 raeburn 9136: 'statustocreate',$rowtotal);
1.224 raeburn 9137: $$rowtotal ++;
9138: }
9139: }
1.240 raeburn 9140: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9141: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9142: $fieldtitles{'inststatus'} = &mt('Institutional status');
9143: my $rem;
9144: my $numperrow = 2;
9145: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9146: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9147: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9148: '<td class="LC_left_item">'."\n".
1.334 raeburn 9149: '<table>'."\n";
1.240 raeburn 9150: for (my $i=0; $i<@fields; $i++) {
9151: $rem = $i%($numperrow);
9152: if ($rem == 0) {
9153: if ($i > 0) {
9154: $datatable .= '</tr>';
9155: }
9156: $datatable .= '<tr>';
9157: }
9158: my $currval;
1.248 raeburn 9159: if (ref($createsettings) eq 'HASH') {
9160: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9161: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9162: }
1.240 raeburn 9163: }
9164: $datatable .= '<td class="LC_left_item">'.
9165: '<span class="LC_nobreak">'.
9166: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9167: 'value="'.$currval.'" size="10" /> '.
9168: $fieldtitles{$fields[$i]}.'</span></td>';
9169: }
9170: my $colsleft = $numperrow - $rem;
9171: if ($colsleft > 1 ) {
9172: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9173: ' </td>';
9174: } elsif ($colsleft == 1) {
9175: $datatable .= '<td class="LC_left_item"> </td>';
9176: }
9177: $datatable .= '</tr></table></td></tr>';
9178: $$rowtotal ++;
1.224 raeburn 9179: } elsif ($position eq 'middle') {
9180: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9181: my @posstypes;
1.224 raeburn 9182: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9183: @posstypes = @{$types};
9184: }
9185: unless (grep(/^default$/,@posstypes)) {
9186: push(@posstypes,'default');
9187: }
9188: my %usertypeshash;
9189: if (ref($usertypes) eq 'HASH') {
9190: %usertypeshash = %{$usertypes};
9191: }
9192: $usertypeshash{'default'} = $othertitle;
9193: foreach my $status (@posstypes) {
9194: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9195: $numinrow,$$rowtotal,\%usertypeshash);
9196: $$rowtotal ++;
1.224 raeburn 9197: }
9198: } else {
1.236 raeburn 9199: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9200: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9201: );
9202: my @toggles = sort(keys(%choices));
9203: my %defaultchecked = (
9204: 'cancreate_email' => 'off',
9205: );
1.305 raeburn 9206: my $customclass = 'LC_selfcreate_email';
9207: my $classprefix = 'LC_canmodify_emailusername_';
9208: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9209: my $display = 'none';
1.305 raeburn 9210: my $rowstyle = 'display:none';
1.236 raeburn 9211: if (grep(/^\Qemail\E$/,@selfcreate)) {
9212: $display = 'block';
1.305 raeburn 9213: $rowstyle = 'display:table-row';
1.236 raeburn 9214: }
1.305 raeburn 9215: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9216: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9217: \%choices,$$rowtotal,$onclick);
9218: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9219: $rowstyle);
9220: $$rowtotal ++;
9221: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9222: $rowstyle);
9223: $$rowtotal ++;
9224: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9225: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9226: my ($emailrules,$emailruleorder) =
9227: &Apache::lonnet::inst_userrules($dom,'email');
9228: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9229: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9230: if (ref($types) eq 'ARRAY') {
9231: @posstypes = @{$types};
9232: }
9233: if (@posstypes) {
9234: unless (grep(/^default$/,@posstypes)) {
9235: push(@posstypes,'default');
1.302 raeburn 9236: }
9237: if (ref($usertypes) eq 'HASH') {
9238: %usertypeshash = %{$usertypes};
9239: }
1.305 raeburn 9240: my $currassign;
9241: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9242: $currassign = {
9243: selfassign => $domdefaults{'inststatusguest'},
9244: };
9245: @ordered = @{$domdefaults{'inststatusguest'}};
9246: } else {
9247: $currassign = { selfassign => [] };
9248: }
9249: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9250: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9251: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9252: $numinrow,$othertitle,'selfassign',
9253: $rowtotal,$onclicktypes,$customclass,
9254: $rowstyle);
9255: $$rowtotal ++;
1.302 raeburn 9256: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9257: foreach my $status (@posstypes) {
9258: my $css_class;
9259: if ($$rowtotal%2) {
9260: $css_class = 'LC_odd_row ';
9261: }
9262: $css_class .= $customclass;
9263: my $rowid = $optionsprefix.$status;
9264: my $hidden = 1;
9265: my $currstyle = 'display:none';
9266: if (grep(/^\Q$status\E$/,@ordered)) {
9267: $currstyle = $rowstyle;
9268: $hidden = 0;
9269: }
9270: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9271: $emailrules,$emailruleorder,$settings,$status,$rowid,
9272: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9273: unless ($hidden) {
9274: $$rowtotal ++;
9275: }
1.224 raeburn 9276: }
1.302 raeburn 9277: } else {
1.305 raeburn 9278: my $css_class;
9279: if ($$rowtotal%2) {
9280: $css_class = 'LC_odd_row ';
9281: }
9282: $css_class .= $customclass;
1.302 raeburn 9283: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9284: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9285: $emailrules,$emailruleorder,$settings,'default','',
9286: $othertitle,$css_class,$rowstyle,$intdom);
9287: $$rowtotal ++;
1.224 raeburn 9288: }
9289: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9290: $numinrow = 1;
1.305 raeburn 9291: if (@posstypes) {
9292: foreach my $status (@posstypes) {
9293: my $rowid = $classprefix.$status;
9294: my $datarowstyle = 'display:none';
9295: if (grep(/^\Q$status\E$/,@ordered)) {
9296: $datarowstyle = $rowstyle;
9297: }
9298: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9299: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9300: $infotitles,$rowid,$customclass,$datarowstyle);
9301: unless ($datarowstyle eq 'display:none') {
9302: $$rowtotal ++;
9303: }
1.224 raeburn 9304: }
1.305 raeburn 9305: } else {
9306: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9307: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9308: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9309: }
9310: }
9311: return $datatable;
9312: }
9313:
1.305 raeburn 9314: sub selfcreate_javascript {
9315: return <<"ENDSCRIPT";
9316:
9317: <script type="text/javascript">
9318: // <![CDATA[
9319:
9320: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9321: var x = document.getElementsByClassName(target);
9322: var insttypes = 0;
9323: var insttypeRegExp = new RegExp(prefix);
9324: if ((x.length != undefined) && (x.length > 0)) {
9325: if (form.elements[radio].length != undefined) {
9326: for (var i=0; i<form.elements[radio].length; i++) {
9327: if (form.elements[radio][i].checked) {
9328: if (form.elements[radio][i].value == 1) {
9329: for (var j=0; j<x.length; j++) {
9330: if (x[j].id == 'undefined') {
9331: x[j].style.display = 'table-row';
9332: } else if (insttypeRegExp.test(x[j].id)) {
9333: insttypes ++;
9334: } else {
9335: x[j].style.display = 'table-row';
9336: }
9337: }
9338: } else {
9339: for (var j=0; j<x.length; j++) {
9340: x[j].style.display = 'none';
9341: }
1.236 raeburn 9342: }
1.305 raeburn 9343: break;
9344: }
9345: }
9346: if (insttypes > 0) {
9347: toggleDataRow(form,checkbox,target,altprefix);
9348: toggleDataRow(form,checkbox,target,prefix,1);
9349: }
9350: }
9351: }
9352: return;
9353: }
9354:
9355: function toggleDataRow(form,checkbox,target,prefix,docount) {
9356: if (form.elements[checkbox].length != undefined) {
9357: var count = 0;
9358: if (docount) {
9359: for (var i=0; i<form.elements[checkbox].length; i++) {
9360: if (form.elements[checkbox][i].checked) {
9361: count ++;
1.236 raeburn 9362: }
1.305 raeburn 9363: }
9364: }
9365: for (var i=0; i<form.elements[checkbox].length; i++) {
9366: var type = form.elements[checkbox][i].value;
9367: if (document.getElementById(prefix+type)) {
9368: if (form.elements[checkbox][i].checked) {
9369: document.getElementById(prefix+type).style.display = 'table-row';
9370: if (count % 2 == 1) {
9371: document.getElementById(prefix+type).className = target+' LC_odd_row';
9372: } else {
9373: document.getElementById(prefix+type).className = target;
1.236 raeburn 9374: }
1.305 raeburn 9375: count ++;
1.236 raeburn 9376: } else {
1.305 raeburn 9377: document.getElementById(prefix+type).style.display = 'none';
9378: }
9379: }
9380: }
9381: }
9382: return;
9383: }
9384:
9385: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9386: var caller = radio+'_'+status;
9387: if (form.elements[caller].length != undefined) {
9388: for (var i=0; i<form.elements[caller].length; i++) {
9389: if (form.elements[caller][i].checked) {
9390: if (document.getElementById(altprefix+'_inst_'+status)) {
9391: var curr = form.elements[caller][i].value;
9392: if (prefix) {
9393: document.getElementById(prefix+'_'+status).style.display = 'none';
9394: }
9395: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9396: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9397: if (curr == 'custom') {
9398: if (prefix) {
9399: document.getElementById(prefix+'_'+status).style.display = 'inline';
9400: }
9401: } else if (curr == 'inst') {
9402: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9403: } else if (curr == 'noninst') {
9404: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9405: }
1.305 raeburn 9406: break;
1.236 raeburn 9407: }
9408: }
9409: }
9410: }
9411: }
9412:
1.305 raeburn 9413: // ]]>
9414: </script>
9415:
9416: ENDSCRIPT
9417: }
9418:
9419: sub noninst_users {
9420: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9421: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9422: my $class = 'LC_left_item';
9423: if ($css_class) {
9424: $css_class = ' class="'.$css_class.'"';
9425: }
9426: if ($rowid) {
9427: $rowid = ' id="'.$rowid.'"';
9428: }
9429: if ($rowstyle) {
9430: $rowstyle = ' style="'.$rowstyle.'"';
9431: }
9432: my ($output,$description);
9433: if ($type eq 'default') {
9434: $description = &mt('Requests for: [_1]',$typetitle);
9435: } else {
9436: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9437: }
9438: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9439: "<td>$description</td>\n".
9440: '<td class="'.$class.'" colspan="2">'.
9441: '<table><tr>';
9442: my %headers = &Apache::lonlocal::texthash(
9443: approve => 'Processing',
9444: email => 'E-mail',
9445: username => 'Username',
9446: );
9447: foreach my $item ('approve','email','username') {
9448: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9449: }
1.305 raeburn 9450: $output .= '</tr><tr>';
9451: foreach my $item ('approve','email','username') {
1.306 raeburn 9452: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9453: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9454: if ($item eq 'approve') {
9455: %choices = &Apache::lonlocal::texthash (
9456: automatic => 'Automatically approved',
9457: approval => 'Queued for approval',
9458: );
9459: @options = ('automatic','approval');
9460: $hashref = $processing;
9461: $defoption = 'automatic';
9462: $name = 'cancreate_emailprocess_'.$type;
9463: } elsif ($item eq 'email') {
9464: %choices = &Apache::lonlocal::texthash (
9465: any => 'Any e-mail',
9466: inst => 'Institutional only',
9467: noninst => 'Non-institutional only',
9468: custom => 'Custom restrictions',
9469: );
9470: @options = ('any','inst','noninst');
9471: my $showcustom;
9472: if (ref($emailrules) eq 'HASH') {
9473: if (keys(%{$emailrules}) > 0) {
9474: push(@options,'custom');
9475: $showcustom = 'cancreate_emailrule';
9476: if (ref($settings) eq 'HASH') {
9477: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9478: foreach my $rule (@{$settings->{'email_rule'}}) {
9479: if (exists($emailrules->{$rule})) {
9480: $hascustom ++;
9481: }
9482: }
9483: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9484: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9485: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9486: if (exists($emailrules->{$rule})) {
9487: $hascustom ++;
9488: }
9489: }
9490: }
9491: }
9492: }
9493: }
9494: }
9495: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9496: "'cancreate_emaildomain','$type'".');"';
9497: $hashref = $emailoptions;
9498: $defoption = 'any';
9499: $name = 'cancreate_emailoptions_'.$type;
9500: } elsif ($item eq 'username') {
9501: %choices = &Apache::lonlocal::texthash (
9502: all => 'Same as e-mail',
9503: first => 'Omit @domain',
9504: free => 'Free to choose',
9505: );
9506: @options = ('all','first','free');
9507: $hashref = $emailverified;
9508: $defoption = 'all';
9509: $name = 'cancreate_usernameoptions_'.$type;
9510: }
9511: foreach my $option (@options) {
9512: my $checked;
9513: if (ref($hashref) eq 'HASH') {
9514: if ($type eq '') {
9515: if (!exists($hashref->{'default'})) {
9516: if ($option eq $defoption) {
9517: $checked = ' checked="checked"';
9518: }
9519: } else {
9520: if ($hashref->{'default'} eq $option) {
9521: $checked = ' checked="checked"';
9522: }
1.303 raeburn 9523: }
9524: } else {
1.305 raeburn 9525: if (!exists($hashref->{$type})) {
9526: if ($option eq $defoption) {
9527: $checked = ' checked="checked"';
9528: }
9529: } else {
9530: if ($hashref->{$type} eq $option) {
9531: $checked = ' checked="checked"';
9532: }
1.303 raeburn 9533: }
9534: }
1.305 raeburn 9535: } elsif (($item eq 'email') && ($hascustom)) {
9536: if ($option eq 'custom') {
9537: $checked = ' checked="checked"';
9538: }
9539: } elsif ($option eq $defoption) {
9540: $checked = ' checked="checked"';
9541: }
9542: $output .= '<span class="LC_nobreak"><label>'.
9543: '<input type="radio" name="'.$name.'"'.
9544: $checked.' value="'.$option.'"'.$onclick.' />'.
9545: $choices{$option}.'</label></span><br />';
9546: if ($item eq 'email') {
9547: if ($option eq 'custom') {
9548: my $id = 'cancreate_emailrule_'.$type;
9549: my $display = 'none';
9550: if ($checked) {
9551: $display = 'inline';
1.303 raeburn 9552: }
1.305 raeburn 9553: my $numinrow = 2;
9554: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9555: '<legend>'.&mt('Disallow').'</legend><table>'.
9556: &user_formats_row('email',$settings,$emailrules,
9557: $emailruleorder,$numinrow,'',$type);
9558: '</table></fieldset>';
9559: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9560: my %text = &Apache::lonlocal::texthash (
9561: inst => 'must end:',
9562: noninst => 'cannot end:',
9563: );
9564: my $value;
9565: if (ref($emaildomain) eq 'HASH') {
9566: if (ref($emaildomain->{$type}) eq 'HASH') {
9567: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9568: }
9569: }
1.305 raeburn 9570: if ($value eq '') {
9571: $value = '@'.$intdom;
9572: }
9573: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9574: my $display = 'none';
9575: if ($checked) {
9576: $display = 'inline';
9577: }
9578: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9579: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9580: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9581: '</div>';
1.303 raeburn 9582: }
9583: }
9584: }
1.305 raeburn 9585: $output .= '</td>'."\n";
1.303 raeburn 9586: }
1.305 raeburn 9587: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9588: return $output;
9589: }
9590:
1.165 raeburn 9591: sub captcha_choice {
1.305 raeburn 9592: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9593: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9594: $vertext,$currver);
1.165 raeburn 9595: my %lt = &captcha_phrases();
9596: $keyentry = 'hidden';
1.354 raeburn 9597: my $colspan=2;
1.165 raeburn 9598: if ($context eq 'cancreate') {
1.224 raeburn 9599: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9600: } elsif ($context eq 'login') {
9601: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9602: } elsif ($context eq 'passwords') {
9603: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9604: $colspan=1;
1.165 raeburn 9605: }
9606: if (ref($settings) eq 'HASH') {
9607: if ($settings->{'captcha'}) {
9608: $checked{$settings->{'captcha'}} = ' checked="checked"';
9609: } else {
9610: $checked{'original'} = ' checked="checked"';
9611: }
9612: if ($settings->{'captcha'} eq 'recaptcha') {
9613: $pubtext = $lt{'pub'};
9614: $privtext = $lt{'priv'};
9615: $keyentry = 'text';
1.269 raeburn 9616: $vertext = $lt{'ver'};
9617: $currver = $settings->{'recaptchaversion'};
9618: if ($currver ne '2') {
9619: $currver = 1;
9620: }
1.165 raeburn 9621: }
9622: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9623: $currpub = $settings->{'recaptchakeys'}{'public'};
9624: $currpriv = $settings->{'recaptchakeys'}{'private'};
9625: }
9626: } else {
9627: $checked{'original'} = ' checked="checked"';
9628: }
1.305 raeburn 9629: my $css_class;
9630: if ($itemcount%2) {
9631: $css_class = 'LC_odd_row';
9632: }
9633: if ($customcss) {
9634: $css_class .= " $customcss";
9635: }
9636: $css_class =~ s/^\s+//;
9637: if ($css_class) {
9638: $css_class = ' class="'.$css_class.'"';
9639: }
9640: if ($rowstyle) {
9641: $css_class .= ' style="'.$rowstyle.'"';
9642: }
1.169 raeburn 9643: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9644: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9645: '<table><tr><td>'."\n";
9646: foreach my $option ('original','recaptcha','notused') {
9647: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9648: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9649: $lt{$option}.'</label></span>';
9650: unless ($option eq 'notused') {
9651: $output .= (' 'x2)."\n";
9652: }
9653: }
9654: #
9655: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9656: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9657: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9658: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9659: #
1.165 raeburn 9660: $output .= '</td></tr>'."\n".
1.305 raeburn 9661: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9662: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9663: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9664: $currpub.'" size="40" /></span><br />'."\n".
9665: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9666: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9667: $currpriv.'" size="40" /></span><br />'.
9668: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9669: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9670: $currver.'" size="3" /></span><br />'.
9671: '</td></tr></table>'."\n".
1.165 raeburn 9672: '</td></tr>';
9673: return $output;
9674: }
9675:
1.32 raeburn 9676: sub user_formats_row {
1.305 raeburn 9677: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9678: my $output;
9679: my %text = (
9680: 'username' => 'new usernames',
9681: 'id' => 'IDs',
9682: );
1.305 raeburn 9683: unless ($type eq 'email') {
9684: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9685: $output = '<tr '.$css_class.'>'.
9686: '<td><span class="LC_nobreak">'.
9687: &mt("Format rules to check for $text{$type}: ").
9688: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9689: }
1.27 raeburn 9690: my $rem;
9691: if (ref($ruleorder) eq 'ARRAY') {
9692: for (my $i=0; $i<@{$ruleorder}; $i++) {
9693: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9694: my $rem = $i%($numinrow);
9695: if ($rem == 0) {
9696: if ($i > 0) {
9697: $output .= '</tr>';
9698: }
9699: $output .= '<tr>';
9700: }
9701: my $check = ' ';
1.39 raeburn 9702: if (ref($settings) eq 'HASH') {
9703: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9704: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9705: $check = ' checked="checked" ';
9706: }
1.305 raeburn 9707: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9708: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9709: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9710: $check = ' checked="checked" ';
9711: }
9712: }
1.27 raeburn 9713: }
9714: }
1.305 raeburn 9715: my $name = $type.'_rule';
9716: if ($type eq 'email') {
9717: $name .= '_'.$status;
9718: }
1.27 raeburn 9719: $output .= '<td class="LC_left_item">'.
9720: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9721: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9722: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9723: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9724: }
9725: }
9726: $rem = @{$ruleorder}%($numinrow);
9727: }
1.305 raeburn 9728: my $colsleft;
9729: if ($rem) {
9730: $colsleft = $numinrow - $rem;
9731: }
1.27 raeburn 9732: if ($colsleft > 1 ) {
9733: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9734: ' </td>';
9735: } elsif ($colsleft == 1) {
9736: $output .= '<td class="LC_left_item"> </td>';
9737: }
1.305 raeburn 9738: $output .= '</tr></table>';
9739: unless ($type eq 'email') {
9740: $output .= '</td></tr>';
9741: }
1.27 raeburn 9742: return $output;
9743: }
9744:
1.34 raeburn 9745: sub usercreation_types {
9746: my %lt = &Apache::lonlocal::texthash (
9747: author => 'When adding a co-author',
9748: course => 'When adding a user to a course',
1.100 raeburn 9749: requestcrs => 'When requesting a course',
1.34 raeburn 9750: any => 'Any',
9751: official => 'Institutional only ',
9752: unofficial => 'Non-institutional only',
9753: none => 'None',
9754: );
9755: return %lt;
1.48 raeburn 9756: }
1.34 raeburn 9757:
1.224 raeburn 9758: sub selfcreation_types {
9759: my %lt = &Apache::lonlocal::texthash (
9760: selfcreate => 'User creates own account',
9761: any => 'Any',
9762: official => 'Institutional only ',
9763: unofficial => 'Non-institutional only',
9764: email => 'E-mail address',
9765: login => 'Institutional Login',
9766: sso => 'SSO',
9767: );
9768: }
9769:
1.28 raeburn 9770: sub authtype_names {
9771: my %lt = &Apache::lonlocal::texthash(
9772: int => 'Internal',
9773: krb4 => 'Kerberos 4',
9774: krb5 => 'Kerberos 5',
9775: loc => 'Local',
1.325 raeburn 9776: lti => 'LTI',
1.28 raeburn 9777: );
9778: return %lt;
9779: }
9780:
9781: sub context_names {
9782: my %context_title = &Apache::lonlocal::texthash(
9783: author => 'Creating users when an Author',
9784: course => 'Creating users when in a course',
9785: domain => 'Creating users when a Domain Coordinator',
9786: );
9787: return %context_title;
9788: }
9789:
1.33 raeburn 9790: sub print_usermodification {
9791: my ($position,$dom,$settings,$rowtotal) = @_;
9792: my $numinrow = 4;
9793: my ($context,$datatable,$rowcount);
9794: if ($position eq 'top') {
9795: $rowcount = 0;
9796: $context = 'author';
9797: foreach my $role ('ca','aa') {
9798: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9799: $numinrow,$rowcount);
9800: $$rowtotal ++;
9801: $rowcount ++;
9802: }
1.230 raeburn 9803: } elsif ($position eq 'bottom') {
1.33 raeburn 9804: $context = 'course';
9805: $rowcount = 0;
9806: foreach my $role ('st','ep','ta','in','cr') {
9807: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9808: $numinrow,$rowcount);
9809: $$rowtotal ++;
9810: $rowcount ++;
9811: }
9812: }
9813: return $datatable;
9814: }
9815:
1.43 raeburn 9816: sub print_defaults {
1.236 raeburn 9817: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9818: my $rownum = 0;
1.294 raeburn 9819: my ($datatable,$css_class,$titles);
9820: unless ($position eq 'bottom') {
9821: $titles = &defaults_titles($dom);
9822: }
1.236 raeburn 9823: if ($position eq 'top') {
9824: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9825: 'datelocale_def','portal_def');
9826: my %defaults;
9827: if (ref($settings) eq 'HASH') {
9828: %defaults = %{$settings};
1.43 raeburn 9829: } else {
1.236 raeburn 9830: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9831: foreach my $item (@items) {
9832: $defaults{$item} = $domdefaults{$item};
9833: }
1.43 raeburn 9834: }
1.236 raeburn 9835: foreach my $item (@items) {
9836: if ($rownum%2) {
9837: $css_class = '';
9838: } else {
9839: $css_class = ' class="LC_odd_row" ';
9840: }
9841: $datatable .= '<tr'.$css_class.'>'.
9842: '<td><span class="LC_nobreak">'.$titles->{$item}.
9843: '</span></td><td class="LC_right_item" colspan="3">';
9844: if ($item eq 'auth_def') {
1.325 raeburn 9845: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9846: my %shortauth = (
9847: internal => 'int',
9848: krb4 => 'krb4',
9849: krb5 => 'krb5',
1.325 raeburn 9850: localauth => 'loc',
9851: lti => 'lti',
1.236 raeburn 9852: );
9853: my %authnames = &authtype_names();
9854: foreach my $auth (@authtypes) {
9855: my $checked = ' ';
9856: if ($defaults{$item} eq $auth) {
9857: $checked = ' checked="checked" ';
9858: }
9859: $datatable .= '<label><input type="radio" name="'.$item.
9860: '" value="'.$auth.'"'.$checked.'/>'.
9861: $authnames{$shortauth{$auth}}.'</label> ';
9862: }
9863: } elsif ($item eq 'timezone_def') {
9864: my $includeempty = 1;
9865: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9866: } elsif ($item eq 'datelocale_def') {
9867: my $includeempty = 1;
9868: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9869: } elsif ($item eq 'lang_def') {
1.263 raeburn 9870: my $includeempty = 1;
9871: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9872: } else {
9873: my $size;
9874: if ($item eq 'portal_def') {
9875: $size = ' size="25"';
9876: }
9877: $datatable .= '<input type="text" name="'.$item.'" value="'.
9878: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9879: }
1.236 raeburn 9880: $datatable .= '</td></tr>';
9881: $rownum ++;
9882: }
1.354 raeburn 9883: } else {
1.294 raeburn 9884: my %defaults;
9885: if (ref($settings) eq 'HASH') {
1.354 raeburn 9886: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9887: my $maxnum = @{$settings->{'inststatusorder'}};
9888: for (my $i=0; $i<$maxnum; $i++) {
9889: $css_class = $rownum%2?' class="LC_odd_row"':'';
9890: my $item = $settings->{'inststatusorder'}->[$i];
9891: my $title = $settings->{'inststatustypes'}->{$item};
9892: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9893: $datatable .= '<tr'.$css_class.'>'.
9894: '<td><span class="LC_nobreak">'.
9895: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9896: for (my $k=0; $k<=$maxnum; $k++) {
9897: my $vpos = $k+1;
9898: my $selstr;
9899: if ($k == $i) {
9900: $selstr = ' selected="selected" ';
9901: }
9902: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9903: }
9904: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9905: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9906: &mt('delete').'</span></td>'.
1.380 raeburn 9907: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 9908: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9909: '</span></td></tr>';
9910: }
9911: $css_class = $rownum%2?' class="LC_odd_row"':'';
9912: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9913: $datatable .= '<tr '.$css_class.'>'.
9914: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9915: for (my $k=0; $k<=$maxnum; $k++) {
9916: my $vpos = $k+1;
9917: my $selstr;
9918: if ($k == $maxnum) {
9919: $selstr = ' selected="selected" ';
9920: }
9921: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9922: }
9923: $datatable .= '</select> '.&mt('Internal ID:').
9924: '<input type="text" size="10" name="addinststatus" value="" />'.
9925: ' '.&mt('(new)').
9926: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 9927: &mt('Name displayed').':'.
1.354 raeburn 9928: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9929: '</tr>'."\n";
9930: $rownum ++;
1.294 raeburn 9931: }
1.354 raeburn 9932: }
9933: }
9934: $$rowtotal += $rownum;
1.43 raeburn 9935: return $datatable;
9936: }
9937:
1.168 raeburn 9938: sub get_languages_hash {
9939: my %langchoices;
9940: foreach my $id (&Apache::loncommon::languageids()) {
9941: my $code = &Apache::loncommon::supportedlanguagecode($id);
9942: if ($code ne '') {
9943: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9944: }
9945: }
9946: return %langchoices;
9947: }
9948:
1.43 raeburn 9949: sub defaults_titles {
1.141 raeburn 9950: my ($dom) = @_;
1.43 raeburn 9951: my %titles = &Apache::lonlocal::texthash (
9952: 'auth_def' => 'Default authentication type',
9953: 'auth_arg_def' => 'Default authentication argument',
9954: 'lang_def' => 'Default language',
1.54 raeburn 9955: 'timezone_def' => 'Default timezone',
1.68 raeburn 9956: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9957: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 9958: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9959: 'intauth_check' => 'Check bcrypt cost if authenticated',
9960: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9961: );
1.141 raeburn 9962: if ($dom) {
9963: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9964: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9965: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9966: $protocol = 'http' if ($protocol ne 'https');
9967: if ($uint_dom) {
9968: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9969: $uint_dom);
9970: }
9971: }
1.43 raeburn 9972: return (\%titles);
9973: }
9974:
1.346 raeburn 9975: sub print_scantron {
9976: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9977: if ($position eq 'top') {
9978: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9979: } else {
9980: return &print_scantronconfig($dom,$settings,\$rowtotal);
9981: }
9982: }
9983:
9984: sub scantron_javascript {
9985: return <<"ENDSCRIPT";
9986:
9987: <script type="text/javascript">
9988: // <![CDATA[
9989:
9990: function toggleScantron(form) {
1.347 raeburn 9991: var csvfieldset = new Array();
1.346 raeburn 9992: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 9993: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9994: }
9995: if (document.getElementById('scantroncsv_options')) {
9996: csvfieldset.push(document.getElementById('scantroncsv_options'));
9997: }
9998: if (csvfieldset.length) {
1.346 raeburn 9999: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10000: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10001: if (scantroncsv.checked) {
1.347 raeburn 10002: for (var i=0; i<csvfieldset.length; i++) {
10003: csvfieldset[i].style.display = 'block';
10004: }
1.346 raeburn 10005: } else {
1.347 raeburn 10006: for (var i=0; i<csvfieldset.length; i++) {
10007: csvfieldset[i].style.display = 'none';
10008: }
1.346 raeburn 10009: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10010: if (csvselects.length) {
10011: for (var j=0; j<csvselects.length; j++) {
10012: csvselects[j].selectedIndex = 0;
10013: }
10014: }
10015: }
10016: }
10017: }
10018: return;
10019: }
10020: // ]]>
10021: </script>
10022:
10023: ENDSCRIPT
10024:
10025: }
10026:
1.46 raeburn 10027: sub print_scantronformat {
10028: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10029: my $itemcount = 1;
1.60 raeburn 10030: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10031: %confhash);
1.46 raeburn 10032: my $switchserver = &check_switchserver($dom,$confname);
10033: my %lt = &Apache::lonlocal::texthash (
1.95 www 10034: default => 'Default bubblesheet format file error',
10035: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10036: );
10037: my %scantronfiles = (
10038: default => 'default.tab',
10039: custom => 'custom.tab',
10040: );
10041: foreach my $key (keys(%scantronfiles)) {
10042: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10043: .$scantronfiles{$key};
10044: }
10045: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10046: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10047: if (!$switchserver) {
10048: my $servadm = $r->dir_config('lonAdmEMail');
10049: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10050: if ($configuserok eq 'ok') {
10051: if ($author_ok eq 'ok') {
10052: my %legacyfile = (
1.346 raeburn 10053: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10054: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10055: );
10056: my %md5chk;
10057: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10058: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10059: chomp($md5chk{$type});
1.46 raeburn 10060: }
10061: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10062: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10063: ($scantronurls{$type},my $error) =
1.46 raeburn 10064: &legacy_scantronformat($r,$dom,$confname,
10065: $type,$legacyfile{$type},
10066: $scantronurls{$type},
10067: $scantronfiles{$type});
1.60 raeburn 10068: if ($error ne '') {
10069: $error{$type} = $error;
10070: }
10071: }
10072: if (keys(%error) == 0) {
10073: $is_custom = 1;
1.346 raeburn 10074: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10075: $scantronurls{'custom'};
1.346 raeburn 10076: my $putresult =
1.60 raeburn 10077: &Apache::lonnet::put_dom('configuration',
10078: \%confhash,$dom);
10079: if ($putresult ne 'ok') {
1.346 raeburn 10080: $error{'custom'} =
1.60 raeburn 10081: '<span class="LC_error">'.
10082: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10083: }
1.46 raeburn 10084: }
10085: } else {
1.60 raeburn 10086: ($scantronurls{'default'},my $error) =
1.46 raeburn 10087: &legacy_scantronformat($r,$dom,$confname,
10088: 'default',$legacyfile{'default'},
10089: $scantronurls{'default'},
10090: $scantronfiles{'default'});
1.60 raeburn 10091: if ($error eq '') {
10092: $confhash{'scantron'}{'scantronformat'} = '';
10093: my $putresult =
10094: &Apache::lonnet::put_dom('configuration',
10095: \%confhash,$dom);
10096: if ($putresult ne 'ok') {
10097: $error{'default'} =
10098: '<span class="LC_error">'.
10099: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10100: }
10101: } else {
10102: $error{'default'} = $error;
10103: }
1.46 raeburn 10104: }
10105: }
10106: }
10107: } else {
1.95 www 10108: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10109: }
10110: }
10111: if (ref($settings) eq 'HASH') {
10112: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10113: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10114: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10115: $scantronurl = '';
10116: } else {
10117: $scantronurl = $settings->{'scantronformat'};
10118: }
10119: $is_custom = 1;
10120: } else {
10121: $scantronurl = $scantronurls{'default'};
10122: }
10123: } else {
1.60 raeburn 10124: if ($is_custom) {
10125: $scantronurl = $scantronurls{'custom'};
10126: } else {
10127: $scantronurl = $scantronurls{'default'};
10128: }
1.46 raeburn 10129: }
10130: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10131: $datatable .= '<tr'.$css_class.'>';
10132: if (!$is_custom) {
1.65 raeburn 10133: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10134: '<span class="LC_nobreak">';
1.46 raeburn 10135: if ($scantronurl) {
1.199 raeburn 10136: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10137: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10138: } else {
10139: $datatable = &mt('File unavailable for display');
10140: }
1.65 raeburn 10141: $datatable .= '</span></td>';
1.60 raeburn 10142: if (keys(%error) == 0) {
1.306 raeburn 10143: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10144: if (!$switchserver) {
10145: $datatable .= &mt('Upload:').'<br />';
10146: }
10147: } else {
10148: my $errorstr;
10149: foreach my $key (sort(keys(%error))) {
10150: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10151: }
10152: $datatable .= '<td>'.$errorstr;
10153: }
1.46 raeburn 10154: } else {
10155: if (keys(%error) > 0) {
10156: my $errorstr;
10157: foreach my $key (sort(keys(%error))) {
10158: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10159: }
1.60 raeburn 10160: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10161: } elsif ($scantronurl) {
1.199 raeburn 10162: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10163: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10164: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10165: $link.
10166: '<label><input type="checkbox" name="scantronformat_del"'.
10167: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10168: '<td><span class="LC_nobreak"> '.
10169: &mt('Replace:').'</span><br />';
1.46 raeburn 10170: }
10171: }
10172: if (keys(%error) == 0) {
10173: if ($switchserver) {
10174: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10175: } else {
1.65 raeburn 10176: $datatable .='<span class="LC_nobreak"> '.
10177: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10178: }
10179: }
10180: $datatable .= '</td></tr>';
10181: $$rowtotal ++;
10182: return $datatable;
10183: }
10184:
10185: sub legacy_scantronformat {
10186: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10187: my ($url,$error);
10188: my @statinfo = &Apache::lonnet::stat_file($newurl);
10189: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
10190: (my $result,$url) =
10191: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
10192: '','',$newfile);
10193: if ($result ne 'ok') {
1.130 raeburn 10194: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10195: }
10196: }
10197: return ($url,$error);
10198: }
1.43 raeburn 10199:
1.346 raeburn 10200: sub print_scantronconfig {
10201: my ($dom,$settings,$rowtotal) = @_;
10202: my $itemcount = 2;
10203: my $is_checked = ' checked="checked"';
1.347 raeburn 10204: my %optionson = (
10205: hdr => ' checked="checked"',
10206: pad => ' checked="checked"',
10207: rem => ' checked="checked"',
10208: );
10209: my %optionsoff = (
10210: hdr => '',
10211: pad => '',
10212: rem => '',
10213: );
1.346 raeburn 10214: my $currcsvsty = 'none';
1.347 raeburn 10215: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10216: my @fields = &scantroncsv_fields();
10217: my %titles = &scantronconfig_titles();
10218: if (ref($settings) eq 'HASH') {
10219: if (ref($settings->{config}) eq 'HASH') {
10220: if ($settings->{config}->{dat}) {
10221: $checked{'dat'} = $is_checked;
10222: }
10223: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10224: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10225: %csvfields = %{$settings->{config}->{csv}->{fields}};
10226: if (keys(%csvfields) > 0) {
10227: $checked{'csv'} = $is_checked;
10228: $currcsvsty = 'block';
10229: }
10230: }
10231: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10232: %csvoptions = %{$settings->{config}->{csv}->{options}};
10233: foreach my $option (keys(%optionson)) {
10234: unless ($csvoptions{$option}) {
10235: $optionsoff{$option} = $optionson{$option};
10236: $optionson{$option} = '';
10237: }
10238: }
1.346 raeburn 10239: }
10240: }
10241: } else {
10242: $checked{'dat'} = $is_checked;
10243: }
10244: } else {
10245: $checked{'dat'} = $is_checked;
10246: }
10247: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10248: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10249: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10250: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10251: foreach my $item ('dat','csv') {
10252: my $id;
10253: if ($item eq 'csv') {
10254: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10255: }
1.346 raeburn 10256: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10257: $titles{$item}.'</label>'.(' 'x3);
10258: if ($item eq 'csv') {
10259: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10260: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10261: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10262: foreach my $col (@fields) {
10263: my $selnone;
10264: if ($csvfields{$col} eq '') {
10265: $selnone = ' selected="selected"';
10266: }
10267: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10268: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10269: '<option value=""'.$selnone.'></option>';
10270: for (my $i=0; $i<20; $i++) {
10271: my $shown = $i+1;
10272: my $sel;
10273: unless ($selnone) {
10274: if (exists($csvfields{$col})) {
10275: if ($csvfields{$col} == $i) {
10276: $sel = ' selected="selected"';
10277: }
10278: }
10279: }
10280: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10281: }
10282: $datatable .= '</select></td></tr>';
10283: }
1.347 raeburn 10284: $datatable .= '</table></fieldset>'.
10285: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10286: '<legend>'.&mt('CSV Options').'</legend>';
10287: foreach my $option ('hdr','pad','rem') {
10288: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10289: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10290: &mt('Yes').'</label>'.(' 'x2)."\n".
10291: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10292: }
10293: $datatable .= '</fieldset>';
1.346 raeburn 10294: $itemcount ++;
10295: }
10296: }
10297: $datatable .= '</td></tr>';
10298: $$rowtotal ++;
10299: return $datatable;
10300: }
10301:
10302: sub scantronconfig_titles {
10303: return &Apache::lonlocal::texthash(
10304: dat => 'Standard format (.dat)',
10305: csv => 'Comma separated values (.csv)',
1.347 raeburn 10306: hdr => 'Remove first line in file (contains column titles)',
10307: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10308: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10309: CODE => 'CODE',
10310: ID => 'Student ID',
10311: PaperID => 'Paper ID',
10312: FirstName => 'First Name',
10313: LastName => 'Last Name',
10314: FirstQuestion => 'First Question Response',
10315: Section => 'Section',
10316: );
10317: }
10318:
10319: sub scantroncsv_fields {
10320: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10321: }
10322:
1.49 raeburn 10323: sub print_coursecategories {
1.57 raeburn 10324: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10325: my $datatable;
10326: if ($position eq 'top') {
1.238 raeburn 10327: my (%checked);
10328: my @catitems = ('unauth','auth');
10329: my @cattypes = ('std','domonly','codesrch','none');
10330: $checked{'unauth'} = 'std';
10331: $checked{'auth'} = 'std';
10332: if (ref($settings) eq 'HASH') {
10333: foreach my $type (@cattypes) {
10334: if ($type eq $settings->{'unauth'}) {
10335: $checked{'unauth'} = $type;
10336: }
10337: if ($type eq $settings->{'auth'}) {
10338: $checked{'auth'} = $type;
10339: }
10340: }
10341: }
10342: my %lt = &Apache::lonlocal::texthash (
10343: unauth => 'Catalog type for unauthenticated users',
10344: auth => 'Catalog type for authenticated users',
10345: none => 'No catalog',
10346: std => 'Standard catalog',
10347: domonly => 'Domain-only catalog',
10348: codesrch => "Code search form",
10349: );
10350: my $itemcount = 0;
10351: foreach my $item (@catitems) {
10352: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10353: $datatable .= '<tr '.$css_class.'>'.
10354: '<td>'.$lt{$item}.'</td>'.
10355: '<td class="LC_right_item"><span class="LC_nobreak">';
10356: foreach my $type (@cattypes) {
10357: my $ischecked;
10358: if ($checked{$item} eq $type) {
10359: $ischecked=' checked="checked"';
10360: }
10361: $datatable .= '<label>'.
10362: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10363: ' />'.$lt{$type}.'</label> ';
10364: }
1.327 raeburn 10365: $datatable .= '</span></td></tr>';
1.238 raeburn 10366: $itemcount ++;
10367: }
10368: $$rowtotal += $itemcount;
10369: } elsif ($position eq 'middle') {
1.57 raeburn 10370: my $toggle_cats_crs = ' ';
10371: my $toggle_cats_dom = ' checked="checked" ';
10372: my $can_cat_crs = ' ';
10373: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10374: my $toggle_catscomm_comm = ' ';
10375: my $toggle_catscomm_dom = ' checked="checked" ';
10376: my $can_catcomm_comm = ' ';
10377: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10378: my $toggle_catsplace_place = ' ';
10379: my $toggle_catsplace_dom = ' checked="checked" ';
10380: my $can_catplace_place = ' ';
10381: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10382:
1.57 raeburn 10383: if (ref($settings) eq 'HASH') {
10384: if ($settings->{'togglecats'} eq 'crs') {
10385: $toggle_cats_crs = $toggle_cats_dom;
10386: $toggle_cats_dom = ' ';
10387: }
10388: if ($settings->{'categorize'} eq 'crs') {
10389: $can_cat_crs = $can_cat_dom;
10390: $can_cat_dom = ' ';
10391: }
1.120 raeburn 10392: if ($settings->{'togglecatscomm'} eq 'comm') {
10393: $toggle_catscomm_comm = $toggle_catscomm_dom;
10394: $toggle_catscomm_dom = ' ';
10395: }
10396: if ($settings->{'categorizecomm'} eq 'comm') {
10397: $can_catcomm_comm = $can_catcomm_dom;
10398: $can_catcomm_dom = ' ';
10399: }
1.272 raeburn 10400: if ($settings->{'togglecatsplace'} eq 'place') {
10401: $toggle_catsplace_place = $toggle_catsplace_dom;
10402: $toggle_catsplace_dom = ' ';
10403: }
10404: if ($settings->{'categorizeplace'} eq 'place') {
10405: $can_catplace_place = $can_catplace_dom;
10406: $can_catplace_dom = ' ';
10407: }
1.57 raeburn 10408: }
10409: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10410: togglecats => 'Show/Hide a course in catalog',
10411: togglecatscomm => 'Show/Hide a community in catalog',
10412: togglecatsplace => 'Show/Hide a placement test in catalog',
10413: categorize => 'Assign a category to a course',
10414: categorizecomm => 'Assign a category to a community',
10415: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10416: );
10417: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10418: dom => 'Set in Domain',
10419: crs => 'Set in Course',
10420: comm => 'Set in Community',
10421: place => 'Set in Placement Test',
1.57 raeburn 10422: );
10423: $datatable = '<tr class="LC_odd_row">'.
10424: '<td>'.$title{'togglecats'}.'</td>'.
10425: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10426: '<input type="radio" name="togglecats"'.
10427: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10428: '<label><input type="radio" name="togglecats"'.
10429: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10430: '</tr><tr>'.
10431: '<td>'.$title{'categorize'}.'</td>'.
10432: '<td class="LC_right_item"><span class="LC_nobreak">'.
10433: '<label><input type="radio" name="categorize"'.
10434: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10435: '<label><input type="radio" name="categorize"'.
10436: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10437: '</tr><tr class="LC_odd_row">'.
10438: '<td>'.$title{'togglecatscomm'}.'</td>'.
10439: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10440: '<input type="radio" name="togglecatscomm"'.
10441: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10442: '<label><input type="radio" name="togglecatscomm"'.
10443: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10444: '</tr><tr>'.
10445: '<td>'.$title{'categorizecomm'}.'</td>'.
10446: '<td class="LC_right_item"><span class="LC_nobreak">'.
10447: '<label><input type="radio" name="categorizecomm"'.
10448: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10449: '<label><input type="radio" name="categorizecomm"'.
10450: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10451: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10452: '<td>'.$title{'togglecatsplace'}.'</td>'.
10453: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10454: '<input type="radio" name="togglecatsplace"'.
10455: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10456: '<label><input type="radio" name="togglecatscomm"'.
10457: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10458: '</tr><tr>'.
10459: '<td>'.$title{'categorizeplace'}.'</td>'.
10460: '<td class="LC_right_item"><span class="LC_nobreak">'.
10461: '<label><input type="radio" name="categorizeplace"'.
10462: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10463: '<label><input type="radio" name="categorizeplace"'.
10464: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10465: '</tr>';
1.272 raeburn 10466: $$rowtotal += 6;
1.57 raeburn 10467: } else {
10468: my $css_class;
10469: my $itemcount = 1;
10470: my $cathash;
10471: if (ref($settings) eq 'HASH') {
10472: $cathash = $settings->{'cats'};
10473: }
10474: if (ref($cathash) eq 'HASH') {
10475: my (@cats,@trails,%allitems,%idx,@jsarray);
10476: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10477: \%allitems,\%idx,\@jsarray);
10478: my $maxdepth = scalar(@cats);
10479: my $colattrib = '';
10480: if ($maxdepth > 2) {
10481: $colattrib = ' colspan="2" ';
10482: }
10483: my @path;
10484: if (@cats > 0) {
10485: if (ref($cats[0]) eq 'ARRAY') {
10486: my $numtop = @{$cats[0]};
10487: my $maxnum = $numtop;
1.120 raeburn 10488: my %default_names = (
10489: instcode => &mt('Official courses'),
10490: communities => &mt('Communities'),
1.272 raeburn 10491: placement => &mt('Placement Tests'),
1.120 raeburn 10492: );
10493:
10494: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10495: ($cathash->{'instcode::0'} eq '') ||
10496: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10497: ($cathash->{'communities::0'} eq '') ||
10498: (!grep(/^placement$/,@{$cats[0]})) ||
10499: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10500: $maxnum ++;
10501: }
10502: my $lastidx;
10503: for (my $i=0; $i<$numtop; $i++) {
10504: my $parent = $cats[0][$i];
10505: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10506: my $item = &escape($parent).'::0';
10507: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10508: $lastidx = $idx{$item};
10509: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10510: .'<select name="'.$item.'"'.$chgstr.'>';
10511: for (my $k=0; $k<=$maxnum; $k++) {
10512: my $vpos = $k+1;
10513: my $selstr;
10514: if ($k == $i) {
10515: $selstr = ' selected="selected" ';
10516: }
10517: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10518: }
1.214 raeburn 10519: $datatable .= '</select></span></td><td>';
1.272 raeburn 10520: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10521: $datatable .= '<span class="LC_nobreak">'
10522: .$default_names{$parent}.'</span>';
10523: if ($parent eq 'instcode') {
10524: $datatable .= '<br /><span class="LC_nobreak">('
10525: .&mt('with institutional codes')
10526: .')</span></td><td'.$colattrib.'>';
10527: } else {
10528: $datatable .= '<table><tr><td>';
10529: }
10530: $datatable .= '<span class="LC_nobreak">'
10531: .'<label><input type="radio" name="'
10532: .$parent.'" value="1" checked="checked" />'
10533: .&mt('Display').'</label>';
10534: if ($parent eq 'instcode') {
10535: $datatable .= ' ';
10536: } else {
10537: $datatable .= '</span></td></tr><tr><td>'
10538: .'<span class="LC_nobreak">';
10539: }
10540: $datatable .= '<label><input type="radio" name="'
10541: .$parent.'" value="0" />'
10542: .&mt('Do not display').'</label></span>';
1.272 raeburn 10543: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10544: $datatable .= '</td></tr></table>';
10545: }
10546: $datatable .= '</td>';
1.57 raeburn 10547: } else {
10548: $datatable .= $parent
1.214 raeburn 10549: .' <span class="LC_nobreak"><label>'
10550: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10551: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10552: }
10553: my $depth = 1;
10554: push(@path,$parent);
10555: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10556: pop(@path);
10557: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10558: $itemcount ++;
10559: }
1.48 raeburn 10560: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10561: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10562: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10563: for (my $k=0; $k<=$maxnum; $k++) {
10564: my $vpos = $k+1;
10565: my $selstr;
1.57 raeburn 10566: if ($k == $numtop) {
1.48 raeburn 10567: $selstr = ' selected="selected" ';
10568: }
10569: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10570: }
1.59 bisitz 10571: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10572: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10573: .'</tr>'."\n";
1.48 raeburn 10574: $itemcount ++;
1.272 raeburn 10575: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10576: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10577: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10578: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10579: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10580: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10581: for (my $k=0; $k<=$maxnum; $k++) {
10582: my $vpos = $k+1;
10583: my $selstr;
10584: if ($k == $maxnum) {
10585: $selstr = ' selected="selected" ';
10586: }
10587: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10588: }
1.120 raeburn 10589: $datatable .= '</select></span></td>'.
10590: '<td><span class="LC_nobreak">'.
10591: $default_names{$default}.'</span>';
10592: if ($default eq 'instcode') {
10593: $datatable .= '<br /><span class="LC_nobreak">('
10594: .&mt('with institutional codes').')</span>';
10595: }
10596: $datatable .= '</td>'
10597: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10598: .&mt('Display').'</label> '
10599: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10600: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10601: }
10602: }
10603: }
1.57 raeburn 10604: } else {
10605: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10606: }
10607: } else {
1.327 raeburn 10608: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10609: .&initialize_categories($itemcount);
1.48 raeburn 10610: }
1.57 raeburn 10611: $$rowtotal += $itemcount;
1.48 raeburn 10612: }
10613: return $datatable;
10614: }
10615:
1.69 raeburn 10616: sub print_serverstatuses {
10617: my ($dom,$settings,$rowtotal) = @_;
10618: my $datatable;
10619: my @pages = &serverstatus_pages();
10620: my (%namedaccess,%machineaccess);
10621: foreach my $type (@pages) {
10622: $namedaccess{$type} = '';
10623: $machineaccess{$type}= '';
10624: }
10625: if (ref($settings) eq 'HASH') {
10626: foreach my $type (@pages) {
10627: if (exists($settings->{$type})) {
10628: if (ref($settings->{$type}) eq 'HASH') {
10629: foreach my $key (keys(%{$settings->{$type}})) {
10630: if ($key eq 'namedusers') {
10631: $namedaccess{$type} = $settings->{$type}->{$key};
10632: } elsif ($key eq 'machines') {
10633: $machineaccess{$type} = $settings->{$type}->{$key};
10634: }
10635: }
10636: }
10637: }
10638: }
10639: }
1.81 raeburn 10640: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10641: my $rownum = 0;
10642: my $css_class;
10643: foreach my $type (@pages) {
10644: $rownum ++;
10645: $css_class = $rownum%2?' class="LC_odd_row"':'';
10646: $datatable .= '<tr'.$css_class.'>'.
10647: '<td><span class="LC_nobreak">'.
10648: $titles->{$type}.'</span></td>'.
10649: '<td class="LC_left_item">'.
10650: '<input type="text" name="'.$type.'_namedusers" '.
10651: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10652: '<td class="LC_right_item">'.
10653: '<span class="LC_nobreak">'.
10654: '<input type="text" name="'.$type.'_machines" '.
10655: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10656: '</span></td></tr>'."\n";
1.69 raeburn 10657: }
10658: $$rowtotal += $rownum;
10659: return $datatable;
10660: }
10661:
10662: sub serverstatus_pages {
10663: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10664: 'checksums','clusterstatus','certstatus','metadata_keywords',
10665: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10666: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10667: }
10668:
1.236 raeburn 10669: sub defaults_javascript {
10670: my ($settings) = @_;
1.354 raeburn 10671: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10672: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10673: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10674: if ($maxnum eq '') {
10675: $maxnum = 0;
10676: }
10677: $maxnum ++;
1.249 raeburn 10678: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10679: return <<"ENDSCRIPT";
10680: <script type="text/javascript">
10681: // <![CDATA[
10682: function reorderTypes(form,caller) {
10683: var changedVal;
10684: $jstext
10685: var newpos = 'addinststatus_pos';
10686: var current = new Array;
10687: var maxh = $maxnum;
10688: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10689: var oldVal;
10690: if (caller == newpos) {
10691: changedVal = newitemVal;
10692: } else {
10693: var curritem = 'inststatus_pos_'+caller;
10694: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10695: current[newitemVal] = newpos;
10696: }
10697: for (var i=0; i<inststatuses.length; i++) {
10698: if (inststatuses[i] != caller) {
10699: var elementName = 'inststatus_pos_'+inststatuses[i];
10700: if (form.elements[elementName]) {
10701: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10702: current[currVal] = elementName;
10703: }
10704: }
10705: }
10706: for (var j=0; j<maxh; j++) {
10707: if (current[j] == undefined) {
10708: oldVal = j;
10709: }
10710: }
10711: if (oldVal < changedVal) {
10712: for (var k=oldVal+1; k<=changedVal ; k++) {
10713: var elementName = current[k];
10714: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10715: }
10716: } else {
10717: for (var k=changedVal; k<oldVal; k++) {
10718: var elementName = current[k];
10719: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10720: }
10721: }
10722: return;
10723: }
10724:
10725: // ]]>
10726: </script>
10727:
10728: ENDSCRIPT
10729: }
1.354 raeburn 10730: return;
10731: }
10732:
10733: sub passwords_javascript {
1.365 raeburn 10734: my %intalert = &Apache::lonlocal::texthash (
10735: 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.',
10736: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10737: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10738: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10739: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10740: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10741: );
10742: &js_escape(\%intalert);
10743: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10744: my $intauthjs = <<"ENDSCRIPT";
10745:
10746: function warnIntAuth(field) {
10747: if (field.name == 'intauth_check') {
10748: if (field.value == '2') {
1.365 raeburn 10749: alert('$intalert{authcheck}');
1.354 raeburn 10750: }
10751: }
10752: if (field.name == 'intauth_cost') {
10753: field.value.replace(/\s/g,'');
10754: if (field.value != '') {
10755: var regexdigit=/^\\d+\$/;
10756: if (!regexdigit.test(field.value)) {
1.365 raeburn 10757: alert('$intalert{authcost}');
10758: }
10759: }
10760: }
10761: return;
10762: }
10763:
10764: function warnIntPass(field) {
10765: field.value.replace(/^\s+/,'');
10766: field.value.replace(/\s+\$/,'');
10767: var regexdigit=/^\\d+\$/;
10768: if (field.name == 'passwords_min') {
10769: if (field.value == '') {
10770: alert('$intalert{passmin}');
10771: field.value = '$defmin';
10772: } else {
10773: if (!regexdigit.test(field.value)) {
10774: alert('$intalert{passmin}');
10775: field.value = '$defmin';
10776: }
1.366 raeburn 10777: var minval = parseInt(field.value,10);
1.365 raeburn 10778: if (minval < $defmin) {
10779: alert('$intalert{passmin}');
10780: field.value = '$defmin';
10781: }
10782: }
10783: } else {
10784: if (field.value == '0') {
10785: field.value = '';
10786: }
10787: if (field.value != '') {
10788: if (field.name == 'passwords_expire') {
10789: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10790: if (!regexpposnum.test(field.value)) {
10791: alert('$intalert{passexp}');
10792: field.value = '';
10793: } else {
10794: var expval = parseFloat(field.value);
10795: if (expval == 0) {
10796: alert('$intalert{passexp}');
10797: field.value = '';
10798: }
10799: }
10800: } else {
10801: if (!regexdigit.test(field.value)) {
10802: if (field.name == 'passwords_max') {
10803: alert('$intalert{passmax}');
10804: } else {
10805: if (field.name == 'passwords_numsaved') {
10806: alert('$intalert{passnum}');
10807: }
10808: }
1.370 raeburn 10809: field.value = '';
1.365 raeburn 10810: }
1.354 raeburn 10811: }
10812: }
10813: }
10814: return;
10815: }
10816:
10817: ENDSCRIPT
10818: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10819: }
10820:
1.49 raeburn 10821: sub coursecategories_javascript {
10822: my ($settings) = @_;
1.57 raeburn 10823: my ($output,$jstext,$cathash);
1.49 raeburn 10824: if (ref($settings) eq 'HASH') {
1.57 raeburn 10825: $cathash = $settings->{'cats'};
10826: }
10827: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10828: my (@cats,@jsarray,%idx);
1.57 raeburn 10829: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10830: if (@jsarray > 0) {
10831: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10832: for (my $i=0; $i<@jsarray; $i++) {
10833: if (ref($jsarray[$i]) eq 'ARRAY') {
10834: my $catstr = join('","',@{$jsarray[$i]});
10835: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10836: }
10837: }
10838: }
10839: } else {
10840: $jstext = ' var categories = Array(1);'."\n".
10841: ' categories[0] = Array("instcode_pos");'."\n";
10842: }
1.237 bisitz 10843: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10844: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10845: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10846: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10847: &js_escape(\$instcode_reserved);
10848: &js_escape(\$communities_reserved);
1.272 raeburn 10849: &js_escape(\$placement_reserved);
1.265 damieng 10850: &js_escape(\$choose_again);
1.49 raeburn 10851: $output = <<"ENDSCRIPT";
10852: <script type="text/javascript">
1.109 raeburn 10853: // <![CDATA[
1.49 raeburn 10854: function reorderCats(form,parent,item,idx) {
10855: var changedVal;
10856: $jstext
10857: var newpos = 'addcategory_pos';
10858: if (parent == '') {
10859: var has_instcode = 0;
10860: var maxtop = categories[idx].length;
10861: for (var j=0; j<maxtop; j++) {
10862: if (categories[idx][j] == 'instcode::0') {
10863: has_instcode == 1;
10864: }
10865: }
10866: if (has_instcode == 0) {
10867: categories[idx][maxtop] = 'instcode_pos';
10868: }
10869: } else {
10870: newpos += '_'+parent;
10871: }
10872: var maxh = 1 + categories[idx].length;
10873: var current = new Array;
10874: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10875: if (item == newpos) {
10876: changedVal = newitemVal;
10877: } else {
10878: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10879: current[newitemVal] = newpos;
10880: }
10881: for (var i=0; i<categories[idx].length; i++) {
10882: var elementName = categories[idx][i];
10883: if (elementName != item) {
10884: if (form.elements[elementName]) {
10885: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10886: current[currVal] = elementName;
10887: }
10888: }
10889: }
10890: var oldVal;
10891: for (var j=0; j<maxh; j++) {
10892: if (current[j] == undefined) {
10893: oldVal = j;
10894: }
10895: }
10896: if (oldVal < changedVal) {
10897: for (var k=oldVal+1; k<=changedVal ; k++) {
10898: var elementName = current[k];
10899: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10900: }
10901: } else {
10902: for (var k=changedVal; k<oldVal; k++) {
10903: var elementName = current[k];
10904: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10905: }
10906: }
10907: return;
10908: }
1.120 raeburn 10909:
10910: function categoryCheck(form) {
10911: if (form.elements['addcategory_name'].value == 'instcode') {
10912: alert('$instcode_reserved\\n$choose_again');
10913: return false;
10914: }
10915: if (form.elements['addcategory_name'].value == 'communities') {
10916: alert('$communities_reserved\\n$choose_again');
10917: return false;
10918: }
1.272 raeburn 10919: if (form.elements['addcategory_name'].value == 'placement') {
10920: alert('$placement_reserved\\n$choose_again');
10921: return false;
10922: }
1.120 raeburn 10923: return true;
10924: }
10925:
1.109 raeburn 10926: // ]]>
1.49 raeburn 10927: </script>
10928:
10929: ENDSCRIPT
10930: return $output;
10931: }
10932:
1.48 raeburn 10933: sub initialize_categories {
10934: my ($itemcount) = @_;
1.120 raeburn 10935: my ($datatable,$css_class,$chgstr);
1.380 raeburn 10936: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10937: instcode => 'Official courses (with institutional codes)',
10938: communities => 'Communities',
1.272 raeburn 10939: placement => 'Placement Tests',
1.120 raeburn 10940: );
1.328 raeburn 10941: my %selnum = (
10942: instcode => '0',
10943: communities => '1',
10944: placement => '2',
10945: );
10946: my %selected;
1.272 raeburn 10947: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 10949: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 10950: map { $selected{$selnum{$_}} = '' } keys(%selnum);
10951: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 10952: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 10953: .'<select name="'.$default.'_pos"'.$chgstr.'>'
10954: .'<option value="0"'.$selected{'0'}.'>1</option>'
10955: .'<option value="1"'.$selected{'1'}.'>2</option>'
10956: .'<option value="2"'.$selected{'2'}.'>3</option>'
10957: .'<option value="3">4</option></select> '
1.120 raeburn 10958: .$default_names{$default}
10959: .'</span></td><td><span class="LC_nobreak">'
10960: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10961: .&mt('Display').'</label> <label>'
10962: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10963: .'</label></span></td></tr>';
1.120 raeburn 10964: $itemcount ++;
10965: }
1.48 raeburn 10966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10967: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10968: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10969: .'<select name="addcategory_pos"'.$chgstr.'>'
10970: .'<option value="0">1</option>'
10971: .'<option value="1">2</option>'
1.328 raeburn 10972: .'<option value="2">3</option>'
10973: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 10974: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10975: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10976: .'</td></tr>';
1.48 raeburn 10977: return $datatable;
10978: }
10979:
10980: sub build_category_rows {
1.49 raeburn 10981: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10982: my ($text,$name,$item,$chgstr);
1.48 raeburn 10983: if (ref($cats) eq 'ARRAY') {
10984: my $maxdepth = scalar(@{$cats});
10985: if (ref($cats->[$depth]) eq 'HASH') {
10986: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10987: my $numchildren = @{$cats->[$depth]{$parent}};
10988: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 10989: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10990: my ($idxnum,$parent_name,$parent_item);
10991: my $higher = $depth - 1;
10992: if ($higher == 0) {
10993: $parent_name = &escape($parent).'::'.$higher;
10994: } else {
10995: if (ref($path) eq 'ARRAY') {
10996: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10997: }
10998: }
10999: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11000: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11001: if ($j < $numchildren) {
1.48 raeburn 11002: $name = $cats->[$depth]{$parent}[$j];
11003: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11004: $idxnum = $idx->{$item};
11005: } else {
11006: $name = $parent_name;
11007: $item = $parent_item;
1.48 raeburn 11008: }
1.49 raeburn 11009: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11010: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11011: for (my $i=0; $i<=$numchildren; $i++) {
11012: my $vpos = $i+1;
11013: my $selstr;
11014: if ($j == $i) {
11015: $selstr = ' selected="selected" ';
11016: }
11017: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11018: }
11019: $text .= '</select> ';
11020: if ($j < $numchildren) {
11021: my $deeper = $depth+1;
11022: $text .= $name.' '
11023: .'<label><input type="checkbox" name="deletecategory" value="'
11024: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11025: if(ref($path) eq 'ARRAY') {
11026: push(@{$path},$name);
1.49 raeburn 11027: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11028: pop(@{$path});
11029: }
11030: } else {
1.330 raeburn 11031: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11032: if ($j == $numchildren) {
11033: $text .= $name;
11034: } else {
11035: $text .= $item;
11036: }
11037: $text .= '" value="" />';
11038: }
11039: $text .= '</td></tr>';
11040: }
11041: $text .= '</table></td>';
11042: } else {
11043: my $higher = $depth-1;
11044: if ($higher == 0) {
11045: $name = &escape($parent).'::'.$higher;
11046: } else {
11047: if (ref($path) eq 'ARRAY') {
11048: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11049: }
11050: }
11051: my $colspan;
11052: if ($parent ne 'instcode') {
11053: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11054: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11055: }
11056: }
11057: }
11058: }
11059: return $text;
11060: }
11061:
1.33 raeburn 11062: sub modifiable_userdata_row {
1.305 raeburn 11063: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11064: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11065: my ($role,$rolename,$statustype);
11066: $role = $item;
1.224 raeburn 11067: if ($context eq 'cancreate') {
1.305 raeburn 11068: if ($item =~ /^(emailusername)_(.+)$/) {
11069: $role = $1;
11070: $statustype = $2;
1.228 raeburn 11071: if (ref($usertypes) eq 'HASH') {
11072: if ($usertypes->{$statustype}) {
11073: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11074: } else {
11075: $rolename = &mt('Data provided by user');
11076: }
11077: }
1.224 raeburn 11078: }
11079: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11080: if (ref($usertypes) eq 'HASH') {
11081: $rolename = $usertypes->{$role};
11082: } else {
11083: $rolename = $role;
11084: }
1.325 raeburn 11085: } elsif ($context eq 'lti') {
11086: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11087: } elsif ($context eq 'privacy') {
11088: $rolename = $itemdesc;
1.33 raeburn 11089: } else {
1.63 raeburn 11090: if ($role eq 'cr') {
11091: $rolename = &mt('Custom role');
11092: } else {
11093: $rolename = &Apache::lonnet::plaintext($role);
11094: }
1.33 raeburn 11095: }
1.224 raeburn 11096: my (@fields,%fieldtitles);
11097: if (ref($fieldsref) eq 'ARRAY') {
11098: @fields = @{$fieldsref};
11099: } else {
11100: @fields = ('lastname','firstname','middlename','generation',
11101: 'permanentemail','id');
11102: }
11103: if ((ref($titlesref) eq 'HASH')) {
11104: %fieldtitles = %{$titlesref};
11105: } else {
11106: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11107: }
1.33 raeburn 11108: my $output;
1.305 raeburn 11109: my $css_class;
11110: if ($rowcount%2) {
11111: $css_class = 'LC_odd_row';
11112: }
11113: if ($customcss) {
11114: $css_class .= " $customcss";
11115: }
11116: $css_class =~ s/^\s+//;
11117: if ($css_class) {
11118: $css_class = ' class="'.$css_class.'"';
11119: }
11120: if ($rowstyle) {
11121: $css_class .= ' style="'.$rowstyle.'"';
11122: }
11123: if ($rowid) {
11124: $rowid = ' id="'.$rowid.'"';
11125: }
11126: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11127: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11128: '<td class="LC_left_item" colspan="2"><table>';
11129: my $rem;
11130: my %checks;
1.325 raeburn 11131: my %current;
1.33 raeburn 11132: if (ref($settings) eq 'HASH') {
1.325 raeburn 11133: my $hashref;
11134: if ($context eq 'lti') {
11135: if (ref($settings) eq 'HASH') {
11136: $hashref = $settings->{'instdata'};
11137: }
1.357 raeburn 11138: } elsif ($context eq 'privacy') {
11139: my ($key,$inner) = split(/_/,$role);
11140: if (ref($settings) eq 'HASH') {
11141: if (ref($settings->{$key}) eq 'HASH') {
11142: $hashref = $settings->{$key}->{$inner};
11143: }
11144: }
1.325 raeburn 11145: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11146: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11147: $hashref = $settings->{'lti_instdata'};
11148: }
11149: if ($role eq 'emailusername') {
11150: if ($statustype) {
11151: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11152: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11153: }
1.325 raeburn 11154: }
11155: }
11156: }
11157: if (ref($hashref) eq 'HASH') {
11158: foreach my $field (@fields) {
11159: if ($hashref->{$field}) {
11160: if ($role eq 'emailusername') {
11161: $checks{$field} = $hashref->{$field};
11162: } else {
11163: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11164: }
11165: }
11166: }
11167: }
11168: }
1.305 raeburn 11169:
11170: my $total = scalar(@fields);
11171: for (my $i=0; $i<$total; $i++) {
11172: $rem = $i%($numinrow);
1.33 raeburn 11173: if ($rem == 0) {
11174: if ($i > 0) {
11175: $output .= '</tr>';
11176: }
11177: $output .= '<tr>';
11178: }
11179: my $check = ' ';
1.228 raeburn 11180: unless ($role eq 'emailusername') {
11181: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11182: $check = $checks{$fields[$i]};
1.357 raeburn 11183: } elsif ($context eq 'privacy') {
11184: if ($role =~ /^priv_(domain|course)$/) {
11185: if (ref($settings) ne 'HASH') {
11186: $check = ' checked="checked" ';
11187: }
11188: } elsif ($role =~ /^priv_(author|community)$/) {
11189: if (ref($settings) ne 'HASH') {
11190: unless ($fields[$i] eq 'id') {
11191: $check = ' checked="checked" ';
11192: }
11193: }
11194: } elsif ($role =~ /^(unpriv|othdom)_/) {
11195: if (ref($settings) ne 'HASH') {
11196: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11197: $check = ' checked="checked" ';
11198: }
11199: }
11200: }
1.325 raeburn 11201: } elsif ($context ne 'lti') {
1.228 raeburn 11202: if ($role eq 'st') {
11203: if (ref($settings) ne 'HASH') {
11204: $check = ' checked="checked" ';
11205: }
1.33 raeburn 11206: }
11207: }
11208: }
11209: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11210: '<span class="LC_nobreak">';
1.325 raeburn 11211: my $prefix = 'canmodify';
1.228 raeburn 11212: if ($role eq 'emailusername') {
11213: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11214: $checks{$fields[$i]} = 'omit';
11215: }
11216: foreach my $option ('required','optional','omit') {
11217: my $checked='';
11218: if ($checks{$fields[$i]} eq $option) {
11219: $checked='checked="checked" ';
11220: }
11221: $output .= '<label>'.
1.325 raeburn 11222: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11223: &mt($option).'</label>'.(' ' x2);
11224: }
11225: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11226: } else {
1.325 raeburn 11227: if ($context eq 'lti') {
11228: $prefix = 'lti';
1.357 raeburn 11229: } elsif ($context eq 'privacy') {
11230: $prefix = 'privacy';
1.325 raeburn 11231: }
1.228 raeburn 11232: $output .= '<label>'.
1.325 raeburn 11233: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11234: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11235: '</label>';
11236: }
11237: $output .= '</span></td>';
1.33 raeburn 11238: }
1.305 raeburn 11239: $rem = $total%$numinrow;
11240: my $colsleft;
11241: if ($rem) {
11242: $colsleft = $numinrow - $rem;
11243: }
11244: if ($colsleft > 1) {
1.33 raeburn 11245: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11246: ' </td>';
11247: } elsif ($colsleft == 1) {
11248: $output .= '<td class="LC_left_item"> </td>';
11249: }
11250: $output .= '</tr></table></td></tr>';
11251: return $output;
11252: }
1.28 raeburn 11253:
1.93 raeburn 11254: sub insttypes_row {
1.305 raeburn 11255: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11256: $customcss,$rowstyle) = @_;
1.93 raeburn 11257: my %lt = &Apache::lonlocal::texthash (
11258: cansearch => 'Users allowed to search',
11259: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11260: lockablenames => 'User preference to lock name',
1.305 raeburn 11261: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11262: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11263: );
11264: my $showdom;
11265: if ($context eq 'cansearch') {
11266: $showdom = ' ('.$dom.')';
11267: }
1.165 raeburn 11268: my $class = 'LC_left_item';
11269: if ($context eq 'statustocreate') {
11270: $class = 'LC_right_item';
11271: }
1.305 raeburn 11272: my $css_class;
11273: if ($$rowtotal%2) {
11274: $css_class = 'LC_odd_row';
11275: }
11276: if ($customcss) {
11277: $css_class .= ' '.$customcss;
11278: }
11279: $css_class =~ s/^\s+//;
11280: if ($css_class) {
11281: $css_class = ' class="'.$css_class.'"';
11282: }
11283: if ($rowstyle) {
11284: $css_class .= ' style="'.$rowstyle.'"';
11285: }
11286: if ($onclick) {
11287: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11288: }
11289: my $output = '<tr'.$css_class.'>'.
11290: '<td>'.$lt{$context}.$showdom.
11291: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11292: my $rem;
11293: if (ref($types) eq 'ARRAY') {
11294: for (my $i=0; $i<@{$types}; $i++) {
11295: if (defined($usertypes->{$types->[$i]})) {
11296: my $rem = $i%($numinrow);
11297: if ($rem == 0) {
11298: if ($i > 0) {
11299: $output .= '</tr>';
11300: }
11301: $output .= '<tr>';
1.23 raeburn 11302: }
1.26 raeburn 11303: my $check = ' ';
1.99 raeburn 11304: if (ref($settings) eq 'HASH') {
11305: if (ref($settings->{$context}) eq 'ARRAY') {
11306: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11307: $check = ' checked="checked" ';
11308: }
1.315 raeburn 11309: } elsif (ref($settings->{$context}) eq 'HASH') {
11310: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11311: $check = ' checked="checked" ';
11312: }
1.99 raeburn 11313: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11314: $check = ' checked="checked" ';
11315: }
1.23 raeburn 11316: }
1.26 raeburn 11317: $output .= '<td class="LC_left_item">'.
11318: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11319: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11320: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11321: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11322: }
11323: }
1.26 raeburn 11324: $rem = @{$types}%($numinrow);
1.23 raeburn 11325: }
11326: my $colsleft = $numinrow - $rem;
1.315 raeburn 11327: if ($context eq 'overrides') {
11328: if ($colsleft > 1) {
11329: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11330: } else {
11331: $output .= '<td class="LC_left_item">';
11332: }
11333: $output .= ' ';
1.23 raeburn 11334: } else {
1.334 raeburn 11335: if ($rem == 0) {
1.315 raeburn 11336: $output .= '<tr>';
11337: }
11338: if ($colsleft > 1) {
11339: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11340: } else {
11341: $output .= '<td class="LC_left_item">';
11342: }
11343: my $defcheck = ' ';
11344: if (ref($settings) eq 'HASH') {
11345: if (ref($settings->{$context}) eq 'ARRAY') {
11346: if (grep(/^default$/,@{$settings->{$context}})) {
11347: $defcheck = ' checked="checked" ';
11348: }
11349: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11350: $defcheck = ' checked="checked" ';
11351: }
1.26 raeburn 11352: }
1.315 raeburn 11353: $output .= '<span class="LC_nobreak"><label>'.
11354: '<input type="checkbox" name="'.$context.'" '.
11355: 'value="default"'.$defcheck.$onclick.' />'.
11356: $othertitle.'</label></span>';
1.23 raeburn 11357: }
1.315 raeburn 11358: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11359: return $output;
1.23 raeburn 11360: }
11361:
11362: sub sorted_searchtitles {
11363: my %searchtitles = &Apache::lonlocal::texthash(
11364: 'uname' => 'username',
11365: 'lastname' => 'last name',
11366: 'lastfirst' => 'last name, first name',
11367: );
11368: my @titleorder = ('uname','lastname','lastfirst');
11369: return (\%searchtitles,\@titleorder);
11370: }
11371:
1.25 raeburn 11372: sub sorted_searchtypes {
11373: my %srchtypes_desc = (
11374: exact => 'is exact match',
11375: contains => 'contains ..',
11376: begins => 'begins with ..',
11377: );
11378: my @srchtypeorder = ('exact','begins','contains');
11379: return (\%srchtypes_desc,\@srchtypeorder);
11380: }
11381:
1.3 raeburn 11382: sub usertype_update_row {
11383: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11384: my $datatable;
11385: my $numinrow = 4;
11386: foreach my $type (@{$types}) {
11387: if (defined($usertypes->{$type})) {
11388: $$rownums ++;
11389: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11390: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11391: '</td><td class="LC_left_item"><table>';
11392: for (my $i=0; $i<@{$fields}; $i++) {
11393: my $rem = $i%($numinrow);
11394: if ($rem == 0) {
11395: if ($i > 0) {
11396: $datatable .= '</tr>';
11397: }
11398: $datatable .= '<tr>';
11399: }
11400: my $check = ' ';
1.39 raeburn 11401: if (ref($settings) eq 'HASH') {
11402: if (ref($settings->{'fields'}) eq 'HASH') {
11403: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11404: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11405: $check = ' checked="checked" ';
11406: }
1.3 raeburn 11407: }
11408: }
11409: }
11410:
11411: if ($i == @{$fields}-1) {
11412: my $colsleft = $numinrow - $rem;
11413: if ($colsleft > 1) {
11414: $datatable .= '<td colspan="'.$colsleft.'">';
11415: } else {
11416: $datatable .= '<td>';
11417: }
11418: } else {
11419: $datatable .= '<td>';
11420: }
1.8 raeburn 11421: $datatable .= '<span class="LC_nobreak"><label>'.
11422: '<input type="checkbox" name="updateable_'.$type.
11423: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11424: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11425: }
11426: $datatable .= '</tr></table></td></tr>';
11427: }
11428: }
11429: return $datatable;
1.1 raeburn 11430: }
11431:
11432: sub modify_login {
1.205 raeburn 11433: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11434: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11435: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
11436: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168 raeburn 11437: %title = ( coursecatalog => 'Display course catalog',
11438: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11439: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11440: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11441: loginheader => 'Log-in box header',
11442: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11443: @offon = ('off','on');
1.112 raeburn 11444: if (ref($domconfig{login}) eq 'HASH') {
11445: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11446: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11447: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11448: }
11449: }
1.386 raeburn 11450: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11451: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11452: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11453: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11454: $saml{$lonhost} = 1;
11455: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11456: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11457: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11458: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11459: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
11460: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11461: }
11462: }
11463: }
1.112 raeburn 11464: }
1.9 raeburn 11465: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11466: \%domconfig,\%loginhash);
1.188 raeburn 11467: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11468: foreach my $item (@toggles) {
11469: $loginhash{login}{$item} = $env{'form.'.$item};
11470: }
1.41 raeburn 11471: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11472: if (ref($colchanges{'login'}) eq 'HASH') {
11473: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11474: \%loginhash);
11475: }
1.110 raeburn 11476:
1.149 raeburn 11477: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11478: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11479: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11480: if (keys(%servers) > 1) {
11481: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11482: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11483: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11484: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11485: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11486: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11487: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11488: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11489: $changes{'loginvia'}{$lonhost} = 1;
11490: } else {
11491: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11492: $changes{'loginvia'}{$lonhost} = 1;
11493: }
11494: } else {
11495: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11496: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11497: $changes{'loginvia'}{$lonhost} = 1;
11498: }
11499: }
11500: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11501: foreach my $item (@loginvia_attribs) {
11502: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11503: }
11504: } else {
11505: foreach my $item (@loginvia_attribs) {
11506: my $new = $env{'form.'.$lonhost.'_'.$item};
11507: if (($item eq 'serverpath') && ($new eq 'custom')) {
11508: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11509: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11510: $new = '/';
11511: }
11512: }
11513: if (($item eq 'custompath') &&
11514: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11515: $new = '';
11516: }
11517: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11518: $changes{'loginvia'}{$lonhost} = 1;
11519: }
11520: if ($item eq 'exempt') {
1.256 raeburn 11521: $new = &check_exempt_addresses($new);
1.128 raeburn 11522: }
11523: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11524: }
11525: }
1.112 raeburn 11526: } else {
1.128 raeburn 11527: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11528: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11529: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11530: foreach my $item (@loginvia_attribs) {
11531: my $new = $env{'form.'.$lonhost.'_'.$item};
11532: if (($item eq 'serverpath') && ($new eq 'custom')) {
11533: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11534: $new = '/';
11535: }
11536: }
11537: if (($item eq 'custompath') &&
11538: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11539: $new = '';
11540: }
11541: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11542: }
1.110 raeburn 11543: }
11544: }
11545: }
11546: }
1.119 raeburn 11547:
1.168 raeburn 11548: my $servadm = $r->dir_config('lonAdmEMail');
11549: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11550: if (ref($domconfig{'login'}) eq 'HASH') {
11551: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11552: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11553: if ($lang eq 'nolang') {
11554: push(@currlangs,$lang);
11555: } elsif (defined($langchoices{$lang})) {
11556: push(@currlangs,$lang);
11557: } else {
11558: next;
11559: }
11560: }
11561: }
11562: }
11563: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11564: if (@currlangs > 0) {
11565: foreach my $lang (@currlangs) {
11566: if (grep(/^\Q$lang\E$/,@delurls)) {
11567: $changes{'helpurl'}{$lang} = 1;
11568: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11569: $changes{'helpurl'}{$lang} = 1;
11570: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11571: push(@newlangs,$lang);
11572: } else {
11573: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11574: }
11575: }
11576: }
11577: unless (grep(/^nolang$/,@currlangs)) {
11578: if ($env{'form.loginhelpurl_nolang.filename'}) {
11579: $changes{'helpurl'}{'nolang'} = 1;
11580: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11581: push(@newlangs,'nolang');
11582: }
11583: }
11584: if ($env{'form.loginhelpurl_add_lang'}) {
11585: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11586: ($env{'form.loginhelpurl_add_file.filename'})) {
11587: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11588: $addedfile = $env{'form.loginhelpurl_add_lang'};
11589: }
11590: }
11591: if ((@newlangs > 0) || ($addedfile)) {
11592: my $error;
11593: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11594: if ($configuserok eq 'ok') {
11595: if ($switchserver) {
11596: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11597: } elsif ($author_ok eq 'ok') {
11598: my @allnew = @newlangs;
11599: if ($addedfile ne '') {
11600: push(@allnew,$addedfile);
11601: }
11602: foreach my $lang (@allnew) {
11603: my $formelem = 'loginhelpurl_'.$lang;
11604: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11605: $formelem = 'loginhelpurl_add_file';
11606: }
11607: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11608: "help/$lang",'','',$newfile{$lang});
11609: if ($result eq 'ok') {
11610: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11611: $changes{'helpurl'}{$lang} = 1;
11612: } else {
11613: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11614: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11615: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11616: (!grep(/^\Q$lang\E$/,@delurls))) {
11617: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11618: }
11619: }
11620: }
11621: } else {
11622: $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);
11623: }
11624: } else {
11625: $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);
11626: }
11627: if ($error) {
11628: &Apache::lonnet::logthis($error);
11629: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11630: }
11631: }
1.256 raeburn 11632:
11633: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11634: if (ref($domconfig{'login'}) eq 'HASH') {
11635: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11636: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11637: if ($domservers{$lonhost}) {
11638: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11639: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11640: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11641: }
11642: }
11643: }
11644: }
11645: }
11646: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11647: foreach my $lonhost (sort(keys(%domservers))) {
11648: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11649: $changes{'headtag'}{$lonhost} = 1;
11650: } else {
11651: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11652: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11653: }
11654: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11655: push(@newhosts,$lonhost);
11656: } elsif ($currheadtagurls{$lonhost}) {
11657: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11658: if ($currexempt{$lonhost}) {
1.289 raeburn 11659: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11660: $changes{'headtag'}{$lonhost} = 1;
11661: }
11662: } elsif ($possexempt{$lonhost}) {
11663: $changes{'headtag'}{$lonhost} = 1;
11664: }
11665: if ($possexempt{$lonhost}) {
11666: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11667: }
11668: }
11669: }
11670: }
11671: if (@newhosts) {
11672: my $error;
11673: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11674: if ($configuserok eq 'ok') {
11675: if ($switchserver) {
11676: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11677: } elsif ($author_ok eq 'ok') {
11678: foreach my $lonhost (@newhosts) {
11679: my $formelem = 'loginheadtag_'.$lonhost;
11680: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11681: "login/headtag/$lonhost",'','',
11682: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11683: if ($result eq 'ok') {
11684: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11685: $changes{'headtag'}{$lonhost} = 1;
11686: if ($possexempt{$lonhost}) {
11687: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11688: }
11689: } else {
11690: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11691: $newheadtagurls{$lonhost},$result);
11692: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11693: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11694: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11695: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11696: }
11697: }
11698: }
11699: } else {
11700: $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);
11701: }
11702: } else {
11703: $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);
11704: }
11705: if ($error) {
11706: &Apache::lonnet::logthis($error);
11707: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11708: }
11709: }
1.386 raeburn 11710: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11711: my @newsamlimgs;
11712: foreach my $lonhost (keys(%domservers)) {
11713: if ($env{'form.saml_'.$lonhost}) {
11714: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11715: push(@newsamlimgs,$lonhost);
11716: }
11717: foreach my $item ('text','alt','url','title','notsso') {
11718: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11719: }
11720: if ($saml{$lonhost}) {
11721: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11722: #FIXME Need to obsolete published image
11723: delete($currsaml{$lonhost}{'img'});
11724: $changes{'saml'}{$lonhost} = 1;
11725: }
11726: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11727: $changes{'saml'}{$lonhost} = 1;
11728: }
11729: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11730: $changes{'saml'}{$lonhost} = 1;
11731: }
11732: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11733: $changes{'saml'}{$lonhost} = 1;
11734: }
11735: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11736: $changes{'saml'}{$lonhost} = 1;
11737: }
11738: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11739: $changes{'saml'}{$lonhost} = 1;
11740: }
11741: } else {
11742: $changes{'saml'}{$lonhost} = 1;
11743: }
11744: foreach my $item ('text','alt','url','title','notsso') {
11745: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11746: }
11747: } else {
1.389 ! raeburn 11748: if ($saml{$lonhost}) {
! 11749: $changes{'saml'}{$lonhost} = 1;
! 11750: delete($currsaml{$lonhost});
! 11751: }
1.386 raeburn 11752: }
11753: }
11754: foreach my $posshost (keys(%currsaml)) {
11755: unless (exists($domservers{$posshost})) {
11756: delete($currsaml{$posshost});
11757: }
11758: }
11759: %{$loginhash{'login'}{'saml'}} = %currsaml;
11760: if (@newsamlimgs) {
11761: my $error;
11762: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11763: if ($configuserok eq 'ok') {
11764: if ($switchserver) {
11765: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11766: } elsif ($author_ok eq 'ok') {
11767: foreach my $lonhost (@newsamlimgs) {
11768: my $formelem = 'saml_img_'.$lonhost;
11769: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11770: "login/saml/$lonhost",'','',
11771: $env{'form.saml_img_'.$lonhost.'.filename'});
11772: if ($result eq 'ok') {
11773: $currsaml{$lonhost}{'img'} = $imgurl;
11774: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11775: $changes{'saml'}{$lonhost} = 1;
11776: } else {
11777: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11778: $lonhost,$result);
11779: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11780: }
11781: }
11782: } else {
11783: $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);
11784: }
11785: } else {
11786: $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);
11787: }
11788: if ($error) {
11789: &Apache::lonnet::logthis($error);
11790: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11791: }
11792: }
1.169 raeburn 11793: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11794:
11795: my $defaulthelpfile = '/adm/loginproblems.html';
11796: my $defaulttext = &mt('Default in use');
11797:
1.1 raeburn 11798: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11799: $dom);
11800: if ($putresult eq 'ok') {
1.188 raeburn 11801: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11802: my %defaultchecked = (
11803: 'coursecatalog' => 'on',
1.188 raeburn 11804: 'helpdesk' => 'on',
1.42 raeburn 11805: 'adminmail' => 'off',
1.43 raeburn 11806: 'newuser' => 'off',
1.42 raeburn 11807: );
1.55 raeburn 11808: if (ref($domconfig{'login'}) eq 'HASH') {
11809: foreach my $item (@toggles) {
11810: if ($defaultchecked{$item} eq 'on') {
11811: if (($domconfig{'login'}{$item} eq '0') &&
11812: ($env{'form.'.$item} eq '1')) {
11813: $changes{$item} = 1;
11814: } elsif (($domconfig{'login'}{$item} eq '' ||
11815: $domconfig{'login'}{$item} eq '1') &&
11816: ($env{'form.'.$item} eq '0')) {
11817: $changes{$item} = 1;
11818: }
11819: } elsif ($defaultchecked{$item} eq 'off') {
11820: if (($domconfig{'login'}{$item} eq '1') &&
11821: ($env{'form.'.$item} eq '0')) {
11822: $changes{$item} = 1;
11823: } elsif (($domconfig{'login'}{$item} eq '' ||
11824: $domconfig{'login'}{$item} eq '0') &&
11825: ($env{'form.'.$item} eq '1')) {
11826: $changes{$item} = 1;
11827: }
1.42 raeburn 11828: }
11829: }
1.41 raeburn 11830: }
1.6 raeburn 11831: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11832: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 11833: if (exists($changes{'saml'})) {
11834: my $hostid_in_use;
11835: my @hosts = &Apache::lonnet::current_machine_ids();
11836: if (@hosts > 1) {
11837: foreach my $hostid (@hosts) {
11838: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11839: $hostid_in_use = $hostid;
11840: last;
11841: }
11842: }
11843: } else {
11844: $hostid_in_use = $r->dir_config('lonHostID');
11845: }
11846: if (($hostid_in_use) &&
11847: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 11848: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 11849: }
11850: if (ref($lastactref) eq 'HASH') {
11851: if (ref($changes{'saml'}) eq 'HASH') {
11852: my %updates;
11853: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11854: $lastactref->{'samllanding'} = \%updates;
11855: }
11856: }
11857: }
1.212 raeburn 11858: if (ref($lastactref) eq 'HASH') {
11859: $lastactref->{'domainconfig'} = 1;
11860: }
1.1 raeburn 11861: $resulttext = &mt('Changes made:').'<ul>';
11862: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11863: if ($item eq 'loginvia') {
1.112 raeburn 11864: if (ref($changes{$item}) eq 'HASH') {
11865: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11866: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11867: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11868: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11869: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11870: $protocol = 'http' if ($protocol ne 'https');
11871: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11872:
11873: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11874: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11875: } else {
11876: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11877: }
11878: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11879: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11880: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11881: }
11882: $resulttext .= '</li>';
11883: } else {
11884: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11885: }
1.112 raeburn 11886: } else {
1.128 raeburn 11887: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11888: }
11889: }
1.128 raeburn 11890: $resulttext .= '</ul></li>';
1.112 raeburn 11891: }
1.168 raeburn 11892: } elsif ($item eq 'helpurl') {
11893: if (ref($changes{$item}) eq 'HASH') {
11894: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11895: if (grep(/^\Q$lang\E$/,@delurls)) {
11896: my ($chg,$link);
11897: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11898: if ($lang eq 'nolang') {
11899: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11900: } else {
11901: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11902: }
11903: $resulttext .= '<li>'.$chg.'</li>';
11904: } else {
11905: my $chg;
11906: if ($lang eq 'nolang') {
11907: $chg = &mt('custom log-in help file for no preferred language');
11908: } else {
11909: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11910: }
11911: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11912: $loginhash{'login'}{'helpurl'}{$lang}.
11913: '?inhibitmenu=yes',$chg,600,500).
11914: '</li>';
11915: }
11916: }
11917: }
1.256 raeburn 11918: } elsif ($item eq 'headtag') {
11919: if (ref($changes{$item}) eq 'HASH') {
11920: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11921: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11922: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11923: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11924: $resulttext .= '<li><a href="'.
11925: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11926: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11927: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11928: if ($possexempt{$lonhost}) {
11929: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11930: } else {
11931: $resulttext .= &mt('included for any client IP');
11932: }
11933: $resulttext .= '</li>';
11934: }
11935: }
11936: }
1.386 raeburn 11937: } elsif ($item eq 'saml') {
11938: if (ref($changes{$item}) eq 'HASH') {
11939: my %notlt = (
11940: text => 'Text for log-in by SSO',
11941: img => 'SSO button image',
11942: alt => 'Alt text for button image',
11943: url => 'SSO URL',
11944: title => 'Tooltip for SSO link',
11945: notsso => 'Text for non-SSO log-in',
11946: );
11947: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11948: if (ref($currsaml{$lonhost}) eq 'HASH') {
11949: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11950: '<ul>';
11951: foreach my $key ('text','img','alt','url','title','notsso') {
11952: if ($currsaml{$lonhost}{$key} eq '') {
11953: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11954: } else {
11955: my $value = "'$currsaml{$lonhost}{$key}'";
11956: if ($key eq 'img') {
11957: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
11958: }
11959: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11960: $value).'</li>';
11961: }
11962: }
11963: $resulttext .= '</ul></li>';
11964: } else {
11965: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11966: }
11967: }
11968: }
1.169 raeburn 11969: } elsif ($item eq 'captcha') {
11970: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 11971: my $chgtxt;
1.169 raeburn 11972: if ($loginhash{'login'}{$item} eq 'notused') {
11973: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11974: } else {
11975: my %captchas = &captcha_phrases();
11976: if ($captchas{$loginhash{'login'}{$item}}) {
11977: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11978: } else {
11979: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11980: }
11981: }
11982: $resulttext .= '<li>'.$chgtxt.'</li>';
11983: }
11984: } elsif ($item eq 'recaptchakeys') {
11985: if (ref($loginhash{'login'}) eq 'HASH') {
11986: my ($privkey,$pubkey);
11987: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11988: $pubkey = $loginhash{'login'}{$item}{'public'};
11989: $privkey = $loginhash{'login'}{$item}{'private'};
11990: }
11991: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11992: if (!$pubkey) {
11993: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11994: } else {
11995: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11996: }
11997: if (!$privkey) {
11998: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11999: } else {
1.251 raeburn 12000: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12001: }
12002: $chgtxt .= '</ul>';
12003: $resulttext .= '<li>'.$chgtxt.'</li>';
12004: }
1.269 raeburn 12005: } elsif ($item eq 'recaptchaversion') {
12006: if (ref($loginhash{'login'}) eq 'HASH') {
12007: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12008: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12009: '</li>';
12010: }
12011: }
1.41 raeburn 12012: } else {
12013: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12014: }
1.1 raeburn 12015: }
1.6 raeburn 12016: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12017: } else {
12018: $resulttext = &mt('No changes made to log-in page settings');
12019: }
12020: } else {
1.11 albertel 12021: $resulttext = '<span class="LC_error">'.
12022: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12023: }
1.6 raeburn 12024: if ($errors) {
1.9 raeburn 12025: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12026: $errors.'</ul>';
12027: }
12028: return $resulttext;
12029: }
12030:
1.256 raeburn 12031: sub check_exempt_addresses {
12032: my ($iplist) = @_;
12033: $iplist =~ s/^\s+//;
12034: $iplist =~ s/\s+$//;
12035: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12036: my (@okips,$new);
12037: foreach my $ip (@poss_ips) {
12038: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12039: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12040: push(@okips,$ip);
12041: }
12042: }
12043: }
12044: if (@okips > 0) {
12045: $new = join(',',@okips);
12046: } else {
12047: $new = '';
12048: }
12049: return $new;
12050: }
12051:
1.6 raeburn 12052: sub color_font_choices {
12053: my %choices =
12054: &Apache::lonlocal::texthash (
12055: img => "Header",
12056: bgs => "Background colors",
12057: links => "Link colors",
1.55 raeburn 12058: images => "Images",
1.6 raeburn 12059: font => "Font color",
1.201 raeburn 12060: fontmenu => "Font menu",
1.76 raeburn 12061: pgbg => "Page",
1.6 raeburn 12062: tabbg => "Header",
12063: sidebg => "Border",
12064: link => "Link",
12065: alink => "Active link",
12066: vlink => "Visited link",
12067: );
12068: return %choices;
12069: }
12070:
12071: sub modify_rolecolors {
1.205 raeburn 12072: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12073: my ($resulttext,%rolehash);
12074: $rolehash{'rolecolors'} = {};
1.55 raeburn 12075: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12076: if ($domconfig{'rolecolors'} eq '') {
12077: $domconfig{'rolecolors'} = {};
12078: }
12079: }
1.9 raeburn 12080: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12081: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12082: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12083: $dom);
12084: if ($putresult eq 'ok') {
12085: if (keys(%changes) > 0) {
1.41 raeburn 12086: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12087: if (ref($lastactref) eq 'HASH') {
12088: $lastactref->{'domainconfig'} = 1;
12089: }
1.6 raeburn 12090: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12091: $rolehash{'rolecolors'});
12092: } else {
12093: $resulttext = &mt('No changes made to default color schemes');
12094: }
12095: } else {
1.11 albertel 12096: $resulttext = '<span class="LC_error">'.
12097: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12098: }
12099: if ($errors) {
12100: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12101: $errors.'</ul>';
12102: }
12103: return $resulttext;
12104: }
12105:
12106: sub modify_colors {
1.9 raeburn 12107: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12108: my (%changes,%choices);
1.51 raeburn 12109: my @bgs;
1.6 raeburn 12110: my @links = ('link','alink','vlink');
1.41 raeburn 12111: my @logintext;
1.6 raeburn 12112: my @images;
12113: my $servadm = $r->dir_config('lonAdmEMail');
12114: my $errors;
1.200 raeburn 12115: my %defaults;
1.6 raeburn 12116: foreach my $role (@{$roles}) {
12117: if ($role eq 'login') {
1.12 raeburn 12118: %choices = &login_choices();
1.41 raeburn 12119: @logintext = ('textcol','bgcol');
1.12 raeburn 12120: } else {
12121: %choices = &color_font_choices();
12122: }
12123: if ($role eq 'login') {
1.41 raeburn 12124: @images = ('img','logo','domlogo','login');
1.51 raeburn 12125: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12126: } else {
12127: @images = ('img');
1.200 raeburn 12128: @bgs = ('pgbg','tabbg','sidebg');
12129: }
12130: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12131: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12132: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12133: }
12134: if ($role eq 'login') {
12135: foreach my $item (@logintext) {
1.234 raeburn 12136: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12137: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12138: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12139: }
12140: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12141: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12142: }
12143: }
12144: } else {
1.234 raeburn 12145: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12146: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12147: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12148: }
12149: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12150: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12151: }
1.6 raeburn 12152: }
1.200 raeburn 12153: foreach my $item (@bgs) {
1.234 raeburn 12154: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12155: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12156: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12157: }
12158: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12159: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12160: }
12161: }
12162: foreach my $item (@links) {
1.234 raeburn 12163: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12164: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12165: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12166: }
12167: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12168: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12169: }
1.6 raeburn 12170: }
1.46 raeburn 12171: my ($configuserok,$author_ok,$switchserver) =
12172: &config_check($dom,$confname,$servadm);
1.9 raeburn 12173: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12174: if (ref($domconfig->{$role}) ne 'HASH') {
12175: $domconfig->{$role} = {};
12176: }
1.8 raeburn 12177: foreach my $img (@images) {
1.70 raeburn 12178: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
12179: if (defined($env{'form.login_showlogo_'.$img})) {
12180: $confhash->{$role}{'showlogo'}{$img} = 1;
12181: } else {
12182: $confhash->{$role}{'showlogo'}{$img} = 0;
12183: }
12184: }
1.18 albertel 12185: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12186: && !defined($domconfig->{$role}{$img})
12187: && !$env{'form.'.$role.'_del_'.$img}
12188: && $env{'form.'.$role.'_import_'.$img}) {
12189: # import the old configured image from the .tab setting
12190: # if they haven't provided a new one
12191: $domconfig->{$role}{$img} =
12192: $env{'form.'.$role.'_import_'.$img};
12193: }
1.6 raeburn 12194: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12195: my $error;
1.6 raeburn 12196: if ($configuserok eq 'ok') {
1.9 raeburn 12197: if ($switchserver) {
1.12 raeburn 12198: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12199: } else {
12200: if ($author_ok eq 'ok') {
12201: my ($result,$logourl) =
12202: &publishlogo($r,'upload',$role.'_'.$img,
12203: $dom,$confname,$img,$width,$height);
12204: if ($result eq 'ok') {
12205: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12206: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12207: } else {
1.12 raeburn 12208: $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 12209: }
12210: } else {
1.46 raeburn 12211: $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 12212: }
12213: }
12214: } else {
1.46 raeburn 12215: $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 12216: }
12217: if ($error) {
1.8 raeburn 12218: &Apache::lonnet::logthis($error);
1.11 albertel 12219: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12220: }
12221: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12222: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12223: my $error;
12224: if ($configuserok eq 'ok') {
12225: # is confname an author?
12226: if ($switchserver eq '') {
12227: if ($author_ok eq 'ok') {
12228: my ($result,$logourl) =
12229: &publishlogo($r,'copy',$domconfig->{$role}{$img},
12230: $dom,$confname,$img,$width,$height);
12231: if ($result eq 'ok') {
12232: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12233: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12234: }
12235: }
12236: }
12237: }
1.6 raeburn 12238: }
12239: }
12240: }
12241: if (ref($domconfig) eq 'HASH') {
12242: if (ref($domconfig->{$role}) eq 'HASH') {
12243: foreach my $img (@images) {
12244: if ($domconfig->{$role}{$img} ne '') {
12245: if ($env{'form.'.$role.'_del_'.$img}) {
12246: $confhash->{$role}{$img} = '';
1.12 raeburn 12247: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12248: } else {
1.9 raeburn 12249: if ($confhash->{$role}{$img} eq '') {
12250: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12251: }
1.6 raeburn 12252: }
12253: } else {
12254: if ($env{'form.'.$role.'_del_'.$img}) {
12255: $confhash->{$role}{$img} = '';
1.12 raeburn 12256: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12257: }
12258: }
1.70 raeburn 12259: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
12260: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12261: if ($confhash->{$role}{'showlogo'}{$img} ne
12262: $domconfig->{$role}{'showlogo'}{$img}) {
12263: $changes{$role}{'showlogo'}{$img} = 1;
12264: }
12265: } else {
12266: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12267: $changes{$role}{'showlogo'}{$img} = 1;
12268: }
12269: }
12270: }
12271: }
1.6 raeburn 12272: if ($domconfig->{$role}{'font'} ne '') {
12273: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12274: $changes{$role}{'font'} = 1;
12275: }
12276: } else {
12277: if ($confhash->{$role}{'font'}) {
12278: $changes{$role}{'font'} = 1;
12279: }
12280: }
1.107 raeburn 12281: if ($role ne 'login') {
12282: if ($domconfig->{$role}{'fontmenu'} ne '') {
12283: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12284: $changes{$role}{'fontmenu'} = 1;
12285: }
12286: } else {
12287: if ($confhash->{$role}{'fontmenu'}) {
12288: $changes{$role}{'fontmenu'} = 1;
12289: }
1.97 tempelho 12290: }
12291: }
1.6 raeburn 12292: foreach my $item (@bgs) {
12293: if ($domconfig->{$role}{$item} ne '') {
12294: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12295: $changes{$role}{'bgs'}{$item} = 1;
12296: }
12297: } else {
12298: if ($confhash->{$role}{$item}) {
12299: $changes{$role}{'bgs'}{$item} = 1;
12300: }
12301: }
12302: }
12303: foreach my $item (@links) {
12304: if ($domconfig->{$role}{$item} ne '') {
12305: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12306: $changes{$role}{'links'}{$item} = 1;
12307: }
12308: } else {
12309: if ($confhash->{$role}{$item}) {
12310: $changes{$role}{'links'}{$item} = 1;
12311: }
12312: }
12313: }
1.41 raeburn 12314: foreach my $item (@logintext) {
12315: if ($domconfig->{$role}{$item} ne '') {
12316: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12317: $changes{$role}{'logintext'}{$item} = 1;
12318: }
12319: } else {
12320: if ($confhash->{$role}{$item}) {
12321: $changes{$role}{'logintext'}{$item} = 1;
12322: }
12323: }
12324: }
1.6 raeburn 12325: } else {
12326: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12327: \@logintext,$confhash,\%changes);
1.6 raeburn 12328: }
12329: } else {
12330: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12331: \@logintext,$confhash,\%changes);
1.6 raeburn 12332: }
12333: }
12334: return ($errors,%changes);
12335: }
12336:
1.46 raeburn 12337: sub config_check {
12338: my ($dom,$confname,$servadm) = @_;
12339: my ($configuserok,$author_ok,$switchserver,%currroles);
12340: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12341: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12342: $confname,$servadm);
12343: if ($configuserok eq 'ok') {
12344: $switchserver = &check_switchserver($dom,$confname);
12345: if ($switchserver eq '') {
12346: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12347: }
12348: }
12349: return ($configuserok,$author_ok,$switchserver);
12350: }
12351:
1.6 raeburn 12352: sub default_change_checker {
1.41 raeburn 12353: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12354: foreach my $item (@{$links}) {
12355: if ($confhash->{$role}{$item}) {
12356: $changes->{$role}{'links'}{$item} = 1;
12357: }
12358: }
12359: foreach my $item (@{$bgs}) {
12360: if ($confhash->{$role}{$item}) {
12361: $changes->{$role}{'bgs'}{$item} = 1;
12362: }
12363: }
1.41 raeburn 12364: foreach my $item (@{$logintext}) {
12365: if ($confhash->{$role}{$item}) {
12366: $changes->{$role}{'logintext'}{$item} = 1;
12367: }
12368: }
1.6 raeburn 12369: foreach my $img (@{$images}) {
12370: if ($env{'form.'.$role.'_del_'.$img}) {
12371: $confhash->{$role}{$img} = '';
1.12 raeburn 12372: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12373: }
1.70 raeburn 12374: if ($role eq 'login') {
12375: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12376: $changes->{$role}{'showlogo'}{$img} = 1;
12377: }
12378: }
1.6 raeburn 12379: }
12380: if ($confhash->{$role}{'font'}) {
12381: $changes->{$role}{'font'} = 1;
12382: }
1.48 raeburn 12383: }
1.6 raeburn 12384:
12385: sub display_colorchgs {
12386: my ($dom,$changes,$roles,$confhash) = @_;
12387: my (%choices,$resulttext);
12388: if (!grep(/^login$/,@{$roles})) {
12389: $resulttext = &mt('Changes made:').'<br />';
12390: }
12391: foreach my $role (@{$roles}) {
12392: if ($role eq 'login') {
12393: %choices = &login_choices();
12394: } else {
12395: %choices = &color_font_choices();
12396: }
12397: if (ref($changes->{$role}) eq 'HASH') {
12398: if ($role ne 'login') {
12399: $resulttext .= '<h4>'.&mt($role).'</h4>';
12400: }
12401: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12402: if ($role ne 'login') {
12403: $resulttext .= '<ul>';
12404: }
12405: if (ref($changes->{$role}{$key}) eq 'HASH') {
12406: if ($role ne 'login') {
12407: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12408: }
12409: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12410: if (($role eq 'login') && ($key eq 'showlogo')) {
12411: if ($confhash->{$role}{$key}{$item}) {
12412: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12413: } else {
12414: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12415: }
12416: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12417: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12418: } else {
1.12 raeburn 12419: my $newitem = $confhash->{$role}{$item};
12420: if ($key eq 'images') {
1.306 raeburn 12421: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 12422: }
12423: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12424: }
12425: }
12426: if ($role ne 'login') {
12427: $resulttext .= '</ul></li>';
12428: }
12429: } else {
12430: if ($confhash->{$role}{$key} eq '') {
12431: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12432: } else {
12433: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12434: }
12435: }
12436: if ($role ne 'login') {
12437: $resulttext .= '</ul>';
12438: }
12439: }
12440: }
12441: }
1.3 raeburn 12442: return $resulttext;
1.1 raeburn 12443: }
12444:
1.9 raeburn 12445: sub thumb_dimensions {
12446: return ('200','50');
12447: }
12448:
1.16 raeburn 12449: sub check_dimensions {
12450: my ($inputfile) = @_;
12451: my ($fullwidth,$fullheight);
12452: if ($inputfile =~ m|^[/\w.\-]+$|) {
12453: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12454: my $imageinfo = <PIPE>;
12455: if (!close(PIPE)) {
12456: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12457: }
12458: chomp($imageinfo);
12459: my ($fullsize) =
1.21 raeburn 12460: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12461: if ($fullsize) {
12462: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12463: }
12464: }
12465: }
12466: return ($fullwidth,$fullheight);
12467: }
12468:
1.9 raeburn 12469: sub check_configuser {
12470: my ($uhome,$dom,$confname,$servadm) = @_;
12471: my ($configuserok,%currroles);
12472: if ($uhome eq 'no_host') {
12473: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 12474: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12475: $configuserok =
12476: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12477: $configpass,'','','','','',undef,$servadm);
12478: } else {
12479: $configuserok = 'ok';
12480: %currroles =
12481: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12482: }
12483: return ($configuserok,%currroles);
12484: }
12485:
12486: sub check_authorstatus {
12487: my ($dom,$confname,%currroles) = @_;
12488: my $author_ok;
1.40 raeburn 12489: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12490: my $start = time;
12491: my $end = 0;
12492: $author_ok =
12493: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12494: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12495: } else {
12496: $author_ok = 'ok';
12497: }
12498: return $author_ok;
12499: }
12500:
12501: sub publishlogo {
1.46 raeburn 12502: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 12503: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 12504: if ($action eq 'upload') {
12505: $fname=$env{'form.'.$formname.'.filename'};
12506: chop($env{'form.'.$formname});
12507: } else {
12508: ($fname) = ($formname =~ /([^\/]+)$/);
12509: }
1.46 raeburn 12510: if ($savefileas ne '') {
12511: $fname = $savefileas;
12512: }
1.9 raeburn 12513: $fname=&Apache::lonnet::clean_filename($fname);
12514: # See if there is anything left
12515: unless ($fname) { return ('error: no uploaded file'); }
12516: $fname="$subdir/$fname";
1.210 raeburn 12517: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 12518: my $filepath="$docroot/priv";
12519: my $relpath = "$dom/$confname";
1.9 raeburn 12520: my ($fnamepath,$file,$fetchthumb);
12521: $file=$fname;
12522: if ($fname=~m|/|) {
12523: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
12524: }
1.164 raeburn 12525: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 12526: my $count;
1.164 raeburn 12527: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 12528: $filepath.="/$parts[$count]";
12529: if ((-e $filepath)!=1) {
12530: mkdir($filepath,02770);
12531: }
12532: }
12533: # Check for bad extension and disallow upload
12534: if ($file=~/\.(\w+)$/ &&
12535: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
12536: $output =
1.207 bisitz 12537: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 12538: } elsif ($file=~/\.(\w+)$/ &&
12539: !defined(&Apache::loncommon::fileembstyle($1))) {
12540: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
12541: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 12542: $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 12543: } elsif (-d "$filepath/$file") {
1.195 bisitz 12544: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 12545: } else {
12546: my $source = $filepath.'/'.$file;
12547: my $logfile;
1.316 raeburn 12548: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 12549: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 12550: }
12551: print $logfile
12552: "\n================= Publish ".localtime()." ================\n".
12553: $env{'user.name'}.':'.$env{'user.domain'}."\n";
12554: # Save the file
1.316 raeburn 12555: if (!open(FH,">",$source)) {
1.9 raeburn 12556: &Apache::lonnet::logthis('Failed to create '.$source);
12557: return (&mt('Failed to create file'));
12558: }
12559: if ($action eq 'upload') {
12560: if (!print FH ($env{'form.'.$formname})) {
12561: &Apache::lonnet::logthis('Failed to write to '.$source);
12562: return (&mt('Failed to write file'));
12563: }
12564: } else {
12565: my $original = &Apache::lonnet::filelocation('',$formname);
12566: if(!copy($original,$source)) {
12567: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
12568: return (&mt('Failed to write file'));
12569: }
12570: }
12571: close(FH);
12572: chmod(0660, $source); # Permissions to rw-rw---.
12573:
12574: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
12575: my $copyfile=$targetdir.'/'.$file;
12576:
12577: my @parts=split(/\//,$targetdir);
12578: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
12579: for (my $count=5;$count<=$#parts;$count++) {
12580: $path.="/$parts[$count]";
12581: if (!-e $path) {
12582: print $logfile "\nCreating directory ".$path;
12583: mkdir($path,02770);
12584: }
12585: }
12586: my $versionresult;
12587: if (-e $copyfile) {
12588: $versionresult = &logo_versioning($targetdir,$file,$logfile);
12589: } else {
12590: $versionresult = 'ok';
12591: }
12592: if ($versionresult eq 'ok') {
12593: if (copy($source,$copyfile)) {
12594: print $logfile "\nCopied original source to ".$copyfile."\n";
12595: $output = 'ok';
12596: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 12597: push(@{$modified_urls},[$copyfile,$source]);
12598: my $metaoutput =
12599: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
12600: unless ($registered_cleanup) {
12601: my $handlers = $r->get_handlers('PerlCleanupHandler');
12602: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12603: $registered_cleanup=1;
12604: }
1.9 raeburn 12605: } else {
12606: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
12607: $output = &mt('Failed to copy file to RES space').", $!";
12608: }
12609: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
12610: my $inputfile = $filepath.'/'.$file;
12611: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 12612: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
12613: if ($fullwidth ne '' && $fullheight ne '') {
12614: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
12615: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 12616: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
12617: system({$args[0]} @args);
1.16 raeburn 12618: chmod(0660, $filepath.'/tn-'.$file);
12619: if (-e $outfile) {
12620: my $copyfile=$targetdir.'/tn-'.$file;
12621: if (copy($outfile,$copyfile)) {
12622: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 12623: my $thumb_metaoutput =
12624: &write_metadata($dom,$confname,$formname,
12625: $targetdir,'tn-'.$file,$logfile);
12626: push(@{$modified_urls},[$copyfile,$outfile]);
12627: unless ($registered_cleanup) {
12628: my $handlers = $r->get_handlers('PerlCleanupHandler');
12629: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12630: $registered_cleanup=1;
12631: }
1.267 raeburn 12632: $madethumb = 1;
1.16 raeburn 12633: } else {
12634: print $logfile "\nUnable to write ".$copyfile.
12635: ':'.$!."\n";
12636: }
12637: }
1.9 raeburn 12638: }
12639: }
12640: }
12641: } else {
12642: $output = $versionresult;
12643: }
12644: }
1.267 raeburn 12645: return ($output,$logourl,$madethumb);
1.9 raeburn 12646: }
12647:
12648: sub logo_versioning {
12649: my ($targetdir,$file,$logfile) = @_;
12650: my $target = $targetdir.'/'.$file;
12651: my ($maxversion,$fn,$extn,$output);
12652: $maxversion = 0;
12653: if ($file =~ /^(.+)\.(\w+)$/) {
12654: $fn=$1;
12655: $extn=$2;
12656: }
12657: opendir(DIR,$targetdir);
12658: while (my $filename=readdir(DIR)) {
12659: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
12660: $maxversion=($1>$maxversion)?$1:$maxversion;
12661: }
12662: }
12663: $maxversion++;
12664: print $logfile "\nCreating old version ".$maxversion."\n";
12665: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12666: if (copy($target,$copyfile)) {
12667: print $logfile "Copied old target to ".$copyfile."\n";
12668: $copyfile=$copyfile.'.meta';
12669: if (copy($target.'.meta',$copyfile)) {
12670: print $logfile "Copied old target metadata to ".$copyfile."\n";
12671: $output = 'ok';
12672: } else {
12673: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12674: $output = &mt('Failed to copy old meta').", $!, ";
12675: }
12676: } else {
12677: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12678: $output = &mt('Failed to copy old target').", $!, ";
12679: }
12680: return $output;
12681: }
12682:
12683: sub write_metadata {
12684: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12685: my (%metadatafields,%metadatakeys,$output);
12686: $metadatafields{'title'}=$formname;
12687: $metadatafields{'creationdate'}=time;
12688: $metadatafields{'lastrevisiondate'}=time;
12689: $metadatafields{'copyright'}='public';
12690: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12691: $env{'user.domain'};
12692: $metadatafields{'authorspace'}=$confname.':'.$dom;
12693: $metadatafields{'domain'}=$dom;
12694: {
12695: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12696: my $mfh;
1.316 raeburn 12697: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12698: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12699: unless ($_=~/\./) {
12700: my $unikey=$_;
12701: $unikey=~/^([A-Za-z]+)/;
12702: my $tag=$1;
12703: $tag=~tr/A-Z/a-z/;
12704: print $mfh "\n\<$tag";
12705: foreach (split(/\,/,$metadatakeys{$unikey})) {
12706: my $value=$metadatafields{$unikey.'.'.$_};
12707: $value=~s/\"/\'\'/g;
12708: print $mfh ' '.$_.'="'.$value.'"';
12709: }
12710: print $mfh '>'.
12711: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12712: .'</'.$tag.'>';
12713: }
12714: }
12715: $output = 'ok';
12716: print $logfile "\nWrote metadata";
12717: close($mfh);
12718: } else {
12719: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12720: $output = &mt('Could not write metadata');
12721: }
12722: }
1.155 raeburn 12723: return $output;
12724: }
12725:
12726: sub notifysubscribed {
12727: foreach my $targetsource (@{$modified_urls}){
12728: next unless (ref($targetsource) eq 'ARRAY');
12729: my ($target,$source)=@{$targetsource};
12730: if ($source ne '') {
1.316 raeburn 12731: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12732: print $logfh "\nCleanup phase: Notifications\n";
12733: my @subscribed=&subscribed_hosts($target);
12734: foreach my $subhost (@subscribed) {
12735: print $logfh "\nNotifying host ".$subhost.':';
12736: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12737: print $logfh $reply;
12738: }
12739: my @subscribedmeta=&subscribed_hosts("$target.meta");
12740: foreach my $subhost (@subscribedmeta) {
12741: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12742: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12743: $subhost);
12744: print $logfh $reply;
12745: }
12746: print $logfh "\n============ Done ============\n";
1.160 raeburn 12747: close($logfh);
1.155 raeburn 12748: }
12749: }
12750: }
12751: return OK;
12752: }
12753:
12754: sub subscribed_hosts {
12755: my ($target) = @_;
12756: my @subscribed;
1.316 raeburn 12757: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12758: while (my $subline=<$fh>) {
12759: if ($subline =~ /^($match_lonid):/) {
12760: my $host = $1;
12761: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12762: unless (grep(/^\Q$host\E$/,@subscribed)) {
12763: push(@subscribed,$host);
12764: }
12765: }
12766: }
12767: }
12768: }
12769: return @subscribed;
1.9 raeburn 12770: }
12771:
12772: sub check_switchserver {
12773: my ($dom,$confname) = @_;
12774: my ($allowed,$switchserver);
12775: my $home = &Apache::lonnet::homeserver($confname,$dom);
12776: if ($home eq 'no_host') {
12777: $home = &Apache::lonnet::domain($dom,'primary');
12778: }
12779: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12780: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12781: if (!$allowed) {
1.180 raeburn 12782: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12783: }
12784: return $switchserver;
12785: }
12786:
1.1 raeburn 12787: sub modify_quotas {
1.216 raeburn 12788: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12789: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12790: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12791: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12792: $validationfieldsref);
1.86 raeburn 12793: if ($action eq 'quotas') {
12794: $context = 'tools';
1.163 raeburn 12795: } else {
1.86 raeburn 12796: $context = $action;
12797: }
12798: if ($context eq 'requestcourses') {
1.325 raeburn 12799: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12800: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12801: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12802: %titles = &courserequest_titles();
12803: $toolregexp = join('|',@usertools);
12804: %conditions = &courserequest_conditions();
1.216 raeburn 12805: $confname = $dom.'-domainconfig';
12806: my $servadm = $r->dir_config('lonAdmEMail');
12807: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12808: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12809: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12810: } elsif ($context eq 'requestauthor') {
12811: @usertools = ('author');
12812: %titles = &authorrequest_titles();
1.86 raeburn 12813: } else {
1.162 raeburn 12814: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12815: %titles = &tool_titles();
1.86 raeburn 12816: }
1.212 raeburn 12817: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12818: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12819: foreach my $key (keys(%env)) {
1.101 raeburn 12820: if ($context eq 'requestcourses') {
12821: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12822: my $item = $1;
12823: my $type = $2;
12824: if ($type =~ /^limit_(.+)/) {
12825: $limithash{$item}{$1} = $env{$key};
12826: } else {
12827: $confhash{$item}{$type} = $env{$key};
12828: }
12829: }
1.163 raeburn 12830: } elsif ($context eq 'requestauthor') {
12831: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12832: $confhash{$1} = $env{$key};
12833: }
1.101 raeburn 12834: } else {
1.86 raeburn 12835: if ($key =~ /^form\.quota_(.+)$/) {
12836: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12837: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12838: $confhash{'authorquota'}{$1} = $env{$key};
12839: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12840: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12841: }
1.72 raeburn 12842: }
12843: }
1.163 raeburn 12844: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12845: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12846: @approvalnotify = sort(@approvalnotify);
12847: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12848: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12849: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12850: foreach my $type (@hasuniquecode) {
12851: if (grep(/^\Q$type\E$/,@crstypes)) {
12852: $confhash{'uniquecode'}{$type} = 1;
12853: }
1.216 raeburn 12854: }
1.242 raeburn 12855: my (%newbook,%allpos);
1.216 raeburn 12856: if ($context eq 'requestcourses') {
1.242 raeburn 12857: foreach my $type ('textbooks','templates') {
12858: @{$allpos{$type}} = ();
12859: my $invalid;
12860: if ($type eq 'textbooks') {
12861: $invalid = &mt('Invalid LON-CAPA course for textbook');
12862: } else {
12863: $invalid = &mt('Invalid LON-CAPA course for template');
12864: }
12865: if ($env{'form.'.$type.'_addbook'}) {
12866: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12867: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12868: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12869: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12870: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12871: } else {
12872: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12873: my $position = $env{'form.'.$type.'_addbook_pos'};
12874: $position =~ s/\D+//g;
12875: if ($position ne '') {
12876: $allpos{$type}[$position] = $newbook{$type};
12877: }
1.216 raeburn 12878: }
1.242 raeburn 12879: } else {
12880: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12881: }
12882: }
1.242 raeburn 12883: }
1.216 raeburn 12884: }
1.102 raeburn 12885: if (ref($domconfig{$action}) eq 'HASH') {
12886: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12887: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12888: $changes{'notify'}{'approval'} = 1;
12889: }
12890: } else {
1.144 raeburn 12891: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12892: $changes{'notify'}{'approval'} = 1;
12893: }
12894: }
1.218 raeburn 12895: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12896: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12897: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12898: unless ($confhash{'uniquecode'}{$crstype}) {
12899: $changes{'uniquecode'} = 1;
12900: }
12901: }
12902: unless ($changes{'uniquecode'}) {
12903: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12904: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12905: $changes{'uniquecode'} = 1;
12906: }
12907: }
12908: }
12909: } else {
12910: $changes{'uniquecode'} = 1;
12911: }
12912: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12913: $changes{'uniquecode'} = 1;
1.216 raeburn 12914: }
12915: if ($context eq 'requestcourses') {
1.242 raeburn 12916: foreach my $type ('textbooks','templates') {
12917: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12918: my %deletions;
12919: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12920: if (@todelete) {
12921: map { $deletions{$_} = 1; } @todelete;
12922: }
12923: my %imgdeletions;
12924: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12925: if (@todeleteimages) {
12926: map { $imgdeletions{$_} = 1; } @todeleteimages;
12927: }
12928: my $maxnum = $env{'form.'.$type.'_maxnum'};
12929: for (my $i=0; $i<=$maxnum; $i++) {
12930: my $itemid = $env{'form.'.$type.'_id_'.$i};
12931: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12932: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12933: if ($deletions{$key}) {
12934: if ($domconfig{$action}{$type}{$key}{'image'}) {
12935: #FIXME need to obsolete item in RES space
12936: }
12937: next;
12938: } else {
12939: my $newpos = $env{'form.'.$itemid};
12940: $newpos =~ s/\D+//g;
1.243 raeburn 12941: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 12942: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 12943: ($type eq 'templates'));
1.242 raeburn 12944: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12945: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12946: $changes{$type}{$key} = 1;
12947: }
12948: }
12949: $allpos{$type}[$newpos] = $key;
12950: }
12951: if ($imgdeletions{$key}) {
12952: $changes{$type}{$key} = 1;
1.216 raeburn 12953: #FIXME need to obsolete item in RES space
1.242 raeburn 12954: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12955: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 12956: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12957: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12958: } else {
12959: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12960: $cdom,$cnum,$type,$configuserok,
12961: $switchserver,$author_ok);
12962: if ($imgurl) {
12963: $confhash{$type}{$key}{'image'} = $imgurl;
12964: $changes{$type}{$key} = 1;
12965: }
12966: if ($error) {
12967: &Apache::lonnet::logthis($error);
12968: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12969: }
12970: }
1.242 raeburn 12971: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12972: $confhash{$type}{$key}{'image'} =
12973: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 12974: }
12975: }
12976: }
12977: }
12978: }
12979: }
1.102 raeburn 12980: } else {
1.144 raeburn 12981: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12982: $changes{'notify'}{'approval'} = 1;
12983: }
1.218 raeburn 12984: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 12985: $changes{'uniquecode'} = 1;
12986: }
12987: }
12988: if ($context eq 'requestcourses') {
1.242 raeburn 12989: foreach my $type ('textbooks','templates') {
12990: if ($newbook{$type}) {
12991: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 12992: foreach my $item ('subject','title','publisher','author') {
12993: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12994: ($type eq 'template'));
1.242 raeburn 12995: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12996: if ($env{'form.'.$type.'_addbook_'.$item}) {
12997: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12998: }
12999: }
13000: if ($type eq 'textbooks') {
13001: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13002: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13003: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13004: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13005: } else {
13006: my ($imageurl,$error) =
13007: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13008: $configuserok,$switchserver,$author_ok);
13009: if ($imageurl) {
13010: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13011: }
13012: if ($error) {
13013: &Apache::lonnet::logthis($error);
13014: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13015: }
1.242 raeburn 13016: }
13017: }
1.216 raeburn 13018: }
13019: }
1.242 raeburn 13020: if (@{$allpos{$type}} > 0) {
13021: my $idx = 0;
13022: foreach my $item (@{$allpos{$type}}) {
13023: if ($item ne '') {
13024: $confhash{$type}{$item}{'order'} = $idx;
13025: if (ref($domconfig{$action}) eq 'HASH') {
13026: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13027: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13028: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13029: $changes{$type}{$item} = 1;
13030: }
1.216 raeburn 13031: }
13032: }
13033: }
1.242 raeburn 13034: $idx ++;
1.216 raeburn 13035: }
13036: }
13037: }
13038: }
1.235 raeburn 13039: if (ref($validationitemsref) eq 'ARRAY') {
13040: foreach my $item (@{$validationitemsref}) {
13041: if ($item eq 'fields') {
13042: my @changed;
13043: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13044: if (@{$confhash{'validation'}{$item}} > 0) {
13045: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13046: }
1.266 raeburn 13047: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13048: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13049: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13050: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13051: $domconfig{'requestcourses'}{'validation'}{$item});
13052: } else {
13053: @changed = @{$confhash{'validation'}{$item}};
13054: }
1.235 raeburn 13055: } else {
13056: @changed = @{$confhash{'validation'}{$item}};
13057: }
13058: } else {
13059: @changed = @{$confhash{'validation'}{$item}};
13060: }
13061: if (@changed) {
13062: if ($confhash{'validation'}{$item}) {
13063: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13064: } else {
13065: $changes{'validation'}{$item} = &mt('None');
13066: }
13067: }
13068: } else {
13069: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13070: if ($item eq 'markup') {
13071: if ($env{'form.requestcourses_validation_'.$item}) {
13072: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13073: }
13074: }
1.266 raeburn 13075: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13076: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13077: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13078: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13079: }
13080: } else {
13081: if ($confhash{'validation'}{$item} ne '') {
13082: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13083: }
1.235 raeburn 13084: }
13085: } else {
13086: if ($confhash{'validation'}{$item} ne '') {
13087: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13088: }
13089: }
13090: }
13091: }
13092: }
13093: if ($env{'form.validationdc'}) {
13094: my $newval = $env{'form.validationdc'};
1.285 raeburn 13095: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13096: if (exists($domcoords{$newval})) {
13097: $confhash{'validation'}{'dc'} = $newval;
13098: }
13099: }
13100: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13101: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13102: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13103: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13104: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13105: if ($confhash{'validation'}{'dc'} eq '') {
13106: $changes{'validation'}{'dc'} = &mt('None');
13107: } else {
13108: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13109: }
1.235 raeburn 13110: }
1.266 raeburn 13111: } elsif ($confhash{'validation'}{'dc'} ne '') {
13112: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13113: }
13114: } elsif ($confhash{'validation'}{'dc'} ne '') {
13115: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13116: }
13117: } elsif ($confhash{'validation'}{'dc'} ne '') {
13118: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13119: }
1.266 raeburn 13120: } else {
13121: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13122: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13123: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13124: $changes{'validation'}{'dc'} = &mt('None');
13125: }
13126: }
1.235 raeburn 13127: }
13128: }
1.102 raeburn 13129: }
13130: } else {
1.86 raeburn 13131: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13132: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13133: }
1.72 raeburn 13134: foreach my $item (@usertools) {
13135: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13136: my $unset;
1.101 raeburn 13137: if ($context eq 'requestcourses') {
1.104 raeburn 13138: $unset = '0';
13139: if ($type eq '_LC_adv') {
13140: $unset = '';
13141: }
1.101 raeburn 13142: if ($confhash{$item}{$type} eq 'autolimit') {
13143: $confhash{$item}{$type} .= '=';
13144: unless ($limithash{$item}{$type} =~ /\D/) {
13145: $confhash{$item}{$type} .= $limithash{$item}{$type};
13146: }
13147: }
1.163 raeburn 13148: } elsif ($context eq 'requestauthor') {
13149: $unset = '0';
13150: if ($type eq '_LC_adv') {
13151: $unset = '';
13152: }
1.72 raeburn 13153: } else {
1.101 raeburn 13154: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13155: $confhash{$item}{$type} = 1;
13156: } else {
13157: $confhash{$item}{$type} = 0;
13158: }
1.72 raeburn 13159: }
1.86 raeburn 13160: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13161: if ($action eq 'requestauthor') {
13162: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13163: $changes{$type} = 1;
13164: }
13165: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13166: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13167: $changes{$item}{$type} = 1;
13168: }
13169: } else {
13170: if ($context eq 'requestcourses') {
1.104 raeburn 13171: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13172: $changes{$item}{$type} = 1;
13173: }
13174: } else {
13175: if (!$confhash{$item}{$type}) {
13176: $changes{$item}{$type} = 1;
13177: }
13178: }
13179: }
13180: } else {
13181: if ($context eq 'requestcourses') {
1.104 raeburn 13182: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13183: $changes{$item}{$type} = 1;
13184: }
1.163 raeburn 13185: } elsif ($context eq 'requestauthor') {
13186: if ($confhash{$type} ne $unset) {
13187: $changes{$type} = 1;
13188: }
1.72 raeburn 13189: } else {
13190: if (!$confhash{$item}{$type}) {
13191: $changes{$item}{$type} = 1;
13192: }
13193: }
13194: }
1.1 raeburn 13195: }
13196: }
1.163 raeburn 13197: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13198: if (ref($domconfig{'quotas'}) eq 'HASH') {
13199: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13200: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13201: if (exists($confhash{'defaultquota'}{$key})) {
13202: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13203: $changes{'defaultquota'}{$key} = 1;
13204: }
13205: } else {
13206: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13207: }
13208: }
1.86 raeburn 13209: } else {
13210: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13211: if (exists($confhash{'defaultquota'}{$key})) {
13212: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13213: $changes{'defaultquota'}{$key} = 1;
13214: }
13215: } else {
13216: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13217: }
1.1 raeburn 13218: }
13219: }
1.197 raeburn 13220: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13221: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13222: if (exists($confhash{'authorquota'}{$key})) {
13223: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13224: $changes{'authorquota'}{$key} = 1;
13225: }
13226: } else {
13227: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13228: }
13229: }
13230: }
1.1 raeburn 13231: }
1.86 raeburn 13232: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13233: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13234: if (ref($domconfig{'quotas'}) eq 'HASH') {
13235: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13236: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13237: $changes{'defaultquota'}{$key} = 1;
13238: }
13239: } else {
13240: if (!exists($domconfig{'quotas'}{$key})) {
13241: $changes{'defaultquota'}{$key} = 1;
13242: }
1.72 raeburn 13243: }
13244: } else {
1.86 raeburn 13245: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13246: }
1.1 raeburn 13247: }
13248: }
1.197 raeburn 13249: if (ref($confhash{'authorquota'}) eq 'HASH') {
13250: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13251: if (ref($domconfig{'quotas'}) eq 'HASH') {
13252: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13253: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13254: $changes{'authorquota'}{$key} = 1;
13255: }
13256: } else {
13257: $changes{'authorquota'}{$key} = 1;
13258: }
13259: } else {
13260: $changes{'authorquota'}{$key} = 1;
13261: }
13262: }
13263: }
1.1 raeburn 13264: }
1.72 raeburn 13265:
1.163 raeburn 13266: if ($context eq 'requestauthor') {
13267: $domdefaults{'requestauthor'} = \%confhash;
13268: } else {
13269: foreach my $key (keys(%confhash)) {
1.242 raeburn 13270: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13271: $domdefaults{$key} = $confhash{$key};
13272: }
1.163 raeburn 13273: }
1.72 raeburn 13274: }
1.163 raeburn 13275:
1.1 raeburn 13276: my %quotahash = (
1.86 raeburn 13277: $action => { %confhash }
1.1 raeburn 13278: );
13279: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13280: $dom);
13281: if ($putresult eq 'ok') {
13282: if (keys(%changes) > 0) {
1.72 raeburn 13283: my $cachetime = 24*60*60;
13284: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13285: if (ref($lastactref) eq 'HASH') {
13286: $lastactref->{'domdefaults'} = 1;
13287: }
1.1 raeburn 13288: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13289: unless (($context eq 'requestcourses') ||
1.163 raeburn 13290: ($context eq 'requestauthor')) {
1.86 raeburn 13291: if (ref($changes{'defaultquota'}) eq 'HASH') {
13292: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13293: foreach my $type (@{$types},'default') {
13294: if (defined($changes{'defaultquota'}{$type})) {
13295: my $typetitle = $usertypes->{$type};
13296: if ($type eq 'default') {
13297: $typetitle = $othertitle;
13298: }
1.213 raeburn 13299: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13300: }
13301: }
1.86 raeburn 13302: $resulttext .= '</ul></li>';
1.72 raeburn 13303: }
1.197 raeburn 13304: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13305: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13306: foreach my $type (@{$types},'default') {
13307: if (defined($changes{'authorquota'}{$type})) {
13308: my $typetitle = $usertypes->{$type};
13309: if ($type eq 'default') {
13310: $typetitle = $othertitle;
13311: }
1.213 raeburn 13312: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13313: }
13314: }
13315: $resulttext .= '</ul></li>';
13316: }
1.72 raeburn 13317: }
1.80 raeburn 13318: my %newenv;
1.72 raeburn 13319: foreach my $item (@usertools) {
1.163 raeburn 13320: my (%haschgs,%inconf);
13321: if ($context eq 'requestauthor') {
13322: %haschgs = %changes;
1.210 raeburn 13323: %inconf = %confhash;
1.163 raeburn 13324: } else {
13325: if (ref($changes{$item}) eq 'HASH') {
13326: %haschgs = %{$changes{$item}};
13327: }
13328: if (ref($confhash{$item}) eq 'HASH') {
13329: %inconf = %{$confhash{$item}};
13330: }
13331: }
13332: if (keys(%haschgs) > 0) {
1.80 raeburn 13333: my $newacc =
13334: &Apache::lonnet::usertools_access($env{'user.name'},
13335: $env{'user.domain'},
1.86 raeburn 13336: $item,'reload',$context);
1.210 raeburn 13337: if (($context eq 'requestcourses') ||
1.163 raeburn 13338: ($context eq 'requestauthor')) {
1.108 raeburn 13339: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13340: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13341: }
13342: } else {
13343: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13344: $newenv{'environment.availabletools.'.$item} = $newacc;
13345: }
1.80 raeburn 13346: }
1.163 raeburn 13347: unless ($context eq 'requestauthor') {
13348: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13349: }
1.72 raeburn 13350: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 13351: if ($haschgs{$type}) {
1.72 raeburn 13352: my $typetitle = $usertypes->{$type};
13353: if ($type eq 'default') {
13354: $typetitle = $othertitle;
13355: } elsif ($type eq '_LC_adv') {
13356: $typetitle = 'LON-CAPA Advanced Users';
13357: }
1.163 raeburn 13358: if ($inconf{$type}) {
1.101 raeburn 13359: if ($context eq 'requestcourses') {
13360: my $cond;
1.163 raeburn 13361: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13362: if ($1 eq '') {
13363: $cond = &mt('(Automatic processing of any request).');
13364: } else {
13365: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13366: }
13367: } else {
1.163 raeburn 13368: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13369: }
13370: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 13371: } elsif ($context eq 'requestauthor') {
13372: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13373: $titles{$inconf{$type}},$typetitle);
13374:
1.101 raeburn 13375: } else {
13376: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13377: }
1.72 raeburn 13378: } else {
1.104 raeburn 13379: if ($type eq '_LC_adv') {
1.163 raeburn 13380: if ($inconf{$type} eq '0') {
1.104 raeburn 13381: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13382: } else {
13383: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13384: }
13385: } else {
13386: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13387: }
1.72 raeburn 13388: }
13389: }
1.26 raeburn 13390: }
1.163 raeburn 13391: unless ($context eq 'requestauthor') {
13392: $resulttext .= '</ul></li>';
13393: }
1.26 raeburn 13394: }
1.1 raeburn 13395: }
1.163 raeburn 13396: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13397: if (ref($changes{'notify'}) eq 'HASH') {
13398: if ($changes{'notify'}{'approval'}) {
13399: if (ref($confhash{'notify'}) eq 'HASH') {
13400: if ($confhash{'notify'}{'approval'}) {
13401: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13402: } else {
1.163 raeburn 13403: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13404: }
13405: }
13406: }
13407: }
13408: }
1.216 raeburn 13409: if ($action eq 'requestcourses') {
13410: my @offon = ('off','on');
13411: if ($changes{'uniquecode'}) {
1.218 raeburn 13412: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13413: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13414: $resulttext .= '<li>'.
13415: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13416: '</li>';
13417: } else {
13418: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13419: '</li>';
13420: }
1.216 raeburn 13421: }
1.242 raeburn 13422: foreach my $type ('textbooks','templates') {
13423: if (ref($changes{$type}) eq 'HASH') {
13424: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13425: foreach my $key (sort(keys(%{$changes{$type}}))) {
13426: my %coursehash = &Apache::lonnet::coursedescription($key);
13427: my $coursetitle = $coursehash{'description'};
13428: my $position = $confhash{$type}{$key}{'order'} + 1;
13429: $resulttext .= '<li>';
1.243 raeburn 13430: foreach my $item ('subject','title','publisher','author') {
13431: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13432: ($type eq 'templates'));
1.242 raeburn 13433: my $name = $item.':';
13434: $name =~ s/^(\w)/\U$1/;
13435: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13436: }
13437: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13438: if ($type eq 'textbooks') {
13439: if ($confhash{$type}{$key}{'image'}) {
13440: $resulttext .= ' '.&mt('Image: [_1]',
13441: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13442: ' alt="Textbook cover" />').'<br />';
13443: }
13444: }
13445: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 13446: }
1.242 raeburn 13447: $resulttext .= '</ul></li>';
1.216 raeburn 13448: }
13449: }
1.235 raeburn 13450: if (ref($changes{'validation'}) eq 'HASH') {
13451: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13452: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13453: foreach my $item (@{$validationitemsref}) {
13454: if (exists($changes{'validation'}{$item})) {
13455: if ($item eq 'markup') {
13456: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13457: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13458: } else {
13459: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13460: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13461: }
13462: }
13463: }
13464: if (exists($changes{'validation'}{'dc'})) {
13465: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13466: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13467: }
13468: }
13469: }
1.216 raeburn 13470: }
1.1 raeburn 13471: $resulttext .= '</ul>';
1.80 raeburn 13472: if (keys(%newenv)) {
13473: &Apache::lonnet::appenv(\%newenv);
13474: }
1.1 raeburn 13475: } else {
1.86 raeburn 13476: if ($context eq 'requestcourses') {
13477: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 13478: } elsif ($context eq 'requestauthor') {
13479: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13480: } else {
1.90 weissno 13481: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13482: }
1.1 raeburn 13483: }
13484: } else {
1.11 albertel 13485: $resulttext = '<span class="LC_error">'.
13486: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13487: }
1.216 raeburn 13488: if ($errors) {
13489: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13490: '<ul>'.$errors.'</ul></p>';
13491: }
1.3 raeburn 13492: return $resulttext;
1.1 raeburn 13493: }
13494:
1.216 raeburn 13495: sub process_textbook_image {
1.242 raeburn 13496: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 13497: my $filename = $env{'form.'.$caller.'.filename'};
13498: my ($error,$url);
13499: my ($width,$height) = (50,50);
13500: if ($configuserok eq 'ok') {
13501: if ($switchserver) {
13502: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13503: $switchserver);
13504: } elsif ($author_ok eq 'ok') {
13505: my ($result,$imageurl) =
13506: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 13507: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 13508: if ($result eq 'ok') {
13509: $url = $imageurl;
13510: } else {
13511: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13512: }
13513: } else {
13514: $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);
13515: }
13516: } else {
13517: $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);
13518: }
13519: return ($url,$error);
13520: }
13521:
1.267 raeburn 13522: sub modify_ltitools {
13523: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13524: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 13525: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 13526: my $confname = $dom.'-domainconfig';
13527: my $servadm = $r->dir_config('lonAdmEMail');
13528: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13529: my (%posslti,%possfield);
13530: my @courseroles = ('cc','in','ta','ep','st');
13531: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
13532: map { $posslti{$_} = 1; } @ltiroles;
13533: my @allfields = ('fullname','firstname','lastname','email','user','roles');
13534: map { $possfield{$_} = 1; } @allfields;
13535: my %lt = <itools_names();
13536: if ($env{'form.ltitools_add'}) {
13537: my $title = $env{'form.ltitools_add_title'};
13538: $title =~ s/(`)/'/g;
13539: ($newid,my $error) = &get_ltitools_id($dom,$title);
13540: if ($newid) {
13541: my $position = $env{'form.ltitools_add_pos'};
13542: $position =~ s/\D+//g;
13543: if ($position ne '') {
13544: $allpos[$position] = $newid;
13545: }
13546: $changes{$newid} = 1;
1.322 raeburn 13547: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 13548: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 13549: if ($item eq 'lifetime') {
13550: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
13551: }
1.267 raeburn 13552: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 13553: if (($item eq 'key') || ($item eq 'secret')) {
13554: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13555: } else {
13556: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13557: }
1.267 raeburn 13558: }
13559: }
13560: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
13561: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
13562: }
13563: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
13564: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
13565: }
1.323 raeburn 13566: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
13567: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
13568: } else {
13569: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
13570: }
1.296 raeburn 13571: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 13572: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
13573: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 13574: if (($item eq 'width') || ($item eq 'height')) {
13575: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
13576: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13577: }
13578: } else {
13579: if ($env{'form.ltitools_add_'.$item} ne '') {
13580: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13581: }
1.267 raeburn 13582: }
13583: }
13584: if ($env{'form.ltitools_add_target'} eq 'window') {
13585: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 13586: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
13587: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 13588: } else {
13589: $confhash{$newid}{'display'}{'target'} = 'iframe';
13590: }
13591: foreach my $item ('passback','roster') {
1.319 raeburn 13592: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 13593: $confhash{$newid}{$item} = 1;
1.319 raeburn 13594: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
13595: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
13596: $lifetime =~ s/^\s+|\s+$//g;
13597: if ($lifetime =~ /^\d+\.?\d*$/) {
13598: $confhash{$newid}{$item.'valid'} = $lifetime;
13599: }
13600: }
1.267 raeburn 13601: }
13602: }
13603: if ($env{'form.ltitools_add_image.filename'} ne '') {
13604: my ($imageurl,$error) =
1.307 raeburn 13605: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 13606: $configuserok,$switchserver,$author_ok);
13607: if ($imageurl) {
13608: $confhash{$newid}{'image'} = $imageurl;
13609: }
13610: if ($error) {
13611: &Apache::lonnet::logthis($error);
13612: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13613: }
13614: }
13615: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
13616: foreach my $field (@fields) {
13617: if ($possfield{$field}) {
13618: if ($field eq 'roles') {
13619: foreach my $role (@courseroles) {
13620: my $choice = $env{'form.ltitools_add_roles_'.$role};
13621: if (($choice ne '') && ($posslti{$choice})) {
13622: $confhash{$newid}{'roles'}{$role} = $choice;
13623: if ($role eq 'cc') {
13624: $confhash{$newid}{'roles'}{'co'} = $choice;
13625: }
13626: }
13627: }
13628: } else {
13629: $confhash{$newid}{'fields'}{$field} = 1;
13630: }
13631: }
13632: }
1.324 raeburn 13633: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
13634: if ($confhash{$newid}{'fields'}{'user'}) {
13635: if ($env{'form.ltitools_userincdom_add'}) {
13636: $confhash{$newid}{'incdom'} = 1;
13637: }
13638: }
13639: }
1.273 raeburn 13640: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
13641: foreach my $item (@courseconfig) {
13642: $confhash{$newid}{'crsconf'}{$item} = 1;
13643: }
1.267 raeburn 13644: if ($env{'form.ltitools_add_custom'}) {
13645: my $name = $env{'form.ltitools_add_custom_name'};
13646: my $value = $env{'form.ltitools_add_custom_value'};
13647: $value =~ s/(`)/'/g;
13648: $name =~ s/(`)/'/g;
13649: $confhash{$newid}{'custom'}{$name} = $value;
13650: }
13651: } else {
13652: my $error = &mt('Failed to acquire unique ID for new external tool');
13653: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13654: }
13655: }
13656: if (ref($domconfig{$action}) eq 'HASH') {
13657: my %deletions;
13658: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
13659: if (@todelete) {
13660: map { $deletions{$_} = 1; } @todelete;
13661: }
13662: my %customadds;
13663: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
13664: if (@newcustom) {
13665: map { $customadds{$_} = 1; } @newcustom;
13666: }
13667: my %imgdeletions;
13668: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13669: if (@todeleteimages) {
13670: map { $imgdeletions{$_} = 1; } @todeleteimages;
13671: }
13672: my $maxnum = $env{'form.ltitools_maxnum'};
13673: for (my $i=0; $i<=$maxnum; $i++) {
13674: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13675: $itemid =~ s/\D+//g;
1.267 raeburn 13676: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13677: if ($deletions{$itemid}) {
13678: if ($domconfig{$action}{$itemid}{'image'}) {
13679: #FIXME need to obsolete item in RES space
13680: }
13681: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13682: next;
13683: } else {
13684: my $newpos = $env{'form.ltitools_'.$itemid};
13685: $newpos =~ s/\D+//g;
1.322 raeburn 13686: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13687: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13688: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13689: $changes{$itemid} = 1;
13690: }
13691: }
1.297 raeburn 13692: foreach my $item ('key','secret') {
13693: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13694: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13695: $changes{$itemid} = 1;
13696: }
13697: }
1.267 raeburn 13698: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13699: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13700: }
13701: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13702: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13703: }
1.323 raeburn 13704: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13705: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13706: } else {
13707: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13708: }
13709: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13710: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13711: $changes{$itemid} = 1;
13712: }
13713: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13714: $changes{$itemid} = 1;
13715: }
1.267 raeburn 13716: foreach my $size ('width','height') {
13717: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13718: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13719: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13720: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13721: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13722: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13723: $changes{$itemid} = 1;
13724: }
13725: } else {
13726: $changes{$itemid} = 1;
13727: }
1.296 raeburn 13728: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13729: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13730: $changes{$itemid} = 1;
13731: }
13732: }
13733: }
13734: foreach my $item ('linktext','explanation') {
13735: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13736: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13737: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13738: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13739: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13740: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13741: $changes{$itemid} = 1;
13742: }
13743: } else {
13744: $changes{$itemid} = 1;
13745: }
13746: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13747: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13748: $changes{$itemid} = 1;
13749: }
1.267 raeburn 13750: }
13751: }
13752: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13753: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13754: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13755: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13756: } else {
13757: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13758: }
13759: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13760: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13761: $changes{$itemid} = 1;
13762: }
13763: } else {
13764: $changes{$itemid} = 1;
13765: }
13766: foreach my $extra ('passback','roster') {
13767: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13768: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13769: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13770: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13771: $lifetime =~ s/^\s+|\s+$//g;
13772: if ($lifetime =~ /^\d+\.?\d*$/) {
13773: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13774: }
13775: }
1.267 raeburn 13776: }
13777: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13778: $changes{$itemid} = 1;
13779: }
1.319 raeburn 13780: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13781: $changes{$itemid} = 1;
13782: }
1.267 raeburn 13783: }
1.273 raeburn 13784: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13785: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13786: if (grep(/^\Q$item\E$/,@courseconfig)) {
13787: $confhash{$itemid}{'crsconf'}{$item} = 1;
13788: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13789: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13790: $changes{$itemid} = 1;
13791: }
13792: } else {
13793: $changes{$itemid} = 1;
13794: }
13795: }
13796: }
1.267 raeburn 13797: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13798: foreach my $field (@fields) {
13799: if ($possfield{$field}) {
13800: if ($field eq 'roles') {
13801: foreach my $role (@courseroles) {
13802: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13803: if (($choice ne '') && ($posslti{$choice})) {
13804: $confhash{$itemid}{'roles'}{$role} = $choice;
13805: if ($role eq 'cc') {
13806: $confhash{$itemid}{'roles'}{'co'} = $choice;
13807: }
13808: }
13809: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13810: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13811: $changes{$itemid} = 1;
13812: }
13813: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13814: $changes{$itemid} = 1;
13815: }
13816: }
13817: } else {
13818: $confhash{$itemid}{'fields'}{$field} = 1;
13819: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13820: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13821: $changes{$itemid} = 1;
13822: }
13823: } else {
13824: $changes{$itemid} = 1;
13825: }
13826: }
13827: }
13828: }
1.324 raeburn 13829: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13830: if ($confhash{$itemid}{'fields'}{'user'}) {
13831: if ($env{'form.ltitools_userincdom_'.$i}) {
13832: $confhash{$itemid}{'incdom'} = 1;
13833: }
13834: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13835: $changes{$itemid} = 1;
13836: }
13837: }
13838: }
1.267 raeburn 13839: $allpos[$newpos] = $itemid;
13840: }
13841: if ($imgdeletions{$itemid}) {
13842: $changes{$itemid} = 1;
13843: #FIXME need to obsolete item in RES space
13844: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13845: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13846: $itemid,$configuserok,$switchserver,
13847: $author_ok);
13848: if ($imgurl) {
13849: $confhash{$itemid}{'image'} = $imgurl;
13850: $changes{$itemid} = 1;
13851: }
13852: if ($error) {
13853: &Apache::lonnet::logthis($error);
13854: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13855: }
13856: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13857: $confhash{$itemid}{'image'} =
13858: $domconfig{$action}{$itemid}{'image'};
13859: }
13860: if ($customadds{$i}) {
13861: my $name = $env{'form.ltitools_custom_name_'.$i};
13862: $name =~ s/(`)/'/g;
13863: $name =~ s/^\s+//;
13864: $name =~ s/\s+$//;
13865: my $value = $env{'form.ltitools_custom_value_'.$i};
13866: $value =~ s/(`)/'/g;
13867: $value =~ s/^\s+//;
13868: $value =~ s/\s+$//;
13869: if ($name ne '') {
13870: $confhash{$itemid}{'custom'}{$name} = $value;
13871: $changes{$itemid} = 1;
13872: }
13873: }
13874: my %customdels;
13875: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13876: if (@customdeletions) {
13877: $changes{$itemid} = 1;
13878: }
13879: map { $customdels{$_} = 1; } @customdeletions;
13880: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13881: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13882: unless ($customdels{$key}) {
13883: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13884: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13885: }
13886: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13887: $changes{$itemid} = 1;
13888: }
13889: }
13890: }
13891: }
13892: unless ($changes{$itemid}) {
13893: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13894: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13895: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13896: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13897: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13898: $changes{$itemid} = 1;
13899: last;
13900: }
13901: }
13902: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13903: $changes{$itemid} = 1;
13904: }
13905: }
13906: last if ($changes{$itemid});
13907: }
13908: }
13909: }
13910: }
13911: }
13912: if (@allpos > 0) {
13913: my $idx = 0;
13914: foreach my $itemid (@allpos) {
13915: if ($itemid ne '') {
13916: $confhash{$itemid}{'order'} = $idx;
13917: if (ref($domconfig{$action}) eq 'HASH') {
13918: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13919: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13920: $changes{$itemid} = 1;
13921: }
13922: }
13923: }
13924: $idx ++;
13925: }
13926: }
13927: }
13928: my %ltitoolshash = (
13929: $action => { %confhash }
13930: );
13931: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13932: $dom);
13933: if ($putresult eq 'ok') {
1.297 raeburn 13934: my %ltienchash = (
13935: $action => { %encconfig }
13936: );
1.384 raeburn 13937: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 13938: if (keys(%changes) > 0) {
13939: my $cachetime = 24*60*60;
1.297 raeburn 13940: my %ltiall = %confhash;
13941: foreach my $id (keys(%ltiall)) {
13942: if (ref($encconfig{$id}) eq 'HASH') {
13943: foreach my $item ('key','secret') {
13944: $ltiall{$id}{$item} = $encconfig{$id}{$item};
13945: }
13946: }
13947: }
13948: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 13949: if (ref($lastactref) eq 'HASH') {
13950: $lastactref->{'ltitools'} = 1;
13951: }
13952: $resulttext = &mt('Changes made:').'<ul>';
13953: my %bynum;
13954: foreach my $itemid (sort(keys(%changes))) {
13955: my $position = $confhash{$itemid}{'order'};
13956: $bynum{$position} = $itemid;
13957: }
13958: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13959: my $itemid = $bynum{$pos};
13960: if (ref($confhash{$itemid}) ne 'HASH') {
13961: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13962: } else {
13963: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
13964: if ($confhash{$itemid}{'image'}) {
13965: $resulttext .= ' '.
13966: '<img src="'.$confhash{$itemid}{'image'}.'"'.
13967: ' alt="'.&mt('Tool Provider icon').'" />';
13968: }
13969: $resulttext .= '</li><ul>';
13970: my $position = $pos + 1;
13971: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 13972: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 13973: if ($confhash{$itemid}{$item} ne '') {
13974: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13975: }
13976: }
1.297 raeburn 13977: if ($encconfig{$itemid}{'key'} ne '') {
13978: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
13979: }
13980: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 13981: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 13982: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 13983: $resulttext .= ('*'x$num).'</li>';
13984: }
1.273 raeburn 13985: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 13986: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 13987: my $numconfig = 0;
13988: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
13989: foreach my $item (@possconfig) {
13990: if ($confhash{$itemid}{'crsconf'}{$item}) {
13991: $numconfig ++;
1.296 raeburn 13992: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 13993: }
13994: }
13995: }
13996: if (!$numconfig) {
1.372 raeburn 13997: $resulttext .= ' '.&mt('None');
1.273 raeburn 13998: }
13999: $resulttext .= '</li>';
1.267 raeburn 14000: foreach my $item ('passback','roster') {
14001: $resulttext .= '<li>'.$lt{$item}.' ';
14002: if ($confhash{$itemid}{$item}) {
14003: $resulttext .= &mt('Yes');
1.319 raeburn 14004: if ($confhash{$itemid}{$item.'valid'}) {
14005: if ($item eq 'passback') {
14006: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
14007: $confhash{$itemid}{$item.'valid'});
14008: } else {
14009: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
14010: $confhash{$itemid}{$item.'valid'});
14011: }
14012: }
1.267 raeburn 14013: } else {
14014: $resulttext .= &mt('No');
14015: }
14016: $resulttext .= '</li>';
14017: }
14018: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
14019: my $displaylist;
14020: if ($confhash{$itemid}{'display'}{'target'}) {
14021: $displaylist = &mt('Display target').': '.
14022: $confhash{$itemid}{'display'}{'target'}.',';
14023: }
14024: foreach my $size ('width','height') {
14025: if ($confhash{$itemid}{'display'}{$size}) {
14026: $displaylist .= (' 'x2).$lt{$size}.': '.
14027: $confhash{$itemid}{'display'}{$size}.',';
14028: }
14029: }
14030: if ($displaylist) {
14031: $displaylist =~ s/,$//;
14032: $resulttext .= '<li>'.$displaylist.'</li>';
14033: }
1.296 raeburn 14034: foreach my $item ('linktext','explanation') {
14035: if ($confhash{$itemid}{'display'}{$item}) {
14036: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
14037: }
14038: }
14039: }
1.267 raeburn 14040: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14041: my $fieldlist;
14042: foreach my $field (@allfields) {
14043: if ($confhash{$itemid}{'fields'}{$field}) {
14044: $fieldlist .= (' 'x2).$lt{$field}.',';
14045: }
14046: }
14047: if ($fieldlist) {
14048: $fieldlist =~ s/,$//;
1.324 raeburn 14049: if ($confhash{$itemid}{'fields'}{'user'}) {
14050: if ($confhash{$itemid}{'incdom'}) {
14051: $fieldlist .= ' ('.&mt('username:domain').')';
14052: } else {
14053: $fieldlist .= ' ('.&mt('username').')';
14054: }
14055: }
1.267 raeburn 14056: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
14057: }
14058: }
14059: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
14060: my $rolemaps;
14061: foreach my $role (@courseroles) {
14062: if ($confhash{$itemid}{'roles'}{$role}) {
14063: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14064: $confhash{$itemid}{'roles'}{$role}.',';
14065: }
14066: }
14067: if ($rolemaps) {
14068: $rolemaps =~ s/,$//;
14069: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14070: }
14071: }
14072: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
14073: my $customlist;
14074: if (keys(%{$confhash{$itemid}{'custom'}})) {
14075: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
14076: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
14077: }
14078: }
14079: if ($customlist) {
1.317 raeburn 14080: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 14081: }
14082: }
14083: $resulttext .= '</ul></li>';
14084: }
14085: }
14086: $resulttext .= '</ul>';
14087: } else {
14088: $resulttext = &mt('No changes made.');
14089: }
14090: } else {
14091: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14092: }
14093: if ($errors) {
14094: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14095: $errors.'</ul>';
14096: }
14097: return $resulttext;
14098: }
14099:
14100: sub process_ltitools_image {
14101: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
14102: my $filename = $env{'form.'.$caller.'.filename'};
14103: my ($error,$url);
14104: my ($width,$height) = (21,21);
14105: if ($configuserok eq 'ok') {
14106: if ($switchserver) {
14107: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
14108: $switchserver);
14109: } elsif ($author_ok eq 'ok') {
14110: my ($result,$imageurl,$madethumb) =
14111: &publishlogo($r,'upload',$caller,$dom,$confname,
14112: "ltitools/$itemid/icon",$width,$height);
14113: if ($result eq 'ok') {
14114: if ($madethumb) {
14115: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14116: my $imagethumb = "$path/tn-".$imagefile;
14117: $url = $imagethumb;
14118: } else {
14119: $url = $imageurl;
14120: }
14121: } else {
14122: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14123: }
14124: } else {
14125: $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);
14126: }
14127: } else {
14128: $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);
14129: }
14130: return ($url,$error);
14131: }
14132:
14133: sub get_ltitools_id {
14134: my ($cdom,$title) = @_;
14135: # get lock on ltitools db
14136: my $lockhash = {
14137: lock => $env{'user.name'}.
14138: ':'.$env{'user.domain'},
14139: };
14140: my $tries = 0;
14141: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14142: my ($id,$error);
14143:
14144: while (($gotlock ne 'ok') && ($tries<10)) {
14145: $tries ++;
14146: sleep (0.1);
14147: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14148: }
14149: if ($gotlock eq 'ok') {
14150: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
14151: if ($currids{'lock'}) {
14152: delete($currids{'lock'});
14153: if (keys(%currids)) {
14154: my @curr = sort { $a <=> $b } keys(%currids);
14155: if ($curr[-1] =~ /^\d+$/) {
14156: $id = 1 + $curr[-1];
14157: }
14158: } else {
14159: $id = 1;
14160: }
14161: if ($id) {
14162: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
14163: $error = 'nostore';
14164: }
14165: } else {
14166: $error = 'nonumber';
14167: }
14168: }
14169: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
14170: } else {
14171: $error = 'nolock';
14172: }
14173: return ($id,$error);
14174: }
14175:
1.372 raeburn 14176: sub modify_proctoring {
14177: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14178: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14179: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14180: my $confname = $dom.'-domainconfig';
14181: my $servadm = $r->dir_config('lonAdmEMail');
14182: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14183: my %providernames = &proctoring_providernames();
14184: my $maxnum = scalar(keys(%providernames));
14185:
14186: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14187: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14188: if (ref($requref) eq 'HASH') {
14189: %requserfields = %{$requref};
14190: }
14191: if (ref($opturef) eq 'HASH') {
14192: %optuserfields = %{$opturef};
14193: }
14194: if (ref($defref) eq 'HASH') {
14195: %defaults = %{$defref};
14196: }
14197: if (ref($extref) eq 'HASH') {
14198: %extended = %{$extref};
14199: }
14200: if (ref($crsref) eq 'HASH') {
14201: %crsconf = %{$crsref};
14202: }
14203: if (ref($rolesref) eq 'ARRAY') {
14204: @courseroles = @{$rolesref};
14205: }
14206: if (ref($ltiref) eq 'ARRAY') {
14207: @ltiroles = @{$ltiref};
14208: }
14209:
14210: if (ref($domconfig{$action}) eq 'HASH') {
14211: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14212: if (@todeleteimages) {
14213: map { $imgdeletions{$_} = 1; } @todeleteimages;
14214: }
14215: }
14216: my %customadds;
14217: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14218: if (@newcustom) {
14219: map { $customadds{$_} = 1; } @newcustom;
14220: }
14221: foreach my $provider (sort(keys(%providernames))) {
14222: $confhash{$provider} = {};
14223: my $pos = $env{'form.proctoring_pos_'.$provider};
14224: $pos =~ s/\D+//g;
14225: $allpos[$pos] = $provider;
14226: my (%current,%currentenc);
14227: my $showroles = 0;
14228: if (ref($domconfig{$action}) eq 'HASH') {
14229: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14230: %current = %{$domconfig{$action}{$provider}};
14231: foreach my $item ('key','secret') {
14232: $currentenc{$item} = $current{$item};
14233: delete($current{$item});
14234: }
14235: }
14236: }
14237: if ($env{'form.proctoring_available_'.$provider}) {
14238: $confhash{$provider}{'available'} = 1;
14239: unless ($current{'available'}) {
14240: $changes{$provider} = 1;
14241: }
14242: } else {
14243: %{$confhash{$provider}} = %current;
14244: %{$encconfhash{$provider}} = %currentenc;
14245: $confhash{$provider}{'available'} = 0;
14246: if ($current{'available'}) {
14247: $changes{$provider} = 1;
14248: }
14249: }
14250: if ($confhash{$provider}{'available'}) {
14251: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14252: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14253: if ($field eq 'lifetime') {
14254: if ($possval =~ /^\d+$/) {
14255: $confhash{$provider}{$field} = $possval;
14256: }
14257: } elsif ($field eq 'version') {
14258: if ($possval =~ /^\d+\.\d+$/) {
14259: $confhash{$provider}{$field} = $possval;
14260: }
14261: } elsif ($field eq 'sigmethod') {
14262: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14263: $confhash{$provider}{$field} = $possval;
14264: }
14265: } elsif ($field eq 'url') {
14266: $confhash{$provider}{$field} = $possval;
14267: } elsif (($field eq 'key') || ($field eq 'secret')) {
14268: $encconfhash{$provider}{$field} = $possval;
14269: unless ($currentenc{$field} eq $possval) {
14270: $changes{$provider} = 1;
14271: }
14272: }
14273: unless (($field eq 'key') || ($field eq 'secret')) {
14274: unless ($current{$field} eq $confhash{$provider}{$field}) {
14275: $changes{$provider} = 1;
14276: }
14277: }
14278: }
14279: if ($imgdeletions{$provider}) {
14280: $changes{$provider} = 1;
14281: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14282: my ($imageurl,$error) =
14283: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14284: $configuserok,$switchserver,$author_ok);
14285: if ($imageurl) {
14286: $confhash{$provider}{'image'} = $imageurl;
14287: $changes{$provider} = 1;
14288: }
14289: if ($error) {
14290: &Apache::lonnet::logthis($error);
14291: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14292: }
14293: } elsif (exists($current{'image'})) {
14294: $confhash{$provider}{'image'} = $current{'image'};
14295: }
14296: if (ref($requserfields{$provider}) eq 'ARRAY') {
14297: if (@{$requserfields{$provider}} > 0) {
14298: if (grep(/^user$/,@{$requserfields{$provider}})) {
14299: if ($env{'form.proctoring_userincdom_'.$provider}) {
14300: $confhash{$provider}{'incdom'} = 1;
14301: }
14302: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14303: $changes{$provider} = 1;
14304: }
14305: }
14306: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14307: $showroles = 1;
14308: }
14309: }
14310: }
14311: $confhash{$provider}{'fields'} = [];
14312: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14313: if (@{$optuserfields{$provider}} > 0) {
14314: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14315: foreach my $field (@{$optuserfields{$provider}}) {
14316: if (grep(/^\Q$field\E$/,@optfields)) {
14317: push(@{$confhash{$provider}{'fields'}},$field);
14318: }
14319: }
14320: }
14321: if (ref($current{'fields'}) eq 'ARRAY') {
14322: unless ($changes{$provider}) {
14323: my @new = sort(@{$confhash{$provider}{'fields'}});
14324: my @old = sort(@{$current{'fields'}});
14325: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14326: if (@diffs) {
14327: $changes{$provider} = 1;
14328: }
14329: }
14330: } elsif (@{$confhash{$provider}{'fields'}}) {
14331: $changes{$provider} = 1;
14332: }
14333: }
14334: if (ref($defaults{$provider}) eq 'ARRAY') {
14335: if (@{$defaults{$provider}} > 0) {
14336: my %options;
14337: if (ref($extended{$provider}) eq 'HASH') {
14338: %options = %{$extended{$provider}};
14339: }
14340: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14341: foreach my $field (@{$defaults{$provider}}) {
14342: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14343: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14344: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14345: push(@{$confhash{$provider}{'defaults'}},$poss);
14346: }
14347: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14348: foreach my $inner (keys(%{$options{$field}})) {
14349: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14350: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14351: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14352: $confhash{$provider}{'defaults'}{$inner} = $poss;
14353: }
14354: } else {
14355: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14356: }
14357: }
14358: } else {
14359: if (grep(/^\Q$field\E$/,@checked)) {
14360: push(@{$confhash{$provider}{'defaults'}},$field);
14361: }
14362: }
14363: }
14364: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14365: if (ref($current{'defaults'}) eq 'ARRAY') {
14366: unless ($changes{$provider}) {
14367: my @new = sort(@{$confhash{$provider}{'defaults'}});
14368: my @old = sort(@{$current{'defaults'}});
14369: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14370: if (@diffs) {
14371: $changes{$provider} = 1;
14372: }
14373: }
14374: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14375: if (@{$current{'defaults'}}) {
14376: $changes{$provider} = 1;
14377: }
14378: }
14379: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14380: if (ref($current{'defaults'}) eq 'HASH') {
14381: unless ($changes{$provider}) {
14382: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14383: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14384: $changes{$provider} = 1;
14385: last;
14386: }
14387: }
14388: }
14389: unless ($changes{$provider}) {
14390: foreach my $key (keys(%{$current{'defaults'}})) {
14391: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14392: $changes{$provider} = 1;
14393: last;
14394: }
14395: }
14396: }
14397: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14398: $changes{$provider} = 1;
14399: }
14400: }
14401: }
14402: }
14403: if (ref($crsconf{$provider}) eq 'ARRAY') {
14404: if (@{$crsconf{$provider}} > 0) {
14405: $confhash{$provider}{'crsconf'} = [];
14406: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14407: foreach my $crsfield (@{$crsconf{$provider}}) {
14408: if (grep(/^\Q$crsfield\E$/,@checked)) {
14409: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14410: }
14411: }
14412: if (ref($current{'crsconf'}) eq 'ARRAY') {
14413: unless ($changes{$provider}) {
14414: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14415: my @old = sort(@{$current{'crsconf'}});
14416: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14417: if (@diffs) {
14418: $changes{$provider} = 1;
14419: }
14420: }
14421: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14422: $changes{$provider} = 1;
14423: }
14424: }
14425: }
14426: if ($showroles) {
14427: $confhash{$provider}{'roles'} = {};
14428: foreach my $role (@courseroles) {
14429: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14430: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14431: $confhash{$provider}{'roles'}{$role} = $poss;
14432: }
14433: }
14434: unless ($changes{$provider}) {
14435: if (ref($current{'roles'}) eq 'HASH') {
14436: foreach my $role (keys(%{$current{'roles'}})) {
14437: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14438: $changes{$provider} = 1;
14439: last
14440: }
14441: }
14442: unless ($changes{$provider}) {
14443: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14444: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14445: $changes{$provider} = 1;
14446: last;
14447: }
14448: }
14449: }
14450: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14451: $changes{$provider} = 1;
14452: }
14453: }
14454: }
14455: if (ref($current{'custom'}) eq 'HASH') {
14456: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14457: foreach my $key (keys(%{$current{'custom'}})) {
14458: if (grep(/^\Q$key\E$/,@customdels)) {
14459: $changes{$provider} = 1;
14460: } else {
14461: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14462: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14463: $changes{$provider} = 1;
14464: }
14465: }
14466: }
14467: }
14468: if ($customadds{$provider}) {
14469: my $name = $env{'form.proctoring_custom_name_'.$provider};
14470: $name =~ s/(`)/'/g;
14471: $name =~ s/^\s+//;
14472: $name =~ s/\s+$//;
14473: my $value = $env{'form.proctoring_custom_value_'.$provider};
14474: $value =~ s/(`)/'/g;
14475: $value =~ s/^\s+//;
14476: $value =~ s/\s+$//;
14477: if ($name ne '') {
14478: $confhash{$provider}{'custom'}{$name} = $value;
14479: $changes{$provider} = 1;
14480: }
14481: }
14482: }
14483: }
14484: if (@allpos > 0) {
14485: my $idx = 0;
14486: foreach my $provider (@allpos) {
14487: if ($provider ne '') {
14488: $confhash{$provider}{'order'} = $idx;
14489: unless ($changes{$provider}) {
14490: if (ref($domconfig{$action}) eq 'HASH') {
14491: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14492: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14493: $changes{$provider} = 1;
14494: }
14495: }
14496: }
14497: }
14498: $idx ++;
14499: }
14500: }
14501: }
14502: my %proc_hash = (
14503: $action => { %confhash }
14504: );
14505: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14506: $dom);
14507: if ($putresult eq 'ok') {
14508: my %proc_enchash = (
14509: $action => { %encconfhash }
14510: );
1.384 raeburn 14511: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14512: if (keys(%changes) > 0) {
14513: my $cachetime = 24*60*60;
14514: my %procall = %confhash;
14515: foreach my $provider (keys(%procall)) {
14516: if (ref($encconfhash{$provider}) eq 'HASH') {
14517: foreach my $key ('key','secret') {
14518: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14519: }
14520: }
14521: }
14522: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14523: if (ref($lastactref) eq 'HASH') {
14524: $lastactref->{'proctoring'} = 1;
14525: }
14526: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14527: my %bynum;
14528: foreach my $provider (sort(keys(%changes))) {
14529: my $position = $confhash{$provider}{'order'};
14530: $bynum{$position} = $provider;
14531: }
14532: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14533: my $provider = $bynum{$pos};
14534: my %lt = &proctoring_titles($provider);
14535: my %fieldtitles = &proctoring_fieldtitles($provider);
14536: if (!$confhash{$provider}{'available'}) {
14537: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14538: } else {
14539: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14540: if ($confhash{$provider}{'image'}) {
14541: $resulttext .= ' '.
14542: '<img src="'.$confhash{$provider}{'image'}.'"'.
14543: ' alt="'.&mt('Proctoring icon').'" />';
14544: }
14545: $resulttext .= '<ul>';
14546: my $position = $pos + 1;
14547: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14548: foreach my $key ('version','sigmethod','url','lifetime') {
14549: if ($confhash{$provider}{$key} ne '') {
14550: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14551: }
14552: }
14553: if ($encconfhash{$provider}{'key'} ne '') {
14554: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14555: }
14556: if ($encconfhash{$provider}{'secret'} ne '') {
14557: $resulttext .= '<li>'.$lt{'secret'}.': ';
14558: my $num = length($encconfhash{$provider}{'secret'});
14559: $resulttext .= ('*'x$num).'</li>';
14560: }
14561: my (@fields,$showroles);
14562: if (ref($requserfields{$provider}) eq 'ARRAY') {
14563: push(@fields,@{$requserfields{$provider}});
14564: }
14565: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14566: push(@fields,@{$confhash{$provider}{'fields'}});
14567: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14568: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14569: }
14570: if (@fields) {
14571: if (grep(/^roles$/,@fields)) {
14572: $showroles = 1;
14573: }
14574: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14575: join('", "', map { $lt{$_}; } @fields).'"</li>';
14576: }
14577: if (ref($requserfields{$provider}) eq 'ARRAY') {
14578: if (grep(/^user$/,@{$requserfields{$provider}})) {
14579: if ($confhash{$provider}{'incdom'}) {
14580: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14581: } else {
14582: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14583: }
14584: }
14585: }
14586: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14587: if (@{$confhash{$provider}{'defaults'}} > 0) {
14588: $resulttext .= '<li>'.$lt{'defa'};
14589: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14590: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14591: }
14592: $resulttext =~ s/,$//;
14593: $resulttext .= '</li>';
14594: }
14595: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14596: if (keys(%{$confhash{$provider}{'defaults'}})) {
14597: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14598: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14599: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14600: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14601: }
14602: }
14603: $resulttext .= '</ul></li>';
14604: }
14605: }
14606: if (ref($crsconf{$provider}) eq 'ARRAY') {
14607: if (@{$crsconf{$provider}} > 0) {
14608: $resulttext .= '<li>'.&mt('Configurable in course:');
14609: my $numconfig = 0;
14610: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14611: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14612: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14613: $numconfig ++;
14614: if ($provider eq 'examity') {
14615: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14616: } else {
14617: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14618: }
14619: }
14620: $resulttext =~ s/,$//;
14621: }
14622: }
14623: if (!$numconfig) {
14624: $resulttext .= ' '.&mt('None');
14625: }
14626: $resulttext .= '</li>';
14627: }
14628: }
14629: if ($showroles) {
14630: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14631: my $rolemaps;
14632: foreach my $role (@courseroles) {
14633: if ($confhash{$provider}{'roles'}{$role}) {
14634: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14635: $confhash{$provider}{'roles'}{$role}.',';
14636: }
14637: }
14638: if ($rolemaps) {
14639: $rolemaps =~ s/,$//;
14640: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14641: }
14642: }
14643: }
14644: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
14645: my $customlist;
14646: if (keys(%{$confhash{$provider}{'custom'}})) {
14647: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
14648: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
14649: }
14650: $customlist =~ s/,$//;
14651: }
14652: if ($customlist) {
14653: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
14654: }
14655: }
14656: $resulttext .= '</ul></li>';
14657: }
14658: }
14659: $resulttext .= '</ul>';
14660: } else {
14661: $resulttext = &mt('No changes made.');
14662: }
14663: } else {
14664: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14665: }
14666: if ($errors) {
14667: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14668: $errors.'</ul>';
14669: }
14670: return $resulttext;
14671: }
14672:
14673: sub process_proctoring_image {
14674: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14675: my $filename = $env{'form.'.$caller.'.filename'};
14676: my ($error,$url);
14677: my ($width,$height) = (21,21);
14678: if ($configuserok eq 'ok') {
14679: if ($switchserver) {
14680: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14681: $switchserver);
14682: } elsif ($author_ok eq 'ok') {
14683: my ($result,$imageurl,$madethumb) =
14684: &publishlogo($r,'upload',$caller,$dom,$confname,
14685: "proctoring/$provider/icon",$width,$height);
14686: if ($result eq 'ok') {
14687: if ($madethumb) {
14688: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14689: my $imagethumb = "$path/tn-".$imagefile;
14690: $url = $imagethumb;
14691: } else {
14692: $url = $imageurl;
14693: }
14694: } else {
14695: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14696: }
14697: } else {
14698: $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);
14699: }
14700: } else {
14701: $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);
14702: }
14703: return ($url,$error);
14704: }
14705:
1.320 raeburn 14706: sub modify_lti {
14707: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14708: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14709: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14710: my (%posslti,%posslticrs,%posscrstype);
14711: my @courseroles = ('cc','in','ta','ep','st');
14712: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14713: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14714: my @coursetypes = ('official','unofficial','community','textbook','placement');
14715: my %coursetypetitles = &Apache::lonlocal::texthash (
14716: official => 'Official',
14717: unofficial => 'Unofficial',
14718: community => 'Community',
14719: textbook => 'Textbook',
14720: placement => 'Placement Test',
14721: );
1.325 raeburn 14722: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14723: my %lt = <i_names();
14724: map { $posslti{$_} = 1; } @ltiroles;
14725: map { $posslticrs{$_} = 1; } @lticourseroles;
14726: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14727:
1.326 raeburn 14728: my %menutitles = <imenu_titles();
14729:
1.320 raeburn 14730: my (@items,%deletions,%itemids);
14731: if ($env{'form.lti_add'}) {
14732: my $consumer = $env{'form.lti_consumer_add'};
14733: $consumer =~ s/(`)/'/g;
14734: ($newid,my $error) = &get_lti_id($dom,$consumer);
14735: if ($newid) {
14736: $itemids{'add'} = $newid;
14737: push(@items,'add');
14738: $changes{$newid} = 1;
14739: } else {
14740: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14741: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14742: }
14743: }
14744: if (ref($domconfig{$action}) eq 'HASH') {
14745: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14746: if (@todelete) {
14747: map { $deletions{$_} = 1; } @todelete;
14748: }
14749: my $maxnum = $env{'form.lti_maxnum'};
14750: for (my $i=0; $i<=$maxnum; $i++) {
14751: my $itemid = $env{'form.lti_id_'.$i};
14752: $itemid =~ s/\D+//g;
14753: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14754: if ($deletions{$itemid}) {
14755: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14756: } else {
14757: push(@items,$i);
14758: $itemids{$i} = $itemid;
14759: }
14760: }
14761: }
14762: }
14763: foreach my $idx (@items) {
14764: my $itemid = $itemids{$idx};
14765: next unless ($itemid);
14766: my $position = $env{'form.lti_pos_'.$idx};
14767: $position =~ s/\D+//g;
14768: if ($position ne '') {
14769: $allpos[$position] = $itemid;
14770: }
1.345 raeburn 14771: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 14772: my $formitem = 'form.lti_'.$item.'_'.$idx;
14773: $env{$formitem} =~ s/(`)/'/g;
14774: if ($item eq 'lifetime') {
14775: $env{$formitem} =~ s/[^\d.]//g;
14776: }
14777: if ($env{$formitem} ne '') {
14778: if (($item eq 'key') || ($item eq 'secret')) {
14779: $encconfig{$itemid}{$item} = $env{$formitem};
14780: } else {
14781: $confhash{$itemid}{$item} = $env{$formitem};
14782: unless (($idx eq 'add') || ($changes{$itemid})) {
14783: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14784: $changes{$itemid} = 1;
14785: }
14786: }
14787: }
14788: }
14789: }
14790: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14791: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14792: }
1.345 raeburn 14793: if ($confhash{$itemid}{'requser'}) {
14794: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14795: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14796: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14797: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14798: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14799: my $mapuser = $env{'form.lti_customuser_'.$idx};
14800: $mapuser =~ s/(`)/'/g;
14801: $mapuser =~ s/^\s+|\s+$//g;
14802: $confhash{$itemid}{'mapuser'} = $mapuser;
14803: }
14804: foreach my $ltirole (@lticourseroles) {
14805: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14806: if (grep(/^\Q$possrole\E$/,@courseroles)) {
14807: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
14808: }
14809: }
14810: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14811: my @makeuser;
14812: foreach my $ltirole (sort(@possmakeuser)) {
14813: if ($posslti{$ltirole}) {
14814: push(@makeuser,$ltirole);
14815: }
14816: }
14817: $confhash{$itemid}{'makeuser'} = \@makeuser;
14818: if (@makeuser) {
14819: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14820: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14821: $confhash{$itemid}{'lcauth'} = $lcauth;
14822: if ($lcauth ne 'internal') {
14823: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14824: $lcauthparm =~ s/^(\s+|\s+)$//g;
14825: $lcauthparm =~ s/`//g;
14826: if ($lcauthparm ne '') {
14827: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14828: }
14829: }
14830: } else {
14831: $confhash{$itemid}{'lcauth'} = 'lti';
14832: }
1.320 raeburn 14833: }
1.345 raeburn 14834: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14835: if (@possinstdata) {
14836: foreach my $field (@possinstdata) {
14837: if (exists($fieldtitles{$field})) {
14838: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14839: }
14840: }
14841: }
1.345 raeburn 14842: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14843: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14844: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14845: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14846: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14847: $mapcrs =~ s/(`)/'/g;
14848: $mapcrs =~ s/^\s+|\s+$//g;
14849: $confhash{$itemid}{'mapcrs'} = $mapcrs;
14850: }
14851: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14852: my @crstypes;
14853: foreach my $type (sort(@posstypes)) {
14854: if ($posscrstype{$type}) {
14855: push(@crstypes,$type);
1.325 raeburn 14856: }
14857: }
1.345 raeburn 14858: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14859: if ($env{'form.lti_makecrs_'.$idx}) {
14860: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 14861: }
1.345 raeburn 14862: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14863: my @selfenroll;
14864: foreach my $type (sort(@possenroll)) {
14865: if ($posslticrs{$type}) {
14866: push(@selfenroll,$type);
14867: }
1.320 raeburn 14868: }
1.345 raeburn 14869: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14870: if ($env{'form.lti_crssec_'.$idx}) {
14871: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14872: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14873: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14874: my $section = $env{'form.lti_customsection_'.$idx};
14875: $section =~ s/(`)/'/g;
14876: $section =~ s/^\s+|\s+$//g;
14877: if ($section ne '') {
14878: $confhash{$itemid}{'section'} = $section;
14879: }
1.320 raeburn 14880: }
14881: }
1.363 raeburn 14882: if ($env{'form.lti_callback_'.$idx}) {
14883: if ($env{'form.lti_callbackparam_'.$idx}) {
14884: my $callback = $env{'form.lti_callbackparam_'.$idx};
14885: $callback =~ s/^\s+|\s+$//g;
14886: $confhash{$itemid}{'callback'} = $callback;
14887: }
14888: }
1.345 raeburn 14889: foreach my $field ('passback','roster','topmenu','inlinemenu') {
14890: if ($env{'form.lti_'.$field.'_'.$idx}) {
14891: $confhash{$itemid}{$field} = 1;
14892: }
1.320 raeburn 14893: }
1.345 raeburn 14894: if ($env{'form.lti_passback_'.$idx}) {
14895: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14896: $confhash{$itemid}{'passbackformat'} = '1.0';
14897: } else {
14898: $confhash{$itemid}{'passbackformat'} = '1.1';
14899: }
1.337 raeburn 14900: }
1.345 raeburn 14901: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14902: $confhash{$itemid}{lcmenu} = [];
14903: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14904: foreach my $field (@possmenu) {
14905: if (exists($menutitles{$field})) {
14906: if ($field eq 'grades') {
14907: next unless ($env{'form.lti_inlinemenu_'.$idx});
14908: }
14909: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14910: }
14911: }
14912: }
1.345 raeburn 14913: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 14914: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 14915: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 14916: $changes{$itemid} = 1;
14917: }
14918: }
1.320 raeburn 14919: unless ($changes{$itemid}) {
1.345 raeburn 14920: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
14921: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14922: $changes{$itemid} = 1;
14923: }
1.345 raeburn 14924: }
1.320 raeburn 14925: }
1.345 raeburn 14926: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
14927: unless ($changes{$itemid}) {
14928: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
14929: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14930: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
14931: $confhash{$itemid}{$field});
14932: if (@diffs) {
14933: $changes{$itemid} = 1;
14934: }
14935: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
14936: $changes{$itemid} = 1;
14937: }
14938: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14939: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 14940: $changes{$itemid} = 1;
14941: }
14942: }
1.345 raeburn 14943: }
14944: }
14945: unless ($changes{$itemid}) {
14946: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
14947: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14948: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
14949: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
14950: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 14951: $changes{$itemid} = 1;
14952: last;
14953: }
14954: }
1.345 raeburn 14955: unless ($changes{$itemid}) {
14956: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14957: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14958: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
14959: $changes{$itemid} = 1;
14960: last;
14961: }
14962: }
14963: }
14964: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
14965: $changes{$itemid} = 1;
1.320 raeburn 14966: }
1.345 raeburn 14967: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14968: unless ($changes{$itemid}) {
14969: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
14970: $changes{$itemid} = 1;
14971: }
1.320 raeburn 14972: }
14973: }
14974: }
14975: }
14976: }
14977: }
14978: if (@allpos > 0) {
14979: my $idx = 0;
14980: foreach my $itemid (@allpos) {
14981: if ($itemid ne '') {
14982: $confhash{$itemid}{'order'} = $idx;
14983: if (ref($domconfig{$action}) eq 'HASH') {
14984: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14985: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14986: $changes{$itemid} = 1;
14987: }
14988: }
14989: }
14990: $idx ++;
14991: }
14992: }
14993: }
14994: my %ltihash = (
14995: $action => { %confhash }
14996: );
14997: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
14998: $dom);
14999: if ($putresult eq 'ok') {
15000: my %ltienchash = (
15001: $action => { %encconfig }
15002: );
1.384 raeburn 15003: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320 raeburn 15004: if (keys(%changes) > 0) {
15005: my $cachetime = 24*60*60;
15006: my %ltiall = %confhash;
15007: foreach my $id (keys(%ltiall)) {
15008: if (ref($encconfig{$id}) eq 'HASH') {
15009: foreach my $item ('key','secret') {
15010: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15011: }
15012: }
15013: }
15014: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15015: if (ref($lastactref) eq 'HASH') {
15016: $lastactref->{'lti'} = 1;
15017: }
15018: $resulttext = &mt('Changes made:').'<ul>';
15019: my %bynum;
15020: foreach my $itemid (sort(keys(%changes))) {
15021: my $position = $confhash{$itemid}{'order'};
15022: $bynum{$position} = $itemid;
15023: }
15024: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15025: my $itemid = $bynum{$pos};
15026: if (ref($confhash{$itemid}) ne 'HASH') {
15027: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15028: } else {
15029: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
15030: my $position = $pos + 1;
15031: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15032: foreach my $item ('version','lifetime') {
15033: if ($confhash{$itemid}{$item} ne '') {
15034: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15035: }
15036: }
15037: if ($encconfig{$itemid}{'key'} ne '') {
15038: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15039: }
15040: if ($encconfig{$itemid}{'secret'} ne '') {
15041: $resulttext .= '<li>'.$lt{'secret'}.': ';
15042: my $num = length($encconfig{$itemid}{'secret'});
15043: $resulttext .= ('*'x$num).'</li>';
15044: }
1.345 raeburn 15045: if ($confhash{$itemid}{'requser'}) {
15046: if ($confhash{$itemid}{'mapuser'}) {
15047: my $shownmapuser;
15048: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15049: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15050: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15051: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15052: } else {
15053: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15054: }
1.345 raeburn 15055: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15056: }
1.345 raeburn 15057: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15058: my $rolemaps;
15059: foreach my $role (@ltiroles) {
15060: if ($confhash{$itemid}{'maproles'}{$role}) {
15061: $rolemaps .= (' 'x2).$role.'='.
15062: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15063: 'Course').',';
15064: }
15065: }
15066: if ($rolemaps) {
15067: $rolemaps =~ s/,$//;
15068: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15069: }
15070: }
15071: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15072: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15073: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15074: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15075: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15076: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15077: } else {
15078: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15079: $confhash{$itemid}{'lcauth'});
15080: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15081: $resulttext .= '; '.&mt('a randomly generated password will be created');
15082: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15083: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15084: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15085: }
15086: } else {
15087: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15088: }
15089: }
15090: $resulttext .= '</li>';
15091: } else {
15092: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15093: }
1.320 raeburn 15094: }
1.345 raeburn 15095: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15096: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15097: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15098: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15099: } else {
1.345 raeburn 15100: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15101: }
1.320 raeburn 15102: }
1.345 raeburn 15103: if ($confhash{$itemid}{'mapcrs'}) {
15104: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15105: }
15106: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15107: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15108: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15109: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15110: '</li>';
15111: } else {
15112: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15113: }
1.325 raeburn 15114: }
1.345 raeburn 15115: if ($confhash{$itemid}{'makecrs'}) {
15116: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 15117: } else {
1.345 raeburn 15118: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 15119: }
1.345 raeburn 15120: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15121: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15122: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15123: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15124: '</li>';
15125: } else {
15126: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15127: }
1.320 raeburn 15128: }
1.345 raeburn 15129: if ($confhash{$itemid}{'section'}) {
15130: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15131: $resulttext .= '<li>'.&mt('User section from standard field:').
15132: ' (course_section_sourcedid)'.'</li>';
15133: } else {
15134: $resulttext .= '<li>'.&mt('User section from:').' '.
15135: $confhash{$itemid}{'section'}.'</li>';
15136: }
1.320 raeburn 15137: } else {
1.345 raeburn 15138: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 15139: }
1.363 raeburn 15140: if ($confhash{$itemid}{'callback'}) {
15141: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15142: } else {
15143: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
15144: }
1.345 raeburn 15145: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15146: $resulttext .= '<li>'.$lt{$item}.': ';
15147: if ($confhash{$itemid}{$item}) {
15148: $resulttext .= &mt('Yes');
15149: if ($item eq 'passback') {
15150: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15151: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15152: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15153: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15154: }
1.337 raeburn 15155: }
1.345 raeburn 15156: } else {
15157: $resulttext .= &mt('No');
1.337 raeburn 15158: }
1.345 raeburn 15159: $resulttext .= '</li>';
1.320 raeburn 15160: }
1.345 raeburn 15161: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15162: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15163: $resulttext .= '<li>'.&mt('Menu items:').' '.
15164: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15165: } else {
15166: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15167: }
1.326 raeburn 15168: }
15169: }
1.320 raeburn 15170: $resulttext .= '</ul></li>';
15171: }
15172: }
15173: $resulttext .= '</ul>';
15174: } else {
15175: $resulttext = &mt('No changes made.');
15176: }
15177: } else {
15178: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15179: }
15180: if ($errors) {
15181: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15182: $errors.'</ul>';
15183: }
15184: return $resulttext;
15185: }
15186:
15187: sub get_lti_id {
15188: my ($domain,$consumer) = @_;
15189: # get lock on lti db
15190: my $lockhash = {
15191: lock => $env{'user.name'}.
15192: ':'.$env{'user.domain'},
15193: };
15194: my $tries = 0;
15195: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15196: my ($id,$error);
15197:
15198: while (($gotlock ne 'ok') && ($tries<10)) {
15199: $tries ++;
15200: sleep (0.1);
15201: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15202: }
15203: if ($gotlock eq 'ok') {
15204: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15205: if ($currids{'lock'}) {
15206: delete($currids{'lock'});
15207: if (keys(%currids)) {
15208: my @curr = sort { $a <=> $b } keys(%currids);
15209: if ($curr[-1] =~ /^\d+$/) {
15210: $id = 1 + $curr[-1];
15211: }
15212: } else {
15213: $id = 1;
15214: }
15215: if ($id) {
15216: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15217: $error = 'nostore';
15218: }
15219: } else {
15220: $error = 'nonumber';
15221: }
15222: }
15223: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15224: } else {
15225: $error = 'nolock';
15226: }
15227: return ($id,$error);
15228: }
15229:
1.3 raeburn 15230: sub modify_autoenroll {
1.205 raeburn 15231: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15232: my ($resulttext,%changes);
15233: my %currautoenroll;
15234: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15235: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15236: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15237: }
15238: }
15239: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15240: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15241: sender => 'Sender for notification messages',
1.274 raeburn 15242: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
15243: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15244: my @offon = ('off','on');
1.17 raeburn 15245: my $sender_uname = $env{'form.sender_uname'};
15246: my $sender_domain = $env{'form.sender_domain'};
15247: if ($sender_domain eq '') {
15248: $sender_uname = '';
15249: } elsif ($sender_uname eq '') {
15250: $sender_domain = '';
15251: }
1.129 raeburn 15252: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 15253: my $failsafe = $env{'form.autoenroll_failsafe'};
15254: $failsafe =~ s{^\s+|\s+$}{}g;
15255: if ($failsafe =~ /\D/) {
15256: undef($failsafe);
15257: }
1.1 raeburn 15258: my %autoenrollhash = (
1.129 raeburn 15259: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15260: 'sender_uname' => $sender_uname,
15261: 'sender_domain' => $sender_domain,
15262: 'co-owners' => $coowners,
1.274 raeburn 15263: 'autofailsafe' => $failsafe,
1.1 raeburn 15264: }
15265: );
1.4 raeburn 15266: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15267: $dom);
1.1 raeburn 15268: if ($putresult eq 'ok') {
15269: if (exists($currautoenroll{'run'})) {
15270: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15271: $changes{'run'} = 1;
15272: }
15273: } elsif ($autorun) {
15274: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15275: $changes{'run'} = 1;
1.1 raeburn 15276: }
15277: }
1.17 raeburn 15278: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15279: $changes{'sender'} = 1;
15280: }
1.17 raeburn 15281: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15282: $changes{'sender'} = 1;
15283: }
1.129 raeburn 15284: if ($currautoenroll{'co-owners'} ne '') {
15285: if ($currautoenroll{'co-owners'} ne $coowners) {
15286: $changes{'coowners'} = 1;
15287: }
15288: } elsif ($coowners) {
15289: $changes{'coowners'} = 1;
1.274 raeburn 15290: }
15291: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
15292: $changes{'autofailsafe'} = 1;
15293: }
1.1 raeburn 15294: if (keys(%changes) > 0) {
15295: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15296: if ($changes{'run'}) {
1.1 raeburn 15297: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15298: }
15299: if ($changes{'sender'}) {
1.17 raeburn 15300: if ($sender_uname eq '' || $sender_domain eq '') {
15301: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15302: } else {
15303: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15304: }
1.1 raeburn 15305: }
1.129 raeburn 15306: if ($changes{'coowners'}) {
15307: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15308: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15309: if (ref($lastactref) eq 'HASH') {
15310: $lastactref->{'domainconfig'} = 1;
15311: }
1.129 raeburn 15312: }
1.274 raeburn 15313: if ($changes{'autofailsafe'}) {
15314: if ($failsafe ne '') {
1.299 raeburn 15315: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 15316: } else {
1.299 raeburn 15317: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 15318: }
15319: &Apache::lonnet::get_domain_defaults($dom,1);
15320: if (ref($lastactref) eq 'HASH') {
15321: $lastactref->{'domdefaults'} = 1;
15322: }
15323: }
1.1 raeburn 15324: $resulttext .= '</ul>';
15325: } else {
15326: $resulttext = &mt('No changes made to auto-enrollment settings');
15327: }
15328: } else {
1.11 albertel 15329: $resulttext = '<span class="LC_error">'.
15330: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15331: }
1.3 raeburn 15332: return $resulttext;
1.1 raeburn 15333: }
15334:
15335: sub modify_autoupdate {
1.3 raeburn 15336: my ($dom,%domconfig) = @_;
1.1 raeburn 15337: my ($resulttext,%currautoupdate,%fields,%changes);
15338: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
15339: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
15340: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
15341: }
15342: }
15343: my @offon = ('off','on');
15344: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 15345: run => 'Auto-update:',
15346: classlists => 'Updates to user information in classlists?',
15347: unexpired => 'Skip updates for users without active or future roles?',
15348: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 15349: );
1.44 raeburn 15350: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 15351: my %fieldtitles = &Apache::lonlocal::texthash (
15352: id => 'Student/Employee ID',
1.20 raeburn 15353: permanentemail => 'E-mail address',
1.1 raeburn 15354: lastname => 'Last Name',
15355: firstname => 'First Name',
15356: middlename => 'Middle Name',
1.132 raeburn 15357: generation => 'Generation',
1.1 raeburn 15358: );
1.142 raeburn 15359: $othertitle = &mt('All users');
1.1 raeburn 15360: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 15361: $othertitle = &mt('Other users');
1.1 raeburn 15362: }
15363: foreach my $key (keys(%env)) {
15364: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 15365: my ($usertype,$item) = ($1,$2);
15366: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
15367: if ($usertype eq 'default') {
15368: push(@{$fields{$1}},$2);
15369: } elsif (ref($types) eq 'ARRAY') {
15370: if (grep(/^\Q$usertype\E$/,@{$types})) {
15371: push(@{$fields{$1}},$2);
15372: }
15373: }
15374: }
1.1 raeburn 15375: }
15376: }
1.131 raeburn 15377: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
15378: @lockablenames = sort(@lockablenames);
15379: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
15380: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15381: if (@changed) {
15382: $changes{'lockablenames'} = 1;
15383: }
15384: } else {
15385: if (@lockablenames) {
15386: $changes{'lockablenames'} = 1;
15387: }
15388: }
1.1 raeburn 15389: my %updatehash = (
15390: autoupdate => { run => $env{'form.autoupdate_run'},
15391: classlists => $env{'form.classlists'},
1.385 raeburn 15392: unexpired => $env{'form.unexpired'},
1.1 raeburn 15393: fields => {%fields},
1.131 raeburn 15394: lockablenames => \@lockablenames,
1.1 raeburn 15395: }
15396: );
1.385 raeburn 15397: my $lastactivedays;
15398: if ($env{'form.lastactive'}) {
15399: $lastactivedays = $env{'form.lastactivedays'};
15400: $lastactivedays =~ s/^\s+|\s+$//g;
15401: unless ($lastactivedays =~ /^\d+$/) {
15402: undef($lastactivedays);
15403: $env{'form.lastactive'} = 0;
15404: }
15405: }
15406: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 15407: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 15408: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 15409: if (exists($updatehash{autoupdate}{$key})) {
15410: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
15411: $changes{$key} = 1;
15412: }
15413: }
15414: } elsif ($key eq 'fields') {
15415: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 15416: foreach my $item (@{$types},'default') {
1.1 raeburn 15417: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
15418: my $change = 0;
15419: foreach my $type (@{$currautoupdate{$key}{$item}}) {
15420: if (!exists($fields{$item})) {
15421: $change = 1;
1.132 raeburn 15422: last;
1.1 raeburn 15423: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15424: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15425: $change = 1;
1.132 raeburn 15426: last;
1.1 raeburn 15427: }
15428: }
15429: }
15430: if ($change) {
15431: push(@{$changes{$key}},$item);
15432: }
1.26 raeburn 15433: }
1.1 raeburn 15434: }
15435: }
1.131 raeburn 15436: } elsif ($key eq 'lockablenames') {
15437: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15438: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15439: if (@changed) {
15440: $changes{'lockablenames'} = 1;
15441: }
15442: } else {
15443: if (@lockablenames) {
15444: $changes{'lockablenames'} = 1;
15445: }
15446: }
15447: }
15448: }
15449: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15450: if (@lockablenames) {
15451: $changes{'lockablenames'} = 1;
1.1 raeburn 15452: }
15453: }
1.385 raeburn 15454: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15455: if ($updatehash{'autoupdate'}{'unexpired'}) {
15456: $changes{'unexpired'} = 1;
15457: }
15458: }
15459: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15460: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15461: $changes{'lastactive'} = 1;
15462: }
15463: }
1.26 raeburn 15464: foreach my $item (@{$types},'default') {
15465: if (defined($fields{$item})) {
15466: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15467: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15468: my $change = 0;
15469: if (ref($fields{$item}) eq 'ARRAY') {
15470: foreach my $type (@{$fields{$item}}) {
15471: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15472: $change = 1;
15473: last;
15474: }
15475: }
15476: }
15477: if ($change) {
15478: push(@{$changes{'fields'}},$item);
15479: }
15480: } else {
1.26 raeburn 15481: push(@{$changes{'fields'}},$item);
15482: }
15483: } else {
15484: push(@{$changes{'fields'}},$item);
1.1 raeburn 15485: }
15486: }
15487: }
15488: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15489: $dom);
15490: if ($putresult eq 'ok') {
15491: if (keys(%changes) > 0) {
15492: $resulttext = &mt('Changes made:').'<ul>';
15493: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15494: if ($key eq 'lockablenames') {
15495: $resulttext .= '<li>';
15496: if (@lockablenames) {
15497: $usertypes->{'default'} = $othertitle;
15498: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15499: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15500: } else {
15501: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15502: }
15503: $resulttext .= '</li>';
15504: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15505: foreach my $item (@{$changes{$key}}) {
15506: my @newvalues;
15507: foreach my $type (@{$fields{$item}}) {
15508: push(@newvalues,$fieldtitles{$type});
15509: }
1.3 raeburn 15510: my $newvaluestr;
15511: if (@newvalues > 0) {
15512: $newvaluestr = join(', ',@newvalues);
15513: } else {
15514: $newvaluestr = &mt('none');
1.6 raeburn 15515: }
1.1 raeburn 15516: if ($item eq 'default') {
1.26 raeburn 15517: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15518: } else {
1.26 raeburn 15519: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15520: }
15521: }
15522: } else {
15523: my $newvalue;
15524: if ($key eq 'run') {
15525: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 15526: } elsif ($key eq 'lastactive') {
15527: $newvalue = $offon[$env{'form.lastactive'}];
15528: unless ($lastactivedays eq '') {
15529: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15530: }
1.1 raeburn 15531: } else {
15532: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15533: }
1.1 raeburn 15534: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15535: }
15536: }
15537: $resulttext .= '</ul>';
15538: } else {
1.3 raeburn 15539: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15540: }
15541: } else {
1.11 albertel 15542: $resulttext = '<span class="LC_error">'.
15543: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15544: }
1.3 raeburn 15545: return $resulttext;
1.1 raeburn 15546: }
15547:
1.125 raeburn 15548: sub modify_autocreate {
15549: my ($dom,%domconfig) = @_;
15550: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15551: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15552: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15553: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15554: }
15555: }
15556: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15557: req => 'Auto-creation of validated requests for official courses',
15558: xmldc => 'Identity of course creator of courses from XML files',
15559: );
15560: my @types = ('xml','req');
15561: foreach my $item (@types) {
15562: $newvals{$item} = $env{'form.autocreate_'.$item};
15563: $newvals{$item} =~ s/\D//g;
15564: $newvals{$item} = 0 if ($newvals{$item} eq '');
15565: }
15566: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 15567: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15568: unless (exists($domcoords{$newvals{'xmldc'}})) {
15569: $newvals{'xmldc'} = '';
15570: }
15571: %autocreatehash = (
15572: autocreate => { xml => $newvals{'xml'},
15573: req => $newvals{'req'},
15574: }
15575: );
15576: if ($newvals{'xmldc'} ne '') {
15577: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15578: }
15579: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15580: $dom);
15581: if ($putresult eq 'ok') {
15582: my @items = @types;
15583: if ($newvals{'xml'}) {
15584: push(@items,'xmldc');
15585: }
15586: foreach my $item (@items) {
15587: if (exists($currautocreate{$item})) {
15588: if ($currautocreate{$item} ne $newvals{$item}) {
15589: $changes{$item} = 1;
15590: }
15591: } elsif ($newvals{$item}) {
15592: $changes{$item} = 1;
15593: }
15594: }
15595: if (keys(%changes) > 0) {
15596: my @offon = ('off','on');
15597: $resulttext = &mt('Changes made:').'<ul>';
15598: foreach my $item (@types) {
15599: if ($changes{$item}) {
15600: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 15601: $resulttext .= '<li>'.
15602: &mt("$title{$item} set to [_1]$newtxt [_2]",
15603: '<b>','</b>').
15604: '</li>';
1.125 raeburn 15605: }
15606: }
15607: if ($changes{'xmldc'}) {
15608: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15609: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 15610: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15611: }
15612: $resulttext .= '</ul>';
15613: } else {
15614: $resulttext = &mt('No changes made to auto-creation settings');
15615: }
15616: } else {
15617: $resulttext = '<span class="LC_error">'.
15618: &mt('An error occurred: [_1]',$putresult).'</span>';
15619: }
15620: return $resulttext;
15621: }
15622:
1.23 raeburn 15623: sub modify_directorysrch {
1.295 raeburn 15624: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15625: my ($resulttext,%changes);
15626: my %currdirsrch;
15627: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15628: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15629: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15630: }
15631: }
1.277 raeburn 15632: my %title = ( available => 'Institutional directory search available',
15633: localonly => 'Other domains can search institution',
15634: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 15635: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15636: searchby => 'Search types',
15637: searchtypes => 'Search latitude');
15638: my @offon = ('off','on');
1.24 raeburn 15639: my @otherdoms = ('Yes','No');
1.23 raeburn 15640:
1.25 raeburn 15641: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15642: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15643: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15644:
1.44 raeburn 15645: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15646: if (keys(%{$usertypes}) == 0) {
15647: @cansearch = ('default');
15648: } else {
15649: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15650: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15651: if (!grep(/^\Q$type\E$/,@cansearch)) {
15652: push(@{$changes{'cansearch'}},$type);
15653: }
1.23 raeburn 15654: }
1.26 raeburn 15655: foreach my $type (@cansearch) {
15656: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15657: push(@{$changes{'cansearch'}},$type);
15658: }
1.23 raeburn 15659: }
1.26 raeburn 15660: } else {
15661: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15662: }
15663: }
15664:
15665: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15666: foreach my $by (@{$currdirsrch{'searchby'}}) {
15667: if (!grep(/^\Q$by\E$/,@searchby)) {
15668: push(@{$changes{'searchby'}},$by);
15669: }
15670: }
15671: foreach my $by (@searchby) {
15672: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15673: push(@{$changes{'searchby'}},$by);
15674: }
15675: }
15676: } else {
15677: push(@{$changes{'searchby'}},@searchby);
15678: }
1.25 raeburn 15679:
15680: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15681: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15682: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15683: push(@{$changes{'searchtypes'}},$type);
15684: }
15685: }
15686: foreach my $type (@searchtypes) {
15687: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15688: push(@{$changes{'searchtypes'}},$type);
15689: }
15690: }
15691: } else {
15692: if (exists($currdirsrch{'searchtypes'})) {
15693: foreach my $type (@searchtypes) {
15694: if ($type ne $currdirsrch{'searchtypes'}) {
15695: push(@{$changes{'searchtypes'}},$type);
15696: }
15697: }
15698: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15699: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15700: }
15701: } else {
15702: push(@{$changes{'searchtypes'}},@searchtypes);
15703: }
15704: }
15705:
1.23 raeburn 15706: my %dirsrch_hash = (
15707: directorysrch => { available => $env{'form.dirsrch_available'},
15708: cansearch => \@cansearch,
1.277 raeburn 15709: localonly => $env{'form.dirsrch_instlocalonly'},
15710: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15711: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15712: searchby => \@searchby,
1.25 raeburn 15713: searchtypes => \@searchtypes,
1.23 raeburn 15714: }
15715: );
15716: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15717: $dom);
15718: if ($putresult eq 'ok') {
15719: if (exists($currdirsrch{'available'})) {
15720: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15721: $changes{'available'} = 1;
15722: }
15723: } else {
15724: if ($env{'form.dirsrch_available'} eq '1') {
15725: $changes{'available'} = 1;
15726: }
15727: }
1.277 raeburn 15728: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15729: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15730: $changes{'lcavailable'} = 1;
15731: }
1.277 raeburn 15732: } else {
15733: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15734: $changes{'lcavailable'} = 1;
15735: }
15736: }
1.24 raeburn 15737: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15738: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15739: $changes{'localonly'} = 1;
15740: }
1.24 raeburn 15741: } else {
1.277 raeburn 15742: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15743: $changes{'localonly'} = 1;
15744: }
15745: }
1.277 raeburn 15746: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15747: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15748: $changes{'lclocalonly'} = 1;
15749: }
1.277 raeburn 15750: } else {
15751: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15752: $changes{'lclocalonly'} = 1;
15753: }
15754: }
1.23 raeburn 15755: if (keys(%changes) > 0) {
15756: $resulttext = &mt('Changes made:').'<ul>';
15757: if ($changes{'available'}) {
15758: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15759: }
1.277 raeburn 15760: if ($changes{'lcavailable'}) {
15761: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15762: }
1.24 raeburn 15763: if ($changes{'localonly'}) {
1.277 raeburn 15764: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15765: }
1.277 raeburn 15766: if ($changes{'lclocalonly'}) {
15767: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15768: }
1.23 raeburn 15769: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15770: my $chgtext;
1.26 raeburn 15771: if (ref($usertypes) eq 'HASH') {
15772: if (keys(%{$usertypes}) > 0) {
15773: foreach my $type (@{$types}) {
15774: if (grep(/^\Q$type\E$/,@cansearch)) {
15775: $chgtext .= $usertypes->{$type}.'; ';
15776: }
15777: }
15778: if (grep(/^default$/,@cansearch)) {
15779: $chgtext .= $othertitle;
15780: } else {
15781: $chgtext =~ s/\; $//;
15782: }
1.210 raeburn 15783: $resulttext .=
1.178 raeburn 15784: '<li>'.
15785: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15786: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15787: '</li>';
1.23 raeburn 15788: }
15789: }
15790: }
15791: if (ref($changes{'searchby'}) eq 'ARRAY') {
15792: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15793: my $chgtext;
15794: foreach my $type (@{$titleorder}) {
15795: if (grep(/^\Q$type\E$/,@searchby)) {
15796: if (defined($searchtitles->{$type})) {
15797: $chgtext .= $searchtitles->{$type}.'; ';
15798: }
15799: }
15800: }
15801: $chgtext =~ s/\; $//;
15802: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15803: }
1.25 raeburn 15804: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15805: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15806: my $chgtext;
15807: foreach my $type (@{$srchtypeorder}) {
15808: if (grep(/^\Q$type\E$/,@searchtypes)) {
15809: if (defined($srchtypes_desc->{$type})) {
15810: $chgtext .= $srchtypes_desc->{$type}.'; ';
15811: }
15812: }
15813: }
15814: $chgtext =~ s/\; $//;
1.178 raeburn 15815: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15816: }
15817: $resulttext .= '</ul>';
1.295 raeburn 15818: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15819: if (ref($lastactref) eq 'HASH') {
15820: $lastactref->{'directorysrch'} = 1;
15821: }
1.23 raeburn 15822: } else {
1.277 raeburn 15823: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15824: }
15825: } else {
15826: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15827: &mt('An error occurred: [_1]',$putresult).'</span>';
15828: }
15829: return $resulttext;
15830: }
15831:
1.28 raeburn 15832: sub modify_contacts {
1.205 raeburn 15833: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15834: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15835: if (ref($domconfig{'contacts'}) eq 'HASH') {
15836: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15837: $currsetting{$key} = $domconfig{'contacts'}{$key};
15838: }
15839: }
1.286 raeburn 15840: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15841: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15842: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15843: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15844: my @toggles = ('reporterrors','reportupdates','reportstatus');
15845: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15846: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15847: foreach my $type (@mailings) {
15848: @{$newsetting{$type}} =
15849: &Apache::loncommon::get_env_multiple('form.'.$type);
15850: foreach my $item (@contacts) {
15851: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15852: $contacts_hash{contacts}{$type}{$item} = 1;
15853: } else {
15854: $contacts_hash{contacts}{$type}{$item} = 0;
15855: }
1.289 raeburn 15856: }
1.28 raeburn 15857: $others{$type} = $env{'form.'.$type.'_others'};
15858: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15859: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15860: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15861: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15862: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15863: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15864: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15865: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15866: }
1.134 raeburn 15867: }
1.28 raeburn 15868: }
15869: foreach my $item (@contacts) {
15870: $to{$item} = $env{'form.'.$item};
15871: $contacts_hash{'contacts'}{$item} = $to{$item};
15872: }
1.203 raeburn 15873: foreach my $item (@toggles) {
15874: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15875: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15876: }
15877: }
1.340 raeburn 15878: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15879: foreach my $item (@lonstatus) {
15880: if ($item eq 'excluded') {
15881: my (%serverhomes,@excluded);
15882: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15883: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15884: if (@possexcluded) {
15885: foreach my $id (sort(@possexcluded)) {
15886: if ($serverhomes{$id}) {
15887: push(@excluded,$id);
15888: }
15889: }
15890: }
15891: if (@excluded) {
15892: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15893: }
15894: } elsif ($item eq 'weights') {
1.377 raeburn 15895: foreach my $type ('E','W','N','U') {
1.340 raeburn 15896: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15897: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15898: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15899: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15900: $env{'form.error'.$item.'_'.$type};
15901: }
15902: }
15903: }
15904: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15905: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15906: if ($env{'form.error'.$item} =~ /^\d+$/) {
15907: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15908: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15909: }
15910: }
15911: }
15912: }
1.286 raeburn 15913: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15914: foreach my $field (@{$fields}) {
15915: if (ref($possoptions->{$field}) eq 'ARRAY') {
15916: my $value = $env{'form.helpform_'.$field};
15917: $value =~ s/^\s+|\s+$//g;
15918: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 15919: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 15920: if ($field eq 'screenshot') {
15921: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15922: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 15923: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 15924: }
15925: }
15926: }
15927: }
15928: }
15929: }
1.315 raeburn 15930: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15931: my (@statuses,%usertypeshash,@overrides);
15932: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15933: @statuses = @{$types};
15934: if (ref($usertypes) eq 'HASH') {
15935: %usertypeshash = %{$usertypes};
15936: }
15937: }
15938: if (@statuses) {
15939: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15940: foreach my $type (@possoverrides) {
15941: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15942: push(@overrides,$type);
15943: }
15944: }
15945: if (@overrides) {
15946: foreach my $type (@overrides) {
15947: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15948: foreach my $item (@contacts) {
15949: if (grep(/^\Q$item\E$/,@standard)) {
15950: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15951: $newsetting{'override_'.$type}{$item} = 1;
15952: } else {
15953: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15954: $newsetting{'override_'.$type}{$item} = 0;
15955: }
15956: }
15957: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15958: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15959: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15960: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15961: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15962: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15963: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15964: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15965: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15966: }
15967: }
15968: }
15969: }
1.28 raeburn 15970: if (keys(%currsetting) > 0) {
15971: foreach my $item (@contacts) {
15972: if ($to{$item} ne $currsetting{$item}) {
15973: $changes{$item} = 1;
15974: }
15975: }
15976: foreach my $type (@mailings) {
15977: foreach my $item (@contacts) {
15978: if (ref($currsetting{$type}) eq 'HASH') {
15979: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15980: push(@{$changes{$type}},$item);
15981: }
15982: } else {
15983: push(@{$changes{$type}},@{$newsetting{$type}});
15984: }
15985: }
15986: if ($others{$type} ne $currsetting{$type}{'others'}) {
15987: push(@{$changes{$type}},'others');
15988: }
1.289 raeburn 15989: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15990: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15991: push(@{$changes{$type}},'bcc');
15992: }
1.286 raeburn 15993: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15994: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15995: push(@{$changes{$type}},'include');
15996: }
15997: }
15998: }
15999: if (ref($fields) eq 'ARRAY') {
16000: if (ref($currsetting{'helpform'}) eq 'HASH') {
16001: foreach my $field (@{$fields}) {
16002: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16003: push(@{$changes{'helpform'}},$field);
16004: }
16005: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16006: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16007: push(@{$changes{'helpform'}},'maxsize');
16008: }
16009: }
16010: }
16011: } else {
16012: foreach my $field (@{$fields}) {
16013: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16014: push(@{$changes{'helpform'}},$field);
16015: }
16016: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16017: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16018: push(@{$changes{'helpform'}},'maxsize');
16019: }
16020: }
16021: }
1.134 raeburn 16022: }
1.28 raeburn 16023: }
1.315 raeburn 16024: if (@statuses) {
16025: if (ref($currsetting{'overrides'}) eq 'HASH') {
16026: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16027: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16028: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16029: foreach my $item (@contacts,'bcc','others','include') {
16030: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16031: push(@{$changes{'overrides'}},$key);
16032: last;
16033: }
16034: }
16035: } else {
16036: push(@{$changes{'overrides'}},$key);
16037: }
16038: }
16039: }
16040: foreach my $key (@overrides) {
16041: unless (exists($currsetting{'overrides'}{$key})) {
16042: push(@{$changes{'overrides'}},$key);
16043: }
16044: }
16045: } else {
16046: foreach my $key (@overrides) {
16047: push(@{$changes{'overrides'}},$key);
16048: }
16049: }
16050: }
1.340 raeburn 16051: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16052: foreach my $key ('excluded','weights','threshold','sysmail') {
16053: if ($key eq 'excluded') {
16054: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16055: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16056: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16057: (@{$currsetting{'lonstatus'}{$key}})) {
16058: my @diffs =
16059: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16060: $currsetting{'lonstatus'}{$key});
16061: if (@diffs) {
16062: push(@{$changes{'lonstatus'}},$key);
16063: }
16064: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16065: push(@{$changes{'lonstatus'}},$key);
16066: }
16067: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16068: (@{$currsetting{'lonstatus'}{$key}})) {
16069: push(@{$changes{'lonstatus'}},$key);
16070: }
16071: } elsif ($key eq 'weights') {
16072: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16073: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16074: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16075: foreach my $type ('E','W','N','U') {
1.340 raeburn 16076: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16077: $currsetting{'lonstatus'}{$key}{$type}) {
16078: push(@{$changes{'lonstatus'}},$key);
16079: last;
16080: }
16081: }
16082: } else {
1.341 raeburn 16083: foreach my $type ('E','W','N','U') {
1.340 raeburn 16084: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16085: push(@{$changes{'lonstatus'}},$key);
16086: last;
16087: }
16088: }
16089: }
16090: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16091: foreach my $type ('E','W','N','U') {
1.340 raeburn 16092: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16093: push(@{$changes{'lonstatus'}},$key);
16094: last;
16095: }
16096: }
16097: }
16098: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16099: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16100: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16101: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16102: push(@{$changes{'lonstatus'}},$key);
16103: }
16104: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16105: push(@{$changes{'lonstatus'}},$key);
16106: }
16107: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16108: push(@{$changes{'lonstatus'}},$key);
16109: }
16110: }
16111: }
16112: } else {
16113: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16114: foreach my $key ('excluded','weights','threshold','sysmail') {
16115: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16116: push(@{$changes{'lonstatus'}},$key);
16117: }
16118: }
16119: }
16120: }
1.28 raeburn 16121: } else {
16122: my %default;
16123: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16124: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16125: $default{'errormail'} = 'adminemail';
16126: $default{'packagesmail'} = 'adminemail';
16127: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16128: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16129: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16130: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16131: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16132: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16133: foreach my $item (@contacts) {
16134: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16135: $changes{$item} = 1;
1.203 raeburn 16136: }
1.28 raeburn 16137: }
16138: foreach my $type (@mailings) {
16139: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16140: push(@{$changes{$type}},@{$newsetting{$type}});
16141: }
16142: if ($others{$type} ne '') {
16143: push(@{$changes{$type}},'others');
1.134 raeburn 16144: }
1.286 raeburn 16145: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16146: if ($bcc{$type} ne '') {
16147: push(@{$changes{$type}},'bcc');
16148: }
1.286 raeburn 16149: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16150: push(@{$changes{$type}},'include');
16151: }
1.134 raeburn 16152: }
1.28 raeburn 16153: }
1.286 raeburn 16154: if (ref($fields) eq 'ARRAY') {
16155: foreach my $field (@{$fields}) {
16156: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16157: push(@{$changes{'helpform'}},$field);
16158: }
16159: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16160: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16161: push(@{$changes{'helpform'}},'maxsize');
16162: }
16163: }
16164: }
1.289 raeburn 16165: }
1.340 raeburn 16166: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16167: foreach my $key ('excluded','weights','threshold','sysmail') {
16168: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16169: push(@{$changes{'lonstatus'}},$key);
16170: }
16171: }
16172: }
1.28 raeburn 16173: }
1.203 raeburn 16174: foreach my $item (@toggles) {
16175: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16176: $changes{$item} = 1;
16177: } elsif ((!$env{'form.'.$item}) &&
16178: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16179: $changes{$item} = 1;
16180: }
16181: }
1.28 raeburn 16182: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16183: $dom);
16184: if ($putresult eq 'ok') {
16185: if (keys(%changes) > 0) {
1.205 raeburn 16186: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16187: if (ref($lastactref) eq 'HASH') {
16188: $lastactref->{'domainconfig'} = 1;
16189: }
1.28 raeburn 16190: my ($titles,$short_titles) = &contact_titles();
16191: $resulttext = &mt('Changes made:').'<ul>';
16192: foreach my $item (@contacts) {
16193: if ($changes{$item}) {
16194: $resulttext .= '<li>'.$titles->{$item}.
16195: &mt(' set to: ').
16196: '<span class="LC_cusr_emph">'.
16197: $to{$item}.'</span></li>';
16198: }
16199: }
16200: foreach my $type (@mailings) {
16201: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16202: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16203: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16204: } else {
16205: $resulttext .= '<li>'.$titles->{$type}.': ';
16206: }
1.28 raeburn 16207: my @text;
16208: foreach my $item (@{$newsetting{$type}}) {
16209: push(@text,$short_titles->{$item});
16210: }
16211: if ($others{$type} ne '') {
16212: push(@text,$others{$type});
16213: }
1.286 raeburn 16214: if (@text) {
16215: $resulttext .= '<span class="LC_cusr_emph">'.
16216: join(', ',@text).'</span>';
16217: }
16218: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16219: if ($bcc{$type} ne '') {
1.286 raeburn 16220: my $bcctext;
16221: if (@text) {
1.289 raeburn 16222: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16223: } else {
16224: $bcctext = '(Bcc)';
16225: }
16226: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16227: } elsif (!@text) {
16228: $resulttext .= &mt('No one');
16229: }
1.289 raeburn 16230: if ($includestr{$type} ne '') {
1.286 raeburn 16231: if ($includeloc{$type} eq 'b') {
16232: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16233: } elsif ($includeloc{$type} eq 's') {
16234: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16235: }
1.134 raeburn 16236: }
1.286 raeburn 16237: } elsif (!@text) {
16238: $resulttext .= &mt('No recipients');
1.134 raeburn 16239: }
16240: $resulttext .= '</li>';
1.28 raeburn 16241: }
16242: }
1.315 raeburn 16243: if (ref($changes{'overrides'}) eq 'ARRAY') {
16244: my @deletions;
16245: foreach my $type (@{$changes{'overrides'}}) {
16246: if ($usertypeshash{$type}) {
16247: if (grep(/^\Q$type\E/,@overrides)) {
16248: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16249: $usertypeshash{$type}).'<ul><li>';
16250: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16251: my @text;
16252: foreach my $item (@contacts) {
16253: if ($newsetting{'override_'.$type}{$item}) {
16254: push(@text,$short_titles->{$item});
16255: }
16256: }
16257: if ($newsetting{'override_'.$type}{'others'} ne '') {
16258: push(@text,$newsetting{'override_'.$type}{'others'});
16259: }
16260:
16261: if (@text) {
16262: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16263: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16264: }
16265: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16266: my $bcctext;
16267: if (@text) {
16268: $bcctext = ' '.&mt('with Bcc to');
16269: } else {
16270: $bcctext = '(Bcc)';
16271: }
16272: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16273: } elsif (!@text) {
16274: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16275: }
16276: $resulttext .= '</li>';
16277: if ($newsetting{'override_'.$type}{'include'} ne '') {
16278: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16279: if ($loc eq 'b') {
16280: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16281: } elsif ($loc eq 's') {
16282: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16283: }
16284: }
16285: }
16286: $resulttext .= '</li></ul></li>';
16287: } else {
16288: push(@deletions,$usertypeshash{$type});
16289: }
16290: }
16291: }
16292: if (@deletions) {
16293: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16294: join(', ',@deletions)).'</li>';
16295: }
16296: }
1.203 raeburn 16297: my @offon = ('off','on');
1.340 raeburn 16298: my $corelink = &core_link_msu();
1.203 raeburn 16299: if ($changes{'reporterrors'}) {
16300: $resulttext .= '<li>'.
16301: &mt('E-mail error reports to [_1] set to "'.
16302: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16303: $corelink).
1.203 raeburn 16304: '</li>';
16305: }
16306: if ($changes{'reportupdates'}) {
16307: $resulttext .= '<li>'.
16308: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16309: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16310: $corelink).
1.203 raeburn 16311: '</li>';
16312: }
1.340 raeburn 16313: if ($changes{'reportstatus'}) {
16314: $resulttext .= '<li>'.
16315: &mt('E-mail status if errors above threshold to [_1] set to "'.
16316: $offon[$env{'form.reportstatus'}].'".',
16317: $corelink).
16318: '</li>';
16319: }
16320: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16321: $resulttext .= '<li>'.
16322: &mt('Nightly status check e-mail settings').':<ul>';
16323: my (%defval,%use_def,%shown);
16324: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
16325: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
16326: $defval{'weights'} =
1.341 raeburn 16327: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 16328: $defval{'excluded'} = &mt('None');
16329: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
16330: foreach my $item ('threshold','sysmail','weights','excluded') {
16331: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
16332: if (($item eq 'threshold') || ($item eq 'sysmail')) {
16333: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
16334: } elsif ($item eq 'weights') {
16335: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 16336: foreach my $type ('E','W','N','U') {
1.340 raeburn 16337: $shown{$item} .= $lonstatus_names->{$type}.'=';
16338: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
16339: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
16340: } else {
16341: $shown{$item} .= $lonstatus_defs->{$type};
16342: }
16343: $shown{$item} .= ', ';
16344: }
16345: $shown{$item} =~ s/, $//;
16346: } else {
16347: $shown{$item} = $defval{$item};
16348: }
16349: } elsif ($item eq 'excluded') {
16350: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
16351: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
16352: } else {
16353: $shown{$item} = $defval{$item};
16354: }
16355: }
16356: } else {
16357: $shown{$item} = $defval{$item};
16358: }
16359: }
16360: } else {
16361: foreach my $item ('threshold','weights','excluded','sysmail') {
16362: $shown{$item} = $defval{$item};
16363: }
16364: }
16365: foreach my $item ('threshold','weights','excluded','sysmail') {
16366: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
16367: $shown{$item}).'</li>';
16368: }
16369: $resulttext .= '</ul></li>';
16370: }
1.286 raeburn 16371: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
16372: my (@optional,@required,@unused,$maxsizechg);
16373: foreach my $field (@{$changes{'helpform'}}) {
16374: if ($field eq 'maxsize') {
16375: $maxsizechg = 1;
16376: next;
16377: }
16378: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 16379: push(@optional,$field);
1.286 raeburn 16380: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
16381: push(@unused,$field);
16382: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 16383: push(@required,$field);
1.286 raeburn 16384: }
16385: }
16386: if (@optional) {
16387: $resulttext .= '<li>'.
16388: &mt('Help form fields changed to "Optional": [_1].',
16389: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
16390: '</li>';
16391: }
16392: if (@required) {
16393: $resulttext .= '<li>'.
16394: &mt('Help form fields changed to "Required": [_1].',
16395: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
16396: '</li>';
16397: }
16398: if (@unused) {
16399: $resulttext .= '<li>'.
16400: &mt('Help form fields changed to "Not shown": [_1].',
16401: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
16402: '</li>';
16403: }
16404: if ($maxsizechg) {
16405: $resulttext .= '<li>'.
16406: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
16407: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
16408: '</li>';
16409: }
16410: }
1.28 raeburn 16411: $resulttext .= '</ul>';
16412: } else {
1.288 raeburn 16413: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 16414: }
16415: } else {
16416: $resulttext = '<span class="LC_error">'.
16417: &mt('An error occurred: [_1].',$putresult).'</span>';
16418: }
16419: return $resulttext;
16420: }
16421:
1.357 raeburn 16422: sub modify_privacy {
16423: my ($dom,%domconfig) = @_;
16424: my ($resulttext,%current,%changes);
16425: if (ref($domconfig{'privacy'}) eq 'HASH') {
16426: %current = %{$domconfig{'privacy'}};
16427: }
16428: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
16429: my @items = ('domain','author','course','community');
16430: my %names = &Apache::lonlocal::texthash (
16431: domain => 'Assigned domain role(s)',
16432: author => 'Assigned co-author role(s)',
16433: course => 'Assigned course role(s)',
16434: community => 'Assigned community role',
16435: );
16436: my %roles = &Apache::lonlocal::texthash (
16437: domain => 'Domain role',
16438: author => 'Co-author role',
16439: course => 'Course role',
16440: community => 'Community role',
16441: );
16442: my %titles = &Apache::lonlocal::texthash (
16443: approval => 'Approval for role in different domain',
16444: othdom => 'User information available in other domain',
16445: priv => 'Information viewable by privileged user in same domain',
16446: unpriv => 'Information viewable by unprivileged user in same domain',
16447: instdom => 'Other domain shares institution/provider',
16448: extdom => 'Other domain has different institution/provider',
16449: none => 'Not allowed',
16450: user => 'User authorizes',
16451: domain => 'Domain Coordinator authorizes',
16452: auto => 'Unrestricted',
16453: );
16454: my %fieldnames = &Apache::lonlocal::texthash (
16455: id => 'Student/Employee ID',
16456: permanentemail => 'E-mail address',
16457: lastname => 'Last Name',
16458: firstname => 'First Name',
16459: middlename => 'Middle Name',
16460: generation => 'Generation',
16461: );
16462: my ($othertitle,$usertypes,$types) =
16463: &Apache::loncommon::sorted_inst_types($dom);
16464: my (%by_ip,%by_location,@intdoms,@instdoms);
16465: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16466:
16467: my %privacyhash = (
16468: 'approval' => {
16469: instdom => {},
16470: extdom => {},
16471: },
16472: 'othdom' => {},
16473: 'priv' => {},
16474: 'unpriv' => {},
16475: );
16476: foreach my $item (@items) {
16477: if (@instdoms > 1) {
16478: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
16479: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
16480: }
16481: if (ref($current{'approval'}) eq 'HASH') {
16482: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
16483: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
16484: $changes{'approval'} = 1;
16485: }
16486: }
16487: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
16488: $changes{'approval'} = 1;
16489: }
16490: }
16491: if (keys(%by_location) > 0) {
16492: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
16493: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
16494: }
16495: if (ref($current{'approval'}) eq 'HASH') {
16496: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
16497: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
16498: $changes{'approval'} = 1;
16499: }
16500: }
16501: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
16502: $changes{'approval'} = 1;
16503: }
16504: }
16505: foreach my $status ('priv','unpriv') {
16506: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
16507: my @newvalues;
16508: foreach my $field (@possibles) {
16509: if (grep(/^\Q$field\E$/,@fields)) {
16510: $privacyhash{$status}{$item}{$field} = 1;
16511: push(@newvalues,$field);
16512: }
16513: }
16514: @newvalues = sort(@newvalues);
16515: if (ref($current{$status}) eq 'HASH') {
16516: if (ref($current{$status}{$item}) eq 'HASH') {
16517: my @currvalues = sort(keys(%{$current{$status}{$item}}));
16518: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16519: if (@diffs > 0) {
16520: $changes{$status} = 1;
16521: }
16522: }
16523: } else {
16524: my @stdfields;
16525: foreach my $field (@fields) {
16526: if ($field eq 'id') {
16527: next if ($status eq 'unpriv');
16528: next if (($status eq 'priv') && ($item eq 'community'));
16529: }
16530: push(@stdfields,$field);
16531: }
16532: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16533: if (@diffs > 0) {
16534: $changes{$status} = 1;
16535: }
16536: }
16537: }
16538: }
16539: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
16540: my @statuses;
16541: if (ref($types) eq 'ARRAY') {
16542: @statuses = @{$types};
16543: }
16544: foreach my $type (@statuses,'default') {
16545: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
16546: my @newvalues;
16547: foreach my $field (sort(@possfields)) {
16548: if (grep(/^\Q$field\E$/,@fields)) {
16549: $privacyhash{'othdom'}{$type}{$field} = 1;
16550: push(@newvalues,$field);
16551: }
16552: }
16553: @newvalues = sort(@newvalues);
16554: if (ref($current{'othdom'}) eq 'HASH') {
16555: if (ref($current{'othdom'}{$type}) eq 'HASH') {
16556: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
16557: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16558: if (@diffs > 0) {
16559: $changes{'othdom'} = 1;
16560: }
16561: }
16562: } else {
16563: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
16564: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16565: if (@diffs > 0) {
16566: $changes{'othdom'} = 1;
16567: }
16568: }
16569: }
16570: }
16571: my %confighash = (
16572: privacy => \%privacyhash,
16573: );
16574: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16575: if ($putresult eq 'ok') {
16576: if (keys(%changes) > 0) {
16577: $resulttext = &mt('Changes made: ').'<ul>';
16578: foreach my $key ('approval','othdom','priv','unpriv') {
16579: if ($changes{$key}) {
16580: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16581: if ($key eq 'approval') {
16582: if (keys(%{$privacyhash{$key}{instdom}})) {
16583: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
16584: foreach my $item (@items) {
16585: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
16586: }
16587: $resulttext .= '</ul></li>';
16588: }
16589: if (keys(%{$privacyhash{$key}{extdom}})) {
16590: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
16591: foreach my $item (@items) {
16592: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
16593: }
16594: $resulttext .= '</ul></li>';
16595: }
16596: } elsif ($key eq 'othdom') {
16597: my @statuses;
16598: if (ref($types) eq 'ARRAY') {
16599: @statuses = @{$types};
16600: }
16601: if (ref($privacyhash{$key}) eq 'HASH') {
16602: foreach my $status (@statuses,'default') {
16603: if ($status eq 'default') {
16604: $resulttext .= '<li>'.$othertitle.': ';
16605: } elsif (ref($usertypes) eq 'HASH') {
16606: $resulttext .= '<li>'.$usertypes->{$status}.': ';
16607: } else {
16608: next;
16609: }
16610: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
16611: if (keys(%{$privacyhash{$key}{$status}})) {
16612: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
16613: } else {
16614: $resulttext .= &mt('none');
16615: }
16616: }
16617: $resulttext .= '</li>';
16618: }
16619: }
16620: } else {
16621: foreach my $item (@items) {
16622: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
16623: $resulttext .= '<li>'.$names{$item}.': ';
16624: if (keys(%{$privacyhash{$key}{$item}})) {
16625: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
16626: } else {
16627: $resulttext .= &mt('none');
16628: }
16629: $resulttext .= '</li>';
16630: }
16631: }
16632: }
16633: $resulttext .= '</ul></li>';
16634: }
16635: }
16636: } else {
16637: $resulttext = &mt('No changes made to user information settings');
16638: }
16639: } else {
16640: $resulttext = '<span class="LC_error">'.
16641: &mt('An error occurred: [_1]',$putresult).'</span>';
16642: }
16643: return $resulttext;
16644: }
16645:
1.354 raeburn 16646: sub modify_passwords {
16647: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 16648: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
16649: $updatedefaults,$updateconf);
1.354 raeburn 16650: my $customfn = 'resetpw.html';
16651: if (ref($domconfig{'passwords'}) eq 'HASH') {
16652: %current = %{$domconfig{'passwords'}};
16653: }
16654: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16655: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16656: if (ref($types) eq 'ARRAY') {
16657: @oktypes = @{$types};
16658: }
16659: push(@oktypes,'default');
16660:
16661: my %titles = &Apache::lonlocal::texthash (
16662: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
16663: intauth_check => 'Check bcrypt cost if authenticated',
16664: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16665: permanent => 'Permanent e-mail address',
16666: critical => 'Critical notification address',
16667: notify => 'Notification address',
16668: min => 'Minimum password length',
16669: max => 'Maximum password length',
16670: chars => 'Required characters',
16671: expire => 'Password expiration (days)',
1.356 raeburn 16672: numsaved => 'Number of previous passwords to save',
1.354 raeburn 16673: reset => 'Resetting Forgotten Password',
16674: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16675: rules => 'Rules for LON-CAPA Passwords',
16676: crsownerchg => 'Course Owner Changing Student Passwords',
16677: username => 'Username',
16678: email => 'E-mail address',
16679: );
16680:
16681: #
16682: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16683: #
16684: my (%curr_defaults,%save_defaults);
16685: if (ref($domconfig{'defaults'}) eq 'HASH') {
16686: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16687: if ($key =~ /^intauth_(cost|check|switch)$/) {
16688: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16689: } else {
16690: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16691: }
16692: }
16693: }
16694: my %staticdefaults = (
16695: 'resetlink' => 2,
16696: 'resetcase' => \@oktypes,
16697: 'resetprelink' => 'both',
16698: 'resetemail' => ['critical','notify','permanent'],
16699: 'intauth_cost' => 10,
16700: 'intauth_check' => 0,
16701: 'intauth_switch' => 0,
16702: );
1.365 raeburn 16703: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16704: foreach my $type (@oktypes) {
16705: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16706: }
16707: my $linklife = $env{'form.passwords_link'};
16708: $linklife =~ s/^\s+|\s+$//g;
16709: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16710: $newvalues{'resetlink'} = $linklife;
16711: if ($current{'resetlink'}) {
16712: if ($current{'resetlink'} ne $linklife) {
16713: $changes{'reset'} = 1;
16714: }
1.368 raeburn 16715: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16716: if ($staticdefaults{'resetlink'} ne $linklife) {
16717: $changes{'reset'} = 1;
16718: }
16719: }
16720: } elsif ($current{'resetlink'}) {
16721: $changes{'reset'} = 1;
16722: }
16723: my @casesens;
16724: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16725: foreach my $case (sort(@posscase)) {
16726: if (grep(/^\Q$case\E$/,@oktypes)) {
16727: push(@casesens,$case);
16728: }
16729: }
16730: $newvalues{'resetcase'} = \@casesens;
16731: if (ref($current{'resetcase'}) eq 'ARRAY') {
16732: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16733: if (@diffs > 0) {
16734: $changes{'reset'} = 1;
16735: }
1.368 raeburn 16736: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16737: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16738: if (@diffs > 0) {
16739: $changes{'reset'} = 1;
16740: }
16741: }
16742: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16743: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16744: if (exists($current{'resetprelink'})) {
16745: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16746: $changes{'reset'} = 1;
16747: }
1.368 raeburn 16748: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16749: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16750: $changes{'reset'} = 1;
16751: }
16752: }
16753: } elsif ($current{'resetprelink'}) {
16754: $changes{'reset'} = 1;
16755: }
16756: foreach my $type (@oktypes) {
16757: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16758: my @postlink;
16759: foreach my $item (sort(@possplink)) {
16760: if ($item =~ /^(email|username)$/) {
16761: push(@postlink,$item);
16762: }
16763: }
16764: $newvalues{'resetpostlink'}{$type} = \@postlink;
16765: unless ($changes{'reset'}) {
16766: if (ref($current{'resetpostlink'}) eq 'HASH') {
16767: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16768: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16769: if (@diffs > 0) {
16770: $changes{'reset'} = 1;
16771: }
16772: } else {
16773: $changes{'reset'} = 1;
16774: }
1.368 raeburn 16775: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16776: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16777: if (@diffs > 0) {
16778: $changes{'reset'} = 1;
16779: }
16780: }
16781: }
16782: }
16783: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16784: my @resetemail;
16785: foreach my $item (sort(@possemailsrc)) {
16786: if ($item =~ /^(permanent|critical|notify)$/) {
16787: push(@resetemail,$item);
16788: }
16789: }
16790: $newvalues{'resetemail'} = \@resetemail;
16791: unless ($changes{'reset'}) {
16792: if (ref($current{'resetemail'}) eq 'ARRAY') {
16793: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16794: if (@diffs > 0) {
16795: $changes{'reset'} = 1;
16796: }
1.368 raeburn 16797: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16798: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16799: if (@diffs > 0) {
16800: $changes{'reset'} = 1;
16801: }
16802: }
16803: }
16804: if ($env{'form.passwords_stdtext'} == 0) {
16805: $newvalues{'resetremove'} = 1;
16806: unless ($current{'resetremove'}) {
16807: $changes{'reset'} = 1;
16808: }
16809: } elsif ($current{'resetremove'}) {
16810: $changes{'reset'} = 1;
16811: }
16812: if ($env{'form.passwords_customfile.filename'} ne '') {
16813: my $servadm = $r->dir_config('lonAdmEMail');
16814: my ($configuserok,$author_ok,$switchserver) =
16815: &config_check($dom,$confname,$servadm);
16816: my $error;
16817: if ($configuserok eq 'ok') {
16818: if ($switchserver) {
16819: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16820: } else {
16821: if ($author_ok eq 'ok') {
16822: my ($result,$customurl) =
16823: &publishlogo($r,'upload','passwords_customfile',$dom,
16824: $confname,'customtext/resetpw','','',$customfn);
16825: if ($result eq 'ok') {
16826: $newvalues{'resetcustom'} = $customurl;
16827: $changes{'reset'} = 1;
16828: } else {
16829: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16830: }
16831: } else {
16832: $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);
16833: }
16834: }
16835: } else {
16836: $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);
16837: }
16838: if ($error) {
16839: &Apache::lonnet::logthis($error);
16840: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16841: }
16842: } elsif ($current{'resetcustom'}) {
16843: if ($env{'form.passwords_custom_del'}) {
16844: $changes{'reset'} = 1;
16845: } else {
16846: $newvalues{'resetcustom'} = $current{'resetcustom'};
16847: }
16848: }
16849: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16850: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16851: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16852: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16853: $changes{'intauth'} = 1;
16854: }
16855: } else {
16856: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16857: }
16858: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16859: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16860: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16861: $changes{'intauth'} = 1;
16862: }
16863: } else {
16864: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16865: }
16866: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16867: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16868: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16869: $changes{'intauth'} = 1;
16870: }
16871: } else {
16872: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16873: }
16874: foreach my $item ('cost','check','switch') {
16875: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16876: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16877: $updatedefaults = 1;
16878: }
16879: }
1.356 raeburn 16880: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16881: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 16882: my $ruleok;
16883: if ($rule eq 'expire') {
1.365 raeburn 16884: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
16885: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 16886: $ruleok = 1;
1.356 raeburn 16887: }
1.365 raeburn 16888: } elsif ($rule eq 'min') {
16889: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
16890: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
16891: $ruleok = 1;
16892: }
16893: }
16894: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
16895: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 16896: $ruleok = 1;
16897: }
16898: if ($ruleok) {
1.354 raeburn 16899: $newvalues{$rule} = $env{'form.passwords_'.$rule};
16900: if (exists($current{$rule})) {
16901: if ($newvalues{$rule} ne $current{$rule}) {
16902: $changes{'rules'} = 1;
16903: }
16904: } elsif ($rule eq 'min') {
16905: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
16906: $changes{'rules'} = 1;
16907: }
1.370 raeburn 16908: } else {
16909: $changes{'rules'} = 1;
1.354 raeburn 16910: }
16911: } elsif (exists($current{$rule})) {
16912: $changes{'rules'} = 1;
16913: }
16914: }
16915: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
16916: my @chars;
16917: foreach my $item (sort(@posschars)) {
16918: if ($item =~ /^(uc|lc|num|spec)$/) {
16919: push(@chars,$item);
16920: }
16921: }
16922: $newvalues{'chars'} = \@chars;
16923: unless ($changes{'rules'}) {
16924: if (ref($current{'chars'}) eq 'ARRAY') {
16925: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
16926: if (@diffs > 0) {
16927: $changes{'rules'} = 1;
16928: }
16929: } else {
16930: if (@chars > 0) {
16931: $changes{'rules'} = 1;
16932: }
16933: }
16934: }
1.359 raeburn 16935: my %crsownerchg = (
16936: by => [],
16937: for => [],
16938: );
16939: foreach my $item ('by','for') {
16940: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16941: foreach my $type (sort(@posstypes)) {
16942: if (grep(/^\Q$type\E$/,@oktypes)) {
16943: push(@{$crsownerchg{$item}},$type);
16944: }
16945: }
16946: }
16947: $newvalues{'crsownerchg'} = \%crsownerchg;
16948: if (ref($current{'crsownerchg'}) eq 'HASH') {
16949: foreach my $item ('by','for') {
16950: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16951: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16952: if (@diffs > 0) {
16953: $changes{'crsownerchg'} = 1;
16954: last;
16955: }
16956: }
16957: }
1.368 raeburn 16958: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 16959: foreach my $item ('by','for') {
16960: if (@{$crsownerchg{$item}} > 0) {
16961: $changes{'crsownerchg'} = 1;
16962: last;
16963: }
1.354 raeburn 16964: }
16965: }
16966:
16967: my %confighash = (
16968: defaults => \%save_defaults,
16969: passwords => \%newvalues,
16970: );
16971: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16972:
16973: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16974: if ($putresult eq 'ok') {
16975: if (keys(%changes) > 0) {
16976: $resulttext = &mt('Changes made: ').'<ul>';
16977: foreach my $key ('reset','intauth','rules','crsownerchg') {
16978: if ($changes{$key}) {
1.355 raeburn 16979: unless ($key eq 'intauth') {
16980: $updateconf = 1;
16981: }
1.354 raeburn 16982: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16983: if ($key eq 'reset') {
16984: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16985: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16986: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16987: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 16988: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16989: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16990: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16991: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16992: }
1.354 raeburn 16993: } else {
16994: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16995: }
16996: if ($confighash{'passwords'}{'resetlink'}) {
16997: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16998: } else {
16999: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17000: &mt('Will default to 2 hours').'</li>';
17001: }
17002: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17003: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17004: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17005: } else {
17006: my $casesens;
17007: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17008: if ($type eq 'default') {
17009: $casesens .= $othertitle.', ';
17010: } elsif ($usertypes->{$type} ne '') {
17011: $casesens .= $usertypes->{$type}.', ';
17012: }
17013: }
17014: $casesens =~ s/\Q, \E$//;
17015: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17016: }
17017: } else {
17018: $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>';
17019: }
17020: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17021: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17022: } else {
17023: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17024: }
17025: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17026: my $output;
17027: if (ref($types) eq 'ARRAY') {
17028: foreach my $type (@{$types}) {
17029: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17030: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17031: $output .= $usertypes->{$type}.' -- '.&mt('none');
17032: } else {
17033: $output .= $usertypes->{$type}.' -- '.
17034: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17035: }
17036: }
17037: }
17038: }
17039: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17040: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17041: $output .= $othertitle.' -- '.&mt('none');
17042: } else {
17043: $output .= $othertitle.' -- '.
17044: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17045: }
17046: }
17047: if ($output) {
17048: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17049: } else {
17050: $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>';
17051: }
17052: } else {
17053: $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>';
17054: }
17055: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17056: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17057: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17058: } else {
17059: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17060: }
17061: } else {
1.379 raeburn 17062: $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 17063: }
17064: if ($confighash{'passwords'}{'resetremove'}) {
17065: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17066: } else {
17067: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17068: }
17069: if ($confighash{'passwords'}{'resetcustom'}) {
17070: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17071: &mt('custom text'),600,500,undef,undef,
17072: undef,undef,'background-color:#ffffff');
17073: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17074: } else {
17075: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17076: }
17077: } elsif ($key eq 'intauth') {
17078: foreach my $item ('cost','switch','check') {
17079: my $value = $save_defaults{$key.'_'.$item};
17080: if ($item eq 'switch') {
17081: my %optiondesc = &Apache::lonlocal::texthash (
17082: 0 => 'No',
17083: 1 => 'Yes',
17084: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17085: );
17086: if ($value =~ /^(0|1|2)$/) {
17087: $value = $optiondesc{$value};
17088: } else {
17089: $value = &mt('none -- defaults to No');
17090: }
17091: } elsif ($item eq 'check') {
17092: my %optiondesc = &Apache::lonlocal::texthash (
17093: 0 => 'No',
17094: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17095: 2 => 'Yes, disallow login if stored cost is less than domain default',
17096: );
17097: if ($value =~ /^(0|1|2)$/) {
17098: $value = $optiondesc{$value};
17099: } else {
17100: $value = &mt('none -- defaults to No');
17101: }
17102: }
17103: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17104: }
17105: } elsif ($key eq 'rules') {
1.356 raeburn 17106: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17107: if ($confighash{'passwords'}{$rule} eq '') {
17108: if ($rule eq 'min') {
1.356 raeburn 17109: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17110: ' '.&mt('Default of [_1] will be used',
17111: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17112: } else {
17113: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17114: }
17115: } else {
17116: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17117: }
17118: }
1.370 raeburn 17119: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17120: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17121: my %rulenames = &Apache::lonlocal::texthash(
17122: uc => 'At least one upper case letter',
17123: lc => 'At least one lower case letter',
17124: num => 'At least one number',
17125: spec => 'At least one non-alphanumeric',
17126: );
17127: my $needed = '<ul><li>'.
17128: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17129: '</li></ul>';
17130: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17131: } else {
17132: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17133: }
17134: } else {
17135: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17136: }
1.354 raeburn 17137: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17138: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17139: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17140: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17141: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17142: } else {
17143: my %crsownerstr;
17144: foreach my $item ('by','for') {
17145: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17146: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17147: if ($type eq 'default') {
17148: $crsownerstr{$item} .= $othertitle.', ';
17149: } elsif ($usertypes->{$type} ne '') {
17150: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17151: }
17152: }
17153: $crsownerstr{$item} =~ s/\Q, \E$//;
17154: }
17155: }
17156: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17157: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17158: }
1.354 raeburn 17159: } else {
1.359 raeburn 17160: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17161: }
17162: }
17163: $resulttext .= '</ul></li>';
17164: }
17165: }
17166: $resulttext .= '</ul>';
17167: } else {
17168: $resulttext = &mt('No changes made to password settings');
17169: }
1.355 raeburn 17170: my $cachetime = 24*60*60;
1.354 raeburn 17171: if ($updatedefaults) {
17172: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17173: if (ref($lastactref) eq 'HASH') {
17174: $lastactref->{'domdefaults'} = 1;
17175: }
17176: }
1.355 raeburn 17177: if ($updateconf) {
17178: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17179: if (ref($lastactref) eq 'HASH') {
17180: $lastactref->{'passwdconf'} = 1;
17181: }
17182: }
1.354 raeburn 17183: } else {
17184: $resulttext = '<span class="LC_error">'.
17185: &mt('An error occurred: [_1]',$putresult).'</span>';
17186: }
17187: if ($errors) {
17188: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17189: $errors.'</ul></p>';
17190: }
17191: return $resulttext;
17192: }
17193:
1.28 raeburn 17194: sub modify_usercreation {
1.27 raeburn 17195: my ($dom,%domconfig) = @_;
1.224 raeburn 17196: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17197: my $warningmsg;
1.27 raeburn 17198: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17199: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17200: if ($key eq 'cancreate') {
17201: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17202: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17203: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17204: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17205: } else {
1.224 raeburn 17206: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17207: }
17208: }
17209: }
17210: } elsif ($key eq 'email_rule') {
17211: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17212: } else {
17213: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17214: }
1.27 raeburn 17215: }
17216: }
17217: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17218: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17219: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17220: foreach my $item(@contexts) {
1.224 raeburn 17221: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17222: }
1.34 raeburn 17223: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17224: foreach my $item (@contexts) {
1.224 raeburn 17225: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17226: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17227: }
1.27 raeburn 17228: }
1.34 raeburn 17229: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17230: foreach my $item (@contexts) {
1.43 raeburn 17231: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17232: if ($cancreate{$item} ne 'any') {
17233: push(@{$changes{'cancreate'}},$item);
17234: }
17235: } else {
17236: if ($cancreate{$item} ne 'none') {
17237: push(@{$changes{'cancreate'}},$item);
17238: }
1.27 raeburn 17239: }
17240: }
17241: } else {
1.43 raeburn 17242: foreach my $item (@contexts) {
1.34 raeburn 17243: push(@{$changes{'cancreate'}},$item);
17244: }
1.27 raeburn 17245: }
1.34 raeburn 17246:
1.27 raeburn 17247: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17248: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17249: if (!grep(/^\Q$type\E$/,@username_rule)) {
17250: push(@{$changes{'username_rule'}},$type);
17251: }
17252: }
17253: foreach my $type (@username_rule) {
17254: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17255: push(@{$changes{'username_rule'}},$type);
17256: }
17257: }
17258: } else {
17259: push(@{$changes{'username_rule'}},@username_rule);
17260: }
17261:
1.32 raeburn 17262: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17263: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17264: if (!grep(/^\Q$type\E$/,@id_rule)) {
17265: push(@{$changes{'id_rule'}},$type);
17266: }
17267: }
17268: foreach my $type (@id_rule) {
17269: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17270: push(@{$changes{'id_rule'}},$type);
17271: }
17272: }
17273: } else {
17274: push(@{$changes{'id_rule'}},@id_rule);
17275: }
17276:
1.43 raeburn 17277: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17278: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17279: my %authhash;
1.43 raeburn 17280: foreach my $item (@authen_contexts) {
1.28 raeburn 17281: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17282: foreach my $auth (@authtypes) {
17283: if (grep(/^\Q$auth\E$/,@authallowed)) {
17284: $authhash{$item}{$auth} = 1;
17285: } else {
17286: $authhash{$item}{$auth} = 0;
17287: }
17288: }
17289: }
17290: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17291: foreach my $item (@authen_contexts) {
1.28 raeburn 17292: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17293: foreach my $auth (@authtypes) {
17294: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17295: push(@{$changes{'authtypes'}},$item);
17296: last;
17297: }
17298: }
17299: }
17300: }
17301: } else {
1.43 raeburn 17302: foreach my $item (@authen_contexts) {
1.28 raeburn 17303: push(@{$changes{'authtypes'}},$item);
17304: }
17305: }
17306:
1.224 raeburn 17307: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17308: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17309: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17310: $save_usercreate{'id_rule'} = \@id_rule;
17311: $save_usercreate{'username_rule'} = \@username_rule,
17312: $save_usercreate{'authtypes'} = \%authhash;
17313:
1.27 raeburn 17314: my %usercreation_hash = (
1.224 raeburn 17315: usercreation => \%save_usercreate,
17316: );
1.27 raeburn 17317:
17318: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17319: $dom);
1.50 raeburn 17320:
1.224 raeburn 17321: if ($putresult eq 'ok') {
17322: if (keys(%changes) > 0) {
17323: $resulttext = &mt('Changes made:').'<ul>';
17324: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17325: my %lt = &usercreation_types();
17326: foreach my $type (@{$changes{'cancreate'}}) {
17327: my $chgtext = $lt{$type}.', ';
17328: if ($cancreate{$type} eq 'none') {
17329: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
17330: } elsif ($cancreate{$type} eq 'any') {
17331: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
17332: } elsif ($cancreate{$type} eq 'official') {
17333: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
17334: } elsif ($cancreate{$type} eq 'unofficial') {
17335: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
17336: }
17337: $resulttext .= '<li>'.$chgtext.'</li>';
17338: }
17339: }
17340: if (ref($changes{'username_rule'}) eq 'ARRAY') {
17341: my ($rules,$ruleorder) =
17342: &Apache::lonnet::inst_userrules($dom,'username');
17343: my $chgtext = '<ul>';
17344: foreach my $type (@username_rule) {
17345: if (ref($rules->{$type}) eq 'HASH') {
17346: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
17347: }
17348: }
17349: $chgtext .= '</ul>';
17350: if (@username_rule > 0) {
17351: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17352: } else {
17353: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
17354: }
17355: }
17356: if (ref($changes{'id_rule'}) eq 'ARRAY') {
17357: my ($idrules,$idruleorder) =
17358: &Apache::lonnet::inst_userrules($dom,'id');
17359: my $chgtext = '<ul>';
17360: foreach my $type (@id_rule) {
17361: if (ref($idrules->{$type}) eq 'HASH') {
17362: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
17363: }
17364: }
17365: $chgtext .= '</ul>';
17366: if (@id_rule > 0) {
17367: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17368: } else {
17369: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
17370: }
17371: }
17372: my %authname = &authtype_names();
17373: my %context_title = &context_names();
17374: if (ref($changes{'authtypes'}) eq 'ARRAY') {
17375: my $chgtext = '<ul>';
17376: foreach my $type (@{$changes{'authtypes'}}) {
17377: my @allowed;
17378: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
17379: foreach my $auth (@authtypes) {
17380: if ($authhash{$type}{$auth}) {
17381: push(@allowed,$authname{$auth});
17382: }
17383: }
17384: if (@allowed > 0) {
17385: $chgtext .= join(', ',@allowed).'</li>';
17386: } else {
17387: $chgtext .= &mt('none').'</li>';
17388: }
17389: }
17390: $chgtext .= '</ul>';
17391: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
17392: $resulttext .= '</li>';
17393: }
17394: $resulttext .= '</ul>';
17395: } else {
17396: $resulttext = &mt('No changes made to user creation settings');
17397: }
17398: } else {
17399: $resulttext = '<span class="LC_error">'.
17400: &mt('An error occurred: [_1]',$putresult).'</span>';
17401: }
17402: if ($warningmsg ne '') {
17403: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17404: }
17405: return $resulttext;
17406: }
17407:
17408: sub modify_selfcreation {
1.305 raeburn 17409: my ($dom,$lastactref,%domconfig) = @_;
17410: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
17411: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
17412: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 17413: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
17414: if (ref($typesref) eq 'ARRAY') {
17415: @types = @{$typesref};
17416: }
17417: if (ref($usertypesref) eq 'HASH') {
17418: %usertypes = %{$usertypesref};
1.228 raeburn 17419: }
1.303 raeburn 17420: $usertypes{'default'} = $othertitle;
1.224 raeburn 17421: #
17422: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
17423: #
17424: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17425: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
17426: if ($key eq 'cancreate') {
17427: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17428: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
17429: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 17430: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
17431: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
17432: ($item eq 'emailusername') || ($item eq 'shibenv') ||
17433: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 17434: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 17435: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17436: } else {
17437: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17438: }
17439: }
17440: }
17441: } elsif ($key eq 'email_rule') {
17442: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17443: } else {
17444: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17445: }
17446: }
17447: }
17448: #
17449: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
17450: #
17451: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17452: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
17453: if ($key eq 'selfcreate') {
17454: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
17455: } else {
17456: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
17457: }
17458: }
17459: }
1.305 raeburn 17460: #
17461: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
17462: #
17463: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17464: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
17465: if ($key eq 'inststatusguest') {
17466: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
17467: } else {
17468: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
17469: }
17470: }
17471: }
1.224 raeburn 17472:
17473: my @contexts = ('selfcreate');
17474: @{$cancreate{'selfcreate'}} = ();
17475: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 17476: if (@types) {
17477: @{$cancreate{'statustocreate'}} = ();
17478: }
1.236 raeburn 17479: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 17480: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 17481: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 17482: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 17483: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 17484: my %selfcreatetypes = (
17485: sso => 'users authenticated by institutional single sign on',
17486: login => 'users authenticated by institutional log-in',
1.303 raeburn 17487: email => 'users verified by e-mail',
1.50 raeburn 17488: );
1.224 raeburn 17489: #
17490: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
17491: # is permitted.
17492: #
1.305 raeburn 17493: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 17494:
1.305 raeburn 17495: my (@statuses,%email_rule);
1.228 raeburn 17496: foreach my $item ('login','sso','email') {
1.224 raeburn 17497: if ($item eq 'email') {
1.236 raeburn 17498: if ($env{'form.cancreate_email'}) {
1.305 raeburn 17499: if (@types) {
17500: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
17501: foreach my $status (@poss_statuses) {
17502: if (grep(/^\Q$status\E$/,(@types,'default'))) {
17503: push(@statuses,$status);
17504: }
17505: }
17506: $save_inststatus{'inststatusguest'} = \@statuses;
17507: } else {
17508: push(@statuses,'default');
17509: }
17510: if (@statuses) {
17511: my %curr_rule;
17512: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
17513: foreach my $type (@statuses) {
17514: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 17515: }
1.305 raeburn 17516: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
17517: foreach my $type (@statuses) {
17518: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
17519: }
17520: }
17521: push(@{$cancreate{'selfcreate'}},'email');
17522: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
17523: my %curremaildom;
17524: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
17525: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
17526: }
17527: foreach my $type (@statuses) {
17528: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
17529: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
17530: }
17531: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
17532: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
17533: }
17534: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
17535: #
17536: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
17537: #
17538: my $chosen = $1;
17539: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
17540: my $emaildom;
17541: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
17542: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
17543: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
17544: if (ref($curremaildom{$type}) eq 'HASH') {
17545: if (exists($curremaildom{$type}{$chosen})) {
17546: if ($curremaildom{$type}{$chosen} ne $emaildom) {
17547: push(@{$changes{'cancreate'}},'emaildomain');
17548: }
17549: } elsif ($emaildom ne '') {
17550: push(@{$changes{'cancreate'}},'emaildomain');
17551: }
17552: } elsif ($emaildom ne '') {
17553: push(@{$changes{'cancreate'}},'emaildomain');
17554: }
17555: }
17556: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17557: } elsif ($chosen eq 'custom') {
17558: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
17559: $email_rule{$type} = [];
17560: if (ref($emailrules) eq 'HASH') {
17561: foreach my $rule (@possemail_rules) {
17562: if (exists($emailrules->{$rule})) {
17563: push(@{$email_rule{$type}},$rule);
17564: }
17565: }
17566: }
17567: if (@{$email_rule{$type}}) {
17568: $cancreate{'emailoptions'}{$type} = 'custom';
17569: if (ref($curr_rule{$type}) eq 'ARRAY') {
17570: if (@{$curr_rule{$type}} > 0) {
17571: foreach my $rule (@{$curr_rule{$type}}) {
17572: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
17573: push(@{$changes{'email_rule'}},$type);
17574: }
17575: }
17576: }
17577: foreach my $type (@{$email_rule{$type}}) {
17578: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
17579: push(@{$changes{'email_rule'}},$type);
17580: }
17581: }
17582: } else {
17583: push(@{$changes{'email_rule'}},$type);
17584: }
17585: }
17586: } else {
17587: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17588: }
17589: }
17590: }
17591: if (@types) {
17592: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17593: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
17594: if (@changed) {
17595: push(@{$changes{'inststatus'}},'inststatusguest');
17596: }
17597: } else {
17598: push(@{$changes{'inststatus'}},'inststatusguest');
17599: }
17600: }
17601: } else {
17602: delete($env{'form.cancreate_email'});
17603: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17604: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17605: push(@{$changes{'inststatus'}},'inststatusguest');
17606: }
17607: }
17608: }
17609: } else {
17610: $save_inststatus{'inststatusguest'} = [];
17611: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17612: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17613: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 17614: }
17615: }
1.224 raeburn 17616: }
17617: } else {
17618: if ($env{'form.cancreate_'.$item}) {
17619: push(@{$cancreate{'selfcreate'}},$item);
17620: }
17621: }
17622: }
1.305 raeburn 17623: my (%userinfo,%savecaptcha);
1.224 raeburn 17624: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
17625: #
1.228 raeburn 17626: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
17627: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 17628: #
1.236 raeburn 17629:
1.244 raeburn 17630: if ($env{'form.cancreate_email'}) {
1.228 raeburn 17631: push(@contexts,'emailusername');
1.305 raeburn 17632: if (@statuses) {
17633: foreach my $type (@statuses) {
1.228 raeburn 17634: if (ref($infofields) eq 'ARRAY') {
17635: foreach my $field (@{$infofields}) {
17636: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
17637: $cancreate{'emailusername'}{$type}{$field} = $1;
17638: }
17639: }
1.224 raeburn 17640: }
17641: }
17642: }
17643: #
17644: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 17645: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 17646: #
17647:
17648: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
17649: @approvalnotify = sort(@approvalnotify);
17650: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
17651: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17652: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17653: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17654: push(@{$changes{'cancreate'}},'notify');
17655: }
17656: } else {
17657: if ($cancreate{'notify'}{'approval'}) {
17658: push(@{$changes{'cancreate'}},'notify');
17659: }
17660: }
17661: } elsif ($cancreate{'notify'}{'approval'}) {
17662: push(@{$changes{'cancreate'}},'notify');
17663: }
17664:
17665: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17666: }
17667: #
1.236 raeburn 17668: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 17669: # institutional log-in.
17670: #
17671: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17672: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17673: ($domdefaults{'auth_def'} eq 'localauth'))) {
17674: $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.').' '.
17675: &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.');
17676: }
17677: }
17678: my @fields = ('lastname','firstname','middlename','generation',
17679: 'permanentemail','id');
1.240 raeburn 17680: my @shibfields = (@fields,'inststatus');
1.224 raeburn 17681: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17682: #
17683: # Where usernames may created for institutional log-in and/or institutional single sign on:
17684: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17685: # may self-create accounts
17686: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17687: # which the user may supply, if institutional data is unavailable.
17688: #
17689: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 17690: if (@types) {
1.305 raeburn 17691: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17692: push(@contexts,'statustocreate');
1.303 raeburn 17693: foreach my $type (@types) {
1.224 raeburn 17694: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17695: foreach my $field (@fields) {
17696: if (grep(/^\Q$field\E$/,@modifiable)) {
17697: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17698: } else {
17699: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17700: }
17701: }
17702: }
17703: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17704: foreach my $type (@types) {
1.224 raeburn 17705: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17706: foreach my $field (@fields) {
17707: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17708: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17709: push(@{$changes{'selfcreate'}},$type);
17710: last;
17711: }
17712: }
17713: }
17714: }
17715: } else {
1.303 raeburn 17716: foreach my $type (@types) {
1.224 raeburn 17717: push(@{$changes{'selfcreate'}},$type);
17718: }
17719: }
17720: }
1.240 raeburn 17721: foreach my $field (@shibfields) {
17722: if ($env{'form.shibenv_'.$field} ne '') {
17723: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17724: }
17725: }
17726: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17727: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17728: foreach my $field (@shibfields) {
17729: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17730: push(@{$changes{'cancreate'}},'shibenv');
17731: }
17732: }
17733: } else {
17734: foreach my $field (@shibfields) {
17735: if ($env{'form.shibenv_'.$field}) {
17736: push(@{$changes{'cancreate'}},'shibenv');
17737: last;
17738: }
17739: }
17740: }
17741: }
1.224 raeburn 17742: }
17743: foreach my $item (@contexts) {
17744: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17745: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17746: if (ref($cancreate{$item}) eq 'ARRAY') {
17747: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17748: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17749: push(@{$changes{'cancreate'}},$item);
17750: }
17751: }
17752: }
17753: }
17754: if (ref($cancreate{$item}) eq 'ARRAY') {
17755: foreach my $type (@{$cancreate{$item}}) {
17756: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17757: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17758: push(@{$changes{'cancreate'}},$item);
17759: }
17760: }
17761: }
17762: }
17763: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17764: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17765: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17766: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17767: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17768: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17769: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17770: push(@{$changes{'cancreate'}},$item);
17771: }
17772: }
17773: }
1.305 raeburn 17774: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17775: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17776: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17777: push(@{$changes{'cancreate'}},$item);
17778: }
1.224 raeburn 17779: }
17780: }
17781: }
1.305 raeburn 17782: foreach my $type (keys(%{$cancreate{$item}})) {
17783: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17784: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17785: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17786: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17787: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17788: push(@{$changes{'cancreate'}},$item);
17789: }
17790: }
17791: } else {
17792: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17793: push(@{$changes{'cancreate'}},$item);
17794: }
17795: }
17796: }
1.305 raeburn 17797: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17798: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17799: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17800: push(@{$changes{'cancreate'}},$item);
17801: }
1.224 raeburn 17802: }
17803: }
17804: }
17805: }
17806: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17807: if (ref($cancreate{$item}) eq 'ARRAY') {
17808: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17809: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17810: push(@{$changes{'cancreate'}},$item);
17811: }
17812: }
1.305 raeburn 17813: }
17814: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17815: if (ref($cancreate{$item}) eq 'HASH') {
17816: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17817: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17818: }
17819: }
17820: } elsif ($item eq 'emailusername') {
1.228 raeburn 17821: if (ref($cancreate{$item}) eq 'HASH') {
17822: foreach my $type (keys(%{$cancreate{$item}})) {
17823: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17824: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17825: if ($cancreate{$item}{$type}{$field}) {
17826: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17827: push(@{$changes{'cancreate'}},$item);
17828: }
17829: last;
17830: }
17831: }
17832: }
17833: }
1.224 raeburn 17834: }
17835: }
17836: }
17837: #
17838: # Populate %save_usercreate hash with updates to self-creation configuration.
17839: #
17840: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17841: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17842: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17843: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17844: if (ref($cancreate{'notify'}) eq 'HASH') {
17845: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17846: }
1.236 raeburn 17847: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17848: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17849: }
1.303 raeburn 17850: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17851: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17852: }
1.305 raeburn 17853: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17854: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17855: }
1.303 raeburn 17856: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17857: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17858: }
1.224 raeburn 17859: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17860: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17861: }
1.240 raeburn 17862: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17863: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17864: }
1.224 raeburn 17865: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17866: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17867:
17868: my %userconfig_hash = (
17869: usercreation => \%save_usercreate,
17870: usermodification => \%save_usermodify,
1.305 raeburn 17871: inststatus => \%save_inststatus,
1.224 raeburn 17872: );
1.305 raeburn 17873:
1.224 raeburn 17874: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17875: $dom);
17876: #
1.305 raeburn 17877: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17878: #
1.27 raeburn 17879: if ($putresult eq 'ok') {
17880: if (keys(%changes) > 0) {
17881: $resulttext = &mt('Changes made:').'<ul>';
17882: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 17883: my %lt = &selfcreation_types();
1.34 raeburn 17884: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 17885: my $chgtext = '';
1.45 raeburn 17886: if ($type eq 'selfcreate') {
1.50 raeburn 17887: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 17888: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17889: } else {
1.224 raeburn 17890: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17891: '<ul>';
1.50 raeburn 17892: foreach my $case (@{$cancreate{$type}}) {
17893: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17894: }
17895: $chgtext .= '</ul>';
1.100 raeburn 17896: if (ref($cancreate{$type}) eq 'ARRAY') {
17897: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17898: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17899: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 17900: $chgtext .= '<span class="LC_warning">'.
17901: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17902: '</span><br />';
17903: }
17904: }
17905: }
17906: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 17907: if (!@statuses) {
17908: $chgtext .= '<span class="LC_warning">'.
17909: &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.").
17910: '</span><br />';
1.303 raeburn 17911:
1.100 raeburn 17912: }
17913: }
17914: }
1.43 raeburn 17915: }
1.240 raeburn 17916: } elsif ($type eq 'shibenv') {
17917: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 17918: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 17919: } else {
17920: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17921: '<ul>';
17922: foreach my $field (@shibfields) {
17923: next if ($cancreate{$type}{$field} eq '');
17924: if ($field eq 'inststatus') {
17925: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17926: } else {
17927: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17928: }
17929: }
17930: $chgtext .= '</ul>';
1.303 raeburn 17931: }
1.93 raeburn 17932: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17933: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17934: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17935: if (@{$cancreate{'selfcreate'}} > 0) {
17936: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17937: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17938: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 17939: $chgtext .= '<br />'.
17940: '<span class="LC_warning">'.
17941: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17942: '</span>';
17943: }
1.303 raeburn 17944: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17945: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17946: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17947: } else {
17948: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17949: }
17950: $chgtext .= '<ul>';
17951: foreach my $case (@{$cancreate{$type}}) {
17952: if ($case eq 'default') {
17953: $chgtext .= '<li>'.$othertitle.'</li>';
17954: } else {
1.303 raeburn 17955: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17956: }
17957: }
1.100 raeburn 17958: $chgtext .= '</ul>';
17959: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 17960: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 17961: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17962: '</span>';
1.100 raeburn 17963: }
17964: }
17965: } else {
17966: if (@{$cancreate{$type}} == 0) {
17967: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17968: } else {
17969: $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 17970: }
17971: }
1.303 raeburn 17972: $chgtext .= '<br />';
1.93 raeburn 17973: }
1.236 raeburn 17974: } elsif ($type eq 'selfcreateprocessing') {
17975: my %choices = &Apache::lonlocal::texthash (
17976: automatic => 'Automatic approval',
17977: approval => 'Queued for approval',
17978: );
1.305 raeburn 17979: if (@types) {
17980: if (@statuses) {
1.303 raeburn 17981: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 17982: '<ul>';
1.305 raeburn 17983: foreach my $status (@statuses) {
17984: if ($status eq 'default') {
17985: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17986: } else {
1.305 raeburn 17987: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 17988: }
17989: }
17990: $chgtext .= '</ul>';
17991: }
17992: } else {
17993: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17994: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17995: }
17996: } elsif ($type eq 'emailverified') {
17997: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 17998: all => 'Same as e-mail',
17999: first => 'Omit @domain',
18000: free => 'Free to choose',
1.303 raeburn 18001: );
1.305 raeburn 18002: if (@types) {
18003: if (@statuses) {
1.303 raeburn 18004: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18005: '<ul>';
1.305 raeburn 18006: foreach my $status (@statuses) {
1.362 raeburn 18007: if ($status eq 'default') {
1.305 raeburn 18008: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18009: } else {
1.305 raeburn 18010: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18011: }
18012: }
18013: $chgtext .= '</ul>';
18014: }
18015: } else {
1.305 raeburn 18016: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18017: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18018: }
1.305 raeburn 18019: } elsif ($type eq 'emailoptions') {
18020: my %options = &Apache::lonlocal::texthash (
18021: any => 'Any e-mail',
18022: inst => 'Institutional only',
18023: noninst => 'Non-institutional only',
18024: custom => 'Custom restrictions',
18025: );
18026: if (@types) {
18027: if (@statuses) {
18028: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18029: '<ul>';
18030: foreach my $status (@statuses) {
18031: if ($type eq 'default') {
18032: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18033: } else {
18034: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18035: }
18036: }
1.305 raeburn 18037: $chgtext .= '</ul>';
18038: }
18039: } else {
18040: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18041: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18042: } else {
18043: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18044: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18045: }
1.305 raeburn 18046: }
18047: } elsif ($type eq 'emaildomain') {
18048: my $output;
18049: if (@statuses) {
18050: foreach my $type (@statuses) {
18051: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18052: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18053: if ($type eq 'default') {
18054: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18055: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18056: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18057: } else {
18058: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18059: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18060: }
1.303 raeburn 18061: } else {
1.305 raeburn 18062: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18063: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18064: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18065: } else {
18066: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
18067: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18068: }
1.303 raeburn 18069: }
1.305 raeburn 18070: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18071: if ($type eq 'default') {
18072: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18073: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18074: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18075: } else {
18076: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18077: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18078: }
1.303 raeburn 18079: } else {
1.305 raeburn 18080: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18081: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18082: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18083: } else {
18084: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
18085: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18086: }
1.303 raeburn 18087: }
18088: }
18089: }
18090: }
1.305 raeburn 18091: }
18092: if ($output ne '') {
18093: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18094: '<ul>'.$output.'</ul>';
1.236 raeburn 18095: }
1.165 raeburn 18096: } elsif ($type eq 'captcha') {
1.224 raeburn 18097: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18098: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18099: } else {
18100: my %captchas = &captcha_phrases();
1.224 raeburn 18101: if ($captchas{$savecaptcha{$type}}) {
18102: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18103: } else {
1.210 raeburn 18104: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18105: }
18106: }
18107: } elsif ($type eq 'recaptchakeys') {
18108: my ($privkey,$pubkey);
1.224 raeburn 18109: if (ref($savecaptcha{$type}) eq 'HASH') {
18110: $pubkey = $savecaptcha{$type}{'public'};
18111: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18112: }
18113: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18114: if (!$pubkey) {
18115: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18116: } else {
18117: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18118: }
18119: if (!$privkey) {
18120: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18121: } else {
18122: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18123: }
18124: $chgtext .= '</ul>';
1.269 raeburn 18125: } elsif ($type eq 'recaptchaversion') {
18126: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18127: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18128: }
1.224 raeburn 18129: } elsif ($type eq 'emailusername') {
18130: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18131: if (@statuses) {
18132: foreach my $type (@statuses) {
1.228 raeburn 18133: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18134: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18135: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18136: '<ul>';
18137: foreach my $field (@{$infofields}) {
18138: if ($cancreate{'emailusername'}{$type}{$field}) {
18139: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18140: }
18141: }
1.245 raeburn 18142: $chgtext .= '</ul>';
18143: } else {
1.303 raeburn 18144: $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 18145: }
18146: } else {
1.303 raeburn 18147: $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 18148: }
18149: }
18150: }
18151: }
18152: } elsif ($type eq 'notify') {
1.303 raeburn 18153: my $numapprove = 0;
1.224 raeburn 18154: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18155: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18156: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18157: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18158: $numapprove ++;
1.224 raeburn 18159: }
18160: }
1.43 raeburn 18161: }
1.303 raeburn 18162: unless ($numapprove) {
18163: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18164: }
1.34 raeburn 18165: }
1.224 raeburn 18166: if ($chgtext) {
18167: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18168: }
18169: }
18170: }
1.305 raeburn 18171: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18172: my ($emailrules,$emailruleorder) =
18173: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18174: foreach my $type (@{$changes{'email_rule'}}) {
18175: if (ref($email_rule{$type}) eq 'ARRAY') {
18176: my $chgtext = '<ul>';
18177: foreach my $rule (@{$email_rule{$type}}) {
18178: if (ref($emailrules->{$rule}) eq 'HASH') {
18179: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18180: }
18181: }
18182: $chgtext .= '</ul>';
1.310 raeburn 18183: my $typename;
1.305 raeburn 18184: if (@types) {
18185: if ($type eq 'default') {
18186: $typename = $othertitle;
18187: } else {
18188: $typename = $usertypes{$type};
18189: }
18190: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18191: }
18192: if (@{$email_rule{$type}} > 0) {
18193: $resulttext .= '<li>'.
18194: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18195: $usertypes{$type}).
18196: $chgtext.
18197: '</li>';
18198: } else {
18199: $resulttext .= '<li>'.
1.310 raeburn 18200: &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 18201: '</li>'.
1.310 raeburn 18202: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18203: }
1.43 raeburn 18204: }
18205: }
1.305 raeburn 18206: }
18207: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18208: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18209: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18210: my $chgtext = '<ul>';
18211: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18212: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18213: }
18214: $chgtext .= '</ul>';
18215: $resulttext .= '<li>'.
18216: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18217: $chgtext.
18218: '</li>';
18219: } else {
18220: $resulttext .= '<li>'.
18221: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18222: '</li>';
18223: }
1.43 raeburn 18224: }
18225: }
1.224 raeburn 18226: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18227: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18228: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18229: foreach my $type (@{$changes{'selfcreate'}}) {
18230: my $typename = $type;
1.303 raeburn 18231: if (keys(%usertypes) > 0) {
18232: if ($usertypes{$type} ne '') {
18233: $typename = $usertypes{$type};
1.224 raeburn 18234: }
18235: }
18236: my @modifiable;
18237: $resulttext .= '<li>'.
18238: &mt('Self-creation of account by users with status: [_1]',
18239: '<span class="LC_cusr_emph">'.$typename.'</span>').
18240: ' - '.&mt('modifiable fields (if institutional data blank): ');
18241: foreach my $field (@fields) {
18242: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18243: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18244: }
18245: }
1.224 raeburn 18246: if (@modifiable > 0) {
18247: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18248: } else {
1.224 raeburn 18249: $resulttext .= &mt('none');
1.43 raeburn 18250: }
1.224 raeburn 18251: $resulttext .= '</li>';
1.28 raeburn 18252: }
1.224 raeburn 18253: $resulttext .= '</ul></li>';
1.28 raeburn 18254: }
1.27 raeburn 18255: $resulttext .= '</ul>';
1.305 raeburn 18256: my $cachetime = 24*60*60;
18257: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18258: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18259: if (ref($lastactref) eq 'HASH') {
18260: $lastactref->{'domdefaults'} = 1;
18261: }
1.27 raeburn 18262: } else {
1.224 raeburn 18263: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18264: }
18265: } else {
18266: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18267: &mt('An error occurred: [_1]',$putresult).'</span>';
18268: }
1.43 raeburn 18269: if ($warningmsg ne '') {
18270: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18271: }
1.23 raeburn 18272: return $resulttext;
18273: }
18274:
1.165 raeburn 18275: sub process_captcha {
1.369 raeburn 18276: my ($container,$changes,$newsettings,$currsettings) = @_;
18277: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18278: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18279: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18280: $newsettings->{'captcha'} = 'original';
18281: }
1.369 raeburn 18282: my %current;
18283: if (ref($currsettings) eq 'HASH') {
18284: %current = %{$currsettings};
18285: }
18286: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18287: if ($container eq 'cancreate') {
1.169 raeburn 18288: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18289: push(@{$changes->{'cancreate'}},'captcha');
18290: } elsif (!defined($changes->{'cancreate'})) {
18291: $changes->{'cancreate'} = ['captcha'];
18292: }
1.368 raeburn 18293: } elsif ($container eq 'passwords') {
18294: $changes->{'reset'} = 1;
1.169 raeburn 18295: } else {
18296: $changes->{'captcha'} = 1;
1.165 raeburn 18297: }
18298: }
1.269 raeburn 18299: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18300: if ($newsettings->{'captcha'} eq 'recaptcha') {
18301: $newpub = $env{'form.'.$container.'_recaptchapub'};
18302: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18303: $newpub =~ s/[^\w\-]//g;
18304: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18305: $newsettings->{'recaptchakeys'} = {
18306: public => $newpub,
18307: private => $newpriv,
18308: };
1.269 raeburn 18309: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18310: $newversion =~ s/\D//g;
18311: if ($newversion ne '2') {
18312: $newversion = 1;
18313: }
18314: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18315: }
1.369 raeburn 18316: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18317: $currpub = $current{'recaptchakeys'}{'public'};
18318: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18319: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18320: $newsettings->{'recaptchakeys'} = {
18321: public => '',
18322: private => '',
18323: }
18324: }
1.165 raeburn 18325: }
1.369 raeburn 18326: if ($current{'captcha'} eq 'recaptcha') {
18327: $currversion = $current{'recaptchaversion'};
1.269 raeburn 18328: if ($currversion ne '2') {
18329: $currversion = 1;
18330: }
18331: }
18332: if ($currversion ne $newversion) {
18333: if ($container eq 'cancreate') {
18334: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18335: push(@{$changes->{'cancreate'}},'recaptchaversion');
18336: } elsif (!defined($changes->{'cancreate'})) {
18337: $changes->{'cancreate'} = ['recaptchaversion'];
18338: }
1.368 raeburn 18339: } elsif ($container eq 'passwords') {
18340: $changes->{'reset'} = 1;
1.269 raeburn 18341: } else {
18342: $changes->{'recaptchaversion'} = 1;
18343: }
18344: }
1.165 raeburn 18345: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 18346: if ($container eq 'cancreate') {
18347: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18348: push(@{$changes->{'cancreate'}},'recaptchakeys');
18349: } elsif (!defined($changes->{'cancreate'})) {
18350: $changes->{'cancreate'} = ['recaptchakeys'];
18351: }
1.368 raeburn 18352: } elsif ($container eq 'passwords') {
18353: $changes->{'reset'} = 1;
1.169 raeburn 18354: } else {
1.210 raeburn 18355: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 18356: }
18357: }
18358: return;
18359: }
18360:
1.33 raeburn 18361: sub modify_usermodification {
18362: my ($dom,%domconfig) = @_;
1.224 raeburn 18363: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 18364: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18365: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 18366: if ($key eq 'selfcreate') {
18367: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
18368: } else {
18369: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
18370: }
1.33 raeburn 18371: }
18372: }
1.224 raeburn 18373: my @contexts = ('author','course');
1.33 raeburn 18374: my %context_title = (
18375: author => 'In author context',
18376: course => 'In course context',
18377: );
18378: my @fields = ('lastname','firstname','middlename','generation',
18379: 'permanentemail','id');
18380: my %roles = (
18381: author => ['ca','aa'],
18382: course => ['st','ep','ta','in','cr'],
18383: );
18384: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18385: foreach my $context (@contexts) {
18386: foreach my $role (@{$roles{$context}}) {
18387: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
18388: foreach my $item (@fields) {
18389: if (grep(/^\Q$item\E$/,@modifiable)) {
18390: $modifyhash{$context}{$role}{$item} = 1;
18391: } else {
18392: $modifyhash{$context}{$role}{$item} = 0;
18393: }
18394: }
18395: }
18396: if (ref($curr_usermodification{$context}) eq 'HASH') {
18397: foreach my $role (@{$roles{$context}}) {
18398: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
18399: foreach my $field (@fields) {
18400: if ($modifyhash{$context}{$role}{$field} ne
18401: $curr_usermodification{$context}{$role}{$field}) {
18402: push(@{$changes{$context}},$role);
18403: last;
18404: }
18405: }
18406: }
18407: }
18408: } else {
18409: foreach my $context (@contexts) {
18410: foreach my $role (@{$roles{$context}}) {
18411: push(@{$changes{$context}},$role);
18412: }
18413: }
18414: }
18415: }
18416: my %usermodification_hash = (
18417: usermodification => \%modifyhash,
18418: );
18419: my $putresult = &Apache::lonnet::put_dom('configuration',
18420: \%usermodification_hash,$dom);
18421: if ($putresult eq 'ok') {
18422: if (keys(%changes) > 0) {
18423: $resulttext = &mt('Changes made: ').'<ul>';
18424: foreach my $context (@contexts) {
18425: if (ref($changes{$context}) eq 'ARRAY') {
18426: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
18427: if (ref($changes{$context}) eq 'ARRAY') {
18428: foreach my $role (@{$changes{$context}}) {
18429: my $rolename;
1.224 raeburn 18430: if ($role eq 'cr') {
18431: $rolename = &mt('Custom');
1.33 raeburn 18432: } else {
1.224 raeburn 18433: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 18434: }
18435: my @modifiable;
1.224 raeburn 18436: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 18437: foreach my $field (@fields) {
18438: if ($modifyhash{$context}{$role}{$field}) {
18439: push(@modifiable,$fieldtitles{$field});
18440: }
18441: }
18442: if (@modifiable > 0) {
18443: $resulttext .= join(', ',@modifiable);
18444: } else {
18445: $resulttext .= &mt('none');
18446: }
18447: $resulttext .= '</li>';
18448: }
18449: $resulttext .= '</ul></li>';
18450: }
18451: }
18452: }
18453: $resulttext .= '</ul>';
18454: } else {
18455: $resulttext = &mt('No changes made to user modification settings');
18456: }
18457: } else {
18458: $resulttext = '<span class="LC_error">'.
18459: &mt('An error occurred: [_1]',$putresult).'</span>';
18460: }
18461: return $resulttext;
18462: }
18463:
1.43 raeburn 18464: sub modify_defaults {
1.212 raeburn 18465: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 18466: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 18467: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 18468: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 18469: 'portal_def');
1.325 raeburn 18470: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 18471: foreach my $item (@items) {
18472: $newvalues{$item} = $env{'form.'.$item};
18473: if ($item eq 'auth_def') {
18474: if ($newvalues{$item} ne '') {
18475: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
18476: push(@errors,$item);
18477: }
18478: }
18479: } elsif ($item eq 'lang_def') {
18480: if ($newvalues{$item} ne '') {
18481: if ($newvalues{$item} =~ /^(\w+)/) {
18482: my $langcode = $1;
1.103 raeburn 18483: if ($langcode ne 'x_chef') {
18484: if (code2language($langcode) eq '') {
18485: push(@errors,$item);
18486: }
1.43 raeburn 18487: }
18488: } else {
18489: push(@errors,$item);
18490: }
18491: }
1.54 raeburn 18492: } elsif ($item eq 'timezone_def') {
18493: if ($newvalues{$item} ne '') {
1.62 raeburn 18494: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 18495: push(@errors,$item);
18496: }
18497: }
1.68 raeburn 18498: } elsif ($item eq 'datelocale_def') {
18499: if ($newvalues{$item} ne '') {
18500: my @datelocale_ids = DateTime::Locale->ids();
18501: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
18502: push(@errors,$item);
18503: }
18504: }
1.141 raeburn 18505: } elsif ($item eq 'portal_def') {
18506: if ($newvalues{$item} ne '') {
18507: 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])\/?$/) {
18508: push(@errors,$item);
18509: }
18510: }
1.43 raeburn 18511: }
18512: if (grep(/^\Q$item\E$/,@errors)) {
18513: $newvalues{$item} = $domdefaults{$item};
18514: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
18515: $changes{$item} = 1;
18516: }
1.72 raeburn 18517: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 18518: }
1.354 raeburn 18519: my %staticdefaults = (
18520: 'intauth_cost' => 10,
18521: 'intauth_check' => 0,
18522: 'intauth_switch' => 0,
18523: );
18524: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
18525: if (exists($domdefaults{$item})) {
18526: $newvalues{$item} = $domdefaults{$item};
18527: } else {
18528: $newvalues{$item} = $staticdefaults{$item};
18529: }
18530: }
1.43 raeburn 18531: my %defaults_hash = (
1.72 raeburn 18532: defaults => \%newvalues,
18533: );
1.43 raeburn 18534: my $title = &defaults_titles();
1.236 raeburn 18535:
18536: my $currinststatus;
18537: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18538: $currinststatus = $domconfig{'inststatus'};
18539: } else {
18540: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18541: $currinststatus = {
18542: inststatustypes => $usertypes,
18543: inststatusorder => $types,
18544: inststatusguest => [],
18545: };
18546: }
18547: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
18548: my @allpos;
18549: my %alltypes;
1.305 raeburn 18550: my @inststatusguest;
18551: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
18552: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
18553: unless (grep(/^\Q$type\E$/,@todelete)) {
18554: push(@inststatusguest,$type);
18555: }
18556: }
18557: }
18558: my ($currtitles,$currorder);
1.236 raeburn 18559: if (ref($currinststatus) eq 'HASH') {
18560: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
18561: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
18562: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
18563: if ($currinststatus->{inststatustypes}->{$type} ne '') {
18564: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
18565: }
18566: }
18567: unless (grep(/^\Q$type\E$/,@todelete)) {
18568: my $position = $env{'form.inststatus_pos_'.$type};
18569: $position =~ s/\D+//g;
18570: $allpos[$position] = $type;
18571: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18572: $alltypes{$type} =~ s/`//g;
18573: }
18574: }
18575: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18576: $currtitles =~ s/,$//;
18577: }
18578: }
18579: if ($env{'form.addinststatus'}) {
18580: my $newtype = $env{'form.addinststatus'};
18581: $newtype =~ s/\W//g;
18582: unless (exists($alltypes{$newtype})) {
18583: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18584: $alltypes{$newtype} =~ s/`//g;
18585: my $position = $env{'form.addinststatus_pos'};
18586: $position =~ s/\D+//g;
18587: if ($position ne '') {
18588: $allpos[$position] = $newtype;
18589: }
18590: }
18591: }
1.305 raeburn 18592: my @orderedstatus;
1.236 raeburn 18593: foreach my $type (@allpos) {
18594: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18595: push(@orderedstatus,$type);
18596: }
18597: }
18598: foreach my $type (keys(%alltypes)) {
18599: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18600: delete($alltypes{$type});
18601: }
18602: }
18603: $defaults_hash{'inststatus'} = {
18604: inststatustypes => \%alltypes,
18605: inststatusorder => \@orderedstatus,
1.305 raeburn 18606: inststatusguest => \@inststatusguest,
1.236 raeburn 18607: };
18608: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18609: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18610: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18611: }
18612: }
18613: if ($currorder ne join(',',@orderedstatus)) {
18614: $changes{'inststatus'}{'inststatusorder'} = 1;
18615: }
18616: my $newtitles;
18617: foreach my $item (@orderedstatus) {
18618: $newtitles .= $alltypes{$item}.',';
18619: }
18620: $newtitles =~ s/,$//;
18621: if ($currtitles ne $newtitles) {
18622: $changes{'inststatus'}{'inststatustypes'} = 1;
18623: }
1.43 raeburn 18624: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18625: $dom);
18626: if ($putresult eq 'ok') {
18627: if (keys(%changes) > 0) {
18628: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 18629: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18630: 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";
18631: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 18632: if ($item eq 'inststatus') {
18633: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 18634: if (@orderedstatus) {
1.236 raeburn 18635: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18636: foreach my $type (@orderedstatus) {
18637: $resulttext .= $alltypes{$type}.', ';
18638: }
18639: $resulttext =~ s/, $//;
18640: $resulttext .= '</li>';
1.305 raeburn 18641: } else {
18642: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 18643: }
18644: }
18645: } else {
18646: my $value = $env{'form.'.$item};
18647: if ($value eq '') {
18648: $value = &mt('none');
18649: } elsif ($item eq 'auth_def') {
18650: my %authnames = &authtype_names();
18651: my %shortauth = (
18652: internal => 'int',
18653: krb4 => 'krb4',
18654: krb5 => 'krb5',
18655: localauth => 'loc',
1.325 raeburn 18656: lti => 'lti',
1.236 raeburn 18657: );
18658: $value = $authnames{$shortauth{$value}};
18659: }
18660: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
18661: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 18662: }
18663: }
18664: $resulttext .= '</ul>';
18665: $mailmsgtext .= "\n";
18666: my $cachetime = 24*60*60;
1.72 raeburn 18667: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 18668: if (ref($lastactref) eq 'HASH') {
18669: $lastactref->{'domdefaults'} = 1;
18670: }
1.68 raeburn 18671: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 18672: my $notify = 1;
18673: if (ref($domconfig{'contacts'}) eq 'HASH') {
18674: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18675: $notify = 0;
18676: }
18677: }
18678: if ($notify) {
18679: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18680: "LON-CAPA Domain Settings Change - $dom",
18681: $mailmsgtext);
18682: }
1.54 raeburn 18683: }
1.43 raeburn 18684: } else {
1.54 raeburn 18685: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18686: }
18687: } else {
18688: $resulttext = '<span class="LC_error">'.
18689: &mt('An error occurred: [_1]',$putresult).'</span>';
18690: }
18691: if (@errors > 0) {
18692: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18693: foreach my $item (@errors) {
18694: $resulttext .= ' "'.$title->{$item}.'",';
18695: }
18696: $resulttext =~ s/,$//;
18697: }
18698: return $resulttext;
18699: }
18700:
1.46 raeburn 18701: sub modify_scantron {
1.205 raeburn 18702: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18703: my ($resulttext,%confhash,%changes,$errors);
18704: my $custom = 'custom.tab';
18705: my $default = 'default.tab';
18706: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18707: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18708: &config_check($dom,$confname,$servadm);
18709: if ($env{'form.scantronformat.filename'} ne '') {
18710: my $error;
18711: if ($configuserok eq 'ok') {
18712: if ($switchserver) {
1.130 raeburn 18713: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18714: } else {
18715: if ($author_ok eq 'ok') {
18716: my ($result,$scantronurl) =
18717: &publishlogo($r,'upload','scantronformat',$dom,
18718: $confname,'scantron','','',$custom);
18719: if ($result eq 'ok') {
18720: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18721: $changes{'scantronformat'} = 1;
1.46 raeburn 18722: } else {
18723: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18724: }
18725: } else {
18726: $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);
18727: }
18728: }
18729: } else {
18730: $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);
18731: }
18732: if ($error) {
18733: &Apache::lonnet::logthis($error);
18734: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18735: }
18736: }
1.48 raeburn 18737: if (ref($domconfig{'scantron'}) eq 'HASH') {
18738: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18739: if ($env{'form.scantronformat_del'}) {
18740: $confhash{'scantron'}{'scantronformat'} = '';
18741: $changes{'scantronformat'} = 1;
1.347 raeburn 18742: } else {
18743: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18744: }
18745: }
18746: }
1.347 raeburn 18747: my @options = ('hdr','pad','rem');
1.346 raeburn 18748: my @fields = &scantroncsv_fields();
18749: my %titles = &scantronconfig_titles();
1.347 raeburn 18750: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18751: my ($newdat,$currdat,%newcol,%currcol);
18752: if (grep(/^dat$/,@formats)) {
18753: $confhash{'scantron'}{config}{dat} = 1;
18754: $newdat = 1;
18755: } else {
18756: $newdat = 0;
18757: }
18758: if (grep(/^csv$/,@formats)) {
18759: my %bynum;
18760: foreach my $field (@fields) {
18761: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18762: my $posscol = $1;
18763: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18764: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18765: $bynum{$posscol} = $field;
18766: $newcol{$field} = $posscol;
18767: }
18768: }
18769: }
1.347 raeburn 18770: if (keys(%newcol)) {
18771: foreach my $option (@options) {
18772: if ($env{'form.scantroncsv_'.$option}) {
18773: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18774: }
18775: }
18776: }
1.346 raeburn 18777: }
18778: $currdat = 1;
18779: if (ref($domconfig{'scantron'}) eq 'HASH') {
18780: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18781: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18782: $currdat = 0;
18783: }
18784: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18785: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18786: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18787: }
1.346 raeburn 18788: }
18789: }
18790: }
18791: if ($currdat != $newdat) {
18792: $changes{'config'} = 1;
18793: } else {
18794: foreach my $field (@fields) {
18795: if ($currcol{$field} ne '') {
18796: if ($currcol{$field} ne $newcol{$field}) {
18797: $changes{'config'} = 1;
18798: last;
1.347 raeburn 18799: }
1.346 raeburn 18800: } elsif ($newcol{$field} ne '') {
18801: $changes{'config'} = 1;
18802: last;
18803: }
18804: }
18805: }
1.46 raeburn 18806: if (keys(%confhash) > 0) {
18807: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18808: $dom);
18809: if ($putresult eq 'ok') {
18810: if (keys(%changes) > 0) {
1.48 raeburn 18811: if (ref($confhash{'scantron'}) eq 'HASH') {
18812: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18813: if ($changes{'scantronformat'}) {
18814: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18815: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18816: } else {
18817: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18818: }
18819: }
1.347 raeburn 18820: if ($changes{'config'}) {
1.346 raeburn 18821: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18822: if ($confhash{'scantron'}{'config'}{'dat'}) {
18823: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18824: }
18825: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18826: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18827: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18828: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18829: foreach my $field (@fields) {
18830: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18831: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18832: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18833: }
18834: }
18835: $resulttext .= '</ul></li>';
18836: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18837: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18838: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18839: foreach my $option (@options) {
18840: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18841: $resulttext .= '<li>'.$titles{$option}.'</li>';
18842: }
18843: }
18844: $resulttext .= '</ul></li>';
18845: }
1.346 raeburn 18846: }
18847: }
18848: }
18849: }
18850: } else {
18851: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18852: }
1.46 raeburn 18853: }
1.48 raeburn 18854: $resulttext .= '</ul>';
18855: } else {
1.130 raeburn 18856: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18857: }
18858: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18859: if (ref($lastactref) eq 'HASH') {
18860: $lastactref->{'domainconfig'} = 1;
18861: }
1.46 raeburn 18862: } else {
1.346 raeburn 18863: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18864: }
18865: } else {
18866: $resulttext = '<span class="LC_error">'.
18867: &mt('An error occurred: [_1]',$putresult).'</span>';
18868: }
18869: } else {
1.130 raeburn 18870: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18871: }
18872: if ($errors) {
1.353 raeburn 18873: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18874: $errors.'</ul></p>';
1.46 raeburn 18875: }
18876: return $resulttext;
18877: }
18878:
1.48 raeburn 18879: sub modify_coursecategories {
1.239 raeburn 18880: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18881: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18882: $cathash);
1.48 raeburn 18883: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 18884: my @catitems = ('unauth','auth');
18885: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18886: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18887: $cathash = $domconfig{'coursecategories'}{'cats'};
18888: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18889: $changes{'togglecats'} = 1;
18890: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18891: }
18892: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18893: $changes{'categorize'} = 1;
18894: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18895: }
1.120 raeburn 18896: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18897: $changes{'togglecatscomm'} = 1;
18898: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18899: }
18900: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18901: $changes{'categorizecomm'} = 1;
18902: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 18903:
18904: }
18905: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
18906: $changes{'togglecatsplace'} = 1;
18907: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
18908: }
18909: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
18910: $changes{'categorizeplace'} = 1;
18911: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 18912: }
1.238 raeburn 18913: foreach my $item (@catitems) {
18914: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18915: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18916: $changes{$item} = 1;
18917: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18918: }
18919: }
18920: }
1.57 raeburn 18921: } else {
18922: $changes{'togglecats'} = 1;
18923: $changes{'categorize'} = 1;
1.124 raeburn 18924: $changes{'togglecatscomm'} = 1;
18925: $changes{'categorizecomm'} = 1;
1.272 raeburn 18926: $changes{'togglecatsplace'} = 1;
18927: $changes{'categorizeplace'} = 1;
1.87 raeburn 18928: $domconfig{'coursecategories'} = {
18929: togglecats => $env{'form.togglecats'},
18930: categorize => $env{'form.categorize'},
1.124 raeburn 18931: togglecatscomm => $env{'form.togglecatscomm'},
18932: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 18933: togglecatsplace => $env{'form.togglecatsplace'},
18934: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 18935: };
1.238 raeburn 18936: foreach my $item (@catitems) {
18937: if ($env{'form.coursecat_'.$item} ne 'std') {
18938: $changes{$item} = 1;
18939: }
18940: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18941: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18942: }
18943: }
1.57 raeburn 18944: }
18945: if (ref($cathash) eq 'HASH') {
18946: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18947: push (@deletecategory,'instcode::0');
18948: }
1.120 raeburn 18949: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18950: push(@deletecategory,'communities::0');
18951: }
1.272 raeburn 18952: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
18953: push(@deletecategory,'placement::0');
18954: }
1.48 raeburn 18955: }
1.57 raeburn 18956: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18957: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18958: if (@deletecategory > 0) {
18959: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18960: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18961: foreach my $item (@deletecategory) {
1.57 raeburn 18962: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18963: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18964: $deletions{$item} = 1;
1.57 raeburn 18965: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18966: }
18967: }
18968: }
1.57 raeburn 18969: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18970: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18971: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18972: $reorderings{$item} = 1;
1.57 raeburn 18973: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18974: }
18975: if ($env{'form.addcategory_name_'.$item} ne '') {
18976: my $newcat = $env{'form.addcategory_name_'.$item};
18977: my $newdepth = $depth+1;
18978: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18979: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18980: $adds{$newitem} = 1;
18981: }
18982: if ($env{'form.subcat_'.$item} ne '') {
18983: my $newcat = $env{'form.subcat_'.$item};
18984: my $newdepth = $depth+1;
18985: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18986: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18987: $adds{$newitem} = 1;
18988: }
18989: }
18990: }
18991: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18992: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18993: my $newitem = 'instcode::0';
1.57 raeburn 18994: if ($cathash->{$newitem} eq '') {
18995: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18996: $adds{$newitem} = 1;
18997: }
18998: } else {
18999: my $newitem = 'instcode::0';
1.57 raeburn 19000: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19001: $adds{$newitem} = 1;
19002: }
19003: }
1.120 raeburn 19004: if ($env{'form.communities'} eq '1') {
19005: if (ref($cathash) eq 'HASH') {
19006: my $newitem = 'communities::0';
19007: if ($cathash->{$newitem} eq '') {
19008: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19009: $adds{$newitem} = 1;
19010: }
19011: } else {
19012: my $newitem = 'communities::0';
19013: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19014: $adds{$newitem} = 1;
19015: }
19016: }
1.272 raeburn 19017: if ($env{'form.placement'} eq '1') {
19018: if (ref($cathash) eq 'HASH') {
19019: my $newitem = 'placement::0';
19020: if ($cathash->{$newitem} eq '') {
19021: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19022: $adds{$newitem} = 1;
19023: }
19024: } else {
19025: my $newitem = 'placement::0';
19026: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19027: $adds{$newitem} = 1;
19028: }
19029: }
1.48 raeburn 19030: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19031: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19032: ($env{'form.addcategory_name'} ne 'communities') &&
19033: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19034: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19035: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19036: $adds{$newitem} = 1;
19037: }
1.48 raeburn 19038: }
1.57 raeburn 19039: my $putresult;
1.48 raeburn 19040: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19041: if (keys(%deletions) > 0) {
19042: foreach my $key (keys(%deletions)) {
19043: if ($predelallitems{$key} ne '') {
19044: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19045: }
19046: }
19047: }
19048: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19049: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19050: if (ref($chkcats[0]) eq 'ARRAY') {
19051: my $depth = 0;
19052: my $chg = 0;
19053: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19054: my $name = $chkcats[0][$i];
19055: my $item;
19056: if ($name eq '') {
19057: $chg ++;
19058: } else {
19059: $item = &escape($name).'::0';
19060: if ($chg) {
1.57 raeburn 19061: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19062: }
19063: $depth ++;
1.57 raeburn 19064: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19065: $depth --;
19066: }
19067: }
19068: }
1.57 raeburn 19069: }
19070: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19071: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19072: if ($putresult eq 'ok') {
1.57 raeburn 19073: my %title = (
1.120 raeburn 19074: togglecats => 'Show/Hide a course in catalog',
19075: categorize => 'Assign a category to a course',
19076: togglecatscomm => 'Show/Hide a community in catalog',
19077: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19078: );
19079: my %level = (
1.120 raeburn 19080: dom => 'set in Domain ("Modify Course/Community")',
19081: crs => 'set in Course ("Course Configuration")',
19082: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19083: none => 'No catalog',
19084: std => 'Standard catalog',
19085: domonly => 'Domain-only catalog',
19086: codesrch => 'Code search form',
1.57 raeburn 19087: );
1.48 raeburn 19088: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19089: if ($changes{'togglecats'}) {
19090: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19091: }
19092: if ($changes{'categorize'}) {
19093: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19094: }
1.120 raeburn 19095: if ($changes{'togglecatscomm'}) {
19096: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19097: }
19098: if ($changes{'categorizecomm'}) {
19099: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19100: }
1.238 raeburn 19101: if ($changes{'unauth'}) {
19102: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19103: }
19104: if ($changes{'auth'}) {
19105: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19106: }
1.57 raeburn 19107: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19108: my $cathash;
19109: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19110: $cathash = $domconfig{'coursecategories'}{'cats'};
19111: } else {
19112: $cathash = {};
19113: }
19114: my (@cats,@trails,%allitems);
19115: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19116: if (keys(%deletions) > 0) {
19117: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19118: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19119: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19120: }
19121: $resulttext .= '</ul></li>';
19122: }
19123: if (keys(%reorderings) > 0) {
19124: my %sort_by_trail;
19125: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19126: foreach my $key (keys(%reorderings)) {
19127: if ($allitems{$key} ne '') {
19128: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19129: }
1.48 raeburn 19130: }
1.57 raeburn 19131: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19132: $resulttext .= '<li>'.$trails[$trail].'</li>';
19133: }
19134: $resulttext .= '</ul></li>';
1.48 raeburn 19135: }
1.57 raeburn 19136: if (keys(%adds) > 0) {
19137: my %sort_by_trail;
19138: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19139: foreach my $key (keys(%adds)) {
19140: if ($allitems{$key} ne '') {
19141: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19142: }
19143: }
19144: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19145: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19146: }
1.57 raeburn 19147: $resulttext .= '</ul></li>';
1.48 raeburn 19148: }
1.364 raeburn 19149: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19150: if (ref($lastactref) eq 'HASH') {
19151: $lastactref->{'cats'} = 1;
19152: }
1.48 raeburn 19153: }
19154: $resulttext .= '</ul>';
1.239 raeburn 19155: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19156: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19157: if ($changes{'auth'}) {
19158: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19159: }
19160: if ($changes{'unauth'}) {
19161: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19162: }
19163: my $cachetime = 24*60*60;
19164: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19165: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19166: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19167: }
19168: }
1.48 raeburn 19169: } else {
19170: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19171: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19172: }
19173: } else {
1.120 raeburn 19174: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19175: }
19176: return $resulttext;
19177: }
19178:
1.69 raeburn 19179: sub modify_serverstatuses {
19180: my ($dom,%domconfig) = @_;
19181: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19182: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19183: %currserverstatus = %{$domconfig{'serverstatuses'}};
19184: }
19185: my @pages = &serverstatus_pages();
19186: foreach my $type (@pages) {
19187: $newserverstatus{$type}{'namedusers'} = '';
19188: $newserverstatus{$type}{'machines'} = '';
19189: if (defined($env{'form.'.$type.'_namedusers'})) {
19190: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19191: my @okusers;
19192: foreach my $user (@users) {
19193: my ($uname,$udom) = split(/:/,$user);
19194: if (($udom =~ /^$match_domain$/) &&
19195: (&Apache::lonnet::domain($udom)) &&
19196: ($uname =~ /^$match_username$/)) {
19197: if (!grep(/^\Q$user\E/,@okusers)) {
19198: push(@okusers,$user);
19199: }
19200: }
19201: }
19202: if (@okusers > 0) {
19203: @okusers = sort(@okusers);
19204: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19205: }
19206: }
19207: if (defined($env{'form.'.$type.'_machines'})) {
19208: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19209: my @okmachines;
19210: foreach my $ip (@machines) {
19211: my @parts = split(/\./,$ip);
19212: next if (@parts < 4);
19213: my $badip = 0;
19214: for (my $i=0; $i<4; $i++) {
19215: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19216: $badip = 1;
19217: last;
19218: }
19219: }
19220: if (!$badip) {
19221: push(@okmachines,$ip);
19222: }
19223: }
19224: @okmachines = sort(@okmachines);
19225: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19226: }
19227: }
19228: my %serverstatushash = (
19229: serverstatuses => \%newserverstatus,
19230: );
19231: foreach my $type (@pages) {
1.83 raeburn 19232: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19233: my (@current,@new);
1.83 raeburn 19234: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19235: if ($currserverstatus{$type}{$setting} ne '') {
19236: @current = split(/,/,$currserverstatus{$type}{$setting});
19237: }
19238: }
19239: if ($newserverstatus{$type}{$setting} ne '') {
19240: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19241: }
19242: if (@current > 0) {
19243: if (@new > 0) {
19244: foreach my $item (@current) {
19245: if (!grep(/^\Q$item\E$/,@new)) {
19246: $changes{$type}{$setting} = 1;
1.82 raeburn 19247: last;
19248: }
19249: }
1.84 raeburn 19250: foreach my $item (@new) {
19251: if (!grep(/^\Q$item\E$/,@current)) {
19252: $changes{$type}{$setting} = 1;
19253: last;
1.82 raeburn 19254: }
19255: }
19256: } else {
1.83 raeburn 19257: $changes{$type}{$setting} = 1;
1.69 raeburn 19258: }
1.83 raeburn 19259: } elsif (@new > 0) {
19260: $changes{$type}{$setting} = 1;
1.69 raeburn 19261: }
19262: }
19263: }
19264: if (keys(%changes) > 0) {
1.81 raeburn 19265: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19266: my $putresult = &Apache::lonnet::put_dom('configuration',
19267: \%serverstatushash,$dom);
19268: if ($putresult eq 'ok') {
19269: $resulttext .= &mt('Changes made:').'<ul>';
19270: foreach my $type (@pages) {
1.84 raeburn 19271: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19272: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19273: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19274: if ($newserverstatus{$type}{'namedusers'} eq '') {
19275: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19276: } else {
19277: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19278: }
1.84 raeburn 19279: }
19280: if ($changes{$type}{'machines'}) {
1.69 raeburn 19281: if ($newserverstatus{$type}{'machines'} eq '') {
19282: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19283: } else {
19284: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19285: }
19286:
19287: }
19288: $resulttext .= '</ul></li>';
19289: }
19290: }
19291: $resulttext .= '</ul>';
19292: } else {
19293: $resulttext = '<span class="LC_error">'.
19294: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19295:
19296: }
19297: } else {
19298: $resulttext = &mt('No changes made to access to server status pages');
19299: }
19300: return $resulttext;
19301: }
19302:
1.118 jms 19303: sub modify_helpsettings {
1.285 raeburn 19304: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19305: my ($resulttext,$errors,%changes,%helphash);
19306: my %defaultchecked = ('submitbugs' => 'on');
19307: my @offon = ('off','on');
1.118 jms 19308: my @toggles = ('submitbugs');
1.285 raeburn 19309: my %current = ('submitbugs' => '',
19310: 'adhoc' => {},
19311: );
1.118 jms 19312: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19313: %current = %{$domconfig{'helpsettings'}};
19314: }
1.285 raeburn 19315: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19316: foreach my $item (@toggles) {
19317: if ($defaultchecked{$item} eq 'on') {
19318: if ($current{$item} eq '') {
19319: if ($env{'form.'.$item} eq '0') {
19320: $changes{$item} = 1;
19321: }
19322: } elsif ($current{$item} ne $env{'form.'.$item}) {
19323: $changes{$item} = 1;
19324: }
19325: } elsif ($defaultchecked{$item} eq 'off') {
19326: if ($current{$item} eq '') {
19327: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 19328: $changes{$item} = 1;
19329: }
1.282 raeburn 19330: } elsif ($current{$item} ne $env{'form.'.$item}) {
19331: $changes{$item} = 1;
19332: }
19333: }
19334: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
19335: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
19336: }
19337: }
1.285 raeburn 19338: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 19339: my $confname = $dom.'-domainconfig';
19340: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 19341: my (@allpos,%newsettings,%changedprivs,$newrole);
19342: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 19343: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 19344: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 19345: my %lt = &Apache::lonlocal::texthash(
19346: s => 'system',
19347: d => 'domain',
19348: order => 'Display order',
19349: access => 'Role usage',
1.291 raeburn 19350: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 19351: dh => 'All with domain helpdesk role',
19352: da => 'All with domain helpdesk assistant role',
1.285 raeburn 19353: none => 'None',
19354: status => 'Determined based on institutional status',
19355: inc => 'Include all, but exclude specific personnel',
19356: exc => 'Exclude all, but include specific personnel',
19357: );
19358: for (my $num=0; $num<=$maxnum; $num++) {
19359: my ($prefix,$identifier,$rolename,%curr);
19360: if ($num == $maxnum) {
19361: next unless ($env{'form.newcusthelp'} == $maxnum);
19362: $identifier = 'custhelp'.$num;
19363: $prefix = 'helproles_'.$num;
19364: $rolename = $env{'form.custhelpname'.$num};
19365: $rolename=~s/[^A-Za-z0-9]//gs;
19366: next if ($rolename eq '');
19367: next if (exists($existing{'rolesdef_'.$rolename}));
19368: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19369: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19370: $newprivs{'c'},$confname,$dom);
19371: if ($result ne 'ok') {
19372: $errors .= '<li><span class="LC_error">'.
19373: &mt('An error occurred storing the new custom role: [_1]',
19374: $result).'</span></li>';
19375: next;
19376: } else {
19377: $changedprivs{$rolename} = \%newprivs;
19378: $newrole = $rolename;
19379: }
19380: } else {
19381: $prefix = 'helproles_'.$num;
19382: $rolename = $env{'form.'.$prefix};
19383: next if ($rolename eq '');
19384: next unless (exists($existing{'rolesdef_'.$rolename}));
19385: $identifier = 'custhelp'.$num;
19386: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19387: my %currprivs;
1.289 raeburn 19388: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 19389: split(/\_/,$existing{'rolesdef_'.$rolename});
19390: foreach my $level ('c','d','s') {
19391: if ($newprivs{$level} ne $currprivs{$level}) {
19392: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19393: $newprivs{'c'},$confname,$dom);
19394: if ($result ne 'ok') {
19395: $errors .= '<li><span class="LC_error">'.
19396: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
19397: $rolename,$result).'</span></li>';
19398: } else {
19399: $changedprivs{$rolename} = \%newprivs;
19400: }
19401: last;
19402: }
19403: }
19404: if (ref($current{'adhoc'}) eq 'HASH') {
19405: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19406: %curr = %{$current{'adhoc'}{$rolename}};
19407: }
19408: }
19409: }
19410: my $newpos = $env{'form.'.$prefix.'_pos'};
19411: $newpos =~ s/\D+//g;
19412: $allpos[$newpos] = $rolename;
19413: my $newdesc = $env{'form.'.$prefix.'_desc'};
19414: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
19415: if ($curr{'desc'}) {
19416: if ($curr{'desc'} ne $newdesc) {
19417: $changes{'customrole'}{$rolename}{'desc'} = 1;
19418: $newsettings{$rolename}{'desc'} = $newdesc;
19419: }
19420: } elsif ($newdesc ne '') {
19421: $changes{'customrole'}{$rolename}{'desc'} = 1;
19422: $newsettings{$rolename}{'desc'} = $newdesc;
19423: }
19424: my $access = $env{'form.'.$prefix.'_access'};
19425: if (grep(/^\Q$access\E$/,@accesstypes)) {
19426: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
19427: if ($access eq 'status') {
19428: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
19429: if (scalar(@statuses) == 0) {
1.289 raeburn 19430: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 19431: } else {
19432: my (@shownstatus,$numtypes);
19433: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19434: if (ref($types) eq 'ARRAY') {
19435: $numtypes = scalar(@{$types});
19436: foreach my $type (sort(@statuses)) {
19437: if ($type eq 'default') {
19438: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19439: } elsif (grep(/^\Q$type\E$/,@{$types})) {
19440: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19441: push(@shownstatus,$usertypes->{$type});
19442: }
19443: }
19444: }
19445: if (grep(/^default$/,@statuses)) {
19446: push(@shownstatus,$othertitle);
19447: }
19448: if (scalar(@shownstatus) == 1+$numtypes) {
19449: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
19450: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
19451: } else {
19452: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
19453: if (ref($curr{'status'}) eq 'ARRAY') {
19454: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19455: if (@diffs) {
19456: $changes{'customrole'}{$rolename}{$access} = 1;
19457: }
19458: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19459: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 19460: }
1.166 raeburn 19461: }
19462: }
1.285 raeburn 19463: } elsif (($access eq 'inc') || ($access eq 'exc')) {
19464: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
19465: my @newspecstaff;
19466: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19467: foreach my $person (sort(@personnel)) {
19468: if ($domhelpdesk{$person}) {
19469: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
19470: }
19471: }
19472: if (ref($curr{$access}) eq 'ARRAY') {
19473: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19474: if (@diffs) {
19475: $changes{'customrole'}{$rolename}{$access} = 1;
19476: }
19477: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19478: $changes{'customrole'}{$rolename}{$access} = 1;
19479: }
19480: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19481: my ($uname,$udom) = split(/:/,$person);
19482: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
19483: }
19484: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 19485: }
1.285 raeburn 19486: } else {
19487: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
19488: }
19489: unless ($curr{'access'} eq $access) {
19490: $changes{'customrole'}{$rolename}{'access'} = 1;
19491: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 19492: }
19493: }
1.285 raeburn 19494: if (@allpos > 0) {
19495: my $idx = 0;
19496: foreach my $rolename (@allpos) {
19497: if ($rolename ne '') {
19498: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
19499: if (ref($current{'adhoc'}) eq 'HASH') {
19500: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19501: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
19502: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 19503: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 19504: }
19505: }
1.282 raeburn 19506: }
1.285 raeburn 19507: $idx ++;
1.166 raeburn 19508: }
19509: }
1.118 jms 19510: }
1.123 jms 19511: my $putresult;
19512: if (keys(%changes) > 0) {
1.166 raeburn 19513: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 19514: if ($putresult eq 'ok') {
1.285 raeburn 19515: if (ref($helphash{'helpsettings'}) eq 'HASH') {
19516: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
19517: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
19518: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
19519: }
19520: }
19521: my $cachetime = 24*60*60;
19522: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19523: if (ref($lastactref) eq 'HASH') {
19524: $lastactref->{'domdefaults'} = 1;
19525: }
19526: } else {
19527: $errors .= '<li><span class="LC_error">'.
19528: &mt('An error occurred storing the settings: [_1]',
19529: $putresult).'</span></li>';
19530: }
19531: }
19532: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
19533: $resulttext = &mt('Changes made:').'<ul>';
19534: my (%shownprivs,@levelorder);
19535: @levelorder = ('c','d','s');
19536: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 19537: foreach my $item (sort(keys(%changes))) {
19538: if ($item eq 'submitbugs') {
19539: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
19540: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
19541: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 19542: } elsif ($item eq 'customrole') {
19543: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 19544: my @keyorder = ('order','desc','access','status','exc','inc');
19545: my %keytext = &Apache::lonlocal::texthash(
19546: order => 'Order',
19547: desc => 'Role description',
19548: access => 'Role usage',
1.300 droeschl 19549: status => 'Allowed institutional types',
1.285 raeburn 19550: exc => 'Allowed personnel',
19551: inc => 'Disallowed personnel',
19552: );
1.282 raeburn 19553: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 19554: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
19555: if ($role eq $newrole) {
19556: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
19557: $role).'<ul>';
19558: } else {
19559: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19560: $role).'<ul>';
19561: }
19562: foreach my $key (@keyorder) {
19563: if ($changes{'customrole'}{$role}{$key}) {
19564: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19565: $keytext{$key},$newsettings{$role}{$key}).
19566: '</li>';
19567: }
19568: }
19569: if (ref($changedprivs{$role}) eq 'HASH') {
19570: $shownprivs{$role} = 1;
19571: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19572: foreach my $level (@levelorder) {
19573: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19574: next if ($item eq '');
19575: my ($priv) = split(/\&/,$item,2);
19576: if (&Apache::lonnet::plaintext($priv)) {
19577: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19578: unless ($level eq 'c') {
19579: $resulttext .= ' ('.$lt{$level}.')';
19580: }
19581: $resulttext .= '</li>';
19582: }
19583: }
19584: }
19585: $resulttext .= '</ul>';
19586: }
19587: $resulttext .= '</ul></li>';
19588: }
19589: }
19590: }
19591: }
19592: }
19593: }
19594: if (keys(%changedprivs)) {
19595: foreach my $role (sort(keys(%changedprivs))) {
19596: unless ($shownprivs{$role}) {
19597: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19598: $role).'<ul>'.
19599: '<li>'.&mt('Privileges set to :').'<ul>';
19600: foreach my $level (@levelorder) {
19601: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19602: next if ($item eq '');
19603: my ($priv) = split(/\&/,$item,2);
19604: if (&Apache::lonnet::plaintext($priv)) {
19605: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19606: unless ($level eq 'c') {
19607: $resulttext .= ' ('.$lt{$level}.')';
19608: }
19609: $resulttext .= '</li>';
19610: }
1.282 raeburn 19611: }
19612: }
1.285 raeburn 19613: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 19614: }
19615: }
19616: }
1.285 raeburn 19617: $resulttext .= '</ul>';
19618: } else {
19619: $resulttext = &mt('No changes made to help settings');
1.118 jms 19620: }
19621: if ($errors) {
1.168 raeburn 19622: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 19623: $errors.'</ul>';
1.118 jms 19624: }
19625: return $resulttext;
19626: }
19627:
1.121 raeburn 19628: sub modify_coursedefaults {
1.212 raeburn 19629: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19630: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 19631: my %defaultchecked = (
19632: 'canuse_pdfforms' => 'off',
19633: 'uselcmath' => 'on',
19634: 'usejsme' => 'on'
19635: );
19636: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 19637: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 19638: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
19639: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19640: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 19641: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 19642: my %staticdefaults = (
19643: anonsurvey_threshold => 10,
19644: uploadquota => 500,
1.257 raeburn 19645: postsubmit => 60,
1.276 raeburn 19646: mysqltables => 172800,
1.198 raeburn 19647: );
1.314 raeburn 19648: my %texoptions = (
19649: MathJax => 'MathJax',
19650: mimetex => &mt('Convert to Images'),
19651: tth => &mt('TeX to HTML'),
19652: );
1.121 raeburn 19653: $defaultshash{'coursedefaults'} = {};
19654:
19655: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19656: if ($domconfig{'coursedefaults'} eq '') {
19657: $domconfig{'coursedefaults'} = {};
19658: }
19659: }
19660:
19661: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19662: foreach my $item (@toggles) {
19663: if ($defaultchecked{$item} eq 'on') {
19664: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19665: ($env{'form.'.$item} eq '0')) {
19666: $changes{$item} = 1;
1.192 raeburn 19667: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19668: $changes{$item} = 1;
19669: }
19670: } elsif ($defaultchecked{$item} eq 'off') {
19671: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19672: ($env{'form.'.$item} eq '1')) {
19673: $changes{$item} = 1;
19674: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19675: $changes{$item} = 1;
19676: }
19677: }
19678: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19679: }
1.198 raeburn 19680: foreach my $item (@numbers) {
19681: my ($currdef,$newdef);
1.208 raeburn 19682: $newdef = $env{'form.'.$item};
1.198 raeburn 19683: if ($item eq 'anonsurvey_threshold') {
19684: $currdef = $domconfig{'coursedefaults'}{$item};
19685: $newdef =~ s/\D//g;
19686: if ($newdef eq '' || $newdef < 1) {
19687: $newdef = 1;
19688: }
19689: $defaultshash{'coursedefaults'}{$item} = $newdef;
19690: } else {
1.276 raeburn 19691: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
19692: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19693: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19694: }
19695: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19696: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19697: }
19698: if ($currdef ne $newdef) {
19699: if ($item eq 'anonsurvey_threshold') {
19700: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19701: $changes{$item} = 1;
19702: }
1.276 raeburn 19703: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19704: my $setting = $1;
1.276 raeburn 19705: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19706: $changes{$setting} = 1;
1.198 raeburn 19707: }
19708: }
1.139 raeburn 19709: }
19710: }
1.314 raeburn 19711: my $texengine;
19712: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19713: $texengine = $env{'form.texengine'};
1.349 raeburn 19714: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19715: if ($currdef eq '') {
19716: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19717: $changes{'texengine'} = 1;
19718: }
1.349 raeburn 19719: } elsif ($currdef ne $texengine) {
1.314 raeburn 19720: $changes{'texengine'} = 1;
19721: }
19722: }
19723: if ($texengine ne '') {
19724: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19725: }
1.264 raeburn 19726: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19727: my @currclonecode;
19728: if (ref($currclone) eq 'HASH') {
19729: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19730: @currclonecode = @{$currclone->{'instcode'}};
19731: }
19732: }
19733: my $newclone;
1.289 raeburn 19734: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19735: $newclone = $env{'form.canclone'};
19736: }
19737: if ($newclone eq 'instcode') {
19738: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19739: my (%codedefaults,@code_order,@clonecode);
19740: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19741: \@code_order);
19742: foreach my $item (@code_order) {
19743: if (grep(/^\Q$item\E$/,@newcodes)) {
19744: push(@clonecode,$item);
19745: }
19746: }
19747: if (@clonecode) {
19748: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19749: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19750: if (@diffs) {
19751: $changes{'canclone'} = 1;
19752: }
19753: } else {
19754: $newclone eq '';
19755: }
19756: } elsif ($newclone ne '') {
1.289 raeburn 19757: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19758: }
1.264 raeburn 19759: if ($newclone ne $currclone) {
19760: $changes{'canclone'} = 1;
19761: }
1.257 raeburn 19762: my %credits;
19763: foreach my $type (@types) {
19764: unless ($type eq 'community') {
19765: $credits{$type} = $env{'form.'.$type.'_credits'};
19766: $credits{$type} =~ s/[^\d.]+//g;
19767: }
19768: }
19769: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19770: ($env{'form.coursecredits'} eq '1')) {
19771: $changes{'coursecredits'} = 1;
19772: foreach my $type (keys(%credits)) {
19773: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19774: }
19775: } else {
1.289 raeburn 19776: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19777: foreach my $type (@types) {
19778: unless ($type eq 'community') {
1.289 raeburn 19779: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19780: $changes{'coursecredits'} = 1;
19781: }
19782: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19783: }
19784: }
19785: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19786: foreach my $type (@types) {
19787: unless ($type eq 'community') {
19788: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19789: $changes{'coursecredits'} = 1;
19790: last;
19791: }
19792: }
19793: }
19794: }
19795: }
19796: if ($env{'form.postsubmit'} eq '1') {
19797: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19798: my %currtimeout;
19799: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19800: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19801: $changes{'postsubmit'} = 1;
19802: }
19803: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19804: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19805: }
19806: } else {
19807: $changes{'postsubmit'} = 1;
19808: }
19809: foreach my $type (@types) {
19810: my $timeout = $env{'form.'.$type.'_timeout'};
19811: $timeout =~ s/\D//g;
19812: if ($timeout == $staticdefaults{'postsubmit'}) {
19813: $timeout = '';
19814: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19815: $timeout = '0';
19816: }
19817: unless ($timeout eq '') {
19818: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19819: }
19820: if (exists($currtimeout{$type})) {
19821: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19822: $changes{'postsubmit'} = 1;
1.257 raeburn 19823: }
19824: } elsif ($timeout ne '') {
19825: $changes{'postsubmit'} = 1;
19826: }
19827: }
19828: } else {
19829: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19830: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19831: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19832: $changes{'postsubmit'} = 1;
19833: }
19834: } else {
19835: $changes{'postsubmit'} = 1;
19836: }
1.192 raeburn 19837: }
1.121 raeburn 19838: }
19839: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19840: $dom);
19841: if ($putresult eq 'ok') {
19842: if (keys(%changes) > 0) {
1.213 raeburn 19843: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19844: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19845: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19846: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19847: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19848: if ($changes{$item}) {
19849: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19850: }
1.289 raeburn 19851: }
1.192 raeburn 19852: if ($changes{'coursecredits'}) {
19853: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19854: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19855: $domdefaults{$type.'credits'} =
19856: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19857: }
19858: }
19859: }
19860: if ($changes{'postsubmit'}) {
19861: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19862: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19863: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19864: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19865: $domdefaults{$type.'postsubtimeout'} =
19866: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19867: }
19868: }
1.192 raeburn 19869: }
19870: }
1.198 raeburn 19871: if ($changes{'uploadquota'}) {
19872: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19873: foreach my $type (@types) {
19874: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19875: }
19876: }
19877: }
1.264 raeburn 19878: if ($changes{'canclone'}) {
19879: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19880: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19881: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19882: if (@clonecodes) {
19883: $domdefaults{'canclone'} = join('+',@clonecodes);
19884: }
19885: }
19886: } else {
19887: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19888: }
19889: }
1.121 raeburn 19890: my $cachetime = 24*60*60;
19891: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19892: if (ref($lastactref) eq 'HASH') {
19893: $lastactref->{'domdefaults'} = 1;
19894: }
1.121 raeburn 19895: }
19896: $resulttext = &mt('Changes made:').'<ul>';
19897: foreach my $item (sort(keys(%changes))) {
19898: if ($item eq 'canuse_pdfforms') {
19899: if ($env{'form.'.$item} eq '1') {
19900: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
19901: } else {
19902: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
19903: }
1.257 raeburn 19904: } elsif ($item eq 'uselcmath') {
19905: if ($env{'form.'.$item} eq '1') {
19906: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
19907: } else {
19908: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19909: }
19910: } elsif ($item eq 'usejsme') {
19911: if ($env{'form.'.$item} eq '1') {
19912: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19913: } else {
1.289 raeburn 19914: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 19915: }
1.314 raeburn 19916: } elsif ($item eq 'texengine') {
19917: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19918: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19919: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19920: }
1.139 raeburn 19921: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 19922: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 19923: } elsif ($item eq 'uploadquota') {
19924: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19925: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19926: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19927: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 19928: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 19929: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 19930: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19931: '</ul>'.
19932: '</li>';
19933: } else {
19934: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19935: }
1.276 raeburn 19936: } elsif ($item eq 'mysqltables') {
19937: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19938: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19939: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19940: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19941: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19942: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
19943: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19944: '</ul>'.
19945: '</li>';
19946: } else {
19947: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19948: }
1.257 raeburn 19949: } elsif ($item eq 'postsubmit') {
19950: if ($domdefaults{'postsubmit'} eq 'off') {
19951: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19952: } else {
19953: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 19954: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 19955: $resulttext .= &mt('durations:').'<ul>';
19956: foreach my $type (@types) {
19957: $resulttext .= '<li>';
19958: my $timeout;
19959: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19960: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19961: }
19962: my $display;
19963: if ($timeout eq '0') {
19964: $display = &mt('unlimited');
19965: } elsif ($timeout eq '') {
19966: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19967: } else {
19968: $display = &mt('[quant,_1,second]',$timeout);
19969: }
19970: if ($type eq 'community') {
19971: $resulttext .= &mt('Communities');
19972: } elsif ($type eq 'official') {
19973: $resulttext .= &mt('Official courses');
19974: } elsif ($type eq 'unofficial') {
19975: $resulttext .= &mt('Unofficial courses');
19976: } elsif ($type eq 'textbook') {
19977: $resulttext .= &mt('Textbook courses');
1.271 raeburn 19978: } elsif ($type eq 'placement') {
19979: $resulttext .= &mt('Placement tests');
1.257 raeburn 19980: }
19981: $resulttext .= ' -- '.$display.'</li>';
19982: }
19983: $resulttext .= '</ul>';
19984: }
1.289 raeburn 19985: $resulttext .= '</li>';
1.257 raeburn 19986: }
1.192 raeburn 19987: } elsif ($item eq 'coursecredits') {
19988: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19989: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 19990: ($domdefaults{'unofficialcredits'} eq '') &&
19991: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 19992: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19993: } else {
19994: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19995: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19996: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 19997: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 19998: '</ul>'.
19999: '</li>';
20000: }
20001: } else {
20002: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20003: }
1.264 raeburn 20004: } elsif ($item eq 'canclone') {
20005: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20006: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20007: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20008: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20009: }
20010: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20011: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20012: } else {
1.289 raeburn 20013: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20014: }
1.140 raeburn 20015: }
1.121 raeburn 20016: }
20017: $resulttext .= '</ul>';
20018: } else {
20019: $resulttext = &mt('No changes made to course defaults');
20020: }
20021: } else {
20022: $resulttext = '<span class="LC_error">'.
20023: &mt('An error occurred: [_1]',$putresult).'</span>';
20024: }
20025: return $resulttext;
20026: }
20027:
1.231 raeburn 20028: sub modify_selfenrollment {
20029: my ($dom,$lastactref,%domconfig) = @_;
20030: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20031: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20032: my %titles = &tool_titles();
1.232 raeburn 20033: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20034: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20035: $ordered{'default'} = ['types','registered','approval','limit'];
20036:
20037: my (%roles,%shown,%toplevel);
20038: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20039:
20040: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20041: if ($domconfig{'selfenrollment'} eq '') {
20042: $domconfig{'selfenrollment'} = {};
20043: }
20044: }
20045: %toplevel = (
20046: admin => 'Configuration Rights',
20047: default => 'Default settings',
20048: validation => 'Validation of self-enrollment requests',
20049: );
1.233 raeburn 20050: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20051:
20052: if (ref($ordered{'admin'}) eq 'ARRAY') {
20053: foreach my $item (@{$ordered{'admin'}}) {
20054: foreach my $type (@types) {
20055: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20056: $selfenrollhash{'admin'}{$type}{$item} = 1;
20057: } else {
20058: $selfenrollhash{'admin'}{$type}{$item} = 0;
20059: }
20060: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20061: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20062: if ($selfenrollhash{'admin'}{$type}{$item} ne
20063: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20064: push(@{$changes{'admin'}{$type}},$item);
20065: }
20066: } else {
20067: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20068: push(@{$changes{'admin'}{$type}},$item);
20069: }
20070: }
20071: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20072: push(@{$changes{'admin'}{$type}},$item);
20073: }
20074: }
20075: }
20076: }
20077:
20078: foreach my $item (@{$ordered{'default'}}) {
20079: foreach my $type (@types) {
20080: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20081: if ($item eq 'types') {
20082: unless (($value eq 'all') || ($value eq 'dom')) {
20083: $value = '';
20084: }
20085: } elsif ($item eq 'registered') {
20086: unless ($value eq '1') {
20087: $value = 0;
20088: }
20089: } elsif ($item eq 'approval') {
20090: unless ($value =~ /^[012]$/) {
20091: $value = 0;
20092: }
20093: } else {
20094: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20095: $value = 'none';
20096: }
20097: }
20098: $selfenrollhash{'default'}{$type}{$item} = $value;
20099: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20100: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20101: if ($selfenrollhash{'default'}{$type}{$item} ne
20102: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20103: push(@{$changes{'default'}{$type}},$item);
20104: }
20105: } else {
20106: push(@{$changes{'default'}{$type}},$item);
20107: }
20108: } else {
20109: push(@{$changes{'default'}{$type}},$item);
20110: }
20111: if ($item eq 'limit') {
20112: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20113: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20114: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20115: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20116: }
20117: } else {
20118: $selfenrollhash{'default'}{$type}{'cap'} = '';
20119: }
20120: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20121: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20122: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20123: push(@{$changes{'default'}{$type}},'cap');
20124: }
20125: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20126: push(@{$changes{'default'}{$type}},'cap');
20127: }
20128: }
20129: }
20130: }
20131:
20132: foreach my $item (@{$itemsref}) {
20133: if ($item eq 'fields') {
20134: my @changed;
20135: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20136: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20137: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20138: }
20139: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20140: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20141: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20142: $domconfig{'selfenrollment'}{'validation'}{$item});
20143: } else {
20144: @changed = @{$selfenrollhash{'validation'}{$item}};
20145: }
20146: } else {
20147: @changed = @{$selfenrollhash{'validation'}{$item}};
20148: }
20149: if (@changed) {
20150: if ($selfenrollhash{'validation'}{$item}) {
20151: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20152: } else {
20153: $changes{'validation'}{$item} = &mt('None');
20154: }
20155: }
20156: } else {
20157: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20158: if ($item eq 'markup') {
20159: if ($env{'form.selfenroll_validation_'.$item}) {
20160: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20161: }
20162: }
20163: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20164: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20165: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20166: }
20167: }
20168: }
20169: }
20170:
20171: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20172: $dom);
20173: if ($putresult eq 'ok') {
20174: if (keys(%changes) > 0) {
20175: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20176: $resulttext = &mt('Changes made:').'<ul>';
20177: foreach my $key ('admin','default','validation') {
20178: if (ref($changes{$key}) eq 'HASH') {
20179: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20180: if ($key eq 'validation') {
20181: foreach my $item (@{$itemsref}) {
20182: if (exists($changes{$key}{$item})) {
20183: if ($item eq 'markup') {
20184: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20185: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20186: } else {
20187: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20188: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20189: }
20190: }
20191: }
20192: } else {
20193: foreach my $type (@types) {
20194: if ($type eq 'community') {
20195: $roles{'1'} = &mt('Community personnel');
20196: } else {
20197: $roles{'1'} = &mt('Course personnel');
20198: }
20199: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20200: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20201: if ($key eq 'admin') {
20202: my @mgrdc = ();
20203: if (ref($ordered{$key}) eq 'ARRAY') {
20204: foreach my $item (@{$ordered{'admin'}}) {
20205: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20206: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20207: push(@mgrdc,$item);
20208: }
20209: }
20210: }
20211: if (@mgrdc) {
20212: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20213: } else {
20214: delete($domdefaults{$type.'selfenrolladmdc'});
20215: }
20216: }
20217: } else {
20218: if (ref($ordered{$key}) eq 'ARRAY') {
20219: foreach my $item (@{$ordered{$key}}) {
20220: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20221: $domdefaults{$type.'selfenroll'.$item} =
20222: $selfenrollhash{$key}{$type}{$item};
20223: }
20224: }
20225: }
20226: }
20227: }
1.231 raeburn 20228: $resulttext .= '<li>'.$titles{$type}.'<ul>';
20229: foreach my $item (@{$ordered{$key}}) {
20230: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20231: $resulttext .= '<li>';
20232: if ($key eq 'admin') {
20233: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
20234: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
20235: } else {
20236: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
20237: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
20238: }
20239: $resulttext .= '</li>';
20240: }
20241: }
20242: $resulttext .= '</ul></li>';
20243: }
20244: }
20245: $resulttext .= '</ul></li>';
20246: }
20247: }
1.305 raeburn 20248: }
20249: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
20250: my $cachetime = 24*60*60;
20251: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20252: if (ref($lastactref) eq 'HASH') {
20253: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 20254: }
1.231 raeburn 20255: }
20256: $resulttext .= '</ul>';
20257: } else {
20258: $resulttext = &mt('No changes made to self-enrollment settings');
20259: }
20260: } else {
20261: $resulttext = '<span class="LC_error">'.
20262: &mt('An error occurred: [_1]',$putresult).'</span>';
20263: }
20264: return $resulttext;
20265: }
20266:
1.373 raeburn 20267: sub modify_wafproxy {
20268: my ($dom,$action,$lastactref,%domconfig) = @_;
20269: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 20270: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
20271: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 20272: foreach my $server (sort(keys(%servers))) {
20273: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20274: if ($serverhome eq $server) {
20275: my $serverdom = &Apache::lonnet::host_domain($server);
20276: if ($serverdom eq $dom) {
20277: $canset{$server} = 1;
20278: }
20279: }
20280: }
1.381 raeburn 20281: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
20282: %{$values{$dom}} = ();
20283: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
20284: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
20285: }
1.388 raeburn 20286: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
20287: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
20288: }
1.382 raeburn 20289: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 20290: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
20291: }
20292: }
1.373 raeburn 20293: my $output;
20294: if (keys(%canset)) {
20295: %{$wafproxy{'alias'}} = ();
1.388 raeburn 20296: %{$wafproxy{'saml'}} = ();
1.373 raeburn 20297: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 20298: if ($env{'form.wafproxy_'.$dom}) {
20299: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
20300: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
20301: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
20302: $changes{'alias'} = 1;
20303: }
1.388 raeburn 20304: if ($env{'form.wafproxy_alias_saml_'.$key}) {
20305: $wafproxy{'saml'}{$key} = 1;
20306: }
20307: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
20308: $changes{'saml'} = 1;
20309: }
1.381 raeburn 20310: } else {
20311: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 20312: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 20313: if ($curralias{$key}) {
20314: $changes{'alias'} = 1;
20315: }
1.388 raeburn 20316: if ($currsaml{$key}) {
20317: $changes{'saml'} = 1;
20318: }
1.373 raeburn 20319: }
20320: if ($wafproxy{'alias'}{$key} eq '') {
20321: if ($curralias{$key}) {
20322: $expirecache{$key} = 1;
20323: }
20324: delete($wafproxy{'alias'}{$key});
20325: }
1.388 raeburn 20326: if ($wafproxy{'saml'}{$key} eq '') {
20327: if ($currsaml{$key}) {
20328: $expiresaml{$key} = 1;
20329: }
20330: delete($wafproxy{'saml'}{$key});
20331: }
1.373 raeburn 20332: }
20333: unless (keys(%{$wafproxy{'alias'}})) {
20334: delete($wafproxy{'alias'});
20335: }
1.388 raeburn 20336: unless (keys(%{$wafproxy{'saml'}})) {
20337: delete($wafproxy{'saml'});
20338: }
20339: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 20340: my %warn = (
20341: trusted => 'trusted IP range(s)',
1.381 raeburn 20342: vpnint => 'internal IP range(s) for VPN sessions(s)',
20343: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 20344: );
1.382 raeburn 20345: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20346: my $possible = $env{'form.wafproxy_'.$item};
20347: $possible =~ s/^\s+|\s+$//g;
20348: if ($possible ne '') {
1.381 raeburn 20349: if ($item eq 'remoteip') {
20350: if ($possible =~ /^[mhn]$/) {
20351: $wafproxy{$item} = $possible;
20352: }
20353: } elsif ($item eq 'ipheader') {
20354: if ($wafproxy{'remoteip'} eq 'h') {
20355: $wafproxy{$item} = $possible;
20356: }
1.382 raeburn 20357: } elsif ($item eq 'sslopt') {
20358: if ($possible =~ /^0|1$/) {
20359: $wafproxy{$item} = $possible;
20360: }
1.373 raeburn 20361: } else {
20362: my (@ok,$count);
1.381 raeburn 20363: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
20364: unless ($env{'form.wafproxy_vpnaccess'}) {
20365: $possible = '';
20366: }
20367: } elsif ($item eq 'trusted') {
20368: unless ($wafproxy{'remoteip'} eq 'h') {
20369: $possible = '';
20370: }
20371: }
20372: unless ($possible eq '') {
20373: $possible =~ s/[\r\n]+/\s/g;
20374: $possible =~ s/\s*-\s*/-/g;
20375: $possible =~ s/\s+/,/g;
20376: }
1.373 raeburn 20377: $count = 0;
1.381 raeburn 20378: if ($possible ne '') {
1.373 raeburn 20379: foreach my $poss (split(/\,/,$possible)) {
20380: $count ++;
20381: if (&validate_ip_pattern($poss)) {
20382: push(@ok,$poss);
20383: }
20384: }
20385: if (@ok) {
20386: $wafproxy{$item} = join(',',@ok);
20387: }
20388: my $diff = $count - scalar(@ok);
20389: if ($diff) {
20390: push(@warnings,'<li>'.
20391: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
20392: $diff,$warn{$item}).
20393: '</li>');
20394: }
20395: }
20396: }
1.381 raeburn 20397: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 20398: $changes{$item} = 1;
20399: }
1.381 raeburn 20400: } elsif ($currvalue{$item}) {
20401: $changes{$item} = 1;
20402: }
20403: }
20404: } else {
20405: if (keys(%curralias)) {
20406: $changes{'alias'} = 1;
1.388 raeburn 20407: }
20408: if (keys(%currsaml)) {
20409: $changes{'saml'} = 1;
1.381 raeburn 20410: }
20411: if (keys(%currvalue)) {
20412: foreach my $key (keys(%currvalue)) {
20413: $changes{$key} = 1;
1.373 raeburn 20414: }
20415: }
20416: }
20417: if (keys(%changes)) {
20418: my %defaultshash = (
20419: wafproxy => \%wafproxy,
20420: );
20421: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20422: $dom);
20423: if ($putresult eq 'ok') {
20424: my $cachetime = 24*60*60;
20425: my (%domdefaults,$updatedomdefs);
1.382 raeburn 20426: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20427: if ($changes{$item}) {
20428: unless ($updatedomdefs) {
20429: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20430: $updatedomdefs = 1;
20431: }
20432: if ($wafproxy{$item}) {
20433: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20434: } elsif (exists($domdefaults{'waf_'.$item})) {
20435: delete($domdefaults{'waf_'.$item});
20436: }
20437: }
20438: }
20439: if ($updatedomdefs) {
20440: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20441: if (ref($lastactref) eq 'HASH') {
20442: $lastactref->{'domdefaults'} = 1;
20443: }
20444: }
20445: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20446: my %updates = %expirecache;
20447: foreach my $key (keys(%expirecache)) {
20448: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20449: }
20450: if (ref($wafproxy{'alias'}) eq 'HASH') {
20451: my $cachetime = 24*60*60;
20452: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20453: $updates{$key} = 1;
20454: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20455: $cachetime);
20456: }
20457: }
20458: if (ref($lastactref) eq 'HASH') {
20459: $lastactref->{'proxyalias'} = \%updates;
20460: }
20461: }
1.388 raeburn 20462: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20463: my %samlupdates = %expiresaml;
20464: foreach my $key (keys(%expiresaml)) {
20465: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20466: }
20467: if (ref($wafproxy{'saml'}) eq 'HASH') {
20468: my $cachetime = 24*60*60;
20469: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20470: $samlupdates{$key} = 1;
20471: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20472: $cachetime);
20473: }
20474: }
20475: if (ref($lastactref) eq 'HASH') {
20476: $lastactref->{'proxysaml'} = \%samlupdates;
20477: }
20478: }
1.373 raeburn 20479: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382 raeburn 20480: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20481: if ($changes{$item}) {
20482: if ($item eq 'alias') {
20483: my $numaliased = 0;
20484: if (ref($wafproxy{'alias'}) eq 'HASH') {
20485: my $shown;
20486: if (keys(%{$wafproxy{'alias'}})) {
20487: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20488: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20489: &Apache::lonnet::hostname($server),
20490: $wafproxy{'alias'}{$server}).'</li>';
20491: $numaliased ++;
20492: }
20493: if ($numaliased) {
20494: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20495: '<ul>'.$shown.'</ul>').'</li>';
20496: }
20497: }
20498: }
20499: unless ($numaliased) {
20500: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20501: }
1.388 raeburn 20502: } elsif ($item eq 'saml') {
20503: my $shown;
20504: if (ref($wafproxy{'saml'}) eq 'HASH') {
20505: if (keys(%{$wafproxy{'saml'}})) {
20506: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20507: }
20508: }
20509: if ($shown) {
20510: $output .= '<li>'.&mt('Alias used by Shibboleth for: [_1]',
20511: $shown).'</li>';
20512: } else {
20513: $output .= '<li>'.&mt('No alias used for Shibboleth').'</li>';
20514: }
1.373 raeburn 20515: } else {
1.381 raeburn 20516: if ($item eq 'remoteip') {
20517: my %ip_methods = &remoteip_methods();
20518: if ($wafproxy{$item} =~ /^[mh]$/) {
20519: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20520: $ip_methods{$wafproxy{$item}}).'</li>';
20521: } else {
20522: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20523: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20524: '</li>';
20525: } else {
20526: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20527: }
20528: }
20529: } elsif ($item eq 'ipheader') {
1.373 raeburn 20530: if ($wafproxy{$item}) {
1.381 raeburn 20531: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 20532: $wafproxy{$item}).'</li>';
20533: } else {
1.381 raeburn 20534: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 20535: }
20536: } elsif ($item eq 'trusted') {
20537: if ($wafproxy{$item}) {
1.381 raeburn 20538: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 20539: $wafproxy{$item}).'</li>';
20540: } else {
20541: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20542: }
1.381 raeburn 20543: } elsif ($item eq 'vpnint') {
20544: if ($wafproxy{$item}) {
20545: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20546: $wafproxy{$item}).'</li>';
20547: } else {
20548: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20549: }
20550: } elsif ($item eq 'vpnext') {
1.373 raeburn 20551: if ($wafproxy{$item}) {
1.381 raeburn 20552: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 20553: $wafproxy{$item}).'</li>';
20554: } else {
1.381 raeburn 20555: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 20556: }
1.382 raeburn 20557: } elsif ($item eq 'sslopt') {
20558: if ($wafproxy{$item}) {
20559: $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>';
20560: } else {
20561: $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>';
20562: }
1.373 raeburn 20563: }
20564: }
20565: }
20566: }
20567: } else {
20568: $output = '<span class="LC_error">'.
20569: &mt('An error occurred: [_1]',$putresult).'</span>';
20570: }
20571: } elsif (keys(%canset)) {
20572: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20573: }
20574: if (@warnings) {
20575: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20576: join("\n",@warnings).'</ul>';
20577: }
20578: return $output;
20579: }
20580:
20581: sub validate_ip_pattern {
20582: my ($pattern) = @_;
20583: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20584: my ($start,$end) = ($1,$2);
20585: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20586: return 1;
20587: }
20588: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
20589: return 1;
20590: }
20591: return
20592: }
20593:
1.137 raeburn 20594: sub modify_usersessions {
1.212 raeburn 20595: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20596: my @hostingtypes = ('version','excludedomain','includedomain');
20597: my @offloadtypes = ('primary','default');
20598: my %types = (
20599: remote => \@hostingtypes,
20600: hosted => \@hostingtypes,
20601: spares => \@offloadtypes,
20602: );
20603: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20604: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 20605: my (%by_ip,%by_location,@intdoms,@instdoms);
20606: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 20607: my @locations = sort(keys(%by_location));
1.137 raeburn 20608: my (%defaultshash,%changes);
20609: foreach my $prefix (@prefixes) {
20610: $defaultshash{'usersessions'}{$prefix} = {};
20611: }
1.212 raeburn 20612: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20613: my $resulttext;
1.138 raeburn 20614: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20615: foreach my $prefix (@prefixes) {
1.145 raeburn 20616: next if ($prefix eq 'spares');
20617: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20618: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20619: if ($type eq 'version') {
20620: my $value = $env{'form.'.$prefix.'_'.$type};
20621: my $okvalue;
20622: if ($value ne '') {
20623: if (grep(/^\Q$value\E$/,@lcversions)) {
20624: $okvalue = $value;
20625: }
20626: }
20627: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20628: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20629: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20630: if ($inuse == 0) {
20631: $changes{$prefix}{$type} = 1;
20632: } else {
20633: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20634: $changes{$prefix}{$type} = 1;
20635: }
20636: if ($okvalue ne '') {
20637: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20638: }
20639: }
20640: } else {
20641: if (($inuse == 1) && ($okvalue ne '')) {
20642: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20643: $changes{$prefix}{$type} = 1;
20644: }
20645: }
20646: } else {
20647: if (($inuse == 1) && ($okvalue ne '')) {
20648: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20649: $changes{$prefix}{$type} = 1;
20650: }
20651: }
20652: } else {
20653: if (($inuse == 1) && ($okvalue ne '')) {
20654: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20655: $changes{$prefix}{$type} = 1;
20656: }
20657: }
20658: } else {
20659: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20660: my @okvals;
20661: foreach my $val (@vals) {
1.138 raeburn 20662: if ($val =~ /:/) {
20663: my @items = split(/:/,$val);
20664: foreach my $item (@items) {
20665: if (ref($by_location{$item}) eq 'ARRAY') {
20666: push(@okvals,$item);
20667: }
20668: }
20669: } else {
20670: if (ref($by_location{$val}) eq 'ARRAY') {
20671: push(@okvals,$val);
20672: }
1.137 raeburn 20673: }
20674: }
20675: @okvals = sort(@okvals);
20676: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20677: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20678: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20679: if ($inuse == 0) {
20680: $changes{$prefix}{$type} = 1;
20681: } else {
20682: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20683: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20684: if (@changed > 0) {
20685: $changes{$prefix}{$type} = 1;
20686: }
20687: }
20688: } else {
20689: if ($inuse == 1) {
20690: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20691: $changes{$prefix}{$type} = 1;
20692: }
20693: }
20694: } else {
20695: if ($inuse == 1) {
20696: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20697: $changes{$prefix}{$type} = 1;
20698: }
20699: }
20700: } else {
20701: if ($inuse == 1) {
20702: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20703: $changes{$prefix}{$type} = 1;
20704: }
20705: }
20706: }
20707: }
20708: }
1.145 raeburn 20709:
20710: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20711: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20712: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20713: my $savespares;
20714:
20715: foreach my $lonhost (sort(keys(%servers))) {
20716: my $serverhomeID =
20717: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20718: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20719: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20720: my %spareschg;
20721: foreach my $type (@{$types{'spares'}}) {
20722: my @okspares;
20723: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20724: foreach my $server (@checked) {
1.152 raeburn 20725: if (&Apache::lonnet::hostname($server) ne '') {
20726: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20727: unless (grep(/^\Q$server\E$/,@okspares)) {
20728: push(@okspares,$server);
20729: }
1.145 raeburn 20730: }
20731: }
20732: }
20733: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20734: my $newspare;
1.152 raeburn 20735: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20736: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20737: $newspare = $new;
20738: }
20739: }
1.152 raeburn 20740: my @spares;
20741: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20742: @spares = sort(@okspares,$newspare);
20743: } else {
20744: @spares = sort(@okspares);
20745: }
20746: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20747: if (ref($spareid{$lonhost}) eq 'HASH') {
20748: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20749: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20750: if (@diffs > 0) {
20751: $spareschg{$type} = 1;
20752: }
20753: }
20754: }
20755: }
20756: if (keys(%spareschg) > 0) {
20757: $changes{'spares'}{$lonhost} = \%spareschg;
20758: }
20759: }
1.261 raeburn 20760: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 20761: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 20762: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20763: my @okoffload;
20764: if (@offloadnow) {
20765: foreach my $server (@offloadnow) {
20766: if (&Apache::lonnet::hostname($server) ne '') {
20767: unless (grep(/^\Q$server\E$/,@okoffload)) {
20768: push(@okoffload,$server);
20769: }
20770: }
20771: }
20772: if (@okoffload) {
20773: foreach my $lonhost (@okoffload) {
20774: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20775: }
20776: }
20777: }
1.371 raeburn 20778: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20779: my @okoffloadoth;
20780: if (@offloadoth) {
20781: foreach my $server (@offloadoth) {
20782: if (&Apache::lonnet::hostname($server) ne '') {
20783: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20784: push(@okoffloadoth,$server);
20785: }
20786: }
20787: }
20788: if (@okoffloadoth) {
20789: foreach my $lonhost (@okoffloadoth) {
20790: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20791: }
20792: }
20793: }
1.145 raeburn 20794: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20795: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20796: if (ref($changes{'spares'}) eq 'HASH') {
20797: if (keys(%{$changes{'spares'}}) > 0) {
20798: $savespares = 1;
20799: }
20800: }
20801: } else {
20802: $savespares = 1;
20803: }
1.371 raeburn 20804: foreach my $offload ('offloadnow','offloadoth') {
20805: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20806: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20807: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20808: $changes{$offload} = 1;
20809: last;
20810: }
1.261 raeburn 20811: }
1.371 raeburn 20812: unless ($changes{$offload}) {
20813: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20814: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20815: $changes{$offload} = 1;
20816: last;
20817: }
1.261 raeburn 20818: }
20819: }
1.371 raeburn 20820: } else {
20821: if (($offload eq 'offloadnow') && (@okoffload)) {
20822: $changes{'offloadnow'} = 1;
20823: }
20824: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20825: $changes{'offloadoth'} = 1;
20826: }
20827: }
20828: }
20829: } else {
20830: if (@okoffload) {
1.261 raeburn 20831: $changes{'offloadnow'} = 1;
20832: }
1.371 raeburn 20833: if (@okoffloadoth) {
20834: $changes{'offloadoth'} = 1;
20835: }
1.145 raeburn 20836: }
1.147 raeburn 20837: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20838: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20839: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20840: $dom);
20841: if ($putresult eq 'ok') {
20842: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20843: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20844: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20845: }
20846: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20847: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20848: }
1.261 raeburn 20849: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20850: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20851: }
1.371 raeburn 20852: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20853: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20854: }
1.137 raeburn 20855: }
20856: my $cachetime = 24*60*60;
20857: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20858: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20859: if (ref($lastactref) eq 'HASH') {
20860: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20861: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20862: }
1.147 raeburn 20863: if (keys(%changes) > 0) {
20864: my %lt = &usersession_titles();
20865: $resulttext = &mt('Changes made:').'<ul>';
20866: foreach my $prefix (@prefixes) {
20867: if (ref($changes{$prefix}) eq 'HASH') {
20868: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20869: if ($prefix eq 'spares') {
20870: if (ref($changes{$prefix}) eq 'HASH') {
20871: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20872: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20873: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20874: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20875: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20876: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20877: foreach my $type (@{$types{$prefix}}) {
20878: if ($changes{$prefix}{$lonhost}{$type}) {
20879: my $offloadto = &mt('None');
20880: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20881: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20882: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20883: }
1.145 raeburn 20884: }
1.147 raeburn 20885: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20886: }
1.137 raeburn 20887: }
20888: }
1.147 raeburn 20889: $resulttext .= '</li>';
1.137 raeburn 20890: }
20891: }
1.147 raeburn 20892: } else {
20893: foreach my $type (@{$types{$prefix}}) {
20894: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 20895: my ($newvalue,$notinuse);
1.147 raeburn 20896: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20897: if (ref($defaultshash{'usersessions'}{$prefix})) {
20898: if ($type eq 'version') {
20899: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 20900: } else {
20901: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20902: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20903: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20904: }
20905: } else {
20906: $notinuse = 1;
1.147 raeburn 20907: }
1.145 raeburn 20908: }
20909: }
20910: }
1.147 raeburn 20911: if ($newvalue eq '') {
20912: if ($type eq 'version') {
20913: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 20914: } elsif ($notinuse) {
20915: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 20916: } else {
20917: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20918: }
1.145 raeburn 20919: } else {
1.147 raeburn 20920: if ($type eq 'version') {
1.344 raeburn 20921: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20922: }
20923: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20924: }
1.137 raeburn 20925: }
20926: }
20927: }
1.147 raeburn 20928: $resulttext .= '</ul>';
1.137 raeburn 20929: }
20930: }
1.261 raeburn 20931: if ($changes{'offloadnow'}) {
20932: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20933: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 20934: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 20935: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20936: $resulttext .= '<li>'.$lonhost.'</li>';
20937: }
20938: $resulttext .= '</ul>';
20939: } else {
1.371 raeburn 20940: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20941: }
20942: } else {
20943: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20944: }
20945: }
20946: if ($changes{'offloadoth'}) {
20947: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20948: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20949: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20950: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20951: $resulttext .= '<li>'.$lonhost.'</li>';
20952: }
20953: $resulttext .= '</ul>';
20954: } else {
20955: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 20956: }
20957: } else {
1.371 raeburn 20958: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 20959: }
20960: }
1.147 raeburn 20961: $resulttext .= '</ul>';
20962: } else {
20963: $resulttext = $nochgmsg;
1.137 raeburn 20964: }
20965: } else {
20966: $resulttext = '<span class="LC_error">'.
20967: &mt('An error occurred: [_1]',$putresult).'</span>';
20968: }
20969: } else {
1.147 raeburn 20970: $resulttext = $nochgmsg;
1.137 raeburn 20971: }
20972: return $resulttext;
20973: }
20974:
1.275 raeburn 20975: sub modify_ssl {
20976: my ($dom,$lastactref,%domconfig) = @_;
20977: my (%by_ip,%by_location,@intdoms,@instdoms);
20978: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
20979: my @locations = sort(keys(%by_location));
20980: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20981: my (%defaultshash,%changes);
20982: my $action = 'ssl';
1.293 raeburn 20983: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 20984: foreach my $prefix (@prefixes) {
20985: $defaultshash{$action}{$prefix} = {};
20986: }
20987: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20988: my $resulttext;
20989: my %iphost = &Apache::lonnet::get_iphost();
20990: my @reptypes = ('certreq','nocertreq');
20991: my @connecttypes = ('dom','intdom','other');
20992: my %types = (
1.293 raeburn 20993: connto => \@connecttypes,
20994: connfrom => \@connecttypes,
20995: replication => \@reptypes,
1.275 raeburn 20996: );
20997: foreach my $prefix (sort(keys(%types))) {
20998: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 20999: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21000: my $value = 'yes';
21001: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21002: $value = $env{'form.'.$prefix.'_'.$type};
21003: }
1.335 raeburn 21004: if (ref($domconfig{$action}) eq 'HASH') {
21005: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21006: if ($domconfig{$action}{$prefix}{$type} ne '') {
21007: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21008: $changes{$prefix}{$type} = 1;
21009: }
21010: $defaultshash{$action}{$prefix}{$type} = $value;
21011: } else {
21012: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21013: $changes{$prefix}{$type} = 1;
21014: }
21015: } else {
21016: $defaultshash{$action}{$prefix}{$type} = $value;
21017: $changes{$prefix}{$type} = 1;
21018: }
21019: } else {
21020: $defaultshash{$action}{$prefix}{$type} = $value;
21021: $changes{$prefix}{$type} = 1;
21022: }
21023: if (($type eq 'dom') && (keys(%servers) == 1)) {
21024: delete($changes{$prefix}{$type});
21025: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21026: delete($changes{$prefix}{$type});
21027: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21028: delete($changes{$prefix}{$type});
21029: }
21030: } elsif ($prefix eq 'replication') {
21031: if (@locations > 0) {
21032: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21033: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21034: my @okvals;
21035: foreach my $val (@vals) {
21036: if ($val =~ /:/) {
21037: my @items = split(/:/,$val);
21038: foreach my $item (@items) {
21039: if (ref($by_location{$item}) eq 'ARRAY') {
21040: push(@okvals,$item);
21041: }
21042: }
21043: } else {
21044: if (ref($by_location{$val}) eq 'ARRAY') {
21045: push(@okvals,$val);
21046: }
21047: }
21048: }
21049: @okvals = sort(@okvals);
21050: if (ref($domconfig{$action}) eq 'HASH') {
21051: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21052: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21053: if ($inuse == 0) {
21054: $changes{$prefix}{$type} = 1;
21055: } else {
21056: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21057: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21058: if (@changed > 0) {
21059: $changes{$prefix}{$type} = 1;
21060: }
21061: }
21062: } else {
21063: if ($inuse == 1) {
21064: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21065: $changes{$prefix}{$type} = 1;
21066: }
21067: }
21068: } else {
21069: if ($inuse == 1) {
21070: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21071: $changes{$prefix}{$type} = 1;
21072: }
21073: }
21074: } else {
21075: if ($inuse == 1) {
21076: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21077: $changes{$prefix}{$type} = 1;
21078: }
21079: }
21080: }
21081: }
21082: }
21083: }
1.336 raeburn 21084: if (keys(%changes)) {
21085: foreach my $prefix (keys(%changes)) {
21086: if (ref($changes{$prefix}) eq 'HASH') {
21087: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21088: delete($changes{$prefix});
21089: }
21090: } else {
21091: delete($changes{$prefix});
21092: }
21093: }
21094: }
1.275 raeburn 21095: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21096: if (keys(%changes) > 0) {
21097: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21098: $dom);
21099: if ($putresult eq 'ok') {
21100: if (ref($defaultshash{$action}) eq 'HASH') {
21101: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21102: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21103: }
1.293 raeburn 21104: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21105: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21106: }
21107: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21108: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21109: }
21110: }
21111: my $cachetime = 24*60*60;
21112: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21113: if (ref($lastactref) eq 'HASH') {
21114: $lastactref->{'domdefaults'} = 1;
21115: }
21116: if (keys(%changes) > 0) {
21117: my %titles = &ssl_titles();
21118: $resulttext = &mt('Changes made:').'<ul>';
21119: foreach my $prefix (@prefixes) {
21120: if (ref($changes{$prefix}) eq 'HASH') {
21121: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21122: foreach my $type (@{$types{$prefix}}) {
21123: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21124: my ($newvalue,$notinuse);
1.275 raeburn 21125: if (ref($defaultshash{$action}) eq 'HASH') {
21126: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21127: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21128: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21129: } else {
21130: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21131: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21132: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21133: }
21134: } else {
21135: $notinuse = 1;
1.275 raeburn 21136: }
21137: }
21138: }
1.344 raeburn 21139: if ($notinuse) {
21140: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21141: } elsif ($newvalue eq '') {
1.275 raeburn 21142: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21143: } else {
21144: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21145: }
21146: }
21147: }
21148: }
21149: $resulttext .= '</ul>';
21150: }
21151: }
21152: } else {
21153: $resulttext = $nochgmsg;
21154: }
21155: } else {
21156: $resulttext = '<span class="LC_error">'.
21157: &mt('An error occurred: [_1]',$putresult).'</span>';
21158: }
21159: } else {
21160: $resulttext = $nochgmsg;
21161: }
21162: return $resulttext;
21163: }
21164:
1.279 raeburn 21165: sub modify_trust {
21166: my ($dom,$lastactref,%domconfig) = @_;
21167: my (%by_ip,%by_location,@intdoms,@instdoms);
21168: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21169: my @locations = sort(keys(%by_location));
21170: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21171: my @types = ('exc','inc');
21172: my (%defaultshash,%changes);
21173: foreach my $prefix (@prefixes) {
21174: $defaultshash{'trust'}{$prefix} = {};
21175: }
21176: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21177: my $resulttext;
21178: foreach my $prefix (@prefixes) {
21179: foreach my $type (@types) {
21180: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21181: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21182: my @okvals;
21183: foreach my $val (@vals) {
21184: if ($val =~ /:/) {
21185: my @items = split(/:/,$val);
21186: foreach my $item (@items) {
21187: if (ref($by_location{$item}) eq 'ARRAY') {
21188: push(@okvals,$item);
21189: }
21190: }
21191: } else {
21192: if (ref($by_location{$val}) eq 'ARRAY') {
21193: push(@okvals,$val);
21194: }
21195: }
21196: }
21197: @okvals = sort(@okvals);
21198: if (ref($domconfig{'trust'}) eq 'HASH') {
21199: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21200: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21201: if ($inuse == 0) {
21202: $changes{$prefix}{$type} = 1;
21203: } else {
21204: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21205: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
21206: if (@changed > 0) {
21207: $changes{$prefix}{$type} = 1;
21208: }
21209: }
21210: } else {
21211: if ($inuse == 1) {
21212: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21213: $changes{$prefix}{$type} = 1;
21214: }
21215: }
21216: } else {
21217: if ($inuse == 1) {
21218: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21219: $changes{$prefix}{$type} = 1;
21220: }
21221: }
21222: } else {
21223: if ($inuse == 1) {
21224: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21225: $changes{$prefix}{$type} = 1;
21226: }
21227: }
21228: }
21229: }
21230: my $nochgmsg = &mt('No changes made to trust settings.');
21231: if (keys(%changes) > 0) {
21232: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21233: $dom);
21234: if ($putresult eq 'ok') {
21235: if (ref($defaultshash{'trust'}) eq 'HASH') {
21236: foreach my $prefix (@prefixes) {
21237: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
21238: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
21239: }
21240: }
21241: }
21242: my $cachetime = 24*60*60;
21243: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21244: if (ref($lastactref) eq 'HASH') {
21245: $lastactref->{'domdefaults'} = 1;
21246: }
21247: if (keys(%changes) > 0) {
21248: my %lt = &trust_titles();
21249: $resulttext = &mt('Changes made:').'<ul>';
21250: foreach my $prefix (@prefixes) {
21251: if (ref($changes{$prefix}) eq 'HASH') {
21252: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21253: foreach my $type (@types) {
21254: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21255: my ($newvalue,$notinuse);
1.279 raeburn 21256: if (ref($defaultshash{'trust'}) eq 'HASH') {
21257: if (ref($defaultshash{'trust'}{$prefix})) {
21258: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21259: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
21260: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
21261: }
1.344 raeburn 21262: } else {
21263: $notinuse = 1;
1.279 raeburn 21264: }
21265: }
21266: }
1.344 raeburn 21267: if ($notinuse) {
21268: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
21269: } elsif ($newvalue eq '') {
1.279 raeburn 21270: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21271: } else {
21272: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
21273: }
21274: }
21275: }
21276: $resulttext .= '</ul>';
21277: }
21278: }
21279: $resulttext .= '</ul>';
21280: } else {
21281: $resulttext = $nochgmsg;
21282: }
21283: } else {
21284: $resulttext = '<span class="LC_error">'.
21285: &mt('An error occurred: [_1]',$putresult).'</span>';
21286: }
21287: } else {
21288: $resulttext = $nochgmsg;
21289: }
21290: return $resulttext;
21291: }
21292:
1.150 raeburn 21293: sub modify_loadbalancing {
21294: my ($dom,%domconfig) = @_;
21295: my $primary_id = &Apache::lonnet::domain($dom,'primary');
21296: my $intdom = &Apache::lonnet::internet_dom($primary_id);
21297: my ($othertitle,$usertypes,$types) =
21298: &Apache::loncommon::sorted_inst_types($dom);
21299: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 21300: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 21301: my @sparestypes = ('primary','default');
21302: my %typetitles = &sparestype_titles();
21303: my $resulttext;
1.342 raeburn 21304: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21305: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21306: %existing = %{$domconfig{'loadbalancing'}};
21307: }
21308: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 21309: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 21310: my ($saveloadbalancing,%defaultshash,%changes);
21311: my ($alltypes,$othertypes,$titles) =
21312: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
21313: my %ruletitles = &offloadtype_text();
21314: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
21315: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
21316: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
21317: if ($balancer eq '') {
21318: next;
21319: }
1.210 raeburn 21320: if (!exists($servers{$balancer})) {
1.171 raeburn 21321: if (exists($currbalancer{$balancer})) {
21322: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 21323: }
1.171 raeburn 21324: next;
21325: }
21326: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
21327: push(@{$changes{'delete'}},$balancer);
21328: next;
21329: }
21330: if (!exists($currbalancer{$balancer})) {
21331: push(@{$changes{'add'}},$balancer);
21332: }
21333: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
21334: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
21335: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
21336: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21337: $saveloadbalancing = 1;
21338: }
21339: foreach my $sparetype (@sparestypes) {
21340: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
21341: my @offloadto;
21342: foreach my $target (@targets) {
21343: if (($servers{$target}) && ($target ne $balancer)) {
21344: if ($sparetype eq 'default') {
21345: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
21346: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 21347: }
21348: }
1.171 raeburn 21349: unless(grep(/^\Q$target\E$/,@offloadto)) {
21350: push(@offloadto,$target);
21351: }
1.150 raeburn 21352: }
21353: }
1.284 raeburn 21354: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
21355: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
21356: push(@offloadto,$balancer);
21357: }
21358: }
21359: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 21360: }
1.342 raeburn 21361: if ($env{'form.loadbalancing_cookie_'.$i}) {
21362: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
21363: if (exists($currbalancer{$balancer})) {
21364: unless ($currcookies{$balancer}) {
21365: $changes{'curr'}{$balancer}{'cookie'} = 1;
21366: }
21367: }
21368: } elsif (exists($currbalancer{$balancer})) {
21369: if ($currcookies{$balancer}) {
21370: $changes{'curr'}{$balancer}{'cookie'} = 1;
21371: }
21372: }
1.171 raeburn 21373: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 21374: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21375: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
21376: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 21377: if (@targetdiffs > 0) {
1.171 raeburn 21378: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21379: }
1.171 raeburn 21380: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21381: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21382: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21383: }
21384: }
21385: }
21386: } else {
1.171 raeburn 21387: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 21388: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21389: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21390: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21391: $changes{'curr'}{$balancer}{'targets'} = 1;
21392: }
1.150 raeburn 21393: }
21394: }
1.210 raeburn 21395: }
1.150 raeburn 21396: }
21397: my $ishomedom;
1.171 raeburn 21398: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
21399: $ishomedom = 1;
1.150 raeburn 21400: }
21401: if (ref($alltypes) eq 'ARRAY') {
21402: foreach my $type (@{$alltypes}) {
21403: my $rule;
1.210 raeburn 21404: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 21405: (!$ishomedom)) {
1.171 raeburn 21406: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
21407: }
21408: if ($rule eq 'specific') {
1.255 raeburn 21409: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 21410: if (exists($servers{$specifiedhost})) {
1.255 raeburn 21411: $rule = $specifiedhost;
21412: }
1.150 raeburn 21413: }
1.171 raeburn 21414: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
21415: if (ref($currrules{$balancer}) eq 'HASH') {
21416: if ($rule ne $currrules{$balancer}{$type}) {
21417: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21418: }
21419: } elsif ($rule ne '') {
1.171 raeburn 21420: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21421: }
21422: }
21423: }
1.171 raeburn 21424: }
21425: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
21426: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
21427: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
21428: $defaultshash{'loadbalancing'} = {};
21429: }
21430: my $putresult = &Apache::lonnet::put_dom('configuration',
21431: \%defaultshash,$dom);
21432: if ($putresult eq 'ok') {
21433: if (keys(%changes) > 0) {
1.252 raeburn 21434: my %toupdate;
1.171 raeburn 21435: if (ref($changes{'delete'}) eq 'ARRAY') {
21436: foreach my $balancer (sort(@{$changes{'delete'}})) {
21437: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 21438: $toupdate{$balancer} = 1;
1.150 raeburn 21439: }
1.171 raeburn 21440: }
21441: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 21442: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 21443: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 21444: $toupdate{$balancer} = 1;
1.171 raeburn 21445: }
21446: }
21447: if (ref($changes{'curr'}) eq 'HASH') {
21448: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 21449: $toupdate{$balancer} = 1;
1.171 raeburn 21450: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
21451: if ($changes{'curr'}{$balancer}{'targets'}) {
21452: my %offloadstr;
21453: foreach my $sparetype (@sparestypes) {
21454: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21455: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21456: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21457: }
21458: }
1.150 raeburn 21459: }
1.171 raeburn 21460: if (keys(%offloadstr) == 0) {
21461: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 21462: } else {
1.171 raeburn 21463: my $showoffload;
21464: foreach my $sparetype (@sparestypes) {
21465: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
21466: if (defined($offloadstr{$sparetype})) {
21467: $showoffload .= $offloadstr{$sparetype};
21468: } else {
21469: $showoffload .= &mt('None');
21470: }
21471: $showoffload .= (' 'x3);
21472: }
21473: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 21474: }
21475: }
21476: }
1.171 raeburn 21477: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
21478: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
21479: foreach my $type (@{$alltypes}) {
21480: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
21481: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21482: my $balancetext;
21483: if ($rule eq '') {
21484: $balancetext = $ruletitles{'default'};
1.209 raeburn 21485: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 21486: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 21487: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 21488: foreach my $sparetype (@sparestypes) {
21489: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21490: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21491: }
21492: }
1.253 raeburn 21493: foreach my $item (@{$alltypes}) {
21494: next if ($item =~ /^_LC_ipchange/);
21495: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
21496: if ($hasrule eq 'homeserver') {
21497: map { $toupdate{$_} = 1; } (keys(%libraryservers));
21498: } else {
21499: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
21500: if ($servers{$hasrule}) {
21501: $toupdate{$hasrule} = 1;
21502: }
21503: }
21504: }
21505: }
1.254 raeburn 21506: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
21507: $balancetext = $ruletitles{$rule};
21508: } else {
21509: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21510: $balancetext = $ruletitles{'particular'}.' '.$receiver;
21511: if ($receiver) {
21512: $toupdate{$receiver};
21513: }
21514: }
21515: } else {
21516: $balancetext = $ruletitles{$rule};
1.252 raeburn 21517: }
1.171 raeburn 21518: } else {
21519: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
21520: }
1.210 raeburn 21521: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 21522: }
21523: }
21524: }
21525: }
1.342 raeburn 21526: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 ! raeburn 21527: if ($currcookies{$balancer}) {
! 21528: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
! 21529: $balancer).'</li>';
! 21530: } else {
! 21531: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
! 21532: $balancer).'</li>';
! 21533: }
1.342 raeburn 21534: }
1.375 raeburn 21535: }
21536: }
21537: if (keys(%toupdate)) {
21538: my %thismachine;
21539: my $updatedhere;
21540: my $cachetime = 60*60*24;
21541: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
21542: foreach my $lonhost (keys(%toupdate)) {
21543: if ($thismachine{$lonhost}) {
21544: unless ($updatedhere) {
21545: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
21546: $defaultshash{'loadbalancing'},
21547: $cachetime);
21548: $updatedhere = 1;
1.252 raeburn 21549: }
1.375 raeburn 21550: } else {
21551: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
21552: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 21553: }
1.150 raeburn 21554: }
1.171 raeburn 21555: }
21556: if ($resulttext ne '') {
21557: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 21558: } else {
21559: $resulttext = $nochgmsg;
21560: }
21561: } else {
1.171 raeburn 21562: $resulttext = $nochgmsg;
1.150 raeburn 21563: }
21564: } else {
1.171 raeburn 21565: $resulttext = '<span class="LC_error">'.
21566: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 21567: }
21568: } else {
1.171 raeburn 21569: $resulttext = $nochgmsg;
1.150 raeburn 21570: }
21571: return $resulttext;
21572: }
21573:
1.48 raeburn 21574: sub recurse_check {
21575: my ($chkcats,$categories,$depth,$name) = @_;
21576: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
21577: my $chg = 0;
21578: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
21579: my $category = $chkcats->[$depth]{$name}[$j];
21580: my $item;
21581: if ($category eq '') {
21582: $chg ++;
21583: } else {
21584: my $deeper = $depth + 1;
21585: $item = &escape($category).':'.&escape($name).':'.$depth;
21586: if ($chg) {
21587: $categories->{$item} -= $chg;
21588: }
21589: &recurse_check($chkcats,$categories,$deeper,$category);
21590: $deeper --;
21591: }
21592: }
21593: }
21594: return;
21595: }
21596:
21597: sub recurse_cat_deletes {
21598: my ($item,$coursecategories,$deletions) = @_;
21599: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
21600: my $subdepth = $depth + 1;
21601: if (ref($coursecategories) eq 'HASH') {
21602: foreach my $subitem (keys(%{$coursecategories})) {
21603: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
21604: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
21605: delete($coursecategories->{$subitem});
21606: $deletions->{$subitem} = 1;
21607: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 21608: }
1.48 raeburn 21609: }
21610: }
21611: return;
21612: }
21613:
1.125 raeburn 21614: sub active_dc_picker {
1.191 raeburn 21615: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 21616: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 21617: my @domcoord = keys(%domcoords);
21618: if (keys(%currhash)) {
21619: foreach my $dc (keys(%currhash)) {
21620: unless (exists($domcoords{$dc})) {
21621: push(@domcoord,$dc);
21622: }
21623: }
21624: }
21625: @domcoord = sort(@domcoord);
1.210 raeburn 21626: my $numdcs = scalar(@domcoord);
1.191 raeburn 21627: my $rows = 0;
21628: my $table;
1.125 raeburn 21629: if ($numdcs > 1) {
1.191 raeburn 21630: $table = '<table>';
21631: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 21632: my $rem = $i%($numinrow);
21633: if ($rem == 0) {
21634: if ($i > 0) {
1.191 raeburn 21635: $table .= '</tr>';
1.125 raeburn 21636: }
1.191 raeburn 21637: $table .= '<tr>';
21638: $rows ++;
1.125 raeburn 21639: }
1.191 raeburn 21640: my $check = '';
21641: if ($inputtype eq 'radio') {
21642: if (keys(%currhash) == 0) {
21643: if (!$i) {
21644: $check = ' checked="checked"';
21645: }
21646: } elsif (exists($currhash{$domcoord[$i]})) {
21647: $check = ' checked="checked"';
21648: }
21649: } else {
21650: if (exists($currhash{$domcoord[$i]})) {
21651: $check = ' checked="checked"';
1.125 raeburn 21652: }
21653: }
1.191 raeburn 21654: if ($i == @domcoord - 1) {
1.125 raeburn 21655: my $colsleft = $numinrow - $rem;
21656: if ($colsleft > 1) {
1.191 raeburn 21657: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 21658: } else {
1.191 raeburn 21659: $table .= '<td class="LC_left_item">';
1.125 raeburn 21660: }
21661: } else {
1.191 raeburn 21662: $table .= '<td class="LC_left_item">';
21663: }
21664: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
21665: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
21666: $table .= '<span class="LC_nobreak"><label>'.
21667: '<input type="'.$inputtype.'" name="'.$name.'"'.
21668: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
21669: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 21670: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 21671: }
1.219 raeburn 21672: $table .= '</label></span></td>';
1.191 raeburn 21673: }
21674: $table .= '</tr></table>';
21675: } elsif ($numdcs == 1) {
1.219 raeburn 21676: my ($dcname,$dcdom) = split(':',$domcoord[0]);
21677: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 21678: if ($inputtype eq 'radio') {
1.247 raeburn 21679: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 21680: if ($user ne $dcname.':'.$dcdom) {
21681: $table .= ' ('.$dcname.':'.$dcdom.')';
21682: }
1.191 raeburn 21683: } else {
21684: my $check;
21685: if (exists($currhash{$domcoord[0]})) {
21686: $check = ' checked="checked"';
1.125 raeburn 21687: }
1.247 raeburn 21688: $table = '<span class="LC_nobreak"><label>'.
21689: '<input type="checkbox" name="'.$name.'" '.
21690: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 21691: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 21692: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 21693: }
1.220 raeburn 21694: $table .= '</label></span>';
1.191 raeburn 21695: $rows ++;
1.125 raeburn 21696: }
21697: }
1.191 raeburn 21698: return ($numdcs,$table,$rows);
1.125 raeburn 21699: }
21700:
1.137 raeburn 21701: sub usersession_titles {
21702: return &Apache::lonlocal::texthash(
21703: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
21704: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 21705: spares => 'Servers offloaded to, when busy',
1.137 raeburn 21706: version => 'LON-CAPA version requirement',
1.138 raeburn 21707: excludedomain => 'Allow all, but exclude specific domains',
21708: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 21709: primary => 'Primary (checked first)',
1.154 raeburn 21710: default => 'Default',
1.137 raeburn 21711: );
21712: }
21713:
1.152 raeburn 21714: sub id_for_thisdom {
21715: my (%servers) = @_;
21716: my %altids;
21717: foreach my $server (keys(%servers)) {
21718: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21719: if ($serverhome ne $server) {
21720: $altids{$serverhome} = $server;
21721: }
21722: }
21723: return %altids;
21724: }
21725:
1.150 raeburn 21726: sub count_servers {
21727: my ($currbalancer,%servers) = @_;
21728: my (@spares,$numspares);
21729: foreach my $lonhost (sort(keys(%servers))) {
21730: next if ($currbalancer eq $lonhost);
21731: push(@spares,$lonhost);
21732: }
21733: if ($currbalancer) {
21734: $numspares = scalar(@spares);
21735: } else {
21736: $numspares = scalar(@spares) - 1;
21737: }
21738: return ($numspares,@spares);
21739: }
21740:
21741: sub lonbalance_targets_js {
1.171 raeburn 21742: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21743: my $select = &mt('Select');
21744: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21745: if (ref($servers) eq 'HASH') {
21746: $alltargets = join("','",sort(keys(%{$servers})));
21747: my @homedoms;
21748: foreach my $server (sort(keys(%{$servers}))) {
21749: if (&Apache::lonnet::host_domain($server) eq $dom) {
21750: push(@homedoms,'1');
21751: } else {
21752: push(@homedoms,'0');
21753: }
21754: }
21755: $allishome = join("','",@homedoms);
21756: }
21757: if (ref($types) eq 'ARRAY') {
21758: if (@{$types} > 0) {
21759: @alltypes = @{$types};
21760: }
21761: }
21762: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21763: $allinsttypes = join("','",@alltypes);
1.342 raeburn 21764: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21765: if (ref($settings) eq 'HASH') {
21766: %existing = %{$settings};
21767: }
21768: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 21769: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 21770: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21771: return <<"END";
21772:
21773: <script type="text/javascript">
21774: // <![CDATA[
21775:
1.171 raeburn 21776: currBalancers = new Array('$balancers');
21777:
21778: function toggleTargets(balnum) {
21779: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21780: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21781: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21782: var prevbalancer = prevhostitem.value;
21783: var baltotal = document.getElementById('loadbalancing_total').value;
21784: prevhostitem.value = balancer;
21785: if (prevbalancer != '') {
21786: var prevIdx = currBalancers.indexOf(prevbalancer);
21787: if (prevIdx != -1) {
21788: currBalancers.splice(prevIdx,1);
21789: }
21790: }
1.150 raeburn 21791: if (balancer == '') {
1.171 raeburn 21792: hideSpares(balnum);
1.150 raeburn 21793: } else {
1.171 raeburn 21794: var currIdx = currBalancers.indexOf(balancer);
21795: if (currIdx == -1) {
21796: currBalancers.push(balancer);
21797: }
1.150 raeburn 21798: var homedoms = new Array('$allishome');
1.171 raeburn 21799: var ishomedom = homedoms[lonhostitem.selectedIndex];
21800: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21801: }
1.171 raeburn 21802: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21803: return;
21804: }
21805:
1.171 raeburn 21806: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21807: var alltargets = new Array('$alltargets');
21808: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21809: var offloadtypes = new Array('primary','default');
21810:
1.171 raeburn 21811: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21812: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21813:
1.151 raeburn 21814: for (var i=0; i<offloadtypes.length; i++) {
21815: var count = 0;
21816: for (var j=0; j<alltargets.length; j++) {
21817: if (alltargets[j] != balancer) {
1.171 raeburn 21818: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21819: item.value = alltargets[j];
21820: item.style.textAlign='left';
21821: item.style.textFace='normal';
21822: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21823: if (currBalancers.indexOf(alltargets[j]) == -1) {
21824: item.disabled = '';
21825: } else {
21826: item.disabled = 'disabled';
21827: item.checked = false;
21828: }
1.151 raeburn 21829: count ++;
21830: }
1.150 raeburn 21831: }
21832: }
1.151 raeburn 21833: for (var k=0; k<insttypes.length; k++) {
21834: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21835: if (ishomedom == 1) {
1.171 raeburn 21836: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21837: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21838: } else {
1.171 raeburn 21839: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21840: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21841: }
21842: } else {
1.171 raeburn 21843: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21844: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21845: }
1.151 raeburn 21846: if ((insttypes[k] != '_LC_external') &&
21847: ((insttypes[k] != '_LC_internetdom') ||
21848: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21849: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21850: item.options.length = 0;
21851: item.options[0] = new Option("","",true,true);
1.210 raeburn 21852: var idx = 0;
1.151 raeburn 21853: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21854: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21855: idx ++;
21856: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21857: }
21858: }
21859: }
21860: }
21861: return;
21862: }
21863:
1.171 raeburn 21864: function hideSpares(balnum) {
1.150 raeburn 21865: var alltargets = new Array('$alltargets');
21866: var insttypes = new Array('$allinsttypes');
21867: var offloadtypes = new Array('primary','default');
21868:
1.171 raeburn 21869: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21870: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21871:
21872: var total = alltargets.length - 1;
21873: for (var i=0; i<offloadtypes; i++) {
21874: for (var j=0; j<total; j++) {
1.171 raeburn 21875: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21876: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21877: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21878: }
1.150 raeburn 21879: }
21880: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21881: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21882: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21883: if (insttypes[k] != '_LC_external') {
1.171 raeburn 21884: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21885: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21886: }
21887: }
21888: return;
21889: }
21890:
1.171 raeburn 21891: function checkOffloads(item,balnum,type) {
1.150 raeburn 21892: var alltargets = new Array('$alltargets');
21893: var offloadtypes = new Array('primary','default');
21894: if (item.checked) {
21895: var total = alltargets.length - 1;
21896: var other;
21897: if (type == offloadtypes[0]) {
1.151 raeburn 21898: other = offloadtypes[1];
1.150 raeburn 21899: } else {
1.151 raeburn 21900: other = offloadtypes[0];
1.150 raeburn 21901: }
21902: for (var i=0; i<total; i++) {
1.171 raeburn 21903: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21904: if (server == item.value) {
1.171 raeburn 21905: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21906: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21907: }
21908: }
21909: }
21910: }
21911: return;
21912: }
21913:
1.171 raeburn 21914: function singleServerToggle(balnum,type) {
21915: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21916: if (offloadtoSelIdx == 0) {
1.171 raeburn 21917: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21918: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21919:
21920: } else {
1.171 raeburn 21921: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21922: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21923: }
21924: return;
21925: }
21926:
1.171 raeburn 21927: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21928: if (type == '_LC_external') {
1.171 raeburn 21929: return;
1.150 raeburn 21930: }
1.171 raeburn 21931: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21932: for (var i=0; i<typesRules.length; i++) {
21933: if (formname.elements[typesRules[i]].checked) {
21934: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 21935: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21936: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21937: } else {
1.171 raeburn 21938: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21939: }
21940: }
21941: }
21942: return;
21943: }
21944:
21945: function balancerDeleteChange(balnum) {
21946: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21947: var baltotal = document.getElementById('loadbalancing_total').value;
21948: var addtarget;
21949: var removetarget;
21950: var action = 'delete';
21951: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21952: var lonhost = hostitem.value;
21953: var currIdx = currBalancers.indexOf(lonhost);
21954: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21955: if (currIdx != -1) {
21956: currBalancers.splice(currIdx,1);
21957: }
21958: addtarget = lonhost;
21959: } else {
21960: if (currIdx == -1) {
21961: currBalancers.push(lonhost);
21962: }
21963: removetarget = lonhost;
21964: action = 'undelete';
21965: }
21966: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21967: }
21968: return;
21969: }
21970:
21971: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21972: if (baltotal > 1) {
21973: var offloadtypes = new Array('primary','default');
21974: var alltargets = new Array('$alltargets');
21975: var insttypes = new Array('$allinsttypes');
21976: for (var i=0; i<baltotal; i++) {
21977: if (i != balnum) {
21978: for (var j=0; j<offloadtypes.length; j++) {
21979: var total = alltargets.length - 1;
21980: for (var k=0; k<total; k++) {
21981: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21982: var server = serveritem.value;
21983: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21984: if (server == addtarget) {
21985: serveritem.disabled = '';
21986: }
21987: }
21988: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21989: if (server == removetarget) {
21990: serveritem.disabled = 'disabled';
21991: serveritem.checked = false;
21992: }
21993: }
21994: }
21995: }
21996: for (var j=0; j<insttypes.length; j++) {
21997: if (insttypes[j] != '_LC_external') {
21998: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21999: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22000: var currSel = singleserver.selectedIndex;
22001: var currVal = singleserver.options[currSel].value;
22002: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22003: var numoptions = singleserver.options.length;
22004: var needsnew = 1;
22005: for (var k=0; k<numoptions; k++) {
22006: if (singleserver.options[k] == addtarget) {
22007: needsnew = 0;
22008: break;
22009: }
22010: }
22011: if (needsnew == 1) {
22012: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22013: }
22014: }
22015: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22016: singleserver.options.length = 0;
22017: if ((currVal) && (currVal != removetarget)) {
22018: singleserver.options[0] = new Option("","",false,false);
22019: } else {
22020: singleserver.options[0] = new Option("","",true,true);
22021: }
22022: var idx = 0;
22023: for (var m=0; m<alltargets.length; m++) {
22024: if (currBalancers.indexOf(alltargets[m]) == -1) {
22025: idx ++;
22026: if (currVal == alltargets[m]) {
22027: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22028: } else {
22029: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22030: }
22031: }
22032: }
22033: }
22034: }
22035: }
22036: }
1.150 raeburn 22037: }
22038: }
22039: }
22040: return;
22041: }
22042:
1.152 raeburn 22043: // ]]>
22044: </script>
22045:
22046: END
22047: }
22048:
1.372 raeburn 22049:
1.152 raeburn 22050: sub new_spares_js {
22051: my @sparestypes = ('primary','default');
22052: my $types = join("','",@sparestypes);
22053: my $select = &mt('Select');
22054: return <<"END";
22055:
22056: <script type="text/javascript">
22057: // <![CDATA[
22058:
22059: function updateNewSpares(formname,lonhost) {
22060: var types = new Array('$types');
22061: var include = new Array();
22062: var exclude = new Array();
22063: for (var i=0; i<types.length; i++) {
22064: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22065: for (var j=0; j<spareboxes.length; j++) {
22066: if (formname.elements[spareboxes[j]].checked) {
22067: exclude.push(formname.elements[spareboxes[j]].value);
22068: } else {
22069: include.push(formname.elements[spareboxes[j]].value);
22070: }
22071: }
22072: }
22073: for (var i=0; i<types.length; i++) {
22074: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22075: var selIdx = newSpare.selectedIndex;
22076: var currnew = newSpare.options[selIdx].value;
22077: var okSpares = new Array();
22078: for (var j=0; j<newSpare.options.length; j++) {
22079: var possible = newSpare.options[j].value;
22080: if (possible != '') {
22081: if (exclude.indexOf(possible) == -1) {
22082: okSpares.push(possible);
22083: } else {
22084: if (currnew == possible) {
22085: selIdx = 0;
22086: }
22087: }
22088: }
22089: }
22090: for (var k=0; k<include.length; k++) {
22091: if (okSpares.indexOf(include[k]) == -1) {
22092: okSpares.push(include[k]);
22093: }
22094: }
22095: okSpares.sort();
22096: newSpare.options.length = 0;
22097: if (selIdx == 0) {
22098: newSpare.options[0] = new Option("$select","",true,true);
22099: } else {
22100: newSpare.options[0] = new Option("$select","",false,false);
22101: }
22102: for (var m=0; m<okSpares.length; m++) {
22103: var idx = m+1;
22104: var selThis = 0;
22105: if (selIdx != 0) {
22106: if (okSpares[m] == currnew) {
22107: selThis = 1;
22108: }
22109: }
22110: if (selThis == 1) {
22111: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22112: } else {
22113: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22114: }
22115: }
22116: }
22117: return;
22118: }
22119:
22120: function checkNewSpares(lonhost,type) {
22121: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22122: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22123: if (chosen != '') {
1.152 raeburn 22124: var othertype;
22125: var othernewSpare;
22126: if (type == 'primary') {
22127: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22128: }
22129: if (type == 'default') {
22130: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22131: }
22132: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22133: othernewSpare.selectedIndex = 0;
22134: }
22135: }
22136: return;
22137: }
22138:
22139: // ]]>
22140: </script>
22141:
22142: END
22143:
22144: }
22145:
22146: sub common_domprefs_js {
22147: return <<"END";
22148:
22149: <script type="text/javascript">
22150: // <![CDATA[
22151:
1.150 raeburn 22152: function getIndicesByName(formname,item) {
1.152 raeburn 22153: var group = new Array();
1.150 raeburn 22154: for (var i=0;i<formname.elements.length;i++) {
22155: if (formname.elements[i].name == item) {
1.152 raeburn 22156: group.push(formname.elements[i].id);
1.150 raeburn 22157: }
22158: }
1.152 raeburn 22159: return group;
1.150 raeburn 22160: }
22161:
22162: // ]]>
22163: </script>
22164:
22165: END
1.152 raeburn 22166:
1.150 raeburn 22167: }
22168:
1.165 raeburn 22169: sub recaptcha_js {
22170: my %lt = &captcha_phrases();
22171: return <<"END";
22172:
22173: <script type="text/javascript">
22174: // <![CDATA[
22175:
22176: function updateCaptcha(caller,context) {
22177: var privitem;
22178: var pubitem;
22179: var privtext;
22180: var pubtext;
1.269 raeburn 22181: var versionitem;
22182: var versiontext;
1.165 raeburn 22183: if (document.getElementById(context+'_recaptchapub')) {
22184: pubitem = document.getElementById(context+'_recaptchapub');
22185: } else {
22186: return;
22187: }
22188: if (document.getElementById(context+'_recaptchapriv')) {
22189: privitem = document.getElementById(context+'_recaptchapriv');
22190: } else {
22191: return;
22192: }
22193: if (document.getElementById(context+'_recaptchapubtxt')) {
22194: pubtext = document.getElementById(context+'_recaptchapubtxt');
22195: } else {
22196: return;
22197: }
22198: if (document.getElementById(context+'_recaptchaprivtxt')) {
22199: privtext = document.getElementById(context+'_recaptchaprivtxt');
22200: } else {
22201: return;
22202: }
1.269 raeburn 22203: if (document.getElementById(context+'_recaptchaversion')) {
22204: versionitem = document.getElementById(context+'_recaptchaversion');
22205: } else {
22206: return;
22207: }
22208: if (document.getElementById(context+'_recaptchavertxt')) {
22209: versiontext = document.getElementById(context+'_recaptchavertxt');
22210: } else {
22211: return;
22212: }
1.165 raeburn 22213: if (caller.checked) {
22214: if (caller.value == 'recaptcha') {
22215: pubitem.type = 'text';
22216: privitem.type = 'text';
22217: pubitem.size = '40';
22218: privitem.size = '40';
22219: pubtext.innerHTML = "$lt{'pub'}";
22220: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 22221: versionitem.type = 'text';
22222: versionitem.size = '3';
1.289 raeburn 22223: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 22224: } else {
22225: pubitem.type = 'hidden';
22226: privitem.type = 'hidden';
1.269 raeburn 22227: versionitem.type = 'hidden';
1.165 raeburn 22228: pubtext.innerHTML = '';
22229: privtext.innerHTML = '';
1.269 raeburn 22230: versiontext.innerHTML = '';
1.165 raeburn 22231: }
22232: }
22233: return;
22234: }
22235:
22236: // ]]>
22237: </script>
22238:
22239: END
22240:
22241: }
22242:
1.236 raeburn 22243: sub toggle_display_js {
1.192 raeburn 22244: return <<"END";
22245:
22246: <script type="text/javascript">
22247: // <![CDATA[
22248:
1.236 raeburn 22249: function toggleDisplay(domForm,caller) {
22250: if (document.getElementById(caller)) {
22251: var divitem = document.getElementById(caller);
22252: var optionsElement = domForm.coursecredits;
1.264 raeburn 22253: var checkval = 1;
22254: var dispval = 'block';
1.303 raeburn 22255: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 22256: if (caller == 'emailoptions') {
1.372 raeburn 22257: optionsElement = domForm.cancreate_email;
1.236 raeburn 22258: }
1.257 raeburn 22259: if (caller == 'studentsubmission') {
22260: optionsElement = domForm.postsubmit;
22261: }
1.264 raeburn 22262: if (caller == 'cloneinstcode') {
22263: optionsElement = domForm.canclone;
22264: checkval = 'instcode';
22265: }
1.303 raeburn 22266: if (selfcreateRegExp.test(caller)) {
22267: optionsElement = domForm.elements[caller];
22268: checkval = 'other';
22269: dispval = 'inline'
22270: }
1.236 raeburn 22271: if (optionsElement.length) {
1.192 raeburn 22272: var currval;
1.236 raeburn 22273: for (var i=0; i<optionsElement.length; i++) {
22274: if (optionsElement[i].checked) {
22275: currval = optionsElement[i].value;
1.192 raeburn 22276: }
22277: }
1.264 raeburn 22278: if (currval == checkval) {
22279: divitem.style.display = dispval;
1.192 raeburn 22280: } else {
1.236 raeburn 22281: divitem.style.display = 'none';
1.192 raeburn 22282: }
22283: }
22284: }
22285: return;
22286: }
22287:
22288: // ]]>
22289: </script>
22290:
22291: END
22292:
22293: }
22294:
1.165 raeburn 22295: sub captcha_phrases {
22296: return &Apache::lonlocal::texthash (
22297: priv => 'Private key',
22298: pub => 'Public key',
22299: original => 'original (CAPTCHA)',
22300: recaptcha => 'successor (ReCAPTCHA)',
22301: notused => 'unused',
1.289 raeburn 22302: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 22303: );
22304: }
22305:
1.205 raeburn 22306: sub devalidate_remote_domconfs {
1.212 raeburn 22307: my ($dom,$cachekeys) = @_;
22308: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 22309: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22310: my %thismachine;
22311: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 22312: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.388 raeburn 22313: 'directorysrch','passwdconf','cats','proxyalias','proxysaml');
1.386 raeburn 22314: my %cache_by_lonhost;
22315: if (exists($cachekeys->{'samllanding'})) {
22316: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
22317: my %landing = %{$cachekeys->{'samllanding'}};
22318: my %domservers = &Apache::lonnet::get_servers($dom);
22319: if (keys(%domservers)) {
22320: foreach my $server (keys(%domservers)) {
22321: my @cached;
22322: next if ($thismachine{$server});
22323: if ($landing{$server}) {
22324: push(@cached,&escape('samllanding').':'.&escape($server));
22325: }
22326: if (@cached) {
22327: $cache_by_lonhost{$server} = \@cached;
22328: }
22329: }
22330: }
22331: }
22332: }
1.260 raeburn 22333: if (keys(%servers)) {
1.205 raeburn 22334: foreach my $server (keys(%servers)) {
22335: next if ($thismachine{$server});
1.212 raeburn 22336: my @cached;
22337: foreach my $name (@posscached) {
22338: if ($cachekeys->{$name}) {
1.388 raeburn 22339: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 22340: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 22341: foreach my $key (keys(%{$cachekeys->{$name}})) {
22342: push(@cached,&escape($name).':'.&escape($key));
22343: }
22344: }
22345: } else {
22346: push(@cached,&escape($name).':'.&escape($dom));
22347: }
1.212 raeburn 22348: }
22349: }
1.386 raeburn 22350: if ((exists($cache_by_lonhost{$server})) &&
22351: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
22352: push(@cached,@{$cache_by_lonhost{$server}});
22353: }
1.212 raeburn 22354: if (@cached) {
22355: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
22356: }
1.205 raeburn 22357: }
22358: }
22359: return;
22360: }
22361:
1.3 raeburn 22362: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>