Annotation of loncom/interface/domainprefs.pm, revision 1.391
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.391 ! raeburn 4: # $Id: domainprefs.pm,v 1.390 2021/11/22 22:19:58 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.1 raeburn 180:
1.155 raeburn 181: my $registered_cleanup;
182: my $modified_urls;
183:
1.1 raeburn 184: sub handler {
185: my $r=shift;
186: if ($r->header_only) {
187: &Apache::loncommon::content_type($r,'text/html');
188: $r->send_http_header;
189: return OK;
190: }
191:
1.91 raeburn 192: my $context = 'domain';
1.1 raeburn 193: my $dom = $env{'request.role.domain'};
1.5 albertel 194: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 195: if (&Apache::lonnet::allowed('mau',$dom)) {
196: &Apache::loncommon::content_type($r,'text/html');
197: $r->send_http_header;
198: } else {
199: $env{'user.error.msg'}=
200: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
201: return HTTP_NOT_ACCEPTABLE;
202: }
1.155 raeburn 203:
204: $registered_cleanup=0;
205: @{$modified_urls}=();
206:
1.1 raeburn 207: &Apache::lonhtmlcommon::clear_breadcrumbs();
208: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 209: ['phase','actions']);
1.30 raeburn 210: my $phase = 'pickactions';
1.3 raeburn 211: if ( exists($env{'form.phase'}) ) {
212: $phase = $env{'form.phase'};
213: }
1.150 raeburn 214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 215: my %domconfig =
1.6 raeburn 216: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 217: 'quotas','autoenroll','autoupdate','autocreate',
218: 'directorysrch','usercreation','usermodification',
219: 'contacts','defaults','scantron','coursecategories',
220: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 221: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 222: 'requestauthor','selfenrollment','inststatus',
1.372 raeburn 223: 'ltitools','ssl','trust','lti','privacy','passwords',
1.373 raeburn 224: 'proctoring','wafproxy'],$dom);
1.320 raeburn 225: my %encconfig =
1.384 raeburn 226: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$dom,undef,1);
1.297 raeburn 227: if (ref($domconfig{'ltitools'}) eq 'HASH') {
228: if (ref($encconfig{'ltitools'}) eq 'HASH') {
229: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 230: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
231: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 232: foreach my $item ('key','secret') {
233: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
234: }
235: }
236: }
237: }
238: }
1.320 raeburn 239: if (ref($domconfig{'lti'}) eq 'HASH') {
240: if (ref($encconfig{'lti'}) eq 'HASH') {
241: foreach my $id (keys(%{$domconfig{'lti'}})) {
242: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
243: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
244: foreach my $item ('key','secret') {
245: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
246: }
247: }
248: }
249: }
250: }
1.372 raeburn 251: if (ref($domconfig{'proctoring'}) eq 'HASH') {
252: if (ref($encconfig{'proctoring'}) eq 'HASH') {
253: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
254: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
255: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
256: foreach my $item ('key','secret') {
257: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
258: }
259: }
260: }
261: }
262: }
1.373 raeburn 263: my @prefs_order = ('rolecolors','login','defaults','wafproxy','passwords','quotas',
264: 'autoenroll','autoupdate','autocreate','directorysrch',
265: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 266: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 267: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 268: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
269: 'trust','lti');
1.171 raeburn 270: my %existing;
271: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
272: %existing = %{$domconfig{'loadbalancing'}};
273: }
274: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 275: push(@prefs_order,'loadbalancing');
276: }
1.30 raeburn 277: my %prefs = (
278: 'rolecolors' =>
279: { text => 'Default color schemes',
1.67 raeburn 280: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 281: header => [{col1 => 'Student Settings',
282: col2 => '',},
283: {col1 => 'Coordinator Settings',
284: col2 => '',},
285: {col1 => 'Author Settings',
286: col2 => '',},
287: {col1 => 'Administrator Settings',
288: col2 => '',}],
1.230 raeburn 289: print => \&print_rolecolors,
290: modify => \&modify_rolecolors,
1.30 raeburn 291: },
1.110 raeburn 292: 'login' =>
1.30 raeburn 293: { text => 'Log-in page options',
1.67 raeburn 294: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 295: header => [{col1 => 'Log-in Page Items',
296: col2 => '',},
297: {col1 => 'Log-in Help',
1.256 raeburn 298: col2 => 'Value'},
299: {col1 => 'Custom HTML in document head',
1.386 raeburn 300: col2 => 'Value'},
301: {col1 => 'SSO',
302: col2 => 'Dual login: SSO and non-SSO options'},
303: ],
1.230 raeburn 304: print => \&print_login,
305: modify => \&modify_login,
1.30 raeburn 306: },
1.43 raeburn 307: 'defaults' =>
1.236 raeburn 308: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 309: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 310: header => [{col1 => 'Setting',
1.236 raeburn 311: col2 => 'Value'},
312: {col1 => 'Institutional user types',
1.305 raeburn 313: col2 => 'Name displayed'}],
1.230 raeburn 314: print => \&print_defaults,
315: modify => \&modify_defaults,
1.43 raeburn 316: },
1.381 raeburn 317: 'wafproxy' =>
318: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 319: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 320: header => [{col1 => 'Domain(s)',
321: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 322: },
1.381 raeburn 323: {col1 => 'Domain(s)',
324: col2 => 'WAF Configuration',}],
1.373 raeburn 325: print => \&print_wafproxy,
1.381 raeburn 326: modify => \&modify_wafproxy,
1.373 raeburn 327: },
1.354 raeburn 328: 'passwords' =>
329: { text => 'Passwords (Internal authentication)',
330: help => 'Domain_Configuration_Passwords',
331: header => [{col1 => 'Resetting Forgotten Password',
332: col2 => 'Settings'},
333: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
334: col2 => 'Settings'},
335: {col1 => 'Rules for LON-CAPA Passwords',
336: col2 => 'Settings'},
337: {col1 => 'Course Owner Changing Student Passwords',
338: col2 => 'Settings'}],
339: print => \&print_passwords,
340: modify => \&modify_passwords,
341: },
1.30 raeburn 342: 'quotas' =>
1.197 raeburn 343: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 344: help => 'Domain_Configuration_Quotas',
1.77 raeburn 345: header => [{col1 => 'User affiliation',
1.72 raeburn 346: col2 => 'Available tools',
1.213 raeburn 347: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 348: print => \&print_quotas,
349: modify => \&modify_quotas,
1.30 raeburn 350: },
351: 'autoenroll' =>
352: { text => 'Auto-enrollment settings',
1.67 raeburn 353: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 354: header => [{col1 => 'Configuration setting',
355: col2 => 'Value(s)'}],
1.230 raeburn 356: print => \&print_autoenroll,
357: modify => \&modify_autoenroll,
1.30 raeburn 358: },
359: 'autoupdate' =>
360: { text => 'Auto-update settings',
1.67 raeburn 361: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 362: header => [{col1 => 'Setting',
363: col2 => 'Value',},
1.131 raeburn 364: {col1 => 'Setting',
365: col2 => 'Affiliation'},
1.43 raeburn 366: {col1 => 'User population',
1.227 bisitz 367: col2 => 'Updatable user data'}],
1.230 raeburn 368: print => \&print_autoupdate,
369: modify => \&modify_autoupdate,
1.30 raeburn 370: },
1.125 raeburn 371: 'autocreate' =>
372: { text => 'Auto-course creation settings',
373: help => 'Domain_Configuration_Auto_Creation',
374: header => [{col1 => 'Configuration Setting',
375: col2 => 'Value',}],
1.230 raeburn 376: print => \&print_autocreate,
377: modify => \&modify_autocreate,
1.125 raeburn 378: },
1.30 raeburn 379: 'directorysrch' =>
1.277 raeburn 380: { text => 'Directory searches',
1.67 raeburn 381: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 382: header => [{col1 => 'Institutional Directory Setting',
383: col2 => 'Value',},
384: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 385: col2 => 'Value',}],
1.230 raeburn 386: print => \&print_directorysrch,
387: modify => \&modify_directorysrch,
1.30 raeburn 388: },
389: 'contacts' =>
1.286 raeburn 390: { text => 'E-mail addresses and helpform',
1.67 raeburn 391: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 392: header => [{col1 => 'Default e-mail addresses',
393: col2 => 'Value',},
394: {col1 => 'Recipient(s) for notifications',
395: col2 => 'Value',},
1.340 raeburn 396: {col1 => 'Nightly status check e-mail',
397: col2 => 'Settings',},
1.286 raeburn 398: {col1 => 'Ask helpdesk form settings',
399: col2 => 'Value',},],
1.230 raeburn 400: print => \&print_contacts,
401: modify => \&modify_contacts,
1.30 raeburn 402: },
403: 'usercreation' =>
404: { text => 'User creation',
1.67 raeburn 405: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 406: header => [{col1 => 'Format rule type',
407: col2 => 'Format rules in force'},
1.34 raeburn 408: {col1 => 'User account creation',
409: col2 => 'Usernames which may be created',},
1.30 raeburn 410: {col1 => 'Context',
1.43 raeburn 411: col2 => 'Assignable authentication types'}],
1.230 raeburn 412: print => \&print_usercreation,
413: modify => \&modify_usercreation,
1.30 raeburn 414: },
1.224 raeburn 415: 'selfcreation' =>
416: { text => 'Users self-creating accounts',
417: help => 'Domain_Configuration_Self_Creation',
418: header => [{col1 => 'Self-creation with institutional username',
419: col2 => 'Enabled?'},
420: {col1 => 'Institutional user type (login/SSO self-creation)',
421: col2 => 'Information user can enter'},
1.303 raeburn 422: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 423: col2 => 'Settings'}],
1.230 raeburn 424: print => \&print_selfcreation,
425: modify => \&modify_selfcreation,
1.224 raeburn 426: },
1.69 raeburn 427: 'usermodification' =>
1.33 raeburn 428: { text => 'User modification',
1.67 raeburn 429: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 430: header => [{col1 => 'Target user has role',
1.227 bisitz 431: col2 => 'User information updatable in author context'},
1.33 raeburn 432: {col1 => 'Target user has role',
1.227 bisitz 433: col2 => 'User information updatable in course context'}],
1.230 raeburn 434: print => \&print_usermodification,
435: modify => \&modify_usermodification,
1.33 raeburn 436: },
1.69 raeburn 437: 'scantron' =>
1.346 raeburn 438: { text => 'Bubblesheet format',
1.67 raeburn 439: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 440: header => [ {col1 => 'Bubblesheet format file',
441: col2 => ''},
442: {col1 => 'Bubblesheet data upload formats',
443: col2 => 'Settings'}],
1.230 raeburn 444: print => \&print_scantron,
445: modify => \&modify_scantron,
1.46 raeburn 446: },
1.86 raeburn 447: 'requestcourses' =>
448: {text => 'Request creation of courses',
449: help => 'Domain_Configuration_Request_Courses',
450: header => [{col1 => 'User affiliation',
1.102 raeburn 451: col2 => 'Availability/Processing of requests',},
452: {col1 => 'Setting',
1.216 raeburn 453: col2 => 'Value'},
454: {col1 => 'Available textbooks',
1.235 raeburn 455: col2 => ''},
1.242 raeburn 456: {col1 => 'Available templates',
457: col2 => ''},
1.235 raeburn 458: {col1 => 'Validation (not official courses)',
459: col2 => 'Value'},],
1.230 raeburn 460: print => \&print_quotas,
461: modify => \&modify_quotas,
1.86 raeburn 462: },
1.163 raeburn 463: 'requestauthor' =>
1.223 bisitz 464: {text => 'Request Authoring Space',
1.163 raeburn 465: help => 'Domain_Configuration_Request_Author',
466: header => [{col1 => 'User affiliation',
467: col2 => 'Availability/Processing of requests',},
468: {col1 => 'Setting',
469: col2 => 'Value'}],
1.230 raeburn 470: print => \&print_quotas,
471: modify => \&modify_quotas,
1.163 raeburn 472: },
1.69 raeburn 473: 'coursecategories' =>
1.120 raeburn 474: { text => 'Cataloging of courses/communities',
1.67 raeburn 475: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 476: header => [{col1 => 'Catalog type/availability',
477: col2 => '',},
478: {col1 => 'Category settings for standard catalog',
1.57 raeburn 479: col2 => '',},
480: {col1 => 'Categories',
481: col2 => '',
482: }],
1.230 raeburn 483: print => \&print_coursecategories,
484: modify => \&modify_coursecategories,
1.69 raeburn 485: },
486: 'serverstatuses' =>
1.77 raeburn 487: {text => 'Access to server status pages',
1.69 raeburn 488: help => 'Domain_Configuration_Server_Status',
489: header => [{col1 => 'Status Page',
490: col2 => 'Other named users',
491: col3 => 'Specific IPs',
492: }],
1.230 raeburn 493: print => \&print_serverstatuses,
494: modify => \&modify_serverstatuses,
1.69 raeburn 495: },
1.118 jms 496: 'helpsettings' =>
1.282 raeburn 497: {text => 'Support settings',
1.118 jms 498: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 499: header => [{col1 => 'Help Page Settings (logged-in users)',
500: col2 => 'Value'},
501: {col1 => 'Helpdesk Roles',
502: col2 => 'Settings'},],
1.230 raeburn 503: print => \&print_helpsettings,
504: modify => \&modify_helpsettings,
1.118 jms 505: },
1.121 raeburn 506: 'coursedefaults' =>
507: {text => 'Course/Community defaults',
508: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 509: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
510: col2 => 'Value',},
511: {col1 => 'Defaults which can be overridden for each course by a DC',
512: col2 => 'Value',},],
1.230 raeburn 513: print => \&print_coursedefaults,
514: modify => \&modify_coursedefaults,
1.121 raeburn 515: },
1.231 raeburn 516: 'selfenrollment' =>
517: {text => 'Self-enrollment in Course/Community',
518: help => 'Domain_Configuration_Selfenrollment',
519: header => [{col1 => 'Configuration Rights',
520: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
521: {col1 => 'Defaults',
522: col2 => 'Value'},
523: {col1 => 'Self-enrollment validation (optional)',
524: col2 => 'Value'},],
525: print => \&print_selfenrollment,
526: modify => \&modify_selfenrollment,
527: },
1.120 raeburn 528: 'privacy' =>
1.357 raeburn 529: {text => 'Availability of User Information',
1.120 raeburn 530: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 531: header => [{col1 => 'Role assigned in different domain',
532: col2 => 'Approval options'},
533: {col1 => 'Role assigned in different domain to user of type',
534: col2 => 'User information available in that domain'},
535: {col1 => "Role assigned in user's domain",
536: col2 => 'Information viewable by privileged user'},
537: {col1 => "Role assigned in user's domain",
538: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 539: print => \&print_privacy,
540: modify => \&modify_privacy,
1.120 raeburn 541: },
1.141 raeburn 542: 'usersessions' =>
1.145 raeburn 543: {text => 'User session hosting/offloading',
1.137 raeburn 544: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 545: header => [{col1 => 'Domain server',
546: col2 => 'Servers to offload sessions to when busy'},
547: {col1 => 'Hosting of users from other domains',
1.137 raeburn 548: col2 => 'Rules'},
549: {col1 => "Hosting domain's own users elsewhere",
550: col2 => 'Rules'}],
1.230 raeburn 551: print => \&print_usersessions,
552: modify => \&modify_usersessions,
1.137 raeburn 553: },
1.279 raeburn 554: 'loadbalancing' =>
1.185 raeburn 555: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 556: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 557: header => [{col1 => 'Balancers',
1.150 raeburn 558: col2 => 'Default destinations',
1.183 bisitz 559: col3 => 'User affiliation',
1.150 raeburn 560: col4 => 'Overrides'},
561: ],
1.230 raeburn 562: print => \&print_loadbalancing,
563: modify => \&modify_loadbalancing,
1.150 raeburn 564: },
1.279 raeburn 565: 'ltitools' =>
1.267 raeburn 566: {text => 'External Tools (LTI)',
1.296 raeburn 567: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 568: header => [{col1 => 'Setting',
569: col2 => 'Value',}],
570: print => \&print_ltitools,
571: modify => \&modify_ltitools,
572: },
1.372 raeburn 573: 'proctoring' =>
574: {text => 'Remote Proctoring Integration',
575: help => 'Domain_Configuration_Proctoring',
576: header => [{col1 => 'Name',
577: col2 => 'Configuration'}],
578: print => \&print_proctoring,
579: modify => \&modify_proctoring,
580: },
1.279 raeburn 581: 'ssl' =>
1.275 raeburn 582: {text => 'LON-CAPA Network (SSL)',
583: help => 'Domain_Configuration_Network_SSL',
584: header => [{col1 => 'Server',
585: col2 => 'Certificate Status'},
586: {col1 => 'Connections to other servers',
587: col2 => 'Rules'},
1.293 raeburn 588: {col1 => 'Connections from other servers',
589: col2 => 'Rules'},
1.275 raeburn 590: {col1 => "Replicating domain's published content",
591: col2 => 'Rules'}],
592: print => \&print_ssl,
593: modify => \&modify_ssl,
594: },
1.279 raeburn 595: 'trust' =>
596: {text => 'Trust Settings',
597: help => 'Domain_Configuration_Trust',
598: header => [{col1 => "Access to this domain's content by others",
599: col2 => 'Rules'},
600: {col1 => "Access to other domain's content by this domain",
601: col2 => 'Rules'},
602: {col1 => "Enrollment in this domain's courses by others",
603: col2 => 'Rules',},
604: {col1 => "Co-author roles in this domain for others",
605: col2 => 'Rules',},
606: {col1 => "Co-author roles for this domain's users elsewhere",
607: col2 => 'Rules',},
608: {col1 => "Domain roles in this domain assignable to others",
609: col2 => 'Rules'},
610: {col1 => "Course catalog for this domain displayed elsewhere",
611: col2 => 'Rules'},
612: {col1 => "Requests for creation of courses in this domain by others",
613: col2 => 'Rules'},
614: {col1 => "Users in other domains can send messages to this domain",
615: col2 => 'Rules'},],
616: print => \&print_trust,
617: modify => \&modify_trust,
618: },
1.320 raeburn 619: 'lti' =>
620: {text => 'LTI Provider',
621: help => 'Domain_Configuration_LTI_Provider',
622: header => [{col1 => 'Setting',
623: col2 => 'Value',}],
624: print => \&print_lti,
625: modify => \&modify_lti,
626: },
1.3 raeburn 627: );
1.110 raeburn 628: if (keys(%servers) > 1) {
629: $prefs{'login'} = { text => 'Log-in page options',
630: help => 'Domain_Configuration_Login_Page',
631: header => [{col1 => 'Log-in Service',
632: col2 => 'Server Setting',},
633: {col1 => 'Log-in Page Items',
1.168 raeburn 634: col2 => ''},
635: {col1 => 'Log-in Help',
1.256 raeburn 636: col2 => 'Value'},
637: {col1 => 'Custom HTML in document head',
1.386 raeburn 638: col2 => 'Value'},
639: {col1 => 'SSO',
640: col2 => 'Dual login: SSO and non-SSO options'},
641: ],
1.230 raeburn 642: print => \&print_login,
643: modify => \&modify_login,
1.110 raeburn 644: };
645: }
1.174 foxr 646:
1.6 raeburn 647: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 648: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 649: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 650: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 651: text=>"Settings to display/modify"});
1.9 raeburn 652: my $confname = $dom.'-domainconfig';
1.174 foxr 653:
1.3 raeburn 654: if ($phase eq 'process') {
1.212 raeburn 655: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
656: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 657: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 658: $r->rflush();
1.212 raeburn 659: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 660: }
1.30 raeburn 661: } elsif ($phase eq 'display') {
1.192 raeburn 662: my $js = &recaptcha_js().
1.236 raeburn 663: &toggle_display_js();
1.171 raeburn 664: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 665: my ($othertitle,$usertypes,$types) =
666: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 667: $js .= &lonbalance_targets_js($dom,$types,\%servers,
668: $domconfig{'loadbalancing'}).
1.170 raeburn 669: &new_spares_js().
670: &common_domprefs_js().
671: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 672: }
1.216 raeburn 673: if (grep(/^requestcourses$/,@actions)) {
674: my $javascript_validations;
675: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
676: $js .= <<END;
677: <script type="text/javascript">
678: $javascript_validations
679: </script>
680: $coursebrowserjs
681: END
682: }
1.305 raeburn 683: if (grep(/^selfcreation$/,@actions)) {
684: $js .= &selfcreate_javascript();
685: }
1.286 raeburn 686: if (grep(/^contacts$/,@actions)) {
687: $js .= &contacts_javascript();
688: }
1.346 raeburn 689: if (grep(/^scantron$/,@actions)) {
690: $js .= &scantron_javascript();
691: }
1.150 raeburn 692: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 693: } else {
1.180 raeburn 694: # check if domconfig user exists for the domain.
695: my $servadm = $r->dir_config('lonAdmEMail');
696: my ($configuserok,$author_ok,$switchserver) =
697: &config_check($dom,$confname,$servadm);
698: unless ($configuserok eq 'ok') {
1.181 raeburn 699: &Apache::lonconfigsettings::print_header($r,$phase,$context);
700: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 701: $confname).
1.181 raeburn 702: '<br />'
703: );
1.180 raeburn 704: if ($switchserver) {
1.181 raeburn 705: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
706: '<br />'.
707: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
708: '<br />'.
709: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
710: '<br />'.
711: &mt('To do that now, use the following link: [_1]',$switchserver)
712: );
713: } else {
714: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
715: '<br />'.
716: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
717: );
1.180 raeburn 718: }
719: $r->print(&Apache::loncommon::end_page());
720: return OK;
721: }
1.21 raeburn 722: if (keys(%domconfig) == 0) {
723: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 724: my @ids=&Apache::lonnet::current_machine_ids();
725: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 726: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 727: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 728: my $custom_img_count = 0;
729: foreach my $img (@loginimages) {
730: if ($designhash{$dom.'.login.'.$img} ne '') {
731: $custom_img_count ++;
732: }
733: }
734: foreach my $role (@roles) {
735: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
736: $custom_img_count ++;
737: }
738: }
739: if ($custom_img_count > 0) {
1.94 raeburn 740: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 741: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 742: $r->print(
743: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
744: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
745: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
746: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
747: if ($switch_server) {
1.30 raeburn 748: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 749: }
1.91 raeburn 750: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 751: return OK;
752: }
753: }
754: }
1.91 raeburn 755: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 756: }
757: return OK;
758: }
759:
760: sub process_changes {
1.205 raeburn 761: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 762: my %domconfig;
763: if (ref($values) eq 'HASH') {
764: %domconfig = %{$values};
765: }
1.3 raeburn 766: my $output;
767: if ($action eq 'login') {
1.205 raeburn 768: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 769: } elsif ($action eq 'rolecolors') {
1.9 raeburn 770: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 771: $lastactref,%domconfig);
1.3 raeburn 772: } elsif ($action eq 'quotas') {
1.216 raeburn 773: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 774: } elsif ($action eq 'autoenroll') {
1.205 raeburn 775: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 776: } elsif ($action eq 'autoupdate') {
777: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 778: } elsif ($action eq 'autocreate') {
779: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 780: } elsif ($action eq 'directorysrch') {
1.295 raeburn 781: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 782: } elsif ($action eq 'usercreation') {
1.28 raeburn 783: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 784: } elsif ($action eq 'selfcreation') {
1.305 raeburn 785: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 786: } elsif ($action eq 'usermodification') {
787: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 788: } elsif ($action eq 'contacts') {
1.205 raeburn 789: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 790: } elsif ($action eq 'defaults') {
1.212 raeburn 791: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 792: } elsif ($action eq 'scantron') {
1.205 raeburn 793: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 794: } elsif ($action eq 'coursecategories') {
1.239 raeburn 795: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 796: } elsif ($action eq 'serverstatuses') {
797: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 798: } elsif ($action eq 'requestcourses') {
1.216 raeburn 799: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 800: } elsif ($action eq 'requestauthor') {
1.216 raeburn 801: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 802: } elsif ($action eq 'helpsettings') {
1.285 raeburn 803: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 804: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 805: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 806: } elsif ($action eq 'selfenrollment') {
807: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 808: } elsif ($action eq 'usersessions') {
1.212 raeburn 809: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 810: } elsif ($action eq 'loadbalancing') {
811: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 812: } elsif ($action eq 'ltitools') {
813: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 814: } elsif ($action eq 'proctoring') {
815: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 816: } elsif ($action eq 'ssl') {
817: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 818: } elsif ($action eq 'trust') {
819: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 820: } elsif ($action eq 'lti') {
821: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 822: } elsif ($action eq 'privacy') {
823: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 824: } elsif ($action eq 'passwords') {
825: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 826: } elsif ($action eq 'wafproxy') {
827: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.3 raeburn 828: }
829: return $output;
830: }
831:
832: sub print_config_box {
1.9 raeburn 833: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 834: my $rowtotal = 0;
1.49 raeburn 835: my $output;
836: if ($action eq 'coursecategories') {
837: $output = &coursecategories_javascript($settings);
1.236 raeburn 838: } elsif ($action eq 'defaults') {
839: $output = &defaults_javascript($settings);
1.354 raeburn 840: } elsif ($action eq 'passwords') {
841: $output = &passwords_javascript();
1.282 raeburn 842: } elsif ($action eq 'helpsettings') {
843: my (%privs,%levelscurrent);
844: my %full=();
845: my %levels=(
846: course => {},
847: domain => {},
848: system => {},
849: );
850: my $context = 'domain';
851: my $crstype = 'Course';
852: my $formname = 'display';
853: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
854: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
855: $output =
856: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
857: \@templateroles);
1.334 raeburn 858: } elsif ($action eq 'ltitools') {
859: $output .= <itools_javascript($settings);
860: } elsif ($action eq 'lti') {
861: $output .= <i_javascript($settings);
1.372 raeburn 862: } elsif ($action eq 'proctoring') {
863: $output .= &proctoring_javascript($settings);
1.381 raeburn 864: } elsif ($action eq 'wafproxy') {
865: $output .= &wafproxy_javascript($dom);
1.385 raeburn 866: } elsif ($action eq 'autoupdate') {
867: $output .= &autoupdate_javascript();
1.386 raeburn 868: } elsif ($action eq 'login') {
869: $output .= &saml_javascript();
1.91 raeburn 870: }
1.236 raeburn 871: $output .=
1.30 raeburn 872: '<table class="LC_nested_outer">
1.3 raeburn 873: <tr>
1.306 raeburn 874: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 875: &mt($item->{text}).' '.
876: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
877: '</tr>';
1.30 raeburn 878: $rowtotal ++;
1.110 raeburn 879: my $numheaders = 1;
880: if (ref($item->{'header'}) eq 'ARRAY') {
881: $numheaders = scalar(@{$item->{'header'}});
882: }
883: if ($numheaders > 1) {
1.64 raeburn 884: my $colspan = '';
1.145 raeburn 885: my $rightcolspan = '';
1.369 raeburn 886: my $leftnobr = '';
1.238 raeburn 887: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 888: ($action eq 'directorysrch') ||
1.386 raeburn 889: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 890: $colspan = ' colspan="2"';
891: }
1.145 raeburn 892: if ($action eq 'usersessions') {
893: $rightcolspan = ' colspan="3"';
894: }
1.369 raeburn 895: if ($action eq 'passwords') {
896: $leftnobr = ' LC_nobreak';
897: }
1.30 raeburn 898: $output .= '
1.3 raeburn 899: <tr>
900: <td>
901: <table class="LC_nested">
902: <tr class="LC_info_row">
1.369 raeburn 903: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 904: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 905: </tr>';
1.69 raeburn 906: $rowtotal ++;
1.230 raeburn 907: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 908: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 909: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 910: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 raeburn 911: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 912: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 913: } elsif ($action eq 'passwords') {
914: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 915: } elsif ($action eq 'coursecategories') {
1.230 raeburn 916: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 917: } elsif ($action eq 'scantron') {
918: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 919: } elsif ($action eq 'login') {
1.386 raeburn 920: if ($numheaders == 5) {
1.168 raeburn 921: $colspan = ' colspan="2"';
922: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
923: } else {
924: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
925: }
1.230 raeburn 926: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 927: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 928: } elsif ($action eq 'rolecolors') {
1.30 raeburn 929: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 930: }
1.30 raeburn 931: $output .= '
1.6 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>
936: <td>
937: <table class="LC_nested">
938: <tr class="LC_info_row">
1.230 raeburn 939: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 940: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 941: </tr>';
942: $rowtotal ++;
1.230 raeburn 943: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
944: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 945: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 946: ($action eq 'trust') || ($action eq 'contacts') ||
947: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 948: if ($action eq 'coursecategories') {
949: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
950: $colspan = ' colspan="2"';
1.279 raeburn 951: } elsif ($action eq 'trust') {
952: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 953: } elsif ($action eq 'passwords') {
954: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 955: } else {
956: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
957: }
1.279 raeburn 958: if ($action eq 'trust') {
959: $output .= '
960: </table>
961: </td>
962: </tr>';
963: my @trusthdrs = qw(2 3 4 5 6 7);
964: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
965: for (my $i=0; $i<@trusthdrs; $i++) {
966: $output .= '
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
972: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
973: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
974: </table>
975: </td>
976: </tr>';
977: }
978: $output .= '
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
984: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
985: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
986: } else {
987: $output .= '
1.63 raeburn 988: </table>
989: </td>
990: </tr>
991: <tr>
992: <td>
993: <table class="LC_nested">
994: <tr class="LC_info_row">
995: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 996: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 997: </tr>'."\n";
1.279 raeburn 998: if ($action eq 'coursecategories') {
999: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 1000: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 1001: if ($action eq 'passwords') {
1002: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1003: } else {
1004: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1005: }
1006: $output .= '
1.340 raeburn 1007: </tr>
1008: </table>
1009: </td>
1010: </tr>
1011: <tr>
1012: <td>
1013: <table class="LC_nested">
1014: <tr class="LC_info_row">
1.369 raeburn 1015: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1016: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1017: if ($action eq 'passwords') {
1018: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1019: } else {
1020: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1021: }
1022: $output .= '
1.340 raeburn 1023: </table>
1024: </td>
1025: </tr>
1026: <tr>';
1.279 raeburn 1027: } else {
1028: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1029: }
1.238 raeburn 1030: }
1.63 raeburn 1031: $rowtotal ++;
1.236 raeburn 1032: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1033: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 raeburn 1034: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1035: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1036: } elsif ($action eq 'scantron') {
1037: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1038: } elsif ($action eq 'ssl') {
1039: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1040: </table>
1041: </td>
1042: </tr>
1043: <tr>
1044: <td>
1045: <table class="LC_nested">
1046: <tr class="LC_info_row">
1047: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1048: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1049: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1050: </table>
1051: </td>
1052: </tr>
1053: <tr>
1054: <td>
1055: <table class="LC_nested">
1056: <tr class="LC_info_row">
1057: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1058: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1059: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1060: } elsif ($action eq 'login') {
1.386 raeburn 1061: if ($numheaders == 5) {
1.168 raeburn 1062: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1063: </table>
1064: </td>
1065: </tr>
1066: <tr>
1067: <td>
1068: <table class="LC_nested">
1069: <tr class="LC_info_row">
1070: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1071: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1072: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1073: $rowtotal ++;
1074: } else {
1075: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1076: }
1.256 raeburn 1077: $output .= '
1078: </table>
1079: </td>
1080: </tr>
1081: <tr>
1082: <td>
1083: <table class="LC_nested">
1084: <tr class="LC_info_row">';
1.386 raeburn 1085: if ($numheaders == 5) {
1.256 raeburn 1086: $output .= '
1087: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1088: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1089: </tr>';
1090: } else {
1091: $output .= '
1092: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1093: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1094: </tr>';
1095: }
1096: $rowtotal ++;
1.386 raeburn 1097: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1098: </table>
1099: </td>
1100: </tr>
1101: <tr>
1102: <td>
1103: <table class="LC_nested">
1104: <tr class="LC_info_row">';
1105: if ($numheaders == 5) {
1106: $output .= '
1107: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1108: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1109: </tr>';
1110: } else {
1111: $output .= '
1112: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1113: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1114: </tr>';
1115: }
1116: $rowtotal ++;
1117: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1118: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1119: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1120: $rowtotal ++;
1121: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1122: </table>
1123: </td>
1124: </tr>
1125: <tr>
1126: <td>
1127: <table class="LC_nested">
1128: <tr class="LC_info_row">
1129: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1130: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1131: &textbookcourses_javascript($settings).
1132: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1133: </table>
1134: </td>
1135: </tr>
1136: <tr>
1137: <td>
1138: <table class="LC_nested">
1139: <tr class="LC_info_row">
1140: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1141: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1142: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1143: </table>
1144: </td>
1145: </tr>
1146: <tr>
1147: <td>
1148: <table class="LC_nested">
1149: <tr class="LC_info_row">
1.306 raeburn 1150: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1151: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1152: </tr>'.
1153: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1154: } elsif ($action eq 'requestauthor') {
1155: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1156: $rowtotal ++;
1.122 jms 1157: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1158: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1159: </table>
1160: </td>
1161: </tr>
1162: <tr>
1163: <td>
1164: <table class="LC_nested">
1165: <tr class="LC_info_row">
1.306 raeburn 1166: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1167: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1168: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1169: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1170: </tr>'.
1.30 raeburn 1171: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1172: </table>
1173: </td>
1174: </tr>
1175: <tr>
1176: <td>
1177: <table class="LC_nested">
1178: <tr class="LC_info_row">
1.59 bisitz 1179: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1180: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1181: </tr>'.
1.30 raeburn 1182: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1183: $rowtotal += 2;
1.6 raeburn 1184: }
1.3 raeburn 1185: } else {
1.30 raeburn 1186: $output .= '
1.3 raeburn 1187: <tr>
1188: <td>
1189: <table class="LC_nested">
1.30 raeburn 1190: <tr class="LC_info_row">';
1.277 raeburn 1191: if ($action eq 'login') {
1.30 raeburn 1192: $output .= '
1.59 bisitz 1193: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1194: } elsif ($action eq 'serverstatuses') {
1195: $output .= '
1.306 raeburn 1196: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1197: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1198:
1.6 raeburn 1199: } else {
1.30 raeburn 1200: $output .= '
1.306 raeburn 1201: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1202: }
1.72 raeburn 1203: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1204: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1205: &mt($item->{'header'}->[0]->{'col2'});
1206: if ($action eq 'serverstatuses') {
1207: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1208: }
1.69 raeburn 1209: } else {
1.306 raeburn 1210: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1211: &mt($item->{'header'}->[0]->{'col2'});
1212: }
1213: $output .= '</td>';
1214: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1215: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1216: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1217: &mt($item->{'header'}->[0]->{'col3'});
1218: } else {
1.306 raeburn 1219: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1220: &mt($item->{'header'}->[0]->{'col3'});
1221: }
1.69 raeburn 1222: if ($action eq 'serverstatuses') {
1223: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1224: }
1225: $output .= '</td>';
1.6 raeburn 1226: }
1.150 raeburn 1227: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1228: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1229: &mt($item->{'header'}->[0]->{'col4'});
1230: }
1.69 raeburn 1231: $output .= '</tr>';
1.48 raeburn 1232: $rowtotal ++;
1.168 raeburn 1233: if ($action eq 'quotas') {
1.86 raeburn 1234: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1235: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1236: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1237: ($action eq 'ltitools') || ($action eq 'lti') ||
1238: ($action eq 'proctoring')) {
1.230 raeburn 1239: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1240: }
1.3 raeburn 1241: }
1.30 raeburn 1242: $output .= '
1.3 raeburn 1243: </table>
1244: </td>
1245: </tr>
1.30 raeburn 1246: </table><br />';
1247: return ($output,$rowtotal);
1.1 raeburn 1248: }
1249:
1.3 raeburn 1250: sub print_login {
1.168 raeburn 1251: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1252: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1253: my %choices = &login_choices();
1.386 raeburn 1254: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1255: %lt = &login_file_options();
1256: $switchserver = &check_switchserver($dom,$confname);
1257: }
1.168 raeburn 1258: if ($caller eq 'service') {
1.149 raeburn 1259: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1260: my $choice = $choices{'disallowlogin'};
1261: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1262: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1263: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1264: '<th>'.$choices{'server'}.'</th>'.
1265: '<th>'.$choices{'serverpath'}.'</th>'.
1266: '<th>'.$choices{'custompath'}.'</th>'.
1267: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1268: my %disallowed;
1269: if (ref($settings) eq 'HASH') {
1270: if (ref($settings->{'loginvia'}) eq 'HASH') {
1271: %disallowed = %{$settings->{'loginvia'}};
1272: }
1273: }
1274: foreach my $lonhost (sort(keys(%servers))) {
1275: my $direct = 'selected="selected"';
1.128 raeburn 1276: if (ref($disallowed{$lonhost}) eq 'HASH') {
1277: if ($disallowed{$lonhost}{'server'} ne '') {
1278: $direct = '';
1279: }
1.110 raeburn 1280: }
1.115 raeburn 1281: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1282: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1283: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1284: '</option>';
1.184 raeburn 1285: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1286: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1287: my $selected = '';
1.128 raeburn 1288: if (ref($disallowed{$lonhost}) eq 'HASH') {
1289: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1290: $selected = 'selected="selected"';
1291: }
1.110 raeburn 1292: }
1293: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1294: $servers{$hostid}.'</option>';
1295: }
1.128 raeburn 1296: $datatable .= '</select></td>'.
1297: '<td><select name="'.$lonhost.'_serverpath">';
1298: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1299: my $pathname = $path;
1300: if ($path eq 'custom') {
1301: $pathname = &mt('Custom Path').' ->';
1302: }
1303: my $selected = '';
1304: if (ref($disallowed{$lonhost}) eq 'HASH') {
1305: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1306: $selected = 'selected="selected"';
1307: }
1308: } elsif ($path eq '') {
1309: $selected = 'selected="selected"';
1310: }
1311: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1312: }
1313: $datatable .= '</select></td>';
1314: my ($custom,$exempt);
1315: if (ref($disallowed{$lonhost}) eq 'HASH') {
1316: $custom = $disallowed{$lonhost}{'custompath'};
1317: $exempt = $disallowed{$lonhost}{'exempt'};
1318: }
1319: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1320: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1321: '</tr>';
1.110 raeburn 1322: }
1323: $datatable .= '</table></td></tr>';
1324: return $datatable;
1.168 raeburn 1325: } elsif ($caller eq 'page') {
1326: my %defaultchecked = (
1327: 'coursecatalog' => 'on',
1.188 raeburn 1328: 'helpdesk' => 'on',
1.168 raeburn 1329: 'adminmail' => 'off',
1330: 'newuser' => 'off',
1331: );
1.188 raeburn 1332: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1333: my (%checkedon,%checkedoff);
1.42 raeburn 1334: foreach my $item (@toggles) {
1.168 raeburn 1335: if ($defaultchecked{$item} eq 'on') {
1336: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1337: $checkedoff{$item} = ' ';
1.168 raeburn 1338: } elsif ($defaultchecked{$item} eq 'off') {
1339: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1340: $checkedon{$item} = ' ';
1341: }
1.1 raeburn 1342: }
1.168 raeburn 1343: my @images = ('img','logo','domlogo','login');
1344: my @logintext = ('textcol','bgcol');
1345: my @bgs = ('pgbg','mainbg','sidebg');
1346: my @links = ('link','alink','vlink');
1347: my %designhash = &Apache::loncommon::get_domainconf($dom);
1348: my %defaultdesign = %Apache::loncommon::defaultdesign;
1349: my (%is_custom,%designs);
1350: my %defaults = (
1351: font => $defaultdesign{'login.font'},
1352: );
1.6 raeburn 1353: foreach my $item (@images) {
1.168 raeburn 1354: $defaults{$item} = $defaultdesign{'login.'.$item};
1355: $defaults{'showlogo'}{$item} = 1;
1356: }
1357: foreach my $item (@bgs) {
1358: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1359: }
1.41 raeburn 1360: foreach my $item (@logintext) {
1.168 raeburn 1361: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1362: }
1.168 raeburn 1363: foreach my $item (@links) {
1364: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1365: }
1.168 raeburn 1366: if (ref($settings) eq 'HASH') {
1367: foreach my $item (@toggles) {
1368: if ($settings->{$item} eq '1') {
1369: $checkedon{$item} = ' checked="checked" ';
1370: $checkedoff{$item} = ' ';
1371: } elsif ($settings->{$item} eq '0') {
1372: $checkedoff{$item} = ' checked="checked" ';
1373: $checkedon{$item} = ' ';
1374: }
1375: }
1376: foreach my $item (@images) {
1377: if (defined($settings->{$item})) {
1378: $designs{$item} = $settings->{$item};
1379: $is_custom{$item} = 1;
1380: }
1381: if (defined($settings->{'showlogo'}{$item})) {
1382: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1383: }
1384: }
1385: foreach my $item (@logintext) {
1386: if ($settings->{$item} ne '') {
1387: $designs{'logintext'}{$item} = $settings->{$item};
1388: $is_custom{$item} = 1;
1389: }
1390: }
1391: if ($settings->{'font'} ne '') {
1392: $designs{'font'} = $settings->{'font'};
1393: $is_custom{'font'} = 1;
1394: }
1395: foreach my $item (@bgs) {
1396: if ($settings->{$item} ne '') {
1397: $designs{'bgs'}{$item} = $settings->{$item};
1398: $is_custom{$item} = 1;
1399: }
1400: }
1401: foreach my $item (@links) {
1402: if ($settings->{$item} ne '') {
1403: $designs{'links'}{$item} = $settings->{$item};
1404: $is_custom{$item} = 1;
1405: }
1406: }
1407: } else {
1408: if ($designhash{$dom.'.login.font'} ne '') {
1409: $designs{'font'} = $designhash{$dom.'.login.font'};
1410: $is_custom{'font'} = 1;
1411: }
1412: foreach my $item (@images) {
1413: if ($designhash{$dom.'.login.'.$item} ne '') {
1414: $designs{$item} = $designhash{$dom.'.login.'.$item};
1415: $is_custom{$item} = 1;
1416: }
1417: }
1418: foreach my $item (@bgs) {
1419: if ($designhash{$dom.'.login.'.$item} ne '') {
1420: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1421: $is_custom{$item} = 1;
1422: }
1.6 raeburn 1423: }
1.168 raeburn 1424: foreach my $item (@links) {
1425: if ($designhash{$dom.'.login.'.$item} ne '') {
1426: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1427: $is_custom{$item} = 1;
1428: }
1.6 raeburn 1429: }
1430: }
1.168 raeburn 1431: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1432: logo => 'Institution Logo',
1433: domlogo => 'Domain Logo',
1434: login => 'Login box');
1435: my $itemcount = 1;
1436: foreach my $item (@toggles) {
1437: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1438: $datatable .=
1439: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1440: '</td><td>'.
1441: '<span class="LC_nobreak"><label><input type="radio" name="'.
1442: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1443: '</label> <label><input type="radio" name="'.$item.'"'.
1444: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1445: '</tr>';
1446: $itemcount ++;
1.6 raeburn 1447: }
1.168 raeburn 1448: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1449: $datatable .= '</tr></table></td></tr>';
1450: } elsif ($caller eq 'help') {
1.386 raeburn 1451: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1452: my $itemcount = 1;
1453: $defaulturl = '/adm/loginproblems.html';
1454: $defaulttype = 'default';
1455: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1456: my @currlangs;
1457: if (ref($settings) eq 'HASH') {
1458: if (ref($settings->{'helpurl'}) eq 'HASH') {
1459: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1460: next if ($settings->{'helpurl'}{$key} eq '');
1461: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1462: $type{$key} = 'custom';
1463: unless ($key eq 'nolang') {
1464: push(@currlangs,$key);
1465: }
1466: }
1467: } elsif ($settings->{'helpurl'} ne '') {
1468: $type{'nolang'} = 'custom';
1469: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1470: }
1471: }
1.168 raeburn 1472: foreach my $lang ('nolang',sort(@currlangs)) {
1473: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1474: $datatable .= '<tr'.$css_class.'>';
1475: if ($url{$lang} eq '') {
1476: $url{$lang} = $defaulturl;
1477: }
1478: if ($type{$lang} eq '') {
1479: $type{$lang} = $defaulttype;
1480: }
1481: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1482: if ($lang eq 'nolang') {
1483: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1484: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1485: } else {
1486: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1487: $langchoices{$lang},
1488: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1489: }
1490: $datatable .= '</span></td>'."\n".
1491: '<td class="LC_left_item">';
1492: if ($type{$lang} eq 'custom') {
1493: $datatable .= '<span class="LC_nobreak"><label>'.
1494: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1495: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1496: } else {
1497: $datatable .= $lt{'upl'};
1498: }
1499: $datatable .='<br />';
1500: if ($switchserver) {
1501: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1502: } else {
1503: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1504: }
1.168 raeburn 1505: $datatable .= '</td></tr>';
1506: $itemcount ++;
1.6 raeburn 1507: }
1.168 raeburn 1508: my @addlangs;
1509: foreach my $lang (sort(keys(%langchoices))) {
1510: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1511: push(@addlangs,$lang);
1512: }
1513: if (@addlangs > 0) {
1514: my %toadd;
1515: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1516: $toadd{''} = &mt('Select');
1517: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1518: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1519: &mt('Add log-in help page for a specific language:').' '.
1520: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1521: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1522: if ($switchserver) {
1523: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1524: } else {
1525: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1526: }
1.168 raeburn 1527: $datatable .= '</td></tr>';
1.169 raeburn 1528: $itemcount ++;
1.6 raeburn 1529: }
1.169 raeburn 1530: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1531: } elsif ($caller eq 'headtag') {
1532: my %domservers = &Apache::lonnet::get_servers($dom);
1533: my $choice = $choices{'headtag'};
1534: $css_class = ' class="LC_odd_row"';
1535: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1536: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1537: '<th>'.$choices{'current'}.'</th>'.
1538: '<th>'.$choices{'action'}.'</th>'.
1539: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1540: my (%currurls,%currexempt);
1541: if (ref($settings) eq 'HASH') {
1542: if (ref($settings->{'headtag'}) eq 'HASH') {
1543: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1544: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1545: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1546: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1547: }
1548: }
1549: }
1550: }
1551: foreach my $lonhost (sort(keys(%domservers))) {
1552: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1553: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1554: if ($currurls{$lonhost}) {
1555: $datatable .= '<td class="LC_right_item"><a href="'.
1556: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1557: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1558: '">'.$lt{'curr'}.'</a></td>'.
1559: '<td><span class="LC_nobreak"><label>'.
1560: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1561: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1562: } else {
1563: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1564: }
1565: $datatable .='<br />';
1566: if ($switchserver) {
1567: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1568: } else {
1569: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1570: }
1.330 raeburn 1571: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1572: }
1573: $datatable .= '</table></td></tr>';
1.386 raeburn 1574: } elsif ($caller eq 'saml') {
1575: my %domservers = &Apache::lonnet::get_servers($dom);
1576: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1577: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1578: '<th>'.$choices{'samllanding'}.'</th>'.
1579: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1580: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1581: foreach my $lonhost (keys(%domservers)) {
1582: $samlurl{$lonhost} = '/adm/sso';
1583: $styleon{$lonhost} = 'display:none';
1584: $styleoff{$lonhost} = '';
1585: }
1586: if (ref($settings->{'saml'}) eq 'HASH') {
1587: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1588: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1589: $saml{$lonhost} = 1;
1590: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1591: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1592: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1593: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1594: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1595: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1596: $styleon{$lonhost} = '';
1597: $styleoff{$lonhost} = 'display:none';
1598: } else {
1599: $styleon{$lonhost} = 'display:none';
1600: $styleoff{$lonhost} = '';
1601: }
1602: }
1603: }
1604: my $itemcount = 1;
1605: foreach my $lonhost (sort(keys(%domservers))) {
1606: my $samlon = ' ';
1607: my $samloff = ' checked="checked" ';
1608: if ($saml{$lonhost}) {
1609: $samlon = $samloff;
1610: $samloff = ' ';
1611: }
1612: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1613: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1614: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1615: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1616: &mt('No').'</label>'.(' 'x2).
1617: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1618: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1619: &mt('Yes').'</label></span></td>'.
1620: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1621: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1622: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1623: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1624: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1625: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1626: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1627: $samltext{$lonhost}.'" /></td><td>';
1628: if ($samlimg{$lonhost}) {
1629: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1630: '<span class="LC_nobreak"><label>'.
1631: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1632: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1633: } else {
1634: $datatable .= $lt{'upl'};
1635: }
1636: $datatable .='<br />';
1637: if ($switchserver) {
1638: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1639: } else {
1640: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1641: }
1642: $datatable .= '</td>'.
1643: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1644: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1645: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1646: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1647: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1648: $samltitle{$lonhost}.'</textarea></td>'.
1649: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1650: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1651: '</table></td>'.
1652: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1653: $itemcount ++;
1654: }
1655: $datatable .= '</table></td></tr>';
1.1 raeburn 1656: }
1.6 raeburn 1657: return $datatable;
1658: }
1659:
1660: sub login_choices {
1661: my %choices =
1662: &Apache::lonlocal::texthash (
1.116 bisitz 1663: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1664: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1665: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1666: disallowlogin => "Login page requests redirected",
1667: hostid => "Server",
1.128 raeburn 1668: server => "Redirect to:",
1669: serverpath => "Path",
1670: custompath => "Custom",
1671: exempt => "Exempt IP(s)",
1.110 raeburn 1672: directlogin => "No redirect",
1673: newuser => "Link to create a user account",
1674: img => "Header",
1675: logo => "Main Logo",
1676: domlogo => "Domain Logo",
1677: login => "Log-in Header",
1678: textcol => "Text color",
1679: bgcol => "Box color",
1680: bgs => "Background colors",
1681: links => "Link colors",
1682: font => "Font color",
1683: pgbg => "Header",
1684: mainbg => "Page",
1685: sidebg => "Login box",
1686: link => "Link",
1687: alink => "Active link",
1688: vlink => "Visited link",
1.256 raeburn 1689: headtag => "Custom markup",
1690: action => "Action",
1691: current => "Current",
1.386 raeburn 1692: samllanding => "Dual login?",
1693: samloptions => "Options",
1.6 raeburn 1694: );
1695: return %choices;
1696: }
1697:
1.386 raeburn 1698: sub login_file_options {
1699: return &Apache::lonlocal::texthash(
1700: del => 'Delete?',
1701: rep => 'Replace:',
1702: upl => 'Upload:',
1703: curr => 'View contents',
1704: default => 'Default',
1705: custom => 'Custom',
1706: none => 'None',
1707: );
1708: }
1709:
1.6 raeburn 1710: sub print_rolecolors {
1.30 raeburn 1711: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1712: my %choices = &color_font_choices();
1713: my @bgs = ('pgbg','tabbg','sidebg');
1714: my @links = ('link','alink','vlink');
1715: my @images = ('img');
1716: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1717: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1718: my %defaultdesign = %Apache::loncommon::defaultdesign;
1719: my (%is_custom,%designs);
1.200 raeburn 1720: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1721: if (ref($settings) eq 'HASH') {
1722: if (ref($settings->{$role}) eq 'HASH') {
1723: if ($settings->{$role}->{'img'} ne '') {
1724: $designs{'img'} = $settings->{$role}->{'img'};
1725: $is_custom{'img'} = 1;
1726: }
1727: if ($settings->{$role}->{'font'} ne '') {
1728: $designs{'font'} = $settings->{$role}->{'font'};
1729: $is_custom{'font'} = 1;
1730: }
1.97 tempelho 1731: if ($settings->{$role}->{'fontmenu'} ne '') {
1732: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1733: $is_custom{'fontmenu'} = 1;
1734: }
1.6 raeburn 1735: foreach my $item (@bgs) {
1736: if ($settings->{$role}->{$item} ne '') {
1737: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1738: $is_custom{$item} = 1;
1739: }
1740: }
1741: foreach my $item (@links) {
1742: if ($settings->{$role}->{$item} ne '') {
1743: $designs{'links'}{$item} = $settings->{$role}->{$item};
1744: $is_custom{$item} = 1;
1745: }
1746: }
1747: }
1748: } else {
1749: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1750: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1751: $is_custom{'img'} = 1;
1752: }
1.97 tempelho 1753: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1754: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1755: $is_custom{'fontmenu'} = 1;
1756: }
1.6 raeburn 1757: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1758: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1759: $is_custom{'font'} = 1;
1760: }
1761: foreach my $item (@bgs) {
1762: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1763: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1764: $is_custom{$item} = 1;
1765:
1766: }
1767: }
1768: foreach my $item (@links) {
1769: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1770: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1771: $is_custom{$item} = 1;
1772: }
1773: }
1774: }
1775: my $itemcount = 1;
1.30 raeburn 1776: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1777: $datatable .= '</tr></table></td></tr>';
1778: return $datatable;
1779: }
1780:
1.200 raeburn 1781: sub role_defaults {
1782: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1783: my %defaults;
1784: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1785: return %defaults;
1786: }
1787: my %defaultdesign = %Apache::loncommon::defaultdesign;
1788: if ($role eq 'login') {
1789: %defaults = (
1790: font => $defaultdesign{$role.'.font'},
1791: );
1792: if (ref($logintext) eq 'ARRAY') {
1793: foreach my $item (@{$logintext}) {
1794: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1795: }
1796: }
1797: foreach my $item (@{$images}) {
1798: $defaults{'showlogo'}{$item} = 1;
1799: }
1800: } else {
1801: %defaults = (
1802: img => $defaultdesign{$role.'.img'},
1803: font => $defaultdesign{$role.'.font'},
1804: fontmenu => $defaultdesign{$role.'.fontmenu'},
1805: );
1806: }
1807: foreach my $item (@{$bgs}) {
1808: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1809: }
1810: foreach my $item (@{$links}) {
1811: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1812: }
1813: foreach my $item (@{$images}) {
1814: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1815: }
1816: return %defaults;
1817: }
1818:
1.6 raeburn 1819: sub display_color_options {
1.9 raeburn 1820: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1821: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1822: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1823: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1824: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1825: '<td>'.$choices->{'font'}.'</td>';
1826: if (!$is_custom->{'font'}) {
1.329 raeburn 1827: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1828: } else {
1829: $datatable .= '<td> </td>';
1830: }
1.174 foxr 1831: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1832:
1.8 raeburn 1833: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1834: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1835: ' value="'.$current_color.'" /> '.
1.329 raeburn 1836: ' </span></td></tr>';
1.107 raeburn 1837: unless ($role eq 'login') {
1838: $datatable .= '<tr'.$css_class.'>'.
1839: '<td>'.$choices->{'fontmenu'}.'</td>';
1840: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1841: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1842: } else {
1843: $datatable .= '<td> </td>';
1844: }
1.202 raeburn 1845: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1846: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1847: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1848: '<input class="colorchooser" type="text" size="10" name="'
1849: .$role.'_fontmenu"'.
1850: ' value="'.$current_color.'" /> '.
1.329 raeburn 1851: ' </span></td></tr>';
1.97 tempelho 1852: }
1.9 raeburn 1853: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1854: foreach my $img (@{$images}) {
1.18 albertel 1855: $itemcount ++;
1.6 raeburn 1856: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1857: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1858: '<td>'.$choices->{$img};
1.41 raeburn 1859: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1860: if ($role eq 'login') {
1861: if ($img eq 'login') {
1862: $login_hdr_pick =
1.135 bisitz 1863: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1864: $logincolors =
1865: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1866: $designs,$defaults);
1.70 raeburn 1867: } elsif ($img ne 'domlogo') {
1868: $datatable.= &logo_display_options($img,$defaults,$designs);
1869: }
1870: }
1871: $datatable .= '</td>';
1.6 raeburn 1872: if ($designs->{$img} ne '') {
1873: $imgfile = $designs->{$img};
1.18 albertel 1874: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1875: } else {
1876: $imgfile = $defaults->{$img};
1877: }
1878: if ($imgfile) {
1.9 raeburn 1879: my ($showfile,$fullsize);
1880: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1881: my $urldir = $1;
1882: my $filename = $2;
1883: my @info = &Apache::lonnet::stat_file($designs->{$img});
1884: if (@info) {
1885: my $thumbfile = 'tn-'.$filename;
1886: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1887: if (@thumb) {
1888: $showfile = $urldir.'/'.$thumbfile;
1889: } else {
1890: $showfile = $imgfile;
1891: }
1892: } else {
1893: $showfile = '';
1894: }
1895: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1896: $showfile = $imgfile;
1.6 raeburn 1897: my $imgdir = $1;
1898: my $filename = $2;
1.159 raeburn 1899: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1900: $showfile = "/$imgdir/tn-".$filename;
1901: } else {
1.159 raeburn 1902: my $input = $londocroot.$imgfile;
1903: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1904: if (!-e $output) {
1.9 raeburn 1905: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1906: my ($fullwidth,$fullheight) = &check_dimensions($input);
1907: if ($fullwidth ne '' && $fullheight ne '') {
1908: if ($fullwidth > $width && $fullheight > $height) {
1909: my $size = $width.'x'.$height;
1.316 raeburn 1910: my @args = ('convert','-sample',$size,$input,$output);
1911: system({$args[0]} @args);
1.159 raeburn 1912: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1913: }
1914: }
1.6 raeburn 1915: }
1916: }
1.16 raeburn 1917: }
1.6 raeburn 1918: if ($showfile) {
1.40 raeburn 1919: if ($showfile =~ m{^/(adm|res)/}) {
1920: if ($showfile =~ m{^/res/}) {
1921: my $local_showfile =
1922: &Apache::lonnet::filelocation('',$showfile);
1923: &Apache::lonnet::repcopy($local_showfile);
1924: }
1925: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1926: }
1927: if ($imgfile) {
1928: if ($imgfile =~ m{^/(adm|res)/}) {
1929: if ($imgfile =~ m{^/res/}) {
1930: my $local_imgfile =
1931: &Apache::lonnet::filelocation('',$imgfile);
1932: &Apache::lonnet::repcopy($local_imgfile);
1933: }
1934: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1935: } else {
1936: $fullsize = $imgfile;
1937: }
1938: }
1.41 raeburn 1939: $datatable .= '<td>';
1940: if ($img eq 'login') {
1.135 bisitz 1941: $datatable .= $login_hdr_pick;
1942: }
1.41 raeburn 1943: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1944: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1945: } else {
1.201 raeburn 1946: $datatable .= '<td> </td><td class="LC_left_item">'.
1947: &mt('Upload:').'<br />';
1.6 raeburn 1948: }
1949: } else {
1.201 raeburn 1950: $datatable .= '<td> </td><td class="LC_left_item">'.
1951: &mt('Upload:').'<br />';
1.6 raeburn 1952: }
1.9 raeburn 1953: if ($switchserver) {
1954: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1955: } else {
1.135 bisitz 1956: if ($img ne 'login') { # suppress file selection for Log-in header
1957: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1958: }
1.9 raeburn 1959: }
1960: $datatable .= '</td></tr>';
1.6 raeburn 1961: }
1962: $itemcount ++;
1963: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1964: $datatable .= '<tr'.$css_class.'>'.
1965: '<td>'.$choices->{'bgs'}.'</td>';
1966: my $bgs_def;
1967: foreach my $item (@{$bgs}) {
1968: if (!$is_custom->{$item}) {
1.329 raeburn 1969: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1970: }
1971: }
1972: if ($bgs_def) {
1.8 raeburn 1973: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1974: } else {
1975: $datatable .= '<td> </td>';
1976: }
1977: $datatable .= '<td class="LC_right_item">'.
1978: '<table border="0"><tr>';
1.174 foxr 1979:
1.6 raeburn 1980: foreach my $item (@{$bgs}) {
1.306 raeburn 1981: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1982: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1983: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1984: $datatable .= ' ';
1.6 raeburn 1985: }
1.174 foxr 1986: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1987: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1988: }
1989: $datatable .= '</tr></table></td></tr>';
1990: $itemcount ++;
1991: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1992: $datatable .= '<tr'.$css_class.'>'.
1993: '<td>'.$choices->{'links'}.'</td>';
1994: my $links_def;
1995: foreach my $item (@{$links}) {
1996: if (!$is_custom->{$item}) {
1.329 raeburn 1997: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1998: }
1999: }
2000: if ($links_def) {
1.8 raeburn 2001: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2002: } else {
2003: $datatable .= '<td> </td>';
2004: }
2005: $datatable .= '<td class="LC_right_item">'.
2006: '<table border="0"><tr>';
2007: foreach my $item (@{$links}) {
1.234 raeburn 2008: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2009: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2010: if ($designs->{'links'}{$item}) {
1.174 foxr 2011: $datatable.=' ';
1.6 raeburn 2012: }
1.174 foxr 2013: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2014: '" /></td>';
2015: }
1.30 raeburn 2016: $$rowtotal += $itemcount;
1.3 raeburn 2017: return $datatable;
2018: }
2019:
1.70 raeburn 2020: sub logo_display_options {
2021: my ($img,$defaults,$designs) = @_;
2022: my $checkedon;
2023: if (ref($defaults) eq 'HASH') {
2024: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2025: if ($defaults->{'showlogo'}{$img}) {
2026: $checkedon = 'checked="checked" ';
2027: }
2028: }
2029: }
2030: if (ref($designs) eq 'HASH') {
2031: if (ref($designs->{'showlogo'}) eq 'HASH') {
2032: if (defined($designs->{'showlogo'}{$img})) {
2033: if ($designs->{'showlogo'}{$img} == 0) {
2034: $checkedon = '';
2035: } elsif ($designs->{'showlogo'}{$img} == 1) {
2036: $checkedon = 'checked="checked" ';
2037: }
2038: }
2039: }
2040: }
2041: return '<br /><label> <input type="checkbox" name="'.
2042: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2043: &mt('show').'</label>'."\n";
2044: }
2045:
1.41 raeburn 2046: sub login_header_options {
1.135 bisitz 2047: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2048: my $output = '';
1.41 raeburn 2049: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2050: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2051: if (!$is_custom->{'textcol'}) {
2052: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2053: ' ';
2054: }
2055: if (!$is_custom->{'bgcol'}) {
2056: $output .= $choices->{'bgcol'}.': '.
2057: '<span id="css_'.$role.'_font" style="background-color: '.
2058: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2059: }
2060: $output .= '<br />';
2061: }
2062: $output .='<br />';
2063: return $output;
2064: }
2065:
2066: sub login_text_colors {
1.201 raeburn 2067: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2068: my $color_menu = '<table border="0"><tr>';
2069: foreach my $item (@{$logintext}) {
1.306 raeburn 2070: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2071: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2072: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2073: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2074: }
2075: $color_menu .= '</tr></table><br />';
2076: return $color_menu;
2077: }
2078:
2079: sub image_changes {
2080: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2081: my $output;
1.135 bisitz 2082: if ($img eq 'login') {
1.331 raeburn 2083: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2084: } elsif (!$is_custom) {
1.70 raeburn 2085: if ($img ne 'domlogo') {
1.331 raeburn 2086: $output = &mt('Default image:').'<br />';
1.41 raeburn 2087: } else {
1.331 raeburn 2088: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2089: }
2090: }
1.331 raeburn 2091: if ($img ne 'login') {
1.135 bisitz 2092: if ($img_import) {
2093: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2094: }
2095: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2096: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2097: if ($is_custom) {
2098: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2099: '<input type="checkbox" name="'.
2100: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2101: '</label> '.&mt('Replace:').'</span><br />';
2102: } else {
1.306 raeburn 2103: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2104: }
1.41 raeburn 2105: }
2106: return $output;
2107: }
2108:
1.3 raeburn 2109: sub print_quotas {
1.86 raeburn 2110: my ($dom,$settings,$rowtotal,$action) = @_;
2111: my $context;
2112: if ($action eq 'quotas') {
2113: $context = 'tools';
2114: } else {
2115: $context = $action;
2116: }
1.197 raeburn 2117: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2118: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2119: my $typecount = 0;
1.101 raeburn 2120: my ($css_class,%titles);
1.86 raeburn 2121: if ($context eq 'requestcourses') {
1.325 raeburn 2122: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2123: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2124: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2125: %titles = &courserequest_titles();
1.163 raeburn 2126: } elsif ($context eq 'requestauthor') {
2127: @usertools = ('author');
2128: @options = ('norequest','approval','automatic');
1.210 raeburn 2129: %titles = &authorrequest_titles();
1.86 raeburn 2130: } else {
1.162 raeburn 2131: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2132: %titles = &tool_titles();
1.86 raeburn 2133: }
1.26 raeburn 2134: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2135: foreach my $type (@{$types}) {
1.197 raeburn 2136: my ($currdefquota,$currauthorquota);
1.163 raeburn 2137: unless (($context eq 'requestcourses') ||
2138: ($context eq 'requestauthor')) {
1.86 raeburn 2139: if (ref($settings) eq 'HASH') {
2140: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2141: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2142: } else {
2143: $currdefquota = $settings->{$type};
2144: }
1.197 raeburn 2145: if (ref($settings->{authorquota}) eq 'HASH') {
2146: $currauthorquota = $settings->{authorquota}->{$type};
2147: }
1.78 raeburn 2148: }
1.72 raeburn 2149: }
1.3 raeburn 2150: if (defined($usertypes->{$type})) {
2151: $typecount ++;
2152: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2153: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2154: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2155: '<td class="LC_left_item">';
1.101 raeburn 2156: if ($context eq 'requestcourses') {
2157: $datatable .= '<table><tr>';
2158: }
2159: my %cell;
1.72 raeburn 2160: foreach my $item (@usertools) {
1.101 raeburn 2161: if ($context eq 'requestcourses') {
2162: my ($curroption,$currlimit);
2163: if (ref($settings) eq 'HASH') {
2164: if (ref($settings->{$item}) eq 'HASH') {
2165: $curroption = $settings->{$item}->{$type};
2166: if ($curroption =~ /^autolimit=(\d*)$/) {
2167: $currlimit = $1;
2168: }
2169: }
2170: }
2171: if (!$curroption) {
2172: $curroption = 'norequest';
2173: }
2174: $datatable .= '<th>'.$titles{$item}.'</th>';
2175: foreach my $option (@options) {
2176: my $val = $option;
2177: if ($option eq 'norequest') {
2178: $val = 0;
2179: }
2180: if ($option eq 'validate') {
2181: my $canvalidate = 0;
2182: if (ref($validations{$item}) eq 'HASH') {
2183: if ($validations{$item}{$type}) {
2184: $canvalidate = 1;
2185: }
2186: }
2187: next if (!$canvalidate);
2188: }
2189: my $checked = '';
2190: if ($option eq $curroption) {
2191: $checked = ' checked="checked"';
2192: } elsif ($option eq 'autolimit') {
2193: if ($curroption =~ /^autolimit/) {
2194: $checked = ' checked="checked"';
2195: }
2196: }
2197: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2198: '<input type="radio" name="crsreq_'.$item.
2199: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2200: $titles{$option}.'</label>';
1.101 raeburn 2201: if ($option eq 'autolimit') {
1.127 raeburn 2202: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2203: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2204: 'value="'.$currlimit.'" />';
1.101 raeburn 2205: }
1.127 raeburn 2206: $cell{$item} .= '</span> ';
1.103 raeburn 2207: if ($option eq 'autolimit') {
1.127 raeburn 2208: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2209: }
1.101 raeburn 2210: }
1.163 raeburn 2211: } elsif ($context eq 'requestauthor') {
2212: my $curroption;
2213: if (ref($settings) eq 'HASH') {
2214: $curroption = $settings->{$type};
2215: }
2216: if (!$curroption) {
2217: $curroption = 'norequest';
2218: }
2219: foreach my $option (@options) {
2220: my $val = $option;
2221: if ($option eq 'norequest') {
2222: $val = 0;
2223: }
2224: my $checked = '';
2225: if ($option eq $curroption) {
2226: $checked = ' checked="checked"';
2227: }
2228: $datatable .= '<span class="LC_nobreak"><label>'.
2229: '<input type="radio" name="authorreq_'.$type.
2230: '" value="'.$val.'"'.$checked.' />'.
2231: $titles{$option}.'</label></span> ';
2232: }
1.101 raeburn 2233: } else {
2234: my $checked = 'checked="checked" ';
2235: if (ref($settings) eq 'HASH') {
2236: if (ref($settings->{$item}) eq 'HASH') {
2237: if ($settings->{$item}->{$type} == 0) {
2238: $checked = '';
2239: } elsif ($settings->{$item}->{$type} == 1) {
2240: $checked = 'checked="checked" ';
2241: }
1.78 raeburn 2242: }
1.72 raeburn 2243: }
1.101 raeburn 2244: $datatable .= '<span class="LC_nobreak"><label>'.
2245: '<input type="checkbox" name="'.$context.'_'.$item.
2246: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2247: '</label></span> ';
1.72 raeburn 2248: }
1.101 raeburn 2249: }
2250: if ($context eq 'requestcourses') {
2251: $datatable .= '</tr><tr>';
2252: foreach my $item (@usertools) {
1.106 raeburn 2253: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2254: }
2255: $datatable .= '</tr></table>';
1.72 raeburn 2256: }
1.86 raeburn 2257: $datatable .= '</td>';
1.163 raeburn 2258: unless (($context eq 'requestcourses') ||
2259: ($context eq 'requestauthor')) {
1.86 raeburn 2260: $datatable .=
1.197 raeburn 2261: '<td class="LC_right_item">'.
2262: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2263: '<input type="text" name="quota_'.$type.
1.72 raeburn 2264: '" value="'.$currdefquota.
1.197 raeburn 2265: '" size="5" /></span>'.(' ' x 2).
2266: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2267: '<input type="text" name="authorquota_'.$type.
2268: '" value="'.$currauthorquota.
2269: '" size="5" /></span></td>';
1.86 raeburn 2270: }
2271: $datatable .= '</tr>';
1.3 raeburn 2272: }
2273: }
2274: }
1.163 raeburn 2275: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2276: $defaultquota = '20';
1.197 raeburn 2277: $authorquota = '500';
1.86 raeburn 2278: if (ref($settings) eq 'HASH') {
2279: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2280: $defaultquota = $settings->{'defaultquota'}->{'default'};
2281: } elsif (defined($settings->{'default'})) {
2282: $defaultquota = $settings->{'default'};
2283: }
1.197 raeburn 2284: if (ref($settings->{'authorquota'}) eq 'HASH') {
2285: $authorquota = $settings->{'authorquota'}->{'default'};
2286: }
1.3 raeburn 2287: }
2288: }
2289: $typecount ++;
2290: $css_class = $typecount%2?' class="LC_odd_row"':'';
2291: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2292: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2293: '<td class="LC_left_item">';
1.101 raeburn 2294: if ($context eq 'requestcourses') {
2295: $datatable .= '<table><tr>';
2296: }
2297: my %defcell;
1.72 raeburn 2298: foreach my $item (@usertools) {
1.101 raeburn 2299: if ($context eq 'requestcourses') {
2300: my ($curroption,$currlimit);
2301: if (ref($settings) eq 'HASH') {
2302: if (ref($settings->{$item}) eq 'HASH') {
2303: $curroption = $settings->{$item}->{'default'};
2304: if ($curroption =~ /^autolimit=(\d*)$/) {
2305: $currlimit = $1;
2306: }
2307: }
2308: }
2309: if (!$curroption) {
2310: $curroption = 'norequest';
2311: }
2312: $datatable .= '<th>'.$titles{$item}.'</th>';
2313: foreach my $option (@options) {
2314: my $val = $option;
2315: if ($option eq 'norequest') {
2316: $val = 0;
2317: }
2318: if ($option eq 'validate') {
2319: my $canvalidate = 0;
2320: if (ref($validations{$item}) eq 'HASH') {
2321: if ($validations{$item}{'default'}) {
2322: $canvalidate = 1;
2323: }
2324: }
2325: next if (!$canvalidate);
2326: }
2327: my $checked = '';
2328: if ($option eq $curroption) {
2329: $checked = ' checked="checked"';
2330: } elsif ($option eq 'autolimit') {
2331: if ($curroption =~ /^autolimit/) {
2332: $checked = ' checked="checked"';
2333: }
2334: }
2335: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2336: '<input type="radio" name="crsreq_'.$item.
2337: '_default" value="'.$val.'"'.$checked.' />'.
2338: $titles{$option}.'</label>';
2339: if ($option eq 'autolimit') {
1.127 raeburn 2340: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2341: $item.'_limit_default" size="1" '.
2342: 'value="'.$currlimit.'" />';
2343: }
1.127 raeburn 2344: $defcell{$item} .= '</span> ';
1.104 raeburn 2345: if ($option eq 'autolimit') {
1.127 raeburn 2346: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2347: }
1.101 raeburn 2348: }
1.163 raeburn 2349: } elsif ($context eq 'requestauthor') {
2350: my $curroption;
2351: if (ref($settings) eq 'HASH') {
1.172 raeburn 2352: $curroption = $settings->{'default'};
1.163 raeburn 2353: }
2354: if (!$curroption) {
2355: $curroption = 'norequest';
2356: }
2357: foreach my $option (@options) {
2358: my $val = $option;
2359: if ($option eq 'norequest') {
2360: $val = 0;
2361: }
2362: my $checked = '';
2363: if ($option eq $curroption) {
2364: $checked = ' checked="checked"';
2365: }
2366: $datatable .= '<span class="LC_nobreak"><label>'.
2367: '<input type="radio" name="authorreq_default"'.
2368: ' value="'.$val.'"'.$checked.' />'.
2369: $titles{$option}.'</label></span> ';
2370: }
1.101 raeburn 2371: } else {
2372: my $checked = 'checked="checked" ';
2373: if (ref($settings) eq 'HASH') {
2374: if (ref($settings->{$item}) eq 'HASH') {
2375: if ($settings->{$item}->{'default'} == 0) {
2376: $checked = '';
2377: } elsif ($settings->{$item}->{'default'} == 1) {
2378: $checked = 'checked="checked" ';
2379: }
1.78 raeburn 2380: }
1.72 raeburn 2381: }
1.101 raeburn 2382: $datatable .= '<span class="LC_nobreak"><label>'.
2383: '<input type="checkbox" name="'.$context.'_'.$item.
2384: '" value="default" '.$checked.'/>'.$titles{$item}.
2385: '</label></span> ';
2386: }
2387: }
2388: if ($context eq 'requestcourses') {
2389: $datatable .= '</tr><tr>';
2390: foreach my $item (@usertools) {
1.106 raeburn 2391: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2392: }
1.101 raeburn 2393: $datatable .= '</tr></table>';
1.72 raeburn 2394: }
1.86 raeburn 2395: $datatable .= '</td>';
1.163 raeburn 2396: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2397: $datatable .= '<td class="LC_right_item">'.
2398: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2399: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2400: $defaultquota.'" size="5" /></span>'.(' ' x2).
2401: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2402: '<input type="text" name="authorquota" value="'.
2403: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2404: }
2405: $datatable .= '</tr>';
1.72 raeburn 2406: $typecount ++;
2407: $css_class = $typecount%2?' class="LC_odd_row"':'';
2408: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2409: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2410: if ($context eq 'requestcourses') {
1.109 raeburn 2411: $datatable .= &mt('(overrides affiliation, if set)').
2412: '</td>'.
2413: '<td class="LC_left_item">'.
2414: '<table><tr>';
1.101 raeburn 2415: } else {
1.109 raeburn 2416: $datatable .= &mt('(overrides affiliation, if checked)').
2417: '</td>'.
2418: '<td class="LC_left_item" colspan="2">'.
2419: '<br />';
1.101 raeburn 2420: }
2421: my %advcell;
1.72 raeburn 2422: foreach my $item (@usertools) {
1.101 raeburn 2423: if ($context eq 'requestcourses') {
2424: my ($curroption,$currlimit);
2425: if (ref($settings) eq 'HASH') {
2426: if (ref($settings->{$item}) eq 'HASH') {
2427: $curroption = $settings->{$item}->{'_LC_adv'};
2428: if ($curroption =~ /^autolimit=(\d*)$/) {
2429: $currlimit = $1;
2430: }
2431: }
2432: }
2433: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2434: my $checked = '';
2435: if ($curroption eq '') {
2436: $checked = ' checked="checked"';
2437: }
2438: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2439: '<input type="radio" name="crsreq_'.$item.
2440: '__LC_adv" value=""'.$checked.' />'.
2441: &mt('No override set').'</label></span> ';
1.101 raeburn 2442: foreach my $option (@options) {
2443: my $val = $option;
2444: if ($option eq 'norequest') {
2445: $val = 0;
2446: }
2447: if ($option eq 'validate') {
2448: my $canvalidate = 0;
2449: if (ref($validations{$item}) eq 'HASH') {
2450: if ($validations{$item}{'_LC_adv'}) {
2451: $canvalidate = 1;
2452: }
2453: }
2454: next if (!$canvalidate);
2455: }
2456: my $checked = '';
1.104 raeburn 2457: if ($val eq $curroption) {
1.101 raeburn 2458: $checked = ' checked="checked"';
2459: } elsif ($option eq 'autolimit') {
2460: if ($curroption =~ /^autolimit/) {
2461: $checked = ' checked="checked"';
2462: }
2463: }
2464: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2465: '<input type="radio" name="crsreq_'.$item.
2466: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2467: $titles{$option}.'</label>';
2468: if ($option eq 'autolimit') {
1.127 raeburn 2469: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2470: $item.'_limit__LC_adv" size="1" '.
2471: 'value="'.$currlimit.'" />';
2472: }
1.127 raeburn 2473: $advcell{$item} .= '</span> ';
1.104 raeburn 2474: if ($option eq 'autolimit') {
1.127 raeburn 2475: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2476: }
1.101 raeburn 2477: }
1.163 raeburn 2478: } elsif ($context eq 'requestauthor') {
2479: my $curroption;
2480: if (ref($settings) eq 'HASH') {
2481: $curroption = $settings->{'_LC_adv'};
2482: }
2483: my $checked = '';
2484: if ($curroption eq '') {
2485: $checked = ' checked="checked"';
2486: }
2487: $datatable .= '<span class="LC_nobreak"><label>'.
2488: '<input type="radio" name="authorreq__LC_adv"'.
2489: ' value=""'.$checked.' />'.
2490: &mt('No override set').'</label></span> ';
2491: foreach my $option (@options) {
2492: my $val = $option;
2493: if ($option eq 'norequest') {
2494: $val = 0;
2495: }
2496: my $checked = '';
2497: if ($val eq $curroption) {
2498: $checked = ' checked="checked"';
2499: }
2500: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2501: '<input type="radio" name="authorreq__LC_adv"'.
2502: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2503: $titles{$option}.'</label></span> ';
2504: }
1.101 raeburn 2505: } else {
2506: my $checked = 'checked="checked" ';
2507: if (ref($settings) eq 'HASH') {
2508: if (ref($settings->{$item}) eq 'HASH') {
2509: if ($settings->{$item}->{'_LC_adv'} == 0) {
2510: $checked = '';
2511: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2512: $checked = 'checked="checked" ';
2513: }
1.79 raeburn 2514: }
1.72 raeburn 2515: }
1.101 raeburn 2516: $datatable .= '<span class="LC_nobreak"><label>'.
2517: '<input type="checkbox" name="'.$context.'_'.$item.
2518: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2519: '</label></span> ';
2520: }
2521: }
2522: if ($context eq 'requestcourses') {
2523: $datatable .= '</tr><tr>';
2524: foreach my $item (@usertools) {
1.106 raeburn 2525: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2526: }
1.101 raeburn 2527: $datatable .= '</tr></table>';
1.72 raeburn 2528: }
1.98 raeburn 2529: $datatable .= '</td></tr>';
1.30 raeburn 2530: $$rowtotal += $typecount;
1.3 raeburn 2531: return $datatable;
2532: }
2533:
1.163 raeburn 2534: sub print_requestmail {
1.305 raeburn 2535: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2536: my ($now,$datatable,%currapp);
1.102 raeburn 2537: $now = time;
2538: if (ref($settings) eq 'HASH') {
2539: if (ref($settings->{'notify'}) eq 'HASH') {
2540: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2541: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2542: }
2543: }
2544: }
1.191 raeburn 2545: my $numinrow = 2;
1.224 raeburn 2546: my $css_class;
1.305 raeburn 2547: if ($$rowtotal%2) {
2548: $css_class = 'LC_odd_row';
2549: }
2550: if ($customcss) {
2551: $css_class .= " $customcss";
2552: }
2553: $css_class =~ s/^\s+//;
2554: if ($css_class) {
2555: $css_class = ' class="'.$css_class.'"';
2556: }
2557: if ($rowstyle) {
2558: $css_class .= ' style="'.$rowstyle.'"';
2559: }
1.163 raeburn 2560: my $text;
2561: if ($action eq 'requestcourses') {
2562: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2563: } elsif ($action eq 'requestauthor') {
2564: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2565: } else {
1.224 raeburn 2566: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2567: }
1.224 raeburn 2568: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2569: ' <td>'.$text.'</td>'.
1.102 raeburn 2570: ' <td class="LC_left_item">';
1.191 raeburn 2571: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2572: $action.'notifyapproval',%currapp);
1.191 raeburn 2573: if ($numdc > 0) {
2574: $datatable .= $table;
1.102 raeburn 2575: } else {
2576: $datatable .= &mt('There are no active Domain Coordinators');
2577: }
2578: $datatable .='</td></tr>';
2579: return $datatable;
2580: }
2581:
1.216 raeburn 2582: sub print_studentcode {
2583: my ($settings,$rowtotal) = @_;
2584: my $rownum = 0;
1.218 raeburn 2585: my ($output,%current);
1.325 raeburn 2586: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2587: if (ref($settings) eq 'HASH') {
2588: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2589: foreach my $type (@crstypes) {
2590: $current{$type} = $settings->{'uniquecode'}{$type};
2591: }
1.218 raeburn 2592: }
2593: }
2594: $output .= '<tr>'.
2595: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2596: '<td class="LC_left_item">';
2597: foreach my $type (@crstypes) {
2598: my $check = ' ';
2599: if ($current{$type}) {
2600: $check = ' checked="checked" ';
2601: }
2602: $output .= '<span class="LC_nobreak"><label>'.
2603: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2604: &mt($type).'</label></span>'.(' 'x2).' ';
2605: }
2606: $output .= '</td></tr>';
2607: $$rowtotal ++;
2608: return $output;
1.216 raeburn 2609: }
2610:
2611: sub print_textbookcourses {
1.242 raeburn 2612: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2613: my $rownum = 0;
2614: my $css_class;
2615: my $itemcount = 1;
2616: my $maxnum = 0;
2617: my $bookshash;
2618: if (ref($settings) eq 'HASH') {
1.242 raeburn 2619: $bookshash = $settings->{$type};
1.216 raeburn 2620: }
2621: my %ordered;
2622: if (ref($bookshash) eq 'HASH') {
2623: foreach my $item (keys(%{$bookshash})) {
2624: if (ref($bookshash->{$item}) eq 'HASH') {
2625: my $num = $bookshash->{$item}{'order'};
2626: $ordered{$num} = $item;
2627: }
2628: }
2629: }
2630: my $confname = $dom.'-domainconfig';
2631: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2632: my $maxnum = scalar(keys(%ordered));
2633: my $datatable;
1.216 raeburn 2634: if (keys(%ordered)) {
2635: my @items = sort { $a <=> $b } keys(%ordered);
2636: for (my $i=0; $i<@items; $i++) {
2637: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2638: my $key = $ordered{$items[$i]};
2639: my %coursehash=&Apache::lonnet::coursedescription($key);
2640: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2641: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2642: if (ref($bookshash->{$key}) eq 'HASH') {
2643: $subject = $bookshash->{$key}->{'subject'};
2644: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2645: if ($type eq 'textbooks') {
1.243 raeburn 2646: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2647: $author = $bookshash->{$key}->{'author'};
2648: $image = $bookshash->{$key}->{'image'};
2649: if ($image ne '') {
2650: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2651: my $imagethumb = "$path/tn-".$imagefile;
2652: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2653: }
1.216 raeburn 2654: }
2655: }
1.242 raeburn 2656: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2657: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2658: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2659: for (my $k=0; $k<=$maxnum; $k++) {
2660: my $vpos = $k+1;
2661: my $selstr;
2662: if ($k == $i) {
2663: $selstr = ' selected="selected" ';
2664: }
2665: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2666: }
2667: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2668: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2669: &mt('Delete?').'</label></span></td>'.
2670: '<td colspan="2">'.
1.242 raeburn 2671: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2672: (' 'x2).
1.242 raeburn 2673: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2674: if ($type eq 'textbooks') {
2675: $datatable .= (' 'x2).
1.243 raeburn 2676: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2677: (' 'x2).
1.242 raeburn 2678: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2679: (' 'x2).
2680: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2681: if ($image) {
1.267 raeburn 2682: $datatable .= $imgsrc.
1.242 raeburn 2683: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2684: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2685: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2686: }
2687: if ($switchserver) {
2688: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2689: } else {
2690: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2691: }
1.216 raeburn 2692: }
1.242 raeburn 2693: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2694: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2695: $coursetitle.'</span></td></tr>'."\n";
2696: $itemcount ++;
2697: }
2698: }
2699: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2700: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2701: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2702: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2703: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2704: for (my $k=0; $k<$maxnum+1; $k++) {
2705: my $vpos = $k+1;
2706: my $selstr;
2707: if ($k == $maxnum) {
2708: $selstr = ' selected="selected" ';
2709: }
2710: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2711: }
2712: $datatable .= '</select> '."\n".
1.334 raeburn 2713: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2714: '<td colspan="2">'.
1.242 raeburn 2715: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2716: (' 'x2).
1.242 raeburn 2717: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2718: (' 'x2);
2719: if ($type eq 'textbooks') {
1.243 raeburn 2720: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2721: (' 'x2).
2722: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2723: (' 'x2).
2724: '<span class="LC_nobreak">'.&mt('Image:').' ';
2725: if ($switchserver) {
2726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2727: } else {
2728: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2729: }
1.334 raeburn 2730: $datatable .= '</span>'."\n";
1.216 raeburn 2731: }
1.334 raeburn 2732: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2733: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2734: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2735: &Apache::loncommon::selectcourse_link
1.334 raeburn 2736: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2737: '</span></td>'."\n".
2738: '</tr>'."\n";
2739: $itemcount ++;
2740: return $datatable;
2741: }
2742:
1.217 raeburn 2743: sub textbookcourses_javascript {
1.242 raeburn 2744: my ($settings) = @_;
2745: return unless(ref($settings) eq 'HASH');
2746: my (%ordered,%total,%jstext);
2747: foreach my $type ('textbooks','templates') {
2748: $total{$type} = 0;
2749: if (ref($settings->{$type}) eq 'HASH') {
2750: foreach my $item (keys(%{$settings->{$type}})) {
2751: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2752: my $num = $settings->{$type}->{$item}{'order'};
2753: $ordered{$type}{$num} = $item;
2754: }
2755: }
2756: $total{$type} = scalar(keys(%{$settings->{$type}}));
2757: }
2758: my @jsarray = ();
2759: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2760: push(@jsarray,$ordered{$type}{$item});
2761: }
2762: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2763: }
2764: return <<"ENDSCRIPT";
2765: <script type="text/javascript">
2766: // <![CDATA[
1.242 raeburn 2767: function reorderBooks(form,item,caller) {
1.217 raeburn 2768: var changedVal;
1.242 raeburn 2769: $jstext{'textbooks'};
2770: $jstext{'templates'};
2771: var newpos;
2772: var maxh;
2773: if (caller == 'textbooks') {
2774: newpos = 'textbooks_addbook_pos';
2775: maxh = 1 + $total{'textbooks'};
2776: } else {
2777: newpos = 'templates_addbook_pos';
2778: maxh = 1 + $total{'templates'};
2779: }
1.217 raeburn 2780: var current = new Array;
2781: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2782: if (item == newpos) {
2783: changedVal = newitemVal;
2784: } else {
2785: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2786: current[newitemVal] = newpos;
2787: }
1.242 raeburn 2788: if (caller == 'textbooks') {
2789: for (var i=0; i<textbooks.length; i++) {
2790: var elementName = 'textbooks_'+textbooks[i];
2791: if (elementName != item) {
2792: if (form.elements[elementName]) {
2793: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2794: current[currVal] = elementName;
2795: }
2796: }
2797: }
2798: }
2799: if (caller == 'templates') {
2800: for (var i=0; i<templates.length; i++) {
2801: var elementName = 'templates_'+templates[i];
2802: if (elementName != item) {
2803: if (form.elements[elementName]) {
2804: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2805: current[currVal] = elementName;
2806: }
1.217 raeburn 2807: }
2808: }
2809: }
2810: var oldVal;
2811: for (var j=0; j<maxh; j++) {
2812: if (current[j] == undefined) {
2813: oldVal = j;
2814: }
2815: }
2816: if (oldVal < changedVal) {
2817: for (var k=oldVal+1; k<=changedVal ; k++) {
2818: var elementName = current[k];
2819: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2820: }
2821: } else {
2822: for (var k=changedVal; k<oldVal; k++) {
2823: var elementName = current[k];
2824: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2825: }
2826: }
2827: return;
2828: }
2829:
2830: // ]]>
2831: </script>
2832:
2833: ENDSCRIPT
2834: }
2835:
1.267 raeburn 2836: sub ltitools_javascript {
2837: my ($settings) = @_;
1.319 raeburn 2838: my $togglejs = <itools_toggle_js();
2839: unless (ref($settings) eq 'HASH') {
2840: return $togglejs;
2841: }
1.267 raeburn 2842: my (%ordered,$total,%jstext);
2843: $total = 0;
2844: foreach my $item (keys(%{$settings})) {
2845: if (ref($settings->{$item}) eq 'HASH') {
2846: my $num = $settings->{$item}{'order'};
2847: $ordered{$num} = $item;
2848: }
2849: }
2850: $total = scalar(keys(%{$settings}));
2851: my @jsarray = ();
2852: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2853: push(@jsarray,$ordered{$item});
2854: }
2855: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2856: return <<"ENDSCRIPT";
2857: <script type="text/javascript">
2858: // <![CDATA[
1.319 raeburn 2859: function reorderLTITools(form,item) {
1.267 raeburn 2860: var changedVal;
2861: $jstext
2862: var newpos = 'ltitools_add_pos';
2863: var maxh = 1 + $total;
2864: var current = new Array;
2865: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2866: if (item == newpos) {
2867: changedVal = newitemVal;
2868: } else {
2869: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2870: current[newitemVal] = newpos;
2871: }
2872: for (var i=0; i<ltitools.length; i++) {
2873: var elementName = 'ltitools_'+ltitools[i];
2874: if (elementName != item) {
2875: if (form.elements[elementName]) {
2876: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2877: current[currVal] = elementName;
2878: }
2879: }
2880: }
2881: var oldVal;
2882: for (var j=0; j<maxh; j++) {
2883: if (current[j] == undefined) {
2884: oldVal = j;
2885: }
2886: }
2887: if (oldVal < changedVal) {
2888: for (var k=oldVal+1; k<=changedVal ; k++) {
2889: var elementName = current[k];
2890: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2891: }
2892: } else {
2893: for (var k=changedVal; k<oldVal; k++) {
2894: var elementName = current[k];
2895: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2896: }
2897: }
2898: return;
2899: }
2900:
2901: // ]]>
2902: </script>
2903:
1.319 raeburn 2904: $togglejs
2905:
2906: ENDSCRIPT
2907: }
2908:
2909: sub ltitools_toggle_js {
2910: return <<"ENDSCRIPT";
2911: <script type="text/javascript">
2912: // <![CDATA[
2913:
2914: function toggleLTITools(form,setting,item) {
2915: var radioname = '';
2916: var divid = '';
2917: if ((setting == 'passback') || (setting == 'roster')) {
2918: radioname = 'ltitools_'+setting+'_'+item;
2919: divid = 'ltitools_'+setting+'time_'+item;
2920: var num = form.elements[radioname].length;
2921: if (num) {
2922: var setvis = '';
2923: for (var i=0; i<num; i++) {
2924: if (form.elements[radioname][i].checked) {
2925: if (form.elements[radioname][i].value == '1') {
2926: if (document.getElementById(divid)) {
2927: document.getElementById(divid).style.display = 'inline-block';
2928: }
2929: setvis = 1;
2930: }
2931: break;
2932: }
2933: }
2934: }
2935: if (!setvis) {
2936: if (document.getElementById(divid)) {
2937: document.getElementById(divid).style.display = 'none';
2938: }
2939: }
2940: }
1.324 raeburn 2941: if (setting == 'user') {
2942: divid = 'ltitools_'+setting+'_div_'+item;
2943: var checkid = 'ltitools_'+setting+'_field_'+item;
2944: if (document.getElementById(divid)) {
2945: if (document.getElementById(checkid)) {
2946: if (document.getElementById(checkid).checked) {
2947: document.getElementById(divid).style.display = 'inline-block';
2948: } else {
2949: document.getElementById(divid).style.display = 'none';
2950: }
2951: }
2952: }
2953: }
1.319 raeburn 2954: return;
2955: }
2956: // ]]>
2957: </script>
2958:
1.267 raeburn 2959: ENDSCRIPT
2960: }
2961:
1.381 raeburn 2962: sub wafproxy_javascript {
2963: my ($dom) = @_;
2964: return <<"ENDSCRIPT";
2965: <script type="text/javascript">
2966: // <![CDATA[
2967: function updateWAF() {
2968: if (document.getElementById('wafproxy_remoteip')) {
2969: var wafremote = 0;
2970: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2971: wafremote = 1;
2972: }
2973: var fields = new Array('header','trust');
2974: for (var i=0; i<fields.length; i++) {
2975: if (document.getElementById('wafproxy_'+fields[i])) {
2976: if (wafremote == 1) {
2977: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2978: }
2979: else {
2980: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2981: }
2982: }
2983: }
2984: if (document.getElementById('wafproxyranges_$dom')) {
2985: if (wafremote == 1) {
2986: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2987: } else {
2988: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2989: if (document.display.wafproxy_vpnaccess[i].checked) {
2990: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2991: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2992: }
2993: }
2994: }
2995: }
2996: }
2997: }
2998: return;
2999: }
3000:
3001: function checkWAF() {
3002: if (document.getElementById('wafproxy_remoteip')) {
3003: var wafvpn = 0;
3004: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3005: if (document.display.wafproxy_vpnaccess[i].checked) {
3006: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3007: wafvpn = 1;
3008: }
3009: break;
3010: }
3011: }
3012: var vpn = new Array('vpnint','vpnext');
3013: for (var i=0; i<vpn.length; i++) {
3014: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3015: if (wafvpn == 1) {
3016: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3017: }
3018: else {
3019: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3020: }
3021: }
3022: }
3023: if (document.getElementById('wafproxyranges_$dom')) {
3024: if (wafvpn == 1) {
3025: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3026: }
3027: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3028: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3029: }
3030: }
3031: }
3032: return;
3033: }
3034:
3035: function toggleWAF() {
3036: if (document.getElementById('wafproxy_table')) {
3037: var wafproxy = 0;
3038: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3039: if (document.display.wafproxy_${dom}[i].checked) {
3040: if (document.display.wafproxy_${dom}[i].value == 1) {
3041: wafproxy = 1;
3042: break;
3043: }
3044: }
3045: }
3046: if (wafproxy == 1) {
3047: document.getElementById('wafproxy_table').style.display='inline';
3048: }
3049: else {
3050: document.getElementById('wafproxy_table').style.display='none';
3051: }
3052: if (document.getElementById('wafproxyrow_${dom}')) {
3053: if (wafproxy == 1) {
3054: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3055: }
3056: else {
3057: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3058: }
3059: }
3060: if (document.getElementById('nowafproxyrow_$dom')) {
3061: if (wafproxy == 1) {
3062: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3063: }
3064: else {
3065: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3066: }
3067: }
3068: }
3069: return;
3070: }
3071: // ]]>
3072: </script>
3073:
3074: ENDSCRIPT
3075: }
3076:
1.372 raeburn 3077: sub proctoring_javascript {
3078: my ($settings) = @_;
3079: my (%ordered,$total,%jstext);
3080: $total = 0;
3081: if (ref($settings) eq 'HASH') {
3082: foreach my $item (keys(%{$settings})) {
3083: if (ref($settings->{$item}) eq 'HASH') {
3084: my $num = $settings->{$item}{'order'};
3085: $ordered{$num} = $item;
3086: }
3087: }
3088: $total = scalar(keys(%{$settings}));
3089: } else {
3090: %ordered = (
3091: 0 => 'proctorio',
3092: 1 => 'examity',
3093: );
3094: $total = 2;
3095: }
3096: my @jsarray = ();
3097: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3098: push(@jsarray,$ordered{$item});
3099: }
3100: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3101: return <<"ENDSCRIPT";
3102: <script type="text/javascript">
3103: // <![CDATA[
3104: function reorderProctoring(form,item) {
3105: var changedVal;
3106: $jstext
3107: var maxh = $total;
3108: var current = new Array;
3109: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3110: for (var i=0; i<proctors.length; i++) {
3111: var elementName = 'proctoring_pos_'+proctors[i];
3112: if (elementName != item) {
3113: if (form.elements[elementName]) {
3114: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3115: current[currVal] = elementName;
3116: }
3117: }
3118: }
3119: var oldVal;
3120: for (var j=0; j<maxh; j++) {
3121: if (current[j] == undefined) {
3122: oldVal = j;
3123: }
3124: }
3125: if (oldVal < changedVal) {
3126: for (var k=oldVal+1; k<=changedVal ; k++) {
3127: var elementName = current[k];
3128: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3129: }
3130: } else {
3131: for (var k=changedVal; k<oldVal; k++) {
3132: var elementName = current[k];
3133: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3134: }
3135: }
3136: return;
3137: }
3138:
3139: function toggleProctoring(form,item) {
3140: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3141: if (fieldsets.length) {
3142: var radioname = 'proctoring_available_'+item;
3143: var num = form.elements[radioname].length;
3144: if (num) {
3145: var setvis = '';
3146: for (var i=0; i<num; i++) {
3147: if (form.elements[radioname][i].checked) {
3148: if (form.elements[radioname][i].value == '1') {
3149: setvis = 1;
3150: break;
3151: }
3152: }
3153: }
3154: for (var j=0; j<fieldsets.length; j++) {
3155: if (setvis) {
3156: fieldsets[j].style.display = 'block';
3157: } else {
3158: fieldsets[j].style.display = 'none';
3159: }
3160: }
3161: }
3162: }
3163: return;
3164: }
3165:
3166: // ]]>
3167: </script>
3168:
3169: ENDSCRIPT
3170: }
3171:
3172:
1.320 raeburn 3173: sub lti_javascript {
3174: my ($settings) = @_;
3175: my $togglejs = <i_toggle_js();
3176: unless (ref($settings) eq 'HASH') {
3177: return $togglejs;
3178: }
3179: my (%ordered,$total,%jstext);
1.390 raeburn 3180: $total = scalar(keys(%{$settings}));
1.320 raeburn 3181: foreach my $item (keys(%{$settings})) {
3182: if (ref($settings->{$item}) eq 'HASH') {
3183: my $num = $settings->{$item}{'order'};
1.390 raeburn 3184: if ($num eq '') {
3185: $num = $total - 1;
3186: }
1.320 raeburn 3187: $ordered{$num} = $item;
3188: }
3189: }
3190: my @jsarray = ();
3191: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3192: push(@jsarray,$ordered{$item});
3193: }
3194: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3195: return <<"ENDSCRIPT";
3196: <script type="text/javascript">
3197: // <![CDATA[
3198: function reorderLTI(form,item) {
3199: var changedVal;
3200: $jstext
3201: var newpos = 'lti_pos_add';
3202: var maxh = 1 + $total;
3203: var current = new Array;
3204: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3205: if (item == newpos) {
3206: changedVal = newitemVal;
3207: } else {
3208: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3209: current[newitemVal] = newpos;
3210: }
3211: for (var i=0; i<lti.length; i++) {
3212: var elementName = 'lti_pos_'+lti[i];
3213: if (elementName != item) {
3214: if (form.elements[elementName]) {
3215: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3216: current[currVal] = elementName;
3217: }
3218: }
3219: }
3220: var oldVal;
3221: for (var j=0; j<maxh; j++) {
3222: if (current[j] == undefined) {
3223: oldVal = j;
3224: }
3225: }
3226: if (oldVal < changedVal) {
3227: for (var k=oldVal+1; k<=changedVal ; k++) {
3228: var elementName = current[k];
3229: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3230: }
3231: } else {
3232: for (var k=changedVal; k<oldVal; k++) {
3233: var elementName = current[k];
3234: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3235: }
3236: }
3237: return;
3238: }
3239: // ]]>
3240: </script>
3241:
3242: $togglejs
3243:
3244: ENDSCRIPT
3245: }
3246:
3247: sub lti_toggle_js {
1.325 raeburn 3248: my %lcauthparmtext = &Apache::lonlocal::texthash (
3249: localauth => 'Local auth argument',
3250: krb => 'Kerberos domain',
3251: );
1.391 ! raeburn 3252: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
! 3253: &js_escape(\$crsincalert);
1.320 raeburn 3254: return <<"ENDSCRIPT";
3255: <script type="text/javascript">
3256: // <![CDATA[
3257:
3258: function toggleLTI(form,setting,item) {
1.391 ! raeburn 3259: if ((setting == 'requser') || (setting == 'crsinc')) {
! 3260: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
! 3261: var setvis = '';
! 3262: var radioname = 'lti_requser_'+item;
! 3263: var num = form.elements[radioname].length;
! 3264: if (num) {
! 3265: for (var i=0; i<num; i++) {
! 3266: if (form.elements[radioname][i].checked) {
! 3267: if (form.elements[radioname][i].value == '1') {
! 3268: setvis = 1;
! 3269: break;
! 3270: }
! 3271: }
! 3272: }
! 3273: }
! 3274: if (usrfieldsets.length) {
! 3275: for (var j=0; j<usrfieldsets.length; j++) {
! 3276: if (setvis) {
! 3277: usrfieldsets[j].style.display = 'block';
! 3278: } else {
! 3279: usrfieldsets[j].style.display = 'none';
! 3280: }
! 3281: }
! 3282: }
! 3283: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
! 3284: if (crsfieldsets.length) {
! 3285: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3286: var num = form.elements[radioname].length;
3287: if (num) {
1.391 ! raeburn 3288: var crsvis = '';
1.345 raeburn 3289: for (var i=0; i<num; i++) {
3290: if (form.elements[radioname][i].checked) {
3291: if (form.elements[radioname][i].value == '1') {
1.391 ! raeburn 3292: if (setvis == '') {
! 3293: if (setting == 'crsinc'){
! 3294: alert("$crsincalert");
! 3295: form.elements[radioname][0].checked = true;
! 3296: }
! 3297: } else {
! 3298: crsvis = 1;
! 3299: }
! 3300: break;
1.345 raeburn 3301: }
3302: }
3303: }
1.391 ! raeburn 3304: setvis = crsvis;
! 3305: }
! 3306: for (var j=0; j<crsfieldsets.length; j++) {
! 3307: if (setvis) {
! 3308: crsfieldsets[j].style.display = 'block';
! 3309: } else {
! 3310: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3311: }
3312: }
3313: }
1.363 raeburn 3314: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3315: var radioname = '';
3316: var divid = '';
3317: if (setting == 'user') {
3318: radioname = 'lti_mapuser_'+item;
3319: divid = 'lti_userfield_'+item;
1.343 raeburn 3320: } else if (setting == 'crs') {
1.320 raeburn 3321: radioname = 'lti_mapcrs_'+item;
3322: divid = 'lti_crsfield_'+item;
1.363 raeburn 3323: } else if (setting == 'callback') {
3324: radioname = 'lti_callback_'+item;
3325: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3326: } else {
1.351 raeburn 3327: radioname = 'lti_passback_'+item;
1.337 raeburn 3328: divid = 'lti_passback_'+item;
1.320 raeburn 3329: }
3330: var num = form.elements[radioname].length;
3331: if (num) {
3332: var setvis = '';
3333: for (var i=0; i<num; i++) {
3334: if (form.elements[radioname][i].checked) {
1.363 raeburn 3335: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3336: if (form.elements[radioname][i].value == '1') {
3337: if (document.getElementById(divid)) {
3338: document.getElementById(divid).style.display = 'inline-block';
3339: }
3340: setvis = 1;
3341: break;
3342: }
3343: } else {
3344: if (form.elements[radioname][i].value == 'other') {
3345: if (document.getElementById(divid)) {
3346: document.getElementById(divid).style.display = 'inline-block';
3347: }
3348: setvis = 1;
3349: break;
1.320 raeburn 3350: }
3351: }
3352: }
3353: }
3354: if (!setvis) {
3355: if (document.getElementById(divid)) {
3356: document.getElementById(divid).style.display = 'none';
3357: }
3358: }
3359: }
3360: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3361: var numsec = form.elements['lti_crssec_'+item].length;
3362: if (numsec) {
3363: var setvis = '';
3364: for (var i=0; i<numsec; i++) {
3365: if (form.elements['lti_crssec_'+item][i].checked) {
3366: if (form.elements['lti_crssec_'+item][i].value == '1') {
3367: if (document.getElementById('lti_crssecfield_'+item)) {
3368: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3369: setvis = 1;
3370: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3371: if (numsrcsec) {
3372: var setsrcvis = '';
3373: for (var j=0; j<numsrcsec; j++) {
3374: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3375: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3376: if (document.getElementById('lti_secsrcfield_'+item)) {
3377: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3378: setsrcvis = 1;
3379: }
3380: }
3381: }
3382: }
3383: if (!setsrcvis) {
3384: if (document.getElementById('lti_secsrcfield_'+item)) {
3385: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3386: }
3387: }
3388: }
3389: }
3390: }
3391: }
3392: }
3393: if (!setvis) {
3394: if (document.getElementById('lti_crssecfield_'+item)) {
3395: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3396: }
3397: if (document.getElementById('lti_secsrcfield_'+item)) {
3398: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3399: }
3400: }
3401: }
1.325 raeburn 3402: } else if (setting == 'lcauth') {
3403: var numauth = form.elements['lti_lcauth_'+item].length;
3404: if (numauth) {
3405: for (var i=0; i<numauth; i++) {
3406: if (form.elements['lti_lcauth_'+item][i].checked) {
3407: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3408: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3409: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3410: } else {
3411: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3412: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3413: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3414: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3415: } else {
3416: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3417: }
3418: }
3419: }
3420: }
3421: }
3422: }
3423: }
1.326 raeburn 3424: } else if (setting == 'lcmenu') {
3425: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3426: var divid = 'lti_menufield_'+item;
3427: var setvis = '';
3428: for (var i=0; i<menus.length; i++) {
3429: var radioname = menus[i];
3430: var num = form.elements[radioname].length;
3431: if (num) {
3432: for (var j=0; j<num; j++) {
3433: if (form.elements[radioname][j].checked) {
3434: if (form.elements[radioname][j].value == '1') {
3435: if (document.getElementById(divid)) {
3436: document.getElementById(divid).style.display = 'inline-block';
3437: }
3438: setvis = 1;
3439: break;
3440: }
3441: }
3442: }
3443: }
3444: if (setvis == 1) {
3445: break;
3446: }
3447: }
3448: if (!setvis) {
3449: if (document.getElementById(divid)) {
3450: document.getElementById(divid).style.display = 'none';
3451: }
3452: }
1.320 raeburn 3453: }
3454: return;
3455: }
3456: // ]]>
3457: </script>
3458:
3459: ENDSCRIPT
3460: }
3461:
1.385 raeburn 3462: sub autoupdate_javascript {
3463: return <<"ENDSCRIPT";
3464: <script type="text/javascript">
3465: // <![CDATA[
3466: function toggleLastActiveDays(form) {
3467: var radioname = 'lastactive';
3468: var divid = 'lastactive_div';
3469: var num = form.elements[radioname].length;
3470: if (num) {
3471: var setvis = '';
3472: for (var i=0; i<num; i++) {
3473: if (form.elements[radioname][i].checked) {
3474: if (form.elements[radioname][i].value == '1') {
3475: if (document.getElementById(divid)) {
3476: document.getElementById(divid).style.display = 'inline-block';
3477: }
3478: setvis = 1;
3479: }
3480: break;
3481: }
3482: }
3483: if (!setvis) {
3484: if (document.getElementById(divid)) {
3485: document.getElementById(divid).style.display = 'none';
3486: }
3487: }
3488: }
3489: return;
3490: }
3491: // ]]>
3492: </script>
3493:
3494: ENDSCRIPT
3495: }
3496:
1.386 raeburn 3497: sub saml_javascript {
3498: return <<"ENDSCRIPT";
3499: <script type="text/javascript">
3500: // <![CDATA[
3501: function toggleSamlOptions(form,hostid) {
3502: var radioname = 'saml_'+hostid;
3503: var tablecellon = 'samloptionson_'+hostid;
3504: var tablecelloff = 'samloptionsoff_'+hostid;
3505: var num = form.elements[radioname].length;
3506: if (num) {
3507: var setvis = '';
3508: for (var i=0; i<num; i++) {
3509: if (form.elements[radioname][i].checked) {
3510: if (form.elements[radioname][i].value == '1') {
3511: if (document.getElementById(tablecellon)) {
3512: document.getElementById(tablecellon).style.display='';
3513: }
3514: if (document.getElementById(tablecelloff)) {
3515: document.getElementById(tablecelloff).style.display='none';
3516: }
3517: setvis = 1;
3518: }
3519: break;
3520: }
3521: }
3522: if (!setvis) {
3523: if (document.getElementById(tablecellon)) {
3524: document.getElementById(tablecellon).style.display='none';
3525: }
3526: if (document.getElementById(tablecelloff)) {
3527: document.getElementById(tablecelloff).style.display='';
3528: }
3529: }
3530: }
3531: return;
3532: }
3533: // ]]>
3534: </script>
3535:
3536: ENDSCRIPT
3537: }
3538:
1.3 raeburn 3539: sub print_autoenroll {
1.30 raeburn 3540: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3541: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3542: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3543: if (ref($settings) eq 'HASH') {
3544: if (exists($settings->{'run'})) {
3545: if ($settings->{'run'} eq '0') {
3546: $runoff = ' checked="checked" ';
3547: $runon = ' ';
3548: } else {
3549: $runon = ' checked="checked" ';
3550: $runoff = ' ';
3551: }
3552: } else {
3553: if ($autorun) {
3554: $runon = ' checked="checked" ';
3555: $runoff = ' ';
3556: } else {
3557: $runoff = ' checked="checked" ';
3558: $runon = ' ';
3559: }
3560: }
1.129 raeburn 3561: if (exists($settings->{'co-owners'})) {
3562: if ($settings->{'co-owners'} eq '0') {
3563: $coownersoff = ' checked="checked" ';
3564: $coownerson = ' ';
3565: } else {
3566: $coownerson = ' checked="checked" ';
3567: $coownersoff = ' ';
3568: }
3569: } else {
3570: $coownersoff = ' checked="checked" ';
3571: $coownerson = ' ';
3572: }
1.3 raeburn 3573: if (exists($settings->{'sender_domain'})) {
3574: $defdom = $settings->{'sender_domain'};
3575: }
1.274 raeburn 3576: if (exists($settings->{'autofailsafe'})) {
3577: $failsafe = $settings->{'autofailsafe'};
3578: }
1.14 raeburn 3579: } else {
3580: if ($autorun) {
3581: $runon = ' checked="checked" ';
3582: $runoff = ' ';
3583: } else {
3584: $runoff = ' checked="checked" ';
3585: $runon = ' ';
3586: }
1.3 raeburn 3587: }
3588: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3589: my $notif_sender;
3590: if (ref($settings) eq 'HASH') {
3591: $notif_sender = $settings->{'sender_uname'};
3592: }
1.3 raeburn 3593: my $datatable='<tr class="LC_odd_row">'.
3594: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3595: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3596: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3597: $runon.' value="1" />'.&mt('Yes').'</label> '.
3598: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3599: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3600: '</tr><tr>'.
3601: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3602: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3603: &mt('username').': '.
3604: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3605: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3606: ': '.$domform.'</span></td></tr>'.
3607: '<tr class="LC_odd_row">'.
3608: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3609: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3610: '<input type="radio" name="autoassign_coowners"'.
3611: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3612: '<label><input type="radio" name="autoassign_coowners"'.
3613: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3614: '</tr><tr>'.
3615: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3616: '<td class="LC_right_item"><span class="LC_nobreak">'.
3617: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3618: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3619: $$rowtotal += 4;
1.3 raeburn 3620: return $datatable;
3621: }
3622:
3623: sub print_autoupdate {
1.30 raeburn 3624: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 3625: my ($enable,$datatable);
1.3 raeburn 3626: if ($position eq 'top') {
1.385 raeburn 3627: my %choices = &Apache::lonlocal::texthash (
3628: run => 'Auto-update active?',
3629: classlists => 'Update information in classlists?',
3630: unexpired => 'Skip updates for users without active or future roles?',
3631: lastactive => 'Skip updates for inactive users?',
3632: );
3633: my $itemcount = 0;
1.3 raeburn 3634: my $updateon = ' ';
3635: my $updateoff = ' checked="checked" ';
3636: if (ref($settings) eq 'HASH') {
3637: if ($settings->{'run'} eq '1') {
3638: $updateon = $updateoff;
3639: $updateoff = ' ';
3640: }
3641: }
1.385 raeburn 3642: $enable = '<tr class="LC_odd_row">'.
3643: '<td>'.$choices{'run'}.'</td>'.
3644: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3645: '<input type="radio" name="autoupdate_run"'.
1.385 raeburn 3646: $updateoff.' value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3647: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 3648: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3649: '</tr>';
1.385 raeburn 3650: my @toggles = ('classlists','unexpired');
3651: my %defaultchecked = ('classlists' => 'off',
3652: 'unexpired' => 'off'
3653: );
3654: $$rowtotal ++;
3655: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3656: \%choices,$itemcount,'','','left','no');
3657: $datatable = $enable.$datatable;
3658: $$rowtotal += $itemcount;
3659: my $lastactiveon = ' ';
3660: my $lastactiveoff = ' checked="checked" ';
3661: my $lastactivestyle = 'none';
3662: my $lastactivedays;
3663: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3664: if (ref($settings) eq 'HASH') {
3665: if ($settings->{'lastactive'} =~ /^\d+$/) {
3666: $lastactiveon = $lastactiveoff;
3667: $lastactiveoff = ' ';
3668: $lastactivestyle = 'inline-block';
3669: $lastactivedays = $settings->{'lastactive'};
3670: }
3671: }
3672: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3673: $datatable .= '<tr'.$css_class.'>'.
3674: '<td>'.$choices{'lastactive'}.'</td>'.
3675: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3676: '<input type="radio" name="lastactive"'.
3677: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3678: ' <label>'.
3679: '<input type="radio" name="lastactive"'.
3680: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3681: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3682: ': '.&mt('inactive = no activity in last [_1] days',
3683: '<input type="text" size="5" name="lastactivedays" value="'.
3684: $lastactivedays.'" />').
3685: '</span></td>'.
3686: '</tr>';
3687: $$rowtotal ++;
1.131 raeburn 3688: } elsif ($position eq 'middle') {
3689: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3690: my $numinrow = 3;
3691: my $locknamesettings;
3692: $datatable .= &insttypes_row($settings,$types,$usertypes,
3693: $dom,$numinrow,$othertitle,
1.305 raeburn 3694: 'lockablenames',$rowtotal);
1.131 raeburn 3695: $$rowtotal ++;
1.3 raeburn 3696: } else {
1.44 raeburn 3697: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3698: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3699: 'permanentemail','id');
1.33 raeburn 3700: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3701: my $numrows = 0;
1.26 raeburn 3702: if (ref($types) eq 'ARRAY') {
3703: if (@{$types} > 0) {
3704: $datatable =
3705: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3706: \@fields,$types,\$numrows);
1.30 raeburn 3707: $$rowtotal += @{$types};
1.26 raeburn 3708: }
1.3 raeburn 3709: }
3710: $datatable .=
3711: &usertype_update_row($settings,{'default' => $othertitle},
3712: \%fieldtitles,\@fields,['default'],
3713: \$numrows);
1.30 raeburn 3714: $$rowtotal ++;
1.3 raeburn 3715: }
3716: return $datatable;
3717: }
3718:
1.125 raeburn 3719: sub print_autocreate {
3720: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3721: my (%createon,%createoff,%currhash);
1.125 raeburn 3722: my @types = ('xml','req');
3723: if (ref($settings) eq 'HASH') {
3724: foreach my $item (@types) {
3725: $createoff{$item} = ' checked="checked" ';
3726: $createon{$item} = ' ';
3727: if (exists($settings->{$item})) {
3728: if ($settings->{$item}) {
3729: $createon{$item} = ' checked="checked" ';
3730: $createoff{$item} = ' ';
3731: }
3732: }
3733: }
1.210 raeburn 3734: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3735: $currhash{$settings->{'xmldc'}} = 1;
3736: }
1.125 raeburn 3737: } else {
3738: foreach my $item (@types) {
3739: $createoff{$item} = ' checked="checked" ';
3740: $createon{$item} = ' ';
3741: }
3742: }
3743: $$rowtotal += 2;
1.191 raeburn 3744: my $numinrow = 2;
1.125 raeburn 3745: my $datatable='<tr class="LC_odd_row">'.
3746: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3747: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3748: '<input type="radio" name="autocreate_xml"'.
3749: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3750: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3751: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3752: '</td></tr><tr>'.
3753: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3754: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3755: '<input type="radio" name="autocreate_req"'.
3756: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3757: '<label><input type="radio" name="autocreate_req"'.
3758: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3759: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3760: 'autocreate_xmldc',%currhash);
1.247 raeburn 3761: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3762: if ($numdc > 1) {
1.247 raeburn 3763: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3764: '</td><td class="LC_left_item">';
1.125 raeburn 3765: } else {
1.247 raeburn 3766: $datatable .= &mt('Course creation processed as:').
3767: '</td><td class="LC_right_item">';
1.125 raeburn 3768: }
1.247 raeburn 3769: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3770: $$rowtotal += $rows;
1.125 raeburn 3771: return $datatable;
3772: }
3773:
1.23 raeburn 3774: sub print_directorysrch {
1.277 raeburn 3775: my ($position,$dom,$settings,$rowtotal) = @_;
3776: my $datatable;
3777: if ($position eq 'top') {
3778: my $instsrchon = ' ';
3779: my $instsrchoff = ' checked="checked" ';
3780: my ($exacton,$containson,$beginson);
3781: my $instlocalon = ' ';
3782: my $instlocaloff = ' checked="checked" ';
3783: if (ref($settings) eq 'HASH') {
3784: if ($settings->{'available'} eq '1') {
3785: $instsrchon = $instsrchoff;
3786: $instsrchoff = ' ';
3787: }
3788: if ($settings->{'localonly'} eq '1') {
3789: $instlocalon = $instlocaloff;
3790: $instlocaloff = ' ';
3791: }
3792: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3793: foreach my $type (@{$settings->{'searchtypes'}}) {
3794: if ($type eq 'exact') {
3795: $exacton = ' checked="checked" ';
3796: } elsif ($type eq 'contains') {
3797: $containson = ' checked="checked" ';
3798: } elsif ($type eq 'begins') {
3799: $beginson = ' checked="checked" ';
3800: }
3801: }
3802: } else {
3803: if ($settings->{'searchtypes'} eq 'exact') {
3804: $exacton = ' checked="checked" ';
3805: } elsif ($settings->{'searchtypes'} eq 'contains') {
3806: $containson = ' checked="checked" ';
3807: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3808: $exacton = ' checked="checked" ';
3809: $containson = ' checked="checked" ';
3810: }
3811: }
1.277 raeburn 3812: }
3813: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3814: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3815:
3816: my $numinrow = 4;
3817: my $cansrchrow = 0;
3818: $datatable='<tr class="LC_odd_row">'.
3819: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3820: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3821: '<input type="radio" name="dirsrch_available"'.
3822: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3823: '<label><input type="radio" name="dirsrch_available"'.
3824: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3825: '</tr><tr>'.
3826: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3827: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3828: '<input type="radio" name="dirsrch_instlocalonly"'.
3829: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3830: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3831: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3832: '</tr>';
3833: $$rowtotal += 2;
3834: if (ref($usertypes) eq 'HASH') {
3835: if (keys(%{$usertypes}) > 0) {
3836: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3837: $numinrow,$othertitle,'cansearch',
3838: $rowtotal);
1.277 raeburn 3839: $cansrchrow = 1;
1.25 raeburn 3840: }
1.23 raeburn 3841: }
1.277 raeburn 3842: if ($cansrchrow) {
3843: $$rowtotal ++;
3844: $datatable .= '<tr>';
3845: } else {
3846: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3847: }
1.277 raeburn 3848: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3849: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3850: foreach my $title (@{$titleorder}) {
3851: if (defined($searchtitles->{$title})) {
3852: my $check = ' ';
3853: if (ref($settings) eq 'HASH') {
3854: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3855: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3856: $check = ' checked="checked" ';
3857: }
1.39 raeburn 3858: }
1.25 raeburn 3859: }
1.277 raeburn 3860: $datatable .= '<td class="LC_left_item">'.
3861: '<span class="LC_nobreak"><label>'.
3862: '<input type="checkbox" name="searchby" '.
3863: 'value="'.$title.'"'.$check.'/>'.
3864: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3865: }
3866: }
1.277 raeburn 3867: $datatable .= '</tr></table></td></tr>';
3868: $$rowtotal ++;
3869: if ($cansrchrow) {
3870: $datatable .= '<tr class="LC_odd_row">';
3871: } else {
3872: $datatable .= '<tr>';
3873: }
3874: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3875: '<td class="LC_left_item" colspan="2">'.
3876: '<span class="LC_nobreak"><label>'.
3877: '<input type="checkbox" name="searchtypes" '.
3878: $exacton.' value="exact" />'.&mt('Exact match').
3879: '</label> '.
3880: '<label><input type="checkbox" name="searchtypes" '.
3881: $beginson.' value="begins" />'.&mt('Begins with').
3882: '</label> '.
3883: '<label><input type="checkbox" name="searchtypes" '.
3884: $containson.' value="contains" />'.&mt('Contains').
3885: '</label></span></td></tr>';
3886: $$rowtotal ++;
1.26 raeburn 3887: } else {
1.277 raeburn 3888: my $domsrchon = ' checked="checked" ';
3889: my $domsrchoff = ' ';
3890: my $domlocalon = ' ';
3891: my $domlocaloff = ' checked="checked" ';
3892: if (ref($settings) eq 'HASH') {
3893: if ($settings->{'lclocalonly'} eq '1') {
3894: $domlocalon = $domlocaloff;
3895: $domlocaloff = ' ';
3896: }
3897: if ($settings->{'lcavailable'} eq '0') {
3898: $domsrchoff = $domsrchon;
3899: $domsrchon = ' ';
3900: }
3901: }
3902: $datatable='<tr class="LC_odd_row">'.
3903: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3904: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3905: '<input type="radio" name="dirsrch_domavailable"'.
3906: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3907: '<label><input type="radio" name="dirsrch_domavailable"'.
3908: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3909: '</tr><tr>'.
3910: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3911: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3912: '<input type="radio" name="dirsrch_domlocalonly"'.
3913: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3914: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3915: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3916: '</tr>';
3917: $$rowtotal += 2;
1.26 raeburn 3918: }
1.25 raeburn 3919: return $datatable;
3920: }
3921:
1.28 raeburn 3922: sub print_contacts {
1.286 raeburn 3923: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3924: my $datatable;
3925: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3926: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3927: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3928: if ($position eq 'top') {
3929: if (ref($settings) eq 'HASH') {
3930: foreach my $item (@contacts) {
3931: if (exists($settings->{$item})) {
3932: $to{$item} = $settings->{$item};
3933: }
3934: }
3935: }
3936: } elsif ($position eq 'middle') {
3937: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3938: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3939: foreach my $type (@mailings) {
3940: $otheremails{$type} = '';
3941: }
1.340 raeburn 3942: } elsif ($position eq 'lower') {
3943: if (ref($settings) eq 'HASH') {
3944: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3945: %lonstatus = %{$settings->{'lonstatus'}};
3946: }
3947: }
1.286 raeburn 3948: } else {
3949: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3950: foreach my $type (@mailings) {
3951: $otheremails{$type} = '';
3952: }
1.286 raeburn 3953: $bccemails{'helpdeskmail'} = '';
3954: $bccemails{'otherdomsmail'} = '';
3955: $includestr{'helpdeskmail'} = '';
3956: $includestr{'otherdomsmail'} = '';
3957: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3958: }
1.28 raeburn 3959: if (ref($settings) eq 'HASH') {
1.340 raeburn 3960: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3961: foreach my $type (@mailings) {
3962: if (exists($settings->{$type})) {
3963: if (ref($settings->{$type}) eq 'HASH') {
3964: foreach my $item (@contacts) {
3965: if ($settings->{$type}{$item}) {
3966: $checked{$type}{$item} = ' checked="checked" ';
3967: }
3968: }
3969: $otheremails{$type} = $settings->{$type}{'others'};
3970: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3971: $bccemails{$type} = $settings->{$type}{'bcc'};
3972: if ($settings->{$type}{'include'} ne '') {
3973: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3974: $includestr{$type} = &unescape($includestr{$type});
3975: }
3976: }
3977: }
3978: } elsif ($type eq 'lonstatusmail') {
3979: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3980: }
1.28 raeburn 3981: }
3982: }
1.286 raeburn 3983: if ($position eq 'bottom') {
3984: foreach my $type (@mailings) {
3985: $bccemails{$type} = $settings->{$type}{'bcc'};
3986: if ($settings->{$type}{'include'} ne '') {
3987: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3988: $includestr{$type} = &unescape($includestr{$type});
3989: }
3990: }
3991: if (ref($settings->{'helpform'}) eq 'HASH') {
3992: if (ref($fields) eq 'ARRAY') {
3993: foreach my $field (@{$fields}) {
3994: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3995: }
1.286 raeburn 3996: }
3997: if (exists($settings->{'helpform'}{'maxsize'})) {
3998: $maxsize = $settings->{'helpform'}{'maxsize'};
3999: } else {
1.289 raeburn 4000: $maxsize = '1.0';
1.286 raeburn 4001: }
4002: } else {
4003: if (ref($fields) eq 'ARRAY') {
4004: foreach my $field (@{$fields}) {
4005: $currfield{$field} = 'yes';
1.134 raeburn 4006: }
1.28 raeburn 4007: }
1.286 raeburn 4008: $maxsize = '1.0';
1.28 raeburn 4009: }
4010: }
4011: } else {
1.286 raeburn 4012: if ($position eq 'top') {
4013: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4014: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4015: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4016: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4017: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4018: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4019: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4020: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4021: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4022: } elsif ($position eq 'bottom') {
4023: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4024: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4025: if (ref($fields) eq 'ARRAY') {
4026: foreach my $field (@{$fields}) {
4027: $currfield{$field} = 'yes';
4028: }
4029: }
4030: $maxsize = '1.0';
4031: }
1.28 raeburn 4032: }
4033: my ($titles,$short_titles) = &contact_titles();
4034: my $rownum = 0;
4035: my $css_class;
1.286 raeburn 4036: if ($position eq 'top') {
4037: foreach my $item (@contacts) {
4038: $css_class = $rownum%2?' class="LC_odd_row"':'';
4039: $datatable .= '<tr'.$css_class.'>'.
4040: '<td><span class="LC_nobreak">'.$titles->{$item}.
4041: '</span></td><td class="LC_right_item">'.
4042: '<input type="text" name="'.$item.'" value="'.
4043: $to{$item}.'" /></td></tr>';
4044: $rownum ++;
4045: }
1.315 raeburn 4046: } elsif ($position eq 'bottom') {
4047: $css_class = $rownum%2?' class="LC_odd_row"':'';
4048: $datatable .= '<tr'.$css_class.'>'.
4049: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4050: &mt('(e-mail, subject, and description always shown)').
4051: '</td><td class="LC_left_item">';
4052: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4053: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4054: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4055: foreach my $field (@{$fields}) {
4056: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4057: if (($field eq 'screenshot') || ($field eq 'cc')) {
4058: $datatable .= ' '.&mt('(logged-in users)');
4059: }
4060: $datatable .='</td><td>';
4061: my $clickaction;
4062: if ($field eq 'screenshot') {
4063: $clickaction = ' onclick="screenshotSize(this);"';
4064: }
4065: if (ref($possoptions->{$field}) eq 'ARRAY') {
4066: foreach my $option (@{$possoptions->{$field}}) {
4067: my $checked;
4068: if ($currfield{$field} eq $option) {
4069: $checked = ' checked="checked"';
4070: }
4071: $datatable .= '<span class="LC_nobreak"><label>'.
4072: '<input type="radio" name="helpform_'.$field.'" '.
4073: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4074: '</label></span>'.(' 'x2);
4075: }
4076: }
4077: if ($field eq 'screenshot') {
4078: my $display;
4079: if ($currfield{$field} eq 'no') {
4080: $display = ' style="display:none"';
4081: }
1.334 raeburn 4082: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4083: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4084: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4085: }
4086: $datatable .= '</td></tr>';
4087: }
4088: $datatable .= '</table>';
4089: }
4090: $datatable .= '</td></tr>'."\n";
4091: $rownum ++;
4092: }
1.340 raeburn 4093: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4094: foreach my $type (@mailings) {
4095: $css_class = $rownum%2?' class="LC_odd_row"':'';
4096: $datatable .= '<tr'.$css_class.'>'.
4097: '<td><span class="LC_nobreak">'.
4098: $titles->{$type}.': </span></td>'.
4099: '<td class="LC_left_item">';
4100: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4101: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4102: }
4103: $datatable .= '<span class="LC_nobreak">';
4104: foreach my $item (@contacts) {
4105: $datatable .= '<label>'.
4106: '<input type="checkbox" name="'.$type.'"'.
4107: $checked{$type}{$item}.
4108: ' value="'.$item.'" />'.$short_titles->{$item}.
4109: '</label> ';
4110: }
4111: $datatable .= '</span><br />'.&mt('Others').': '.
4112: '<input type="text" name="'.$type.'_others" '.
4113: 'value="'.$otheremails{$type}.'" />';
4114: my %locchecked;
4115: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4116: foreach my $loc ('s','b') {
4117: if ($includeloc{$type} eq $loc) {
4118: $locchecked{$loc} = ' checked="checked"';
4119: last;
4120: }
4121: }
4122: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4123: '<input type="text" name="'.$type.'_bcc" '.
4124: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4125: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4126: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4127: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4128: '<span class="LC_nobreak">'.&mt('Location:').' '.
4129: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4130: (' 'x2).
4131: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4132: '</span></fieldset>';
4133: }
4134: $datatable .= '</td></tr>'."\n";
4135: $rownum ++;
4136: }
1.28 raeburn 4137: }
1.286 raeburn 4138: if ($position eq 'middle') {
4139: my %choices;
1.340 raeburn 4140: my $corelink = &core_link_msu();
4141: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4142: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4143: $corelink);
4144: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4145: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4146: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4147: 'reportupdates' => 'on',
4148: 'reportstatus' => 'on');
1.286 raeburn 4149: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4150: \%choices,$rownum);
4151: $datatable .= $reports;
1.340 raeburn 4152: } elsif ($position eq 'lower') {
1.378 raeburn 4153: my (%current,%excluded,%weights);
1.340 raeburn 4154: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4155: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4156: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4157: } else {
1.378 raeburn 4158: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4159: }
4160: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4161: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4162: } else {
1.378 raeburn 4163: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4164: }
4165: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4166: foreach my $type ('E','W','N','U') {
1.340 raeburn 4167: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4168: $weights{$type} = $lonstatus{'weights'}{$type};
4169: } else {
4170: $weights{$type} = $defaults->{$type};
4171: }
4172: }
4173: } else {
1.341 raeburn 4174: foreach my $type ('E','W','N','U') {
1.340 raeburn 4175: $weights{$type} = $defaults->{$type};
4176: }
4177: }
4178: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4179: if (@{$lonstatus{'excluded'}} > 0) {
4180: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4181: }
4182: }
1.378 raeburn 4183: foreach my $item ('errorthreshold','errorsysmail') {
4184: $css_class = $rownum%2?' class="LC_odd_row"':'';
4185: $datatable .= '<tr'.$css_class.'>'.
4186: '<td class="LC_left_item"><span class="LC_nobreak">'.
4187: $titles->{$item}.
4188: '</span></td><td class="LC_left_item">'.
4189: '<input type="text" name="'.$item.'" value="'.
4190: $current{$item}.'" size="5" /></td></tr>';
4191: $rownum ++;
4192: }
1.340 raeburn 4193: $css_class = $rownum%2?' class="LC_odd_row"':'';
4194: $datatable .= '<tr'.$css_class.'>'.
4195: '<td class="LC_left_item">'.
4196: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4197: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4198: foreach my $type ('E','W','N','U') {
1.340 raeburn 4199: $datatable .= '<td>'.$names->{$type}.'<br />'.
4200: '<input type="text" name="errorweights_'.$type.'" value="'.
4201: $weights{$type}.'" size="5" /></td>';
4202: }
4203: $datatable .= '</tr></table></tr>';
4204: $rownum ++;
4205: $css_class = $rownum%2?' class="LC_odd_row"':'';
4206: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4207: $titles->{'errorexcluded'}.'</td>'.
4208: '<td class="LC_left_item"><table>';
4209: my $numinrow = 4;
4210: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4211: for (my $i=0; $i<@ids; $i++) {
4212: my $rem = $i%($numinrow);
4213: if ($rem == 0) {
4214: if ($i > 0) {
4215: $datatable .= '</tr>';
4216: }
4217: $datatable .= '<tr>';
4218: }
4219: my $check;
4220: if ($excluded{$ids[$i]}) {
4221: $check = ' checked="checked" ';
4222: }
4223: $datatable .= '<td class="LC_left_item">'.
4224: '<span class="LC_nobreak"><label>'.
4225: '<input type="checkbox" name="errorexcluded" '.
4226: 'value="'.$ids[$i].'"'.$check.' />'.
4227: $ids[$i].'</label></span></td>';
4228: }
4229: my $colsleft = $numinrow - @ids%($numinrow);
4230: if ($colsleft > 1 ) {
4231: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4232: ' </td>';
4233: } elsif ($colsleft == 1) {
4234: $datatable .= '<td class="LC_left_item"> </td>';
4235: }
4236: $datatable .= '</tr></table></td></tr>';
4237: $rownum ++;
1.286 raeburn 4238: } elsif ($position eq 'bottom') {
1.315 raeburn 4239: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4240: my (@posstypes,%usertypeshash);
4241: if (ref($types) eq 'ARRAY') {
4242: @posstypes = @{$types};
4243: }
4244: if (@posstypes) {
4245: if (ref($usertypes) eq 'HASH') {
4246: %usertypeshash = %{$usertypes};
4247: }
4248: my @overridden;
4249: my $numinrow = 4;
4250: if (ref($settings) eq 'HASH') {
4251: if (ref($settings->{'overrides'}) eq 'HASH') {
4252: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4253: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4254: push(@overridden,$key);
4255: foreach my $item (@contacts) {
4256: if ($settings->{'overrides'}{$key}{$item}) {
4257: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4258: }
4259: }
4260: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4261: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4262: $includeloc{'override_'.$key} = '';
4263: $includestr{'override_'.$key} = '';
4264: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4265: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4266: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4267: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4268: }
1.286 raeburn 4269: }
4270: }
4271: }
1.315 raeburn 4272: }
4273: my $customclass = 'LC_helpdesk_override';
4274: my $optionsprefix = 'LC_options_helpdesk_';
4275:
4276: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4277:
4278: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4279: $numinrow,$othertitle,'overrides',
4280: \$rownum,$onclicktypes,$customclass);
4281: $rownum ++;
4282: $usertypeshash{'default'} = $othertitle;
4283: foreach my $status (@posstypes) {
4284: my $css_class;
4285: if ($rownum%2) {
4286: $css_class = 'LC_odd_row ';
4287: }
4288: $css_class .= $customclass;
4289: my $rowid = $optionsprefix.$status;
4290: my $hidden = 1;
4291: my $currstyle = 'display:none';
4292: if (grep(/^\Q$status\E$/,@overridden)) {
4293: $currstyle = 'display:table-row';
4294: $hidden = 0;
4295: }
4296: my $key = 'override_'.$status;
4297: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4298: $includeloc{$key},$includestr{$key},$status,$rowid,
4299: $usertypeshash{$status},$css_class,$currstyle,
4300: \@contacts,$short_titles);
4301: unless ($hidden) {
4302: $rownum ++;
1.286 raeburn 4303: }
4304: }
1.134 raeburn 4305: }
1.28 raeburn 4306: }
1.30 raeburn 4307: $$rowtotal += $rownum;
1.28 raeburn 4308: return $datatable;
4309: }
4310:
1.340 raeburn 4311: sub core_link_msu {
4312: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4313: &mt('LON-CAPA core group - MSU'),600,500);
4314: }
4315:
1.315 raeburn 4316: sub overridden_helpdesk {
4317: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4318: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4319: my $class = 'LC_left_item';
4320: if ($css_class) {
4321: $css_class = ' class="'.$css_class.'"';
4322: }
4323: if ($rowid) {
4324: $rowid = ' id="'.$rowid.'"';
4325: }
4326: if ($rowstyle) {
4327: $rowstyle = ' style="'.$rowstyle.'"';
4328: }
4329: my ($output,$description);
4330: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4331: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4332: "<td>$description</td>\n".
4333: '<td class="'.$class.'" colspan="2">'.
4334: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4335: '<span class="LC_nobreak">';
4336: if (ref($contacts) eq 'ARRAY') {
4337: foreach my $item (@{$contacts}) {
4338: my $check;
4339: if (ref($checked) eq 'HASH') {
4340: $check = $checked->{$item};
4341: }
4342: my $title;
4343: if (ref($short_titles) eq 'HASH') {
4344: $title = $short_titles->{$item};
4345: }
4346: $output .= '<label>'.
4347: '<input type="checkbox" name="override_'.$type.'"'.$check.
4348: ' value="'.$item.'" />'.$title.'</label> ';
4349: }
4350: }
4351: $output .= '</span><br />'.&mt('Others').': '.
4352: '<input type="text" name="override_'.$type.'_others" '.
4353: 'value="'.$otheremails.'" />';
4354: my %locchecked;
4355: foreach my $loc ('s','b') {
4356: if ($includeloc eq $loc) {
4357: $locchecked{$loc} = ' checked="checked"';
4358: last;
4359: }
4360: }
4361: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4362: '<input type="text" name="override_'.$type.'_bcc" '.
4363: 'value="'.$bccemails.'" /></fieldset>'.
4364: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4365: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4366: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4367: '<span class="LC_nobreak">'.&mt('Location:').' '.
4368: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4369: (' 'x2).
4370: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4371: '</span></fieldset>'.
4372: '</td></tr>'."\n";
4373: return $output;
4374: }
4375:
1.286 raeburn 4376: sub contacts_javascript {
4377: return <<"ENDSCRIPT";
4378:
4379: <script type="text/javascript">
4380: // <![CDATA[
4381:
4382: function screenshotSize(field) {
4383: if (document.getElementById('help_screenshotsize')) {
4384: if (field.value == 'no') {
1.289 raeburn 4385: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4386: } else {
4387: document.getElementById('help_screenshotsize').style.display="";
4388: }
4389: }
4390: return;
4391: }
4392:
1.315 raeburn 4393: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4394: if (form.elements[checkbox].length != undefined) {
4395: var count = 0;
4396: if (docount) {
4397: for (var i=0; i<form.elements[checkbox].length; i++) {
4398: if (form.elements[checkbox][i].checked) {
4399: count ++;
4400: }
4401: }
4402: }
4403: for (var i=0; i<form.elements[checkbox].length; i++) {
4404: var type = form.elements[checkbox][i].value;
4405: if (document.getElementById(prefix+type)) {
4406: if (form.elements[checkbox][i].checked) {
4407: document.getElementById(prefix+type).style.display = 'table-row';
4408: if (count % 2 == 1) {
4409: document.getElementById(prefix+type).className = target+' LC_odd_row';
4410: } else {
4411: document.getElementById(prefix+type).className = target;
4412: }
4413: count ++;
4414: } else {
4415: document.getElementById(prefix+type).style.display = 'none';
4416: }
4417: }
4418: }
4419: }
4420: return;
4421: }
4422:
4423:
1.286 raeburn 4424: // ]]>
4425: </script>
4426:
4427: ENDSCRIPT
4428: }
4429:
1.118 jms 4430: sub print_helpsettings {
1.282 raeburn 4431: my ($position,$dom,$settings,$rowtotal) = @_;
4432: my $confname = $dom.'-domainconfig';
1.285 raeburn 4433: my $formname = 'display';
1.168 raeburn 4434: my ($datatable,$itemcount);
1.282 raeburn 4435: if ($position eq 'top') {
4436: $itemcount = 1;
4437: my (%choices,%defaultchecked,@toggles);
4438: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4439: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4440: &mt('LON-CAPA bug tracker'),600,500));
4441: %defaultchecked = ('submitbugs' => 'on');
4442: @toggles = ('submitbugs');
4443: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4444: \%choices,$itemcount);
4445: $$rowtotal ++;
4446: } else {
4447: my $css_class;
4448: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4449: my (%customroles,%ordered,%current);
1.301 raeburn 4450: if (ref($settings) eq 'HASH') {
4451: if (ref($settings->{'adhoc'}) eq 'HASH') {
4452: %current = %{$settings->{'adhoc'}};
4453: }
1.285 raeburn 4454: }
4455: my $count = 0;
4456: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4457: if ($key=~/^rolesdef\_(\w+)$/) {
4458: my $rolename = $1;
1.285 raeburn 4459: my (%privs,$order);
1.282 raeburn 4460: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4461: $customroles{$rolename} = \%privs;
1.285 raeburn 4462: if (ref($current{$rolename}) eq 'HASH') {
4463: $order = $current{$rolename}{'order'};
4464: }
4465: if ($order eq '') {
4466: $order = $count;
4467: }
4468: $ordered{$order} = $rolename;
4469: $count++;
4470: }
4471: }
4472: my $maxnum = scalar(keys(%ordered));
4473: my @roles_by_num = ();
4474: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4475: push(@roles_by_num,$item);
4476: }
4477: my $context = 'domprefs';
4478: my $crstype = 'Course';
4479: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4480: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4481: my ($numstatustypes,@jsarray);
4482: if (ref($types) eq 'ARRAY') {
4483: if (@{$types} > 0) {
4484: $numstatustypes = scalar(@{$types});
4485: push(@accesstypes,'status');
4486: @jsarray = ('bystatus');
1.282 raeburn 4487: }
4488: }
1.290 raeburn 4489: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4490: if (keys(%domhelpdesk)) {
4491: push(@accesstypes,('inc','exc'));
4492: push(@jsarray,('notinc','notexc'));
4493: }
4494: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4495: my $context = 'domprefs';
4496: my $crstype = 'Course';
1.285 raeburn 4497: my $prefix = 'helproles_';
4498: my $add_class = 'LC_hidden';
4499: foreach my $num (@roles_by_num) {
4500: my $role = $ordered{$num};
4501: my ($desc,$access,@statuses);
4502: if (ref($current{$role}) eq 'HASH') {
4503: $desc = $current{$role}{'desc'};
4504: $access = $current{$role}{'access'};
4505: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4506: @statuses = @{$current{$role}{'insttypes'}};
4507: }
4508: }
4509: if ($desc eq '') {
4510: $desc = $role;
4511: }
4512: my $identifier = 'custhelp'.$num;
1.282 raeburn 4513: my %full=();
4514: my %levels= (
4515: course => {},
4516: domain => {},
4517: system => {},
4518: );
4519: my %levelscurrent=(
4520: course => {},
4521: domain => {},
4522: system => {},
4523: );
4524: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4525: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4527: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4528: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4529: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4530: for (my $k=0; $k<=$maxnum; $k++) {
4531: my $vpos = $k+1;
4532: my $selstr;
4533: if ($k == $num) {
4534: $selstr = ' selected="selected" ';
4535: }
4536: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4537: }
4538: $datatable .= '</select>'.(' 'x2).
4539: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4540: '</td>'.
4541: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4542: &mt('Name shown to users:').
4543: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4544: '</fieldset>'.
4545: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4546: $othertitle,$usertypes,$types,\%domhelpdesk).
4547: '<fieldset>'.
4548: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4549: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4550: \%levelscurrent,$identifier,
4551: 'LC_hidden',$prefix.$num.'_privs').
4552: '</fieldset></td>';
1.282 raeburn 4553: $itemcount ++;
4554: }
4555: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4556: my $newcust = 'custhelp'.$count;
4557: my (%privs,%levelscurrent);
4558: my %full=();
4559: my %levels= (
4560: course => {},
4561: domain => {},
4562: system => {},
4563: );
4564: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4565: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4566: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4567: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4568: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4569: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4570: for (my $k=0; $k<$maxnum+1; $k++) {
4571: my $vpos = $k+1;
4572: my $selstr;
4573: if ($k == $maxnum) {
4574: $selstr = ' selected="selected" ';
4575: }
4576: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4577: }
4578: $datatable .= '</select> '."\n".
1.282 raeburn 4579: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4580: '</label></span></td>'.
1.285 raeburn 4581: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4582: '<span class="LC_nobreak">'.
4583: &mt('Internal name:').
4584: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4585: '</span>'.(' 'x4).
4586: '<span class="LC_nobreak">'.
4587: &mt('Name shown to users:').
4588: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4589: '</span></fieldset>'.
4590: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4591: $usertypes,$types,\%domhelpdesk).
4592: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4593: &Apache::lonuserutils::custom_role_header($context,$crstype,
4594: \@templateroles,$newcust).
4595: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4596: \%levelscurrent,$newcust).
1.334 raeburn 4597: '</fieldset>'.
4598: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4599: '</td></tr>';
1.282 raeburn 4600: $count ++;
4601: $$rowtotal += $count;
4602: }
1.166 raeburn 4603: return $datatable;
1.121 raeburn 4604: }
4605:
1.285 raeburn 4606: sub adhocbutton {
4607: my ($prefix,$num,$field,$visibility) = @_;
4608: my %lt = &Apache::lonlocal::texthash(
4609: show => 'Show details',
4610: hide => 'Hide details',
4611: );
4612: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4613: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4614: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4615: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4616: }
4617:
4618: sub helpsettings_javascript {
4619: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4620: return unless(ref($roles_by_num) eq 'ARRAY');
4621: my %html_js_lt = &Apache::lonlocal::texthash(
4622: show => 'Show details',
4623: hide => 'Hide details',
4624: );
4625: &html_escape(\%html_js_lt);
4626: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4627: return <<"ENDSCRIPT";
4628: <script type="text/javascript">
4629: // <![CDATA[
4630:
4631: function reorderHelpRoles(form,item) {
4632: var changedVal;
4633: $jstext
4634: var newpos = 'helproles_${total}_pos';
4635: var maxh = 1 + $total;
4636: var current = new Array();
4637: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4638: if (item == newpos) {
4639: changedVal = newitemVal;
4640: } else {
4641: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4642: current[newitemVal] = newpos;
4643: }
4644: for (var i=0; i<helproles.length; i++) {
4645: var elementName = 'helproles_'+helproles[i]+'_pos';
4646: if (elementName != item) {
4647: if (form.elements[elementName]) {
4648: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4649: current[currVal] = elementName;
4650: }
4651: }
4652: }
4653: var oldVal;
4654: for (var j=0; j<maxh; j++) {
4655: if (current[j] == undefined) {
4656: oldVal = j;
4657: }
4658: }
4659: if (oldVal < changedVal) {
4660: for (var k=oldVal+1; k<=changedVal ; k++) {
4661: var elementName = current[k];
4662: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4663: }
4664: } else {
4665: for (var k=changedVal; k<oldVal; k++) {
4666: var elementName = current[k];
4667: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4668: }
4669: }
4670: return;
4671: }
4672:
4673: function helpdeskAccess(num) {
4674: var curraccess = null;
4675: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4676: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4677: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4678: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4679: }
4680: }
4681: }
4682: var shown = Array();
4683: var hidden = Array();
4684: if (curraccess == 'none') {
4685: hidden = Array('$hiddenstr');
4686: } else {
4687: if (curraccess == 'status') {
4688: shown = Array('bystatus');
4689: hidden = Array('notinc','notexc');
4690: } else {
4691: if (curraccess == 'exc') {
4692: shown = Array('notexc');
4693: hidden = Array('notinc','bystatus');
4694: }
4695: if (curraccess == 'inc') {
4696: shown = Array('notinc');
4697: hidden = Array('notexc','bystatus');
4698: }
1.293 raeburn 4699: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4700: hidden = Array('notinc','notexc','bystatus');
4701: }
4702: }
4703: }
4704: if (hidden.length > 0) {
4705: for (var i=0; i<hidden.length; i++) {
4706: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4707: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4708: }
4709: }
4710: }
4711: if (shown.length > 0) {
4712: for (var i=0; i<shown.length; i++) {
4713: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4714: if (shown[i] == 'privs') {
4715: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4716: } else {
4717: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4718: }
4719: }
4720: }
4721: }
4722: return;
4723: }
4724:
4725: function toggleHelpdeskItem(num,field) {
4726: if (document.getElementById('helproles_'+num+'_'+field)) {
4727: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4728: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4729: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4730: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4731: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4732: }
4733: } else {
4734: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4735: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4736: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4737: }
4738: }
4739: }
4740: return;
4741: }
4742:
4743: // ]]>
4744: </script>
4745:
4746: ENDSCRIPT
4747: }
4748:
4749: sub helpdeskroles_access {
4750: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4751: $usertypes,$types,$domhelpdesk) = @_;
4752: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4753: my %lt = &Apache::lonlocal::texthash(
4754: 'rou' => 'Role usage',
4755: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4756: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4757: 'dh' => 'All with domain helpdesk role',
4758: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4759: 'none' => 'None',
4760: 'status' => 'Determined based on institutional status',
4761: 'inc' => 'Include all, but exclude specific personnel',
4762: 'exc' => 'Exclude all, but include specific personnel',
4763: );
4764: my %usecheck = (
4765: all => ' checked="checked"',
4766: );
4767: my %displaydiv = (
4768: status => 'none',
4769: inc => 'none',
4770: exc => 'none',
4771: priv => 'block',
4772: );
4773: my $output;
4774: if (ref($current) eq 'HASH') {
4775: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4776: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4777: $usecheck{$current->{access}} = $usecheck{'all'};
4778: delete($usecheck{'all'});
4779: if ($current->{access} =~ /^(status|inc|exc)$/) {
4780: my $access = $1;
4781: $displaydiv{$access} = 'inline';
4782: } elsif ($current->{access} eq 'none') {
4783: $displaydiv{'priv'} = 'none';
4784: }
4785: }
4786: }
4787: }
4788: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4789: '<p>'.$lt{'whi'}.'</p>';
4790: foreach my $access (@{$accesstypes}) {
4791: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4792: ' onclick="helpdeskAccess('."'$num'".');" />'.
4793: $lt{$access}.'</label>';
4794: if ($access eq 'status') {
4795: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4796: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4797: $othertitle,$usertypes,$types).
4798: '</div>';
4799: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4800: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4801: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4802: '</div>';
4803: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4804: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4805: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4806: '</div>';
4807: }
4808: $output .= '</p>';
4809: }
4810: $output .= '</fieldset>';
4811: return $output;
4812: }
4813:
1.121 raeburn 4814: sub radiobutton_prefs {
1.192 raeburn 4815: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 4816: $additional,$align,$firstval) = @_;
1.121 raeburn 4817: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4818: (ref($choices) eq 'HASH'));
4819:
1.170 raeburn 4820: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4821:
4822: foreach my $item (@{$toggles}) {
4823: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4824: $checkedon{$item} = ' checked="checked" ';
4825: $checkedoff{$item} = ' ';
1.121 raeburn 4826: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4827: $checkedoff{$item} = ' checked="checked" ';
4828: $checkedon{$item} = ' ';
4829: }
4830: }
4831: if (ref($settings) eq 'HASH') {
1.121 raeburn 4832: foreach my $item (@{$toggles}) {
1.118 jms 4833: if ($settings->{$item} eq '1') {
4834: $checkedon{$item} = ' checked="checked" ';
4835: $checkedoff{$item} = ' ';
4836: } elsif ($settings->{$item} eq '0') {
4837: $checkedoff{$item} = ' checked="checked" ';
4838: $checkedon{$item} = ' ';
4839: }
4840: }
1.121 raeburn 4841: }
1.192 raeburn 4842: if ($onclick) {
4843: $onclick = ' onclick="'.$onclick.'"';
4844: }
1.121 raeburn 4845: foreach my $item (@{$toggles}) {
1.118 jms 4846: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4847: $datatable .=
1.306 raeburn 4848: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4849: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4850: '</span></td>';
4851: if ($align eq 'left') {
4852: $datatable .= '<td class="LC_left_item">';
4853: } else {
4854: $datatable .= '<td class="LC_right_item">';
4855: }
1.385 raeburn 4856: $datatable .= '<span class="LC_nobreak">';
4857: if ($firstval eq 'no') {
4858: $datatable .=
4859: '<label><input type="radio" name="'.
4860: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4861: '</label> <label><input type="radio" name="'.$item.'" '.
4862: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4863: } else {
4864: $datatable .=
4865: '<label><input type="radio" name="'.
4866: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
4867: '</label> <label><input type="radio" name="'.$item.'" '.
4868: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4869: }
4870: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4871: $itemcount ++;
1.121 raeburn 4872: }
4873: return ($datatable,$itemcount);
4874: }
4875:
1.267 raeburn 4876: sub print_ltitools {
4877: my ($dom,$settings,$rowtotal) = @_;
4878: my $rownum = 0;
4879: my $css_class;
4880: my $itemcount = 1;
4881: my $maxnum = 0;
4882: my %ordered;
4883: if (ref($settings) eq 'HASH') {
4884: foreach my $item (keys(%{$settings})) {
4885: if (ref($settings->{$item}) eq 'HASH') {
4886: my $num = $settings->{$item}{'order'};
4887: $ordered{$num} = $item;
4888: }
4889: }
4890: }
4891: my $confname = $dom.'-domainconfig';
4892: my $switchserver = &check_switchserver($dom,$confname);
4893: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4894: my $datatable;
1.267 raeburn 4895: my %lt = <itools_names();
4896: my @courseroles = ('cc','in','ta','ep','st');
4897: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4898: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4899: if (keys(%ordered)) {
4900: my @items = sort { $a <=> $b } keys(%ordered);
4901: for (my $i=0; $i<@items; $i++) {
4902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4903: my $item = $ordered{$items[$i]};
1.323 raeburn 4904: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4905: if (ref($settings->{$item}) eq 'HASH') {
4906: $title = $settings->{$item}->{'title'};
4907: $url = $settings->{$item}->{'url'};
4908: $key = $settings->{$item}->{'key'};
4909: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4910: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4911: my $image = $settings->{$item}->{'image'};
4912: if ($image ne '') {
4913: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4914: }
1.323 raeburn 4915: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4916: $sigsel{'HMAC-256'} = ' selected="selected"';
4917: } else {
4918: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4919: }
1.267 raeburn 4920: }
1.319 raeburn 4921: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4922: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4923: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4924: for (my $k=0; $k<=$maxnum; $k++) {
4925: my $vpos = $k+1;
4926: my $selstr;
4927: if ($k == $i) {
4928: $selstr = ' selected="selected" ';
4929: }
4930: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4931: }
4932: $datatable .= '</select>'.(' 'x2).
4933: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4934: &mt('Delete?').'</label></span></td>'.
4935: '<td colspan="2">'.
4936: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4937: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4938: (' 'x2).
4939: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4940: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4941: (' 'x2).
4942: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4943: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4944: (' 'x2).
4945: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4946: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4947: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4948: '<br /><br />'.
1.323 raeburn 4949: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4950: ' value="'.$url.'" /></span>'.
4951: (' 'x2).
1.319 raeburn 4952: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4953: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4954: (' 'x2).
1.322 raeburn 4955: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4956: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4957: (' 'x2).
1.267 raeburn 4958: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4959: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4960: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4961: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4962: '</fieldset>'.
4963: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4964: '<span class="LC_nobreak">'.&mt('Display target:');
4965: my %currdisp;
4966: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4967: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4968: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4969: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4970: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4971: } else {
4972: $currdisp{'iframe'} = ' checked="checked"';
4973: }
4974: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4975: $currdisp{'width'} = $1;
4976: }
4977: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4978: $currdisp{'height'} = $1;
4979: }
1.296 raeburn 4980: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4981: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4982: } else {
4983: $currdisp{'iframe'} = ' checked="checked"';
4984: }
1.298 raeburn 4985: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4986: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4987: $lt{$disp}.'</label>'.(' 'x2);
4988: }
4989: $datatable .= (' 'x4);
4990: foreach my $dimen ('width','height') {
4991: $datatable .= '<label>'.$lt{$dimen}.' '.
4992: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4993: (' 'x2);
4994: }
1.334 raeburn 4995: $datatable .= '</span><br />'.
1.296 raeburn 4996: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4997: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4998: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4999: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5000: '</textarea></div><div style=""></div><br />';
1.319 raeburn 5001: my %units = (
5002: 'passback' => 'days',
5003: 'roster' => 'seconds',
5004: );
1.267 raeburn 5005: foreach my $extra ('passback','roster') {
1.319 raeburn 5006: my $validsty = 'none';
5007: my $currvalid;
1.267 raeburn 5008: my $checkedon = '';
5009: my $checkedoff = ' checked="checked"';
5010: if ($settings->{$item}->{$extra}) {
5011: $checkedon = $checkedoff;
5012: $checkedoff = '';
1.319 raeburn 5013: $validsty = 'inline-block';
5014: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
5015: $currvalid = $settings->{$item}->{$extra.'valid'};
5016: }
5017: }
5018: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
5019: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5020: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
5021: &mt('No').'</label>'.(' 'x2).
5022: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
5023: &mt('Yes').'</label></span></div>'.
5024: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
5025: '<span class="LC_nobreak">'.
5026: &mt("at least [_1] $units{$extra} after launch",
5027: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
5028: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5029: }
1.319 raeburn 5030: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 5031: if ($imgsrc) {
5032: $datatable .= $imgsrc.
5033: '<label><input type="checkbox" name="ltitools_image_del"'.
5034: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5035: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5036: } else {
5037: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5038: }
5039: if ($switchserver) {
5040: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5041: } else {
5042: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5043: }
5044: $datatable .= '</span></fieldset>';
1.324 raeburn 5045: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5046: if (ref($settings->{$item}) eq 'HASH') {
5047: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5048: %checkedfields = %{$settings->{$item}->{'fields'}};
5049: }
1.324 raeburn 5050: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5051: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5052: %rolemaps = %{$settings->{$item}->{'roles'}};
5053: $checkedfields{'roles'} = 1;
5054: }
5055: }
5056: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5057: '<span class="LC_nobreak">';
1.324 raeburn 5058: my $userfieldstyle = 'display:none;';
5059: my $seluserdom = '';
5060: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5061: foreach my $field (@fields) {
1.324 raeburn 5062: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5063: if ($checkedfields{$field}) {
5064: $checked = ' checked="checked"';
5065: }
1.324 raeburn 5066: if ($field eq 'user') {
5067: $id = ' id="ltitools_user_field_'.$i.'"';
5068: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5069: if ($checked) {
5070: $userfieldstyle = 'display:inline-block';
5071: if ($userincdom) {
5072: $seluserdom = $unseluserdom;
5073: $unseluserdom = '';
5074: }
5075: }
5076: } else {
5077: $spacer = (' ' x2);
5078: }
1.267 raeburn 5079: $datatable .= '<label>'.
1.324 raeburn 5080: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5081: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5082: }
1.324 raeburn 5083: $datatable .= '</span>';
5084: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5085: '<span class="LC_nobreak"> : '.
5086: '<select name="ltitools_userincdom_'.$i.'">'.
5087: '<option value="">'.&mt('Select').'</option>'.
5088: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5089: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5090: '</select></span></div>';
5091: $datatable .= '</fieldset>'.
1.267 raeburn 5092: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5093: foreach my $role (@courseroles) {
5094: my ($selected,$selectnone);
5095: if (!$rolemaps{$role}) {
5096: $selectnone = ' selected="selected"';
5097: }
1.306 raeburn 5098: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5099: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5100: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5101: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5102: foreach my $ltirole (@ltiroles) {
5103: unless ($selectnone) {
5104: if ($rolemaps{$role} eq $ltirole) {
5105: $selected = ' selected="selected"';
5106: } else {
5107: $selected = '';
5108: }
5109: }
5110: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5111: }
5112: $datatable .= '</select></td>';
5113: }
1.273 raeburn 5114: $datatable .= '</tr></table></fieldset>';
5115: my %courseconfig;
5116: if (ref($settings->{$item}) eq 'HASH') {
5117: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5118: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5119: }
5120: }
5121: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5122: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5123: my $checked;
5124: if ($courseconfig{$item}) {
5125: $checked = ' checked="checked"';
5126: }
5127: $datatable .= '<label>'.
5128: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5129: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5130: }
5131: $datatable .= '</span></fieldset>'.
1.267 raeburn 5132: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5133: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5134: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5135: my %custom = %{$settings->{$item}->{'custom'}};
5136: if (keys(%custom) > 0) {
5137: foreach my $key (sort(keys(%custom))) {
5138: $datatable .= '<tr><td><span class="LC_nobreak">'.
5139: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5140: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5141: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5142: ' value="'.$custom{$key}.'" /></td></tr>';
5143: }
5144: }
5145: }
5146: $datatable .= '<tr><td><span class="LC_nobreak">'.
5147: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5148: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5149: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5150: $datatable .= '</table></fieldset></td></tr>'."\n";
5151: $itemcount ++;
5152: }
5153: }
5154: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5155: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5156: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5157: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5158: '<select name="ltitools_add_pos"'.$chgstr.'>';
5159: for (my $k=0; $k<$maxnum+1; $k++) {
5160: my $vpos = $k+1;
5161: my $selstr;
5162: if ($k == $maxnum) {
5163: $selstr = ' selected="selected" ';
5164: }
5165: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5166: }
5167: $datatable .= '</select> '."\n".
1.334 raeburn 5168: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5169: '<td colspan="2">'.
5170: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5171: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5172: (' 'x2).
5173: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5174: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5175: (' 'x2).
5176: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5177: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5178: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5179: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5180: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5181: '<br />'.
1.323 raeburn 5182: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5183: (' 'x2).
5184: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5185: (' 'x2).
1.322 raeburn 5186: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5187: (' 'x2).
1.267 raeburn 5188: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5189: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
5190: '</fieldset>'.
5191: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5192: '<span class="LC_nobreak">'.&mt('Display target:');
5193: my %defaultdisp;
5194: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5195: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5196: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5197: $lt{$disp}.'</label>'.(' 'x2);
5198: }
5199: $datatable .= (' 'x4);
5200: foreach my $dimen ('width','height') {
5201: $datatable .= '<label>'.$lt{$dimen}.' '.
5202: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5203: (' 'x2);
5204: }
1.334 raeburn 5205: $datatable .= '</span><br />'.
1.296 raeburn 5206: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5207: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5208: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5209: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5210: '</div><div style=""></div><br />';
1.319 raeburn 5211: my %units = (
5212: 'passback' => 'days',
5213: 'roster' => 'seconds',
5214: );
5215: my %defaulttimes = (
5216: 'passback' => '7',
1.322 raeburn 5217: 'roster' => '300',
1.319 raeburn 5218: );
1.267 raeburn 5219: foreach my $extra ('passback','roster') {
1.319 raeburn 5220: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5221: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5222: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5223: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5224: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5225: &mt('Yes').'</label></span></div>'.
5226: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5227: '<span class="LC_nobreak">'.
5228: &mt("at least [_1] $units{$extra} after launch",
5229: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5230: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5231: }
1.319 raeburn 5232: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5233: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5234: if ($switchserver) {
5235: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5236: } else {
5237: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5238: }
5239: $datatable .= '</span></fieldset>'.
5240: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5241: '<span class="LC_nobreak">';
5242: foreach my $field (@fields) {
1.324 raeburn 5243: my ($id,$onclick,$spacer);
5244: if ($field eq 'user') {
5245: $id = ' id="ltitools_user_field_add"';
5246: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5247: } else {
5248: $spacer = (' ' x2);
5249: }
1.267 raeburn 5250: $datatable .= '<label>'.
1.324 raeburn 5251: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5252: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5253: }
1.324 raeburn 5254: $datatable .= '</span>'.
5255: '<div style="display:none;" id="ltitools_user_div_add">'.
5256: '<span class="LC_nobreak"> : '.
5257: '<select name="ltitools_userincdom_add">'.
5258: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5259: '<option value="0">'.&mt('username').'</option>'.
5260: '<option value="1">'.&mt('username:domain').'</option>'.
5261: '</select></span></div></fieldset>';
5262: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5263: foreach my $role (@courseroles) {
5264: my ($checked,$checkednone);
1.306 raeburn 5265: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5266: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5267: '<select name="ltitools_add_roles_'.$role.'">'.
5268: '<option value="" selected="selected">'.&mt('Select').'</option>';
5269: foreach my $ltirole (@ltiroles) {
5270: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5271: }
5272: $datatable .= '</select></td>';
5273: }
5274: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5275: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5276: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5277: $datatable .= '<label>'.
5278: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5279: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5280: }
5281: $datatable .= '</span></fieldset>'.
1.267 raeburn 5282: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5283: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5284: '<tr><td><span class="LC_nobreak">'.
5285: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5286: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5287: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5288: '</table></fieldset>'."\n".
1.267 raeburn 5289: '</td>'."\n".
5290: '</tr>'."\n";
5291: $itemcount ++;
5292: return $datatable;
5293: }
5294:
5295: sub ltitools_names {
5296: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5297: 'title' => 'Title',
5298: 'version' => 'Version',
5299: 'msgtype' => 'Message Type',
1.323 raeburn 5300: 'sigmethod' => 'Signature Method',
1.296 raeburn 5301: 'url' => 'URL',
5302: 'key' => 'Key',
1.322 raeburn 5303: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5304: 'secret' => 'Secret',
5305: 'icon' => 'Icon',
1.324 raeburn 5306: 'user' => 'User',
1.296 raeburn 5307: 'fullname' => 'Full Name',
5308: 'firstname' => 'First Name',
5309: 'lastname' => 'Last Name',
5310: 'email' => 'E-mail',
5311: 'roles' => 'Role',
1.298 raeburn 5312: 'window' => 'Window',
5313: 'tab' => 'Tab',
1.296 raeburn 5314: 'iframe' => 'iFrame',
5315: 'height' => 'Height',
5316: 'width' => 'Width',
5317: 'linktext' => 'Default Link Text',
5318: 'explanation' => 'Default Explanation',
5319: 'passback' => 'Tool can return grades:',
5320: 'roster' => 'Tool can retrieve roster:',
5321: 'crstarget' => 'Display target',
5322: 'crslabel' => 'Course label',
5323: 'crstitle' => 'Course title',
5324: 'crslinktext' => 'Link Text',
5325: 'crsexplanation' => 'Explanation',
1.318 raeburn 5326: 'crsappend' => 'Provider URL',
1.267 raeburn 5327: );
5328: return %lt;
5329: }
5330:
1.372 raeburn 5331: sub print_proctoring {
5332: my ($dom,$settings,$rowtotal) = @_;
5333: my $itemcount = 1;
5334: my (%ordered,%providernames,%current,%currentdef);
5335: my $confname = $dom.'-domainconfig';
5336: my $switchserver = &check_switchserver($dom,$confname);
5337: if (ref($settings) eq 'HASH') {
5338: foreach my $item (keys(%{$settings})) {
5339: if (ref($settings->{$item}) eq 'HASH') {
5340: my $num = $settings->{$item}{'order'};
5341: $ordered{$num} = $item;
5342: }
5343: }
5344: } else {
5345: %ordered = (
5346: 1 => 'proctorio',
5347: 2 => 'examity',
5348: );
5349: }
5350: %providernames = &proctoring_providernames();
5351: my $maxnum = scalar(keys(%ordered));
5352: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5353: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5354: if (ref($requref) eq 'HASH') {
5355: %requserfields = %{$requref};
5356: }
5357: if (ref($opturef) eq 'HASH') {
5358: %optuserfields = %{$opturef};
5359: }
5360: if (ref($defref) eq 'HASH') {
5361: %defaults = %{$defref};
5362: }
5363: if (ref($extref) eq 'HASH') {
5364: %extended = %{$extref};
5365: }
5366: if (ref($crsref) eq 'HASH') {
5367: %crsconf = %{$crsref};
5368: }
5369: if (ref($rolesref) eq 'ARRAY') {
5370: @courseroles = @{$rolesref};
5371: }
5372: if (ref($ltiref) eq 'ARRAY') {
5373: @ltiroles = @{$ltiref};
5374: }
5375: my $datatable;
5376: my $css_class;
5377: if (keys(%ordered)) {
5378: my @items = sort { $a <=> $b } keys(%ordered);
5379: for (my $i=0; $i<@items; $i++) {
5380: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5381: my $provider = $ordered{$items[$i]};
5382: my $optionsty = 'none';
5383: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5384: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5385: if (ref($settings) eq 'HASH') {
5386: if (ref($settings->{$provider}) eq 'HASH') {
5387: %current = %{$settings->{$provider}};
5388: if ($current{'available'}) {
5389: $optionsty = 'block';
5390: $available = 1;
5391: }
5392: if ($current{'lifetime'} =~ /^\d+$/) {
5393: $lifetime = $current{'lifetime'};
5394: }
5395: if ($current{'version'} =~ /^\d+\.\d+$/) {
5396: $version = $current{'version'};
5397: }
5398: if ($current{'image'} ne '') {
5399: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5400: }
5401: if (ref($current{'fields'}) eq 'ARRAY') {
5402: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5403: }
5404: $userincdom = $current{'incdom'};
5405: if (ref($current{'roles'}) eq 'HASH') {
5406: %rolemaps = %{$current{'roles'}};
5407: $checkedfields{'roles'} = 1;
5408: }
5409: if (ref($current{'defaults'}) eq 'ARRAY') {
5410: foreach my $val (@{$current{'defaults'}}) {
5411: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5412: $inuse{$val} = 1;
5413: } else {
5414: foreach my $poss (keys(%{$extended{$provider}})) {
5415: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5416: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5417: $inuse{$poss} = $val;
5418: last;
5419: }
5420: }
5421: }
5422: }
5423: }
5424: } elsif (ref($current{'defaults'}) eq 'HASH') {
5425: foreach my $key (keys(%{$current{'defaults'}})) {
5426: my $currval = $current{'defaults'}{$key};
5427: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5428: $inuse{$key} = 1;
5429: } else {
5430: my $match;
5431: foreach my $poss (keys(%{$extended{$provider}})) {
5432: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5433: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5434: $inuse{$poss} = $key;
5435: last;
5436: }
5437: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5438: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5439: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5440: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5441: $currentdef{$inner} = $currval;
5442: $match = 1;
5443: last;
5444: }
5445: } elsif ($inner eq $key) {
5446: $currentdef{$key} = $currval;
5447: $match = 1;
5448: last;
5449: }
5450: }
5451: }
5452: last if ($match);
5453: }
5454: }
5455: }
5456: }
5457: if (ref($current{'crsconf'}) eq 'ARRAY') {
5458: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5459: }
5460: }
5461: }
5462: my %lt = &proctoring_titles($provider);
5463: my %fieldtitles = &proctoring_fieldtitles($provider);
5464: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5465: my %checkedavailable = (
5466: yes => '',
5467: no => ' checked="checked"',
5468: );
5469: if ($available) {
5470: $checkedavailable{'yes'} = $checkedavailable{'no'};
5471: $checkedavailable{'no'} = '';
5472: }
5473: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5474: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5475: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5476: for (my $k=0; $k<$maxnum; $k++) {
5477: my $vpos = $k+1;
5478: my $selstr;
5479: if ($k == $i) {
5480: $selstr = ' selected="selected" ';
5481: }
5482: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5483: }
5484: if ($version eq '') {
5485: if ($provider eq 'proctorio') {
5486: $version = '1.0';
5487: } elsif ($provider eq 'examity') {
5488: $version = '1.1';
5489: }
5490: }
5491: if ($lifetime eq '') {
5492: $lifetime = '300';
5493: }
5494: $datatable .=
5495: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5496: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5497: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5498: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5499: '</td>'.
5500: '<td colspan="2">'.
5501: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5502: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5503: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5504: (' 'x2).
5505: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5506: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5507: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5508: (' 'x2).
5509: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5510: '<br />'.
5511: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5512: '<br />'.
5513: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5514: (' 'x2).
5515: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5516: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5517: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5518: if ($imgsrc) {
5519: $datatable .= $imgsrc.
5520: '<label><input type="checkbox" name="proctoring_image_del"'.
5521: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5522: '<span class="LC_nobreak"> '.&mt('Replace:');
5523: }
5524: $datatable .= ' ';
5525: if ($switchserver) {
5526: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5527: } else {
5528: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5529: }
5530: unless ($imgsrc) {
5531: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5532: }
5533: $datatable .= '</fieldset>'."\n";
5534: if (ref($requserfields{$provider}) eq 'ARRAY') {
5535: if (@{$requserfields{$provider}} > 0) {
5536: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5537: foreach my $field (@{$requserfields{$provider}}) {
5538: $datatable .= '<span class="LC_nobreak">'.
5539: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5540: $lt{$field}.'</label>';
5541: if ($field eq 'user') {
5542: my $seluserdom = '';
5543: my $unseluserdom = ' selected="selected"';
5544: if ($userincdom) {
5545: $seluserdom = $unseluserdom;
5546: $unseluserdom = '';
5547: }
5548: $datatable .= ': '.
5549: '<select name="proctoring_userincdom_'.$provider.'">'.
5550: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5551: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5552: '</select> ';
5553: } else {
5554: $datatable .= ' ';
5555: if ($field eq 'roles') {
5556: $showroles = 1;
5557: }
5558: }
5559: $datatable .= '</span> ';
5560: }
5561: }
5562: $datatable .= '</fieldset>'."\n";
5563: }
5564: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5565: if (@{$optuserfields{$provider}} > 0) {
5566: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5567: foreach my $field (@{$optuserfields{$provider}}) {
5568: my $checked;
5569: if ($checkedfields{$field}) {
5570: $checked = ' checked="checked"';
5571: }
5572: $datatable .= '<span class="LC_nobreak">'.
5573: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5574: }
5575: $datatable .= '</fieldset>'."\n";
5576: }
5577: }
5578: if (ref($defaults{$provider}) eq 'ARRAY') {
5579: if (@{$defaults{$provider}}) {
5580: my (%options,@selectboxes);
5581: if (ref($extended{$provider}) eq 'HASH') {
5582: %options = %{$extended{$provider}};
5583: }
5584: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5585: my ($rem,$numinrow,$dropdowns);
5586: if ($provider eq 'proctorio') {
5587: $datatable .= '<table>';
5588: $numinrow = 4;
5589: }
5590: my $i = 0;
5591: foreach my $field (@{$defaults{$provider}}) {
5592: my $checked;
5593: if ($inuse{$field}) {
5594: $checked = ' checked="checked"';
5595: }
5596: if ($provider eq 'examity') {
5597: if ($field eq 'display') {
5598: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5599: foreach my $option ('iframe','tab','window') {
5600: my $checkdisp;
5601: if ($currentdef{'target'} eq $option) {
5602: $checkdisp = ' checked="checked"';
5603: }
5604: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5605: $fieldtitles{$option}.'</label>'.(' 'x2);
5606: }
5607: $datatable .= (' 'x4);
5608: foreach my $dimen ('width','height') {
5609: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5610: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5611: 'value="'.$currentdef{$dimen}.'" /></label>'.
5612: (' 'x2);
5613: }
5614: $datatable .= '</span><br />'.
5615: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5616: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5617: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5618: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5619: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5620: $currentdef{'explanation'}.
5621: '</textarea></div><div style=""></div><br />';
5622: }
5623: } else {
5624: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5625: my ($output,$selnone);
5626: unless ($checked) {
5627: $selnone = ' selected="selected"';
5628: }
5629: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5630: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5631: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5632: foreach my $option (@{$options{$field}}) {
5633: my $sel;
5634: if ($inuse{$field} eq $option) {
5635: $sel = ' selected="selected"';
5636: }
5637: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5638: }
5639: $output .= '</select></span>';
5640: push(@selectboxes,$output);
5641: } else {
5642: $rem = $i%($numinrow);
5643: if ($rem == 0) {
5644: if ($i > 0) {
5645: $datatable .= '</tr>';
5646: }
5647: $datatable .= '<tr>';
5648: }
5649: $datatable .= '<td class="LC_left_item">'.
5650: '<span class="LC_nobreak">'.
5651: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5652: $fieldtitles{$field}.'</label></span></td>';
5653: $i++;
5654: }
5655: }
5656: }
5657: if ($provider eq 'proctorio') {
5658: if ($numinrow) {
5659: $rem = $i%$numinrow;
5660: }
5661: my $colsleft = $numinrow - $rem;
5662: if ($colsleft > 1) {
5663: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5664: } else {
5665: $datatable .= '<td class="LC_left_item">';
5666: }
5667: $datatable .= ' '.
5668: '</td></tr></table>';
5669: if (@selectboxes) {
5670: $datatable .= '<hr /><table>';
5671: $numinrow = 2;
5672: for (my $i=0; $i<@selectboxes; $i++) {
5673: $rem = $i%($numinrow);
5674: if ($rem == 0) {
5675: if ($i > 0) {
5676: $datatable .= '</tr>';
5677: }
5678: $datatable .= '<tr>';
5679: }
5680: $datatable .= '<td class="LC_left_item">'.
5681: $selectboxes[$i].'</td>';
5682: }
5683: if ($numinrow) {
5684: $rem = $i%$numinrow;
5685: }
5686: $colsleft = $numinrow - $rem;
5687: if ($colsleft > 1) {
5688: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5689: } else {
5690: $datatable .= '<td class="LC_left_item">';
5691: }
5692: $datatable .= ' '.
5693: '</td></tr></table>';
5694: }
5695: }
5696: $datatable .= '</fieldset>';
5697: }
5698: if (ref($crsconf{$provider}) eq 'ARRAY') {
5699: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5700: '<legend>'.&mt('Configurable in course').'</legend>';
5701: my ($rem,$numinrow);
5702: if ($provider eq 'proctorio') {
5703: $datatable .= '<table>';
5704: $numinrow = 4;
5705: }
5706: my $i = 0;
5707: foreach my $item (@{$crsconf{$provider}}) {
5708: my $name;
5709: if ($provider eq 'examity') {
5710: $name = $lt{'crs'.$item};
5711: } elsif ($provider eq 'proctorio') {
5712: $name = $fieldtitles{$item};
5713: $rem = $i%($numinrow);
5714: if ($rem == 0) {
5715: if ($i > 0) {
5716: $datatable .= '</tr>';
5717: }
5718: $datatable .= '<tr>';
5719: }
5720: $datatable .= '<td class="LC_left_item>';
5721: }
5722: my $checked;
5723: if ($crsconfig{$item}) {
5724: $checked = ' checked="checked"';
5725: }
5726: $datatable .= '<span class="LC_nobreak"><label>'.
5727: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5728: $name.'</label></span>';
5729: if ($provider eq 'examity') {
5730: $datatable .= ' ';
5731: }
5732: $datatable .= "\n";
5733: $i++;
5734: }
5735: if ($provider eq 'proctorio') {
5736: if ($numinrow) {
5737: $rem = $i%$numinrow;
5738: }
5739: my $colsleft = $numinrow - $rem;
5740: if ($colsleft > 1) {
5741: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5742: } else {
5743: $datatable .= '<td class="LC_left_item">';
5744: }
5745: $datatable .= ' '.
5746: '</td></tr></table>';
5747: }
5748: $datatable .= '</fieldset>';
5749: }
5750: if ($showroles) {
5751: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5752: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5753: foreach my $role (@courseroles) {
5754: my ($selected,$selectnone);
5755: if (!$rolemaps{$role}) {
5756: $selectnone = ' selected="selected"';
5757: }
5758: $datatable .= '<td style="text-align: center">'.
5759: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5760: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5761: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5762: foreach my $ltirole (@ltiroles) {
5763: unless ($selectnone) {
5764: if ($rolemaps{$role} eq $ltirole) {
5765: $selected = ' selected="selected"';
5766: } else {
5767: $selected = '';
5768: }
5769: }
5770: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5771: }
5772: $datatable .= '</select></td>';
5773: }
5774: $datatable .= '</tr></table></fieldset>'.
5775: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5776: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5777: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5778: '<tr><td></td><td>lms</td>'.
5779: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5780: ' value="Loncapa" disabled="disabled"/></td></tr>';
5781: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5782: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5783: my %custom = %{$settings->{$provider}->{'custom'}};
5784: if (keys(%custom) > 0) {
5785: foreach my $key (sort(keys(%custom))) {
5786: next if ($key eq 'lms');
5787: $datatable .= '<tr><td><span class="LC_nobreak">'.
5788: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5789: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5790: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5791: ' value="'.$custom{$key}.'" /></td></tr>';
5792: }
5793: }
5794: }
5795: $datatable .= '<tr><td><span class="LC_nobreak">'.
5796: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5797: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5798: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5799: '</table></fieldset></td></tr>'."\n";
5800: }
5801: $datatable .= '</td></tr>';
5802: }
5803: $itemcount ++;
5804: }
5805: }
5806: return $datatable;
5807: }
5808:
5809: sub proctoring_data {
5810: my $requserfields = {
5811: proctorio => ['user'],
5812: examity => ['roles','user'],
5813: };
5814: my $optuserfields = {
5815: proctorio => ['fullname'],
5816: examity => ['fullname','firstname','lastname','email'],
5817: };
5818: my $defaults = {
5819: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5820: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5821: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5822: 'closetabs','onescreen','print','downloads','cache','rightclick',
5823: 'reentry','calculator','whiteboard'],
5824: examity => ['display'],
5825: };
5826: my $extended = {
5827: proctorio => {
5828: verifyid => ['verifyidauto','verifyidlive'],
5829: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
5830: tabslinks => ['notabs','linksonly'],
5831: reentry => ['noreentry','agentreentry'],
5832: calculator => ['calculatorbasic','calculatorsci'],
5833: },
5834: examity => {
5835: display => {
5836: target => ['iframe','tab','window'],
5837: width => '',
5838: height => '',
5839: linktext => '',
5840: explanation => '',
5841: },
5842: },
5843: };
5844: my $crsconf = {
5845: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
5846: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
5847: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
5848: 'closetabs','onescreen','print','downloads','cache','rightclick',
5849: 'reentry','calculator','whiteboard'],
5850: examity => ['label','title','target','linktext','explanation','append'],
5851: };
5852: my $courseroles = ['cc','in','ta','ep','st'];
5853: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
5854: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
5855: }
5856:
5857: sub proctoring_titles {
5858: my ($item) = @_;
5859: my (%common_lt,%custom_lt);
5860: %common_lt = &Apache::lonlocal::texthash (
5861: 'avai' => 'Available?',
5862: 'base' => 'Basic Settings',
5863: 'requ' => 'User data required to be sent on launch',
5864: 'optu' => 'User data optionally sent on launch',
5865: 'udsl' => 'User data sent on launch',
5866: 'defa' => 'Defaults for items configurable in course',
5867: 'sigmethod' => 'Signature Method',
5868: 'key' => 'Key',
5869: 'lifetime' => 'Nonce lifetime (s)',
5870: 'secret' => 'Secret',
5871: 'icon' => 'Icon',
5872: 'fullname' => 'Full Name',
5873: 'visible' => 'Visible input',
5874: 'username' => 'username',
5875: 'user' => 'User',
5876: );
5877: if ($item eq 'proctorio') {
5878: %custom_lt = &Apache::lonlocal::texthash (
5879: 'version' => 'OAuth version',
5880: 'url' => 'API URL',
5881: 'uname:dom' => 'username-domain',
5882: );
5883: } elsif ($item eq 'examity') {
5884: %custom_lt = &Apache::lonlocal::texthash (
5885: 'version' => 'LTI Version',
5886: 'url' => 'URL',
5887: 'uname:dom' => 'username:domain',
5888: 'msgtype' => 'Message Type',
5889: 'firstname' => 'First Name',
5890: 'lastname' => 'Last Name',
5891: 'email' => 'E-mail',
5892: 'roles' => 'Role',
5893: 'crstarget' => 'Display target',
5894: 'crslabel' => 'Course label',
5895: 'crstitle' => 'Course title',
5896: 'crslinktext' => 'Link Text',
5897: 'crsexplanation' => 'Explanation',
5898: 'crsappend' => 'Provider URL',
5899: );
5900: }
5901: my %lt = (%common_lt,%custom_lt);
5902: return %lt;
5903: }
5904:
5905: sub proctoring_fieldtitles {
5906: my ($item) = @_;
5907: if ($item eq 'proctorio') {
5908: return &Apache::lonlocal::texthash (
5909: 'recordvideo' => 'Record video',
5910: 'recordaudio' => 'Record audio',
5911: 'recordscreen' => 'Record screen',
5912: 'recordwebtraffic' => 'Record web traffic',
5913: 'recordroomstart' => 'Record room scan',
5914: 'verifyvideo' => 'Verify webcam',
5915: 'verifyaudio' => 'Verify microphone',
5916: 'verifydesktop' => 'Verify desktop recording',
5917: 'verifyid' => 'Photo ID verification',
5918: 'verifysignature' => 'Require signature',
5919: 'fullscreen' => 'Fullscreen',
5920: 'clipboard' => 'Disable copy/paste',
5921: 'tabslinks' => 'New tabs/windows',
5922: 'closetabs' => 'Close other tabs',
5923: 'onescreen' => 'Limit to single screen',
5924: 'print' => 'Disable Printing',
5925: 'downloads' => 'Disable Downloads',
5926: 'cache' => 'Empty cache after exam',
5927: 'rightclick' => 'Disable right click',
5928: 'reentry' => 'Re-entry to exam',
5929: 'calculator' => 'Onscreen calculator',
5930: 'whiteboard' => 'Onscreen whiteboard',
5931: 'verifyidauto' => 'Automated verification',
5932: 'verifyidlive' => 'Live agent verification',
5933: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
5934: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
5935: 'fullscreensever' => 'Forced, navigation away ends exam',
5936: 'notabs' => 'Disaallowed',
5937: 'linksonly' => 'Allowed from links in exam',
5938: 'noreentry' => 'Disallowed',
5939: 'agentreentry' => 'Agent required for re-entry',
5940: 'calculatorbasic' => 'Basic',
5941: 'calculatorsci' => 'Scientific',
5942: );
5943: } elsif ($item eq 'examity') {
5944: return &Apache::lonlocal::texthash (
5945: 'target' => 'Display target',
5946: 'window' => 'Window',
5947: 'tab' => 'Tab',
5948: 'iframe' => 'iFrame',
5949: 'height' => 'Height (pixels)',
5950: 'width' => 'Width (pixels)',
5951: 'linktext' => 'Default Link Text',
5952: 'explanation' => 'Default Explanation',
5953: 'append' => 'Provider URL',
5954: );
5955: }
5956: }
5957:
5958: sub proctoring_providernames {
5959: return (
5960: proctorio => 'Proctorio',
5961: examity => 'Examity',
5962: );
5963: }
5964:
1.320 raeburn 5965: sub print_lti {
5966: my ($dom,$settings,$rowtotal) = @_;
5967: my $itemcount = 1;
5968: my $maxnum = 0;
5969: my $css_class;
5970: my %ordered;
5971: if (ref($settings) eq 'HASH') {
5972: foreach my $item (keys(%{$settings})) {
5973: if (ref($settings->{$item}) eq 'HASH') {
5974: my $num = $settings->{$item}{'order'};
1.390 raeburn 5975: if ($num eq '') {
5976: $num = scalar(keys(%{$settings}));
5977: }
1.320 raeburn 5978: $ordered{$num} = $item;
5979: }
5980: }
5981: }
5982: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5983: my $datatable;
1.320 raeburn 5984: my %lt = <i_names();
5985: if (keys(%ordered)) {
5986: my @items = sort { $a <=> $b } keys(%ordered);
5987: for (my $i=0; $i<@items; $i++) {
5988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5989: my $item = $ordered{$items[$i]};
1.391 ! raeburn 5990: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320 raeburn 5991: if (ref($settings->{$item}) eq 'HASH') {
5992: $key = $settings->{$item}->{'key'};
5993: $secret = $settings->{$item}->{'secret'};
5994: $lifetime = $settings->{$item}->{'lifetime'};
5995: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 5996: $requser = $settings->{$item}->{'requser'};
1.391 ! raeburn 5997: $crsinc = $settings->{$item}->{'crsinc'};
1.320 raeburn 5998: $current = $settings->{$item};
5999: }
1.345 raeburn 6000: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6001: my %checkedrequser = (
6002: yes => ' checked="checked"',
6003: no => '',
6004: );
6005: if (!$requser) {
6006: $checkedrequser{'no'} = $checkedrequser{'yes'};
6007: $checkedrequser{'yes'} = '';
1.352 raeburn 6008: }
1.391 ! raeburn 6009: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
! 6010: my %checkedcrsinc = (
! 6011: yes => ' checked="checked"',
! 6012: no => '',
! 6013: );
! 6014: if (!$crsinc) {
! 6015: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
! 6016: $checkedcrsinc{'yes'} = '';
! 6017: }
1.320 raeburn 6018: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6019: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6020: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6021: for (my $k=0; $k<=$maxnum; $k++) {
6022: my $vpos = $k+1;
6023: my $selstr;
6024: if ($k == $i) {
6025: $selstr = ' selected="selected" ';
6026: }
6027: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6028: }
6029: $datatable .= '</select>'.(' 'x2).
6030: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6031: &mt('Delete?').'</label></span></td>'.
6032: '<td colspan="2">'.
6033: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6034: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6035: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 6036: (' 'x2).
6037: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6038: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6039: (' 'x2).
6040: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 6041: 'value="'.$lifetime.'" size="3" /></span>'.
6042: (' 'x2).
6043: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6044: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6045: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6046: '<br /><br />'.
1.391 ! raeburn 6047: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
! 6048: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
! 6049: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
! 6050: (' 'x4).
1.320 raeburn 6051: '<span class="LC_nobreak">'.$lt{'key'}.
6052: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6053: (' 'x2).
6054: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6055: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6056: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
6057: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 6058: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 6059: $itemcount ++;
6060: }
6061: }
6062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6063: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6064: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6065: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6066: '<select name="lti_pos_add"'.$chgstr.'>';
6067: for (my $k=0; $k<$maxnum+1; $k++) {
6068: my $vpos = $k+1;
6069: my $selstr;
6070: if ($k == $maxnum) {
6071: $selstr = ' selected="selected" ';
6072: }
6073: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6074: }
6075: $datatable .= '</select> '."\n".
1.334 raeburn 6076: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 6077: '<td colspan="2">'.
6078: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6079: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6080: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 6081: (' 'x2).
6082: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6083: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6084: (' 'x2).
1.345 raeburn 6085: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6086: (' 'x2).
6087: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6088: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6089: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6090: '<br /><br />'.
1.391 ! raeburn 6091: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
! 6092: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
! 6093: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
! 6094: (' 'x4).
1.320 raeburn 6095: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6096: (' 'x2).
6097: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6098: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 6099: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 6100: '</td>'."\n".
6101: '</tr>'."\n";
6102: $$rowtotal ++;
6103: return $datatable;;
6104: }
6105:
6106: sub lti_names {
6107: my %lt = &Apache::lonlocal::texthash(
6108: 'version' => 'LTI Version',
6109: 'url' => 'URL',
6110: 'key' => 'Key',
1.322 raeburn 6111: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6112: 'consumer' => 'Consumer',
1.320 raeburn 6113: 'secret' => 'Secret',
1.345 raeburn 6114: 'requser' => "User's identity sent",
1.391 ! raeburn 6115: 'crsinc' => "Course's identity sent",
1.320 raeburn 6116: 'email' => 'Email address',
6117: 'sourcedid' => 'User ID',
6118: 'other' => 'Other',
6119: 'passback' => 'Can return grades to Consumer:',
6120: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6121: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6122: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6123: );
6124: return %lt;
6125: }
6126:
6127: sub lti_options {
1.325 raeburn 6128: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6129: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6130: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6131: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
6132: $checked{'makecrs'}{'N'} = ' checked="checked"';
6133: $checked{'mapcrstype'} = {};
6134: $checked{'makeuser'} = {};
6135: $checked{'selfenroll'} = {};
6136: $checked{'crssec'} = {};
6137: $checked{'crssecsrc'} = {};
1.325 raeburn 6138: $checked{'lcauth'} = {};
1.326 raeburn 6139: $checked{'menuitem'} = {};
1.325 raeburn 6140: if ($num eq 'add') {
6141: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6142: }
1.320 raeburn 6143: my $userfieldsty = 'none';
6144: my $crsfieldsty = 'none';
6145: my $crssecfieldsty = 'none';
6146: my $secsrcfieldsty = 'none';
1.363 raeburn 6147: my $callbacksty = 'none';
1.337 raeburn 6148: my $passbacksty = 'none';
1.345 raeburn 6149: my $optionsty = 'block';
1.391 ! raeburn 6150: my $crssty = 'block';
1.325 raeburn 6151: my $lcauthparm;
6152: my $lcauthparmstyle = 'display:none';
6153: my $lcauthparmtext;
1.326 raeburn 6154: my $menusty;
1.325 raeburn 6155: my $numinrow = 4;
1.326 raeburn 6156: my %menutitles = <imenu_titles();
1.320 raeburn 6157:
6158: if (ref($current) eq 'HASH') {
1.345 raeburn 6159: if (!$current->{'requser'}) {
6160: $optionsty = 'none';
1.391 ! raeburn 6161: $crssty = 'none';
! 6162: } elsif (!$current->{'crsinc'}) {
! 6163: $crssty = 'none';
1.345 raeburn 6164: }
1.320 raeburn 6165: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6166: $checked{'mapuser'}{'sourcedid'} = '';
6167: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6168: $checked{'mapuser'}{'email'} = ' checked="checked"';
6169: } else {
6170: $checked{'mapuser'}{'other'} = ' checked="checked"';
6171: $userfield = $current->{'mapuser'};
6172: $userfieldsty = 'inline-block';
6173: }
6174: }
6175: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6176: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6177: if ($current->{'mapcrs'} eq 'context_id') {
6178: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6179: } else {
6180: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6181: $cidfield = $current->{'mapcrs'};
6182: $crsfieldsty = 'inline-block';
6183: }
6184: }
6185: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6186: foreach my $type (@{$current->{'mapcrstype'}}) {
6187: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6188: }
6189: }
1.345 raeburn 6190: if ($current->{'makecrs'}) {
1.320 raeburn 6191: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6192: }
1.320 raeburn 6193: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6194: foreach my $role (@{$current->{'makeuser'}}) {
6195: $checked{'makeuser'}{$role} = ' checked="checked"';
6196: }
6197: }
1.325 raeburn 6198: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6199: $checked{'lcauth'}{$1} = ' checked="checked"';
6200: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6201: $lcauthparm = $current->{'lcauthparm'};
6202: $lcauthparmstyle = 'display:table-row';
6203: if ($current->{'lcauth'} eq 'localauth') {
6204: $lcauthparmtext = &mt('Local auth argument');
6205: } else {
6206: $lcauthparmtext = &mt('Kerberos domain');
6207: }
6208: }
6209: }
1.320 raeburn 6210: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6211: foreach my $role (@{$current->{'selfenroll'}}) {
6212: $checked{'selfenroll'}{$role} = ' checked="checked"';
6213: }
6214: }
6215: if (ref($current->{'maproles'}) eq 'HASH') {
6216: %rolemaps = %{$current->{'maproles'}};
6217: }
6218: if ($current->{'section'} ne '') {
6219: $checked{'crssec'}{'Y'} = ' checked="checked"';
6220: $crssecfieldsty = 'inline-block';
6221: if ($current->{'section'} eq 'course_section_sourcedid') {
6222: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6223: } else {
6224: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6225: $crssecsrc = $current->{'section'};
6226: $secsrcfieldsty = 'inline-block';
6227: }
6228: } else {
6229: $checked{'crssec'}{'N'} = ' checked="checked"';
6230: }
1.363 raeburn 6231: if ($current->{'callback'} ne '') {
6232: $callback = $current->{'callback'};
6233: $checked{'callback'}{'Y'} = ' checked="checked"';
6234: $callbacksty = 'inline-block';
6235: } else {
6236: $checked{'callback'}{'N'} = ' checked="checked"';
6237: }
1.326 raeburn 6238: if ($current->{'topmenu'}) {
6239: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6240: } else {
6241: $checked{'topmenu'}{'N'} = ' checked="checked"';
6242: }
6243: if ($current->{'inlinemenu'}) {
6244: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6245: } else {
6246: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6247: }
6248: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6249: $menusty = 'inline-block';
6250: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6251: foreach my $item (@{$current->{'lcmenu'}}) {
6252: if (exists($menutitles{$item})) {
6253: $checked{'menuitem'}{$item} = ' checked="checked"';
6254: }
6255: }
6256: }
6257: } else {
6258: $menusty = 'none';
6259: }
1.320 raeburn 6260: } else {
6261: $checked{'makecrs'}{'N'} = ' checked="checked"';
6262: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6263: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6264: $checked{'topmenu'}{'N'} = ' checked="checked"';
6265: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6266: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6267: $menusty = 'inline-block';
1.320 raeburn 6268: }
1.325 raeburn 6269: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6270: my %coursetypetitles = &Apache::lonlocal::texthash (
6271: official => 'Official',
6272: unofficial => 'Unofficial',
6273: community => 'Community',
6274: textbook => 'Textbook',
6275: placement => 'Placement Test',
1.325 raeburn 6276: lti => 'LTI Provider',
1.320 raeburn 6277: );
1.325 raeburn 6278: my @authtypes = ('internal','krb4','krb5','localauth');
6279: my %shortauth = (
6280: internal => 'int',
6281: krb4 => 'krb4',
6282: krb5 => 'krb5',
6283: localauth => 'loc'
6284: );
6285: my %authnames = &authtype_names();
1.320 raeburn 6286: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6287: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6288: my @courseroles = ('cc','in','ta','ep','st');
6289: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6290: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6291: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6292: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6293: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6294: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6295: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 ! raeburn 6296: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
! 6297: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
! 6298: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
! 6299: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
! 6300: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
! 6301: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
! 6302: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
! 6303: '<span class="LC_nobreak">'.&mt('Parameter').': '.
! 6304: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
! 6305: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
! 6306: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6307: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6308: foreach my $option ('sourcedid','email','other') {
6309: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6310: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6311: ($option eq 'other' ? '' : (' 'x2) );
6312: }
6313: $output .= '</span></div>'.
6314: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6315: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6316: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 ! raeburn 6317: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6318: foreach my $ltirole (@ltiroles) {
6319: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6320: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6321: }
6322: $output .= '</fieldset>'.
1.391 ! raeburn 6323: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6324: '<table>'.
6325: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6326: '</table>'.
6327: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6328: '<td class="LC_left_item">';
6329: foreach my $auth ('lti',@authtypes) {
6330: my $authtext;
6331: if ($auth eq 'lti') {
6332: $authtext = &mt('None');
6333: } else {
6334: $authtext = $authnames{$shortauth{$auth}};
6335: }
6336: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6337: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6338: $authtext.'</label></span> ';
6339: }
6340: $output .= '</td></tr>'.
6341: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6342: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6343: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6344: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6345: '</table></fieldset>'.
1.391 ! raeburn 6346: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
! 6347: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
! 6348: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
! 6349: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
! 6350: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
! 6351: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
! 6352: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
! 6353: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 6354: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
! 6355: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
! 6356: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
! 6357: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
! 6358: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
! 6359: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 6360: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
! 6361: '<span class="LC_nobreak">'.&mt('Menu items').': ';
! 6362: foreach my $type ('fullname','coursetitle','role','logout','grades') {
! 6363: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
! 6364: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
! 6365: (' 'x2);
! 6366: }
! 6367: $output .= '</span></div></fieldset>'.
! 6368: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6369: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6370: &mt('Unique course identifier').': ';
6371: foreach my $option ('course_offering_sourcedid','context_id','other') {
6372: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6373: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6374: ($option eq 'other' ? '' : (' 'x2) );
6375: }
1.334 raeburn 6376: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6377: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6378: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6379: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6380: foreach my $type (@coursetypes) {
6381: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6382: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6383: (' 'x2);
6384: }
6385: $output .= '</span></fieldset>'.
1.391 ! raeburn 6386: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
! 6387: foreach my $ltirole (@lticourseroles) {
! 6388: my ($selected,$selectnone);
! 6389: if ($rolemaps{$ltirole} eq '') {
! 6390: $selectnone = ' selected="selected"';
! 6391: }
! 6392: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
! 6393: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
! 6394: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
! 6395: foreach my $role (@courseroles) {
! 6396: unless ($selectnone) {
! 6397: if ($rolemaps{$ltirole} eq $role) {
! 6398: $selected = ' selected="selected"';
! 6399: } else {
! 6400: $selected = '';
! 6401: }
! 6402: }
! 6403: $output .= '<option value="'.$role.'"'.$selected.'>'.
! 6404: &Apache::lonnet::plaintext($role,'Course').
! 6405: '</option>';
! 6406: }
! 6407: $output .= '</select></td>';
! 6408: }
! 6409: $output .= '</tr></table></fieldset>'.
! 6410: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6411: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6412: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6413: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6414: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6415: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6416: '</fieldset>'.
1.391 ! raeburn 6417: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6418: foreach my $lticrsrole (@lticourseroles) {
6419: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6420: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6421: }
6422: $output .= '</fieldset>'.
1.391 ! raeburn 6423: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6424: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6425: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6426: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6427: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6428: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6429: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6430: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6431: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6432: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6433: &mt('Standard field').'</label>'.(' 'x2).
6434: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6435: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6436: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6437: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6438: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6439: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6440: foreach my $extra ('roster','passback') {
1.320 raeburn 6441: my $checkedon = '';
6442: my $checkedoff = ' checked="checked"';
1.337 raeburn 6443: if ($extra eq 'passback') {
6444: $pb1p1chk = ' checked="checked"';
6445: $pb1p0chk = '';
6446: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6447: } else {
6448: $onclickpb = '';
6449: }
1.320 raeburn 6450: if (ref($current) eq 'HASH') {
6451: if (($current->{$extra})) {
6452: $checkedon = $checkedoff;
6453: $checkedoff = '';
1.337 raeburn 6454: if ($extra eq 'passback') {
6455: $passbacksty = 'inline-block';
6456: }
6457: if ($current->{'passbackformat'} eq '1.0') {
6458: $pb1p0chk = ' checked="checked"';
6459: $pb1p1chk = '';
6460: }
1.320 raeburn 6461: }
6462: }
6463: $output .= $lt{$extra}.' '.
1.337 raeburn 6464: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6465: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6466: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6467: &mt('Yes').'</label><br />';
6468: }
1.337 raeburn 6469: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6470: '<span class="LC_nobreak">'.&mt('Grade format').
6471: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6472: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6473: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6474: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 ! raeburn 6475: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6476: $output .= '</span></div></fieldset>';
1.320 raeburn 6477: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6478: #
6479: # $output .= '</fieldset>'.
6480: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6481: return $output;
6482: }
6483:
1.326 raeburn 6484: sub ltimenu_titles {
6485: return &Apache::lonlocal::texthash(
6486: fullname => 'Full name',
6487: coursetitle => 'Course title',
6488: role => 'Role',
6489: logout => 'Logout',
6490: grades => 'Grades',
6491: );
6492: }
6493:
1.121 raeburn 6494: sub print_coursedefaults {
1.139 raeburn 6495: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6496: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6497: my $itemcount = 1;
1.192 raeburn 6498: my %choices = &Apache::lonlocal::texthash (
6499: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6500: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6501: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6502: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6503: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6504: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6505: texengine => 'Default method to display mathematics',
1.257 raeburn 6506: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6507: canclone => "People who may clone a course (besides course's owner and coordinators)",
6508: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6509: );
1.198 raeburn 6510: my %staticdefaults = (
6511: anonsurvey_threshold => 10,
6512: uploadquota => 500,
1.257 raeburn 6513: postsubmit => 60,
1.276 raeburn 6514: mysqltables => 172800,
1.198 raeburn 6515: );
1.139 raeburn 6516: if ($position eq 'top') {
1.257 raeburn 6517: %defaultchecked = (
6518: 'canuse_pdfforms' => 'off',
6519: 'uselcmath' => 'on',
6520: 'usejsme' => 'on',
1.289 raeburn 6521: 'canclone' => 'none',
1.257 raeburn 6522: );
6523: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6524: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6525: if (ref($settings) eq 'HASH') {
6526: if ($settings->{'texengine'}) {
6527: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6528: $deftex = $settings->{'texengine'};
6529: }
6530: }
6531: }
6532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6533: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6534: '<span class="LC_nobreak">'.$choices{'texengine'}.
6535: '</span></td><td class="LC_right_item">'.
6536: '<select name="texengine">'."\n";
6537: my %texoptions = (
6538: MathJax => 'MathJax',
6539: mimetex => &mt('Convert to Images'),
6540: tth => &mt('TeX to HTML'),
6541: );
6542: foreach my $renderer ('MathJax','mimetex','tth') {
6543: my $selected = '';
6544: if ($renderer eq $deftex) {
6545: $selected = ' selected="selected"';
6546: }
6547: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6548: }
6549: $mathdisp .= '</select></td></tr>'."\n";
6550: $itemcount ++;
1.139 raeburn 6551: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6552: \%choices,$itemcount);
1.314 raeburn 6553: $datatable = $mathdisp.$datatable;
1.264 raeburn 6554: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6555: $datatable .=
1.306 raeburn 6556: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6557: '<span class="LC_nobreak">'.$choices{'canclone'}.
6558: '</span></td><td class="LC_left_item">';
6559: my $currcanclone = 'none';
6560: my $onclick;
6561: my @cloneoptions = ('none','domain');
1.380 raeburn 6562: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6563: none => 'No additional course requesters',
6564: domain => "Any course requester in course's domain",
6565: instcode => 'Course requests for official courses ...',
6566: );
6567: my (%codedefaults,@code_order,@posscodes);
6568: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6569: \@code_order) eq 'ok') {
6570: if (@code_order > 0) {
6571: push(@cloneoptions,'instcode');
6572: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6573: }
6574: }
6575: if (ref($settings) eq 'HASH') {
6576: if ($settings->{'canclone'}) {
6577: if (ref($settings->{'canclone'}) eq 'HASH') {
6578: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6579: if (@code_order > 0) {
6580: $currcanclone = 'instcode';
6581: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6582: }
6583: }
6584: } elsif ($settings->{'canclone'} eq 'domain') {
6585: $currcanclone = $settings->{'canclone'};
6586: }
6587: }
1.289 raeburn 6588: }
1.264 raeburn 6589: foreach my $option (@cloneoptions) {
6590: my ($checked,$additional);
6591: if ($currcanclone eq $option) {
6592: $checked = ' checked="checked"';
6593: }
6594: if ($option eq 'instcode') {
6595: if (@code_order) {
6596: my $show = 'none';
6597: if ($checked) {
6598: $show = 'block';
6599: }
1.317 raeburn 6600: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6601: &mt('Institutional codes for new and cloned course have identical:').
6602: '<br />';
6603: foreach my $item (@code_order) {
6604: my $codechk;
6605: if ($checked) {
6606: if (grep(/^\Q$item\E$/,@posscodes)) {
6607: $codechk = ' checked="checked"';
6608: }
6609: }
6610: $additional .= '<label>'.
6611: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6612: $item.'</label>';
6613: }
6614: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6615: }
6616: }
6617: $datatable .=
6618: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6619: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6620: '</label> '.$additional.'</span><br />';
6621: }
6622: $datatable .= '</td>'.
6623: '</tr>';
6624: $itemcount ++;
1.139 raeburn 6625: } else {
6626: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6627: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6628: my $currusecredits = 0;
1.257 raeburn 6629: my $postsubmitclient = 1;
1.271 raeburn 6630: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6631: if (ref($settings) eq 'HASH') {
6632: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6633: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6634: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6635: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6636: }
6637: }
1.192 raeburn 6638: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6639: foreach my $type (@types) {
6640: next if ($type eq 'community');
6641: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6642: if ($defcredits{$type} ne '') {
6643: $currusecredits = 1;
6644: }
6645: }
6646: }
6647: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6648: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6649: $postsubmitclient = 0;
6650: foreach my $type (@types) {
6651: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6652: }
6653: } else {
6654: foreach my $type (@types) {
6655: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6656: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6657: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6658: } else {
6659: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6660: }
6661: } else {
6662: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6663: }
6664: }
6665: }
6666: } else {
6667: foreach my $type (@types) {
6668: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6669: }
6670: }
1.276 raeburn 6671: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6672: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6673: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6674: }
6675: } else {
6676: foreach my $type (@types) {
6677: $currmysql{$type} = $staticdefaults{'mysqltables'};
6678: }
6679: }
1.258 raeburn 6680: } else {
6681: foreach my $type (@types) {
6682: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6683: }
1.139 raeburn 6684: }
6685: if (!$currdefresponder) {
1.198 raeburn 6686: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6687: } elsif ($currdefresponder < 1) {
6688: $currdefresponder = 1;
6689: }
1.198 raeburn 6690: foreach my $type (@types) {
6691: if ($curruploadquota{$type} eq '') {
6692: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6693: }
6694: }
1.139 raeburn 6695: $datatable .=
1.192 raeburn 6696: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6697: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6698: '</span></td>'.
6699: '<td class="LC_right_item"><span class="LC_nobreak">'.
6700: '<input type="text" name="anonsurvey_threshold"'.
6701: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6702: '</td></tr>'."\n";
6703: $itemcount ++;
6704: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6705: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6706: $choices{'uploadquota'}.
6707: '</span></td>'.
1.306 raeburn 6708: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6709: '<table><tr>';
1.198 raeburn 6710: foreach my $type (@types) {
1.306 raeburn 6711: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6712: '<input type="text" name="uploadquota_'.$type.'"'.
6713: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6714: }
6715: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6716: $itemcount ++;
1.236 raeburn 6717: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6718: my $display = 'none';
1.192 raeburn 6719: if ($currusecredits) {
6720: $display = 'block';
6721: }
6722: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6723: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6724: foreach my $type (@types) {
6725: next if ($type eq 'community');
1.306 raeburn 6726: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6727: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 6728: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 6729: }
6730: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 6731: %defaultchecked = ('coursecredits' => 'off');
6732: @toggles = ('coursecredits');
6733: my $current = {
6734: 'coursecredits' => $currusecredits,
6735: };
6736: (my $table,$itemcount) =
6737: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 6738: \%choices,$itemcount,$onclick,$additional,'left');
6739: $datatable .= $table;
6740: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6741: my $display = 'none';
6742: if ($postsubmitclient) {
6743: $display = 'block';
6744: }
6745: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 6746: &mt('Number of seconds submit is disabled').'<br />'.
6747: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6748: '<table><tr>';
1.257 raeburn 6749: foreach my $type (@types) {
1.306 raeburn 6750: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 6751: '<input type="text" name="'.$type.'_timeout" value="'.
6752: $deftimeout{$type}.'" size="5" /></td>';
6753: }
6754: $additional .= '</tr></table></div>'."\n";
6755: %defaultchecked = ('postsubmit' => 'on');
6756: @toggles = ('postsubmit');
1.280 raeburn 6757: $current = {
6758: 'postsubmit' => $postsubmitclient,
6759: };
1.257 raeburn 6760: ($table,$itemcount) =
6761: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6762: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 6763: $datatable .= $table;
1.276 raeburn 6764: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6765: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6766: $choices{'mysqltables'}.
6767: '</span></td>'.
1.306 raeburn 6768: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 6769: '<table><tr>';
6770: foreach my $type (@types) {
1.306 raeburn 6771: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 6772: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 6773: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 6774: }
6775: $datatable .= '</tr></table></td></tr>'."\n";
6776: $itemcount ++;
6777:
1.139 raeburn 6778: }
1.192 raeburn 6779: $$rowtotal += $itemcount;
1.121 raeburn 6780: return $datatable;
1.118 jms 6781: }
6782:
1.231 raeburn 6783: sub print_selfenrollment {
6784: my ($position,$dom,$settings,$rowtotal) = @_;
6785: my ($css_class,$datatable);
6786: my $itemcount = 1;
1.271 raeburn 6787: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 6788: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 6789: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6790: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 6791: my @rows;
6792: my $key;
6793: if ($position eq 'top') {
6794: $key = 'admin';
6795: if (ref($rowsref) eq 'ARRAY') {
6796: @rows = @{$rowsref};
6797: }
6798: } elsif ($position eq 'middle') {
6799: $key = 'default';
6800: @rows = ('types','registered','approval','limit');
6801: }
6802: foreach my $row (@rows) {
6803: if (defined($titlesref->{$row})) {
6804: $itemcount ++;
6805: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6806: $datatable .= '<tr'.$css_class.'>'.
6807: '<td>'.$titlesref->{$row}.'</td>'.
6808: '<td class="LC_left_item">'.
6809: '<table><tr>';
6810: my (%current,%currentcap);
6811: if (ref($settings) eq 'HASH') {
6812: if (ref($settings->{$key}) eq 'HASH') {
6813: foreach my $type (@types) {
6814: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6815: $current{$type} = $settings->{$key}->{$type}->{$row};
6816: }
6817: if (($row eq 'limit') && ($key eq 'default')) {
6818: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6819: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6820: }
6821: }
6822: }
6823: }
6824: }
6825: my %roles = (
6826: '0' => &Apache::lonnet::plaintext('dc'),
6827: );
6828:
6829: foreach my $type (@types) {
6830: unless (($row eq 'registered') && ($key eq 'default')) {
6831: $datatable .= '<th>'.&mt($type).'</th>';
6832: }
6833: }
6834: unless (($row eq 'registered') && ($key eq 'default')) {
6835: $datatable .= '</tr><tr>';
6836: }
6837: foreach my $type (@types) {
6838: if ($type eq 'community') {
6839: $roles{'1'} = &mt('Community personnel');
6840: } else {
6841: $roles{'1'} = &mt('Course personnel');
6842: }
6843: $datatable .= '<td style="vertical-align: top">';
6844: if ($position eq 'top') {
6845: my %checked;
6846: if ($current{$type} eq '0') {
6847: $checked{'0'} = ' checked="checked"';
6848: } else {
6849: $checked{'1'} = ' checked="checked"';
6850: }
6851: foreach my $role ('1','0') {
6852: $datatable .= '<span class="LC_nobreak"><label>'.
6853: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6854: 'value="'.$role.'"'.$checked{$role}.' />'.
6855: $roles{$role}.'</label></span> ';
6856: }
6857: } else {
6858: if ($row eq 'types') {
6859: my %checked;
6860: if ($current{$type} =~ /^(all|dom)$/) {
6861: $checked{$1} = ' checked="checked"';
6862: } else {
6863: $checked{''} = ' checked="checked"';
6864: }
6865: foreach my $val ('','dom','all') {
6866: $datatable .= '<span class="LC_nobreak"><label>'.
6867: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6868: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6869: }
6870: } elsif ($row eq 'registered') {
6871: my %checked;
6872: if ($current{$type} eq '1') {
6873: $checked{'1'} = ' checked="checked"';
6874: } else {
6875: $checked{'0'} = ' checked="checked"';
6876: }
6877: foreach my $val ('0','1') {
6878: $datatable .= '<span class="LC_nobreak"><label>'.
6879: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6880: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6881: }
6882: } elsif ($row eq 'approval') {
6883: my %checked;
6884: if ($current{$type} =~ /^([12])$/) {
6885: $checked{$1} = ' checked="checked"';
6886: } else {
6887: $checked{'0'} = ' checked="checked"';
6888: }
6889: for my $val (0..2) {
6890: $datatable .= '<span class="LC_nobreak"><label>'.
6891: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6892: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6893: }
6894: } elsif ($row eq 'limit') {
6895: my %checked;
6896: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6897: $checked{$1} = ' checked="checked"';
6898: } else {
6899: $checked{'none'} = ' checked="checked"';
6900: }
6901: my $cap;
6902: if ($currentcap{$type} =~ /^\d+$/) {
6903: $cap = $currentcap{$type};
6904: }
6905: foreach my $val ('none','allstudents','selfenrolled') {
6906: $datatable .= '<span class="LC_nobreak"><label>'.
6907: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6908: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6909: }
6910: $datatable .= '<br />'.
6911: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6912: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6913: '</span>';
6914: }
6915: }
6916: $datatable .= '</td>';
6917: }
6918: $datatable .= '</tr>';
6919: }
6920: $datatable .= '</table></td></tr>';
6921: }
6922: } elsif ($position eq 'bottom') {
1.235 raeburn 6923: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6924: }
6925: $$rowtotal += $itemcount;
6926: return $datatable;
6927: }
6928:
6929: sub print_validation_rows {
6930: my ($caller,$dom,$settings,$rowtotal) = @_;
6931: my ($itemsref,$namesref,$fieldsref);
6932: if ($caller eq 'selfenroll') {
6933: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6934: } elsif ($caller eq 'requestcourses') {
6935: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6936: }
6937: my %currvalidation;
6938: if (ref($settings) eq 'HASH') {
6939: if (ref($settings->{'validation'}) eq 'HASH') {
6940: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 6941: }
1.235 raeburn 6942: }
6943: my $datatable;
6944: my $itemcount = 0;
6945: foreach my $item (@{$itemsref}) {
6946: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6947: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6948: $namesref->{$item}.
6949: '</span></td>'.
6950: '<td class="LC_left_item">';
6951: if (($item eq 'url') || ($item eq 'button')) {
6952: $datatable .= '<span class="LC_nobreak">'.
6953: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6954: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6955: } elsif ($item eq 'fields') {
6956: my @currfields;
6957: if (ref($currvalidation{$item}) eq 'ARRAY') {
6958: @currfields = @{$currvalidation{$item}};
6959: }
6960: foreach my $field (@{$fieldsref}) {
6961: my $check = '';
6962: if (grep(/^\Q$field\E$/,@currfields)) {
6963: $check = ' checked="checked"';
6964: }
6965: $datatable .= '<span class="LC_nobreak"><label>'.
6966: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6967: ' value="'.$field.'"'.$check.' />'.$field.
6968: '</label></span> ';
6969: }
6970: } elsif ($item eq 'markup') {
1.334 raeburn 6971: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 6972: $currvalidation{$item}.
1.231 raeburn 6973: '</textarea>';
1.235 raeburn 6974: }
6975: $datatable .= '</td></tr>'."\n";
6976: if (ref($rowtotal)) {
1.231 raeburn 6977: $itemcount ++;
6978: }
6979: }
1.235 raeburn 6980: if ($caller eq 'requestcourses') {
6981: my %currhash;
1.248 raeburn 6982: if (ref($settings) eq 'HASH') {
6983: if (ref($settings->{'validation'}) eq 'HASH') {
6984: if ($settings->{'validation'}{'dc'} ne '') {
6985: $currhash{$settings->{'validation'}{'dc'}} = 1;
6986: }
1.235 raeburn 6987: }
6988: }
6989: my $numinrow = 2;
6990: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6991: 'validationdc',%currhash);
1.247 raeburn 6992: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 6993: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 6994: if ($numdc > 1) {
1.247 raeburn 6995: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 6996: } else {
1.247 raeburn 6997: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 6998: }
1.247 raeburn 6999: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7000: $itemcount ++;
7001: }
7002: if (ref($rowtotal)) {
7003: $$rowtotal += $itemcount;
7004: }
1.231 raeburn 7005: return $datatable;
7006: }
7007:
1.357 raeburn 7008: sub print_privacy {
7009: my ($position,$dom,$settings,$rowtotal) = @_;
7010: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7011: my $itemcount = 0;
7012: unless ($position eq 'top') {
7013: @items = ('domain','author','course','community');
7014: %names = &Apache::lonlocal::texthash (
7015: domain => 'Assigned domain role(s)',
7016: author => 'Assigned co-author role(s)',
7017: course => 'Assigned course role(s)',
7018: community => 'Assigned community role',
7019: );
7020: $numinrow = 4;
7021: ($othertitle,$usertypes,$types) =
7022: &Apache::loncommon::sorted_inst_types($dom);
7023: }
7024: if (($position eq 'top') || ($position eq 'middle')) {
7025: my (%by_ip,%by_location,@intdoms,@instdoms);
7026: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7027: if ($position eq 'top') {
7028: my %curr;
7029: my @options = ('none','user','domain','auto');
7030: my %titles = &Apache::lonlocal::texthash (
7031: none => 'Not allowed',
7032: user => 'User authorizes',
7033: domain => 'DC authorizes',
7034: auto => 'Unrestricted',
7035: instdom => 'Other domain shares institution/provider',
7036: extdom => 'Other domain has different institution/provider',
7037: );
7038: my %names = &Apache::lonlocal::texthash (
7039: domain => 'Domain role',
7040: author => 'Co-author role',
7041: course => 'Course role',
7042: community => 'Community role',
7043: );
7044: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7045: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7046: foreach my $domtype ('instdom','extdom') {
7047: my (%checked,$skip);
7048: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7049: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7050: '<td class="LC_left_item">';
7051: if ($domtype eq 'instdom') {
7052: unless (@instdoms > 1) {
7053: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7054: $skip = 1;
7055: }
7056: } elsif ($domtype eq 'extdom') {
7057: if (keys(%by_location) == 0) {
7058: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7059: $skip = 1;
7060: }
7061: }
7062: unless ($skip) {
7063: foreach my $roletype ('domain','author','course','community') {
7064: $checked{'auto'} = ' checked="checked"';
7065: if (ref($settings) eq 'HASH') {
7066: if (ref($settings->{approval}) eq 'HASH') {
7067: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7068: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7069: $checked{$1} = ' checked="checked"';
7070: $checked{'auto'} = '';
7071: }
7072: }
7073: }
7074: }
7075: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7076: foreach my $option (@options) {
7077: $datatable .= '<span class="LC_nobreak"><label>'.
7078: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7079: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7080: '</label></span> ';
7081: }
7082: $datatable .= '</fieldset>';
7083: }
7084: }
7085: $datatable .= '</td></tr>';
7086: $itemcount ++;
7087: }
7088: } elsif ($position eq 'middle') {
7089: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7090: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7091: foreach my $item (@{$types}) {
7092: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7093: $numinrow,$itemcount,'','','','','',
7094: '',$usertypes->{$item});
7095: $itemcount ++;
7096: }
7097: }
7098: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7099: $numinrow,$itemcount,'','','','','',
7100: '',$othertitle);
7101: $itemcount ++;
7102: } else {
1.360 raeburn 7103: my (@insttypes,%insttitles);
7104: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7105: @insttypes = @{$types};
7106: %insttitles = %{$usertypes};
7107: }
7108: foreach my $item (@insttypes,'default') {
7109: my $title;
7110: if ($item eq 'default') {
7111: $title = $othertitle;
7112: } else {
7113: $title = $insttitles{$item};
7114: }
7115: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7116: $datatable .= '<tr'.$css_class.'>'.
7117: '<td class="LC_left_item">'.$title.'</td>'.
7118: '<td class="LC_left_item">'.
7119: &mt('Nothing to set here, as there are no other domains').
7120: '</td></tr>';
7121: $itemcount ++;
7122: }
1.357 raeburn 7123: }
7124: }
7125: } else {
7126: my $prefix;
7127: if ($position eq 'lower') {
7128: $prefix = 'priv';
7129: } else {
7130: $prefix = 'unpriv';
7131: }
7132: foreach my $item (@items) {
7133: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7134: $numinrow,$itemcount,'','','','','',
7135: '',$names{$item});
7136: $itemcount ++;
7137: }
7138: }
7139: if (ref($rowtotal)) {
7140: $$rowtotal += $itemcount;
7141: }
7142: return $datatable;
7143: }
7144:
1.354 raeburn 7145: sub print_passwords {
7146: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7147: my ($datatable,$css_class);
7148: my $itemcount = 0;
7149: my %titles = &Apache::lonlocal::texthash (
7150: captcha => '"Forgot Password" CAPTCHA validation',
7151: link => 'Reset link expiration (hours)',
7152: case => 'Case-sensitive usernames/e-mail',
7153: prelink => 'Information required (form 1)',
7154: postlink => 'Information required (form 2)',
7155: emailsrc => 'LON-CAPA e-mail address type(s)',
7156: customtext => 'Domain specific text (HTML)',
7157: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7158: intauth_check => 'Check bcrypt cost if authenticated',
7159: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7160: permanent => 'Permanent e-mail address',
7161: critical => 'Critical notification address',
7162: notify => 'Notification address',
7163: min => 'Minimum password length',
7164: max => 'Maximum password length',
7165: chars => 'Required characters',
7166: expire => 'Password expiration (days)',
1.356 raeburn 7167: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7168: );
7169: if ($position eq 'top') {
7170: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7171: my $shownlinklife = 2;
7172: my $prelink = 'both';
7173: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7174: if (ref($settings) eq 'HASH') {
7175: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7176: $shownlinklife = $settings->{resetlink};
7177: }
7178: if (ref($settings->{resetcase}) eq 'ARRAY') {
7179: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7180: }
7181: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7182: $prelink = $settings->{resetprelink};
7183: }
7184: if (ref($settings->{resetpostlink}) eq 'HASH') {
7185: %postlink = %{$settings->{resetpostlink}};
7186: }
7187: if (ref($settings->{resetemail}) eq 'ARRAY') {
7188: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7189: }
7190: if ($settings->{resetremove}) {
7191: $nostdtext = 1;
7192: }
7193: if ($settings->{resetcustom}) {
7194: $customurl = $settings->{resetcustom};
7195: }
7196: } else {
7197: if (ref($types) eq 'ARRAY') {
7198: foreach my $item (@{$types}) {
7199: $casesens{$item} = 1;
7200: $postlink{$item} = ['username','email'];
7201: }
7202: }
7203: $casesens{'default'} = 1;
7204: $postlink{'default'} = ['username','email'];
7205: $prelink = 'both';
7206: %emailsrc = (
7207: permanent => 1,
7208: critical => 1,
7209: notify => 1,
7210: );
7211: }
7212: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7213: $itemcount ++;
7214: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7215: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7216: '<td class="LC_left_item">'.
7217: '<input type="textbox" value="'.$shownlinklife.'" '.
7218: 'name="passwords_link" size="3" /></td></tr>';
7219: $itemcount ++;
7220: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7221: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7222: '<td class="LC_left_item">';
7223: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7224: foreach my $item (@{$types}) {
7225: my $checkedcase;
7226: if ($casesens{$item}) {
7227: $checkedcase = ' checked="checked"';
7228: }
7229: $datatable .= '<span class="LC_nobreak"><label>'.
7230: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7231: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7232: '</span> ';
1.354 raeburn 7233: }
7234: }
7235: my $checkedcase;
7236: if ($casesens{'default'}) {
7237: $checkedcase = ' checked="checked"';
7238: }
7239: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7240: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7241: $othertitle.'</label></span></td>';
7242: $itemcount ++;
7243: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7244: my %checkedpre = (
7245: both => ' checked="checked"',
7246: either => '',
7247: );
7248: if ($prelink eq 'either') {
7249: $checkedpre{either} = ' checked="checked"';
7250: $checkedpre{both} = '';
7251: }
7252: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7253: '<td class="LC_left_item"><span class="LC_nobreak">'.
7254: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7255: &mt('Both username and e-mail address').'</label></span> '.
7256: '<span class="LC_nobreak"><label>'.
7257: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7258: &mt('Either username or e-mail address').'</label></span></td></tr>';
7259: $itemcount ++;
7260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7261: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7262: '<td class="LC_left_item">';
7263: my %postlinked;
7264: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7265: foreach my $item (@{$types}) {
7266: undef(%postlinked);
7267: $datatable .= '<fieldset style="display: inline-block;">'.
7268: '<legend>'.$usertypes->{$item}.'</legend>';
7269: if (ref($postlink{$item}) eq 'ARRAY') {
7270: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7271: }
7272: foreach my $field ('email','username') {
7273: my $checked;
7274: if ($postlinked{$field}) {
7275: $checked = ' checked="checked"';
7276: }
7277: $datatable .= '<span class="LC_nobreak"><label>'.
7278: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7279: $field.'"'.$checked.' />'.$field.'</label>'.
7280: '<span> ';
7281: }
7282: $datatable .= '</fieldset>';
7283: }
7284: }
7285: if (ref($postlink{'default'}) eq 'ARRAY') {
7286: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7287: }
7288: $datatable .= '<fieldset style="display: inline-block;">'.
7289: '<legend>'.$othertitle.'</legend>';
7290: foreach my $field ('email','username') {
7291: my $checked;
7292: if ($postlinked{$field}) {
7293: $checked = ' checked="checked"';
7294: }
7295: $datatable .= '<span class="LC_nobreak"><label>'.
7296: '<input type="checkbox" name="passwords_postlink_default" value="'.
7297: $field.'"'.$checked.' />'.$field.'</label>'.
7298: '<span> ';
7299: }
7300: $datatable .= '</fieldset></td></tr>';
7301: $itemcount ++;
7302: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7303: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7304: '<td class="LC_left_item">';
7305: foreach my $type ('permanent','critical','notify') {
7306: my $checkedemail;
7307: if ($emailsrc{$type}) {
7308: $checkedemail = ' checked="checked"';
7309: }
7310: $datatable .= '<span class="LC_nobreak"><label>'.
7311: '<input type="checkbox" name="passwords_emailsrc" value="'.
7312: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7313: '<span> ';
7314: }
7315: $datatable .= '</td></tr>';
7316: $itemcount ++;
7317: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7318: my $switchserver = &check_switchserver($dom,$confname);
7319: my ($showstd,$noshowstd);
7320: if ($nostdtext) {
7321: $noshowstd = ' checked="checked"';
7322: } else {
7323: $showstd = ' checked="checked"';
7324: }
7325: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7326: '<td class="LC_left_item"><span class="LC_nobreak">'.
7327: &mt('Retain standard text:').
7328: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7329: &mt('Yes').'</label>'.' '.
7330: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7331: &mt('No').'</label></span><br />'.
7332: '<span class="LC_fontsize_small">'.
7333: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7334: &mt('Include custom text:');
7335: if ($customurl) {
1.369 raeburn 7336: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7337: undef,undef,undef,undef,'background-color:#ffffff');
7338: $datatable .= '<span class="LC_nobreak"> '.$link.
7339: '<label><input type="checkbox" name="passwords_custom_del"'.
7340: ' value="1" />'.&mt('Delete?').'</label></span>'.
7341: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7342: }
7343: if ($switchserver) {
7344: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7345: } else {
7346: $datatable .='<span class="LC_nobreak"> '.
7347: '<input type="file" name="passwords_customfile" /></span>';
7348: }
7349: $datatable .= '</td></tr>';
7350: } elsif ($position eq 'middle') {
7351: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7352: my @items = ('intauth_cost','intauth_check','intauth_switch');
7353: my %defaults;
7354: if (ref($domconf{'defaults'}) eq 'HASH') {
7355: %defaults = %{$domconf{'defaults'}};
7356: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7357: $defaults{'intauth_cost'} = 10;
7358: }
7359: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7360: $defaults{'intauth_check'} = 0;
7361: }
7362: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7363: $defaults{'intauth_switch'} = 0;
7364: }
7365: } else {
7366: %defaults = (
7367: 'intauth_cost' => 10,
7368: 'intauth_check' => 0,
7369: 'intauth_switch' => 0,
7370: );
7371: }
7372: foreach my $item (@items) {
7373: if ($itemcount%2) {
7374: $css_class = '';
7375: } else {
7376: $css_class = ' class="LC_odd_row" ';
7377: }
7378: $datatable .= '<tr'.$css_class.'>'.
7379: '<td><span class="LC_nobreak">'.$titles{$item}.
7380: '</span></td><td class="LC_left_item" colspan="3">';
7381: if ($item eq 'intauth_switch') {
7382: my @options = (0,1,2);
7383: my %optiondesc = &Apache::lonlocal::texthash (
7384: 0 => 'No',
7385: 1 => 'Yes',
7386: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7387: );
7388: $datatable .= '<table width="100%">';
7389: foreach my $option (@options) {
7390: my $checked = ' ';
7391: if ($defaults{$item} eq $option) {
7392: $checked = ' checked="checked"';
7393: }
7394: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7395: '<label><input type="radio" name="'.$item.
7396: '" value="'.$option.'"'.$checked.' />'.
7397: $optiondesc{$option}.'</label></span></td></tr>';
7398: }
7399: $datatable .= '</table>';
7400: } elsif ($item eq 'intauth_check') {
7401: my @options = (0,1,2);
7402: my %optiondesc = &Apache::lonlocal::texthash (
7403: 0 => 'No',
7404: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7405: 2 => 'Yes, disallow login if stored cost is less than domain default',
7406: );
7407: $datatable .= '<table width="100%">';
7408: foreach my $option (@options) {
7409: my $checked = ' ';
7410: my $onclick;
7411: if ($defaults{$item} eq $option) {
7412: $checked = ' checked="checked"';
7413: }
7414: if ($option == 2) {
7415: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7416: }
7417: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7418: '<label><input type="radio" name="'.$item.
7419: '" value="'.$option.'"'.$checked.$onclick.' />'.
7420: $optiondesc{$option}.'</label></span></td></tr>';
7421: }
7422: $datatable .= '</table>';
7423: } else {
7424: $datatable .= '<input type="text" name="'.$item.'" value="'.
7425: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7426: }
7427: $datatable .= '</td></tr>';
7428: $itemcount ++;
7429: }
7430: } elsif ($position eq 'lower') {
1.356 raeburn 7431: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7432: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7433: if (ref($settings) eq 'HASH') {
7434: if ($settings->{min}) {
7435: $min = $settings->{min};
7436: }
7437: if ($settings->{max}) {
7438: $max = $settings->{max};
7439: }
7440: if (ref($settings->{chars}) eq 'ARRAY') {
7441: map { $chars{$_} = 1; } (@{$settings->{chars}});
7442: }
7443: if ($settings->{expire}) {
7444: $expire = $settings->{expire};
7445: }
1.358 raeburn 7446: if ($settings->{numsaved}) {
7447: $numsaved = $settings->{numsaved};
1.356 raeburn 7448: }
1.354 raeburn 7449: }
7450: my %rulenames = &Apache::lonlocal::texthash(
7451: uc => 'At least one upper case letter',
7452: lc => 'At least one lower case letter',
7453: num => 'At least one number',
7454: spec => 'At least one non-alphanumeric',
7455: );
7456: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7457: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7458: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7459: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7460: 'onblur="javascript:warnIntPass(this);" />'.
7461: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7462: '</span></td></tr>';
7463: $itemcount ++;
7464: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7465: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7466: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7467: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7468: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7469: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7470: '</span></td></tr>';
7471: $itemcount ++;
7472: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7473: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7474: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7475: '</span></td>';
7476: my $numinrow = 2;
7477: my @possrules = ('uc','lc','num','spec');
7478: $datatable .= '<td class="LC_left_item"><table>';
7479: for (my $i=0; $i<@possrules; $i++) {
7480: my ($rem,$checked);
7481: if ($chars{$possrules[$i]}) {
7482: $checked = ' checked="checked"';
7483: }
7484: $rem = $i%($numinrow);
7485: if ($rem == 0) {
7486: if ($i > 0) {
7487: $datatable .= '</tr>';
7488: }
7489: $datatable .= '<tr>';
7490: }
7491: $datatable .= '<td><span class="LC_nobreak"><label>'.
7492: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7493: $rulenames{$possrules[$i]}.'</label></span></td>';
7494: }
7495: my $rem = @possrules%($numinrow);
7496: my $colsleft = $numinrow - $rem;
7497: if ($colsleft > 1 ) {
7498: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7499: ' </td>';
7500: } elsif ($colsleft == 1) {
7501: $datatable .= '<td class="LC_left_item"> </td>';
7502: }
7503: $datatable .='</table></td></tr>';
7504: $itemcount ++;
7505: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7506: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7507: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7508: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7509: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7510: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7511: '</span></td></tr>';
1.356 raeburn 7512: $itemcount ++;
7513: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7514: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7515: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7516: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7517: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7518: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7519: '</span></td></tr>';
1.354 raeburn 7520: } else {
1.359 raeburn 7521: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7522: my %ownerchg = (
7523: by => {},
7524: for => {},
7525: );
7526: my %ownertitles = &Apache::lonlocal::texthash (
7527: by => 'Course owner status(es) allowed',
7528: for => 'Student status(es) allowed',
7529: );
1.354 raeburn 7530: if (ref($settings) eq 'HASH') {
1.359 raeburn 7531: if (ref($settings->{crsownerchg}) eq 'HASH') {
7532: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7533: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7534: }
7535: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7536: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7537: }
1.354 raeburn 7538: }
7539: }
7540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7541: $datatable .= '<tr '.$css_class.'>'.
7542: '<td>'.
7543: &mt('Requirements').'<ul>'.
1.359 raeburn 7544: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7545: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7546: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7547: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7548: '</ul>'.
7549: '</td>'.
1.359 raeburn 7550: '<td class="LC_left_item">';
7551: foreach my $item ('by','for') {
7552: $datatable .= '<fieldset style="display: inline-block;">'.
7553: '<legend>'.$ownertitles{$item}.'</legend>';
7554: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7555: foreach my $type (@{$types}) {
7556: my $checked;
7557: if ($ownerchg{$item}{$type}) {
7558: $checked = ' checked="checked"';
7559: }
7560: $datatable .= '<span class="LC_nobreak"><label>'.
7561: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7562: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7563: '</span> ';
1.359 raeburn 7564: }
7565: }
7566: my $checked;
7567: if ($ownerchg{$item}{'default'}) {
7568: $checked = ' checked="checked"';
7569: }
7570: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7571: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7572: $othertitle.'</label></span></fieldset>';
7573: }
7574: $datatable .= '</td></tr>';
1.354 raeburn 7575: }
7576: return $datatable;
7577: }
7578:
1.373 raeburn 7579: sub print_wafproxy {
7580: my ($position,$dom,$settings,$rowtotal) = @_;
7581: my $css_class;
7582: my $itemcount = 0;
7583: my $datatable;
7584: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7585: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7586: my %lt = &wafproxy_titles();
1.373 raeburn 7587: foreach my $server (sort(keys(%servers))) {
7588: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7589: next if ($serverhome eq '');
1.373 raeburn 7590: my $serverdom;
7591: if ($serverhome ne $server) {
7592: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7593: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7594: $othercontrol{$server} = $serverdom;
7595: }
1.373 raeburn 7596: } else {
7597: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7598: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7599: if ($serverdom ne $dom) {
7600: $othercontrol{$server} = $serverdom;
7601: } else {
7602: $setdom = 1;
7603: if (ref($settings) eq 'HASH') {
7604: if (ref($settings->{'alias'}) eq 'HASH') {
7605: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7606: if ($aliases{$dom} ne '') {
7607: $showdom = 1;
7608: }
1.373 raeburn 7609: }
1.388 raeburn 7610: if (ref($settings->{'saml'}) eq 'HASH') {
7611: $saml{$dom} = $settings->{'saml'};
7612: }
1.373 raeburn 7613: }
7614: }
7615: }
7616: }
1.381 raeburn 7617: if ($setdom) {
7618: %{$values{$dom}} = ();
7619: if (ref($settings) eq 'HASH') {
7620: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7621: $values{$dom}{$item} = $settings->{$item};
7622: }
7623: }
7624: }
1.373 raeburn 7625: if (keys(%othercontrol)) {
7626: %otherdoms = reverse(%othercontrol);
7627: foreach my $domain (keys(%otherdoms)) {
7628: %{$values{$domain}} = ();
7629: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 7630: if (ref($config{'wafproxy'}) eq 'HASH') {
7631: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 7632: if (exists($config{'wafproxy'}{'saml'})) {
7633: $saml{$domain} = $config{'wafproxy'}{'saml'};
7634: }
1.383 raeburn 7635: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7636: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 7637: }
7638: }
7639: }
7640: }
7641: if ($position eq 'top') {
7642: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7643: my %aliasinfo;
1.373 raeburn 7644: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7645: $itemcount ++;
7646: my $dom_in_effect;
7647: my $aliasrows = '<tr>'.
1.383 raeburn 7648: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7649: &mt('Hostname').': '.
7650: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 7651: if ($othercontrol{$server}) {
1.381 raeburn 7652: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 7653: my ($current,$forsaml);
1.383 raeburn 7654: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7655: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 7656: }
1.388 raeburn 7657: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7658: if ($saml{$dom_in_effect}{$server}) {
7659: $forsaml = 1;
7660: }
7661: }
1.383 raeburn 7662: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7663: &mt('Alias').': ';
1.373 raeburn 7664: if ($current) {
1.381 raeburn 7665: $aliasrows .= $current;
1.388 raeburn 7666: if ($forsaml) {
7667: $aliasrows .= ' ('.&mt('also for Shibboleth').')';
7668: }
1.373 raeburn 7669: } else {
1.383 raeburn 7670: $aliasrows .= &mt('None');
1.373 raeburn 7671: }
1.383 raeburn 7672: $aliasrows .= ' <span class="LC_small">('.
7673: &mt('controlled by domain: [_1]',
7674: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 7675: } else {
1.381 raeburn 7676: $dom_in_effect = $dom;
1.388 raeburn 7677: my ($current,$samlon,$samloff);
7678: $samloff = ' checked="checked"';
1.373 raeburn 7679: if (ref($aliases{$dom}) eq 'HASH') {
7680: if ($aliases{$dom}{$server}) {
7681: $current = $aliases{$dom}{$server};
7682: }
7683: }
1.388 raeburn 7684: if (ref($saml{$dom}) eq 'HASH') {
7685: if ($saml{$dom}{$server}) {
7686: $samlon = $samloff;
7687: undef($samloff);
7688: }
7689: }
1.383 raeburn 7690: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7691: &mt('Alias').': '.
1.381 raeburn 7692: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 7693: 'value="'.$current.'" size="30" />'.
7694: (' 'x2).'<span class="LC_nobreak">'.
7695: &mt('Alias used for Shibboleth').': <label>'.
7696: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7697: &mt('No').'</label> <label>'.
7698: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7699: &mt('Yes').'</label></span>'.
7700: '</td>';
1.381 raeburn 7701: }
7702: $aliasrows .= '</tr>';
7703: $aliasinfo{$dom_in_effect} .= $aliasrows;
7704: }
7705: if ($aliasinfo{$dom}) {
7706: my ($onclick,$wafon,$wafoff,$showtable);
7707: $onclick = ' onclick="javascript:toggleWAF();"';
7708: $wafoff = ' checked="checked"';
7709: $showtable = ' style="display:none";';
7710: if ($showdom) {
7711: $wafon = $wafoff;
7712: $wafoff = '';
7713: $showtable = ' style="display:inline;"';
7714: }
7715: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7716: $datatable = '<tr'.$css_class.'>'.
7717: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7718: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7719: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7720: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7721: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7722: &mt('No').'</label></span></td>'.
7723: '<td class="LC_left_item">'.
7724: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7725: '</table></td></tr>';
7726: $itemcount++;
7727: }
1.383 raeburn 7728: if (keys(%otherdoms)) {
7729: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 7730: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 7731: $datatable .= '<tr'.$css_class.'>'.
7732: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7733: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7734: '</table></td></tr>';
1.381 raeburn 7735: $itemcount++;
1.373 raeburn 7736: }
7737: }
7738: } else {
1.383 raeburn 7739: my %ip_methods = &remoteip_methods();
1.373 raeburn 7740: if ($setdom) {
7741: $itemcount ++;
7742: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 7743: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 7744: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 7745: $wafstyle = ' style="display:none;"';
7746: $nowafstyle = ' style="display:table-row;"';
7747: $currwafdisplay = ' style="display: none"';
7748: $wafrangestyle = ' style="display: none"';
7749: $curr_remotip = 'n';
1.382 raeburn 7750: $ssltossl = ' checked="checked"';
1.381 raeburn 7751: if ($showdom) {
7752: $wafstyle = ' style="display:table-row;"';
7753: $nowafstyle = ' style="display:none;"';
7754: if (keys(%{$values{$dom}})) {
7755: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7756: $curr_remotip = $values{$dom}{remoteip};
7757: }
7758: if ($curr_remotip eq 'h') {
7759: $currwafdisplay = ' style="display:table-row"';
7760: $wafrangestyle = ' style="display:inline-block;"';
7761: }
1.382 raeburn 7762: if ($values{$dom}{'sslopt'}) {
7763: $alltossl = ' checked="checked"';
7764: $ssltossl = '';
7765: }
1.381 raeburn 7766: }
7767: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7768: $vpndircheck = ' checked="checked"';
7769: $currwafvpn = ' style="display:table-row;"';
7770: $wafrangestyle = ' style="display:inline-block;"';
7771: } else {
7772: $vpnaliascheck = ' checked="checked"';
7773: $currwafvpn = ' style="display:none;"';
7774: }
7775: }
7776: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7777: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7778: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7779: '</tr>'.
7780: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 7781: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 7782: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7783: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'</div></td>'.
7784: '<td class="LC_left_item"><table>'.
7785: '<tr>'.
7786: '<td valign="top">'.$lt{'remoteip'}.': '.
7787: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7788: foreach my $option ('m','h','n') {
7789: my $sel;
7790: if ($option eq $curr_remotip) {
7791: $sel = ' selected="selected"';
7792: }
7793: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7794: $ip_methods{$option}.'</option>';
7795: }
7796: $datatable .= '</select></td></tr>'."\n".
7797: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7798: $lt{'ipheader'}.': '.
7799: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7800: 'name="wafproxy_ipheader" />'.
7801: '</td></tr>'."\n".
7802: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 7803: $lt{'trusted'}.':<br />'.
1.381 raeburn 7804: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7805: $values{$dom}{'trusted'}.'</textarea>'.
7806: '</td></tr>'."\n".
7807: '<tr><td><hr /></td></tr>'."\n".
7808: '<tr>'.
7809: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7810: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7811: $lt{'vpndirect'}.'</label>'.(' 'x2).
7812: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7813: $lt{'vpnaliased'}.'</label></span></td></tr>';
7814: foreach my $item ('vpnint','vpnext') {
7815: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 7816: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 7817: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7818: $values{$dom}{$item}.'</textarea>'.
7819: '</td></tr>'."\n";
1.373 raeburn 7820: }
1.382 raeburn 7821: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7822: '<tr>'.
7823: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7824: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7825: $lt{'alltossl'}.'</label>'.(' 'x2).
7826: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7827: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7828: '</table></td></tr>';
1.373 raeburn 7829: }
7830: if (keys(%otherdoms)) {
7831: foreach my $domain (sort(keys(%otherdoms))) {
7832: $itemcount ++;
7833: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7834: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 7835: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 7836: '<td class="LC_left_item"><table>';
1.382 raeburn 7837: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 7838: my $showval = &mt('None');
1.382 raeburn 7839: if ($item eq 'ssl') {
7840: $showval = $lt{'ssltossl'};
7841: }
1.373 raeburn 7842: if ($values{$domain}{$item}) {
1.381 raeburn 7843: $showval = $values{$domain}{$item};
1.382 raeburn 7844: if ($item eq 'ssl') {
7845: $showval = $lt{'alltossl'};
1.383 raeburn 7846: } elsif ($item eq 'remoteip') {
7847: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 7848: }
1.373 raeburn 7849: }
7850: $datatable .= '<tr>'.
7851: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7852: }
1.381 raeburn 7853: $datatable .= '</table></td></tr>';
1.373 raeburn 7854: }
7855: }
7856: }
7857: $$rowtotal += $itemcount;
7858: return $datatable;
7859: }
7860:
7861: sub wafproxy_titles {
7862: return &Apache::lonlocal::texthash(
1.381 raeburn 7863: remoteip => "Method for determining user's IP",
7864: ipheader => 'Request header containing remote IP',
7865: trusted => 'Trusted IP range(s)',
7866: vpnaccess => 'Access from institutional VPN',
7867: vpndirect => 'via regular hostname (no WAF)',
7868: vpnaliased => 'via aliased hostname (WAF)',
7869: vpnint => 'Internal IP Range(s) for VPN sessions',
7870: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 7871: sslopt => 'Forwarding http/https',
1.381 raeburn 7872: alltossl => 'WAF forwards both http and https requests to https',
7873: ssltossl => 'WAF forwards http requests to http and https to https',
7874: );
7875: }
7876:
7877: sub remoteip_methods {
7878: return &Apache::lonlocal::texthash(
7879: m => 'Use Apache mod_remoteip',
7880: h => 'Use headers parsed by LON-CAPA',
7881: n => 'Not in use',
1.373 raeburn 7882: );
7883: }
7884:
1.137 raeburn 7885: sub print_usersessions {
7886: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 7887: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 7888: my (%by_ip,%by_location,@intdoms,@instdoms);
7889: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 7890:
7891: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7892: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7893: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7894: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7895: if ($position eq 'top') {
1.152 raeburn 7896: if (keys(%serverhomes) > 1) {
1.145 raeburn 7897: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 7898: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 7899: if (ref($settings) eq 'HASH') {
7900: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7901: $curroffloadnow = $settings->{'offloadnow'};
7902: }
1.371 raeburn 7903: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7904: $curroffloadoth = $settings->{'offloadoth'};
7905: }
1.261 raeburn 7906: }
1.371 raeburn 7907: my $other_insts = scalar(keys(%by_location));
7908: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7909: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7910: } else {
1.140 raeburn 7911: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 7912: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7913: '</td></tr>';
1.140 raeburn 7914: }
1.137 raeburn 7915: } else {
1.279 raeburn 7916: my %titles = &usersession_titles();
7917: my ($prefix,@types);
7918: if ($position eq 'bottom') {
7919: $prefix = 'remote';
7920: @types = ('version','excludedomain','includedomain');
1.145 raeburn 7921: } else {
1.279 raeburn 7922: $prefix = 'hosted';
7923: @types = ('excludedomain','includedomain');
7924: }
7925: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
7926: }
7927: $$rowtotal += $itemcount;
7928: return $datatable;
7929: }
7930:
7931: sub rules_by_location {
7932: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
7933: my ($datatable,$itemcount,$css_class);
7934: if (keys(%{$by_location}) == 0) {
7935: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7936: $datatable = '<tr'.$css_class.'><td colspan="2">'.
7937: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7938: '</td></tr>';
7939: $itemcount = 1;
7940: } else {
7941: $itemcount = 0;
7942: my $numinrow = 5;
7943: my (%current,%checkedon,%checkedoff);
7944: my @locations = sort(keys(%{$by_location}));
7945: foreach my $type (@{$types}) {
7946: $checkedon{$type} = '';
7947: $checkedoff{$type} = ' checked="checked"';
7948: }
7949: if (ref($settings) eq 'HASH') {
7950: if (ref($settings->{$prefix}) eq 'HASH') {
7951: foreach my $key (keys(%{$settings->{$prefix}})) {
7952: $current{$key} = $settings->{$prefix}{$key};
7953: if ($key eq 'version') {
7954: if ($current{$key} ne '') {
1.145 raeburn 7955: $checkedon{$key} = ' checked="checked"';
7956: $checkedoff{$key} = '';
7957: }
1.279 raeburn 7958: } elsif (ref($current{$key}) eq 'ARRAY') {
7959: $checkedon{$key} = ' checked="checked"';
7960: $checkedoff{$key} = '';
1.137 raeburn 7961: }
7962: }
7963: }
1.279 raeburn 7964: }
7965: foreach my $type (@{$types}) {
7966: next if ($type ne 'version' && !@locations);
7967: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7968: $datatable .= '<tr'.$css_class.'>
7969: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
7970: <span class="LC_nobreak">
7971: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7972: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7973: if ($type eq 'version') {
7974: my @lcversions = &Apache::lonnet::all_loncaparevs();
7975: my $selector = '<select name="'.$prefix.'_version">';
7976: foreach my $version (@lcversions) {
7977: my $selected = '';
7978: if ($current{'version'} eq $version) {
7979: $selected = ' selected="selected"';
1.145 raeburn 7980: }
1.279 raeburn 7981: $selector .= ' <option value="'.$version.'"'.
7982: $selected.'>'.$version.'</option>';
7983: }
7984: $selector .= '</select> ';
7985: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7986: } else {
7987: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7988: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7989: ' />'.(' 'x2).
7990: '<input type="button" value="'.&mt('uncheck all').'" '.
7991: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7992: "\n".
7993: '</div><div><table>';
7994: my $rem;
7995: for (my $i=0; $i<@locations; $i++) {
7996: my ($showloc,$value,$checkedtype);
7997: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
7998: my $ip = $by_location->{$locations[$i]}->[0];
7999: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8000: $value = join(':',@{$by_ip->{$ip}});
8001: $showloc = join(', ',@{$by_ip->{$ip}});
8002: if (ref($current{$type}) eq 'ARRAY') {
8003: foreach my $loc (@{$by_ip->{$ip}}) {
8004: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8005: $checkedtype = ' checked="checked"';
8006: last;
1.145 raeburn 8007: }
1.138 raeburn 8008: }
8009: }
8010: }
1.137 raeburn 8011: }
1.279 raeburn 8012: $rem = $i%($numinrow);
8013: if ($rem == 0) {
8014: if ($i > 0) {
8015: $datatable .= '</tr>';
8016: }
8017: $datatable .= '<tr>';
8018: }
8019: $datatable .= '<td class="LC_left_item">'.
8020: '<span class="LC_nobreak"><label>'.
8021: '<input type="checkbox" name="'.$prefix.'_'.$type.
8022: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8023: '</label></span></td>';
8024: }
8025: $rem = @locations%($numinrow);
8026: my $colsleft = $numinrow - $rem;
8027: if ($colsleft > 1 ) {
8028: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8029: ' </td>';
8030: } elsif ($colsleft == 1) {
8031: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8032: }
1.279 raeburn 8033: $datatable .= '</tr></table>';
1.137 raeburn 8034: }
1.279 raeburn 8035: $datatable .= '</td></tr>';
8036: $itemcount ++;
1.137 raeburn 8037: }
8038: }
1.279 raeburn 8039: return ($datatable,$itemcount);
1.137 raeburn 8040: }
8041:
1.275 raeburn 8042: sub print_ssl {
8043: my ($position,$dom,$settings,$rowtotal) = @_;
8044: my ($css_class,$datatable);
8045: my $itemcount = 1;
8046: if ($position eq 'top') {
1.281 raeburn 8047: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8048: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8049: my $same_institution;
8050: if ($intdom ne '') {
8051: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8052: if (ref($internet_names) eq 'ARRAY') {
8053: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8054: $same_institution = 1;
8055: }
8056: }
8057: }
1.275 raeburn 8058: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8059: $datatable = '<tr'.$css_class.'><td colspan="2">';
8060: if ($same_institution) {
8061: my %domservers = &Apache::lonnet::get_servers($dom);
8062: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8063: } else {
8064: $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.");
8065: }
8066: $datatable .= '</td></tr>';
1.275 raeburn 8067: $itemcount ++;
8068: } else {
8069: my %titles = &ssl_titles();
8070: my (%by_ip,%by_location,@intdoms,@instdoms);
8071: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8072: my @alldoms = &Apache::lonnet::all_domains();
8073: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8074: my @domservers = &Apache::lonnet::get_servers($dom);
8075: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8076: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8077: if (($position eq 'connto') || ($position eq 'connfrom')) {
8078: my $legacy;
8079: unless (ref($settings) eq 'HASH') {
8080: my $name;
8081: if ($position eq 'connto') {
8082: $name = 'loncAllowInsecure';
8083: } else {
8084: $name = 'londAllowInsecure';
8085: }
8086: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8087: my @ids=&Apache::lonnet::current_machine_ids();
8088: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8089: my %what = (
8090: $name => 1,
8091: );
8092: my ($result,$returnhash) =
8093: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8094: if ($result eq 'ok') {
8095: if (ref($returnhash) eq 'HASH') {
8096: $legacy = $returnhash->{$name};
8097: }
8098: }
8099: } else {
8100: $legacy = $Apache::lonnet::perlvar{$name};
8101: }
8102: }
1.275 raeburn 8103: foreach my $type ('dom','intdom','other') {
8104: my %checked;
8105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8106: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8107: '<td class="LC_right_item">';
8108: my $skip;
8109: if ($type eq 'dom') {
8110: unless (keys(%servers) > 1) {
8111: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8112: $skip = 1;
8113: }
8114: }
8115: if ($type eq 'intdom') {
8116: unless (@instdoms > 1) {
8117: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8118: $skip = 1;
8119: }
8120: } elsif ($type eq 'other') {
8121: if (keys(%by_location) == 0) {
8122: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8123: $skip = 1;
8124: }
8125: }
8126: unless ($skip) {
8127: $checked{'yes'} = ' checked="checked"';
8128: if (ref($settings) eq 'HASH') {
1.293 raeburn 8129: if (ref($settings->{$position}) eq 'HASH') {
8130: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8131: $checked{$1} = $checked{'yes'};
8132: delete($checked{'yes'});
8133: }
8134: }
1.293 raeburn 8135: } else {
8136: if ($legacy == 0) {
8137: $checked{'req'} = $checked{'yes'};
8138: delete($checked{'yes'});
8139: }
1.275 raeburn 8140: }
8141: foreach my $option ('no','yes','req') {
8142: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8143: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8144: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8145: '</label></span>'.(' 'x2);
8146: }
8147: }
8148: $datatable .= '</td></tr>';
8149: $itemcount ++;
8150: }
8151: } else {
8152: my $prefix = 'replication';
8153: my @types = ('certreq','nocertreq');
1.279 raeburn 8154: if (keys(%by_location) == 0) {
8155: $datatable .= '<tr'.$css_class.'><td>'.
8156: &mt('Nothing to set here, as there are no other institutions').
8157: '</td></tr>';
8158: $itemcount ++;
1.275 raeburn 8159: } else {
1.279 raeburn 8160: ($datatable,$itemcount) =
8161: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8162: }
8163: }
8164: }
8165: $$rowtotal += $itemcount;
8166: return $datatable;
8167: }
8168:
8169: sub ssl_titles {
8170: return &Apache::lonlocal::texthash (
8171: dom => 'LON-CAPA servers/VMs from same domain',
8172: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8173: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8174: connto => 'Connections to other servers',
8175: connfrom => 'Connections from other servers',
1.275 raeburn 8176: replication => 'Replicating content to other institutions',
8177: certreq => 'Client certificate required, but specific domains exempt',
8178: nocertreq => 'No client certificate required, except for specific domains',
8179: no => 'SSL not used',
8180: yes => 'SSL Optional (used if available)',
8181: req => 'SSL Required',
8182: );
1.279 raeburn 8183: }
8184:
8185: sub print_trust {
8186: my ($prefix,$dom,$settings,$rowtotal) = @_;
8187: my ($css_class,$datatable,%checked,%choices);
8188: my (%by_ip,%by_location,@intdoms,@instdoms);
8189: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8190: my $itemcount = 1;
8191: my %titles = &trust_titles();
8192: my @types = ('exc','inc');
8193: if ($prefix eq 'top') {
8194: $prefix = 'content';
8195: } elsif ($prefix eq 'bottom') {
8196: $prefix = 'msg';
8197: }
8198: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8199: $$rowtotal += $itemcount;
8200: return $datatable;
8201: }
8202:
8203: sub trust_titles {
8204: return &Apache::lonlocal::texthash(
8205: content => "Access to this domain's content by others",
8206: shared => "Access to other domain's content by this domain",
8207: enroll => "Enrollment in this domain's courses by others",
8208: othcoau => "Co-author roles in this domain for others",
8209: coaurem => "Co-author roles for this domain's users elsewhere",
8210: domroles => "Domain roles in this domain assignable to others",
8211: catalog => "Course Catalog for this domain displayed elsewhere",
8212: reqcrs => "Requests for creation of courses in this domain by others",
8213: msg => "Users in other domains can send messages to this domain",
8214: exc => "Allow all, but exclude specific domains",
8215: inc => "Deny all, but include specific domains",
8216: );
1.275 raeburn 8217: }
8218:
1.138 raeburn 8219: sub build_location_hashes {
1.275 raeburn 8220: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8221: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8222: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8223: my %iphost = &Apache::lonnet::get_iphost();
8224: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8225: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8226: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8227: foreach my $id (@{$iphost{$primary_ip}}) {
8228: my $intdom = &Apache::lonnet::internet_dom($id);
8229: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8230: push(@{$intdoms},$intdom);
8231: }
8232: }
8233: }
8234: foreach my $ip (keys(%iphost)) {
8235: if (ref($iphost{$ip}) eq 'ARRAY') {
8236: foreach my $id (@{$iphost{$ip}}) {
8237: my $location = &Apache::lonnet::internet_dom($id);
8238: if ($location) {
1.275 raeburn 8239: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8240: my $dom = &Apache::lonnet::host_domain($id);
8241: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8242: push(@{$instdoms},$dom);
8243: }
8244: next;
8245: }
1.138 raeburn 8246: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8247: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8248: push(@{$by_ip->{$ip}},$location);
8249: }
8250: } else {
8251: $by_ip->{$ip} = [$location];
8252: }
8253: }
8254: }
8255: }
8256: }
8257: foreach my $ip (sort(keys(%{$by_ip}))) {
8258: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8259: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8260: my $first = $by_ip->{$ip}->[0];
8261: if (ref($by_location->{$first}) eq 'ARRAY') {
8262: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8263: push(@{$by_location->{$first}},$ip);
8264: }
8265: } else {
8266: $by_location->{$first} = [$ip];
8267: }
8268: }
8269: }
8270: return;
8271: }
8272:
1.145 raeburn 8273: sub current_offloads_to {
8274: my ($dom,$settings,$servers) = @_;
8275: my (%spareid,%otherdomconfigs);
1.152 raeburn 8276: if (ref($servers) eq 'HASH') {
1.145 raeburn 8277: foreach my $lonhost (sort(keys(%{$servers}))) {
8278: my $gotspares;
1.152 raeburn 8279: if (ref($settings) eq 'HASH') {
8280: if (ref($settings->{'spares'}) eq 'HASH') {
8281: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8282: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8283: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8284: $gotspares = 1;
8285: }
1.145 raeburn 8286: }
8287: }
8288: unless ($gotspares) {
8289: my $gotspares;
8290: my $serverhomeID =
8291: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8292: my $serverhomedom =
8293: &Apache::lonnet::host_domain($serverhomeID);
8294: if ($serverhomedom ne $dom) {
8295: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8296: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8297: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8298: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8299: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8300: $gotspares = 1;
8301: }
8302: }
8303: } else {
8304: $otherdomconfigs{$serverhomedom} =
8305: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8306: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8307: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8308: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8309: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8310: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8311: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8312: $gotspares = 1;
8313: }
8314: }
8315: }
8316: }
8317: }
8318: }
8319: }
8320: unless ($gotspares) {
8321: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8322: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8323: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8324: } else {
8325: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8326: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8327: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8328: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8329: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8330: } else {
1.150 raeburn 8331: my %what = (
8332: spareid => 1,
8333: );
8334: my ($result,$returnhash) =
8335: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8336: if ($result eq 'ok') {
8337: if (ref($returnhash) eq 'HASH') {
8338: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8339: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8340: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8341: }
8342: }
1.145 raeburn 8343: }
8344: }
8345: }
8346: }
8347: }
8348: }
8349: return %spareid;
8350: }
8351:
8352: sub spares_row {
1.371 raeburn 8353: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8354: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8355: my $css_class;
8356: my $numinrow = 4;
8357: my $itemcount = 1;
8358: my $datatable;
1.152 raeburn 8359: my %typetitles = &sparestype_titles();
8360: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8361: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8362: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8363: my ($othercontrol,$serverdom);
8364: if ($serverhome ne $server) {
8365: $serverdom = &Apache::lonnet::host_domain($serverhome);
8366: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8367: } else {
8368: $serverdom = &Apache::lonnet::host_domain($server);
8369: if ($serverdom ne $dom) {
8370: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8371: }
8372: }
8373: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8374: my ($checkednow,$checkedoth);
1.261 raeburn 8375: if (ref($curroffloadnow) eq 'HASH') {
8376: if ($curroffloadnow->{$server}) {
8377: $checkednow = ' checked="checked"';
8378: }
8379: }
1.371 raeburn 8380: if (ref($curroffloadoth) eq 'HASH') {
8381: if ($curroffloadoth->{$server}) {
8382: $checkedoth = ' checked="checked"';
8383: }
8384: }
1.145 raeburn 8385: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8386: $datatable .= '<tr'.$css_class.'>
8387: <td rowspan="2">
1.183 bisitz 8388: <span class="LC_nobreak">'.
8389: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8390: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8391: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8392: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8393: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8394: "\n";
1.371 raeburn 8395: if ($other_insts) {
8396: $datatable .= '<br />'.
8397: '<span class="LC_nobreak">'."\n".
8398: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8399: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8400: "\n";
8401: }
1.145 raeburn 8402: my (%current,%canselect);
1.152 raeburn 8403: my @choices =
8404: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8405: foreach my $type ('primary','default') {
8406: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8407: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8408: my @spares = @{$spareid->{$server}{$type}};
8409: if (@spares > 0) {
1.152 raeburn 8410: if ($othercontrol) {
8411: $current{$type} = join(', ',@spares);
8412: } else {
8413: $current{$type} .= '<table>';
8414: my $numspares = scalar(@spares);
8415: for (my $i=0; $i<@spares; $i++) {
8416: my $rem = $i%($numinrow);
8417: if ($rem == 0) {
8418: if ($i > 0) {
8419: $current{$type} .= '</tr>';
8420: }
8421: $current{$type} .= '<tr>';
1.145 raeburn 8422: }
1.152 raeburn 8423: $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'".');" /> '.
8424: $spareid->{$server}{$type}[$i].
8425: '</label></td>'."\n";
8426: }
8427: my $rem = @spares%($numinrow);
8428: my $colsleft = $numinrow - $rem;
8429: if ($colsleft > 1 ) {
8430: $current{$type} .= '<td colspan="'.$colsleft.
8431: '" class="LC_left_item">'.
8432: ' </td>';
8433: } elsif ($colsleft == 1) {
8434: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8435: }
1.152 raeburn 8436: $current{$type} .= '</tr></table>';
1.150 raeburn 8437: }
1.145 raeburn 8438: }
8439: }
8440: if ($current{$type} eq '') {
8441: $current{$type} = &mt('None specified');
8442: }
1.152 raeburn 8443: if ($othercontrol) {
8444: if ($type eq 'primary') {
8445: $canselect{$type} = $othercontrol;
8446: }
8447: } else {
8448: $canselect{$type} =
8449: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8450: '<select name="newspare_'.$type.'_'.$server.'" '.
8451: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8452: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8453: if (@choices > 0) {
8454: foreach my $lonhost (@choices) {
8455: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8456: }
8457: }
8458: $canselect{$type} .= '</select>'."\n";
8459: }
8460: } else {
8461: $current{$type} = &mt('Could not be determined');
8462: if ($type eq 'primary') {
8463: $canselect{$type} = $othercontrol;
8464: }
1.145 raeburn 8465: }
1.152 raeburn 8466: if ($type eq 'default') {
8467: $datatable .= '<tr'.$css_class.'>';
8468: }
8469: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8470: '<td>'.$current{$type}.'</td>'."\n".
8471: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8472: }
8473: $itemcount ++;
8474: }
8475: }
8476: $$rowtotal += $itemcount;
8477: return $datatable;
8478: }
8479:
1.152 raeburn 8480: sub possible_newspares {
8481: my ($server,$currspares,$serverhomes,$altids) = @_;
8482: my $serverhostname = &Apache::lonnet::hostname($server);
8483: my %excluded;
8484: if ($serverhostname ne '') {
8485: %excluded = (
8486: $serverhostname => 1,
8487: );
8488: }
8489: if (ref($currspares) eq 'HASH') {
8490: foreach my $type (keys(%{$currspares})) {
8491: if (ref($currspares->{$type}) eq 'ARRAY') {
8492: if (@{$currspares->{$type}} > 0) {
8493: foreach my $curr (@{$currspares->{$type}}) {
8494: my $hostname = &Apache::lonnet::hostname($curr);
8495: $excluded{$hostname} = 1;
8496: }
8497: }
8498: }
8499: }
8500: }
8501: my @choices;
8502: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8503: if (keys(%{$serverhomes}) > 1) {
8504: foreach my $name (sort(keys(%{$serverhomes}))) {
8505: unless ($excluded{$name}) {
8506: if (exists($altids->{$serverhomes->{$name}})) {
8507: push(@choices,$altids->{$serverhomes->{$name}});
8508: } else {
8509: push(@choices,$serverhomes->{$name});
1.145 raeburn 8510: }
8511: }
8512: }
8513: }
8514: }
1.152 raeburn 8515: return sort(@choices);
1.145 raeburn 8516: }
8517:
1.150 raeburn 8518: sub print_loadbalancing {
8519: my ($dom,$settings,$rowtotal) = @_;
8520: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8521: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8522: my $numinrow = 1;
8523: my $datatable;
8524: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8525: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8526: if (ref($settings) eq 'HASH') {
8527: %existing = %{$settings};
8528: }
8529: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8530: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8531: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8532: } else {
8533: return;
8534: }
8535: my ($othertitle,$usertypes,$types) =
8536: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8537: my $rownum = 8;
1.150 raeburn 8538: if (ref($types) eq 'ARRAY') {
8539: $rownum += scalar(@{$types});
8540: }
1.171 raeburn 8541: my @css_class = ('LC_odd_row','LC_even_row');
8542: my $balnum = 0;
8543: my $islast;
8544: my (@toshow,$disabledtext);
8545: if (keys(%currbalancer) > 0) {
8546: @toshow = sort(keys(%currbalancer));
8547: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8548: push(@toshow,'');
8549: }
8550: } else {
8551: @toshow = ('');
8552: $disabledtext = &mt('No existing load balancer');
8553: }
8554: foreach my $lonhost (@toshow) {
8555: if ($balnum == scalar(@toshow)-1) {
8556: $islast = 1;
8557: } else {
8558: $islast = 0;
8559: }
8560: my $cssidx = $balnum%2;
8561: my $targets_div_style = 'display: none';
8562: my $disabled_div_style = 'display: block';
8563: my $homedom_div_style = 'display: none';
8564: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8565: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8566: '<p>';
8567: if ($lonhost eq '') {
1.210 raeburn 8568: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8569: if (keys(%currbalancer) > 0) {
8570: $datatable .= &mt('Add balancer:');
8571: } else {
8572: $datatable .= &mt('Enable balancer:');
8573: }
8574: $datatable .= ' '.
8575: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8576: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8577: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8578: '<option value="" selected="selected">'.&mt('None').
8579: '</option>'."\n";
8580: foreach my $server (sort(keys(%servers))) {
8581: next if ($currbalancer{$server});
8582: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8583: }
1.210 raeburn 8584: $datatable .=
1.171 raeburn 8585: '</select>'."\n".
8586: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8587: } else {
8588: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8589: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8590: &mt('Stop balancing').'</label>'.
8591: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8592: $targets_div_style = 'display: block';
8593: $disabled_div_style = 'display: none';
8594: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8595: $homedom_div_style = 'display: block';
8596: }
8597: }
1.306 raeburn 8598: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8599: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8600: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8601: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8602: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8603: my @sparestypes = ('primary','default');
8604: my %typetitles = &sparestype_titles();
1.284 raeburn 8605: my %hostherechecked = (
8606: no => ' checked="checked"',
8607: );
1.342 raeburn 8608: my %balcookiechecked = (
8609: no => ' checked="checked"',
8610: );
1.171 raeburn 8611: foreach my $sparetype (@sparestypes) {
8612: my $targettable;
8613: for (my $i=0; $i<$numspares; $i++) {
8614: my $checked;
8615: if (ref($currtargets{$lonhost}) eq 'HASH') {
8616: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8617: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8618: $checked = ' checked="checked"';
8619: }
8620: }
8621: }
8622: my ($chkboxval,$disabled);
8623: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8624: $chkboxval = $spares[$i];
8625: }
8626: if (exists($currbalancer{$spares[$i]})) {
8627: $disabled = ' disabled="disabled"';
8628: }
1.210 raeburn 8629: $targettable .=
1.253 raeburn 8630: '<td><span class="LC_nobreak"><label>'.
8631: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8632: $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 8633: '</span></label></span></td>';
1.171 raeburn 8634: my $rem = $i%($numinrow);
8635: if ($rem == 0) {
8636: if (($i > 0) && ($i < $numspares-1)) {
8637: $targettable .= '</tr>';
8638: }
8639: if ($i < $numspares-1) {
8640: $targettable .= '<tr>';
1.150 raeburn 8641: }
8642: }
8643: }
1.171 raeburn 8644: if ($targettable ne '') {
8645: my $rem = $numspares%($numinrow);
8646: my $colsleft = $numinrow - $rem;
8647: if ($colsleft > 1 ) {
8648: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8649: ' </td>';
8650: } elsif ($colsleft == 1) {
8651: $targettable .= '<td class="LC_left_item"> </td>';
8652: }
8653: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8654: '<table><tr>'.$targettable.'</tr></table><br />';
8655: }
1.284 raeburn 8656: $hostherechecked{$sparetype} = '';
8657: if (ref($currtargets{$lonhost}) eq 'HASH') {
8658: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8659: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8660: $hostherechecked{$sparetype} = ' checked="checked"';
8661: $hostherechecked{'no'} = '';
8662: }
8663: }
8664: }
8665: }
1.342 raeburn 8666: if ($currcookies{$lonhost}) {
8667: %balcookiechecked = (
8668: yes => ' checked="checked"',
8669: );
8670: }
1.284 raeburn 8671: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8672: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8673: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8674: foreach my $sparetype (@sparestypes) {
8675: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8676: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8677: '</i></label><br />';
1.171 raeburn 8678: }
1.342 raeburn 8679: $datatable .= &mt('Use balancer cookie').'<br />'.
8680: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8681: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8682: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8683: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8684: '</div></td></tr>'.
1.171 raeburn 8685: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8686: $othertitle,$usertypes,$types,\%servers,
8687: \%currbalancer,$lonhost,
8688: $targets_div_style,$homedom_div_style,
8689: $css_class[$cssidx],$balnum,$islast);
8690: $$rowtotal += $rownum;
8691: $balnum ++;
8692: }
8693: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8694: return $datatable;
8695: }
8696:
8697: sub get_loadbalancers_config {
1.342 raeburn 8698: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8699: return unless ((ref($servers) eq 'HASH') &&
8700: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8701: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8702: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8703: if (keys(%{$existing}) > 0) {
8704: my $oldlonhost;
8705: foreach my $key (sort(keys(%{$existing}))) {
8706: if ($key eq 'lonhost') {
8707: $oldlonhost = $existing->{'lonhost'};
8708: $currbalancer->{$oldlonhost} = 1;
8709: } elsif ($key eq 'targets') {
8710: if ($oldlonhost) {
8711: $currtargets->{$oldlonhost} = $existing->{'targets'};
8712: }
8713: } elsif ($key eq 'rules') {
8714: if ($oldlonhost) {
8715: $currrules->{$oldlonhost} = $existing->{'rules'};
8716: }
8717: } elsif (ref($existing->{$key}) eq 'HASH') {
8718: $currbalancer->{$key} = 1;
8719: $currtargets->{$key} = $existing->{$key}{'targets'};
8720: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8721: if ($existing->{$key}{'cookie'}) {
8722: $currcookies->{$key} = 1;
8723: }
1.150 raeburn 8724: }
8725: }
1.171 raeburn 8726: } else {
8727: my ($balancerref,$targetsref) =
8728: &Apache::lonnet::get_lonbalancer_config($servers);
8729: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8730: foreach my $server (sort(keys(%{$balancerref}))) {
8731: $currbalancer->{$server} = 1;
8732: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8733: }
8734: }
8735: }
1.171 raeburn 8736: return;
1.150 raeburn 8737: }
8738:
8739: sub loadbalancing_rules {
8740: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 8741: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8742: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8743: my $output;
1.171 raeburn 8744: my $num = 0;
1.210 raeburn 8745: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8746: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8747: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8748: foreach my $type (@{$alltypes}) {
1.171 raeburn 8749: $num ++;
1.150 raeburn 8750: my $current;
8751: if (ref($currrules) eq 'HASH') {
8752: $current = $currrules->{$type};
8753: }
1.253 raeburn 8754: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 8755: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8756: $current = '';
8757: }
8758: }
8759: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 8760: $servers,$currbalancer,$lonhost,$dom,
8761: $targets_div_style,$homedom_div_style,
8762: $css_class,$balnum,$num,$islast);
1.150 raeburn 8763: }
8764: }
8765: return $output;
8766: }
8767:
8768: sub loadbalancing_titles {
8769: my ($dom,$intdom,$usertypes,$types) = @_;
8770: my %othertypes = (
8771: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8772: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8773: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8774: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 8775: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8776: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8777: );
1.209 raeburn 8778: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 8779: my @available;
1.150 raeburn 8780: if (ref($types) eq 'ARRAY') {
1.302 raeburn 8781: @available = @{$types};
1.150 raeburn 8782: }
1.302 raeburn 8783: unless (grep(/^default$/,@available)) {
8784: push(@available,'default');
8785: }
8786: unshift(@alltypes,@available);
1.150 raeburn 8787: my %titles;
8788: foreach my $type (@alltypes) {
8789: if ($type =~ /^_LC_/) {
8790: $titles{$type} = $othertypes{$type};
8791: } elsif ($type eq 'default') {
8792: $titles{$type} = &mt('All users from [_1]',$dom);
8793: if (ref($types) eq 'ARRAY') {
8794: if (@{$types} > 0) {
8795: $titles{$type} = &mt('Other users from [_1]',$dom);
8796: }
8797: }
8798: } elsif (ref($usertypes) eq 'HASH') {
8799: $titles{$type} = $usertypes->{$type};
8800: }
8801: }
8802: return (\@alltypes,\%othertypes,\%titles);
8803: }
8804:
8805: sub loadbalance_rule_row {
1.171 raeburn 8806: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8807: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 8808: my @rulenames;
1.150 raeburn 8809: my %ruletitles = &offloadtype_text();
1.209 raeburn 8810: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 8811: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8812: } else {
1.209 raeburn 8813: @rulenames = ('default','homeserver');
8814: if ($type eq '_LC_external') {
8815: push(@rulenames,'externalbalancer');
8816: } else {
8817: push(@rulenames,'specific');
8818: }
8819: push(@rulenames,'none');
1.150 raeburn 8820: }
8821: my $style = $targets_div_style;
1.253 raeburn 8822: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8823: $style = $homedom_div_style;
8824: }
1.171 raeburn 8825: my $space;
8826: if ($islast && $num == 1) {
1.317 raeburn 8827: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 8828: }
1.210 raeburn 8829: my $output =
1.306 raeburn 8830: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 8831: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8832: '<td valaign="top">'.$space.
8833: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8834: for (my $i=0; $i<@rulenames; $i++) {
8835: my $rule = $rulenames[$i];
8836: my ($checked,$extra);
8837: if ($rulenames[$i] eq 'default') {
8838: $rule = '';
8839: }
8840: if ($rulenames[$i] eq 'specific') {
8841: if (ref($servers) eq 'HASH') {
8842: my $default;
8843: if (($current ne '') && (exists($servers->{$current}))) {
8844: $checked = ' checked="checked"';
8845: }
8846: unless ($checked) {
8847: $default = ' selected="selected"';
8848: }
1.210 raeburn 8849: $extra =
1.171 raeburn 8850: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8851: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8852: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8853: '<option value=""'.$default.'></option>'."\n";
8854: foreach my $server (sort(keys(%{$servers}))) {
8855: if (ref($currbalancer) eq 'HASH') {
8856: next if (exists($currbalancer->{$server}));
8857: }
1.150 raeburn 8858: my $selected;
1.171 raeburn 8859: if ($server eq $current) {
1.150 raeburn 8860: $selected = ' selected="selected"';
8861: }
1.171 raeburn 8862: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8863: }
8864: $extra .= '</select>';
8865: }
8866: } elsif ($rule eq $current) {
8867: $checked = ' checked="checked"';
8868: }
8869: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 8870: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8871: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8872: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 8873: ')"'.$checked.' /> ';
8874: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8875: $output .= $ruletitles{'particular'};
8876: } else {
8877: $output .= $ruletitles{$rulenames[$i]};
8878: }
8879: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8880: }
8881: $output .= '</div></td></tr>'."\n";
8882: return $output;
8883: }
8884:
8885: sub offloadtype_text {
8886: my %ruletitles = &Apache::lonlocal::texthash (
8887: 'default' => 'Offloads to default destinations',
8888: 'homeserver' => "Offloads to user's home server",
8889: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8890: 'specific' => 'Offloads to specific server',
1.161 raeburn 8891: 'none' => 'No offload',
1.209 raeburn 8892: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8893: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 8894: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8895: );
8896: return %ruletitles;
8897: }
8898:
8899: sub sparestype_titles {
8900: my %typestitles = &Apache::lonlocal::texthash (
8901: 'primary' => 'primary',
8902: 'default' => 'default',
8903: );
8904: return %typestitles;
8905: }
8906:
1.28 raeburn 8907: sub contact_titles {
8908: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 8909: 'supportemail' => 'Support E-mail address',
8910: 'adminemail' => 'Default Server Admin E-mail address',
8911: 'errormail' => 'Error reports to be e-mailed to',
8912: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 8913: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8914: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 8915: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8916: 'requestsmail' => 'E-mail from course requests requiring approval',
8917: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 8918: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 8919: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 8920: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8921: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 8922: 'errorweights' => 'Weights used to compute error count',
8923: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8924: );
8925: my %short_titles = &Apache::lonlocal::texthash (
8926: adminemail => 'Admin E-mail address',
8927: supportemail => 'Support E-mail',
8928: );
8929: return (\%titles,\%short_titles);
8930: }
8931:
1.286 raeburn 8932: sub helpform_fields {
8933: my %titles = &Apache::lonlocal::texthash (
8934: 'username' => 'Name',
8935: 'user' => 'Username/domain',
8936: 'phone' => 'Phone',
8937: 'cc' => 'Cc e-mail',
8938: 'course' => 'Course Details',
8939: 'section' => 'Sections',
1.289 raeburn 8940: 'screenshot' => 'File upload',
1.286 raeburn 8941: );
8942: my @fields = ('username','phone','user','course','section','cc','screenshot');
8943: my %possoptions = (
8944: username => ['yes','no','req'],
1.289 raeburn 8945: phone => ['yes','no','req'],
1.286 raeburn 8946: user => ['yes','no'],
1.289 raeburn 8947: cc => ['yes','no'],
1.286 raeburn 8948: course => ['yes','no'],
8949: section => ['yes','no'],
8950: screenshot => ['yes','no'],
8951: );
8952: my %fieldoptions = &Apache::lonlocal::texthash (
8953: 'yes' => 'Optional',
8954: 'req' => 'Required',
8955: 'no' => "Not shown",
8956: );
8957: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8958: }
8959:
1.72 raeburn 8960: sub tool_titles {
8961: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 8962: aboutme => 'Personal web page',
1.86 raeburn 8963: blog => 'Blog',
1.162 raeburn 8964: webdav => 'WebDAV',
1.86 raeburn 8965: portfolio => 'Portfolio',
1.88 bisitz 8966: official => 'Official courses (with institutional codes)',
8967: unofficial => 'Unofficial courses',
1.98 raeburn 8968: community => 'Communities',
1.216 raeburn 8969: textbook => 'Textbook courses',
1.271 raeburn 8970: placement => 'Placement tests',
1.86 raeburn 8971: );
1.72 raeburn 8972: return %titles;
8973: }
8974:
1.101 raeburn 8975: sub courserequest_titles {
8976: my %titles = &Apache::lonlocal::texthash (
8977: official => 'Official',
8978: unofficial => 'Unofficial',
8979: community => 'Communities',
1.216 raeburn 8980: textbook => 'Textbook',
1.271 raeburn 8981: placement => 'Placement tests',
1.325 raeburn 8982: lti => 'LTI Provider',
1.101 raeburn 8983: norequest => 'Not allowed',
1.325 raeburn 8984: approval => 'Approval by DC',
1.101 raeburn 8985: validate => 'With validation',
8986: autolimit => 'Numerical limit',
1.103 raeburn 8987: unlimited => '(blank for unlimited)',
1.101 raeburn 8988: );
8989: return %titles;
8990: }
8991:
1.163 raeburn 8992: sub authorrequest_titles {
8993: my %titles = &Apache::lonlocal::texthash (
8994: norequest => 'Not allowed',
8995: approval => 'Approval by Dom. Coord.',
8996: automatic => 'Automatic approval',
8997: );
8998: return %titles;
1.210 raeburn 8999: }
1.163 raeburn 9000:
1.101 raeburn 9001: sub courserequest_conditions {
9002: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9003: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9004: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9005: );
9006: return %conditions;
9007: }
9008:
9009:
1.27 raeburn 9010: sub print_usercreation {
1.30 raeburn 9011: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9012: my $numinrow = 4;
1.28 raeburn 9013: my $datatable;
9014: if ($position eq 'top') {
1.30 raeburn 9015: $$rowtotal ++;
1.34 raeburn 9016: my $rowcount = 0;
1.32 raeburn 9017: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9018: if (ref($rules) eq 'HASH') {
9019: if (keys(%{$rules}) > 0) {
1.32 raeburn 9020: $datatable .= &user_formats_row('username',$settings,$rules,
9021: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9022: $$rowtotal ++;
1.32 raeburn 9023: $rowcount ++;
9024: }
9025: }
9026: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9027: if (ref($idrules) eq 'HASH') {
9028: if (keys(%{$idrules}) > 0) {
9029: $datatable .= &user_formats_row('id',$settings,$idrules,
9030: $idruleorder,$numinrow,$rowcount);
9031: $$rowtotal ++;
9032: $rowcount ++;
1.28 raeburn 9033: }
9034: }
1.39 raeburn 9035: if ($rowcount == 0) {
9036: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9037: $$rowtotal ++;
9038: $rowcount ++;
9039: }
1.34 raeburn 9040: } elsif ($position eq 'middle') {
1.224 raeburn 9041: my @creators = ('author','course','requestcrs');
1.37 raeburn 9042: my ($rules,$ruleorder) =
9043: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9044: my %lt = &usercreation_types();
9045: my %checked;
9046: if (ref($settings) eq 'HASH') {
9047: if (ref($settings->{'cancreate'}) eq 'HASH') {
9048: foreach my $item (@creators) {
9049: $checked{$item} = $settings->{'cancreate'}{$item};
9050: }
9051: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9052: foreach my $item (@creators) {
9053: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9054: $checked{$item} = 'none';
9055: }
9056: }
9057: }
9058: }
9059: my $rownum = 0;
9060: foreach my $item (@creators) {
9061: $rownum ++;
1.224 raeburn 9062: if ($checked{$item} eq '') {
9063: $checked{$item} = 'any';
1.34 raeburn 9064: }
9065: my $css_class;
9066: if ($rownum%2) {
9067: $css_class = '';
9068: } else {
9069: $css_class = ' class="LC_odd_row" ';
9070: }
9071: $datatable .= '<tr'.$css_class.'>'.
9072: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9073: '</span></td><td style="text-align: right">';
1.224 raeburn 9074: my @options = ('any');
9075: if (ref($rules) eq 'HASH') {
9076: if (keys(%{$rules}) > 0) {
9077: push(@options,('official','unofficial'));
1.37 raeburn 9078: }
9079: }
1.224 raeburn 9080: push(@options,'none');
1.37 raeburn 9081: foreach my $option (@options) {
1.50 raeburn 9082: my $type = 'radio';
1.34 raeburn 9083: my $check = ' ';
1.224 raeburn 9084: if ($checked{$item} eq $option) {
9085: $check = ' checked="checked" ';
1.34 raeburn 9086: }
9087: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9088: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9089: $item.'" value="'.$option.'"'.$check.'/> '.
9090: $lt{$option}.'</label> </span>';
9091: }
9092: $datatable .= '</td></tr>';
9093: }
1.28 raeburn 9094: } else {
9095: my @contexts = ('author','course','domain');
1.325 raeburn 9096: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9097: my %checked;
9098: if (ref($settings) eq 'HASH') {
9099: if (ref($settings->{'authtypes'}) eq 'HASH') {
9100: foreach my $item (@contexts) {
9101: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9102: foreach my $auth (@authtypes) {
9103: if ($settings->{'authtypes'}{$item}{$auth}) {
9104: $checked{$item}{$auth} = ' checked="checked" ';
9105: }
9106: }
9107: }
9108: }
1.27 raeburn 9109: }
1.35 raeburn 9110: } else {
9111: foreach my $item (@contexts) {
1.36 raeburn 9112: foreach my $auth (@authtypes) {
1.35 raeburn 9113: $checked{$item}{$auth} = ' checked="checked" ';
9114: }
9115: }
1.27 raeburn 9116: }
1.28 raeburn 9117: my %title = &context_names();
9118: my %authname = &authtype_names();
9119: my $rownum = 0;
9120: my $css_class;
9121: foreach my $item (@contexts) {
9122: if ($rownum%2) {
9123: $css_class = '';
9124: } else {
9125: $css_class = ' class="LC_odd_row" ';
9126: }
1.30 raeburn 9127: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9128: '<td>'.$title{$item}.
9129: '</td><td class="LC_left_item">'.
9130: '<span class="LC_nobreak">';
9131: foreach my $auth (@authtypes) {
9132: $datatable .= '<label>'.
9133: '<input type="checkbox" name="'.$item.'_auth" '.
9134: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9135: $authname{$auth}.'</label> ';
9136: }
9137: $datatable .= '</span></td></tr>';
9138: $rownum ++;
1.27 raeburn 9139: }
1.30 raeburn 9140: $$rowtotal += $rownum;
1.27 raeburn 9141: }
9142: return $datatable;
9143: }
9144:
1.224 raeburn 9145: sub print_selfcreation {
9146: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9147: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9148: $emaildomain,$datatable);
1.224 raeburn 9149: if (ref($settings) eq 'HASH') {
9150: if (ref($settings->{'cancreate'}) eq 'HASH') {
9151: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9152: if (ref($createsettings) eq 'HASH') {
9153: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9154: @selfcreate = @{$createsettings->{'selfcreate'}};
9155: } elsif ($createsettings->{'selfcreate'} ne '') {
9156: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9157: @selfcreate = ('email','login','sso');
9158: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9159: @selfcreate = ($createsettings->{'selfcreate'});
9160: }
9161: }
9162: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9163: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9164: }
1.305 raeburn 9165: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9166: $emailoptions = $createsettings->{'emailoptions'};
9167: }
1.303 raeburn 9168: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9169: $emailverified = $createsettings->{'emailverified'};
9170: }
9171: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9172: $emaildomain = $createsettings->{'emaildomain'};
9173: }
1.224 raeburn 9174: }
9175: }
9176: }
9177: my %radiohash;
9178: my $numinrow = 4;
9179: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9180: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9181: if ($position eq 'top') {
9182: my %choices = &Apache::lonlocal::texthash (
9183: cancreate_login => 'Institutional Login',
9184: cancreate_sso => 'Institutional Single Sign On',
9185: );
9186: my @toggles = sort(keys(%choices));
9187: my %defaultchecked = (
9188: 'cancreate_login' => 'off',
9189: 'cancreate_sso' => 'off',
9190: );
1.228 raeburn 9191: my ($onclick,$itemcount);
1.224 raeburn 9192: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9193: \%choices,$itemcount,$onclick);
1.228 raeburn 9194: $$rowtotal += $itemcount;
9195:
1.224 raeburn 9196: if (ref($usertypes) eq 'HASH') {
9197: if (keys(%{$usertypes}) > 0) {
9198: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9199: $dom,$numinrow,$othertitle,
1.305 raeburn 9200: 'statustocreate',$rowtotal);
1.224 raeburn 9201: $$rowtotal ++;
9202: }
9203: }
1.240 raeburn 9204: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9205: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9206: $fieldtitles{'inststatus'} = &mt('Institutional status');
9207: my $rem;
9208: my $numperrow = 2;
9209: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9210: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9211: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9212: '<td class="LC_left_item">'."\n".
1.334 raeburn 9213: '<table>'."\n";
1.240 raeburn 9214: for (my $i=0; $i<@fields; $i++) {
9215: $rem = $i%($numperrow);
9216: if ($rem == 0) {
9217: if ($i > 0) {
9218: $datatable .= '</tr>';
9219: }
9220: $datatable .= '<tr>';
9221: }
9222: my $currval;
1.248 raeburn 9223: if (ref($createsettings) eq 'HASH') {
9224: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9225: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9226: }
1.240 raeburn 9227: }
9228: $datatable .= '<td class="LC_left_item">'.
9229: '<span class="LC_nobreak">'.
9230: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9231: 'value="'.$currval.'" size="10" /> '.
9232: $fieldtitles{$fields[$i]}.'</span></td>';
9233: }
9234: my $colsleft = $numperrow - $rem;
9235: if ($colsleft > 1 ) {
9236: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9237: ' </td>';
9238: } elsif ($colsleft == 1) {
9239: $datatable .= '<td class="LC_left_item"> </td>';
9240: }
9241: $datatable .= '</tr></table></td></tr>';
9242: $$rowtotal ++;
1.224 raeburn 9243: } elsif ($position eq 'middle') {
9244: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9245: my @posstypes;
1.224 raeburn 9246: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9247: @posstypes = @{$types};
9248: }
9249: unless (grep(/^default$/,@posstypes)) {
9250: push(@posstypes,'default');
9251: }
9252: my %usertypeshash;
9253: if (ref($usertypes) eq 'HASH') {
9254: %usertypeshash = %{$usertypes};
9255: }
9256: $usertypeshash{'default'} = $othertitle;
9257: foreach my $status (@posstypes) {
9258: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9259: $numinrow,$$rowtotal,\%usertypeshash);
9260: $$rowtotal ++;
1.224 raeburn 9261: }
9262: } else {
1.236 raeburn 9263: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9264: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9265: );
9266: my @toggles = sort(keys(%choices));
9267: my %defaultchecked = (
9268: 'cancreate_email' => 'off',
9269: );
1.305 raeburn 9270: my $customclass = 'LC_selfcreate_email';
9271: my $classprefix = 'LC_canmodify_emailusername_';
9272: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9273: my $display = 'none';
1.305 raeburn 9274: my $rowstyle = 'display:none';
1.236 raeburn 9275: if (grep(/^\Qemail\E$/,@selfcreate)) {
9276: $display = 'block';
1.305 raeburn 9277: $rowstyle = 'display:table-row';
1.236 raeburn 9278: }
1.305 raeburn 9279: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9280: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9281: \%choices,$$rowtotal,$onclick);
9282: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9283: $rowstyle);
9284: $$rowtotal ++;
9285: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9286: $rowstyle);
9287: $$rowtotal ++;
9288: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9289: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9290: my ($emailrules,$emailruleorder) =
9291: &Apache::lonnet::inst_userrules($dom,'email');
9292: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9293: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9294: if (ref($types) eq 'ARRAY') {
9295: @posstypes = @{$types};
9296: }
9297: if (@posstypes) {
9298: unless (grep(/^default$/,@posstypes)) {
9299: push(@posstypes,'default');
1.302 raeburn 9300: }
9301: if (ref($usertypes) eq 'HASH') {
9302: %usertypeshash = %{$usertypes};
9303: }
1.305 raeburn 9304: my $currassign;
9305: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9306: $currassign = {
9307: selfassign => $domdefaults{'inststatusguest'},
9308: };
9309: @ordered = @{$domdefaults{'inststatusguest'}};
9310: } else {
9311: $currassign = { selfassign => [] };
9312: }
9313: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9314: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9315: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9316: $numinrow,$othertitle,'selfassign',
9317: $rowtotal,$onclicktypes,$customclass,
9318: $rowstyle);
9319: $$rowtotal ++;
1.302 raeburn 9320: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9321: foreach my $status (@posstypes) {
9322: my $css_class;
9323: if ($$rowtotal%2) {
9324: $css_class = 'LC_odd_row ';
9325: }
9326: $css_class .= $customclass;
9327: my $rowid = $optionsprefix.$status;
9328: my $hidden = 1;
9329: my $currstyle = 'display:none';
9330: if (grep(/^\Q$status\E$/,@ordered)) {
9331: $currstyle = $rowstyle;
9332: $hidden = 0;
9333: }
9334: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9335: $emailrules,$emailruleorder,$settings,$status,$rowid,
9336: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9337: unless ($hidden) {
9338: $$rowtotal ++;
9339: }
1.224 raeburn 9340: }
1.302 raeburn 9341: } else {
1.305 raeburn 9342: my $css_class;
9343: if ($$rowtotal%2) {
9344: $css_class = 'LC_odd_row ';
9345: }
9346: $css_class .= $customclass;
1.302 raeburn 9347: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9348: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9349: $emailrules,$emailruleorder,$settings,'default','',
9350: $othertitle,$css_class,$rowstyle,$intdom);
9351: $$rowtotal ++;
1.224 raeburn 9352: }
9353: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9354: $numinrow = 1;
1.305 raeburn 9355: if (@posstypes) {
9356: foreach my $status (@posstypes) {
9357: my $rowid = $classprefix.$status;
9358: my $datarowstyle = 'display:none';
9359: if (grep(/^\Q$status\E$/,@ordered)) {
9360: $datarowstyle = $rowstyle;
9361: }
9362: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9363: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9364: $infotitles,$rowid,$customclass,$datarowstyle);
9365: unless ($datarowstyle eq 'display:none') {
9366: $$rowtotal ++;
9367: }
1.224 raeburn 9368: }
1.305 raeburn 9369: } else {
9370: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9371: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9372: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9373: }
9374: }
9375: return $datatable;
9376: }
9377:
1.305 raeburn 9378: sub selfcreate_javascript {
9379: return <<"ENDSCRIPT";
9380:
9381: <script type="text/javascript">
9382: // <![CDATA[
9383:
9384: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9385: var x = document.getElementsByClassName(target);
9386: var insttypes = 0;
9387: var insttypeRegExp = new RegExp(prefix);
9388: if ((x.length != undefined) && (x.length > 0)) {
9389: if (form.elements[radio].length != undefined) {
9390: for (var i=0; i<form.elements[radio].length; i++) {
9391: if (form.elements[radio][i].checked) {
9392: if (form.elements[radio][i].value == 1) {
9393: for (var j=0; j<x.length; j++) {
9394: if (x[j].id == 'undefined') {
9395: x[j].style.display = 'table-row';
9396: } else if (insttypeRegExp.test(x[j].id)) {
9397: insttypes ++;
9398: } else {
9399: x[j].style.display = 'table-row';
9400: }
9401: }
9402: } else {
9403: for (var j=0; j<x.length; j++) {
9404: x[j].style.display = 'none';
9405: }
1.236 raeburn 9406: }
1.305 raeburn 9407: break;
9408: }
9409: }
9410: if (insttypes > 0) {
9411: toggleDataRow(form,checkbox,target,altprefix);
9412: toggleDataRow(form,checkbox,target,prefix,1);
9413: }
9414: }
9415: }
9416: return;
9417: }
9418:
9419: function toggleDataRow(form,checkbox,target,prefix,docount) {
9420: if (form.elements[checkbox].length != undefined) {
9421: var count = 0;
9422: if (docount) {
9423: for (var i=0; i<form.elements[checkbox].length; i++) {
9424: if (form.elements[checkbox][i].checked) {
9425: count ++;
1.236 raeburn 9426: }
1.305 raeburn 9427: }
9428: }
9429: for (var i=0; i<form.elements[checkbox].length; i++) {
9430: var type = form.elements[checkbox][i].value;
9431: if (document.getElementById(prefix+type)) {
9432: if (form.elements[checkbox][i].checked) {
9433: document.getElementById(prefix+type).style.display = 'table-row';
9434: if (count % 2 == 1) {
9435: document.getElementById(prefix+type).className = target+' LC_odd_row';
9436: } else {
9437: document.getElementById(prefix+type).className = target;
1.236 raeburn 9438: }
1.305 raeburn 9439: count ++;
1.236 raeburn 9440: } else {
1.305 raeburn 9441: document.getElementById(prefix+type).style.display = 'none';
9442: }
9443: }
9444: }
9445: }
9446: return;
9447: }
9448:
9449: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9450: var caller = radio+'_'+status;
9451: if (form.elements[caller].length != undefined) {
9452: for (var i=0; i<form.elements[caller].length; i++) {
9453: if (form.elements[caller][i].checked) {
9454: if (document.getElementById(altprefix+'_inst_'+status)) {
9455: var curr = form.elements[caller][i].value;
9456: if (prefix) {
9457: document.getElementById(prefix+'_'+status).style.display = 'none';
9458: }
9459: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9460: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9461: if (curr == 'custom') {
9462: if (prefix) {
9463: document.getElementById(prefix+'_'+status).style.display = 'inline';
9464: }
9465: } else if (curr == 'inst') {
9466: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9467: } else if (curr == 'noninst') {
9468: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9469: }
1.305 raeburn 9470: break;
1.236 raeburn 9471: }
9472: }
9473: }
9474: }
9475: }
9476:
1.305 raeburn 9477: // ]]>
9478: </script>
9479:
9480: ENDSCRIPT
9481: }
9482:
9483: sub noninst_users {
9484: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9485: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9486: my $class = 'LC_left_item';
9487: if ($css_class) {
9488: $css_class = ' class="'.$css_class.'"';
9489: }
9490: if ($rowid) {
9491: $rowid = ' id="'.$rowid.'"';
9492: }
9493: if ($rowstyle) {
9494: $rowstyle = ' style="'.$rowstyle.'"';
9495: }
9496: my ($output,$description);
9497: if ($type eq 'default') {
9498: $description = &mt('Requests for: [_1]',$typetitle);
9499: } else {
9500: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9501: }
9502: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9503: "<td>$description</td>\n".
9504: '<td class="'.$class.'" colspan="2">'.
9505: '<table><tr>';
9506: my %headers = &Apache::lonlocal::texthash(
9507: approve => 'Processing',
9508: email => 'E-mail',
9509: username => 'Username',
9510: );
9511: foreach my $item ('approve','email','username') {
9512: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9513: }
1.305 raeburn 9514: $output .= '</tr><tr>';
9515: foreach my $item ('approve','email','username') {
1.306 raeburn 9516: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9517: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9518: if ($item eq 'approve') {
9519: %choices = &Apache::lonlocal::texthash (
9520: automatic => 'Automatically approved',
9521: approval => 'Queued for approval',
9522: );
9523: @options = ('automatic','approval');
9524: $hashref = $processing;
9525: $defoption = 'automatic';
9526: $name = 'cancreate_emailprocess_'.$type;
9527: } elsif ($item eq 'email') {
9528: %choices = &Apache::lonlocal::texthash (
9529: any => 'Any e-mail',
9530: inst => 'Institutional only',
9531: noninst => 'Non-institutional only',
9532: custom => 'Custom restrictions',
9533: );
9534: @options = ('any','inst','noninst');
9535: my $showcustom;
9536: if (ref($emailrules) eq 'HASH') {
9537: if (keys(%{$emailrules}) > 0) {
9538: push(@options,'custom');
9539: $showcustom = 'cancreate_emailrule';
9540: if (ref($settings) eq 'HASH') {
9541: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9542: foreach my $rule (@{$settings->{'email_rule'}}) {
9543: if (exists($emailrules->{$rule})) {
9544: $hascustom ++;
9545: }
9546: }
9547: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9548: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9549: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9550: if (exists($emailrules->{$rule})) {
9551: $hascustom ++;
9552: }
9553: }
9554: }
9555: }
9556: }
9557: }
9558: }
9559: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9560: "'cancreate_emaildomain','$type'".');"';
9561: $hashref = $emailoptions;
9562: $defoption = 'any';
9563: $name = 'cancreate_emailoptions_'.$type;
9564: } elsif ($item eq 'username') {
9565: %choices = &Apache::lonlocal::texthash (
9566: all => 'Same as e-mail',
9567: first => 'Omit @domain',
9568: free => 'Free to choose',
9569: );
9570: @options = ('all','first','free');
9571: $hashref = $emailverified;
9572: $defoption = 'all';
9573: $name = 'cancreate_usernameoptions_'.$type;
9574: }
9575: foreach my $option (@options) {
9576: my $checked;
9577: if (ref($hashref) eq 'HASH') {
9578: if ($type eq '') {
9579: if (!exists($hashref->{'default'})) {
9580: if ($option eq $defoption) {
9581: $checked = ' checked="checked"';
9582: }
9583: } else {
9584: if ($hashref->{'default'} eq $option) {
9585: $checked = ' checked="checked"';
9586: }
1.303 raeburn 9587: }
9588: } else {
1.305 raeburn 9589: if (!exists($hashref->{$type})) {
9590: if ($option eq $defoption) {
9591: $checked = ' checked="checked"';
9592: }
9593: } else {
9594: if ($hashref->{$type} eq $option) {
9595: $checked = ' checked="checked"';
9596: }
1.303 raeburn 9597: }
9598: }
1.305 raeburn 9599: } elsif (($item eq 'email') && ($hascustom)) {
9600: if ($option eq 'custom') {
9601: $checked = ' checked="checked"';
9602: }
9603: } elsif ($option eq $defoption) {
9604: $checked = ' checked="checked"';
9605: }
9606: $output .= '<span class="LC_nobreak"><label>'.
9607: '<input type="radio" name="'.$name.'"'.
9608: $checked.' value="'.$option.'"'.$onclick.' />'.
9609: $choices{$option}.'</label></span><br />';
9610: if ($item eq 'email') {
9611: if ($option eq 'custom') {
9612: my $id = 'cancreate_emailrule_'.$type;
9613: my $display = 'none';
9614: if ($checked) {
9615: $display = 'inline';
1.303 raeburn 9616: }
1.305 raeburn 9617: my $numinrow = 2;
9618: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9619: '<legend>'.&mt('Disallow').'</legend><table>'.
9620: &user_formats_row('email',$settings,$emailrules,
9621: $emailruleorder,$numinrow,'',$type);
9622: '</table></fieldset>';
9623: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9624: my %text = &Apache::lonlocal::texthash (
9625: inst => 'must end:',
9626: noninst => 'cannot end:',
9627: );
9628: my $value;
9629: if (ref($emaildomain) eq 'HASH') {
9630: if (ref($emaildomain->{$type}) eq 'HASH') {
9631: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9632: }
9633: }
1.305 raeburn 9634: if ($value eq '') {
9635: $value = '@'.$intdom;
9636: }
9637: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9638: my $display = 'none';
9639: if ($checked) {
9640: $display = 'inline';
9641: }
9642: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9643: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9644: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9645: '</div>';
1.303 raeburn 9646: }
9647: }
9648: }
1.305 raeburn 9649: $output .= '</td>'."\n";
1.303 raeburn 9650: }
1.305 raeburn 9651: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9652: return $output;
9653: }
9654:
1.165 raeburn 9655: sub captcha_choice {
1.305 raeburn 9656: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9657: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9658: $vertext,$currver);
1.165 raeburn 9659: my %lt = &captcha_phrases();
9660: $keyentry = 'hidden';
1.354 raeburn 9661: my $colspan=2;
1.165 raeburn 9662: if ($context eq 'cancreate') {
1.224 raeburn 9663: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9664: } elsif ($context eq 'login') {
9665: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9666: } elsif ($context eq 'passwords') {
9667: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9668: $colspan=1;
1.165 raeburn 9669: }
9670: if (ref($settings) eq 'HASH') {
9671: if ($settings->{'captcha'}) {
9672: $checked{$settings->{'captcha'}} = ' checked="checked"';
9673: } else {
9674: $checked{'original'} = ' checked="checked"';
9675: }
9676: if ($settings->{'captcha'} eq 'recaptcha') {
9677: $pubtext = $lt{'pub'};
9678: $privtext = $lt{'priv'};
9679: $keyentry = 'text';
1.269 raeburn 9680: $vertext = $lt{'ver'};
9681: $currver = $settings->{'recaptchaversion'};
9682: if ($currver ne '2') {
9683: $currver = 1;
9684: }
1.165 raeburn 9685: }
9686: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9687: $currpub = $settings->{'recaptchakeys'}{'public'};
9688: $currpriv = $settings->{'recaptchakeys'}{'private'};
9689: }
9690: } else {
9691: $checked{'original'} = ' checked="checked"';
9692: }
1.305 raeburn 9693: my $css_class;
9694: if ($itemcount%2) {
9695: $css_class = 'LC_odd_row';
9696: }
9697: if ($customcss) {
9698: $css_class .= " $customcss";
9699: }
9700: $css_class =~ s/^\s+//;
9701: if ($css_class) {
9702: $css_class = ' class="'.$css_class.'"';
9703: }
9704: if ($rowstyle) {
9705: $css_class .= ' style="'.$rowstyle.'"';
9706: }
1.169 raeburn 9707: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9708: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9709: '<table><tr><td>'."\n";
9710: foreach my $option ('original','recaptcha','notused') {
9711: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9712: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9713: $lt{$option}.'</label></span>';
9714: unless ($option eq 'notused') {
9715: $output .= (' 'x2)."\n";
9716: }
9717: }
9718: #
9719: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9720: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9721: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9722: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9723: #
1.165 raeburn 9724: $output .= '</td></tr>'."\n".
1.305 raeburn 9725: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 9726: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9727: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9728: $currpub.'" size="40" /></span><br />'."\n".
9729: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9730: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 9731: $currpriv.'" size="40" /></span><br />'.
9732: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9733: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9734: $currver.'" size="3" /></span><br />'.
9735: '</td></tr></table>'."\n".
1.165 raeburn 9736: '</td></tr>';
9737: return $output;
9738: }
9739:
1.32 raeburn 9740: sub user_formats_row {
1.305 raeburn 9741: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9742: my $output;
9743: my %text = (
9744: 'username' => 'new usernames',
9745: 'id' => 'IDs',
9746: );
1.305 raeburn 9747: unless ($type eq 'email') {
9748: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9749: $output = '<tr '.$css_class.'>'.
9750: '<td><span class="LC_nobreak">'.
9751: &mt("Format rules to check for $text{$type}: ").
9752: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9753: }
1.27 raeburn 9754: my $rem;
9755: if (ref($ruleorder) eq 'ARRAY') {
9756: for (my $i=0; $i<@{$ruleorder}; $i++) {
9757: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9758: my $rem = $i%($numinrow);
9759: if ($rem == 0) {
9760: if ($i > 0) {
9761: $output .= '</tr>';
9762: }
9763: $output .= '<tr>';
9764: }
9765: my $check = ' ';
1.39 raeburn 9766: if (ref($settings) eq 'HASH') {
9767: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9768: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9769: $check = ' checked="checked" ';
9770: }
1.305 raeburn 9771: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9772: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9773: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9774: $check = ' checked="checked" ';
9775: }
9776: }
1.27 raeburn 9777: }
9778: }
1.305 raeburn 9779: my $name = $type.'_rule';
9780: if ($type eq 'email') {
9781: $name .= '_'.$status;
9782: }
1.27 raeburn 9783: $output .= '<td class="LC_left_item">'.
9784: '<span class="LC_nobreak"><label>'.
1.311 raeburn 9785: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9786: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9787: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9788: }
9789: }
9790: $rem = @{$ruleorder}%($numinrow);
9791: }
1.305 raeburn 9792: my $colsleft;
9793: if ($rem) {
9794: $colsleft = $numinrow - $rem;
9795: }
1.27 raeburn 9796: if ($colsleft > 1 ) {
9797: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9798: ' </td>';
9799: } elsif ($colsleft == 1) {
9800: $output .= '<td class="LC_left_item"> </td>';
9801: }
1.305 raeburn 9802: $output .= '</tr></table>';
9803: unless ($type eq 'email') {
9804: $output .= '</td></tr>';
9805: }
1.27 raeburn 9806: return $output;
9807: }
9808:
1.34 raeburn 9809: sub usercreation_types {
9810: my %lt = &Apache::lonlocal::texthash (
9811: author => 'When adding a co-author',
9812: course => 'When adding a user to a course',
1.100 raeburn 9813: requestcrs => 'When requesting a course',
1.34 raeburn 9814: any => 'Any',
9815: official => 'Institutional only ',
9816: unofficial => 'Non-institutional only',
9817: none => 'None',
9818: );
9819: return %lt;
1.48 raeburn 9820: }
1.34 raeburn 9821:
1.224 raeburn 9822: sub selfcreation_types {
9823: my %lt = &Apache::lonlocal::texthash (
9824: selfcreate => 'User creates own account',
9825: any => 'Any',
9826: official => 'Institutional only ',
9827: unofficial => 'Non-institutional only',
9828: email => 'E-mail address',
9829: login => 'Institutional Login',
9830: sso => 'SSO',
9831: );
9832: }
9833:
1.28 raeburn 9834: sub authtype_names {
9835: my %lt = &Apache::lonlocal::texthash(
9836: int => 'Internal',
9837: krb4 => 'Kerberos 4',
9838: krb5 => 'Kerberos 5',
9839: loc => 'Local',
1.325 raeburn 9840: lti => 'LTI',
1.28 raeburn 9841: );
9842: return %lt;
9843: }
9844:
9845: sub context_names {
9846: my %context_title = &Apache::lonlocal::texthash(
9847: author => 'Creating users when an Author',
9848: course => 'Creating users when in a course',
9849: domain => 'Creating users when a Domain Coordinator',
9850: );
9851: return %context_title;
9852: }
9853:
1.33 raeburn 9854: sub print_usermodification {
9855: my ($position,$dom,$settings,$rowtotal) = @_;
9856: my $numinrow = 4;
9857: my ($context,$datatable,$rowcount);
9858: if ($position eq 'top') {
9859: $rowcount = 0;
9860: $context = 'author';
9861: foreach my $role ('ca','aa') {
9862: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9863: $numinrow,$rowcount);
9864: $$rowtotal ++;
9865: $rowcount ++;
9866: }
1.230 raeburn 9867: } elsif ($position eq 'bottom') {
1.33 raeburn 9868: $context = 'course';
9869: $rowcount = 0;
9870: foreach my $role ('st','ep','ta','in','cr') {
9871: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9872: $numinrow,$rowcount);
9873: $$rowtotal ++;
9874: $rowcount ++;
9875: }
9876: }
9877: return $datatable;
9878: }
9879:
1.43 raeburn 9880: sub print_defaults {
1.236 raeburn 9881: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9882: my $rownum = 0;
1.294 raeburn 9883: my ($datatable,$css_class,$titles);
9884: unless ($position eq 'bottom') {
9885: $titles = &defaults_titles($dom);
9886: }
1.236 raeburn 9887: if ($position eq 'top') {
9888: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9889: 'datelocale_def','portal_def');
9890: my %defaults;
9891: if (ref($settings) eq 'HASH') {
9892: %defaults = %{$settings};
1.43 raeburn 9893: } else {
1.236 raeburn 9894: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9895: foreach my $item (@items) {
9896: $defaults{$item} = $domdefaults{$item};
9897: }
1.43 raeburn 9898: }
1.236 raeburn 9899: foreach my $item (@items) {
9900: if ($rownum%2) {
9901: $css_class = '';
9902: } else {
9903: $css_class = ' class="LC_odd_row" ';
9904: }
9905: $datatable .= '<tr'.$css_class.'>'.
9906: '<td><span class="LC_nobreak">'.$titles->{$item}.
9907: '</span></td><td class="LC_right_item" colspan="3">';
9908: if ($item eq 'auth_def') {
1.325 raeburn 9909: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 9910: my %shortauth = (
9911: internal => 'int',
9912: krb4 => 'krb4',
9913: krb5 => 'krb5',
1.325 raeburn 9914: localauth => 'loc',
9915: lti => 'lti',
1.236 raeburn 9916: );
9917: my %authnames = &authtype_names();
9918: foreach my $auth (@authtypes) {
9919: my $checked = ' ';
9920: if ($defaults{$item} eq $auth) {
9921: $checked = ' checked="checked" ';
9922: }
9923: $datatable .= '<label><input type="radio" name="'.$item.
9924: '" value="'.$auth.'"'.$checked.'/>'.
9925: $authnames{$shortauth{$auth}}.'</label> ';
9926: }
9927: } elsif ($item eq 'timezone_def') {
9928: my $includeempty = 1;
9929: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9930: } elsif ($item eq 'datelocale_def') {
9931: my $includeempty = 1;
9932: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9933: } elsif ($item eq 'lang_def') {
1.263 raeburn 9934: my $includeempty = 1;
9935: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 9936: } else {
9937: my $size;
9938: if ($item eq 'portal_def') {
9939: $size = ' size="25"';
9940: }
9941: $datatable .= '<input type="text" name="'.$item.'" value="'.
9942: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 9943: }
1.236 raeburn 9944: $datatable .= '</td></tr>';
9945: $rownum ++;
9946: }
1.354 raeburn 9947: } else {
1.294 raeburn 9948: my %defaults;
9949: if (ref($settings) eq 'HASH') {
1.354 raeburn 9950: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9951: my $maxnum = @{$settings->{'inststatusorder'}};
9952: for (my $i=0; $i<$maxnum; $i++) {
9953: $css_class = $rownum%2?' class="LC_odd_row"':'';
9954: my $item = $settings->{'inststatusorder'}->[$i];
9955: my $title = $settings->{'inststatustypes'}->{$item};
9956: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9957: $datatable .= '<tr'.$css_class.'>'.
9958: '<td><span class="LC_nobreak">'.
9959: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9960: for (my $k=0; $k<=$maxnum; $k++) {
9961: my $vpos = $k+1;
9962: my $selstr;
9963: if ($k == $i) {
9964: $selstr = ' selected="selected" ';
9965: }
9966: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9967: }
9968: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9969: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9970: &mt('delete').'</span></td>'.
1.380 raeburn 9971: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 9972: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9973: '</span></td></tr>';
9974: }
9975: $css_class = $rownum%2?' class="LC_odd_row"':'';
9976: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9977: $datatable .= '<tr '.$css_class.'>'.
9978: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9979: for (my $k=0; $k<=$maxnum; $k++) {
9980: my $vpos = $k+1;
9981: my $selstr;
9982: if ($k == $maxnum) {
9983: $selstr = ' selected="selected" ';
9984: }
9985: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9986: }
9987: $datatable .= '</select> '.&mt('Internal ID:').
9988: '<input type="text" size="10" name="addinststatus" value="" />'.
9989: ' '.&mt('(new)').
9990: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 9991: &mt('Name displayed').':'.
1.354 raeburn 9992: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9993: '</tr>'."\n";
9994: $rownum ++;
1.294 raeburn 9995: }
1.354 raeburn 9996: }
9997: }
9998: $$rowtotal += $rownum;
1.43 raeburn 9999: return $datatable;
10000: }
10001:
1.168 raeburn 10002: sub get_languages_hash {
10003: my %langchoices;
10004: foreach my $id (&Apache::loncommon::languageids()) {
10005: my $code = &Apache::loncommon::supportedlanguagecode($id);
10006: if ($code ne '') {
10007: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10008: }
10009: }
10010: return %langchoices;
10011: }
10012:
1.43 raeburn 10013: sub defaults_titles {
1.141 raeburn 10014: my ($dom) = @_;
1.43 raeburn 10015: my %titles = &Apache::lonlocal::texthash (
10016: 'auth_def' => 'Default authentication type',
10017: 'auth_arg_def' => 'Default authentication argument',
10018: 'lang_def' => 'Default language',
1.54 raeburn 10019: 'timezone_def' => 'Default timezone',
1.68 raeburn 10020: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10021: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 10022: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10023: 'intauth_check' => 'Check bcrypt cost if authenticated',
10024: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10025: );
1.141 raeburn 10026: if ($dom) {
10027: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10028: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10029: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10030: $protocol = 'http' if ($protocol ne 'https');
10031: if ($uint_dom) {
10032: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10033: $uint_dom);
10034: }
10035: }
1.43 raeburn 10036: return (\%titles);
10037: }
10038:
1.346 raeburn 10039: sub print_scantron {
10040: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10041: if ($position eq 'top') {
10042: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10043: } else {
10044: return &print_scantronconfig($dom,$settings,\$rowtotal);
10045: }
10046: }
10047:
10048: sub scantron_javascript {
10049: return <<"ENDSCRIPT";
10050:
10051: <script type="text/javascript">
10052: // <![CDATA[
10053:
10054: function toggleScantron(form) {
1.347 raeburn 10055: var csvfieldset = new Array();
1.346 raeburn 10056: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10057: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10058: }
10059: if (document.getElementById('scantroncsv_options')) {
10060: csvfieldset.push(document.getElementById('scantroncsv_options'));
10061: }
10062: if (csvfieldset.length) {
1.346 raeburn 10063: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10064: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10065: if (scantroncsv.checked) {
1.347 raeburn 10066: for (var i=0; i<csvfieldset.length; i++) {
10067: csvfieldset[i].style.display = 'block';
10068: }
1.346 raeburn 10069: } else {
1.347 raeburn 10070: for (var i=0; i<csvfieldset.length; i++) {
10071: csvfieldset[i].style.display = 'none';
10072: }
1.346 raeburn 10073: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10074: if (csvselects.length) {
10075: for (var j=0; j<csvselects.length; j++) {
10076: csvselects[j].selectedIndex = 0;
10077: }
10078: }
10079: }
10080: }
10081: }
10082: return;
10083: }
10084: // ]]>
10085: </script>
10086:
10087: ENDSCRIPT
10088:
10089: }
10090:
1.46 raeburn 10091: sub print_scantronformat {
10092: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10093: my $itemcount = 1;
1.60 raeburn 10094: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10095: %confhash);
1.46 raeburn 10096: my $switchserver = &check_switchserver($dom,$confname);
10097: my %lt = &Apache::lonlocal::texthash (
1.95 www 10098: default => 'Default bubblesheet format file error',
10099: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10100: );
10101: my %scantronfiles = (
10102: default => 'default.tab',
10103: custom => 'custom.tab',
10104: );
10105: foreach my $key (keys(%scantronfiles)) {
10106: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10107: .$scantronfiles{$key};
10108: }
10109: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10110: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10111: if (!$switchserver) {
10112: my $servadm = $r->dir_config('lonAdmEMail');
10113: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10114: if ($configuserok eq 'ok') {
10115: if ($author_ok eq 'ok') {
10116: my %legacyfile = (
1.346 raeburn 10117: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10118: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10119: );
10120: my %md5chk;
10121: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10122: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10123: chomp($md5chk{$type});
1.46 raeburn 10124: }
10125: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10126: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10127: ($scantronurls{$type},my $error) =
1.46 raeburn 10128: &legacy_scantronformat($r,$dom,$confname,
10129: $type,$legacyfile{$type},
10130: $scantronurls{$type},
10131: $scantronfiles{$type});
1.60 raeburn 10132: if ($error ne '') {
10133: $error{$type} = $error;
10134: }
10135: }
10136: if (keys(%error) == 0) {
10137: $is_custom = 1;
1.346 raeburn 10138: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10139: $scantronurls{'custom'};
1.346 raeburn 10140: my $putresult =
1.60 raeburn 10141: &Apache::lonnet::put_dom('configuration',
10142: \%confhash,$dom);
10143: if ($putresult ne 'ok') {
1.346 raeburn 10144: $error{'custom'} =
1.60 raeburn 10145: '<span class="LC_error">'.
10146: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10147: }
1.46 raeburn 10148: }
10149: } else {
1.60 raeburn 10150: ($scantronurls{'default'},my $error) =
1.46 raeburn 10151: &legacy_scantronformat($r,$dom,$confname,
10152: 'default',$legacyfile{'default'},
10153: $scantronurls{'default'},
10154: $scantronfiles{'default'});
1.60 raeburn 10155: if ($error eq '') {
10156: $confhash{'scantron'}{'scantronformat'} = '';
10157: my $putresult =
10158: &Apache::lonnet::put_dom('configuration',
10159: \%confhash,$dom);
10160: if ($putresult ne 'ok') {
10161: $error{'default'} =
10162: '<span class="LC_error">'.
10163: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10164: }
10165: } else {
10166: $error{'default'} = $error;
10167: }
1.46 raeburn 10168: }
10169: }
10170: }
10171: } else {
1.95 www 10172: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10173: }
10174: }
10175: if (ref($settings) eq 'HASH') {
10176: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10177: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10178: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10179: $scantronurl = '';
10180: } else {
10181: $scantronurl = $settings->{'scantronformat'};
10182: }
10183: $is_custom = 1;
10184: } else {
10185: $scantronurl = $scantronurls{'default'};
10186: }
10187: } else {
1.60 raeburn 10188: if ($is_custom) {
10189: $scantronurl = $scantronurls{'custom'};
10190: } else {
10191: $scantronurl = $scantronurls{'default'};
10192: }
1.46 raeburn 10193: }
10194: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10195: $datatable .= '<tr'.$css_class.'>';
10196: if (!$is_custom) {
1.65 raeburn 10197: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10198: '<span class="LC_nobreak">';
1.46 raeburn 10199: if ($scantronurl) {
1.199 raeburn 10200: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10201: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10202: } else {
10203: $datatable = &mt('File unavailable for display');
10204: }
1.65 raeburn 10205: $datatable .= '</span></td>';
1.60 raeburn 10206: if (keys(%error) == 0) {
1.306 raeburn 10207: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10208: if (!$switchserver) {
10209: $datatable .= &mt('Upload:').'<br />';
10210: }
10211: } else {
10212: my $errorstr;
10213: foreach my $key (sort(keys(%error))) {
10214: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10215: }
10216: $datatable .= '<td>'.$errorstr;
10217: }
1.46 raeburn 10218: } else {
10219: if (keys(%error) > 0) {
10220: my $errorstr;
10221: foreach my $key (sort(keys(%error))) {
10222: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10223: }
1.60 raeburn 10224: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10225: } elsif ($scantronurl) {
1.199 raeburn 10226: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10227: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10228: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10229: $link.
10230: '<label><input type="checkbox" name="scantronformat_del"'.
10231: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10232: '<td><span class="LC_nobreak"> '.
10233: &mt('Replace:').'</span><br />';
1.46 raeburn 10234: }
10235: }
10236: if (keys(%error) == 0) {
10237: if ($switchserver) {
10238: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10239: } else {
1.65 raeburn 10240: $datatable .='<span class="LC_nobreak"> '.
10241: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10242: }
10243: }
10244: $datatable .= '</td></tr>';
10245: $$rowtotal ++;
10246: return $datatable;
10247: }
10248:
10249: sub legacy_scantronformat {
10250: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10251: my ($url,$error);
10252: my @statinfo = &Apache::lonnet::stat_file($newurl);
10253: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
10254: (my $result,$url) =
10255: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
10256: '','',$newfile);
10257: if ($result ne 'ok') {
1.130 raeburn 10258: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10259: }
10260: }
10261: return ($url,$error);
10262: }
1.43 raeburn 10263:
1.346 raeburn 10264: sub print_scantronconfig {
10265: my ($dom,$settings,$rowtotal) = @_;
10266: my $itemcount = 2;
10267: my $is_checked = ' checked="checked"';
1.347 raeburn 10268: my %optionson = (
10269: hdr => ' checked="checked"',
10270: pad => ' checked="checked"',
10271: rem => ' checked="checked"',
10272: );
10273: my %optionsoff = (
10274: hdr => '',
10275: pad => '',
10276: rem => '',
10277: );
1.346 raeburn 10278: my $currcsvsty = 'none';
1.347 raeburn 10279: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10280: my @fields = &scantroncsv_fields();
10281: my %titles = &scantronconfig_titles();
10282: if (ref($settings) eq 'HASH') {
10283: if (ref($settings->{config}) eq 'HASH') {
10284: if ($settings->{config}->{dat}) {
10285: $checked{'dat'} = $is_checked;
10286: }
10287: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10288: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10289: %csvfields = %{$settings->{config}->{csv}->{fields}};
10290: if (keys(%csvfields) > 0) {
10291: $checked{'csv'} = $is_checked;
10292: $currcsvsty = 'block';
10293: }
10294: }
10295: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10296: %csvoptions = %{$settings->{config}->{csv}->{options}};
10297: foreach my $option (keys(%optionson)) {
10298: unless ($csvoptions{$option}) {
10299: $optionsoff{$option} = $optionson{$option};
10300: $optionson{$option} = '';
10301: }
10302: }
1.346 raeburn 10303: }
10304: }
10305: } else {
10306: $checked{'dat'} = $is_checked;
10307: }
10308: } else {
10309: $checked{'dat'} = $is_checked;
10310: }
10311: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10312: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10313: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10314: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10315: foreach my $item ('dat','csv') {
10316: my $id;
10317: if ($item eq 'csv') {
10318: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10319: }
1.346 raeburn 10320: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10321: $titles{$item}.'</label>'.(' 'x3);
10322: if ($item eq 'csv') {
10323: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10324: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10325: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10326: foreach my $col (@fields) {
10327: my $selnone;
10328: if ($csvfields{$col} eq '') {
10329: $selnone = ' selected="selected"';
10330: }
10331: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10332: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10333: '<option value=""'.$selnone.'></option>';
10334: for (my $i=0; $i<20; $i++) {
10335: my $shown = $i+1;
10336: my $sel;
10337: unless ($selnone) {
10338: if (exists($csvfields{$col})) {
10339: if ($csvfields{$col} == $i) {
10340: $sel = ' selected="selected"';
10341: }
10342: }
10343: }
10344: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10345: }
10346: $datatable .= '</select></td></tr>';
10347: }
1.347 raeburn 10348: $datatable .= '</table></fieldset>'.
10349: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10350: '<legend>'.&mt('CSV Options').'</legend>';
10351: foreach my $option ('hdr','pad','rem') {
10352: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10353: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10354: &mt('Yes').'</label>'.(' 'x2)."\n".
10355: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10356: }
10357: $datatable .= '</fieldset>';
1.346 raeburn 10358: $itemcount ++;
10359: }
10360: }
10361: $datatable .= '</td></tr>';
10362: $$rowtotal ++;
10363: return $datatable;
10364: }
10365:
10366: sub scantronconfig_titles {
10367: return &Apache::lonlocal::texthash(
10368: dat => 'Standard format (.dat)',
10369: csv => 'Comma separated values (.csv)',
1.347 raeburn 10370: hdr => 'Remove first line in file (contains column titles)',
10371: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10372: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10373: CODE => 'CODE',
10374: ID => 'Student ID',
10375: PaperID => 'Paper ID',
10376: FirstName => 'First Name',
10377: LastName => 'Last Name',
10378: FirstQuestion => 'First Question Response',
10379: Section => 'Section',
10380: );
10381: }
10382:
10383: sub scantroncsv_fields {
10384: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10385: }
10386:
1.49 raeburn 10387: sub print_coursecategories {
1.57 raeburn 10388: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10389: my $datatable;
10390: if ($position eq 'top') {
1.238 raeburn 10391: my (%checked);
10392: my @catitems = ('unauth','auth');
10393: my @cattypes = ('std','domonly','codesrch','none');
10394: $checked{'unauth'} = 'std';
10395: $checked{'auth'} = 'std';
10396: if (ref($settings) eq 'HASH') {
10397: foreach my $type (@cattypes) {
10398: if ($type eq $settings->{'unauth'}) {
10399: $checked{'unauth'} = $type;
10400: }
10401: if ($type eq $settings->{'auth'}) {
10402: $checked{'auth'} = $type;
10403: }
10404: }
10405: }
10406: my %lt = &Apache::lonlocal::texthash (
10407: unauth => 'Catalog type for unauthenticated users',
10408: auth => 'Catalog type for authenticated users',
10409: none => 'No catalog',
10410: std => 'Standard catalog',
10411: domonly => 'Domain-only catalog',
10412: codesrch => "Code search form",
10413: );
10414: my $itemcount = 0;
10415: foreach my $item (@catitems) {
10416: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10417: $datatable .= '<tr '.$css_class.'>'.
10418: '<td>'.$lt{$item}.'</td>'.
10419: '<td class="LC_right_item"><span class="LC_nobreak">';
10420: foreach my $type (@cattypes) {
10421: my $ischecked;
10422: if ($checked{$item} eq $type) {
10423: $ischecked=' checked="checked"';
10424: }
10425: $datatable .= '<label>'.
10426: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10427: ' />'.$lt{$type}.'</label> ';
10428: }
1.327 raeburn 10429: $datatable .= '</span></td></tr>';
1.238 raeburn 10430: $itemcount ++;
10431: }
10432: $$rowtotal += $itemcount;
10433: } elsif ($position eq 'middle') {
1.57 raeburn 10434: my $toggle_cats_crs = ' ';
10435: my $toggle_cats_dom = ' checked="checked" ';
10436: my $can_cat_crs = ' ';
10437: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10438: my $toggle_catscomm_comm = ' ';
10439: my $toggle_catscomm_dom = ' checked="checked" ';
10440: my $can_catcomm_comm = ' ';
10441: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10442: my $toggle_catsplace_place = ' ';
10443: my $toggle_catsplace_dom = ' checked="checked" ';
10444: my $can_catplace_place = ' ';
10445: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10446:
1.57 raeburn 10447: if (ref($settings) eq 'HASH') {
10448: if ($settings->{'togglecats'} eq 'crs') {
10449: $toggle_cats_crs = $toggle_cats_dom;
10450: $toggle_cats_dom = ' ';
10451: }
10452: if ($settings->{'categorize'} eq 'crs') {
10453: $can_cat_crs = $can_cat_dom;
10454: $can_cat_dom = ' ';
10455: }
1.120 raeburn 10456: if ($settings->{'togglecatscomm'} eq 'comm') {
10457: $toggle_catscomm_comm = $toggle_catscomm_dom;
10458: $toggle_catscomm_dom = ' ';
10459: }
10460: if ($settings->{'categorizecomm'} eq 'comm') {
10461: $can_catcomm_comm = $can_catcomm_dom;
10462: $can_catcomm_dom = ' ';
10463: }
1.272 raeburn 10464: if ($settings->{'togglecatsplace'} eq 'place') {
10465: $toggle_catsplace_place = $toggle_catsplace_dom;
10466: $toggle_catsplace_dom = ' ';
10467: }
10468: if ($settings->{'categorizeplace'} eq 'place') {
10469: $can_catplace_place = $can_catplace_dom;
10470: $can_catplace_dom = ' ';
10471: }
1.57 raeburn 10472: }
10473: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10474: togglecats => 'Show/Hide a course in catalog',
10475: togglecatscomm => 'Show/Hide a community in catalog',
10476: togglecatsplace => 'Show/Hide a placement test in catalog',
10477: categorize => 'Assign a category to a course',
10478: categorizecomm => 'Assign a category to a community',
10479: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10480: );
10481: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10482: dom => 'Set in Domain',
10483: crs => 'Set in Course',
10484: comm => 'Set in Community',
10485: place => 'Set in Placement Test',
1.57 raeburn 10486: );
10487: $datatable = '<tr class="LC_odd_row">'.
10488: '<td>'.$title{'togglecats'}.'</td>'.
10489: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10490: '<input type="radio" name="togglecats"'.
10491: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10492: '<label><input type="radio" name="togglecats"'.
10493: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10494: '</tr><tr>'.
10495: '<td>'.$title{'categorize'}.'</td>'.
10496: '<td class="LC_right_item"><span class="LC_nobreak">'.
10497: '<label><input type="radio" name="categorize"'.
10498: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10499: '<label><input type="radio" name="categorize"'.
10500: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10501: '</tr><tr class="LC_odd_row">'.
10502: '<td>'.$title{'togglecatscomm'}.'</td>'.
10503: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10504: '<input type="radio" name="togglecatscomm"'.
10505: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10506: '<label><input type="radio" name="togglecatscomm"'.
10507: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10508: '</tr><tr>'.
10509: '<td>'.$title{'categorizecomm'}.'</td>'.
10510: '<td class="LC_right_item"><span class="LC_nobreak">'.
10511: '<label><input type="radio" name="categorizecomm"'.
10512: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10513: '<label><input type="radio" name="categorizecomm"'.
10514: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10515: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10516: '<td>'.$title{'togglecatsplace'}.'</td>'.
10517: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10518: '<input type="radio" name="togglecatsplace"'.
10519: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10520: '<label><input type="radio" name="togglecatscomm"'.
10521: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10522: '</tr><tr>'.
10523: '<td>'.$title{'categorizeplace'}.'</td>'.
10524: '<td class="LC_right_item"><span class="LC_nobreak">'.
10525: '<label><input type="radio" name="categorizeplace"'.
10526: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10527: '<label><input type="radio" name="categorizeplace"'.
10528: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10529: '</tr>';
1.272 raeburn 10530: $$rowtotal += 6;
1.57 raeburn 10531: } else {
10532: my $css_class;
10533: my $itemcount = 1;
10534: my $cathash;
10535: if (ref($settings) eq 'HASH') {
10536: $cathash = $settings->{'cats'};
10537: }
10538: if (ref($cathash) eq 'HASH') {
10539: my (@cats,@trails,%allitems,%idx,@jsarray);
10540: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10541: \%allitems,\%idx,\@jsarray);
10542: my $maxdepth = scalar(@cats);
10543: my $colattrib = '';
10544: if ($maxdepth > 2) {
10545: $colattrib = ' colspan="2" ';
10546: }
10547: my @path;
10548: if (@cats > 0) {
10549: if (ref($cats[0]) eq 'ARRAY') {
10550: my $numtop = @{$cats[0]};
10551: my $maxnum = $numtop;
1.120 raeburn 10552: my %default_names = (
10553: instcode => &mt('Official courses'),
10554: communities => &mt('Communities'),
1.272 raeburn 10555: placement => &mt('Placement Tests'),
1.120 raeburn 10556: );
10557:
10558: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10559: ($cathash->{'instcode::0'} eq '') ||
10560: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10561: ($cathash->{'communities::0'} eq '') ||
10562: (!grep(/^placement$/,@{$cats[0]})) ||
10563: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10564: $maxnum ++;
10565: }
10566: my $lastidx;
10567: for (my $i=0; $i<$numtop; $i++) {
10568: my $parent = $cats[0][$i];
10569: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10570: my $item = &escape($parent).'::0';
10571: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10572: $lastidx = $idx{$item};
10573: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10574: .'<select name="'.$item.'"'.$chgstr.'>';
10575: for (my $k=0; $k<=$maxnum; $k++) {
10576: my $vpos = $k+1;
10577: my $selstr;
10578: if ($k == $i) {
10579: $selstr = ' selected="selected" ';
10580: }
10581: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10582: }
1.214 raeburn 10583: $datatable .= '</select></span></td><td>';
1.272 raeburn 10584: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10585: $datatable .= '<span class="LC_nobreak">'
10586: .$default_names{$parent}.'</span>';
10587: if ($parent eq 'instcode') {
10588: $datatable .= '<br /><span class="LC_nobreak">('
10589: .&mt('with institutional codes')
10590: .')</span></td><td'.$colattrib.'>';
10591: } else {
10592: $datatable .= '<table><tr><td>';
10593: }
10594: $datatable .= '<span class="LC_nobreak">'
10595: .'<label><input type="radio" name="'
10596: .$parent.'" value="1" checked="checked" />'
10597: .&mt('Display').'</label>';
10598: if ($parent eq 'instcode') {
10599: $datatable .= ' ';
10600: } else {
10601: $datatable .= '</span></td></tr><tr><td>'
10602: .'<span class="LC_nobreak">';
10603: }
10604: $datatable .= '<label><input type="radio" name="'
10605: .$parent.'" value="0" />'
10606: .&mt('Do not display').'</label></span>';
1.272 raeburn 10607: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10608: $datatable .= '</td></tr></table>';
10609: }
10610: $datatable .= '</td>';
1.57 raeburn 10611: } else {
10612: $datatable .= $parent
1.214 raeburn 10613: .' <span class="LC_nobreak"><label>'
10614: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10615: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10616: }
10617: my $depth = 1;
10618: push(@path,$parent);
10619: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10620: pop(@path);
10621: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10622: $itemcount ++;
10623: }
1.48 raeburn 10624: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10625: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10626: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10627: for (my $k=0; $k<=$maxnum; $k++) {
10628: my $vpos = $k+1;
10629: my $selstr;
1.57 raeburn 10630: if ($k == $numtop) {
1.48 raeburn 10631: $selstr = ' selected="selected" ';
10632: }
10633: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10634: }
1.59 bisitz 10635: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10636: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10637: .'</tr>'."\n";
1.48 raeburn 10638: $itemcount ++;
1.272 raeburn 10639: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10640: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10641: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10642: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10643: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10644: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10645: for (my $k=0; $k<=$maxnum; $k++) {
10646: my $vpos = $k+1;
10647: my $selstr;
10648: if ($k == $maxnum) {
10649: $selstr = ' selected="selected" ';
10650: }
10651: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10652: }
1.120 raeburn 10653: $datatable .= '</select></span></td>'.
10654: '<td><span class="LC_nobreak">'.
10655: $default_names{$default}.'</span>';
10656: if ($default eq 'instcode') {
10657: $datatable .= '<br /><span class="LC_nobreak">('
10658: .&mt('with institutional codes').')</span>';
10659: }
10660: $datatable .= '</td>'
10661: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10662: .&mt('Display').'</label> '
10663: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10664: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10665: }
10666: }
10667: }
1.57 raeburn 10668: } else {
10669: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10670: }
10671: } else {
1.327 raeburn 10672: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10673: .&initialize_categories($itemcount);
1.48 raeburn 10674: }
1.57 raeburn 10675: $$rowtotal += $itemcount;
1.48 raeburn 10676: }
10677: return $datatable;
10678: }
10679:
1.69 raeburn 10680: sub print_serverstatuses {
10681: my ($dom,$settings,$rowtotal) = @_;
10682: my $datatable;
10683: my @pages = &serverstatus_pages();
10684: my (%namedaccess,%machineaccess);
10685: foreach my $type (@pages) {
10686: $namedaccess{$type} = '';
10687: $machineaccess{$type}= '';
10688: }
10689: if (ref($settings) eq 'HASH') {
10690: foreach my $type (@pages) {
10691: if (exists($settings->{$type})) {
10692: if (ref($settings->{$type}) eq 'HASH') {
10693: foreach my $key (keys(%{$settings->{$type}})) {
10694: if ($key eq 'namedusers') {
10695: $namedaccess{$type} = $settings->{$type}->{$key};
10696: } elsif ($key eq 'machines') {
10697: $machineaccess{$type} = $settings->{$type}->{$key};
10698: }
10699: }
10700: }
10701: }
10702: }
10703: }
1.81 raeburn 10704: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10705: my $rownum = 0;
10706: my $css_class;
10707: foreach my $type (@pages) {
10708: $rownum ++;
10709: $css_class = $rownum%2?' class="LC_odd_row"':'';
10710: $datatable .= '<tr'.$css_class.'>'.
10711: '<td><span class="LC_nobreak">'.
10712: $titles->{$type}.'</span></td>'.
10713: '<td class="LC_left_item">'.
10714: '<input type="text" name="'.$type.'_namedusers" '.
10715: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10716: '<td class="LC_right_item">'.
10717: '<span class="LC_nobreak">'.
10718: '<input type="text" name="'.$type.'_machines" '.
10719: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10720: '</span></td></tr>'."\n";
1.69 raeburn 10721: }
10722: $$rowtotal += $rownum;
10723: return $datatable;
10724: }
10725:
10726: sub serverstatus_pages {
10727: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 10728: 'checksums','clusterstatus','certstatus','metadata_keywords',
10729: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
10730: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10731: }
10732:
1.236 raeburn 10733: sub defaults_javascript {
10734: my ($settings) = @_;
1.354 raeburn 10735: return unless (ref($settings) eq 'HASH');
1.236 raeburn 10736: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10737: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10738: if ($maxnum eq '') {
10739: $maxnum = 0;
10740: }
10741: $maxnum ++;
1.249 raeburn 10742: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 10743: return <<"ENDSCRIPT";
10744: <script type="text/javascript">
10745: // <![CDATA[
10746: function reorderTypes(form,caller) {
10747: var changedVal;
10748: $jstext
10749: var newpos = 'addinststatus_pos';
10750: var current = new Array;
10751: var maxh = $maxnum;
10752: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10753: var oldVal;
10754: if (caller == newpos) {
10755: changedVal = newitemVal;
10756: } else {
10757: var curritem = 'inststatus_pos_'+caller;
10758: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10759: current[newitemVal] = newpos;
10760: }
10761: for (var i=0; i<inststatuses.length; i++) {
10762: if (inststatuses[i] != caller) {
10763: var elementName = 'inststatus_pos_'+inststatuses[i];
10764: if (form.elements[elementName]) {
10765: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10766: current[currVal] = elementName;
10767: }
10768: }
10769: }
10770: for (var j=0; j<maxh; j++) {
10771: if (current[j] == undefined) {
10772: oldVal = j;
10773: }
10774: }
10775: if (oldVal < changedVal) {
10776: for (var k=oldVal+1; k<=changedVal ; k++) {
10777: var elementName = current[k];
10778: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10779: }
10780: } else {
10781: for (var k=changedVal; k<oldVal; k++) {
10782: var elementName = current[k];
10783: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10784: }
10785: }
10786: return;
10787: }
10788:
10789: // ]]>
10790: </script>
10791:
10792: ENDSCRIPT
10793: }
1.354 raeburn 10794: return;
10795: }
10796:
10797: sub passwords_javascript {
1.365 raeburn 10798: my %intalert = &Apache::lonlocal::texthash (
10799: 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.',
10800: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10801: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10802: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10803: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
10804: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10805: );
10806: &js_escape(\%intalert);
10807: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 10808: my $intauthjs = <<"ENDSCRIPT";
10809:
10810: function warnIntAuth(field) {
10811: if (field.name == 'intauth_check') {
10812: if (field.value == '2') {
1.365 raeburn 10813: alert('$intalert{authcheck}');
1.354 raeburn 10814: }
10815: }
10816: if (field.name == 'intauth_cost') {
10817: field.value.replace(/\s/g,'');
10818: if (field.value != '') {
10819: var regexdigit=/^\\d+\$/;
10820: if (!regexdigit.test(field.value)) {
1.365 raeburn 10821: alert('$intalert{authcost}');
10822: }
10823: }
10824: }
10825: return;
10826: }
10827:
10828: function warnIntPass(field) {
10829: field.value.replace(/^\s+/,'');
10830: field.value.replace(/\s+\$/,'');
10831: var regexdigit=/^\\d+\$/;
10832: if (field.name == 'passwords_min') {
10833: if (field.value == '') {
10834: alert('$intalert{passmin}');
10835: field.value = '$defmin';
10836: } else {
10837: if (!regexdigit.test(field.value)) {
10838: alert('$intalert{passmin}');
10839: field.value = '$defmin';
10840: }
1.366 raeburn 10841: var minval = parseInt(field.value,10);
1.365 raeburn 10842: if (minval < $defmin) {
10843: alert('$intalert{passmin}');
10844: field.value = '$defmin';
10845: }
10846: }
10847: } else {
10848: if (field.value == '0') {
10849: field.value = '';
10850: }
10851: if (field.value != '') {
10852: if (field.name == 'passwords_expire') {
10853: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
10854: if (!regexpposnum.test(field.value)) {
10855: alert('$intalert{passexp}');
10856: field.value = '';
10857: } else {
10858: var expval = parseFloat(field.value);
10859: if (expval == 0) {
10860: alert('$intalert{passexp}');
10861: field.value = '';
10862: }
10863: }
10864: } else {
10865: if (!regexdigit.test(field.value)) {
10866: if (field.name == 'passwords_max') {
10867: alert('$intalert{passmax}');
10868: } else {
10869: if (field.name == 'passwords_numsaved') {
10870: alert('$intalert{passnum}');
10871: }
10872: }
1.370 raeburn 10873: field.value = '';
1.365 raeburn 10874: }
1.354 raeburn 10875: }
10876: }
10877: }
10878: return;
10879: }
10880:
10881: ENDSCRIPT
10882: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 10883: }
10884:
1.49 raeburn 10885: sub coursecategories_javascript {
10886: my ($settings) = @_;
1.57 raeburn 10887: my ($output,$jstext,$cathash);
1.49 raeburn 10888: if (ref($settings) eq 'HASH') {
1.57 raeburn 10889: $cathash = $settings->{'cats'};
10890: }
10891: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10892: my (@cats,@jsarray,%idx);
1.57 raeburn 10893: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10894: if (@jsarray > 0) {
10895: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10896: for (my $i=0; $i<@jsarray; $i++) {
10897: if (ref($jsarray[$i]) eq 'ARRAY') {
10898: my $catstr = join('","',@{$jsarray[$i]});
10899: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10900: }
10901: }
10902: }
10903: } else {
10904: $jstext = ' var categories = Array(1);'."\n".
10905: ' categories[0] = Array("instcode_pos");'."\n";
10906: }
1.237 bisitz 10907: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10908: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 10909: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 10910: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10911: &js_escape(\$instcode_reserved);
10912: &js_escape(\$communities_reserved);
1.272 raeburn 10913: &js_escape(\$placement_reserved);
1.265 damieng 10914: &js_escape(\$choose_again);
1.49 raeburn 10915: $output = <<"ENDSCRIPT";
10916: <script type="text/javascript">
1.109 raeburn 10917: // <![CDATA[
1.49 raeburn 10918: function reorderCats(form,parent,item,idx) {
10919: var changedVal;
10920: $jstext
10921: var newpos = 'addcategory_pos';
10922: if (parent == '') {
10923: var has_instcode = 0;
10924: var maxtop = categories[idx].length;
10925: for (var j=0; j<maxtop; j++) {
10926: if (categories[idx][j] == 'instcode::0') {
10927: has_instcode == 1;
10928: }
10929: }
10930: if (has_instcode == 0) {
10931: categories[idx][maxtop] = 'instcode_pos';
10932: }
10933: } else {
10934: newpos += '_'+parent;
10935: }
10936: var maxh = 1 + categories[idx].length;
10937: var current = new Array;
10938: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10939: if (item == newpos) {
10940: changedVal = newitemVal;
10941: } else {
10942: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10943: current[newitemVal] = newpos;
10944: }
10945: for (var i=0; i<categories[idx].length; i++) {
10946: var elementName = categories[idx][i];
10947: if (elementName != item) {
10948: if (form.elements[elementName]) {
10949: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10950: current[currVal] = elementName;
10951: }
10952: }
10953: }
10954: var oldVal;
10955: for (var j=0; j<maxh; j++) {
10956: if (current[j] == undefined) {
10957: oldVal = j;
10958: }
10959: }
10960: if (oldVal < changedVal) {
10961: for (var k=oldVal+1; k<=changedVal ; k++) {
10962: var elementName = current[k];
10963: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10964: }
10965: } else {
10966: for (var k=changedVal; k<oldVal; k++) {
10967: var elementName = current[k];
10968: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10969: }
10970: }
10971: return;
10972: }
1.120 raeburn 10973:
10974: function categoryCheck(form) {
10975: if (form.elements['addcategory_name'].value == 'instcode') {
10976: alert('$instcode_reserved\\n$choose_again');
10977: return false;
10978: }
10979: if (form.elements['addcategory_name'].value == 'communities') {
10980: alert('$communities_reserved\\n$choose_again');
10981: return false;
10982: }
1.272 raeburn 10983: if (form.elements['addcategory_name'].value == 'placement') {
10984: alert('$placement_reserved\\n$choose_again');
10985: return false;
10986: }
1.120 raeburn 10987: return true;
10988: }
10989:
1.109 raeburn 10990: // ]]>
1.49 raeburn 10991: </script>
10992:
10993: ENDSCRIPT
10994: return $output;
10995: }
10996:
1.48 raeburn 10997: sub initialize_categories {
10998: my ($itemcount) = @_;
1.120 raeburn 10999: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11000: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11001: instcode => 'Official courses (with institutional codes)',
11002: communities => 'Communities',
1.272 raeburn 11003: placement => 'Placement Tests',
1.120 raeburn 11004: );
1.328 raeburn 11005: my %selnum = (
11006: instcode => '0',
11007: communities => '1',
11008: placement => '2',
11009: );
11010: my %selected;
1.272 raeburn 11011: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11013: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11014: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11015: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11016: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11017: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11018: .'<option value="0"'.$selected{'0'}.'>1</option>'
11019: .'<option value="1"'.$selected{'1'}.'>2</option>'
11020: .'<option value="2"'.$selected{'2'}.'>3</option>'
11021: .'<option value="3">4</option></select> '
1.120 raeburn 11022: .$default_names{$default}
11023: .'</span></td><td><span class="LC_nobreak">'
11024: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11025: .&mt('Display').'</label> <label>'
11026: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11027: .'</label></span></td></tr>';
1.120 raeburn 11028: $itemcount ++;
11029: }
1.48 raeburn 11030: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11031: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11032: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11033: .'<select name="addcategory_pos"'.$chgstr.'>'
11034: .'<option value="0">1</option>'
11035: .'<option value="1">2</option>'
1.328 raeburn 11036: .'<option value="2">3</option>'
11037: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11038: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11039: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11040: .'</td></tr>';
1.48 raeburn 11041: return $datatable;
11042: }
11043:
11044: sub build_category_rows {
1.49 raeburn 11045: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11046: my ($text,$name,$item,$chgstr);
1.48 raeburn 11047: if (ref($cats) eq 'ARRAY') {
11048: my $maxdepth = scalar(@{$cats});
11049: if (ref($cats->[$depth]) eq 'HASH') {
11050: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11051: my $numchildren = @{$cats->[$depth]{$parent}};
11052: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11053: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11054: my ($idxnum,$parent_name,$parent_item);
11055: my $higher = $depth - 1;
11056: if ($higher == 0) {
11057: $parent_name = &escape($parent).'::'.$higher;
11058: } else {
11059: if (ref($path) eq 'ARRAY') {
11060: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11061: }
11062: }
11063: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11064: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11065: if ($j < $numchildren) {
1.48 raeburn 11066: $name = $cats->[$depth]{$parent}[$j];
11067: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11068: $idxnum = $idx->{$item};
11069: } else {
11070: $name = $parent_name;
11071: $item = $parent_item;
1.48 raeburn 11072: }
1.49 raeburn 11073: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11074: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11075: for (my $i=0; $i<=$numchildren; $i++) {
11076: my $vpos = $i+1;
11077: my $selstr;
11078: if ($j == $i) {
11079: $selstr = ' selected="selected" ';
11080: }
11081: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11082: }
11083: $text .= '</select> ';
11084: if ($j < $numchildren) {
11085: my $deeper = $depth+1;
11086: $text .= $name.' '
11087: .'<label><input type="checkbox" name="deletecategory" value="'
11088: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11089: if(ref($path) eq 'ARRAY') {
11090: push(@{$path},$name);
1.49 raeburn 11091: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11092: pop(@{$path});
11093: }
11094: } else {
1.330 raeburn 11095: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11096: if ($j == $numchildren) {
11097: $text .= $name;
11098: } else {
11099: $text .= $item;
11100: }
11101: $text .= '" value="" />';
11102: }
11103: $text .= '</td></tr>';
11104: }
11105: $text .= '</table></td>';
11106: } else {
11107: my $higher = $depth-1;
11108: if ($higher == 0) {
11109: $name = &escape($parent).'::'.$higher;
11110: } else {
11111: if (ref($path) eq 'ARRAY') {
11112: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11113: }
11114: }
11115: my $colspan;
11116: if ($parent ne 'instcode') {
11117: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11118: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11119: }
11120: }
11121: }
11122: }
11123: return $text;
11124: }
11125:
1.33 raeburn 11126: sub modifiable_userdata_row {
1.305 raeburn 11127: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11128: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11129: my ($role,$rolename,$statustype);
11130: $role = $item;
1.224 raeburn 11131: if ($context eq 'cancreate') {
1.305 raeburn 11132: if ($item =~ /^(emailusername)_(.+)$/) {
11133: $role = $1;
11134: $statustype = $2;
1.228 raeburn 11135: if (ref($usertypes) eq 'HASH') {
11136: if ($usertypes->{$statustype}) {
11137: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11138: } else {
11139: $rolename = &mt('Data provided by user');
11140: }
11141: }
1.224 raeburn 11142: }
11143: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11144: if (ref($usertypes) eq 'HASH') {
11145: $rolename = $usertypes->{$role};
11146: } else {
11147: $rolename = $role;
11148: }
1.325 raeburn 11149: } elsif ($context eq 'lti') {
11150: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11151: } elsif ($context eq 'privacy') {
11152: $rolename = $itemdesc;
1.33 raeburn 11153: } else {
1.63 raeburn 11154: if ($role eq 'cr') {
11155: $rolename = &mt('Custom role');
11156: } else {
11157: $rolename = &Apache::lonnet::plaintext($role);
11158: }
1.33 raeburn 11159: }
1.224 raeburn 11160: my (@fields,%fieldtitles);
11161: if (ref($fieldsref) eq 'ARRAY') {
11162: @fields = @{$fieldsref};
11163: } else {
11164: @fields = ('lastname','firstname','middlename','generation',
11165: 'permanentemail','id');
11166: }
11167: if ((ref($titlesref) eq 'HASH')) {
11168: %fieldtitles = %{$titlesref};
11169: } else {
11170: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11171: }
1.33 raeburn 11172: my $output;
1.305 raeburn 11173: my $css_class;
11174: if ($rowcount%2) {
11175: $css_class = 'LC_odd_row';
11176: }
11177: if ($customcss) {
11178: $css_class .= " $customcss";
11179: }
11180: $css_class =~ s/^\s+//;
11181: if ($css_class) {
11182: $css_class = ' class="'.$css_class.'"';
11183: }
11184: if ($rowstyle) {
11185: $css_class .= ' style="'.$rowstyle.'"';
11186: }
11187: if ($rowid) {
11188: $rowid = ' id="'.$rowid.'"';
11189: }
11190: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11191: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11192: '<td class="LC_left_item" colspan="2"><table>';
11193: my $rem;
11194: my %checks;
1.325 raeburn 11195: my %current;
1.33 raeburn 11196: if (ref($settings) eq 'HASH') {
1.325 raeburn 11197: my $hashref;
11198: if ($context eq 'lti') {
11199: if (ref($settings) eq 'HASH') {
11200: $hashref = $settings->{'instdata'};
11201: }
1.357 raeburn 11202: } elsif ($context eq 'privacy') {
11203: my ($key,$inner) = split(/_/,$role);
11204: if (ref($settings) eq 'HASH') {
11205: if (ref($settings->{$key}) eq 'HASH') {
11206: $hashref = $settings->{$key}->{$inner};
11207: }
11208: }
1.325 raeburn 11209: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11210: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11211: $hashref = $settings->{'lti_instdata'};
11212: }
11213: if ($role eq 'emailusername') {
11214: if ($statustype) {
11215: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11216: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11217: }
1.325 raeburn 11218: }
11219: }
11220: }
11221: if (ref($hashref) eq 'HASH') {
11222: foreach my $field (@fields) {
11223: if ($hashref->{$field}) {
11224: if ($role eq 'emailusername') {
11225: $checks{$field} = $hashref->{$field};
11226: } else {
11227: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11228: }
11229: }
11230: }
11231: }
11232: }
1.305 raeburn 11233:
11234: my $total = scalar(@fields);
11235: for (my $i=0; $i<$total; $i++) {
11236: $rem = $i%($numinrow);
1.33 raeburn 11237: if ($rem == 0) {
11238: if ($i > 0) {
11239: $output .= '</tr>';
11240: }
11241: $output .= '<tr>';
11242: }
11243: my $check = ' ';
1.228 raeburn 11244: unless ($role eq 'emailusername') {
11245: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11246: $check = $checks{$fields[$i]};
1.357 raeburn 11247: } elsif ($context eq 'privacy') {
11248: if ($role =~ /^priv_(domain|course)$/) {
11249: if (ref($settings) ne 'HASH') {
11250: $check = ' checked="checked" ';
11251: }
11252: } elsif ($role =~ /^priv_(author|community)$/) {
11253: if (ref($settings) ne 'HASH') {
11254: unless ($fields[$i] eq 'id') {
11255: $check = ' checked="checked" ';
11256: }
11257: }
11258: } elsif ($role =~ /^(unpriv|othdom)_/) {
11259: if (ref($settings) ne 'HASH') {
11260: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11261: $check = ' checked="checked" ';
11262: }
11263: }
11264: }
1.325 raeburn 11265: } elsif ($context ne 'lti') {
1.228 raeburn 11266: if ($role eq 'st') {
11267: if (ref($settings) ne 'HASH') {
11268: $check = ' checked="checked" ';
11269: }
1.33 raeburn 11270: }
11271: }
11272: }
11273: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11274: '<span class="LC_nobreak">';
1.325 raeburn 11275: my $prefix = 'canmodify';
1.228 raeburn 11276: if ($role eq 'emailusername') {
11277: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11278: $checks{$fields[$i]} = 'omit';
11279: }
11280: foreach my $option ('required','optional','omit') {
11281: my $checked='';
11282: if ($checks{$fields[$i]} eq $option) {
11283: $checked='checked="checked" ';
11284: }
11285: $output .= '<label>'.
1.325 raeburn 11286: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11287: &mt($option).'</label>'.(' ' x2);
11288: }
11289: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11290: } else {
1.325 raeburn 11291: if ($context eq 'lti') {
11292: $prefix = 'lti';
1.357 raeburn 11293: } elsif ($context eq 'privacy') {
11294: $prefix = 'privacy';
1.325 raeburn 11295: }
1.228 raeburn 11296: $output .= '<label>'.
1.325 raeburn 11297: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11298: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11299: '</label>';
11300: }
11301: $output .= '</span></td>';
1.33 raeburn 11302: }
1.305 raeburn 11303: $rem = $total%$numinrow;
11304: my $colsleft;
11305: if ($rem) {
11306: $colsleft = $numinrow - $rem;
11307: }
11308: if ($colsleft > 1) {
1.33 raeburn 11309: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11310: ' </td>';
11311: } elsif ($colsleft == 1) {
11312: $output .= '<td class="LC_left_item"> </td>';
11313: }
11314: $output .= '</tr></table></td></tr>';
11315: return $output;
11316: }
1.28 raeburn 11317:
1.93 raeburn 11318: sub insttypes_row {
1.305 raeburn 11319: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11320: $customcss,$rowstyle) = @_;
1.93 raeburn 11321: my %lt = &Apache::lonlocal::texthash (
11322: cansearch => 'Users allowed to search',
11323: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11324: lockablenames => 'User preference to lock name',
1.305 raeburn 11325: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11326: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11327: );
11328: my $showdom;
11329: if ($context eq 'cansearch') {
11330: $showdom = ' ('.$dom.')';
11331: }
1.165 raeburn 11332: my $class = 'LC_left_item';
11333: if ($context eq 'statustocreate') {
11334: $class = 'LC_right_item';
11335: }
1.305 raeburn 11336: my $css_class;
11337: if ($$rowtotal%2) {
11338: $css_class = 'LC_odd_row';
11339: }
11340: if ($customcss) {
11341: $css_class .= ' '.$customcss;
11342: }
11343: $css_class =~ s/^\s+//;
11344: if ($css_class) {
11345: $css_class = ' class="'.$css_class.'"';
11346: }
11347: if ($rowstyle) {
11348: $css_class .= ' style="'.$rowstyle.'"';
11349: }
11350: if ($onclick) {
11351: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11352: }
11353: my $output = '<tr'.$css_class.'>'.
11354: '<td>'.$lt{$context}.$showdom.
11355: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11356: my $rem;
11357: if (ref($types) eq 'ARRAY') {
11358: for (my $i=0; $i<@{$types}; $i++) {
11359: if (defined($usertypes->{$types->[$i]})) {
11360: my $rem = $i%($numinrow);
11361: if ($rem == 0) {
11362: if ($i > 0) {
11363: $output .= '</tr>';
11364: }
11365: $output .= '<tr>';
1.23 raeburn 11366: }
1.26 raeburn 11367: my $check = ' ';
1.99 raeburn 11368: if (ref($settings) eq 'HASH') {
11369: if (ref($settings->{$context}) eq 'ARRAY') {
11370: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11371: $check = ' checked="checked" ';
11372: }
1.315 raeburn 11373: } elsif (ref($settings->{$context}) eq 'HASH') {
11374: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11375: $check = ' checked="checked" ';
11376: }
1.99 raeburn 11377: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11378: $check = ' checked="checked" ';
11379: }
1.23 raeburn 11380: }
1.26 raeburn 11381: $output .= '<td class="LC_left_item">'.
11382: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11383: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11384: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11385: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11386: }
11387: }
1.26 raeburn 11388: $rem = @{$types}%($numinrow);
1.23 raeburn 11389: }
11390: my $colsleft = $numinrow - $rem;
1.315 raeburn 11391: if ($context eq 'overrides') {
11392: if ($colsleft > 1) {
11393: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11394: } else {
11395: $output .= '<td class="LC_left_item">';
11396: }
11397: $output .= ' ';
1.23 raeburn 11398: } else {
1.334 raeburn 11399: if ($rem == 0) {
1.315 raeburn 11400: $output .= '<tr>';
11401: }
11402: if ($colsleft > 1) {
11403: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11404: } else {
11405: $output .= '<td class="LC_left_item">';
11406: }
11407: my $defcheck = ' ';
11408: if (ref($settings) eq 'HASH') {
11409: if (ref($settings->{$context}) eq 'ARRAY') {
11410: if (grep(/^default$/,@{$settings->{$context}})) {
11411: $defcheck = ' checked="checked" ';
11412: }
11413: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11414: $defcheck = ' checked="checked" ';
11415: }
1.26 raeburn 11416: }
1.315 raeburn 11417: $output .= '<span class="LC_nobreak"><label>'.
11418: '<input type="checkbox" name="'.$context.'" '.
11419: 'value="default"'.$defcheck.$onclick.' />'.
11420: $othertitle.'</label></span>';
1.23 raeburn 11421: }
1.315 raeburn 11422: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11423: return $output;
1.23 raeburn 11424: }
11425:
11426: sub sorted_searchtitles {
11427: my %searchtitles = &Apache::lonlocal::texthash(
11428: 'uname' => 'username',
11429: 'lastname' => 'last name',
11430: 'lastfirst' => 'last name, first name',
11431: );
11432: my @titleorder = ('uname','lastname','lastfirst');
11433: return (\%searchtitles,\@titleorder);
11434: }
11435:
1.25 raeburn 11436: sub sorted_searchtypes {
11437: my %srchtypes_desc = (
11438: exact => 'is exact match',
11439: contains => 'contains ..',
11440: begins => 'begins with ..',
11441: );
11442: my @srchtypeorder = ('exact','begins','contains');
11443: return (\%srchtypes_desc,\@srchtypeorder);
11444: }
11445:
1.3 raeburn 11446: sub usertype_update_row {
11447: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11448: my $datatable;
11449: my $numinrow = 4;
11450: foreach my $type (@{$types}) {
11451: if (defined($usertypes->{$type})) {
11452: $$rownums ++;
11453: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11454: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11455: '</td><td class="LC_left_item"><table>';
11456: for (my $i=0; $i<@{$fields}; $i++) {
11457: my $rem = $i%($numinrow);
11458: if ($rem == 0) {
11459: if ($i > 0) {
11460: $datatable .= '</tr>';
11461: }
11462: $datatable .= '<tr>';
11463: }
11464: my $check = ' ';
1.39 raeburn 11465: if (ref($settings) eq 'HASH') {
11466: if (ref($settings->{'fields'}) eq 'HASH') {
11467: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11468: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11469: $check = ' checked="checked" ';
11470: }
1.3 raeburn 11471: }
11472: }
11473: }
11474:
11475: if ($i == @{$fields}-1) {
11476: my $colsleft = $numinrow - $rem;
11477: if ($colsleft > 1) {
11478: $datatable .= '<td colspan="'.$colsleft.'">';
11479: } else {
11480: $datatable .= '<td>';
11481: }
11482: } else {
11483: $datatable .= '<td>';
11484: }
1.8 raeburn 11485: $datatable .= '<span class="LC_nobreak"><label>'.
11486: '<input type="checkbox" name="updateable_'.$type.
11487: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11488: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11489: }
11490: $datatable .= '</tr></table></td></tr>';
11491: }
11492: }
11493: return $datatable;
1.1 raeburn 11494: }
11495:
11496: sub modify_login {
1.205 raeburn 11497: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11498: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11499: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
11500: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168 raeburn 11501: %title = ( coursecatalog => 'Display course catalog',
11502: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11503: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11504: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11505: loginheader => 'Log-in box header',
11506: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11507: @offon = ('off','on');
1.112 raeburn 11508: if (ref($domconfig{login}) eq 'HASH') {
11509: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11510: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11511: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11512: }
11513: }
1.386 raeburn 11514: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11515: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11516: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11517: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11518: $saml{$lonhost} = 1;
11519: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11520: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11521: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11522: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11523: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
11524: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11525: }
11526: }
11527: }
1.112 raeburn 11528: }
1.9 raeburn 11529: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11530: \%domconfig,\%loginhash);
1.188 raeburn 11531: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11532: foreach my $item (@toggles) {
11533: $loginhash{login}{$item} = $env{'form.'.$item};
11534: }
1.41 raeburn 11535: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11536: if (ref($colchanges{'login'}) eq 'HASH') {
11537: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11538: \%loginhash);
11539: }
1.110 raeburn 11540:
1.149 raeburn 11541: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11542: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11543: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11544: if (keys(%servers) > 1) {
11545: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11546: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11547: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11548: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11549: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11550: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11551: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11552: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11553: $changes{'loginvia'}{$lonhost} = 1;
11554: } else {
11555: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11556: $changes{'loginvia'}{$lonhost} = 1;
11557: }
11558: } else {
11559: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11560: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11561: $changes{'loginvia'}{$lonhost} = 1;
11562: }
11563: }
11564: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11565: foreach my $item (@loginvia_attribs) {
11566: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11567: }
11568: } else {
11569: foreach my $item (@loginvia_attribs) {
11570: my $new = $env{'form.'.$lonhost.'_'.$item};
11571: if (($item eq 'serverpath') && ($new eq 'custom')) {
11572: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11573: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11574: $new = '/';
11575: }
11576: }
11577: if (($item eq 'custompath') &&
11578: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11579: $new = '';
11580: }
11581: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11582: $changes{'loginvia'}{$lonhost} = 1;
11583: }
11584: if ($item eq 'exempt') {
1.256 raeburn 11585: $new = &check_exempt_addresses($new);
1.128 raeburn 11586: }
11587: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11588: }
11589: }
1.112 raeburn 11590: } else {
1.128 raeburn 11591: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11592: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11593: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11594: foreach my $item (@loginvia_attribs) {
11595: my $new = $env{'form.'.$lonhost.'_'.$item};
11596: if (($item eq 'serverpath') && ($new eq 'custom')) {
11597: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11598: $new = '/';
11599: }
11600: }
11601: if (($item eq 'custompath') &&
11602: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11603: $new = '';
11604: }
11605: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11606: }
1.110 raeburn 11607: }
11608: }
11609: }
11610: }
1.119 raeburn 11611:
1.168 raeburn 11612: my $servadm = $r->dir_config('lonAdmEMail');
11613: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11614: if (ref($domconfig{'login'}) eq 'HASH') {
11615: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11616: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11617: if ($lang eq 'nolang') {
11618: push(@currlangs,$lang);
11619: } elsif (defined($langchoices{$lang})) {
11620: push(@currlangs,$lang);
11621: } else {
11622: next;
11623: }
11624: }
11625: }
11626: }
11627: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11628: if (@currlangs > 0) {
11629: foreach my $lang (@currlangs) {
11630: if (grep(/^\Q$lang\E$/,@delurls)) {
11631: $changes{'helpurl'}{$lang} = 1;
11632: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11633: $changes{'helpurl'}{$lang} = 1;
11634: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11635: push(@newlangs,$lang);
11636: } else {
11637: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11638: }
11639: }
11640: }
11641: unless (grep(/^nolang$/,@currlangs)) {
11642: if ($env{'form.loginhelpurl_nolang.filename'}) {
11643: $changes{'helpurl'}{'nolang'} = 1;
11644: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11645: push(@newlangs,'nolang');
11646: }
11647: }
11648: if ($env{'form.loginhelpurl_add_lang'}) {
11649: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11650: ($env{'form.loginhelpurl_add_file.filename'})) {
11651: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11652: $addedfile = $env{'form.loginhelpurl_add_lang'};
11653: }
11654: }
11655: if ((@newlangs > 0) || ($addedfile)) {
11656: my $error;
11657: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11658: if ($configuserok eq 'ok') {
11659: if ($switchserver) {
11660: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11661: } elsif ($author_ok eq 'ok') {
11662: my @allnew = @newlangs;
11663: if ($addedfile ne '') {
11664: push(@allnew,$addedfile);
11665: }
11666: foreach my $lang (@allnew) {
11667: my $formelem = 'loginhelpurl_'.$lang;
11668: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11669: $formelem = 'loginhelpurl_add_file';
11670: }
11671: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11672: "help/$lang",'','',$newfile{$lang});
11673: if ($result eq 'ok') {
11674: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11675: $changes{'helpurl'}{$lang} = 1;
11676: } else {
11677: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11678: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11679: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11680: (!grep(/^\Q$lang\E$/,@delurls))) {
11681: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11682: }
11683: }
11684: }
11685: } else {
11686: $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);
11687: }
11688: } else {
11689: $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);
11690: }
11691: if ($error) {
11692: &Apache::lonnet::logthis($error);
11693: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11694: }
11695: }
1.256 raeburn 11696:
11697: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11698: if (ref($domconfig{'login'}) eq 'HASH') {
11699: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11700: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11701: if ($domservers{$lonhost}) {
11702: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11703: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11704: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11705: }
11706: }
11707: }
11708: }
11709: }
11710: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11711: foreach my $lonhost (sort(keys(%domservers))) {
11712: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11713: $changes{'headtag'}{$lonhost} = 1;
11714: } else {
11715: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11716: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11717: }
11718: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11719: push(@newhosts,$lonhost);
11720: } elsif ($currheadtagurls{$lonhost}) {
11721: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11722: if ($currexempt{$lonhost}) {
1.289 raeburn 11723: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11724: $changes{'headtag'}{$lonhost} = 1;
11725: }
11726: } elsif ($possexempt{$lonhost}) {
11727: $changes{'headtag'}{$lonhost} = 1;
11728: }
11729: if ($possexempt{$lonhost}) {
11730: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11731: }
11732: }
11733: }
11734: }
11735: if (@newhosts) {
11736: my $error;
11737: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11738: if ($configuserok eq 'ok') {
11739: if ($switchserver) {
11740: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11741: } elsif ($author_ok eq 'ok') {
11742: foreach my $lonhost (@newhosts) {
11743: my $formelem = 'loginheadtag_'.$lonhost;
11744: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11745: "login/headtag/$lonhost",'','',
11746: $env{'form.loginheadtag_'.$lonhost.'.filename'});
11747: if ($result eq 'ok') {
11748: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11749: $changes{'headtag'}{$lonhost} = 1;
11750: if ($possexempt{$lonhost}) {
11751: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11752: }
11753: } else {
11754: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11755: $newheadtagurls{$lonhost},$result);
11756: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11757: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11758: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11759: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11760: }
11761: }
11762: }
11763: } else {
11764: $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);
11765: }
11766: } else {
11767: $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);
11768: }
11769: if ($error) {
11770: &Apache::lonnet::logthis($error);
11771: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11772: }
11773: }
1.386 raeburn 11774: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11775: my @newsamlimgs;
11776: foreach my $lonhost (keys(%domservers)) {
11777: if ($env{'form.saml_'.$lonhost}) {
11778: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11779: push(@newsamlimgs,$lonhost);
11780: }
11781: foreach my $item ('text','alt','url','title','notsso') {
11782: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11783: }
11784: if ($saml{$lonhost}) {
11785: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11786: #FIXME Need to obsolete published image
11787: delete($currsaml{$lonhost}{'img'});
11788: $changes{'saml'}{$lonhost} = 1;
11789: }
11790: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11791: $changes{'saml'}{$lonhost} = 1;
11792: }
11793: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11794: $changes{'saml'}{$lonhost} = 1;
11795: }
11796: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11797: $changes{'saml'}{$lonhost} = 1;
11798: }
11799: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11800: $changes{'saml'}{$lonhost} = 1;
11801: }
11802: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11803: $changes{'saml'}{$lonhost} = 1;
11804: }
11805: } else {
11806: $changes{'saml'}{$lonhost} = 1;
11807: }
11808: foreach my $item ('text','alt','url','title','notsso') {
11809: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11810: }
11811: } else {
1.389 raeburn 11812: if ($saml{$lonhost}) {
11813: $changes{'saml'}{$lonhost} = 1;
11814: delete($currsaml{$lonhost});
11815: }
1.386 raeburn 11816: }
11817: }
11818: foreach my $posshost (keys(%currsaml)) {
11819: unless (exists($domservers{$posshost})) {
11820: delete($currsaml{$posshost});
11821: }
11822: }
11823: %{$loginhash{'login'}{'saml'}} = %currsaml;
11824: if (@newsamlimgs) {
11825: my $error;
11826: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11827: if ($configuserok eq 'ok') {
11828: if ($switchserver) {
11829: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11830: } elsif ($author_ok eq 'ok') {
11831: foreach my $lonhost (@newsamlimgs) {
11832: my $formelem = 'saml_img_'.$lonhost;
11833: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11834: "login/saml/$lonhost",'','',
11835: $env{'form.saml_img_'.$lonhost.'.filename'});
11836: if ($result eq 'ok') {
11837: $currsaml{$lonhost}{'img'} = $imgurl;
11838: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11839: $changes{'saml'}{$lonhost} = 1;
11840: } else {
11841: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11842: $lonhost,$result);
11843: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11844: }
11845: }
11846: } else {
11847: $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);
11848: }
11849: } else {
11850: $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);
11851: }
11852: if ($error) {
11853: &Apache::lonnet::logthis($error);
11854: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11855: }
11856: }
1.169 raeburn 11857: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 11858:
11859: my $defaulthelpfile = '/adm/loginproblems.html';
11860: my $defaulttext = &mt('Default in use');
11861:
1.1 raeburn 11862: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11863: $dom);
11864: if ($putresult eq 'ok') {
1.188 raeburn 11865: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11866: my %defaultchecked = (
11867: 'coursecatalog' => 'on',
1.188 raeburn 11868: 'helpdesk' => 'on',
1.42 raeburn 11869: 'adminmail' => 'off',
1.43 raeburn 11870: 'newuser' => 'off',
1.42 raeburn 11871: );
1.55 raeburn 11872: if (ref($domconfig{'login'}) eq 'HASH') {
11873: foreach my $item (@toggles) {
11874: if ($defaultchecked{$item} eq 'on') {
11875: if (($domconfig{'login'}{$item} eq '0') &&
11876: ($env{'form.'.$item} eq '1')) {
11877: $changes{$item} = 1;
11878: } elsif (($domconfig{'login'}{$item} eq '' ||
11879: $domconfig{'login'}{$item} eq '1') &&
11880: ($env{'form.'.$item} eq '0')) {
11881: $changes{$item} = 1;
11882: }
11883: } elsif ($defaultchecked{$item} eq 'off') {
11884: if (($domconfig{'login'}{$item} eq '1') &&
11885: ($env{'form.'.$item} eq '0')) {
11886: $changes{$item} = 1;
11887: } elsif (($domconfig{'login'}{$item} eq '' ||
11888: $domconfig{'login'}{$item} eq '0') &&
11889: ($env{'form.'.$item} eq '1')) {
11890: $changes{$item} = 1;
11891: }
1.42 raeburn 11892: }
11893: }
1.41 raeburn 11894: }
1.6 raeburn 11895: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11896: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 11897: if (exists($changes{'saml'})) {
11898: my $hostid_in_use;
11899: my @hosts = &Apache::lonnet::current_machine_ids();
11900: if (@hosts > 1) {
11901: foreach my $hostid (@hosts) {
11902: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11903: $hostid_in_use = $hostid;
11904: last;
11905: }
11906: }
11907: } else {
11908: $hostid_in_use = $r->dir_config('lonHostID');
11909: }
11910: if (($hostid_in_use) &&
11911: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 11912: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 11913: }
11914: if (ref($lastactref) eq 'HASH') {
11915: if (ref($changes{'saml'}) eq 'HASH') {
11916: my %updates;
11917: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11918: $lastactref->{'samllanding'} = \%updates;
11919: }
11920: }
11921: }
1.212 raeburn 11922: if (ref($lastactref) eq 'HASH') {
11923: $lastactref->{'domainconfig'} = 1;
11924: }
1.1 raeburn 11925: $resulttext = &mt('Changes made:').'<ul>';
11926: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11927: if ($item eq 'loginvia') {
1.112 raeburn 11928: if (ref($changes{$item}) eq 'HASH') {
11929: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11930: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11931: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11932: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11933: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11934: $protocol = 'http' if ($protocol ne 'https');
11935: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11936:
11937: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11938: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11939: } else {
11940: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11941: }
11942: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11943: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11944: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11945: }
11946: $resulttext .= '</li>';
11947: } else {
11948: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11949: }
1.112 raeburn 11950: } else {
1.128 raeburn 11951: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11952: }
11953: }
1.128 raeburn 11954: $resulttext .= '</ul></li>';
1.112 raeburn 11955: }
1.168 raeburn 11956: } elsif ($item eq 'helpurl') {
11957: if (ref($changes{$item}) eq 'HASH') {
11958: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11959: if (grep(/^\Q$lang\E$/,@delurls)) {
11960: my ($chg,$link);
11961: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11962: if ($lang eq 'nolang') {
11963: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11964: } else {
11965: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11966: }
11967: $resulttext .= '<li>'.$chg.'</li>';
11968: } else {
11969: my $chg;
11970: if ($lang eq 'nolang') {
11971: $chg = &mt('custom log-in help file for no preferred language');
11972: } else {
11973: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11974: }
11975: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11976: $loginhash{'login'}{'helpurl'}{$lang}.
11977: '?inhibitmenu=yes',$chg,600,500).
11978: '</li>';
11979: }
11980: }
11981: }
1.256 raeburn 11982: } elsif ($item eq 'headtag') {
11983: if (ref($changes{$item}) eq 'HASH') {
11984: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11985: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11986: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11987: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11988: $resulttext .= '<li><a href="'.
11989: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11990: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11991: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11992: if ($possexempt{$lonhost}) {
11993: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11994: } else {
11995: $resulttext .= &mt('included for any client IP');
11996: }
11997: $resulttext .= '</li>';
11998: }
11999: }
12000: }
1.386 raeburn 12001: } elsif ($item eq 'saml') {
12002: if (ref($changes{$item}) eq 'HASH') {
12003: my %notlt = (
12004: text => 'Text for log-in by SSO',
12005: img => 'SSO button image',
12006: alt => 'Alt text for button image',
12007: url => 'SSO URL',
12008: title => 'Tooltip for SSO link',
12009: notsso => 'Text for non-SSO log-in',
12010: );
12011: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12012: if (ref($currsaml{$lonhost}) eq 'HASH') {
12013: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12014: '<ul>';
12015: foreach my $key ('text','img','alt','url','title','notsso') {
12016: if ($currsaml{$lonhost}{$key} eq '') {
12017: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12018: } else {
12019: my $value = "'$currsaml{$lonhost}{$key}'";
12020: if ($key eq 'img') {
12021: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
12022: }
12023: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12024: $value).'</li>';
12025: }
12026: }
12027: $resulttext .= '</ul></li>';
12028: } else {
12029: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12030: }
12031: }
12032: }
1.169 raeburn 12033: } elsif ($item eq 'captcha') {
12034: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12035: my $chgtxt;
1.169 raeburn 12036: if ($loginhash{'login'}{$item} eq 'notused') {
12037: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12038: } else {
12039: my %captchas = &captcha_phrases();
12040: if ($captchas{$loginhash{'login'}{$item}}) {
12041: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12042: } else {
12043: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12044: }
12045: }
12046: $resulttext .= '<li>'.$chgtxt.'</li>';
12047: }
12048: } elsif ($item eq 'recaptchakeys') {
12049: if (ref($loginhash{'login'}) eq 'HASH') {
12050: my ($privkey,$pubkey);
12051: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12052: $pubkey = $loginhash{'login'}{$item}{'public'};
12053: $privkey = $loginhash{'login'}{$item}{'private'};
12054: }
12055: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12056: if (!$pubkey) {
12057: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12058: } else {
12059: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12060: }
12061: if (!$privkey) {
12062: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12063: } else {
1.251 raeburn 12064: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12065: }
12066: $chgtxt .= '</ul>';
12067: $resulttext .= '<li>'.$chgtxt.'</li>';
12068: }
1.269 raeburn 12069: } elsif ($item eq 'recaptchaversion') {
12070: if (ref($loginhash{'login'}) eq 'HASH') {
12071: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12072: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12073: '</li>';
12074: }
12075: }
1.41 raeburn 12076: } else {
12077: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12078: }
1.1 raeburn 12079: }
1.6 raeburn 12080: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12081: } else {
12082: $resulttext = &mt('No changes made to log-in page settings');
12083: }
12084: } else {
1.11 albertel 12085: $resulttext = '<span class="LC_error">'.
12086: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12087: }
1.6 raeburn 12088: if ($errors) {
1.9 raeburn 12089: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12090: $errors.'</ul>';
12091: }
12092: return $resulttext;
12093: }
12094:
1.256 raeburn 12095: sub check_exempt_addresses {
12096: my ($iplist) = @_;
12097: $iplist =~ s/^\s+//;
12098: $iplist =~ s/\s+$//;
12099: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12100: my (@okips,$new);
12101: foreach my $ip (@poss_ips) {
12102: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12103: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12104: push(@okips,$ip);
12105: }
12106: }
12107: }
12108: if (@okips > 0) {
12109: $new = join(',',@okips);
12110: } else {
12111: $new = '';
12112: }
12113: return $new;
12114: }
12115:
1.6 raeburn 12116: sub color_font_choices {
12117: my %choices =
12118: &Apache::lonlocal::texthash (
12119: img => "Header",
12120: bgs => "Background colors",
12121: links => "Link colors",
1.55 raeburn 12122: images => "Images",
1.6 raeburn 12123: font => "Font color",
1.201 raeburn 12124: fontmenu => "Font menu",
1.76 raeburn 12125: pgbg => "Page",
1.6 raeburn 12126: tabbg => "Header",
12127: sidebg => "Border",
12128: link => "Link",
12129: alink => "Active link",
12130: vlink => "Visited link",
12131: );
12132: return %choices;
12133: }
12134:
12135: sub modify_rolecolors {
1.205 raeburn 12136: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12137: my ($resulttext,%rolehash);
12138: $rolehash{'rolecolors'} = {};
1.55 raeburn 12139: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12140: if ($domconfig{'rolecolors'} eq '') {
12141: $domconfig{'rolecolors'} = {};
12142: }
12143: }
1.9 raeburn 12144: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12145: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12146: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12147: $dom);
12148: if ($putresult eq 'ok') {
12149: if (keys(%changes) > 0) {
1.41 raeburn 12150: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12151: if (ref($lastactref) eq 'HASH') {
12152: $lastactref->{'domainconfig'} = 1;
12153: }
1.6 raeburn 12154: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12155: $rolehash{'rolecolors'});
12156: } else {
12157: $resulttext = &mt('No changes made to default color schemes');
12158: }
12159: } else {
1.11 albertel 12160: $resulttext = '<span class="LC_error">'.
12161: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12162: }
12163: if ($errors) {
12164: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12165: $errors.'</ul>';
12166: }
12167: return $resulttext;
12168: }
12169:
12170: sub modify_colors {
1.9 raeburn 12171: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12172: my (%changes,%choices);
1.51 raeburn 12173: my @bgs;
1.6 raeburn 12174: my @links = ('link','alink','vlink');
1.41 raeburn 12175: my @logintext;
1.6 raeburn 12176: my @images;
12177: my $servadm = $r->dir_config('lonAdmEMail');
12178: my $errors;
1.200 raeburn 12179: my %defaults;
1.6 raeburn 12180: foreach my $role (@{$roles}) {
12181: if ($role eq 'login') {
1.12 raeburn 12182: %choices = &login_choices();
1.41 raeburn 12183: @logintext = ('textcol','bgcol');
1.12 raeburn 12184: } else {
12185: %choices = &color_font_choices();
12186: }
12187: if ($role eq 'login') {
1.41 raeburn 12188: @images = ('img','logo','domlogo','login');
1.51 raeburn 12189: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12190: } else {
12191: @images = ('img');
1.200 raeburn 12192: @bgs = ('pgbg','tabbg','sidebg');
12193: }
12194: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12195: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12196: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12197: }
12198: if ($role eq 'login') {
12199: foreach my $item (@logintext) {
1.234 raeburn 12200: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12201: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12202: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12203: }
12204: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12205: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12206: }
12207: }
12208: } else {
1.234 raeburn 12209: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12210: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12211: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12212: }
12213: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12214: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12215: }
1.6 raeburn 12216: }
1.200 raeburn 12217: foreach my $item (@bgs) {
1.234 raeburn 12218: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12219: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12220: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12221: }
12222: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12223: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12224: }
12225: }
12226: foreach my $item (@links) {
1.234 raeburn 12227: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12228: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12229: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12230: }
12231: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12232: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12233: }
1.6 raeburn 12234: }
1.46 raeburn 12235: my ($configuserok,$author_ok,$switchserver) =
12236: &config_check($dom,$confname,$servadm);
1.9 raeburn 12237: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12238: if (ref($domconfig->{$role}) ne 'HASH') {
12239: $domconfig->{$role} = {};
12240: }
1.8 raeburn 12241: foreach my $img (@images) {
1.70 raeburn 12242: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
12243: if (defined($env{'form.login_showlogo_'.$img})) {
12244: $confhash->{$role}{'showlogo'}{$img} = 1;
12245: } else {
12246: $confhash->{$role}{'showlogo'}{$img} = 0;
12247: }
12248: }
1.18 albertel 12249: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12250: && !defined($domconfig->{$role}{$img})
12251: && !$env{'form.'.$role.'_del_'.$img}
12252: && $env{'form.'.$role.'_import_'.$img}) {
12253: # import the old configured image from the .tab setting
12254: # if they haven't provided a new one
12255: $domconfig->{$role}{$img} =
12256: $env{'form.'.$role.'_import_'.$img};
12257: }
1.6 raeburn 12258: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12259: my $error;
1.6 raeburn 12260: if ($configuserok eq 'ok') {
1.9 raeburn 12261: if ($switchserver) {
1.12 raeburn 12262: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12263: } else {
12264: if ($author_ok eq 'ok') {
12265: my ($result,$logourl) =
12266: &publishlogo($r,'upload',$role.'_'.$img,
12267: $dom,$confname,$img,$width,$height);
12268: if ($result eq 'ok') {
12269: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12270: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12271: } else {
1.12 raeburn 12272: $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 12273: }
12274: } else {
1.46 raeburn 12275: $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 12276: }
12277: }
12278: } else {
1.46 raeburn 12279: $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 12280: }
12281: if ($error) {
1.8 raeburn 12282: &Apache::lonnet::logthis($error);
1.11 albertel 12283: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12284: }
12285: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12286: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12287: my $error;
12288: if ($configuserok eq 'ok') {
12289: # is confname an author?
12290: if ($switchserver eq '') {
12291: if ($author_ok eq 'ok') {
12292: my ($result,$logourl) =
12293: &publishlogo($r,'copy',$domconfig->{$role}{$img},
12294: $dom,$confname,$img,$width,$height);
12295: if ($result eq 'ok') {
12296: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12297: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12298: }
12299: }
12300: }
12301: }
1.6 raeburn 12302: }
12303: }
12304: }
12305: if (ref($domconfig) eq 'HASH') {
12306: if (ref($domconfig->{$role}) eq 'HASH') {
12307: foreach my $img (@images) {
12308: if ($domconfig->{$role}{$img} ne '') {
12309: if ($env{'form.'.$role.'_del_'.$img}) {
12310: $confhash->{$role}{$img} = '';
1.12 raeburn 12311: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12312: } else {
1.9 raeburn 12313: if ($confhash->{$role}{$img} eq '') {
12314: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12315: }
1.6 raeburn 12316: }
12317: } else {
12318: if ($env{'form.'.$role.'_del_'.$img}) {
12319: $confhash->{$role}{$img} = '';
1.12 raeburn 12320: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12321: }
12322: }
1.70 raeburn 12323: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
12324: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12325: if ($confhash->{$role}{'showlogo'}{$img} ne
12326: $domconfig->{$role}{'showlogo'}{$img}) {
12327: $changes{$role}{'showlogo'}{$img} = 1;
12328: }
12329: } else {
12330: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12331: $changes{$role}{'showlogo'}{$img} = 1;
12332: }
12333: }
12334: }
12335: }
1.6 raeburn 12336: if ($domconfig->{$role}{'font'} ne '') {
12337: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12338: $changes{$role}{'font'} = 1;
12339: }
12340: } else {
12341: if ($confhash->{$role}{'font'}) {
12342: $changes{$role}{'font'} = 1;
12343: }
12344: }
1.107 raeburn 12345: if ($role ne 'login') {
12346: if ($domconfig->{$role}{'fontmenu'} ne '') {
12347: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12348: $changes{$role}{'fontmenu'} = 1;
12349: }
12350: } else {
12351: if ($confhash->{$role}{'fontmenu'}) {
12352: $changes{$role}{'fontmenu'} = 1;
12353: }
1.97 tempelho 12354: }
12355: }
1.6 raeburn 12356: foreach my $item (@bgs) {
12357: if ($domconfig->{$role}{$item} ne '') {
12358: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12359: $changes{$role}{'bgs'}{$item} = 1;
12360: }
12361: } else {
12362: if ($confhash->{$role}{$item}) {
12363: $changes{$role}{'bgs'}{$item} = 1;
12364: }
12365: }
12366: }
12367: foreach my $item (@links) {
12368: if ($domconfig->{$role}{$item} ne '') {
12369: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12370: $changes{$role}{'links'}{$item} = 1;
12371: }
12372: } else {
12373: if ($confhash->{$role}{$item}) {
12374: $changes{$role}{'links'}{$item} = 1;
12375: }
12376: }
12377: }
1.41 raeburn 12378: foreach my $item (@logintext) {
12379: if ($domconfig->{$role}{$item} ne '') {
12380: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12381: $changes{$role}{'logintext'}{$item} = 1;
12382: }
12383: } else {
12384: if ($confhash->{$role}{$item}) {
12385: $changes{$role}{'logintext'}{$item} = 1;
12386: }
12387: }
12388: }
1.6 raeburn 12389: } else {
12390: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12391: \@logintext,$confhash,\%changes);
1.6 raeburn 12392: }
12393: } else {
12394: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12395: \@logintext,$confhash,\%changes);
1.6 raeburn 12396: }
12397: }
12398: return ($errors,%changes);
12399: }
12400:
1.46 raeburn 12401: sub config_check {
12402: my ($dom,$confname,$servadm) = @_;
12403: my ($configuserok,$author_ok,$switchserver,%currroles);
12404: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12405: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12406: $confname,$servadm);
12407: if ($configuserok eq 'ok') {
12408: $switchserver = &check_switchserver($dom,$confname);
12409: if ($switchserver eq '') {
12410: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12411: }
12412: }
12413: return ($configuserok,$author_ok,$switchserver);
12414: }
12415:
1.6 raeburn 12416: sub default_change_checker {
1.41 raeburn 12417: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12418: foreach my $item (@{$links}) {
12419: if ($confhash->{$role}{$item}) {
12420: $changes->{$role}{'links'}{$item} = 1;
12421: }
12422: }
12423: foreach my $item (@{$bgs}) {
12424: if ($confhash->{$role}{$item}) {
12425: $changes->{$role}{'bgs'}{$item} = 1;
12426: }
12427: }
1.41 raeburn 12428: foreach my $item (@{$logintext}) {
12429: if ($confhash->{$role}{$item}) {
12430: $changes->{$role}{'logintext'}{$item} = 1;
12431: }
12432: }
1.6 raeburn 12433: foreach my $img (@{$images}) {
12434: if ($env{'form.'.$role.'_del_'.$img}) {
12435: $confhash->{$role}{$img} = '';
1.12 raeburn 12436: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12437: }
1.70 raeburn 12438: if ($role eq 'login') {
12439: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12440: $changes->{$role}{'showlogo'}{$img} = 1;
12441: }
12442: }
1.6 raeburn 12443: }
12444: if ($confhash->{$role}{'font'}) {
12445: $changes->{$role}{'font'} = 1;
12446: }
1.48 raeburn 12447: }
1.6 raeburn 12448:
12449: sub display_colorchgs {
12450: my ($dom,$changes,$roles,$confhash) = @_;
12451: my (%choices,$resulttext);
12452: if (!grep(/^login$/,@{$roles})) {
12453: $resulttext = &mt('Changes made:').'<br />';
12454: }
12455: foreach my $role (@{$roles}) {
12456: if ($role eq 'login') {
12457: %choices = &login_choices();
12458: } else {
12459: %choices = &color_font_choices();
12460: }
12461: if (ref($changes->{$role}) eq 'HASH') {
12462: if ($role ne 'login') {
12463: $resulttext .= '<h4>'.&mt($role).'</h4>';
12464: }
12465: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12466: if ($role ne 'login') {
12467: $resulttext .= '<ul>';
12468: }
12469: if (ref($changes->{$role}{$key}) eq 'HASH') {
12470: if ($role ne 'login') {
12471: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12472: }
12473: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12474: if (($role eq 'login') && ($key eq 'showlogo')) {
12475: if ($confhash->{$role}{$key}{$item}) {
12476: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12477: } else {
12478: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12479: }
12480: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12481: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12482: } else {
1.12 raeburn 12483: my $newitem = $confhash->{$role}{$item};
12484: if ($key eq 'images') {
1.306 raeburn 12485: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 12486: }
12487: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12488: }
12489: }
12490: if ($role ne 'login') {
12491: $resulttext .= '</ul></li>';
12492: }
12493: } else {
12494: if ($confhash->{$role}{$key} eq '') {
12495: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12496: } else {
12497: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12498: }
12499: }
12500: if ($role ne 'login') {
12501: $resulttext .= '</ul>';
12502: }
12503: }
12504: }
12505: }
1.3 raeburn 12506: return $resulttext;
1.1 raeburn 12507: }
12508:
1.9 raeburn 12509: sub thumb_dimensions {
12510: return ('200','50');
12511: }
12512:
1.16 raeburn 12513: sub check_dimensions {
12514: my ($inputfile) = @_;
12515: my ($fullwidth,$fullheight);
12516: if ($inputfile =~ m|^[/\w.\-]+$|) {
12517: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12518: my $imageinfo = <PIPE>;
12519: if (!close(PIPE)) {
12520: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12521: }
12522: chomp($imageinfo);
12523: my ($fullsize) =
1.21 raeburn 12524: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12525: if ($fullsize) {
12526: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12527: }
12528: }
12529: }
12530: return ($fullwidth,$fullheight);
12531: }
12532:
1.9 raeburn 12533: sub check_configuser {
12534: my ($uhome,$dom,$confname,$servadm) = @_;
12535: my ($configuserok,%currroles);
12536: if ($uhome eq 'no_host') {
12537: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 12538: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12539: $configuserok =
12540: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12541: $configpass,'','','','','',undef,$servadm);
12542: } else {
12543: $configuserok = 'ok';
12544: %currroles =
12545: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12546: }
12547: return ($configuserok,%currroles);
12548: }
12549:
12550: sub check_authorstatus {
12551: my ($dom,$confname,%currroles) = @_;
12552: my $author_ok;
1.40 raeburn 12553: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12554: my $start = time;
12555: my $end = 0;
12556: $author_ok =
12557: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12558: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12559: } else {
12560: $author_ok = 'ok';
12561: }
12562: return $author_ok;
12563: }
12564:
12565: sub publishlogo {
1.46 raeburn 12566: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 12567: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 12568: if ($action eq 'upload') {
12569: $fname=$env{'form.'.$formname.'.filename'};
12570: chop($env{'form.'.$formname});
12571: } else {
12572: ($fname) = ($formname =~ /([^\/]+)$/);
12573: }
1.46 raeburn 12574: if ($savefileas ne '') {
12575: $fname = $savefileas;
12576: }
1.9 raeburn 12577: $fname=&Apache::lonnet::clean_filename($fname);
12578: # See if there is anything left
12579: unless ($fname) { return ('error: no uploaded file'); }
12580: $fname="$subdir/$fname";
1.210 raeburn 12581: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 12582: my $filepath="$docroot/priv";
12583: my $relpath = "$dom/$confname";
1.9 raeburn 12584: my ($fnamepath,$file,$fetchthumb);
12585: $file=$fname;
12586: if ($fname=~m|/|) {
12587: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
12588: }
1.164 raeburn 12589: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 12590: my $count;
1.164 raeburn 12591: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 12592: $filepath.="/$parts[$count]";
12593: if ((-e $filepath)!=1) {
12594: mkdir($filepath,02770);
12595: }
12596: }
12597: # Check for bad extension and disallow upload
12598: if ($file=~/\.(\w+)$/ &&
12599: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
12600: $output =
1.207 bisitz 12601: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 12602: } elsif ($file=~/\.(\w+)$/ &&
12603: !defined(&Apache::loncommon::fileembstyle($1))) {
12604: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
12605: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 12606: $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 12607: } elsif (-d "$filepath/$file") {
1.195 bisitz 12608: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 12609: } else {
12610: my $source = $filepath.'/'.$file;
12611: my $logfile;
1.316 raeburn 12612: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 12613: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 12614: }
12615: print $logfile
12616: "\n================= Publish ".localtime()." ================\n".
12617: $env{'user.name'}.':'.$env{'user.domain'}."\n";
12618: # Save the file
1.316 raeburn 12619: if (!open(FH,">",$source)) {
1.9 raeburn 12620: &Apache::lonnet::logthis('Failed to create '.$source);
12621: return (&mt('Failed to create file'));
12622: }
12623: if ($action eq 'upload') {
12624: if (!print FH ($env{'form.'.$formname})) {
12625: &Apache::lonnet::logthis('Failed to write to '.$source);
12626: return (&mt('Failed to write file'));
12627: }
12628: } else {
12629: my $original = &Apache::lonnet::filelocation('',$formname);
12630: if(!copy($original,$source)) {
12631: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
12632: return (&mt('Failed to write file'));
12633: }
12634: }
12635: close(FH);
12636: chmod(0660, $source); # Permissions to rw-rw---.
12637:
12638: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
12639: my $copyfile=$targetdir.'/'.$file;
12640:
12641: my @parts=split(/\//,$targetdir);
12642: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
12643: for (my $count=5;$count<=$#parts;$count++) {
12644: $path.="/$parts[$count]";
12645: if (!-e $path) {
12646: print $logfile "\nCreating directory ".$path;
12647: mkdir($path,02770);
12648: }
12649: }
12650: my $versionresult;
12651: if (-e $copyfile) {
12652: $versionresult = &logo_versioning($targetdir,$file,$logfile);
12653: } else {
12654: $versionresult = 'ok';
12655: }
12656: if ($versionresult eq 'ok') {
12657: if (copy($source,$copyfile)) {
12658: print $logfile "\nCopied original source to ".$copyfile."\n";
12659: $output = 'ok';
12660: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 12661: push(@{$modified_urls},[$copyfile,$source]);
12662: my $metaoutput =
12663: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
12664: unless ($registered_cleanup) {
12665: my $handlers = $r->get_handlers('PerlCleanupHandler');
12666: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12667: $registered_cleanup=1;
12668: }
1.9 raeburn 12669: } else {
12670: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
12671: $output = &mt('Failed to copy file to RES space').", $!";
12672: }
12673: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
12674: my $inputfile = $filepath.'/'.$file;
12675: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 12676: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
12677: if ($fullwidth ne '' && $fullheight ne '') {
12678: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
12679: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 12680: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
12681: system({$args[0]} @args);
1.16 raeburn 12682: chmod(0660, $filepath.'/tn-'.$file);
12683: if (-e $outfile) {
12684: my $copyfile=$targetdir.'/tn-'.$file;
12685: if (copy($outfile,$copyfile)) {
12686: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 12687: my $thumb_metaoutput =
12688: &write_metadata($dom,$confname,$formname,
12689: $targetdir,'tn-'.$file,$logfile);
12690: push(@{$modified_urls},[$copyfile,$outfile]);
12691: unless ($registered_cleanup) {
12692: my $handlers = $r->get_handlers('PerlCleanupHandler');
12693: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12694: $registered_cleanup=1;
12695: }
1.267 raeburn 12696: $madethumb = 1;
1.16 raeburn 12697: } else {
12698: print $logfile "\nUnable to write ".$copyfile.
12699: ':'.$!."\n";
12700: }
12701: }
1.9 raeburn 12702: }
12703: }
12704: }
12705: } else {
12706: $output = $versionresult;
12707: }
12708: }
1.267 raeburn 12709: return ($output,$logourl,$madethumb);
1.9 raeburn 12710: }
12711:
12712: sub logo_versioning {
12713: my ($targetdir,$file,$logfile) = @_;
12714: my $target = $targetdir.'/'.$file;
12715: my ($maxversion,$fn,$extn,$output);
12716: $maxversion = 0;
12717: if ($file =~ /^(.+)\.(\w+)$/) {
12718: $fn=$1;
12719: $extn=$2;
12720: }
12721: opendir(DIR,$targetdir);
12722: while (my $filename=readdir(DIR)) {
12723: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
12724: $maxversion=($1>$maxversion)?$1:$maxversion;
12725: }
12726: }
12727: $maxversion++;
12728: print $logfile "\nCreating old version ".$maxversion."\n";
12729: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
12730: if (copy($target,$copyfile)) {
12731: print $logfile "Copied old target to ".$copyfile."\n";
12732: $copyfile=$copyfile.'.meta';
12733: if (copy($target.'.meta',$copyfile)) {
12734: print $logfile "Copied old target metadata to ".$copyfile."\n";
12735: $output = 'ok';
12736: } else {
12737: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
12738: $output = &mt('Failed to copy old meta').", $!, ";
12739: }
12740: } else {
12741: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
12742: $output = &mt('Failed to copy old target').", $!, ";
12743: }
12744: return $output;
12745: }
12746:
12747: sub write_metadata {
12748: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
12749: my (%metadatafields,%metadatakeys,$output);
12750: $metadatafields{'title'}=$formname;
12751: $metadatafields{'creationdate'}=time;
12752: $metadatafields{'lastrevisiondate'}=time;
12753: $metadatafields{'copyright'}='public';
12754: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
12755: $env{'user.domain'};
12756: $metadatafields{'authorspace'}=$confname.':'.$dom;
12757: $metadatafields{'domain'}=$dom;
12758: {
12759: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
12760: my $mfh;
1.316 raeburn 12761: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 12762: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 12763: unless ($_=~/\./) {
12764: my $unikey=$_;
12765: $unikey=~/^([A-Za-z]+)/;
12766: my $tag=$1;
12767: $tag=~tr/A-Z/a-z/;
12768: print $mfh "\n\<$tag";
12769: foreach (split(/\,/,$metadatakeys{$unikey})) {
12770: my $value=$metadatafields{$unikey.'.'.$_};
12771: $value=~s/\"/\'\'/g;
12772: print $mfh ' '.$_.'="'.$value.'"';
12773: }
12774: print $mfh '>'.
12775: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
12776: .'</'.$tag.'>';
12777: }
12778: }
12779: $output = 'ok';
12780: print $logfile "\nWrote metadata";
12781: close($mfh);
12782: } else {
12783: print $logfile "\nFailed to open metadata file";
1.9 raeburn 12784: $output = &mt('Could not write metadata');
12785: }
12786: }
1.155 raeburn 12787: return $output;
12788: }
12789:
12790: sub notifysubscribed {
12791: foreach my $targetsource (@{$modified_urls}){
12792: next unless (ref($targetsource) eq 'ARRAY');
12793: my ($target,$source)=@{$targetsource};
12794: if ($source ne '') {
1.316 raeburn 12795: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12796: print $logfh "\nCleanup phase: Notifications\n";
12797: my @subscribed=&subscribed_hosts($target);
12798: foreach my $subhost (@subscribed) {
12799: print $logfh "\nNotifying host ".$subhost.':';
12800: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12801: print $logfh $reply;
12802: }
12803: my @subscribedmeta=&subscribed_hosts("$target.meta");
12804: foreach my $subhost (@subscribedmeta) {
12805: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12806: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12807: $subhost);
12808: print $logfh $reply;
12809: }
12810: print $logfh "\n============ Done ============\n";
1.160 raeburn 12811: close($logfh);
1.155 raeburn 12812: }
12813: }
12814: }
12815: return OK;
12816: }
12817:
12818: sub subscribed_hosts {
12819: my ($target) = @_;
12820: my @subscribed;
1.316 raeburn 12821: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12822: while (my $subline=<$fh>) {
12823: if ($subline =~ /^($match_lonid):/) {
12824: my $host = $1;
12825: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12826: unless (grep(/^\Q$host\E$/,@subscribed)) {
12827: push(@subscribed,$host);
12828: }
12829: }
12830: }
12831: }
12832: }
12833: return @subscribed;
1.9 raeburn 12834: }
12835:
12836: sub check_switchserver {
12837: my ($dom,$confname) = @_;
12838: my ($allowed,$switchserver);
12839: my $home = &Apache::lonnet::homeserver($confname,$dom);
12840: if ($home eq 'no_host') {
12841: $home = &Apache::lonnet::domain($dom,'primary');
12842: }
12843: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12844: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12845: if (!$allowed) {
1.180 raeburn 12846: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12847: }
12848: return $switchserver;
12849: }
12850:
1.1 raeburn 12851: sub modify_quotas {
1.216 raeburn 12852: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12853: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 12854: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 12855: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12856: $validationfieldsref);
1.86 raeburn 12857: if ($action eq 'quotas') {
12858: $context = 'tools';
1.163 raeburn 12859: } else {
1.86 raeburn 12860: $context = $action;
12861: }
12862: if ($context eq 'requestcourses') {
1.325 raeburn 12863: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 12864: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12865: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12866: %titles = &courserequest_titles();
12867: $toolregexp = join('|',@usertools);
12868: %conditions = &courserequest_conditions();
1.216 raeburn 12869: $confname = $dom.'-domainconfig';
12870: my $servadm = $r->dir_config('lonAdmEMail');
12871: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 12872: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12873: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 12874: } elsif ($context eq 'requestauthor') {
12875: @usertools = ('author');
12876: %titles = &authorrequest_titles();
1.86 raeburn 12877: } else {
1.162 raeburn 12878: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 12879: %titles = &tool_titles();
1.86 raeburn 12880: }
1.212 raeburn 12881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12882: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12883: foreach my $key (keys(%env)) {
1.101 raeburn 12884: if ($context eq 'requestcourses') {
12885: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12886: my $item = $1;
12887: my $type = $2;
12888: if ($type =~ /^limit_(.+)/) {
12889: $limithash{$item}{$1} = $env{$key};
12890: } else {
12891: $confhash{$item}{$type} = $env{$key};
12892: }
12893: }
1.163 raeburn 12894: } elsif ($context eq 'requestauthor') {
12895: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12896: $confhash{$1} = $env{$key};
12897: }
1.101 raeburn 12898: } else {
1.86 raeburn 12899: if ($key =~ /^form\.quota_(.+)$/) {
12900: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 12901: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12902: $confhash{'authorquota'}{$1} = $env{$key};
12903: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12904: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12905: }
1.72 raeburn 12906: }
12907: }
1.163 raeburn 12908: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 12909: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12910: @approvalnotify = sort(@approvalnotify);
12911: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 12912: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 12913: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12914: foreach my $type (@hasuniquecode) {
12915: if (grep(/^\Q$type\E$/,@crstypes)) {
12916: $confhash{'uniquecode'}{$type} = 1;
12917: }
1.216 raeburn 12918: }
1.242 raeburn 12919: my (%newbook,%allpos);
1.216 raeburn 12920: if ($context eq 'requestcourses') {
1.242 raeburn 12921: foreach my $type ('textbooks','templates') {
12922: @{$allpos{$type}} = ();
12923: my $invalid;
12924: if ($type eq 'textbooks') {
12925: $invalid = &mt('Invalid LON-CAPA course for textbook');
12926: } else {
12927: $invalid = &mt('Invalid LON-CAPA course for template');
12928: }
12929: if ($env{'form.'.$type.'_addbook'}) {
12930: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12931: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12932: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12933: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12934: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12935: } else {
12936: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12937: my $position = $env{'form.'.$type.'_addbook_pos'};
12938: $position =~ s/\D+//g;
12939: if ($position ne '') {
12940: $allpos{$type}[$position] = $newbook{$type};
12941: }
1.216 raeburn 12942: }
1.242 raeburn 12943: } else {
12944: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 12945: }
12946: }
1.242 raeburn 12947: }
1.216 raeburn 12948: }
1.102 raeburn 12949: if (ref($domconfig{$action}) eq 'HASH') {
12950: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12951: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12952: $changes{'notify'}{'approval'} = 1;
12953: }
12954: } else {
1.144 raeburn 12955: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12956: $changes{'notify'}{'approval'} = 1;
12957: }
12958: }
1.218 raeburn 12959: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12960: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12961: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12962: unless ($confhash{'uniquecode'}{$crstype}) {
12963: $changes{'uniquecode'} = 1;
12964: }
12965: }
12966: unless ($changes{'uniquecode'}) {
12967: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12968: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12969: $changes{'uniquecode'} = 1;
12970: }
12971: }
12972: }
12973: } else {
12974: $changes{'uniquecode'} = 1;
12975: }
12976: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12977: $changes{'uniquecode'} = 1;
1.216 raeburn 12978: }
12979: if ($context eq 'requestcourses') {
1.242 raeburn 12980: foreach my $type ('textbooks','templates') {
12981: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12982: my %deletions;
12983: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12984: if (@todelete) {
12985: map { $deletions{$_} = 1; } @todelete;
12986: }
12987: my %imgdeletions;
12988: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12989: if (@todeleteimages) {
12990: map { $imgdeletions{$_} = 1; } @todeleteimages;
12991: }
12992: my $maxnum = $env{'form.'.$type.'_maxnum'};
12993: for (my $i=0; $i<=$maxnum; $i++) {
12994: my $itemid = $env{'form.'.$type.'_id_'.$i};
12995: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12996: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12997: if ($deletions{$key}) {
12998: if ($domconfig{$action}{$type}{$key}{'image'}) {
12999: #FIXME need to obsolete item in RES space
13000: }
13001: next;
13002: } else {
13003: my $newpos = $env{'form.'.$itemid};
13004: $newpos =~ s/\D+//g;
1.243 raeburn 13005: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13006: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13007: ($type eq 'templates'));
1.242 raeburn 13008: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13009: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13010: $changes{$type}{$key} = 1;
13011: }
13012: }
13013: $allpos{$type}[$newpos] = $key;
13014: }
13015: if ($imgdeletions{$key}) {
13016: $changes{$type}{$key} = 1;
1.216 raeburn 13017: #FIXME need to obsolete item in RES space
1.242 raeburn 13018: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13019: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13020: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13021: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13022: } else {
13023: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13024: $cdom,$cnum,$type,$configuserok,
13025: $switchserver,$author_ok);
13026: if ($imgurl) {
13027: $confhash{$type}{$key}{'image'} = $imgurl;
13028: $changes{$type}{$key} = 1;
13029: }
13030: if ($error) {
13031: &Apache::lonnet::logthis($error);
13032: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13033: }
13034: }
1.242 raeburn 13035: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13036: $confhash{$type}{$key}{'image'} =
13037: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13038: }
13039: }
13040: }
13041: }
13042: }
13043: }
1.102 raeburn 13044: } else {
1.144 raeburn 13045: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13046: $changes{'notify'}{'approval'} = 1;
13047: }
1.218 raeburn 13048: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13049: $changes{'uniquecode'} = 1;
13050: }
13051: }
13052: if ($context eq 'requestcourses') {
1.242 raeburn 13053: foreach my $type ('textbooks','templates') {
13054: if ($newbook{$type}) {
13055: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13056: foreach my $item ('subject','title','publisher','author') {
13057: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13058: ($type eq 'template'));
1.242 raeburn 13059: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13060: if ($env{'form.'.$type.'_addbook_'.$item}) {
13061: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13062: }
13063: }
13064: if ($type eq 'textbooks') {
13065: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13066: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13067: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13068: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13069: } else {
13070: my ($imageurl,$error) =
13071: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13072: $configuserok,$switchserver,$author_ok);
13073: if ($imageurl) {
13074: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13075: }
13076: if ($error) {
13077: &Apache::lonnet::logthis($error);
13078: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13079: }
1.242 raeburn 13080: }
13081: }
1.216 raeburn 13082: }
13083: }
1.242 raeburn 13084: if (@{$allpos{$type}} > 0) {
13085: my $idx = 0;
13086: foreach my $item (@{$allpos{$type}}) {
13087: if ($item ne '') {
13088: $confhash{$type}{$item}{'order'} = $idx;
13089: if (ref($domconfig{$action}) eq 'HASH') {
13090: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13091: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13092: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13093: $changes{$type}{$item} = 1;
13094: }
1.216 raeburn 13095: }
13096: }
13097: }
1.242 raeburn 13098: $idx ++;
1.216 raeburn 13099: }
13100: }
13101: }
13102: }
1.235 raeburn 13103: if (ref($validationitemsref) eq 'ARRAY') {
13104: foreach my $item (@{$validationitemsref}) {
13105: if ($item eq 'fields') {
13106: my @changed;
13107: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13108: if (@{$confhash{'validation'}{$item}} > 0) {
13109: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13110: }
1.266 raeburn 13111: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13112: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13113: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13114: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13115: $domconfig{'requestcourses'}{'validation'}{$item});
13116: } else {
13117: @changed = @{$confhash{'validation'}{$item}};
13118: }
1.235 raeburn 13119: } else {
13120: @changed = @{$confhash{'validation'}{$item}};
13121: }
13122: } else {
13123: @changed = @{$confhash{'validation'}{$item}};
13124: }
13125: if (@changed) {
13126: if ($confhash{'validation'}{$item}) {
13127: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13128: } else {
13129: $changes{'validation'}{$item} = &mt('None');
13130: }
13131: }
13132: } else {
13133: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13134: if ($item eq 'markup') {
13135: if ($env{'form.requestcourses_validation_'.$item}) {
13136: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13137: }
13138: }
1.266 raeburn 13139: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13140: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13141: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13142: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13143: }
13144: } else {
13145: if ($confhash{'validation'}{$item} ne '') {
13146: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13147: }
1.235 raeburn 13148: }
13149: } else {
13150: if ($confhash{'validation'}{$item} ne '') {
13151: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13152: }
13153: }
13154: }
13155: }
13156: }
13157: if ($env{'form.validationdc'}) {
13158: my $newval = $env{'form.validationdc'};
1.285 raeburn 13159: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13160: if (exists($domcoords{$newval})) {
13161: $confhash{'validation'}{'dc'} = $newval;
13162: }
13163: }
13164: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13165: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13166: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13167: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13168: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13169: if ($confhash{'validation'}{'dc'} eq '') {
13170: $changes{'validation'}{'dc'} = &mt('None');
13171: } else {
13172: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13173: }
1.235 raeburn 13174: }
1.266 raeburn 13175: } elsif ($confhash{'validation'}{'dc'} ne '') {
13176: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13177: }
13178: } elsif ($confhash{'validation'}{'dc'} ne '') {
13179: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13180: }
13181: } elsif ($confhash{'validation'}{'dc'} ne '') {
13182: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13183: }
1.266 raeburn 13184: } else {
13185: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13186: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13187: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13188: $changes{'validation'}{'dc'} = &mt('None');
13189: }
13190: }
1.235 raeburn 13191: }
13192: }
1.102 raeburn 13193: }
13194: } else {
1.86 raeburn 13195: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13196: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13197: }
1.72 raeburn 13198: foreach my $item (@usertools) {
13199: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13200: my $unset;
1.101 raeburn 13201: if ($context eq 'requestcourses') {
1.104 raeburn 13202: $unset = '0';
13203: if ($type eq '_LC_adv') {
13204: $unset = '';
13205: }
1.101 raeburn 13206: if ($confhash{$item}{$type} eq 'autolimit') {
13207: $confhash{$item}{$type} .= '=';
13208: unless ($limithash{$item}{$type} =~ /\D/) {
13209: $confhash{$item}{$type} .= $limithash{$item}{$type};
13210: }
13211: }
1.163 raeburn 13212: } elsif ($context eq 'requestauthor') {
13213: $unset = '0';
13214: if ($type eq '_LC_adv') {
13215: $unset = '';
13216: }
1.72 raeburn 13217: } else {
1.101 raeburn 13218: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13219: $confhash{$item}{$type} = 1;
13220: } else {
13221: $confhash{$item}{$type} = 0;
13222: }
1.72 raeburn 13223: }
1.86 raeburn 13224: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13225: if ($action eq 'requestauthor') {
13226: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13227: $changes{$type} = 1;
13228: }
13229: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13230: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13231: $changes{$item}{$type} = 1;
13232: }
13233: } else {
13234: if ($context eq 'requestcourses') {
1.104 raeburn 13235: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13236: $changes{$item}{$type} = 1;
13237: }
13238: } else {
13239: if (!$confhash{$item}{$type}) {
13240: $changes{$item}{$type} = 1;
13241: }
13242: }
13243: }
13244: } else {
13245: if ($context eq 'requestcourses') {
1.104 raeburn 13246: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13247: $changes{$item}{$type} = 1;
13248: }
1.163 raeburn 13249: } elsif ($context eq 'requestauthor') {
13250: if ($confhash{$type} ne $unset) {
13251: $changes{$type} = 1;
13252: }
1.72 raeburn 13253: } else {
13254: if (!$confhash{$item}{$type}) {
13255: $changes{$item}{$type} = 1;
13256: }
13257: }
13258: }
1.1 raeburn 13259: }
13260: }
1.163 raeburn 13261: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13262: if (ref($domconfig{'quotas'}) eq 'HASH') {
13263: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13264: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13265: if (exists($confhash{'defaultquota'}{$key})) {
13266: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13267: $changes{'defaultquota'}{$key} = 1;
13268: }
13269: } else {
13270: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13271: }
13272: }
1.86 raeburn 13273: } else {
13274: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13275: if (exists($confhash{'defaultquota'}{$key})) {
13276: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13277: $changes{'defaultquota'}{$key} = 1;
13278: }
13279: } else {
13280: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13281: }
1.1 raeburn 13282: }
13283: }
1.197 raeburn 13284: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13285: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13286: if (exists($confhash{'authorquota'}{$key})) {
13287: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13288: $changes{'authorquota'}{$key} = 1;
13289: }
13290: } else {
13291: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13292: }
13293: }
13294: }
1.1 raeburn 13295: }
1.86 raeburn 13296: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13297: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13298: if (ref($domconfig{'quotas'}) eq 'HASH') {
13299: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13300: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13301: $changes{'defaultquota'}{$key} = 1;
13302: }
13303: } else {
13304: if (!exists($domconfig{'quotas'}{$key})) {
13305: $changes{'defaultquota'}{$key} = 1;
13306: }
1.72 raeburn 13307: }
13308: } else {
1.86 raeburn 13309: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13310: }
1.1 raeburn 13311: }
13312: }
1.197 raeburn 13313: if (ref($confhash{'authorquota'}) eq 'HASH') {
13314: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13315: if (ref($domconfig{'quotas'}) eq 'HASH') {
13316: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13317: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13318: $changes{'authorquota'}{$key} = 1;
13319: }
13320: } else {
13321: $changes{'authorquota'}{$key} = 1;
13322: }
13323: } else {
13324: $changes{'authorquota'}{$key} = 1;
13325: }
13326: }
13327: }
1.1 raeburn 13328: }
1.72 raeburn 13329:
1.163 raeburn 13330: if ($context eq 'requestauthor') {
13331: $domdefaults{'requestauthor'} = \%confhash;
13332: } else {
13333: foreach my $key (keys(%confhash)) {
1.242 raeburn 13334: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13335: $domdefaults{$key} = $confhash{$key};
13336: }
1.163 raeburn 13337: }
1.72 raeburn 13338: }
1.163 raeburn 13339:
1.1 raeburn 13340: my %quotahash = (
1.86 raeburn 13341: $action => { %confhash }
1.1 raeburn 13342: );
13343: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13344: $dom);
13345: if ($putresult eq 'ok') {
13346: if (keys(%changes) > 0) {
1.72 raeburn 13347: my $cachetime = 24*60*60;
13348: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13349: if (ref($lastactref) eq 'HASH') {
13350: $lastactref->{'domdefaults'} = 1;
13351: }
1.1 raeburn 13352: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13353: unless (($context eq 'requestcourses') ||
1.163 raeburn 13354: ($context eq 'requestauthor')) {
1.86 raeburn 13355: if (ref($changes{'defaultquota'}) eq 'HASH') {
13356: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13357: foreach my $type (@{$types},'default') {
13358: if (defined($changes{'defaultquota'}{$type})) {
13359: my $typetitle = $usertypes->{$type};
13360: if ($type eq 'default') {
13361: $typetitle = $othertitle;
13362: }
1.213 raeburn 13363: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13364: }
13365: }
1.86 raeburn 13366: $resulttext .= '</ul></li>';
1.72 raeburn 13367: }
1.197 raeburn 13368: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13369: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13370: foreach my $type (@{$types},'default') {
13371: if (defined($changes{'authorquota'}{$type})) {
13372: my $typetitle = $usertypes->{$type};
13373: if ($type eq 'default') {
13374: $typetitle = $othertitle;
13375: }
1.213 raeburn 13376: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13377: }
13378: }
13379: $resulttext .= '</ul></li>';
13380: }
1.72 raeburn 13381: }
1.80 raeburn 13382: my %newenv;
1.72 raeburn 13383: foreach my $item (@usertools) {
1.163 raeburn 13384: my (%haschgs,%inconf);
13385: if ($context eq 'requestauthor') {
13386: %haschgs = %changes;
1.210 raeburn 13387: %inconf = %confhash;
1.163 raeburn 13388: } else {
13389: if (ref($changes{$item}) eq 'HASH') {
13390: %haschgs = %{$changes{$item}};
13391: }
13392: if (ref($confhash{$item}) eq 'HASH') {
13393: %inconf = %{$confhash{$item}};
13394: }
13395: }
13396: if (keys(%haschgs) > 0) {
1.80 raeburn 13397: my $newacc =
13398: &Apache::lonnet::usertools_access($env{'user.name'},
13399: $env{'user.domain'},
1.86 raeburn 13400: $item,'reload',$context);
1.210 raeburn 13401: if (($context eq 'requestcourses') ||
1.163 raeburn 13402: ($context eq 'requestauthor')) {
1.108 raeburn 13403: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13404: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13405: }
13406: } else {
13407: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13408: $newenv{'environment.availabletools.'.$item} = $newacc;
13409: }
1.80 raeburn 13410: }
1.163 raeburn 13411: unless ($context eq 'requestauthor') {
13412: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13413: }
1.72 raeburn 13414: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 13415: if ($haschgs{$type}) {
1.72 raeburn 13416: my $typetitle = $usertypes->{$type};
13417: if ($type eq 'default') {
13418: $typetitle = $othertitle;
13419: } elsif ($type eq '_LC_adv') {
13420: $typetitle = 'LON-CAPA Advanced Users';
13421: }
1.163 raeburn 13422: if ($inconf{$type}) {
1.101 raeburn 13423: if ($context eq 'requestcourses') {
13424: my $cond;
1.163 raeburn 13425: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13426: if ($1 eq '') {
13427: $cond = &mt('(Automatic processing of any request).');
13428: } else {
13429: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13430: }
13431: } else {
1.163 raeburn 13432: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13433: }
13434: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 13435: } elsif ($context eq 'requestauthor') {
13436: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13437: $titles{$inconf{$type}},$typetitle);
13438:
1.101 raeburn 13439: } else {
13440: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13441: }
1.72 raeburn 13442: } else {
1.104 raeburn 13443: if ($type eq '_LC_adv') {
1.163 raeburn 13444: if ($inconf{$type} eq '0') {
1.104 raeburn 13445: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13446: } else {
13447: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13448: }
13449: } else {
13450: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13451: }
1.72 raeburn 13452: }
13453: }
1.26 raeburn 13454: }
1.163 raeburn 13455: unless ($context eq 'requestauthor') {
13456: $resulttext .= '</ul></li>';
13457: }
1.26 raeburn 13458: }
1.1 raeburn 13459: }
1.163 raeburn 13460: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13461: if (ref($changes{'notify'}) eq 'HASH') {
13462: if ($changes{'notify'}{'approval'}) {
13463: if (ref($confhash{'notify'}) eq 'HASH') {
13464: if ($confhash{'notify'}{'approval'}) {
13465: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13466: } else {
1.163 raeburn 13467: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13468: }
13469: }
13470: }
13471: }
13472: }
1.216 raeburn 13473: if ($action eq 'requestcourses') {
13474: my @offon = ('off','on');
13475: if ($changes{'uniquecode'}) {
1.218 raeburn 13476: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13477: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13478: $resulttext .= '<li>'.
13479: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13480: '</li>';
13481: } else {
13482: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13483: '</li>';
13484: }
1.216 raeburn 13485: }
1.242 raeburn 13486: foreach my $type ('textbooks','templates') {
13487: if (ref($changes{$type}) eq 'HASH') {
13488: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13489: foreach my $key (sort(keys(%{$changes{$type}}))) {
13490: my %coursehash = &Apache::lonnet::coursedescription($key);
13491: my $coursetitle = $coursehash{'description'};
13492: my $position = $confhash{$type}{$key}{'order'} + 1;
13493: $resulttext .= '<li>';
1.243 raeburn 13494: foreach my $item ('subject','title','publisher','author') {
13495: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13496: ($type eq 'templates'));
1.242 raeburn 13497: my $name = $item.':';
13498: $name =~ s/^(\w)/\U$1/;
13499: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13500: }
13501: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13502: if ($type eq 'textbooks') {
13503: if ($confhash{$type}{$key}{'image'}) {
13504: $resulttext .= ' '.&mt('Image: [_1]',
13505: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13506: ' alt="Textbook cover" />').'<br />';
13507: }
13508: }
13509: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 13510: }
1.242 raeburn 13511: $resulttext .= '</ul></li>';
1.216 raeburn 13512: }
13513: }
1.235 raeburn 13514: if (ref($changes{'validation'}) eq 'HASH') {
13515: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13516: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13517: foreach my $item (@{$validationitemsref}) {
13518: if (exists($changes{'validation'}{$item})) {
13519: if ($item eq 'markup') {
13520: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13521: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13522: } else {
13523: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13524: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13525: }
13526: }
13527: }
13528: if (exists($changes{'validation'}{'dc'})) {
13529: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13530: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13531: }
13532: }
13533: }
1.216 raeburn 13534: }
1.1 raeburn 13535: $resulttext .= '</ul>';
1.80 raeburn 13536: if (keys(%newenv)) {
13537: &Apache::lonnet::appenv(\%newenv);
13538: }
1.1 raeburn 13539: } else {
1.86 raeburn 13540: if ($context eq 'requestcourses') {
13541: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 13542: } elsif ($context eq 'requestauthor') {
13543: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13544: } else {
1.90 weissno 13545: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13546: }
1.1 raeburn 13547: }
13548: } else {
1.11 albertel 13549: $resulttext = '<span class="LC_error">'.
13550: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13551: }
1.216 raeburn 13552: if ($errors) {
13553: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13554: '<ul>'.$errors.'</ul></p>';
13555: }
1.3 raeburn 13556: return $resulttext;
1.1 raeburn 13557: }
13558:
1.216 raeburn 13559: sub process_textbook_image {
1.242 raeburn 13560: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 13561: my $filename = $env{'form.'.$caller.'.filename'};
13562: my ($error,$url);
13563: my ($width,$height) = (50,50);
13564: if ($configuserok eq 'ok') {
13565: if ($switchserver) {
13566: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13567: $switchserver);
13568: } elsif ($author_ok eq 'ok') {
13569: my ($result,$imageurl) =
13570: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 13571: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 13572: if ($result eq 'ok') {
13573: $url = $imageurl;
13574: } else {
13575: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13576: }
13577: } else {
13578: $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);
13579: }
13580: } else {
13581: $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);
13582: }
13583: return ($url,$error);
13584: }
13585:
1.267 raeburn 13586: sub modify_ltitools {
13587: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13588: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 13589: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 13590: my $confname = $dom.'-domainconfig';
13591: my $servadm = $r->dir_config('lonAdmEMail');
13592: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
13593: my (%posslti,%possfield);
13594: my @courseroles = ('cc','in','ta','ep','st');
13595: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
13596: map { $posslti{$_} = 1; } @ltiroles;
13597: my @allfields = ('fullname','firstname','lastname','email','user','roles');
13598: map { $possfield{$_} = 1; } @allfields;
13599: my %lt = <itools_names();
13600: if ($env{'form.ltitools_add'}) {
13601: my $title = $env{'form.ltitools_add_title'};
13602: $title =~ s/(`)/'/g;
13603: ($newid,my $error) = &get_ltitools_id($dom,$title);
13604: if ($newid) {
13605: my $position = $env{'form.ltitools_add_pos'};
13606: $position =~ s/\D+//g;
13607: if ($position ne '') {
13608: $allpos[$position] = $newid;
13609: }
13610: $changes{$newid} = 1;
1.322 raeburn 13611: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 13612: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 13613: if ($item eq 'lifetime') {
13614: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
13615: }
1.267 raeburn 13616: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 13617: if (($item eq 'key') || ($item eq 'secret')) {
13618: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13619: } else {
13620: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
13621: }
1.267 raeburn 13622: }
13623: }
13624: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
13625: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
13626: }
13627: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
13628: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
13629: }
1.323 raeburn 13630: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
13631: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
13632: } else {
13633: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
13634: }
1.296 raeburn 13635: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 13636: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
13637: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 13638: if (($item eq 'width') || ($item eq 'height')) {
13639: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
13640: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13641: }
13642: } else {
13643: if ($env{'form.ltitools_add_'.$item} ne '') {
13644: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
13645: }
1.267 raeburn 13646: }
13647: }
13648: if ($env{'form.ltitools_add_target'} eq 'window') {
13649: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 13650: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
13651: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 13652: } else {
13653: $confhash{$newid}{'display'}{'target'} = 'iframe';
13654: }
13655: foreach my $item ('passback','roster') {
1.319 raeburn 13656: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 13657: $confhash{$newid}{$item} = 1;
1.319 raeburn 13658: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
13659: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
13660: $lifetime =~ s/^\s+|\s+$//g;
13661: if ($lifetime =~ /^\d+\.?\d*$/) {
13662: $confhash{$newid}{$item.'valid'} = $lifetime;
13663: }
13664: }
1.267 raeburn 13665: }
13666: }
13667: if ($env{'form.ltitools_add_image.filename'} ne '') {
13668: my ($imageurl,$error) =
1.307 raeburn 13669: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 13670: $configuserok,$switchserver,$author_ok);
13671: if ($imageurl) {
13672: $confhash{$newid}{'image'} = $imageurl;
13673: }
13674: if ($error) {
13675: &Apache::lonnet::logthis($error);
13676: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13677: }
13678: }
13679: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
13680: foreach my $field (@fields) {
13681: if ($possfield{$field}) {
13682: if ($field eq 'roles') {
13683: foreach my $role (@courseroles) {
13684: my $choice = $env{'form.ltitools_add_roles_'.$role};
13685: if (($choice ne '') && ($posslti{$choice})) {
13686: $confhash{$newid}{'roles'}{$role} = $choice;
13687: if ($role eq 'cc') {
13688: $confhash{$newid}{'roles'}{'co'} = $choice;
13689: }
13690: }
13691: }
13692: } else {
13693: $confhash{$newid}{'fields'}{$field} = 1;
13694: }
13695: }
13696: }
1.324 raeburn 13697: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
13698: if ($confhash{$newid}{'fields'}{'user'}) {
13699: if ($env{'form.ltitools_userincdom_add'}) {
13700: $confhash{$newid}{'incdom'} = 1;
13701: }
13702: }
13703: }
1.273 raeburn 13704: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
13705: foreach my $item (@courseconfig) {
13706: $confhash{$newid}{'crsconf'}{$item} = 1;
13707: }
1.267 raeburn 13708: if ($env{'form.ltitools_add_custom'}) {
13709: my $name = $env{'form.ltitools_add_custom_name'};
13710: my $value = $env{'form.ltitools_add_custom_value'};
13711: $value =~ s/(`)/'/g;
13712: $name =~ s/(`)/'/g;
13713: $confhash{$newid}{'custom'}{$name} = $value;
13714: }
13715: } else {
13716: my $error = &mt('Failed to acquire unique ID for new external tool');
13717: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13718: }
13719: }
13720: if (ref($domconfig{$action}) eq 'HASH') {
13721: my %deletions;
13722: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
13723: if (@todelete) {
13724: map { $deletions{$_} = 1; } @todelete;
13725: }
13726: my %customadds;
13727: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
13728: if (@newcustom) {
13729: map { $customadds{$_} = 1; } @newcustom;
13730: }
13731: my %imgdeletions;
13732: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
13733: if (@todeleteimages) {
13734: map { $imgdeletions{$_} = 1; } @todeleteimages;
13735: }
13736: my $maxnum = $env{'form.ltitools_maxnum'};
13737: for (my $i=0; $i<=$maxnum; $i++) {
13738: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 13739: $itemid =~ s/\D+//g;
1.267 raeburn 13740: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13741: if ($deletions{$itemid}) {
13742: if ($domconfig{$action}{$itemid}{'image'}) {
13743: #FIXME need to obsolete item in RES space
13744: }
13745: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
13746: next;
13747: } else {
13748: my $newpos = $env{'form.ltitools_'.$itemid};
13749: $newpos =~ s/\D+//g;
1.322 raeburn 13750: foreach my $item ('title','url','lifetime') {
1.267 raeburn 13751: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13752: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
13753: $changes{$itemid} = 1;
13754: }
13755: }
1.297 raeburn 13756: foreach my $item ('key','secret') {
13757: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13758: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
13759: $changes{$itemid} = 1;
13760: }
13761: }
1.267 raeburn 13762: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
13763: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
13764: }
13765: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
13766: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
13767: }
1.323 raeburn 13768: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
13769: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
13770: } else {
13771: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
13772: }
13773: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
13774: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
13775: $changes{$itemid} = 1;
13776: }
13777: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
13778: $changes{$itemid} = 1;
13779: }
1.267 raeburn 13780: foreach my $size ('width','height') {
13781: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
13782: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
13783: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
13784: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
13785: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13786: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
13787: $changes{$itemid} = 1;
13788: }
13789: } else {
13790: $changes{$itemid} = 1;
13791: }
1.296 raeburn 13792: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13793: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
13794: $changes{$itemid} = 1;
13795: }
13796: }
13797: }
13798: foreach my $item ('linktext','explanation') {
13799: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
13800: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
13801: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
13802: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
13803: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13804: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
13805: $changes{$itemid} = 1;
13806: }
13807: } else {
13808: $changes{$itemid} = 1;
13809: }
13810: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13811: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
13812: $changes{$itemid} = 1;
13813: }
1.267 raeburn 13814: }
13815: }
13816: if ($env{'form.ltitools_target_'.$i} eq 'window') {
13817: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 13818: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
13819: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 13820: } else {
13821: $confhash{$itemid}{'display'}{'target'} = 'iframe';
13822: }
13823: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
13824: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
13825: $changes{$itemid} = 1;
13826: }
13827: } else {
13828: $changes{$itemid} = 1;
13829: }
13830: foreach my $extra ('passback','roster') {
13831: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
13832: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 13833: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 13834: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 13835: $lifetime =~ s/^\s+|\s+$//g;
13836: if ($lifetime =~ /^\d+\.?\d*$/) {
13837: $confhash{$itemid}{$extra.'valid'} = $lifetime;
13838: }
13839: }
1.267 raeburn 13840: }
13841: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
13842: $changes{$itemid} = 1;
13843: }
1.319 raeburn 13844: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
13845: $changes{$itemid} = 1;
13846: }
1.267 raeburn 13847: }
1.273 raeburn 13848: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 13849: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 13850: if (grep(/^\Q$item\E$/,@courseconfig)) {
13851: $confhash{$itemid}{'crsconf'}{$item} = 1;
13852: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
13853: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
13854: $changes{$itemid} = 1;
13855: }
13856: } else {
13857: $changes{$itemid} = 1;
13858: }
13859: }
13860: }
1.267 raeburn 13861: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
13862: foreach my $field (@fields) {
13863: if ($possfield{$field}) {
13864: if ($field eq 'roles') {
13865: foreach my $role (@courseroles) {
13866: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
13867: if (($choice ne '') && ($posslti{$choice})) {
13868: $confhash{$itemid}{'roles'}{$role} = $choice;
13869: if ($role eq 'cc') {
13870: $confhash{$itemid}{'roles'}{'co'} = $choice;
13871: }
13872: }
13873: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
13874: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
13875: $changes{$itemid} = 1;
13876: }
13877: } elsif ($confhash{$itemid}{'roles'}{$role}) {
13878: $changes{$itemid} = 1;
13879: }
13880: }
13881: } else {
13882: $confhash{$itemid}{'fields'}{$field} = 1;
13883: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
13884: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
13885: $changes{$itemid} = 1;
13886: }
13887: } else {
13888: $changes{$itemid} = 1;
13889: }
13890: }
13891: }
13892: }
1.324 raeburn 13893: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
13894: if ($confhash{$itemid}{'fields'}{'user'}) {
13895: if ($env{'form.ltitools_userincdom_'.$i}) {
13896: $confhash{$itemid}{'incdom'} = 1;
13897: }
13898: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
13899: $changes{$itemid} = 1;
13900: }
13901: }
13902: }
1.267 raeburn 13903: $allpos[$newpos] = $itemid;
13904: }
13905: if ($imgdeletions{$itemid}) {
13906: $changes{$itemid} = 1;
13907: #FIXME need to obsolete item in RES space
13908: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
13909: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
13910: $itemid,$configuserok,$switchserver,
13911: $author_ok);
13912: if ($imgurl) {
13913: $confhash{$itemid}{'image'} = $imgurl;
13914: $changes{$itemid} = 1;
13915: }
13916: if ($error) {
13917: &Apache::lonnet::logthis($error);
13918: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13919: }
13920: } elsif ($domconfig{$action}{$itemid}{'image'}) {
13921: $confhash{$itemid}{'image'} =
13922: $domconfig{$action}{$itemid}{'image'};
13923: }
13924: if ($customadds{$i}) {
13925: my $name = $env{'form.ltitools_custom_name_'.$i};
13926: $name =~ s/(`)/'/g;
13927: $name =~ s/^\s+//;
13928: $name =~ s/\s+$//;
13929: my $value = $env{'form.ltitools_custom_value_'.$i};
13930: $value =~ s/(`)/'/g;
13931: $value =~ s/^\s+//;
13932: $value =~ s/\s+$//;
13933: if ($name ne '') {
13934: $confhash{$itemid}{'custom'}{$name} = $value;
13935: $changes{$itemid} = 1;
13936: }
13937: }
13938: my %customdels;
13939: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
13940: if (@customdeletions) {
13941: $changes{$itemid} = 1;
13942: }
13943: map { $customdels{$_} = 1; } @customdeletions;
13944: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
13945: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
13946: unless ($customdels{$key}) {
13947: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
13948: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
13949: }
13950: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
13951: $changes{$itemid} = 1;
13952: }
13953: }
13954: }
13955: }
13956: unless ($changes{$itemid}) {
13957: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
13958: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
13959: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13960: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
13961: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13962: $changes{$itemid} = 1;
13963: last;
13964: }
13965: }
13966: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
13967: $changes{$itemid} = 1;
13968: }
13969: }
13970: last if ($changes{$itemid});
13971: }
13972: }
13973: }
13974: }
13975: }
13976: if (@allpos > 0) {
13977: my $idx = 0;
13978: foreach my $itemid (@allpos) {
13979: if ($itemid ne '') {
13980: $confhash{$itemid}{'order'} = $idx;
13981: if (ref($domconfig{$action}) eq 'HASH') {
13982: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13983: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13984: $changes{$itemid} = 1;
13985: }
13986: }
13987: }
13988: $idx ++;
13989: }
13990: }
13991: }
13992: my %ltitoolshash = (
13993: $action => { %confhash }
13994: );
13995: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
13996: $dom);
13997: if ($putresult eq 'ok') {
1.297 raeburn 13998: my %ltienchash = (
13999: $action => { %encconfig }
14000: );
1.384 raeburn 14001: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 14002: if (keys(%changes) > 0) {
14003: my $cachetime = 24*60*60;
1.297 raeburn 14004: my %ltiall = %confhash;
14005: foreach my $id (keys(%ltiall)) {
14006: if (ref($encconfig{$id}) eq 'HASH') {
14007: foreach my $item ('key','secret') {
14008: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14009: }
14010: }
14011: }
14012: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 14013: if (ref($lastactref) eq 'HASH') {
14014: $lastactref->{'ltitools'} = 1;
14015: }
14016: $resulttext = &mt('Changes made:').'<ul>';
14017: my %bynum;
14018: foreach my $itemid (sort(keys(%changes))) {
14019: my $position = $confhash{$itemid}{'order'};
14020: $bynum{$position} = $itemid;
14021: }
14022: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14023: my $itemid = $bynum{$pos};
14024: if (ref($confhash{$itemid}) ne 'HASH') {
14025: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14026: } else {
14027: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
14028: if ($confhash{$itemid}{'image'}) {
14029: $resulttext .= ' '.
14030: '<img src="'.$confhash{$itemid}{'image'}.'"'.
14031: ' alt="'.&mt('Tool Provider icon').'" />';
14032: }
14033: $resulttext .= '</li><ul>';
14034: my $position = $pos + 1;
14035: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 14036: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 14037: if ($confhash{$itemid}{$item} ne '') {
14038: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14039: }
14040: }
1.297 raeburn 14041: if ($encconfig{$itemid}{'key'} ne '') {
14042: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14043: }
14044: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 14045: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 14046: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 14047: $resulttext .= ('*'x$num).'</li>';
14048: }
1.273 raeburn 14049: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 14050: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 14051: my $numconfig = 0;
14052: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
14053: foreach my $item (@possconfig) {
14054: if ($confhash{$itemid}{'crsconf'}{$item}) {
14055: $numconfig ++;
1.296 raeburn 14056: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 14057: }
14058: }
14059: }
14060: if (!$numconfig) {
1.372 raeburn 14061: $resulttext .= ' '.&mt('None');
1.273 raeburn 14062: }
14063: $resulttext .= '</li>';
1.267 raeburn 14064: foreach my $item ('passback','roster') {
14065: $resulttext .= '<li>'.$lt{$item}.' ';
14066: if ($confhash{$itemid}{$item}) {
14067: $resulttext .= &mt('Yes');
1.319 raeburn 14068: if ($confhash{$itemid}{$item.'valid'}) {
14069: if ($item eq 'passback') {
14070: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
14071: $confhash{$itemid}{$item.'valid'});
14072: } else {
14073: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
14074: $confhash{$itemid}{$item.'valid'});
14075: }
14076: }
1.267 raeburn 14077: } else {
14078: $resulttext .= &mt('No');
14079: }
14080: $resulttext .= '</li>';
14081: }
14082: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
14083: my $displaylist;
14084: if ($confhash{$itemid}{'display'}{'target'}) {
14085: $displaylist = &mt('Display target').': '.
14086: $confhash{$itemid}{'display'}{'target'}.',';
14087: }
14088: foreach my $size ('width','height') {
14089: if ($confhash{$itemid}{'display'}{$size}) {
14090: $displaylist .= (' 'x2).$lt{$size}.': '.
14091: $confhash{$itemid}{'display'}{$size}.',';
14092: }
14093: }
14094: if ($displaylist) {
14095: $displaylist =~ s/,$//;
14096: $resulttext .= '<li>'.$displaylist.'</li>';
14097: }
1.296 raeburn 14098: foreach my $item ('linktext','explanation') {
14099: if ($confhash{$itemid}{'display'}{$item}) {
14100: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
14101: }
14102: }
14103: }
1.267 raeburn 14104: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14105: my $fieldlist;
14106: foreach my $field (@allfields) {
14107: if ($confhash{$itemid}{'fields'}{$field}) {
14108: $fieldlist .= (' 'x2).$lt{$field}.',';
14109: }
14110: }
14111: if ($fieldlist) {
14112: $fieldlist =~ s/,$//;
1.324 raeburn 14113: if ($confhash{$itemid}{'fields'}{'user'}) {
14114: if ($confhash{$itemid}{'incdom'}) {
14115: $fieldlist .= ' ('.&mt('username:domain').')';
14116: } else {
14117: $fieldlist .= ' ('.&mt('username').')';
14118: }
14119: }
1.267 raeburn 14120: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
14121: }
14122: }
14123: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
14124: my $rolemaps;
14125: foreach my $role (@courseroles) {
14126: if ($confhash{$itemid}{'roles'}{$role}) {
14127: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14128: $confhash{$itemid}{'roles'}{$role}.',';
14129: }
14130: }
14131: if ($rolemaps) {
14132: $rolemaps =~ s/,$//;
14133: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14134: }
14135: }
14136: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
14137: my $customlist;
14138: if (keys(%{$confhash{$itemid}{'custom'}})) {
14139: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
14140: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
14141: }
14142: }
14143: if ($customlist) {
1.317 raeburn 14144: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 14145: }
14146: }
14147: $resulttext .= '</ul></li>';
14148: }
14149: }
14150: $resulttext .= '</ul>';
14151: } else {
14152: $resulttext = &mt('No changes made.');
14153: }
14154: } else {
14155: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14156: }
14157: if ($errors) {
14158: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14159: $errors.'</ul>';
14160: }
14161: return $resulttext;
14162: }
14163:
14164: sub process_ltitools_image {
14165: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
14166: my $filename = $env{'form.'.$caller.'.filename'};
14167: my ($error,$url);
14168: my ($width,$height) = (21,21);
14169: if ($configuserok eq 'ok') {
14170: if ($switchserver) {
14171: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
14172: $switchserver);
14173: } elsif ($author_ok eq 'ok') {
14174: my ($result,$imageurl,$madethumb) =
14175: &publishlogo($r,'upload',$caller,$dom,$confname,
14176: "ltitools/$itemid/icon",$width,$height);
14177: if ($result eq 'ok') {
14178: if ($madethumb) {
14179: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14180: my $imagethumb = "$path/tn-".$imagefile;
14181: $url = $imagethumb;
14182: } else {
14183: $url = $imageurl;
14184: }
14185: } else {
14186: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14187: }
14188: } else {
14189: $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);
14190: }
14191: } else {
14192: $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);
14193: }
14194: return ($url,$error);
14195: }
14196:
14197: sub get_ltitools_id {
14198: my ($cdom,$title) = @_;
14199: # get lock on ltitools db
14200: my $lockhash = {
14201: lock => $env{'user.name'}.
14202: ':'.$env{'user.domain'},
14203: };
14204: my $tries = 0;
14205: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14206: my ($id,$error);
14207:
14208: while (($gotlock ne 'ok') && ($tries<10)) {
14209: $tries ++;
14210: sleep (0.1);
14211: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14212: }
14213: if ($gotlock eq 'ok') {
14214: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
14215: if ($currids{'lock'}) {
14216: delete($currids{'lock'});
14217: if (keys(%currids)) {
14218: my @curr = sort { $a <=> $b } keys(%currids);
14219: if ($curr[-1] =~ /^\d+$/) {
14220: $id = 1 + $curr[-1];
14221: }
14222: } else {
14223: $id = 1;
14224: }
14225: if ($id) {
14226: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
14227: $error = 'nostore';
14228: }
14229: } else {
14230: $error = 'nonumber';
14231: }
14232: }
14233: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
14234: } else {
14235: $error = 'nolock';
14236: }
14237: return ($id,$error);
14238: }
14239:
1.372 raeburn 14240: sub modify_proctoring {
14241: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14242: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14243: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14244: my $confname = $dom.'-domainconfig';
14245: my $servadm = $r->dir_config('lonAdmEMail');
14246: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14247: my %providernames = &proctoring_providernames();
14248: my $maxnum = scalar(keys(%providernames));
14249:
14250: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14251: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14252: if (ref($requref) eq 'HASH') {
14253: %requserfields = %{$requref};
14254: }
14255: if (ref($opturef) eq 'HASH') {
14256: %optuserfields = %{$opturef};
14257: }
14258: if (ref($defref) eq 'HASH') {
14259: %defaults = %{$defref};
14260: }
14261: if (ref($extref) eq 'HASH') {
14262: %extended = %{$extref};
14263: }
14264: if (ref($crsref) eq 'HASH') {
14265: %crsconf = %{$crsref};
14266: }
14267: if (ref($rolesref) eq 'ARRAY') {
14268: @courseroles = @{$rolesref};
14269: }
14270: if (ref($ltiref) eq 'ARRAY') {
14271: @ltiroles = @{$ltiref};
14272: }
14273:
14274: if (ref($domconfig{$action}) eq 'HASH') {
14275: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14276: if (@todeleteimages) {
14277: map { $imgdeletions{$_} = 1; } @todeleteimages;
14278: }
14279: }
14280: my %customadds;
14281: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14282: if (@newcustom) {
14283: map { $customadds{$_} = 1; } @newcustom;
14284: }
14285: foreach my $provider (sort(keys(%providernames))) {
14286: $confhash{$provider} = {};
14287: my $pos = $env{'form.proctoring_pos_'.$provider};
14288: $pos =~ s/\D+//g;
14289: $allpos[$pos] = $provider;
14290: my (%current,%currentenc);
14291: my $showroles = 0;
14292: if (ref($domconfig{$action}) eq 'HASH') {
14293: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14294: %current = %{$domconfig{$action}{$provider}};
14295: foreach my $item ('key','secret') {
14296: $currentenc{$item} = $current{$item};
14297: delete($current{$item});
14298: }
14299: }
14300: }
14301: if ($env{'form.proctoring_available_'.$provider}) {
14302: $confhash{$provider}{'available'} = 1;
14303: unless ($current{'available'}) {
14304: $changes{$provider} = 1;
14305: }
14306: } else {
14307: %{$confhash{$provider}} = %current;
14308: %{$encconfhash{$provider}} = %currentenc;
14309: $confhash{$provider}{'available'} = 0;
14310: if ($current{'available'}) {
14311: $changes{$provider} = 1;
14312: }
14313: }
14314: if ($confhash{$provider}{'available'}) {
14315: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14316: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14317: if ($field eq 'lifetime') {
14318: if ($possval =~ /^\d+$/) {
14319: $confhash{$provider}{$field} = $possval;
14320: }
14321: } elsif ($field eq 'version') {
14322: if ($possval =~ /^\d+\.\d+$/) {
14323: $confhash{$provider}{$field} = $possval;
14324: }
14325: } elsif ($field eq 'sigmethod') {
14326: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14327: $confhash{$provider}{$field} = $possval;
14328: }
14329: } elsif ($field eq 'url') {
14330: $confhash{$provider}{$field} = $possval;
14331: } elsif (($field eq 'key') || ($field eq 'secret')) {
14332: $encconfhash{$provider}{$field} = $possval;
14333: unless ($currentenc{$field} eq $possval) {
14334: $changes{$provider} = 1;
14335: }
14336: }
14337: unless (($field eq 'key') || ($field eq 'secret')) {
14338: unless ($current{$field} eq $confhash{$provider}{$field}) {
14339: $changes{$provider} = 1;
14340: }
14341: }
14342: }
14343: if ($imgdeletions{$provider}) {
14344: $changes{$provider} = 1;
14345: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14346: my ($imageurl,$error) =
14347: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14348: $configuserok,$switchserver,$author_ok);
14349: if ($imageurl) {
14350: $confhash{$provider}{'image'} = $imageurl;
14351: $changes{$provider} = 1;
14352: }
14353: if ($error) {
14354: &Apache::lonnet::logthis($error);
14355: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14356: }
14357: } elsif (exists($current{'image'})) {
14358: $confhash{$provider}{'image'} = $current{'image'};
14359: }
14360: if (ref($requserfields{$provider}) eq 'ARRAY') {
14361: if (@{$requserfields{$provider}} > 0) {
14362: if (grep(/^user$/,@{$requserfields{$provider}})) {
14363: if ($env{'form.proctoring_userincdom_'.$provider}) {
14364: $confhash{$provider}{'incdom'} = 1;
14365: }
14366: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14367: $changes{$provider} = 1;
14368: }
14369: }
14370: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14371: $showroles = 1;
14372: }
14373: }
14374: }
14375: $confhash{$provider}{'fields'} = [];
14376: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14377: if (@{$optuserfields{$provider}} > 0) {
14378: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14379: foreach my $field (@{$optuserfields{$provider}}) {
14380: if (grep(/^\Q$field\E$/,@optfields)) {
14381: push(@{$confhash{$provider}{'fields'}},$field);
14382: }
14383: }
14384: }
14385: if (ref($current{'fields'}) eq 'ARRAY') {
14386: unless ($changes{$provider}) {
14387: my @new = sort(@{$confhash{$provider}{'fields'}});
14388: my @old = sort(@{$current{'fields'}});
14389: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14390: if (@diffs) {
14391: $changes{$provider} = 1;
14392: }
14393: }
14394: } elsif (@{$confhash{$provider}{'fields'}}) {
14395: $changes{$provider} = 1;
14396: }
14397: }
14398: if (ref($defaults{$provider}) eq 'ARRAY') {
14399: if (@{$defaults{$provider}} > 0) {
14400: my %options;
14401: if (ref($extended{$provider}) eq 'HASH') {
14402: %options = %{$extended{$provider}};
14403: }
14404: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14405: foreach my $field (@{$defaults{$provider}}) {
14406: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14407: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14408: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14409: push(@{$confhash{$provider}{'defaults'}},$poss);
14410: }
14411: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14412: foreach my $inner (keys(%{$options{$field}})) {
14413: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14414: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14415: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14416: $confhash{$provider}{'defaults'}{$inner} = $poss;
14417: }
14418: } else {
14419: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14420: }
14421: }
14422: } else {
14423: if (grep(/^\Q$field\E$/,@checked)) {
14424: push(@{$confhash{$provider}{'defaults'}},$field);
14425: }
14426: }
14427: }
14428: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14429: if (ref($current{'defaults'}) eq 'ARRAY') {
14430: unless ($changes{$provider}) {
14431: my @new = sort(@{$confhash{$provider}{'defaults'}});
14432: my @old = sort(@{$current{'defaults'}});
14433: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14434: if (@diffs) {
14435: $changes{$provider} = 1;
14436: }
14437: }
14438: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14439: if (@{$current{'defaults'}}) {
14440: $changes{$provider} = 1;
14441: }
14442: }
14443: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14444: if (ref($current{'defaults'}) eq 'HASH') {
14445: unless ($changes{$provider}) {
14446: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14447: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14448: $changes{$provider} = 1;
14449: last;
14450: }
14451: }
14452: }
14453: unless ($changes{$provider}) {
14454: foreach my $key (keys(%{$current{'defaults'}})) {
14455: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14456: $changes{$provider} = 1;
14457: last;
14458: }
14459: }
14460: }
14461: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14462: $changes{$provider} = 1;
14463: }
14464: }
14465: }
14466: }
14467: if (ref($crsconf{$provider}) eq 'ARRAY') {
14468: if (@{$crsconf{$provider}} > 0) {
14469: $confhash{$provider}{'crsconf'} = [];
14470: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14471: foreach my $crsfield (@{$crsconf{$provider}}) {
14472: if (grep(/^\Q$crsfield\E$/,@checked)) {
14473: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14474: }
14475: }
14476: if (ref($current{'crsconf'}) eq 'ARRAY') {
14477: unless ($changes{$provider}) {
14478: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14479: my @old = sort(@{$current{'crsconf'}});
14480: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14481: if (@diffs) {
14482: $changes{$provider} = 1;
14483: }
14484: }
14485: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14486: $changes{$provider} = 1;
14487: }
14488: }
14489: }
14490: if ($showroles) {
14491: $confhash{$provider}{'roles'} = {};
14492: foreach my $role (@courseroles) {
14493: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14494: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14495: $confhash{$provider}{'roles'}{$role} = $poss;
14496: }
14497: }
14498: unless ($changes{$provider}) {
14499: if (ref($current{'roles'}) eq 'HASH') {
14500: foreach my $role (keys(%{$current{'roles'}})) {
14501: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14502: $changes{$provider} = 1;
14503: last
14504: }
14505: }
14506: unless ($changes{$provider}) {
14507: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14508: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14509: $changes{$provider} = 1;
14510: last;
14511: }
14512: }
14513: }
14514: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14515: $changes{$provider} = 1;
14516: }
14517: }
14518: }
14519: if (ref($current{'custom'}) eq 'HASH') {
14520: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14521: foreach my $key (keys(%{$current{'custom'}})) {
14522: if (grep(/^\Q$key\E$/,@customdels)) {
14523: $changes{$provider} = 1;
14524: } else {
14525: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14526: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14527: $changes{$provider} = 1;
14528: }
14529: }
14530: }
14531: }
14532: if ($customadds{$provider}) {
14533: my $name = $env{'form.proctoring_custom_name_'.$provider};
14534: $name =~ s/(`)/'/g;
14535: $name =~ s/^\s+//;
14536: $name =~ s/\s+$//;
14537: my $value = $env{'form.proctoring_custom_value_'.$provider};
14538: $value =~ s/(`)/'/g;
14539: $value =~ s/^\s+//;
14540: $value =~ s/\s+$//;
14541: if ($name ne '') {
14542: $confhash{$provider}{'custom'}{$name} = $value;
14543: $changes{$provider} = 1;
14544: }
14545: }
14546: }
14547: }
14548: if (@allpos > 0) {
14549: my $idx = 0;
14550: foreach my $provider (@allpos) {
14551: if ($provider ne '') {
14552: $confhash{$provider}{'order'} = $idx;
14553: unless ($changes{$provider}) {
14554: if (ref($domconfig{$action}) eq 'HASH') {
14555: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14556: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14557: $changes{$provider} = 1;
14558: }
14559: }
14560: }
14561: }
14562: $idx ++;
14563: }
14564: }
14565: }
14566: my %proc_hash = (
14567: $action => { %confhash }
14568: );
14569: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14570: $dom);
14571: if ($putresult eq 'ok') {
14572: my %proc_enchash = (
14573: $action => { %encconfhash }
14574: );
1.384 raeburn 14575: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14576: if (keys(%changes) > 0) {
14577: my $cachetime = 24*60*60;
14578: my %procall = %confhash;
14579: foreach my $provider (keys(%procall)) {
14580: if (ref($encconfhash{$provider}) eq 'HASH') {
14581: foreach my $key ('key','secret') {
14582: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14583: }
14584: }
14585: }
14586: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14587: if (ref($lastactref) eq 'HASH') {
14588: $lastactref->{'proctoring'} = 1;
14589: }
14590: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14591: my %bynum;
14592: foreach my $provider (sort(keys(%changes))) {
14593: my $position = $confhash{$provider}{'order'};
14594: $bynum{$position} = $provider;
14595: }
14596: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14597: my $provider = $bynum{$pos};
14598: my %lt = &proctoring_titles($provider);
14599: my %fieldtitles = &proctoring_fieldtitles($provider);
14600: if (!$confhash{$provider}{'available'}) {
14601: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14602: } else {
14603: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14604: if ($confhash{$provider}{'image'}) {
14605: $resulttext .= ' '.
14606: '<img src="'.$confhash{$provider}{'image'}.'"'.
14607: ' alt="'.&mt('Proctoring icon').'" />';
14608: }
14609: $resulttext .= '<ul>';
14610: my $position = $pos + 1;
14611: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14612: foreach my $key ('version','sigmethod','url','lifetime') {
14613: if ($confhash{$provider}{$key} ne '') {
14614: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14615: }
14616: }
14617: if ($encconfhash{$provider}{'key'} ne '') {
14618: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14619: }
14620: if ($encconfhash{$provider}{'secret'} ne '') {
14621: $resulttext .= '<li>'.$lt{'secret'}.': ';
14622: my $num = length($encconfhash{$provider}{'secret'});
14623: $resulttext .= ('*'x$num).'</li>';
14624: }
14625: my (@fields,$showroles);
14626: if (ref($requserfields{$provider}) eq 'ARRAY') {
14627: push(@fields,@{$requserfields{$provider}});
14628: }
14629: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14630: push(@fields,@{$confhash{$provider}{'fields'}});
14631: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14632: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14633: }
14634: if (@fields) {
14635: if (grep(/^roles$/,@fields)) {
14636: $showroles = 1;
14637: }
14638: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
14639: join('", "', map { $lt{$_}; } @fields).'"</li>';
14640: }
14641: if (ref($requserfields{$provider}) eq 'ARRAY') {
14642: if (grep(/^user$/,@{$requserfields{$provider}})) {
14643: if ($confhash{$provider}{'incdom'}) {
14644: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
14645: } else {
14646: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
14647: }
14648: }
14649: }
14650: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14651: if (@{$confhash{$provider}{'defaults'}} > 0) {
14652: $resulttext .= '<li>'.$lt{'defa'};
14653: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
14654: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14655: }
14656: $resulttext =~ s/,$//;
14657: $resulttext .= '</li>';
14658: }
14659: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14660: if (keys(%{$confhash{$provider}{'defaults'}})) {
14661: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
14662: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
14663: if ($confhash{$provider}{'defaults'}{$key} ne '') {
14664: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
14665: }
14666: }
14667: $resulttext .= '</ul></li>';
14668: }
14669: }
14670: if (ref($crsconf{$provider}) eq 'ARRAY') {
14671: if (@{$crsconf{$provider}} > 0) {
14672: $resulttext .= '<li>'.&mt('Configurable in course:');
14673: my $numconfig = 0;
14674: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
14675: if (@{$confhash{$provider}{'crsconf'}} > 0) {
14676: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
14677: $numconfig ++;
14678: if ($provider eq 'examity') {
14679: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
14680: } else {
14681: $resulttext .= ' "'.$fieldtitles{$field}.'",';
14682: }
14683: }
14684: $resulttext =~ s/,$//;
14685: }
14686: }
14687: if (!$numconfig) {
14688: $resulttext .= ' '.&mt('None');
14689: }
14690: $resulttext .= '</li>';
14691: }
14692: }
14693: if ($showroles) {
14694: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
14695: my $rolemaps;
14696: foreach my $role (@courseroles) {
14697: if ($confhash{$provider}{'roles'}{$role}) {
14698: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14699: $confhash{$provider}{'roles'}{$role}.',';
14700: }
14701: }
14702: if ($rolemaps) {
14703: $rolemaps =~ s/,$//;
14704: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14705: }
14706: }
14707: }
14708: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
14709: my $customlist;
14710: if (keys(%{$confhash{$provider}{'custom'}})) {
14711: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
14712: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
14713: }
14714: $customlist =~ s/,$//;
14715: }
14716: if ($customlist) {
14717: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
14718: }
14719: }
14720: $resulttext .= '</ul></li>';
14721: }
14722: }
14723: $resulttext .= '</ul>';
14724: } else {
14725: $resulttext = &mt('No changes made.');
14726: }
14727: } else {
14728: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14729: }
14730: if ($errors) {
14731: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14732: $errors.'</ul>';
14733: }
14734: return $resulttext;
14735: }
14736:
14737: sub process_proctoring_image {
14738: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
14739: my $filename = $env{'form.'.$caller.'.filename'};
14740: my ($error,$url);
14741: my ($width,$height) = (21,21);
14742: if ($configuserok eq 'ok') {
14743: if ($switchserver) {
14744: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
14745: $switchserver);
14746: } elsif ($author_ok eq 'ok') {
14747: my ($result,$imageurl,$madethumb) =
14748: &publishlogo($r,'upload',$caller,$dom,$confname,
14749: "proctoring/$provider/icon",$width,$height);
14750: if ($result eq 'ok') {
14751: if ($madethumb) {
14752: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14753: my $imagethumb = "$path/tn-".$imagefile;
14754: $url = $imagethumb;
14755: } else {
14756: $url = $imageurl;
14757: }
14758: } else {
14759: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14760: }
14761: } else {
14762: $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);
14763: }
14764: } else {
14765: $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);
14766: }
14767: return ($url,$error);
14768: }
14769:
1.320 raeburn 14770: sub modify_lti {
14771: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14772: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14773: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
14774: my (%posslti,%posslticrs,%posscrstype);
14775: my @courseroles = ('cc','in','ta','ep','st');
14776: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
14777: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
14778: my @coursetypes = ('official','unofficial','community','textbook','placement');
14779: my %coursetypetitles = &Apache::lonlocal::texthash (
14780: official => 'Official',
14781: unofficial => 'Unofficial',
14782: community => 'Community',
14783: textbook => 'Textbook',
14784: placement => 'Placement Test',
14785: );
1.325 raeburn 14786: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 14787: my %lt = <i_names();
14788: map { $posslti{$_} = 1; } @ltiroles;
14789: map { $posslticrs{$_} = 1; } @lticourseroles;
14790: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 14791:
1.326 raeburn 14792: my %menutitles = <imenu_titles();
14793:
1.320 raeburn 14794: my (@items,%deletions,%itemids);
14795: if ($env{'form.lti_add'}) {
14796: my $consumer = $env{'form.lti_consumer_add'};
14797: $consumer =~ s/(`)/'/g;
14798: ($newid,my $error) = &get_lti_id($dom,$consumer);
14799: if ($newid) {
14800: $itemids{'add'} = $newid;
14801: push(@items,'add');
14802: $changes{$newid} = 1;
14803: } else {
14804: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
14805: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14806: }
14807: }
14808: if (ref($domconfig{$action}) eq 'HASH') {
14809: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
14810: if (@todelete) {
14811: map { $deletions{$_} = 1; } @todelete;
14812: }
14813: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 14814: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 14815: my $itemid = $env{'form.lti_id_'.$i};
14816: $itemid =~ s/\D+//g;
14817: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14818: if ($deletions{$itemid}) {
14819: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
14820: } else {
1.390 raeburn 14821: push(@items,$i);
14822: $itemids{$i} = $itemid;
1.320 raeburn 14823: }
14824: }
14825: }
14826: }
14827: foreach my $idx (@items) {
14828: my $itemid = $itemids{$idx};
14829: next unless ($itemid);
1.390 raeburn 14830: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 14831: $position =~ s/\D+//g;
14832: if ($position ne '') {
14833: $allpos[$position] = $itemid;
14834: }
1.391 ! raeburn 14835: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 14836: my $formitem = 'form.lti_'.$item.'_'.$idx;
14837: $env{$formitem} =~ s/(`)/'/g;
14838: if ($item eq 'lifetime') {
14839: $env{$formitem} =~ s/[^\d.]//g;
14840: }
14841: if ($env{$formitem} ne '') {
14842: if (($item eq 'key') || ($item eq 'secret')) {
14843: $encconfig{$itemid}{$item} = $env{$formitem};
14844: } else {
14845: $confhash{$itemid}{$item} = $env{$formitem};
14846: unless (($idx eq 'add') || ($changes{$itemid})) {
14847: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14848: $changes{$itemid} = 1;
14849: }
14850: }
14851: }
14852: }
14853: }
14854: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14855: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14856: }
1.345 raeburn 14857: if ($confhash{$itemid}{'requser'}) {
14858: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14859: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14860: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14861: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14862: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14863: my $mapuser = $env{'form.lti_customuser_'.$idx};
14864: $mapuser =~ s/(`)/'/g;
14865: $mapuser =~ s/^\s+|\s+$//g;
14866: $confhash{$itemid}{'mapuser'} = $mapuser;
14867: }
14868: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14869: my @makeuser;
14870: foreach my $ltirole (sort(@possmakeuser)) {
14871: if ($posslti{$ltirole}) {
14872: push(@makeuser,$ltirole);
14873: }
14874: }
14875: $confhash{$itemid}{'makeuser'} = \@makeuser;
14876: if (@makeuser) {
14877: my $lcauth = $env{'form.lti_lcauth_'.$idx};
14878: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14879: $confhash{$itemid}{'lcauth'} = $lcauth;
14880: if ($lcauth ne 'internal') {
14881: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14882: $lcauthparm =~ s/^(\s+|\s+)$//g;
14883: $lcauthparm =~ s/`//g;
14884: if ($lcauthparm ne '') {
14885: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
14886: }
14887: }
14888: } else {
14889: $confhash{$itemid}{'lcauth'} = 'lti';
14890: }
1.320 raeburn 14891: }
1.345 raeburn 14892: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14893: if (@possinstdata) {
14894: foreach my $field (@possinstdata) {
14895: if (exists($fieldtitles{$field})) {
14896: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 14897: }
14898: }
14899: }
1.363 raeburn 14900: if ($env{'form.lti_callback_'.$idx}) {
14901: if ($env{'form.lti_callbackparam_'.$idx}) {
14902: my $callback = $env{'form.lti_callbackparam_'.$idx};
14903: $callback =~ s/^\s+|\s+$//g;
14904: $confhash{$itemid}{'callback'} = $callback;
14905: }
14906: }
1.391 ! raeburn 14907: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 14908: if ($env{'form.lti_'.$field.'_'.$idx}) {
14909: $confhash{$itemid}{$field} = 1;
14910: }
1.320 raeburn 14911: }
1.345 raeburn 14912: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14913: $confhash{$itemid}{lcmenu} = [];
14914: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14915: foreach my $field (@possmenu) {
14916: if (exists($menutitles{$field})) {
14917: if ($field eq 'grades') {
14918: next unless ($env{'form.lti_inlinemenu_'.$idx});
14919: }
14920: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 14921: }
14922: }
14923: }
1.391 ! raeburn 14924: if ($confhash{$itemid}{'crsinc'}) {
! 14925: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
! 14926: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
! 14927: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
! 14928: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
! 14929: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
! 14930: $mapcrs =~ s/(`)/'/g;
! 14931: $mapcrs =~ s/^\s+|\s+$//g;
! 14932: $confhash{$itemid}{'mapcrs'} = $mapcrs;
! 14933: }
! 14934: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
! 14935: my @crstypes;
! 14936: foreach my $type (sort(@posstypes)) {
! 14937: if ($posscrstype{$type}) {
! 14938: push(@crstypes,$type);
! 14939: }
! 14940: }
! 14941: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
! 14942: if ($env{'form.lti_makecrs_'.$idx}) {
! 14943: $confhash{$itemid}{'makecrs'} = 1;
! 14944: }
! 14945: foreach my $ltirole (@lticourseroles) {
! 14946: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
! 14947: if (grep(/^\Q$possrole\E$/,@courseroles)) {
! 14948: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
! 14949: }
! 14950: }
! 14951: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
! 14952: my @selfenroll;
! 14953: foreach my $type (sort(@possenroll)) {
! 14954: if ($posslticrs{$type}) {
! 14955: push(@selfenroll,$type);
! 14956: }
! 14957: }
! 14958: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
! 14959: if ($env{'form.lti_crssec_'.$idx}) {
! 14960: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
! 14961: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
! 14962: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
! 14963: my $section = $env{'form.lti_customsection_'.$idx};
! 14964: $section =~ s/(`)/'/g;
! 14965: $section =~ s/^\s+|\s+$//g;
! 14966: if ($section ne '') {
! 14967: $confhash{$itemid}{'section'} = $section;
! 14968: }
! 14969: }
! 14970: }
! 14971: foreach my $field ('passback','roster') {
! 14972: if ($env{'form.lti_'.$field.'_'.$idx}) {
! 14973: $confhash{$itemid}{$field} = 1;
! 14974: }
! 14975: }
! 14976: if ($env{'form.lti_passback_'.$idx}) {
! 14977: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
! 14978: $confhash{$itemid}{'passbackformat'} = '1.0';
! 14979: } else {
! 14980: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 14981: }
14982: }
1.391 ! raeburn 14983: }
! 14984: unless (($idx eq 'add') || ($changes{$itemid})) {
! 14985: if ($confhash{$itemid}{'crsinc'}) {
! 14986: foreach my $field ('mapcrs','makecrs','section','passback','roster') {
! 14987: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 14988: $changes{$itemid} = 1;
14989: }
1.345 raeburn 14990: }
14991: unless ($changes{$itemid}) {
1.391 ! raeburn 14992: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
! 14993: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 14994: $changes{$itemid} = 1;
14995: }
14996: }
1.345 raeburn 14997: }
1.391 ! raeburn 14998: foreach my $field ('mapcrstype','selfenroll') {
! 14999: unless ($changes{$itemid}) {
! 15000: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
! 15001: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
! 15002: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
! 15003: $confhash{$itemid}{$field});
! 15004: if (@diffs) {
! 15005: $changes{$itemid} = 1;
! 15006: }
! 15007: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
! 15008: $changes{$itemid} = 1;
! 15009: }
! 15010: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
! 15011: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15012: $changes{$itemid} = 1;
15013: }
15014: }
1.391 ! raeburn 15015: }
! 15016: }
! 15017: unless ($changes{$itemid}) {
! 15018: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
! 15019: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
! 15020: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
! 15021: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
! 15022: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15023: $changes{$itemid} = 1;
15024: last;
15025: }
15026: }
1.391 ! raeburn 15027: unless ($changes{$itemid}) {
! 15028: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
! 15029: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
! 15030: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
! 15031: $changes{$itemid} = 1;
! 15032: last;
! 15033: }
! 15034: }
! 15035: }
! 15036: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
! 15037: $changes{$itemid} = 1;
1.345 raeburn 15038: }
1.391 ! raeburn 15039: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
! 15040: unless ($changes{$itemid}) {
! 15041: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
! 15042: $changes{$itemid} = 1;
! 15043: }
! 15044: }
! 15045: }
! 15046: }
! 15047: }
! 15048: unless ($changes{$itemid}) {
! 15049: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
! 15050: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15051: $changes{$itemid} = 1;
1.320 raeburn 15052: }
1.391 ! raeburn 15053: }
! 15054: unless ($changes{$itemid}) {
! 15055: foreach my $field ('makeuser','lcmenu') {
! 15056: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
! 15057: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
! 15058: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
! 15059: $confhash{$itemid}{$field});
! 15060: if (@diffs) {
! 15061: $changes{$itemid} = 1;
! 15062: }
! 15063: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
! 15064: $changes{$itemid} = 1;
! 15065: }
! 15066: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
! 15067: if (@{$confhash{$itemid}{$field}} > 0) {
! 15068: $changes{$itemid} = 1;
! 15069: }
1.345 raeburn 15070: }
1.320 raeburn 15071: }
15072: }
15073: }
15074: }
15075: }
15076: }
15077: if (@allpos > 0) {
15078: my $idx = 0;
15079: foreach my $itemid (@allpos) {
15080: if ($itemid ne '') {
15081: $confhash{$itemid}{'order'} = $idx;
15082: if (ref($domconfig{$action}) eq 'HASH') {
15083: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15084: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15085: $changes{$itemid} = 1;
15086: }
15087: }
15088: }
15089: $idx ++;
15090: }
15091: }
15092: }
15093: my %ltihash = (
15094: $action => { %confhash }
15095: );
15096: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
15097: $dom);
15098: if ($putresult eq 'ok') {
15099: my %ltienchash = (
15100: $action => { %encconfig }
15101: );
1.384 raeburn 15102: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320 raeburn 15103: if (keys(%changes) > 0) {
15104: my $cachetime = 24*60*60;
15105: my %ltiall = %confhash;
15106: foreach my $id (keys(%ltiall)) {
15107: if (ref($encconfig{$id}) eq 'HASH') {
15108: foreach my $item ('key','secret') {
15109: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15110: }
15111: }
15112: }
15113: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15114: if (ref($lastactref) eq 'HASH') {
15115: $lastactref->{'lti'} = 1;
15116: }
15117: $resulttext = &mt('Changes made:').'<ul>';
15118: my %bynum;
15119: foreach my $itemid (sort(keys(%changes))) {
15120: my $position = $confhash{$itemid}{'order'};
15121: $bynum{$position} = $itemid;
15122: }
15123: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15124: my $itemid = $bynum{$pos};
15125: if (ref($confhash{$itemid}) ne 'HASH') {
15126: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15127: } else {
1.390 raeburn 15128: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15129: my $position = $pos + 1;
15130: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15131: foreach my $item ('version','lifetime') {
15132: if ($confhash{$itemid}{$item} ne '') {
15133: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15134: }
15135: }
15136: if ($encconfig{$itemid}{'key'} ne '') {
15137: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15138: }
15139: if ($encconfig{$itemid}{'secret'} ne '') {
15140: $resulttext .= '<li>'.$lt{'secret'}.': ';
15141: my $num = length($encconfig{$itemid}{'secret'});
15142: $resulttext .= ('*'x$num).'</li>';
15143: }
1.345 raeburn 15144: if ($confhash{$itemid}{'requser'}) {
1.391 ! raeburn 15145: if ($confhash{$itemid}{'callback'}) {
! 15146: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
! 15147: } else {
! 15148: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer').'</li>';
! 15149: }
1.345 raeburn 15150: if ($confhash{$itemid}{'mapuser'}) {
15151: my $shownmapuser;
15152: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15153: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15154: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15155: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15156: } else {
15157: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15158: }
1.345 raeburn 15159: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15160: }
1.345 raeburn 15161: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15162: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15163: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15164: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15165: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15166: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15167: } else {
15168: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15169: $confhash{$itemid}{'lcauth'});
15170: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15171: $resulttext .= '; '.&mt('a randomly generated password will be created');
15172: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15173: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15174: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15175: }
15176: } else {
15177: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15178: }
15179: }
15180: $resulttext .= '</li>';
15181: } else {
15182: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15183: }
1.320 raeburn 15184: }
1.345 raeburn 15185: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15186: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15187: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15188: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15189: } else {
1.345 raeburn 15190: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15191: }
1.320 raeburn 15192: }
1.391 ! raeburn 15193: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15194: $resulttext .= '<li>'.$lt{$item}.': ';
15195: if ($confhash{$itemid}{$item}) {
15196: $resulttext .= &mt('Yes');
15197: } else {
15198: $resulttext .= &mt('No');
1.337 raeburn 15199: }
1.345 raeburn 15200: $resulttext .= '</li>';
1.320 raeburn 15201: }
1.345 raeburn 15202: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15203: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15204: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 ! raeburn 15205: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
! 15206: } else {
! 15207: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
! 15208: }
! 15209: }
! 15210: if ($confhash{$itemid}{'crsinc'}) {
! 15211: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
! 15212: my $rolemaps;
! 15213: foreach my $role (@ltiroles) {
! 15214: if ($confhash{$itemid}{'maproles'}{$role}) {
! 15215: $rolemaps .= (' 'x2).$role.'='.
! 15216: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
! 15217: 'Course').',';
! 15218: }
! 15219: }
! 15220: if ($rolemaps) {
! 15221: $rolemaps =~ s/,$//;
! 15222: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
! 15223: }
! 15224: }
! 15225: if ($confhash{$itemid}{'mapcrs'}) {
! 15226: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
! 15227: }
! 15228: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
! 15229: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
! 15230: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
! 15231: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
! 15232: '</li>';
! 15233: } else {
! 15234: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
! 15235: }
! 15236: }
! 15237: if ($confhash{$itemid}{'makecrs'}) {
! 15238: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
! 15239: } else {
! 15240: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
! 15241: }
! 15242: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
! 15243: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
! 15244: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
! 15245: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
! 15246: '</li>';
! 15247: } else {
! 15248: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
! 15249: }
! 15250: }
! 15251: if ($confhash{$itemid}{'section'}) {
! 15252: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
! 15253: $resulttext .= '<li>'.&mt('User section from standard field:').
! 15254: ' (course_section_sourcedid)'.'</li>';
! 15255: } else {
! 15256: $resulttext .= '<li>'.&mt('User section from:').' '.
! 15257: $confhash{$itemid}{'section'}.'</li>';
! 15258: }
1.345 raeburn 15259: } else {
1.391 ! raeburn 15260: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
! 15261: }
! 15262: foreach my $item ('passback','roster','topmenu','inlinemenu') {
! 15263: $resulttext .= '<li>'.$lt{$item}.': ';
! 15264: if ($confhash{$itemid}{$item}) {
! 15265: $resulttext .= &mt('Yes');
! 15266: if ($item eq 'passback') {
! 15267: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
! 15268: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
! 15269: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
! 15270: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
! 15271: }
! 15272: }
! 15273: } else {
! 15274: $resulttext .= &mt('No');
! 15275: }
! 15276: $resulttext .= '</li>';
! 15277: }
! 15278: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
! 15279: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
! 15280: $resulttext .= '<li>'.&mt('Menu items:').' '.
! 15281: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
! 15282: } else {
! 15283: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
! 15284: }
1.345 raeburn 15285: }
1.326 raeburn 15286: }
15287: }
1.320 raeburn 15288: $resulttext .= '</ul></li>';
15289: }
15290: }
15291: $resulttext .= '</ul>';
15292: } else {
15293: $resulttext = &mt('No changes made.');
15294: }
15295: } else {
15296: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15297: }
15298: if ($errors) {
15299: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15300: $errors.'</ul>';
15301: }
15302: return $resulttext;
15303: }
15304:
15305: sub get_lti_id {
15306: my ($domain,$consumer) = @_;
15307: # get lock on lti db
15308: my $lockhash = {
15309: lock => $env{'user.name'}.
15310: ':'.$env{'user.domain'},
15311: };
15312: my $tries = 0;
15313: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15314: my ($id,$error);
15315:
15316: while (($gotlock ne 'ok') && ($tries<10)) {
15317: $tries ++;
15318: sleep (0.1);
15319: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15320: }
15321: if ($gotlock eq 'ok') {
15322: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15323: if ($currids{'lock'}) {
15324: delete($currids{'lock'});
15325: if (keys(%currids)) {
15326: my @curr = sort { $a <=> $b } keys(%currids);
15327: if ($curr[-1] =~ /^\d+$/) {
15328: $id = 1 + $curr[-1];
15329: }
15330: } else {
15331: $id = 1;
15332: }
15333: if ($id) {
15334: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15335: $error = 'nostore';
15336: }
15337: } else {
15338: $error = 'nonumber';
15339: }
15340: }
15341: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15342: } else {
15343: $error = 'nolock';
15344: }
15345: return ($id,$error);
15346: }
15347:
1.3 raeburn 15348: sub modify_autoenroll {
1.205 raeburn 15349: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15350: my ($resulttext,%changes);
15351: my %currautoenroll;
15352: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15353: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15354: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15355: }
15356: }
15357: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15358: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15359: sender => 'Sender for notification messages',
1.274 raeburn 15360: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
15361: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15362: my @offon = ('off','on');
1.17 raeburn 15363: my $sender_uname = $env{'form.sender_uname'};
15364: my $sender_domain = $env{'form.sender_domain'};
15365: if ($sender_domain eq '') {
15366: $sender_uname = '';
15367: } elsif ($sender_uname eq '') {
15368: $sender_domain = '';
15369: }
1.129 raeburn 15370: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 15371: my $failsafe = $env{'form.autoenroll_failsafe'};
15372: $failsafe =~ s{^\s+|\s+$}{}g;
15373: if ($failsafe =~ /\D/) {
15374: undef($failsafe);
15375: }
1.1 raeburn 15376: my %autoenrollhash = (
1.129 raeburn 15377: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15378: 'sender_uname' => $sender_uname,
15379: 'sender_domain' => $sender_domain,
15380: 'co-owners' => $coowners,
1.274 raeburn 15381: 'autofailsafe' => $failsafe,
1.1 raeburn 15382: }
15383: );
1.4 raeburn 15384: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15385: $dom);
1.1 raeburn 15386: if ($putresult eq 'ok') {
15387: if (exists($currautoenroll{'run'})) {
15388: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15389: $changes{'run'} = 1;
15390: }
15391: } elsif ($autorun) {
15392: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15393: $changes{'run'} = 1;
1.1 raeburn 15394: }
15395: }
1.17 raeburn 15396: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15397: $changes{'sender'} = 1;
15398: }
1.17 raeburn 15399: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15400: $changes{'sender'} = 1;
15401: }
1.129 raeburn 15402: if ($currautoenroll{'co-owners'} ne '') {
15403: if ($currautoenroll{'co-owners'} ne $coowners) {
15404: $changes{'coowners'} = 1;
15405: }
15406: } elsif ($coowners) {
15407: $changes{'coowners'} = 1;
1.274 raeburn 15408: }
15409: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
15410: $changes{'autofailsafe'} = 1;
15411: }
1.1 raeburn 15412: if (keys(%changes) > 0) {
15413: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15414: if ($changes{'run'}) {
1.1 raeburn 15415: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15416: }
15417: if ($changes{'sender'}) {
1.17 raeburn 15418: if ($sender_uname eq '' || $sender_domain eq '') {
15419: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15420: } else {
15421: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15422: }
1.1 raeburn 15423: }
1.129 raeburn 15424: if ($changes{'coowners'}) {
15425: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15426: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15427: if (ref($lastactref) eq 'HASH') {
15428: $lastactref->{'domainconfig'} = 1;
15429: }
1.129 raeburn 15430: }
1.274 raeburn 15431: if ($changes{'autofailsafe'}) {
15432: if ($failsafe ne '') {
1.299 raeburn 15433: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 15434: } else {
1.299 raeburn 15435: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 15436: }
15437: &Apache::lonnet::get_domain_defaults($dom,1);
15438: if (ref($lastactref) eq 'HASH') {
15439: $lastactref->{'domdefaults'} = 1;
15440: }
15441: }
1.1 raeburn 15442: $resulttext .= '</ul>';
15443: } else {
15444: $resulttext = &mt('No changes made to auto-enrollment settings');
15445: }
15446: } else {
1.11 albertel 15447: $resulttext = '<span class="LC_error">'.
15448: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15449: }
1.3 raeburn 15450: return $resulttext;
1.1 raeburn 15451: }
15452:
15453: sub modify_autoupdate {
1.3 raeburn 15454: my ($dom,%domconfig) = @_;
1.1 raeburn 15455: my ($resulttext,%currautoupdate,%fields,%changes);
15456: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
15457: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
15458: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
15459: }
15460: }
15461: my @offon = ('off','on');
15462: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 15463: run => 'Auto-update:',
15464: classlists => 'Updates to user information in classlists?',
15465: unexpired => 'Skip updates for users without active or future roles?',
15466: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 15467: );
1.44 raeburn 15468: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 15469: my %fieldtitles = &Apache::lonlocal::texthash (
15470: id => 'Student/Employee ID',
1.20 raeburn 15471: permanentemail => 'E-mail address',
1.1 raeburn 15472: lastname => 'Last Name',
15473: firstname => 'First Name',
15474: middlename => 'Middle Name',
1.132 raeburn 15475: generation => 'Generation',
1.1 raeburn 15476: );
1.142 raeburn 15477: $othertitle = &mt('All users');
1.1 raeburn 15478: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 15479: $othertitle = &mt('Other users');
1.1 raeburn 15480: }
15481: foreach my $key (keys(%env)) {
15482: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 15483: my ($usertype,$item) = ($1,$2);
15484: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
15485: if ($usertype eq 'default') {
15486: push(@{$fields{$1}},$2);
15487: } elsif (ref($types) eq 'ARRAY') {
15488: if (grep(/^\Q$usertype\E$/,@{$types})) {
15489: push(@{$fields{$1}},$2);
15490: }
15491: }
15492: }
1.1 raeburn 15493: }
15494: }
1.131 raeburn 15495: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
15496: @lockablenames = sort(@lockablenames);
15497: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
15498: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15499: if (@changed) {
15500: $changes{'lockablenames'} = 1;
15501: }
15502: } else {
15503: if (@lockablenames) {
15504: $changes{'lockablenames'} = 1;
15505: }
15506: }
1.1 raeburn 15507: my %updatehash = (
15508: autoupdate => { run => $env{'form.autoupdate_run'},
15509: classlists => $env{'form.classlists'},
1.385 raeburn 15510: unexpired => $env{'form.unexpired'},
1.1 raeburn 15511: fields => {%fields},
1.131 raeburn 15512: lockablenames => \@lockablenames,
1.1 raeburn 15513: }
15514: );
1.385 raeburn 15515: my $lastactivedays;
15516: if ($env{'form.lastactive'}) {
15517: $lastactivedays = $env{'form.lastactivedays'};
15518: $lastactivedays =~ s/^\s+|\s+$//g;
15519: unless ($lastactivedays =~ /^\d+$/) {
15520: undef($lastactivedays);
15521: $env{'form.lastactive'} = 0;
15522: }
15523: }
15524: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 15525: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 15526: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 15527: if (exists($updatehash{autoupdate}{$key})) {
15528: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
15529: $changes{$key} = 1;
15530: }
15531: }
15532: } elsif ($key eq 'fields') {
15533: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 15534: foreach my $item (@{$types},'default') {
1.1 raeburn 15535: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
15536: my $change = 0;
15537: foreach my $type (@{$currautoupdate{$key}{$item}}) {
15538: if (!exists($fields{$item})) {
15539: $change = 1;
1.132 raeburn 15540: last;
1.1 raeburn 15541: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 15542: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 15543: $change = 1;
1.132 raeburn 15544: last;
1.1 raeburn 15545: }
15546: }
15547: }
15548: if ($change) {
15549: push(@{$changes{$key}},$item);
15550: }
1.26 raeburn 15551: }
1.1 raeburn 15552: }
15553: }
1.131 raeburn 15554: } elsif ($key eq 'lockablenames') {
15555: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15556: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15557: if (@changed) {
15558: $changes{'lockablenames'} = 1;
15559: }
15560: } else {
15561: if (@lockablenames) {
15562: $changes{'lockablenames'} = 1;
15563: }
15564: }
15565: }
15566: }
15567: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15568: if (@lockablenames) {
15569: $changes{'lockablenames'} = 1;
1.1 raeburn 15570: }
15571: }
1.385 raeburn 15572: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15573: if ($updatehash{'autoupdate'}{'unexpired'}) {
15574: $changes{'unexpired'} = 1;
15575: }
15576: }
15577: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15578: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15579: $changes{'lastactive'} = 1;
15580: }
15581: }
1.26 raeburn 15582: foreach my $item (@{$types},'default') {
15583: if (defined($fields{$item})) {
15584: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15585: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15586: my $change = 0;
15587: if (ref($fields{$item}) eq 'ARRAY') {
15588: foreach my $type (@{$fields{$item}}) {
15589: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15590: $change = 1;
15591: last;
15592: }
15593: }
15594: }
15595: if ($change) {
15596: push(@{$changes{'fields'}},$item);
15597: }
15598: } else {
1.26 raeburn 15599: push(@{$changes{'fields'}},$item);
15600: }
15601: } else {
15602: push(@{$changes{'fields'}},$item);
1.1 raeburn 15603: }
15604: }
15605: }
15606: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15607: $dom);
15608: if ($putresult eq 'ok') {
15609: if (keys(%changes) > 0) {
15610: $resulttext = &mt('Changes made:').'<ul>';
15611: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15612: if ($key eq 'lockablenames') {
15613: $resulttext .= '<li>';
15614: if (@lockablenames) {
15615: $usertypes->{'default'} = $othertitle;
15616: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15617: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15618: } else {
15619: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15620: }
15621: $resulttext .= '</li>';
15622: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15623: foreach my $item (@{$changes{$key}}) {
15624: my @newvalues;
15625: foreach my $type (@{$fields{$item}}) {
15626: push(@newvalues,$fieldtitles{$type});
15627: }
1.3 raeburn 15628: my $newvaluestr;
15629: if (@newvalues > 0) {
15630: $newvaluestr = join(', ',@newvalues);
15631: } else {
15632: $newvaluestr = &mt('none');
1.6 raeburn 15633: }
1.1 raeburn 15634: if ($item eq 'default') {
1.26 raeburn 15635: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15636: } else {
1.26 raeburn 15637: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15638: }
15639: }
15640: } else {
15641: my $newvalue;
15642: if ($key eq 'run') {
15643: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 15644: } elsif ($key eq 'lastactive') {
15645: $newvalue = $offon[$env{'form.lastactive'}];
15646: unless ($lastactivedays eq '') {
15647: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15648: }
1.1 raeburn 15649: } else {
15650: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15651: }
1.1 raeburn 15652: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15653: }
15654: }
15655: $resulttext .= '</ul>';
15656: } else {
1.3 raeburn 15657: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15658: }
15659: } else {
1.11 albertel 15660: $resulttext = '<span class="LC_error">'.
15661: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15662: }
1.3 raeburn 15663: return $resulttext;
1.1 raeburn 15664: }
15665:
1.125 raeburn 15666: sub modify_autocreate {
15667: my ($dom,%domconfig) = @_;
15668: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15669: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15670: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15671: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15672: }
15673: }
15674: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15675: req => 'Auto-creation of validated requests for official courses',
15676: xmldc => 'Identity of course creator of courses from XML files',
15677: );
15678: my @types = ('xml','req');
15679: foreach my $item (@types) {
15680: $newvals{$item} = $env{'form.autocreate_'.$item};
15681: $newvals{$item} =~ s/\D//g;
15682: $newvals{$item} = 0 if ($newvals{$item} eq '');
15683: }
15684: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 15685: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15686: unless (exists($domcoords{$newvals{'xmldc'}})) {
15687: $newvals{'xmldc'} = '';
15688: }
15689: %autocreatehash = (
15690: autocreate => { xml => $newvals{'xml'},
15691: req => $newvals{'req'},
15692: }
15693: );
15694: if ($newvals{'xmldc'} ne '') {
15695: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15696: }
15697: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15698: $dom);
15699: if ($putresult eq 'ok') {
15700: my @items = @types;
15701: if ($newvals{'xml'}) {
15702: push(@items,'xmldc');
15703: }
15704: foreach my $item (@items) {
15705: if (exists($currautocreate{$item})) {
15706: if ($currautocreate{$item} ne $newvals{$item}) {
15707: $changes{$item} = 1;
15708: }
15709: } elsif ($newvals{$item}) {
15710: $changes{$item} = 1;
15711: }
15712: }
15713: if (keys(%changes) > 0) {
15714: my @offon = ('off','on');
15715: $resulttext = &mt('Changes made:').'<ul>';
15716: foreach my $item (@types) {
15717: if ($changes{$item}) {
15718: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 15719: $resulttext .= '<li>'.
15720: &mt("$title{$item} set to [_1]$newtxt [_2]",
15721: '<b>','</b>').
15722: '</li>';
1.125 raeburn 15723: }
15724: }
15725: if ($changes{'xmldc'}) {
15726: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15727: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 15728: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15729: }
15730: $resulttext .= '</ul>';
15731: } else {
15732: $resulttext = &mt('No changes made to auto-creation settings');
15733: }
15734: } else {
15735: $resulttext = '<span class="LC_error">'.
15736: &mt('An error occurred: [_1]',$putresult).'</span>';
15737: }
15738: return $resulttext;
15739: }
15740:
1.23 raeburn 15741: sub modify_directorysrch {
1.295 raeburn 15742: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15743: my ($resulttext,%changes);
15744: my %currdirsrch;
15745: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15746: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15747: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15748: }
15749: }
1.277 raeburn 15750: my %title = ( available => 'Institutional directory search available',
15751: localonly => 'Other domains can search institution',
15752: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 15753: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15754: searchby => 'Search types',
15755: searchtypes => 'Search latitude');
15756: my @offon = ('off','on');
1.24 raeburn 15757: my @otherdoms = ('Yes','No');
1.23 raeburn 15758:
1.25 raeburn 15759: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15760: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15761: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15762:
1.44 raeburn 15763: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15764: if (keys(%{$usertypes}) == 0) {
15765: @cansearch = ('default');
15766: } else {
15767: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15768: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15769: if (!grep(/^\Q$type\E$/,@cansearch)) {
15770: push(@{$changes{'cansearch'}},$type);
15771: }
1.23 raeburn 15772: }
1.26 raeburn 15773: foreach my $type (@cansearch) {
15774: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15775: push(@{$changes{'cansearch'}},$type);
15776: }
1.23 raeburn 15777: }
1.26 raeburn 15778: } else {
15779: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15780: }
15781: }
15782:
15783: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15784: foreach my $by (@{$currdirsrch{'searchby'}}) {
15785: if (!grep(/^\Q$by\E$/,@searchby)) {
15786: push(@{$changes{'searchby'}},$by);
15787: }
15788: }
15789: foreach my $by (@searchby) {
15790: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15791: push(@{$changes{'searchby'}},$by);
15792: }
15793: }
15794: } else {
15795: push(@{$changes{'searchby'}},@searchby);
15796: }
1.25 raeburn 15797:
15798: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15799: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15800: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15801: push(@{$changes{'searchtypes'}},$type);
15802: }
15803: }
15804: foreach my $type (@searchtypes) {
15805: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15806: push(@{$changes{'searchtypes'}},$type);
15807: }
15808: }
15809: } else {
15810: if (exists($currdirsrch{'searchtypes'})) {
15811: foreach my $type (@searchtypes) {
15812: if ($type ne $currdirsrch{'searchtypes'}) {
15813: push(@{$changes{'searchtypes'}},$type);
15814: }
15815: }
15816: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15817: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15818: }
15819: } else {
15820: push(@{$changes{'searchtypes'}},@searchtypes);
15821: }
15822: }
15823:
1.23 raeburn 15824: my %dirsrch_hash = (
15825: directorysrch => { available => $env{'form.dirsrch_available'},
15826: cansearch => \@cansearch,
1.277 raeburn 15827: localonly => $env{'form.dirsrch_instlocalonly'},
15828: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15829: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15830: searchby => \@searchby,
1.25 raeburn 15831: searchtypes => \@searchtypes,
1.23 raeburn 15832: }
15833: );
15834: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15835: $dom);
15836: if ($putresult eq 'ok') {
15837: if (exists($currdirsrch{'available'})) {
15838: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15839: $changes{'available'} = 1;
15840: }
15841: } else {
15842: if ($env{'form.dirsrch_available'} eq '1') {
15843: $changes{'available'} = 1;
15844: }
15845: }
1.277 raeburn 15846: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 15847: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15848: $changes{'lcavailable'} = 1;
15849: }
1.277 raeburn 15850: } else {
15851: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15852: $changes{'lcavailable'} = 1;
15853: }
15854: }
1.24 raeburn 15855: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 15856: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
15857: $changes{'localonly'} = 1;
15858: }
1.24 raeburn 15859: } else {
1.277 raeburn 15860: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 15861: $changes{'localonly'} = 1;
15862: }
15863: }
1.277 raeburn 15864: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 15865: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15866: $changes{'lclocalonly'} = 1;
15867: }
1.277 raeburn 15868: } else {
15869: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15870: $changes{'lclocalonly'} = 1;
15871: }
15872: }
1.23 raeburn 15873: if (keys(%changes) > 0) {
15874: $resulttext = &mt('Changes made:').'<ul>';
15875: if ($changes{'available'}) {
15876: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15877: }
1.277 raeburn 15878: if ($changes{'lcavailable'}) {
15879: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15880: }
1.24 raeburn 15881: if ($changes{'localonly'}) {
1.277 raeburn 15882: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 15883: }
1.277 raeburn 15884: if ($changes{'lclocalonly'}) {
15885: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 15886: }
1.23 raeburn 15887: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15888: my $chgtext;
1.26 raeburn 15889: if (ref($usertypes) eq 'HASH') {
15890: if (keys(%{$usertypes}) > 0) {
15891: foreach my $type (@{$types}) {
15892: if (grep(/^\Q$type\E$/,@cansearch)) {
15893: $chgtext .= $usertypes->{$type}.'; ';
15894: }
15895: }
15896: if (grep(/^default$/,@cansearch)) {
15897: $chgtext .= $othertitle;
15898: } else {
15899: $chgtext =~ s/\; $//;
15900: }
1.210 raeburn 15901: $resulttext .=
1.178 raeburn 15902: '<li>'.
15903: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15904: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15905: '</li>';
1.23 raeburn 15906: }
15907: }
15908: }
15909: if (ref($changes{'searchby'}) eq 'ARRAY') {
15910: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15911: my $chgtext;
15912: foreach my $type (@{$titleorder}) {
15913: if (grep(/^\Q$type\E$/,@searchby)) {
15914: if (defined($searchtitles->{$type})) {
15915: $chgtext .= $searchtitles->{$type}.'; ';
15916: }
15917: }
15918: }
15919: $chgtext =~ s/\; $//;
15920: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15921: }
1.25 raeburn 15922: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15923: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15924: my $chgtext;
15925: foreach my $type (@{$srchtypeorder}) {
15926: if (grep(/^\Q$type\E$/,@searchtypes)) {
15927: if (defined($srchtypes_desc->{$type})) {
15928: $chgtext .= $srchtypes_desc->{$type}.'; ';
15929: }
15930: }
15931: }
15932: $chgtext =~ s/\; $//;
1.178 raeburn 15933: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15934: }
15935: $resulttext .= '</ul>';
1.295 raeburn 15936: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15937: if (ref($lastactref) eq 'HASH') {
15938: $lastactref->{'directorysrch'} = 1;
15939: }
1.23 raeburn 15940: } else {
1.277 raeburn 15941: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15942: }
15943: } else {
15944: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15945: &mt('An error occurred: [_1]',$putresult).'</span>';
15946: }
15947: return $resulttext;
15948: }
15949:
1.28 raeburn 15950: sub modify_contacts {
1.205 raeburn 15951: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15952: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15953: if (ref($domconfig{'contacts'}) eq 'HASH') {
15954: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15955: $currsetting{$key} = $domconfig{'contacts'}{$key};
15956: }
15957: }
1.286 raeburn 15958: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15959: my @contacts = ('supportemail','adminemail');
1.286 raeburn 15960: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 15961: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 15962: my @toggles = ('reporterrors','reportupdates','reportstatus');
15963: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 15964: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15965: foreach my $type (@mailings) {
15966: @{$newsetting{$type}} =
15967: &Apache::loncommon::get_env_multiple('form.'.$type);
15968: foreach my $item (@contacts) {
15969: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15970: $contacts_hash{contacts}{$type}{$item} = 1;
15971: } else {
15972: $contacts_hash{contacts}{$type}{$item} = 0;
15973: }
1.289 raeburn 15974: }
1.28 raeburn 15975: $others{$type} = $env{'form.'.$type.'_others'};
15976: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 15977: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15978: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15979: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 15980: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15981: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15982: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15983: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15984: }
1.134 raeburn 15985: }
1.28 raeburn 15986: }
15987: foreach my $item (@contacts) {
15988: $to{$item} = $env{'form.'.$item};
15989: $contacts_hash{'contacts'}{$item} = $to{$item};
15990: }
1.203 raeburn 15991: foreach my $item (@toggles) {
15992: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15993: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15994: }
15995: }
1.340 raeburn 15996: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15997: foreach my $item (@lonstatus) {
15998: if ($item eq 'excluded') {
15999: my (%serverhomes,@excluded);
16000: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16001: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16002: if (@possexcluded) {
16003: foreach my $id (sort(@possexcluded)) {
16004: if ($serverhomes{$id}) {
16005: push(@excluded,$id);
16006: }
16007: }
16008: }
16009: if (@excluded) {
16010: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16011: }
16012: } elsif ($item eq 'weights') {
1.377 raeburn 16013: foreach my $type ('E','W','N','U') {
1.340 raeburn 16014: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16015: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16016: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16017: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16018: $env{'form.error'.$item.'_'.$type};
16019: }
16020: }
16021: }
16022: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16023: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16024: if ($env{'form.error'.$item} =~ /^\d+$/) {
16025: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16026: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16027: }
16028: }
16029: }
16030: }
1.286 raeburn 16031: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16032: foreach my $field (@{$fields}) {
16033: if (ref($possoptions->{$field}) eq 'ARRAY') {
16034: my $value = $env{'form.helpform_'.$field};
16035: $value =~ s/^\s+|\s+$//g;
16036: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16037: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16038: if ($field eq 'screenshot') {
16039: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16040: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16041: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16042: }
16043: }
16044: }
16045: }
16046: }
16047: }
1.315 raeburn 16048: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16049: my (@statuses,%usertypeshash,@overrides);
16050: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16051: @statuses = @{$types};
16052: if (ref($usertypes) eq 'HASH') {
16053: %usertypeshash = %{$usertypes};
16054: }
16055: }
16056: if (@statuses) {
16057: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16058: foreach my $type (@possoverrides) {
16059: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16060: push(@overrides,$type);
16061: }
16062: }
16063: if (@overrides) {
16064: foreach my $type (@overrides) {
16065: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16066: foreach my $item (@contacts) {
16067: if (grep(/^\Q$item\E$/,@standard)) {
16068: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16069: $newsetting{'override_'.$type}{$item} = 1;
16070: } else {
16071: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16072: $newsetting{'override_'.$type}{$item} = 0;
16073: }
16074: }
16075: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16076: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16077: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16078: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16079: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16080: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16081: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16082: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16083: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16084: }
16085: }
16086: }
16087: }
1.28 raeburn 16088: if (keys(%currsetting) > 0) {
16089: foreach my $item (@contacts) {
16090: if ($to{$item} ne $currsetting{$item}) {
16091: $changes{$item} = 1;
16092: }
16093: }
16094: foreach my $type (@mailings) {
16095: foreach my $item (@contacts) {
16096: if (ref($currsetting{$type}) eq 'HASH') {
16097: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16098: push(@{$changes{$type}},$item);
16099: }
16100: } else {
16101: push(@{$changes{$type}},@{$newsetting{$type}});
16102: }
16103: }
16104: if ($others{$type} ne $currsetting{$type}{'others'}) {
16105: push(@{$changes{$type}},'others');
16106: }
1.289 raeburn 16107: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16108: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16109: push(@{$changes{$type}},'bcc');
16110: }
1.286 raeburn 16111: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16112: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16113: push(@{$changes{$type}},'include');
16114: }
16115: }
16116: }
16117: if (ref($fields) eq 'ARRAY') {
16118: if (ref($currsetting{'helpform'}) eq 'HASH') {
16119: foreach my $field (@{$fields}) {
16120: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16121: push(@{$changes{'helpform'}},$field);
16122: }
16123: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16124: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16125: push(@{$changes{'helpform'}},'maxsize');
16126: }
16127: }
16128: }
16129: } else {
16130: foreach my $field (@{$fields}) {
16131: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16132: push(@{$changes{'helpform'}},$field);
16133: }
16134: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16135: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16136: push(@{$changes{'helpform'}},'maxsize');
16137: }
16138: }
16139: }
1.134 raeburn 16140: }
1.28 raeburn 16141: }
1.315 raeburn 16142: if (@statuses) {
16143: if (ref($currsetting{'overrides'}) eq 'HASH') {
16144: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16145: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16146: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16147: foreach my $item (@contacts,'bcc','others','include') {
16148: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16149: push(@{$changes{'overrides'}},$key);
16150: last;
16151: }
16152: }
16153: } else {
16154: push(@{$changes{'overrides'}},$key);
16155: }
16156: }
16157: }
16158: foreach my $key (@overrides) {
16159: unless (exists($currsetting{'overrides'}{$key})) {
16160: push(@{$changes{'overrides'}},$key);
16161: }
16162: }
16163: } else {
16164: foreach my $key (@overrides) {
16165: push(@{$changes{'overrides'}},$key);
16166: }
16167: }
16168: }
1.340 raeburn 16169: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16170: foreach my $key ('excluded','weights','threshold','sysmail') {
16171: if ($key eq 'excluded') {
16172: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16173: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16174: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16175: (@{$currsetting{'lonstatus'}{$key}})) {
16176: my @diffs =
16177: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16178: $currsetting{'lonstatus'}{$key});
16179: if (@diffs) {
16180: push(@{$changes{'lonstatus'}},$key);
16181: }
16182: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16183: push(@{$changes{'lonstatus'}},$key);
16184: }
16185: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16186: (@{$currsetting{'lonstatus'}{$key}})) {
16187: push(@{$changes{'lonstatus'}},$key);
16188: }
16189: } elsif ($key eq 'weights') {
16190: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16191: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16192: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16193: foreach my $type ('E','W','N','U') {
1.340 raeburn 16194: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16195: $currsetting{'lonstatus'}{$key}{$type}) {
16196: push(@{$changes{'lonstatus'}},$key);
16197: last;
16198: }
16199: }
16200: } else {
1.341 raeburn 16201: foreach my $type ('E','W','N','U') {
1.340 raeburn 16202: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16203: push(@{$changes{'lonstatus'}},$key);
16204: last;
16205: }
16206: }
16207: }
16208: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16209: foreach my $type ('E','W','N','U') {
1.340 raeburn 16210: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16211: push(@{$changes{'lonstatus'}},$key);
16212: last;
16213: }
16214: }
16215: }
16216: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16217: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16218: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16219: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16220: push(@{$changes{'lonstatus'}},$key);
16221: }
16222: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16223: push(@{$changes{'lonstatus'}},$key);
16224: }
16225: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16226: push(@{$changes{'lonstatus'}},$key);
16227: }
16228: }
16229: }
16230: } else {
16231: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16232: foreach my $key ('excluded','weights','threshold','sysmail') {
16233: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16234: push(@{$changes{'lonstatus'}},$key);
16235: }
16236: }
16237: }
16238: }
1.28 raeburn 16239: } else {
16240: my %default;
16241: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16242: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16243: $default{'errormail'} = 'adminemail';
16244: $default{'packagesmail'} = 'adminemail';
16245: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16246: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16247: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16248: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16249: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16250: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16251: foreach my $item (@contacts) {
16252: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16253: $changes{$item} = 1;
1.203 raeburn 16254: }
1.28 raeburn 16255: }
16256: foreach my $type (@mailings) {
16257: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16258: push(@{$changes{$type}},@{$newsetting{$type}});
16259: }
16260: if ($others{$type} ne '') {
16261: push(@{$changes{$type}},'others');
1.134 raeburn 16262: }
1.286 raeburn 16263: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16264: if ($bcc{$type} ne '') {
16265: push(@{$changes{$type}},'bcc');
16266: }
1.286 raeburn 16267: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16268: push(@{$changes{$type}},'include');
16269: }
1.134 raeburn 16270: }
1.28 raeburn 16271: }
1.286 raeburn 16272: if (ref($fields) eq 'ARRAY') {
16273: foreach my $field (@{$fields}) {
16274: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16275: push(@{$changes{'helpform'}},$field);
16276: }
16277: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16278: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16279: push(@{$changes{'helpform'}},'maxsize');
16280: }
16281: }
16282: }
1.289 raeburn 16283: }
1.340 raeburn 16284: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16285: foreach my $key ('excluded','weights','threshold','sysmail') {
16286: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16287: push(@{$changes{'lonstatus'}},$key);
16288: }
16289: }
16290: }
1.28 raeburn 16291: }
1.203 raeburn 16292: foreach my $item (@toggles) {
16293: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16294: $changes{$item} = 1;
16295: } elsif ((!$env{'form.'.$item}) &&
16296: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16297: $changes{$item} = 1;
16298: }
16299: }
1.28 raeburn 16300: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16301: $dom);
16302: if ($putresult eq 'ok') {
16303: if (keys(%changes) > 0) {
1.205 raeburn 16304: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16305: if (ref($lastactref) eq 'HASH') {
16306: $lastactref->{'domainconfig'} = 1;
16307: }
1.28 raeburn 16308: my ($titles,$short_titles) = &contact_titles();
16309: $resulttext = &mt('Changes made:').'<ul>';
16310: foreach my $item (@contacts) {
16311: if ($changes{$item}) {
16312: $resulttext .= '<li>'.$titles->{$item}.
16313: &mt(' set to: ').
16314: '<span class="LC_cusr_emph">'.
16315: $to{$item}.'</span></li>';
16316: }
16317: }
16318: foreach my $type (@mailings) {
16319: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16320: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16321: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16322: } else {
16323: $resulttext .= '<li>'.$titles->{$type}.': ';
16324: }
1.28 raeburn 16325: my @text;
16326: foreach my $item (@{$newsetting{$type}}) {
16327: push(@text,$short_titles->{$item});
16328: }
16329: if ($others{$type} ne '') {
16330: push(@text,$others{$type});
16331: }
1.286 raeburn 16332: if (@text) {
16333: $resulttext .= '<span class="LC_cusr_emph">'.
16334: join(', ',@text).'</span>';
16335: }
16336: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16337: if ($bcc{$type} ne '') {
1.286 raeburn 16338: my $bcctext;
16339: if (@text) {
1.289 raeburn 16340: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16341: } else {
16342: $bcctext = '(Bcc)';
16343: }
16344: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16345: } elsif (!@text) {
16346: $resulttext .= &mt('No one');
16347: }
1.289 raeburn 16348: if ($includestr{$type} ne '') {
1.286 raeburn 16349: if ($includeloc{$type} eq 'b') {
16350: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16351: } elsif ($includeloc{$type} eq 's') {
16352: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16353: }
1.134 raeburn 16354: }
1.286 raeburn 16355: } elsif (!@text) {
16356: $resulttext .= &mt('No recipients');
1.134 raeburn 16357: }
16358: $resulttext .= '</li>';
1.28 raeburn 16359: }
16360: }
1.315 raeburn 16361: if (ref($changes{'overrides'}) eq 'ARRAY') {
16362: my @deletions;
16363: foreach my $type (@{$changes{'overrides'}}) {
16364: if ($usertypeshash{$type}) {
16365: if (grep(/^\Q$type\E/,@overrides)) {
16366: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16367: $usertypeshash{$type}).'<ul><li>';
16368: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16369: my @text;
16370: foreach my $item (@contacts) {
16371: if ($newsetting{'override_'.$type}{$item}) {
16372: push(@text,$short_titles->{$item});
16373: }
16374: }
16375: if ($newsetting{'override_'.$type}{'others'} ne '') {
16376: push(@text,$newsetting{'override_'.$type}{'others'});
16377: }
16378:
16379: if (@text) {
16380: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16381: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16382: }
16383: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16384: my $bcctext;
16385: if (@text) {
16386: $bcctext = ' '.&mt('with Bcc to');
16387: } else {
16388: $bcctext = '(Bcc)';
16389: }
16390: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16391: } elsif (!@text) {
16392: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16393: }
16394: $resulttext .= '</li>';
16395: if ($newsetting{'override_'.$type}{'include'} ne '') {
16396: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16397: if ($loc eq 'b') {
16398: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16399: } elsif ($loc eq 's') {
16400: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16401: }
16402: }
16403: }
16404: $resulttext .= '</li></ul></li>';
16405: } else {
16406: push(@deletions,$usertypeshash{$type});
16407: }
16408: }
16409: }
16410: if (@deletions) {
16411: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16412: join(', ',@deletions)).'</li>';
16413: }
16414: }
1.203 raeburn 16415: my @offon = ('off','on');
1.340 raeburn 16416: my $corelink = &core_link_msu();
1.203 raeburn 16417: if ($changes{'reporterrors'}) {
16418: $resulttext .= '<li>'.
16419: &mt('E-mail error reports to [_1] set to "'.
16420: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16421: $corelink).
1.203 raeburn 16422: '</li>';
16423: }
16424: if ($changes{'reportupdates'}) {
16425: $resulttext .= '<li>'.
16426: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16427: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16428: $corelink).
1.203 raeburn 16429: '</li>';
16430: }
1.340 raeburn 16431: if ($changes{'reportstatus'}) {
16432: $resulttext .= '<li>'.
16433: &mt('E-mail status if errors above threshold to [_1] set to "'.
16434: $offon[$env{'form.reportstatus'}].'".',
16435: $corelink).
16436: '</li>';
16437: }
16438: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16439: $resulttext .= '<li>'.
16440: &mt('Nightly status check e-mail settings').':<ul>';
16441: my (%defval,%use_def,%shown);
16442: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
16443: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
16444: $defval{'weights'} =
1.341 raeburn 16445: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 16446: $defval{'excluded'} = &mt('None');
16447: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
16448: foreach my $item ('threshold','sysmail','weights','excluded') {
16449: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
16450: if (($item eq 'threshold') || ($item eq 'sysmail')) {
16451: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
16452: } elsif ($item eq 'weights') {
16453: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 16454: foreach my $type ('E','W','N','U') {
1.340 raeburn 16455: $shown{$item} .= $lonstatus_names->{$type}.'=';
16456: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
16457: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
16458: } else {
16459: $shown{$item} .= $lonstatus_defs->{$type};
16460: }
16461: $shown{$item} .= ', ';
16462: }
16463: $shown{$item} =~ s/, $//;
16464: } else {
16465: $shown{$item} = $defval{$item};
16466: }
16467: } elsif ($item eq 'excluded') {
16468: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
16469: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
16470: } else {
16471: $shown{$item} = $defval{$item};
16472: }
16473: }
16474: } else {
16475: $shown{$item} = $defval{$item};
16476: }
16477: }
16478: } else {
16479: foreach my $item ('threshold','weights','excluded','sysmail') {
16480: $shown{$item} = $defval{$item};
16481: }
16482: }
16483: foreach my $item ('threshold','weights','excluded','sysmail') {
16484: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
16485: $shown{$item}).'</li>';
16486: }
16487: $resulttext .= '</ul></li>';
16488: }
1.286 raeburn 16489: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
16490: my (@optional,@required,@unused,$maxsizechg);
16491: foreach my $field (@{$changes{'helpform'}}) {
16492: if ($field eq 'maxsize') {
16493: $maxsizechg = 1;
16494: next;
16495: }
16496: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 16497: push(@optional,$field);
1.286 raeburn 16498: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
16499: push(@unused,$field);
16500: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 16501: push(@required,$field);
1.286 raeburn 16502: }
16503: }
16504: if (@optional) {
16505: $resulttext .= '<li>'.
16506: &mt('Help form fields changed to "Optional": [_1].',
16507: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
16508: '</li>';
16509: }
16510: if (@required) {
16511: $resulttext .= '<li>'.
16512: &mt('Help form fields changed to "Required": [_1].',
16513: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
16514: '</li>';
16515: }
16516: if (@unused) {
16517: $resulttext .= '<li>'.
16518: &mt('Help form fields changed to "Not shown": [_1].',
16519: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
16520: '</li>';
16521: }
16522: if ($maxsizechg) {
16523: $resulttext .= '<li>'.
16524: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
16525: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
16526: '</li>';
16527: }
16528: }
1.28 raeburn 16529: $resulttext .= '</ul>';
16530: } else {
1.288 raeburn 16531: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 16532: }
16533: } else {
16534: $resulttext = '<span class="LC_error">'.
16535: &mt('An error occurred: [_1].',$putresult).'</span>';
16536: }
16537: return $resulttext;
16538: }
16539:
1.357 raeburn 16540: sub modify_privacy {
16541: my ($dom,%domconfig) = @_;
16542: my ($resulttext,%current,%changes);
16543: if (ref($domconfig{'privacy'}) eq 'HASH') {
16544: %current = %{$domconfig{'privacy'}};
16545: }
16546: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
16547: my @items = ('domain','author','course','community');
16548: my %names = &Apache::lonlocal::texthash (
16549: domain => 'Assigned domain role(s)',
16550: author => 'Assigned co-author role(s)',
16551: course => 'Assigned course role(s)',
16552: community => 'Assigned community role',
16553: );
16554: my %roles = &Apache::lonlocal::texthash (
16555: domain => 'Domain role',
16556: author => 'Co-author role',
16557: course => 'Course role',
16558: community => 'Community role',
16559: );
16560: my %titles = &Apache::lonlocal::texthash (
16561: approval => 'Approval for role in different domain',
16562: othdom => 'User information available in other domain',
16563: priv => 'Information viewable by privileged user in same domain',
16564: unpriv => 'Information viewable by unprivileged user in same domain',
16565: instdom => 'Other domain shares institution/provider',
16566: extdom => 'Other domain has different institution/provider',
16567: none => 'Not allowed',
16568: user => 'User authorizes',
16569: domain => 'Domain Coordinator authorizes',
16570: auto => 'Unrestricted',
16571: );
16572: my %fieldnames = &Apache::lonlocal::texthash (
16573: id => 'Student/Employee ID',
16574: permanentemail => 'E-mail address',
16575: lastname => 'Last Name',
16576: firstname => 'First Name',
16577: middlename => 'Middle Name',
16578: generation => 'Generation',
16579: );
16580: my ($othertitle,$usertypes,$types) =
16581: &Apache::loncommon::sorted_inst_types($dom);
16582: my (%by_ip,%by_location,@intdoms,@instdoms);
16583: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16584:
16585: my %privacyhash = (
16586: 'approval' => {
16587: instdom => {},
16588: extdom => {},
16589: },
16590: 'othdom' => {},
16591: 'priv' => {},
16592: 'unpriv' => {},
16593: );
16594: foreach my $item (@items) {
16595: if (@instdoms > 1) {
16596: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
16597: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
16598: }
16599: if (ref($current{'approval'}) eq 'HASH') {
16600: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
16601: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
16602: $changes{'approval'} = 1;
16603: }
16604: }
16605: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
16606: $changes{'approval'} = 1;
16607: }
16608: }
16609: if (keys(%by_location) > 0) {
16610: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
16611: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
16612: }
16613: if (ref($current{'approval'}) eq 'HASH') {
16614: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
16615: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
16616: $changes{'approval'} = 1;
16617: }
16618: }
16619: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
16620: $changes{'approval'} = 1;
16621: }
16622: }
16623: foreach my $status ('priv','unpriv') {
16624: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
16625: my @newvalues;
16626: foreach my $field (@possibles) {
16627: if (grep(/^\Q$field\E$/,@fields)) {
16628: $privacyhash{$status}{$item}{$field} = 1;
16629: push(@newvalues,$field);
16630: }
16631: }
16632: @newvalues = sort(@newvalues);
16633: if (ref($current{$status}) eq 'HASH') {
16634: if (ref($current{$status}{$item}) eq 'HASH') {
16635: my @currvalues = sort(keys(%{$current{$status}{$item}}));
16636: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16637: if (@diffs > 0) {
16638: $changes{$status} = 1;
16639: }
16640: }
16641: } else {
16642: my @stdfields;
16643: foreach my $field (@fields) {
16644: if ($field eq 'id') {
16645: next if ($status eq 'unpriv');
16646: next if (($status eq 'priv') && ($item eq 'community'));
16647: }
16648: push(@stdfields,$field);
16649: }
16650: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16651: if (@diffs > 0) {
16652: $changes{$status} = 1;
16653: }
16654: }
16655: }
16656: }
16657: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
16658: my @statuses;
16659: if (ref($types) eq 'ARRAY') {
16660: @statuses = @{$types};
16661: }
16662: foreach my $type (@statuses,'default') {
16663: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
16664: my @newvalues;
16665: foreach my $field (sort(@possfields)) {
16666: if (grep(/^\Q$field\E$/,@fields)) {
16667: $privacyhash{'othdom'}{$type}{$field} = 1;
16668: push(@newvalues,$field);
16669: }
16670: }
16671: @newvalues = sort(@newvalues);
16672: if (ref($current{'othdom'}) eq 'HASH') {
16673: if (ref($current{'othdom'}{$type}) eq 'HASH') {
16674: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
16675: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
16676: if (@diffs > 0) {
16677: $changes{'othdom'} = 1;
16678: }
16679: }
16680: } else {
16681: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
16682: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
16683: if (@diffs > 0) {
16684: $changes{'othdom'} = 1;
16685: }
16686: }
16687: }
16688: }
16689: my %confighash = (
16690: privacy => \%privacyhash,
16691: );
16692: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16693: if ($putresult eq 'ok') {
16694: if (keys(%changes) > 0) {
16695: $resulttext = &mt('Changes made: ').'<ul>';
16696: foreach my $key ('approval','othdom','priv','unpriv') {
16697: if ($changes{$key}) {
16698: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16699: if ($key eq 'approval') {
16700: if (keys(%{$privacyhash{$key}{instdom}})) {
16701: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
16702: foreach my $item (@items) {
16703: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
16704: }
16705: $resulttext .= '</ul></li>';
16706: }
16707: if (keys(%{$privacyhash{$key}{extdom}})) {
16708: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
16709: foreach my $item (@items) {
16710: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
16711: }
16712: $resulttext .= '</ul></li>';
16713: }
16714: } elsif ($key eq 'othdom') {
16715: my @statuses;
16716: if (ref($types) eq 'ARRAY') {
16717: @statuses = @{$types};
16718: }
16719: if (ref($privacyhash{$key}) eq 'HASH') {
16720: foreach my $status (@statuses,'default') {
16721: if ($status eq 'default') {
16722: $resulttext .= '<li>'.$othertitle.': ';
16723: } elsif (ref($usertypes) eq 'HASH') {
16724: $resulttext .= '<li>'.$usertypes->{$status}.': ';
16725: } else {
16726: next;
16727: }
16728: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
16729: if (keys(%{$privacyhash{$key}{$status}})) {
16730: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
16731: } else {
16732: $resulttext .= &mt('none');
16733: }
16734: }
16735: $resulttext .= '</li>';
16736: }
16737: }
16738: } else {
16739: foreach my $item (@items) {
16740: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
16741: $resulttext .= '<li>'.$names{$item}.': ';
16742: if (keys(%{$privacyhash{$key}{$item}})) {
16743: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
16744: } else {
16745: $resulttext .= &mt('none');
16746: }
16747: $resulttext .= '</li>';
16748: }
16749: }
16750: }
16751: $resulttext .= '</ul></li>';
16752: }
16753: }
16754: } else {
16755: $resulttext = &mt('No changes made to user information settings');
16756: }
16757: } else {
16758: $resulttext = '<span class="LC_error">'.
16759: &mt('An error occurred: [_1]',$putresult).'</span>';
16760: }
16761: return $resulttext;
16762: }
16763:
1.354 raeburn 16764: sub modify_passwords {
16765: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 16766: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
16767: $updatedefaults,$updateconf);
1.354 raeburn 16768: my $customfn = 'resetpw.html';
16769: if (ref($domconfig{'passwords'}) eq 'HASH') {
16770: %current = %{$domconfig{'passwords'}};
16771: }
16772: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16773: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16774: if (ref($types) eq 'ARRAY') {
16775: @oktypes = @{$types};
16776: }
16777: push(@oktypes,'default');
16778:
16779: my %titles = &Apache::lonlocal::texthash (
16780: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
16781: intauth_check => 'Check bcrypt cost if authenticated',
16782: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16783: permanent => 'Permanent e-mail address',
16784: critical => 'Critical notification address',
16785: notify => 'Notification address',
16786: min => 'Minimum password length',
16787: max => 'Maximum password length',
16788: chars => 'Required characters',
16789: expire => 'Password expiration (days)',
1.356 raeburn 16790: numsaved => 'Number of previous passwords to save',
1.354 raeburn 16791: reset => 'Resetting Forgotten Password',
16792: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16793: rules => 'Rules for LON-CAPA Passwords',
16794: crsownerchg => 'Course Owner Changing Student Passwords',
16795: username => 'Username',
16796: email => 'E-mail address',
16797: );
16798:
16799: #
16800: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16801: #
16802: my (%curr_defaults,%save_defaults);
16803: if (ref($domconfig{'defaults'}) eq 'HASH') {
16804: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16805: if ($key =~ /^intauth_(cost|check|switch)$/) {
16806: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16807: } else {
16808: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16809: }
16810: }
16811: }
16812: my %staticdefaults = (
16813: 'resetlink' => 2,
16814: 'resetcase' => \@oktypes,
16815: 'resetprelink' => 'both',
16816: 'resetemail' => ['critical','notify','permanent'],
16817: 'intauth_cost' => 10,
16818: 'intauth_check' => 0,
16819: 'intauth_switch' => 0,
16820: );
1.365 raeburn 16821: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 16822: foreach my $type (@oktypes) {
16823: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16824: }
16825: my $linklife = $env{'form.passwords_link'};
16826: $linklife =~ s/^\s+|\s+$//g;
16827: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16828: $newvalues{'resetlink'} = $linklife;
16829: if ($current{'resetlink'}) {
16830: if ($current{'resetlink'} ne $linklife) {
16831: $changes{'reset'} = 1;
16832: }
1.368 raeburn 16833: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16834: if ($staticdefaults{'resetlink'} ne $linklife) {
16835: $changes{'reset'} = 1;
16836: }
16837: }
16838: } elsif ($current{'resetlink'}) {
16839: $changes{'reset'} = 1;
16840: }
16841: my @casesens;
16842: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16843: foreach my $case (sort(@posscase)) {
16844: if (grep(/^\Q$case\E$/,@oktypes)) {
16845: push(@casesens,$case);
16846: }
16847: }
16848: $newvalues{'resetcase'} = \@casesens;
16849: if (ref($current{'resetcase'}) eq 'ARRAY') {
16850: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16851: if (@diffs > 0) {
16852: $changes{'reset'} = 1;
16853: }
1.368 raeburn 16854: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16855: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16856: if (@diffs > 0) {
16857: $changes{'reset'} = 1;
16858: }
16859: }
16860: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16861: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16862: if (exists($current{'resetprelink'})) {
16863: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16864: $changes{'reset'} = 1;
16865: }
1.368 raeburn 16866: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16867: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16868: $changes{'reset'} = 1;
16869: }
16870: }
16871: } elsif ($current{'resetprelink'}) {
16872: $changes{'reset'} = 1;
16873: }
16874: foreach my $type (@oktypes) {
16875: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16876: my @postlink;
16877: foreach my $item (sort(@possplink)) {
16878: if ($item =~ /^(email|username)$/) {
16879: push(@postlink,$item);
16880: }
16881: }
16882: $newvalues{'resetpostlink'}{$type} = \@postlink;
16883: unless ($changes{'reset'}) {
16884: if (ref($current{'resetpostlink'}) eq 'HASH') {
16885: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16886: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16887: if (@diffs > 0) {
16888: $changes{'reset'} = 1;
16889: }
16890: } else {
16891: $changes{'reset'} = 1;
16892: }
1.368 raeburn 16893: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16894: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16895: if (@diffs > 0) {
16896: $changes{'reset'} = 1;
16897: }
16898: }
16899: }
16900: }
16901: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16902: my @resetemail;
16903: foreach my $item (sort(@possemailsrc)) {
16904: if ($item =~ /^(permanent|critical|notify)$/) {
16905: push(@resetemail,$item);
16906: }
16907: }
16908: $newvalues{'resetemail'} = \@resetemail;
16909: unless ($changes{'reset'}) {
16910: if (ref($current{'resetemail'}) eq 'ARRAY') {
16911: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16912: if (@diffs > 0) {
16913: $changes{'reset'} = 1;
16914: }
1.368 raeburn 16915: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 16916: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16917: if (@diffs > 0) {
16918: $changes{'reset'} = 1;
16919: }
16920: }
16921: }
16922: if ($env{'form.passwords_stdtext'} == 0) {
16923: $newvalues{'resetremove'} = 1;
16924: unless ($current{'resetremove'}) {
16925: $changes{'reset'} = 1;
16926: }
16927: } elsif ($current{'resetremove'}) {
16928: $changes{'reset'} = 1;
16929: }
16930: if ($env{'form.passwords_customfile.filename'} ne '') {
16931: my $servadm = $r->dir_config('lonAdmEMail');
16932: my ($configuserok,$author_ok,$switchserver) =
16933: &config_check($dom,$confname,$servadm);
16934: my $error;
16935: if ($configuserok eq 'ok') {
16936: if ($switchserver) {
16937: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16938: } else {
16939: if ($author_ok eq 'ok') {
16940: my ($result,$customurl) =
16941: &publishlogo($r,'upload','passwords_customfile',$dom,
16942: $confname,'customtext/resetpw','','',$customfn);
16943: if ($result eq 'ok') {
16944: $newvalues{'resetcustom'} = $customurl;
16945: $changes{'reset'} = 1;
16946: } else {
16947: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16948: }
16949: } else {
16950: $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);
16951: }
16952: }
16953: } else {
16954: $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);
16955: }
16956: if ($error) {
16957: &Apache::lonnet::logthis($error);
16958: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16959: }
16960: } elsif ($current{'resetcustom'}) {
16961: if ($env{'form.passwords_custom_del'}) {
16962: $changes{'reset'} = 1;
16963: } else {
16964: $newvalues{'resetcustom'} = $current{'resetcustom'};
16965: }
16966: }
16967: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16968: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16969: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16970: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16971: $changes{'intauth'} = 1;
16972: }
16973: } else {
16974: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16975: }
16976: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16977: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16978: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16979: $changes{'intauth'} = 1;
16980: }
16981: } else {
16982: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16983: }
16984: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16985: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16986: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16987: $changes{'intauth'} = 1;
16988: }
16989: } else {
16990: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16991: }
16992: foreach my $item ('cost','check','switch') {
16993: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16994: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16995: $updatedefaults = 1;
16996: }
16997: }
1.356 raeburn 16998: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 16999: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 17000: my $ruleok;
17001: if ($rule eq 'expire') {
1.365 raeburn 17002: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17003: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 17004: $ruleok = 1;
1.356 raeburn 17005: }
1.365 raeburn 17006: } elsif ($rule eq 'min') {
17007: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
17008: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
17009: $ruleok = 1;
17010: }
17011: }
17012: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
17013: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 17014: $ruleok = 1;
17015: }
17016: if ($ruleok) {
1.354 raeburn 17017: $newvalues{$rule} = $env{'form.passwords_'.$rule};
17018: if (exists($current{$rule})) {
17019: if ($newvalues{$rule} ne $current{$rule}) {
17020: $changes{'rules'} = 1;
17021: }
17022: } elsif ($rule eq 'min') {
17023: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
17024: $changes{'rules'} = 1;
17025: }
1.370 raeburn 17026: } else {
17027: $changes{'rules'} = 1;
1.354 raeburn 17028: }
17029: } elsif (exists($current{$rule})) {
17030: $changes{'rules'} = 1;
17031: }
17032: }
17033: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
17034: my @chars;
17035: foreach my $item (sort(@posschars)) {
17036: if ($item =~ /^(uc|lc|num|spec)$/) {
17037: push(@chars,$item);
17038: }
17039: }
17040: $newvalues{'chars'} = \@chars;
17041: unless ($changes{'rules'}) {
17042: if (ref($current{'chars'}) eq 'ARRAY') {
17043: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
17044: if (@diffs > 0) {
17045: $changes{'rules'} = 1;
17046: }
17047: } else {
17048: if (@chars > 0) {
17049: $changes{'rules'} = 1;
17050: }
17051: }
17052: }
1.359 raeburn 17053: my %crsownerchg = (
17054: by => [],
17055: for => [],
17056: );
17057: foreach my $item ('by','for') {
17058: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17059: foreach my $type (sort(@posstypes)) {
17060: if (grep(/^\Q$type\E$/,@oktypes)) {
17061: push(@{$crsownerchg{$item}},$type);
17062: }
17063: }
17064: }
17065: $newvalues{'crsownerchg'} = \%crsownerchg;
17066: if (ref($current{'crsownerchg'}) eq 'HASH') {
17067: foreach my $item ('by','for') {
17068: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17069: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17070: if (@diffs > 0) {
17071: $changes{'crsownerchg'} = 1;
17072: last;
17073: }
17074: }
17075: }
1.368 raeburn 17076: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17077: foreach my $item ('by','for') {
17078: if (@{$crsownerchg{$item}} > 0) {
17079: $changes{'crsownerchg'} = 1;
17080: last;
17081: }
1.354 raeburn 17082: }
17083: }
17084:
17085: my %confighash = (
17086: defaults => \%save_defaults,
17087: passwords => \%newvalues,
17088: );
17089: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17090:
17091: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17092: if ($putresult eq 'ok') {
17093: if (keys(%changes) > 0) {
17094: $resulttext = &mt('Changes made: ').'<ul>';
17095: foreach my $key ('reset','intauth','rules','crsownerchg') {
17096: if ($changes{$key}) {
1.355 raeburn 17097: unless ($key eq 'intauth') {
17098: $updateconf = 1;
17099: }
1.354 raeburn 17100: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17101: if ($key eq 'reset') {
17102: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17103: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17104: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17105: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17106: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17107: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17108: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17109: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17110: }
1.354 raeburn 17111: } else {
17112: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17113: }
17114: if ($confighash{'passwords'}{'resetlink'}) {
17115: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17116: } else {
17117: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17118: &mt('Will default to 2 hours').'</li>';
17119: }
17120: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17121: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17122: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17123: } else {
17124: my $casesens;
17125: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17126: if ($type eq 'default') {
17127: $casesens .= $othertitle.', ';
17128: } elsif ($usertypes->{$type} ne '') {
17129: $casesens .= $usertypes->{$type}.', ';
17130: }
17131: }
17132: $casesens =~ s/\Q, \E$//;
17133: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17134: }
17135: } else {
17136: $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>';
17137: }
17138: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17139: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17140: } else {
17141: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17142: }
17143: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17144: my $output;
17145: if (ref($types) eq 'ARRAY') {
17146: foreach my $type (@{$types}) {
17147: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17148: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17149: $output .= $usertypes->{$type}.' -- '.&mt('none');
17150: } else {
17151: $output .= $usertypes->{$type}.' -- '.
17152: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17153: }
17154: }
17155: }
17156: }
17157: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17158: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17159: $output .= $othertitle.' -- '.&mt('none');
17160: } else {
17161: $output .= $othertitle.' -- '.
17162: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17163: }
17164: }
17165: if ($output) {
17166: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17167: } else {
17168: $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>';
17169: }
17170: } else {
17171: $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>';
17172: }
17173: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17174: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17175: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17176: } else {
17177: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17178: }
17179: } else {
1.379 raeburn 17180: $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 17181: }
17182: if ($confighash{'passwords'}{'resetremove'}) {
17183: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17184: } else {
17185: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17186: }
17187: if ($confighash{'passwords'}{'resetcustom'}) {
17188: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17189: &mt('custom text'),600,500,undef,undef,
17190: undef,undef,'background-color:#ffffff');
17191: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17192: } else {
17193: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17194: }
17195: } elsif ($key eq 'intauth') {
17196: foreach my $item ('cost','switch','check') {
17197: my $value = $save_defaults{$key.'_'.$item};
17198: if ($item eq 'switch') {
17199: my %optiondesc = &Apache::lonlocal::texthash (
17200: 0 => 'No',
17201: 1 => 'Yes',
17202: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17203: );
17204: if ($value =~ /^(0|1|2)$/) {
17205: $value = $optiondesc{$value};
17206: } else {
17207: $value = &mt('none -- defaults to No');
17208: }
17209: } elsif ($item eq 'check') {
17210: my %optiondesc = &Apache::lonlocal::texthash (
17211: 0 => 'No',
17212: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17213: 2 => 'Yes, disallow login if stored cost is less than domain default',
17214: );
17215: if ($value =~ /^(0|1|2)$/) {
17216: $value = $optiondesc{$value};
17217: } else {
17218: $value = &mt('none -- defaults to No');
17219: }
17220: }
17221: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17222: }
17223: } elsif ($key eq 'rules') {
1.356 raeburn 17224: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17225: if ($confighash{'passwords'}{$rule} eq '') {
17226: if ($rule eq 'min') {
1.356 raeburn 17227: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17228: ' '.&mt('Default of [_1] will be used',
17229: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17230: } else {
17231: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17232: }
17233: } else {
17234: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17235: }
17236: }
1.370 raeburn 17237: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17238: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17239: my %rulenames = &Apache::lonlocal::texthash(
17240: uc => 'At least one upper case letter',
17241: lc => 'At least one lower case letter',
17242: num => 'At least one number',
17243: spec => 'At least one non-alphanumeric',
17244: );
17245: my $needed = '<ul><li>'.
17246: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17247: '</li></ul>';
17248: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17249: } else {
17250: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17251: }
17252: } else {
17253: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17254: }
1.354 raeburn 17255: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17256: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17257: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17258: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17259: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17260: } else {
17261: my %crsownerstr;
17262: foreach my $item ('by','for') {
17263: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17264: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17265: if ($type eq 'default') {
17266: $crsownerstr{$item} .= $othertitle.', ';
17267: } elsif ($usertypes->{$type} ne '') {
17268: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17269: }
17270: }
17271: $crsownerstr{$item} =~ s/\Q, \E$//;
17272: }
17273: }
17274: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17275: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17276: }
1.354 raeburn 17277: } else {
1.359 raeburn 17278: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17279: }
17280: }
17281: $resulttext .= '</ul></li>';
17282: }
17283: }
17284: $resulttext .= '</ul>';
17285: } else {
17286: $resulttext = &mt('No changes made to password settings');
17287: }
1.355 raeburn 17288: my $cachetime = 24*60*60;
1.354 raeburn 17289: if ($updatedefaults) {
17290: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17291: if (ref($lastactref) eq 'HASH') {
17292: $lastactref->{'domdefaults'} = 1;
17293: }
17294: }
1.355 raeburn 17295: if ($updateconf) {
17296: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17297: if (ref($lastactref) eq 'HASH') {
17298: $lastactref->{'passwdconf'} = 1;
17299: }
17300: }
1.354 raeburn 17301: } else {
17302: $resulttext = '<span class="LC_error">'.
17303: &mt('An error occurred: [_1]',$putresult).'</span>';
17304: }
17305: if ($errors) {
17306: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17307: $errors.'</ul></p>';
17308: }
17309: return $resulttext;
17310: }
17311:
1.28 raeburn 17312: sub modify_usercreation {
1.27 raeburn 17313: my ($dom,%domconfig) = @_;
1.224 raeburn 17314: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17315: my $warningmsg;
1.27 raeburn 17316: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17317: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17318: if ($key eq 'cancreate') {
17319: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17320: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17321: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17322: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17323: } else {
1.224 raeburn 17324: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17325: }
17326: }
17327: }
17328: } elsif ($key eq 'email_rule') {
17329: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17330: } else {
17331: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17332: }
1.27 raeburn 17333: }
17334: }
17335: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17336: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17337: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17338: foreach my $item(@contexts) {
1.224 raeburn 17339: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17340: }
1.34 raeburn 17341: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17342: foreach my $item (@contexts) {
1.224 raeburn 17343: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17344: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17345: }
1.27 raeburn 17346: }
1.34 raeburn 17347: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17348: foreach my $item (@contexts) {
1.43 raeburn 17349: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17350: if ($cancreate{$item} ne 'any') {
17351: push(@{$changes{'cancreate'}},$item);
17352: }
17353: } else {
17354: if ($cancreate{$item} ne 'none') {
17355: push(@{$changes{'cancreate'}},$item);
17356: }
1.27 raeburn 17357: }
17358: }
17359: } else {
1.43 raeburn 17360: foreach my $item (@contexts) {
1.34 raeburn 17361: push(@{$changes{'cancreate'}},$item);
17362: }
1.27 raeburn 17363: }
1.34 raeburn 17364:
1.27 raeburn 17365: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17366: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17367: if (!grep(/^\Q$type\E$/,@username_rule)) {
17368: push(@{$changes{'username_rule'}},$type);
17369: }
17370: }
17371: foreach my $type (@username_rule) {
17372: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17373: push(@{$changes{'username_rule'}},$type);
17374: }
17375: }
17376: } else {
17377: push(@{$changes{'username_rule'}},@username_rule);
17378: }
17379:
1.32 raeburn 17380: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17381: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17382: if (!grep(/^\Q$type\E$/,@id_rule)) {
17383: push(@{$changes{'id_rule'}},$type);
17384: }
17385: }
17386: foreach my $type (@id_rule) {
17387: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17388: push(@{$changes{'id_rule'}},$type);
17389: }
17390: }
17391: } else {
17392: push(@{$changes{'id_rule'}},@id_rule);
17393: }
17394:
1.43 raeburn 17395: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17396: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17397: my %authhash;
1.43 raeburn 17398: foreach my $item (@authen_contexts) {
1.28 raeburn 17399: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17400: foreach my $auth (@authtypes) {
17401: if (grep(/^\Q$auth\E$/,@authallowed)) {
17402: $authhash{$item}{$auth} = 1;
17403: } else {
17404: $authhash{$item}{$auth} = 0;
17405: }
17406: }
17407: }
17408: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17409: foreach my $item (@authen_contexts) {
1.28 raeburn 17410: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17411: foreach my $auth (@authtypes) {
17412: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17413: push(@{$changes{'authtypes'}},$item);
17414: last;
17415: }
17416: }
17417: }
17418: }
17419: } else {
1.43 raeburn 17420: foreach my $item (@authen_contexts) {
1.28 raeburn 17421: push(@{$changes{'authtypes'}},$item);
17422: }
17423: }
17424:
1.224 raeburn 17425: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17426: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17427: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17428: $save_usercreate{'id_rule'} = \@id_rule;
17429: $save_usercreate{'username_rule'} = \@username_rule,
17430: $save_usercreate{'authtypes'} = \%authhash;
17431:
1.27 raeburn 17432: my %usercreation_hash = (
1.224 raeburn 17433: usercreation => \%save_usercreate,
17434: );
1.27 raeburn 17435:
17436: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17437: $dom);
1.50 raeburn 17438:
1.224 raeburn 17439: if ($putresult eq 'ok') {
17440: if (keys(%changes) > 0) {
17441: $resulttext = &mt('Changes made:').'<ul>';
17442: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17443: my %lt = &usercreation_types();
17444: foreach my $type (@{$changes{'cancreate'}}) {
17445: my $chgtext = $lt{$type}.', ';
17446: if ($cancreate{$type} eq 'none') {
17447: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
17448: } elsif ($cancreate{$type} eq 'any') {
17449: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
17450: } elsif ($cancreate{$type} eq 'official') {
17451: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
17452: } elsif ($cancreate{$type} eq 'unofficial') {
17453: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
17454: }
17455: $resulttext .= '<li>'.$chgtext.'</li>';
17456: }
17457: }
17458: if (ref($changes{'username_rule'}) eq 'ARRAY') {
17459: my ($rules,$ruleorder) =
17460: &Apache::lonnet::inst_userrules($dom,'username');
17461: my $chgtext = '<ul>';
17462: foreach my $type (@username_rule) {
17463: if (ref($rules->{$type}) eq 'HASH') {
17464: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
17465: }
17466: }
17467: $chgtext .= '</ul>';
17468: if (@username_rule > 0) {
17469: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17470: } else {
17471: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
17472: }
17473: }
17474: if (ref($changes{'id_rule'}) eq 'ARRAY') {
17475: my ($idrules,$idruleorder) =
17476: &Apache::lonnet::inst_userrules($dom,'id');
17477: my $chgtext = '<ul>';
17478: foreach my $type (@id_rule) {
17479: if (ref($idrules->{$type}) eq 'HASH') {
17480: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
17481: }
17482: }
17483: $chgtext .= '</ul>';
17484: if (@id_rule > 0) {
17485: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
17486: } else {
17487: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
17488: }
17489: }
17490: my %authname = &authtype_names();
17491: my %context_title = &context_names();
17492: if (ref($changes{'authtypes'}) eq 'ARRAY') {
17493: my $chgtext = '<ul>';
17494: foreach my $type (@{$changes{'authtypes'}}) {
17495: my @allowed;
17496: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
17497: foreach my $auth (@authtypes) {
17498: if ($authhash{$type}{$auth}) {
17499: push(@allowed,$authname{$auth});
17500: }
17501: }
17502: if (@allowed > 0) {
17503: $chgtext .= join(', ',@allowed).'</li>';
17504: } else {
17505: $chgtext .= &mt('none').'</li>';
17506: }
17507: }
17508: $chgtext .= '</ul>';
17509: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
17510: $resulttext .= '</li>';
17511: }
17512: $resulttext .= '</ul>';
17513: } else {
17514: $resulttext = &mt('No changes made to user creation settings');
17515: }
17516: } else {
17517: $resulttext = '<span class="LC_error">'.
17518: &mt('An error occurred: [_1]',$putresult).'</span>';
17519: }
17520: if ($warningmsg ne '') {
17521: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17522: }
17523: return $resulttext;
17524: }
17525:
17526: sub modify_selfcreation {
1.305 raeburn 17527: my ($dom,$lastactref,%domconfig) = @_;
17528: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
17529: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
17530: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 17531: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
17532: if (ref($typesref) eq 'ARRAY') {
17533: @types = @{$typesref};
17534: }
17535: if (ref($usertypesref) eq 'HASH') {
17536: %usertypes = %{$usertypesref};
1.228 raeburn 17537: }
1.303 raeburn 17538: $usertypes{'default'} = $othertitle;
1.224 raeburn 17539: #
17540: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
17541: #
17542: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17543: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
17544: if ($key eq 'cancreate') {
17545: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17546: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
17547: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 17548: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
17549: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
17550: ($item eq 'emailusername') || ($item eq 'shibenv') ||
17551: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 17552: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 17553: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17554: } else {
17555: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17556: }
17557: }
17558: }
17559: } elsif ($key eq 'email_rule') {
17560: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17561: } else {
17562: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17563: }
17564: }
17565: }
17566: #
17567: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
17568: #
17569: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17570: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
17571: if ($key eq 'selfcreate') {
17572: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
17573: } else {
17574: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
17575: }
17576: }
17577: }
1.305 raeburn 17578: #
17579: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
17580: #
17581: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17582: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
17583: if ($key eq 'inststatusguest') {
17584: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
17585: } else {
17586: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
17587: }
17588: }
17589: }
1.224 raeburn 17590:
17591: my @contexts = ('selfcreate');
17592: @{$cancreate{'selfcreate'}} = ();
17593: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 17594: if (@types) {
17595: @{$cancreate{'statustocreate'}} = ();
17596: }
1.236 raeburn 17597: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 17598: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 17599: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 17600: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 17601: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 17602: my %selfcreatetypes = (
17603: sso => 'users authenticated by institutional single sign on',
17604: login => 'users authenticated by institutional log-in',
1.303 raeburn 17605: email => 'users verified by e-mail',
1.50 raeburn 17606: );
1.224 raeburn 17607: #
17608: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
17609: # is permitted.
17610: #
1.305 raeburn 17611: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 17612:
1.305 raeburn 17613: my (@statuses,%email_rule);
1.228 raeburn 17614: foreach my $item ('login','sso','email') {
1.224 raeburn 17615: if ($item eq 'email') {
1.236 raeburn 17616: if ($env{'form.cancreate_email'}) {
1.305 raeburn 17617: if (@types) {
17618: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
17619: foreach my $status (@poss_statuses) {
17620: if (grep(/^\Q$status\E$/,(@types,'default'))) {
17621: push(@statuses,$status);
17622: }
17623: }
17624: $save_inststatus{'inststatusguest'} = \@statuses;
17625: } else {
17626: push(@statuses,'default');
17627: }
17628: if (@statuses) {
17629: my %curr_rule;
17630: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
17631: foreach my $type (@statuses) {
17632: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 17633: }
1.305 raeburn 17634: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
17635: foreach my $type (@statuses) {
17636: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
17637: }
17638: }
17639: push(@{$cancreate{'selfcreate'}},'email');
17640: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
17641: my %curremaildom;
17642: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
17643: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
17644: }
17645: foreach my $type (@statuses) {
17646: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
17647: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
17648: }
17649: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
17650: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
17651: }
17652: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
17653: #
17654: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
17655: #
17656: my $chosen = $1;
17657: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
17658: my $emaildom;
17659: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
17660: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
17661: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
17662: if (ref($curremaildom{$type}) eq 'HASH') {
17663: if (exists($curremaildom{$type}{$chosen})) {
17664: if ($curremaildom{$type}{$chosen} ne $emaildom) {
17665: push(@{$changes{'cancreate'}},'emaildomain');
17666: }
17667: } elsif ($emaildom ne '') {
17668: push(@{$changes{'cancreate'}},'emaildomain');
17669: }
17670: } elsif ($emaildom ne '') {
17671: push(@{$changes{'cancreate'}},'emaildomain');
17672: }
17673: }
17674: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17675: } elsif ($chosen eq 'custom') {
17676: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
17677: $email_rule{$type} = [];
17678: if (ref($emailrules) eq 'HASH') {
17679: foreach my $rule (@possemail_rules) {
17680: if (exists($emailrules->{$rule})) {
17681: push(@{$email_rule{$type}},$rule);
17682: }
17683: }
17684: }
17685: if (@{$email_rule{$type}}) {
17686: $cancreate{'emailoptions'}{$type} = 'custom';
17687: if (ref($curr_rule{$type}) eq 'ARRAY') {
17688: if (@{$curr_rule{$type}} > 0) {
17689: foreach my $rule (@{$curr_rule{$type}}) {
17690: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
17691: push(@{$changes{'email_rule'}},$type);
17692: }
17693: }
17694: }
17695: foreach my $type (@{$email_rule{$type}}) {
17696: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
17697: push(@{$changes{'email_rule'}},$type);
17698: }
17699: }
17700: } else {
17701: push(@{$changes{'email_rule'}},$type);
17702: }
17703: }
17704: } else {
17705: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
17706: }
17707: }
17708: }
17709: if (@types) {
17710: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17711: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
17712: if (@changed) {
17713: push(@{$changes{'inststatus'}},'inststatusguest');
17714: }
17715: } else {
17716: push(@{$changes{'inststatus'}},'inststatusguest');
17717: }
17718: }
17719: } else {
17720: delete($env{'form.cancreate_email'});
17721: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17722: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17723: push(@{$changes{'inststatus'}},'inststatusguest');
17724: }
17725: }
17726: }
17727: } else {
17728: $save_inststatus{'inststatusguest'} = [];
17729: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
17730: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
17731: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 17732: }
17733: }
1.224 raeburn 17734: }
17735: } else {
17736: if ($env{'form.cancreate_'.$item}) {
17737: push(@{$cancreate{'selfcreate'}},$item);
17738: }
17739: }
17740: }
1.305 raeburn 17741: my (%userinfo,%savecaptcha);
1.224 raeburn 17742: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
17743: #
1.228 raeburn 17744: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
17745: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 17746: #
1.236 raeburn 17747:
1.244 raeburn 17748: if ($env{'form.cancreate_email'}) {
1.228 raeburn 17749: push(@contexts,'emailusername');
1.305 raeburn 17750: if (@statuses) {
17751: foreach my $type (@statuses) {
1.228 raeburn 17752: if (ref($infofields) eq 'ARRAY') {
17753: foreach my $field (@{$infofields}) {
17754: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
17755: $cancreate{'emailusername'}{$type}{$field} = $1;
17756: }
17757: }
1.224 raeburn 17758: }
17759: }
17760: }
17761: #
17762: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 17763: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 17764: #
17765:
17766: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
17767: @approvalnotify = sort(@approvalnotify);
17768: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
17769: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17770: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17771: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17772: push(@{$changes{'cancreate'}},'notify');
17773: }
17774: } else {
17775: if ($cancreate{'notify'}{'approval'}) {
17776: push(@{$changes{'cancreate'}},'notify');
17777: }
17778: }
17779: } elsif ($cancreate{'notify'}{'approval'}) {
17780: push(@{$changes{'cancreate'}},'notify');
17781: }
17782:
17783: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17784: }
17785: #
1.236 raeburn 17786: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 17787: # institutional log-in.
17788: #
17789: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17790: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17791: ($domdefaults{'auth_def'} eq 'localauth'))) {
17792: $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.').' '.
17793: &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.');
17794: }
17795: }
17796: my @fields = ('lastname','firstname','middlename','generation',
17797: 'permanentemail','id');
1.240 raeburn 17798: my @shibfields = (@fields,'inststatus');
1.224 raeburn 17799: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17800: #
17801: # Where usernames may created for institutional log-in and/or institutional single sign on:
17802: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17803: # may self-create accounts
17804: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17805: # which the user may supply, if institutional data is unavailable.
17806: #
17807: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 17808: if (@types) {
1.305 raeburn 17809: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17810: push(@contexts,'statustocreate');
1.303 raeburn 17811: foreach my $type (@types) {
1.224 raeburn 17812: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17813: foreach my $field (@fields) {
17814: if (grep(/^\Q$field\E$/,@modifiable)) {
17815: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17816: } else {
17817: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17818: }
17819: }
17820: }
17821: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 17822: foreach my $type (@types) {
1.224 raeburn 17823: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17824: foreach my $field (@fields) {
17825: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17826: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17827: push(@{$changes{'selfcreate'}},$type);
17828: last;
17829: }
17830: }
17831: }
17832: }
17833: } else {
1.303 raeburn 17834: foreach my $type (@types) {
1.224 raeburn 17835: push(@{$changes{'selfcreate'}},$type);
17836: }
17837: }
17838: }
1.240 raeburn 17839: foreach my $field (@shibfields) {
17840: if ($env{'form.shibenv_'.$field} ne '') {
17841: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17842: }
17843: }
17844: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17845: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17846: foreach my $field (@shibfields) {
17847: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17848: push(@{$changes{'cancreate'}},'shibenv');
17849: }
17850: }
17851: } else {
17852: foreach my $field (@shibfields) {
17853: if ($env{'form.shibenv_'.$field}) {
17854: push(@{$changes{'cancreate'}},'shibenv');
17855: last;
17856: }
17857: }
17858: }
17859: }
1.224 raeburn 17860: }
17861: foreach my $item (@contexts) {
17862: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17863: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17864: if (ref($cancreate{$item}) eq 'ARRAY') {
17865: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17866: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17867: push(@{$changes{'cancreate'}},$item);
17868: }
17869: }
17870: }
17871: }
17872: if (ref($cancreate{$item}) eq 'ARRAY') {
17873: foreach my $type (@{$cancreate{$item}}) {
17874: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17875: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17876: push(@{$changes{'cancreate'}},$item);
17877: }
17878: }
17879: }
17880: }
17881: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17882: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 17883: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17884: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17885: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17886: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17887: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17888: push(@{$changes{'cancreate'}},$item);
17889: }
17890: }
17891: }
1.305 raeburn 17892: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17893: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17894: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17895: push(@{$changes{'cancreate'}},$item);
17896: }
1.224 raeburn 17897: }
17898: }
17899: }
1.305 raeburn 17900: foreach my $type (keys(%{$cancreate{$item}})) {
17901: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17902: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17903: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17904: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 17905: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17906: push(@{$changes{'cancreate'}},$item);
17907: }
17908: }
17909: } else {
17910: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17911: push(@{$changes{'cancreate'}},$item);
17912: }
17913: }
17914: }
1.305 raeburn 17915: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17916: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 17917: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17918: push(@{$changes{'cancreate'}},$item);
17919: }
1.224 raeburn 17920: }
17921: }
17922: }
17923: }
17924: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17925: if (ref($cancreate{$item}) eq 'ARRAY') {
17926: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17927: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17928: push(@{$changes{'cancreate'}},$item);
17929: }
17930: }
1.305 raeburn 17931: }
17932: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17933: if (ref($cancreate{$item}) eq 'HASH') {
17934: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17935: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 17936: }
17937: }
17938: } elsif ($item eq 'emailusername') {
1.228 raeburn 17939: if (ref($cancreate{$item}) eq 'HASH') {
17940: foreach my $type (keys(%{$cancreate{$item}})) {
17941: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17942: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17943: if ($cancreate{$item}{$type}{$field}) {
17944: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17945: push(@{$changes{'cancreate'}},$item);
17946: }
17947: last;
17948: }
17949: }
17950: }
17951: }
1.224 raeburn 17952: }
17953: }
17954: }
17955: #
17956: # Populate %save_usercreate hash with updates to self-creation configuration.
17957: #
17958: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17959: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 17960: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 17961: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17962: if (ref($cancreate{'notify'}) eq 'HASH') {
17963: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17964: }
1.236 raeburn 17965: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17966: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17967: }
1.303 raeburn 17968: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17969: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17970: }
1.305 raeburn 17971: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17972: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17973: }
1.303 raeburn 17974: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17975: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17976: }
1.224 raeburn 17977: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17978: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17979: }
1.240 raeburn 17980: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17981: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17982: }
1.224 raeburn 17983: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 17984: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 17985:
17986: my %userconfig_hash = (
17987: usercreation => \%save_usercreate,
17988: usermodification => \%save_usermodify,
1.305 raeburn 17989: inststatus => \%save_inststatus,
1.224 raeburn 17990: );
1.305 raeburn 17991:
1.224 raeburn 17992: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17993: $dom);
17994: #
1.305 raeburn 17995: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 17996: #
1.27 raeburn 17997: if ($putresult eq 'ok') {
17998: if (keys(%changes) > 0) {
17999: $resulttext = &mt('Changes made:').'<ul>';
18000: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18001: my %lt = &selfcreation_types();
1.34 raeburn 18002: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18003: my $chgtext = '';
1.45 raeburn 18004: if ($type eq 'selfcreate') {
1.50 raeburn 18005: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18006: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18007: } else {
1.224 raeburn 18008: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18009: '<ul>';
1.50 raeburn 18010: foreach my $case (@{$cancreate{$type}}) {
18011: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18012: }
18013: $chgtext .= '</ul>';
1.100 raeburn 18014: if (ref($cancreate{$type}) eq 'ARRAY') {
18015: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18016: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18017: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18018: $chgtext .= '<span class="LC_warning">'.
18019: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18020: '</span><br />';
18021: }
18022: }
18023: }
18024: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18025: if (!@statuses) {
18026: $chgtext .= '<span class="LC_warning">'.
18027: &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.").
18028: '</span><br />';
1.303 raeburn 18029:
1.100 raeburn 18030: }
18031: }
18032: }
1.43 raeburn 18033: }
1.240 raeburn 18034: } elsif ($type eq 'shibenv') {
18035: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18036: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18037: } else {
18038: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18039: '<ul>';
18040: foreach my $field (@shibfields) {
18041: next if ($cancreate{$type}{$field} eq '');
18042: if ($field eq 'inststatus') {
18043: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18044: } else {
18045: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18046: }
18047: }
18048: $chgtext .= '</ul>';
1.303 raeburn 18049: }
1.93 raeburn 18050: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18051: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18052: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18053: if (@{$cancreate{'selfcreate'}} > 0) {
18054: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18055: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18056: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18057: $chgtext .= '<br />'.
18058: '<span class="LC_warning">'.
18059: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18060: '</span>';
18061: }
1.303 raeburn 18062: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18063: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18064: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18065: } else {
18066: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18067: }
18068: $chgtext .= '<ul>';
18069: foreach my $case (@{$cancreate{$type}}) {
18070: if ($case eq 'default') {
18071: $chgtext .= '<li>'.$othertitle.'</li>';
18072: } else {
1.303 raeburn 18073: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18074: }
18075: }
1.100 raeburn 18076: $chgtext .= '</ul>';
18077: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18078: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18079: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18080: '</span>';
1.100 raeburn 18081: }
18082: }
18083: } else {
18084: if (@{$cancreate{$type}} == 0) {
18085: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18086: } else {
18087: $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 18088: }
18089: }
1.303 raeburn 18090: $chgtext .= '<br />';
1.93 raeburn 18091: }
1.236 raeburn 18092: } elsif ($type eq 'selfcreateprocessing') {
18093: my %choices = &Apache::lonlocal::texthash (
18094: automatic => 'Automatic approval',
18095: approval => 'Queued for approval',
18096: );
1.305 raeburn 18097: if (@types) {
18098: if (@statuses) {
1.303 raeburn 18099: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18100: '<ul>';
1.305 raeburn 18101: foreach my $status (@statuses) {
18102: if ($status eq 'default') {
18103: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18104: } else {
1.305 raeburn 18105: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18106: }
18107: }
18108: $chgtext .= '</ul>';
18109: }
18110: } else {
18111: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18112: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18113: }
18114: } elsif ($type eq 'emailverified') {
18115: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18116: all => 'Same as e-mail',
18117: first => 'Omit @domain',
18118: free => 'Free to choose',
1.303 raeburn 18119: );
1.305 raeburn 18120: if (@types) {
18121: if (@statuses) {
1.303 raeburn 18122: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18123: '<ul>';
1.305 raeburn 18124: foreach my $status (@statuses) {
1.362 raeburn 18125: if ($status eq 'default') {
1.305 raeburn 18126: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18127: } else {
1.305 raeburn 18128: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18129: }
18130: }
18131: $chgtext .= '</ul>';
18132: }
18133: } else {
1.305 raeburn 18134: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18135: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18136: }
1.305 raeburn 18137: } elsif ($type eq 'emailoptions') {
18138: my %options = &Apache::lonlocal::texthash (
18139: any => 'Any e-mail',
18140: inst => 'Institutional only',
18141: noninst => 'Non-institutional only',
18142: custom => 'Custom restrictions',
18143: );
18144: if (@types) {
18145: if (@statuses) {
18146: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18147: '<ul>';
18148: foreach my $status (@statuses) {
18149: if ($type eq 'default') {
18150: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18151: } else {
18152: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18153: }
18154: }
1.305 raeburn 18155: $chgtext .= '</ul>';
18156: }
18157: } else {
18158: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18159: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18160: } else {
18161: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18162: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18163: }
1.305 raeburn 18164: }
18165: } elsif ($type eq 'emaildomain') {
18166: my $output;
18167: if (@statuses) {
18168: foreach my $type (@statuses) {
18169: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18170: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18171: if ($type eq 'default') {
18172: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18173: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18174: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18175: } else {
18176: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18177: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18178: }
1.303 raeburn 18179: } else {
1.305 raeburn 18180: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18181: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18182: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18183: } else {
18184: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
18185: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18186: }
1.303 raeburn 18187: }
1.305 raeburn 18188: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18189: if ($type eq 'default') {
18190: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18191: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18192: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18193: } else {
18194: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18195: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18196: }
1.303 raeburn 18197: } else {
1.305 raeburn 18198: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18199: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18200: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18201: } else {
18202: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
18203: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18204: }
1.303 raeburn 18205: }
18206: }
18207: }
18208: }
1.305 raeburn 18209: }
18210: if ($output ne '') {
18211: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18212: '<ul>'.$output.'</ul>';
1.236 raeburn 18213: }
1.165 raeburn 18214: } elsif ($type eq 'captcha') {
1.224 raeburn 18215: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18216: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18217: } else {
18218: my %captchas = &captcha_phrases();
1.224 raeburn 18219: if ($captchas{$savecaptcha{$type}}) {
18220: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18221: } else {
1.210 raeburn 18222: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18223: }
18224: }
18225: } elsif ($type eq 'recaptchakeys') {
18226: my ($privkey,$pubkey);
1.224 raeburn 18227: if (ref($savecaptcha{$type}) eq 'HASH') {
18228: $pubkey = $savecaptcha{$type}{'public'};
18229: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18230: }
18231: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18232: if (!$pubkey) {
18233: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18234: } else {
18235: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18236: }
18237: if (!$privkey) {
18238: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18239: } else {
18240: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18241: }
18242: $chgtext .= '</ul>';
1.269 raeburn 18243: } elsif ($type eq 'recaptchaversion') {
18244: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18245: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18246: }
1.224 raeburn 18247: } elsif ($type eq 'emailusername') {
18248: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18249: if (@statuses) {
18250: foreach my $type (@statuses) {
1.228 raeburn 18251: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18252: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18253: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18254: '<ul>';
18255: foreach my $field (@{$infofields}) {
18256: if ($cancreate{'emailusername'}{$type}{$field}) {
18257: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18258: }
18259: }
1.245 raeburn 18260: $chgtext .= '</ul>';
18261: } else {
1.303 raeburn 18262: $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 18263: }
18264: } else {
1.303 raeburn 18265: $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 18266: }
18267: }
18268: }
18269: }
18270: } elsif ($type eq 'notify') {
1.303 raeburn 18271: my $numapprove = 0;
1.224 raeburn 18272: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18273: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18274: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18275: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18276: $numapprove ++;
1.224 raeburn 18277: }
18278: }
1.43 raeburn 18279: }
1.303 raeburn 18280: unless ($numapprove) {
18281: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18282: }
1.34 raeburn 18283: }
1.224 raeburn 18284: if ($chgtext) {
18285: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18286: }
18287: }
18288: }
1.305 raeburn 18289: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18290: my ($emailrules,$emailruleorder) =
18291: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18292: foreach my $type (@{$changes{'email_rule'}}) {
18293: if (ref($email_rule{$type}) eq 'ARRAY') {
18294: my $chgtext = '<ul>';
18295: foreach my $rule (@{$email_rule{$type}}) {
18296: if (ref($emailrules->{$rule}) eq 'HASH') {
18297: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18298: }
18299: }
18300: $chgtext .= '</ul>';
1.310 raeburn 18301: my $typename;
1.305 raeburn 18302: if (@types) {
18303: if ($type eq 'default') {
18304: $typename = $othertitle;
18305: } else {
18306: $typename = $usertypes{$type};
18307: }
18308: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18309: }
18310: if (@{$email_rule{$type}} > 0) {
18311: $resulttext .= '<li>'.
18312: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18313: $usertypes{$type}).
18314: $chgtext.
18315: '</li>';
18316: } else {
18317: $resulttext .= '<li>'.
1.310 raeburn 18318: &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 18319: '</li>'.
1.310 raeburn 18320: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18321: }
1.43 raeburn 18322: }
18323: }
1.305 raeburn 18324: }
18325: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18326: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18327: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18328: my $chgtext = '<ul>';
18329: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18330: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18331: }
18332: $chgtext .= '</ul>';
18333: $resulttext .= '<li>'.
18334: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18335: $chgtext.
18336: '</li>';
18337: } else {
18338: $resulttext .= '<li>'.
18339: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18340: '</li>';
18341: }
1.43 raeburn 18342: }
18343: }
1.224 raeburn 18344: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18345: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18346: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18347: foreach my $type (@{$changes{'selfcreate'}}) {
18348: my $typename = $type;
1.303 raeburn 18349: if (keys(%usertypes) > 0) {
18350: if ($usertypes{$type} ne '') {
18351: $typename = $usertypes{$type};
1.224 raeburn 18352: }
18353: }
18354: my @modifiable;
18355: $resulttext .= '<li>'.
18356: &mt('Self-creation of account by users with status: [_1]',
18357: '<span class="LC_cusr_emph">'.$typename.'</span>').
18358: ' - '.&mt('modifiable fields (if institutional data blank): ');
18359: foreach my $field (@fields) {
18360: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18361: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18362: }
18363: }
1.224 raeburn 18364: if (@modifiable > 0) {
18365: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18366: } else {
1.224 raeburn 18367: $resulttext .= &mt('none');
1.43 raeburn 18368: }
1.224 raeburn 18369: $resulttext .= '</li>';
1.28 raeburn 18370: }
1.224 raeburn 18371: $resulttext .= '</ul></li>';
1.28 raeburn 18372: }
1.27 raeburn 18373: $resulttext .= '</ul>';
1.305 raeburn 18374: my $cachetime = 24*60*60;
18375: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18376: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18377: if (ref($lastactref) eq 'HASH') {
18378: $lastactref->{'domdefaults'} = 1;
18379: }
1.27 raeburn 18380: } else {
1.224 raeburn 18381: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18382: }
18383: } else {
18384: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18385: &mt('An error occurred: [_1]',$putresult).'</span>';
18386: }
1.43 raeburn 18387: if ($warningmsg ne '') {
18388: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18389: }
1.23 raeburn 18390: return $resulttext;
18391: }
18392:
1.165 raeburn 18393: sub process_captcha {
1.369 raeburn 18394: my ($container,$changes,$newsettings,$currsettings) = @_;
18395: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18396: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18397: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18398: $newsettings->{'captcha'} = 'original';
18399: }
1.369 raeburn 18400: my %current;
18401: if (ref($currsettings) eq 'HASH') {
18402: %current = %{$currsettings};
18403: }
18404: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18405: if ($container eq 'cancreate') {
1.169 raeburn 18406: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18407: push(@{$changes->{'cancreate'}},'captcha');
18408: } elsif (!defined($changes->{'cancreate'})) {
18409: $changes->{'cancreate'} = ['captcha'];
18410: }
1.368 raeburn 18411: } elsif ($container eq 'passwords') {
18412: $changes->{'reset'} = 1;
1.169 raeburn 18413: } else {
18414: $changes->{'captcha'} = 1;
1.165 raeburn 18415: }
18416: }
1.269 raeburn 18417: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18418: if ($newsettings->{'captcha'} eq 'recaptcha') {
18419: $newpub = $env{'form.'.$container.'_recaptchapub'};
18420: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18421: $newpub =~ s/[^\w\-]//g;
18422: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18423: $newsettings->{'recaptchakeys'} = {
18424: public => $newpub,
18425: private => $newpriv,
18426: };
1.269 raeburn 18427: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18428: $newversion =~ s/\D//g;
18429: if ($newversion ne '2') {
18430: $newversion = 1;
18431: }
18432: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18433: }
1.369 raeburn 18434: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18435: $currpub = $current{'recaptchakeys'}{'public'};
18436: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18437: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18438: $newsettings->{'recaptchakeys'} = {
18439: public => '',
18440: private => '',
18441: }
18442: }
1.165 raeburn 18443: }
1.369 raeburn 18444: if ($current{'captcha'} eq 'recaptcha') {
18445: $currversion = $current{'recaptchaversion'};
1.269 raeburn 18446: if ($currversion ne '2') {
18447: $currversion = 1;
18448: }
18449: }
18450: if ($currversion ne $newversion) {
18451: if ($container eq 'cancreate') {
18452: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18453: push(@{$changes->{'cancreate'}},'recaptchaversion');
18454: } elsif (!defined($changes->{'cancreate'})) {
18455: $changes->{'cancreate'} = ['recaptchaversion'];
18456: }
1.368 raeburn 18457: } elsif ($container eq 'passwords') {
18458: $changes->{'reset'} = 1;
1.269 raeburn 18459: } else {
18460: $changes->{'recaptchaversion'} = 1;
18461: }
18462: }
1.165 raeburn 18463: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 18464: if ($container eq 'cancreate') {
18465: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18466: push(@{$changes->{'cancreate'}},'recaptchakeys');
18467: } elsif (!defined($changes->{'cancreate'})) {
18468: $changes->{'cancreate'} = ['recaptchakeys'];
18469: }
1.368 raeburn 18470: } elsif ($container eq 'passwords') {
18471: $changes->{'reset'} = 1;
1.169 raeburn 18472: } else {
1.210 raeburn 18473: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 18474: }
18475: }
18476: return;
18477: }
18478:
1.33 raeburn 18479: sub modify_usermodification {
18480: my ($dom,%domconfig) = @_;
1.224 raeburn 18481: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 18482: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18483: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 18484: if ($key eq 'selfcreate') {
18485: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
18486: } else {
18487: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
18488: }
1.33 raeburn 18489: }
18490: }
1.224 raeburn 18491: my @contexts = ('author','course');
1.33 raeburn 18492: my %context_title = (
18493: author => 'In author context',
18494: course => 'In course context',
18495: );
18496: my @fields = ('lastname','firstname','middlename','generation',
18497: 'permanentemail','id');
18498: my %roles = (
18499: author => ['ca','aa'],
18500: course => ['st','ep','ta','in','cr'],
18501: );
18502: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18503: foreach my $context (@contexts) {
18504: foreach my $role (@{$roles{$context}}) {
18505: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
18506: foreach my $item (@fields) {
18507: if (grep(/^\Q$item\E$/,@modifiable)) {
18508: $modifyhash{$context}{$role}{$item} = 1;
18509: } else {
18510: $modifyhash{$context}{$role}{$item} = 0;
18511: }
18512: }
18513: }
18514: if (ref($curr_usermodification{$context}) eq 'HASH') {
18515: foreach my $role (@{$roles{$context}}) {
18516: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
18517: foreach my $field (@fields) {
18518: if ($modifyhash{$context}{$role}{$field} ne
18519: $curr_usermodification{$context}{$role}{$field}) {
18520: push(@{$changes{$context}},$role);
18521: last;
18522: }
18523: }
18524: }
18525: }
18526: } else {
18527: foreach my $context (@contexts) {
18528: foreach my $role (@{$roles{$context}}) {
18529: push(@{$changes{$context}},$role);
18530: }
18531: }
18532: }
18533: }
18534: my %usermodification_hash = (
18535: usermodification => \%modifyhash,
18536: );
18537: my $putresult = &Apache::lonnet::put_dom('configuration',
18538: \%usermodification_hash,$dom);
18539: if ($putresult eq 'ok') {
18540: if (keys(%changes) > 0) {
18541: $resulttext = &mt('Changes made: ').'<ul>';
18542: foreach my $context (@contexts) {
18543: if (ref($changes{$context}) eq 'ARRAY') {
18544: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
18545: if (ref($changes{$context}) eq 'ARRAY') {
18546: foreach my $role (@{$changes{$context}}) {
18547: my $rolename;
1.224 raeburn 18548: if ($role eq 'cr') {
18549: $rolename = &mt('Custom');
1.33 raeburn 18550: } else {
1.224 raeburn 18551: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 18552: }
18553: my @modifiable;
1.224 raeburn 18554: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 18555: foreach my $field (@fields) {
18556: if ($modifyhash{$context}{$role}{$field}) {
18557: push(@modifiable,$fieldtitles{$field});
18558: }
18559: }
18560: if (@modifiable > 0) {
18561: $resulttext .= join(', ',@modifiable);
18562: } else {
18563: $resulttext .= &mt('none');
18564: }
18565: $resulttext .= '</li>';
18566: }
18567: $resulttext .= '</ul></li>';
18568: }
18569: }
18570: }
18571: $resulttext .= '</ul>';
18572: } else {
18573: $resulttext = &mt('No changes made to user modification settings');
18574: }
18575: } else {
18576: $resulttext = '<span class="LC_error">'.
18577: &mt('An error occurred: [_1]',$putresult).'</span>';
18578: }
18579: return $resulttext;
18580: }
18581:
1.43 raeburn 18582: sub modify_defaults {
1.212 raeburn 18583: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 18584: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 18585: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 18586: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 18587: 'portal_def');
1.325 raeburn 18588: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 18589: foreach my $item (@items) {
18590: $newvalues{$item} = $env{'form.'.$item};
18591: if ($item eq 'auth_def') {
18592: if ($newvalues{$item} ne '') {
18593: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
18594: push(@errors,$item);
18595: }
18596: }
18597: } elsif ($item eq 'lang_def') {
18598: if ($newvalues{$item} ne '') {
18599: if ($newvalues{$item} =~ /^(\w+)/) {
18600: my $langcode = $1;
1.103 raeburn 18601: if ($langcode ne 'x_chef') {
18602: if (code2language($langcode) eq '') {
18603: push(@errors,$item);
18604: }
1.43 raeburn 18605: }
18606: } else {
18607: push(@errors,$item);
18608: }
18609: }
1.54 raeburn 18610: } elsif ($item eq 'timezone_def') {
18611: if ($newvalues{$item} ne '') {
1.62 raeburn 18612: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 18613: push(@errors,$item);
18614: }
18615: }
1.68 raeburn 18616: } elsif ($item eq 'datelocale_def') {
18617: if ($newvalues{$item} ne '') {
18618: my @datelocale_ids = DateTime::Locale->ids();
18619: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
18620: push(@errors,$item);
18621: }
18622: }
1.141 raeburn 18623: } elsif ($item eq 'portal_def') {
18624: if ($newvalues{$item} ne '') {
18625: 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])\/?$/) {
18626: push(@errors,$item);
18627: }
18628: }
1.43 raeburn 18629: }
18630: if (grep(/^\Q$item\E$/,@errors)) {
18631: $newvalues{$item} = $domdefaults{$item};
18632: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
18633: $changes{$item} = 1;
18634: }
1.72 raeburn 18635: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 18636: }
1.354 raeburn 18637: my %staticdefaults = (
18638: 'intauth_cost' => 10,
18639: 'intauth_check' => 0,
18640: 'intauth_switch' => 0,
18641: );
18642: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
18643: if (exists($domdefaults{$item})) {
18644: $newvalues{$item} = $domdefaults{$item};
18645: } else {
18646: $newvalues{$item} = $staticdefaults{$item};
18647: }
18648: }
1.43 raeburn 18649: my %defaults_hash = (
1.72 raeburn 18650: defaults => \%newvalues,
18651: );
1.43 raeburn 18652: my $title = &defaults_titles();
1.236 raeburn 18653:
18654: my $currinststatus;
18655: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18656: $currinststatus = $domconfig{'inststatus'};
18657: } else {
18658: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18659: $currinststatus = {
18660: inststatustypes => $usertypes,
18661: inststatusorder => $types,
18662: inststatusguest => [],
18663: };
18664: }
18665: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
18666: my @allpos;
18667: my %alltypes;
1.305 raeburn 18668: my @inststatusguest;
18669: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
18670: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
18671: unless (grep(/^\Q$type\E$/,@todelete)) {
18672: push(@inststatusguest,$type);
18673: }
18674: }
18675: }
18676: my ($currtitles,$currorder);
1.236 raeburn 18677: if (ref($currinststatus) eq 'HASH') {
18678: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
18679: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
18680: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
18681: if ($currinststatus->{inststatustypes}->{$type} ne '') {
18682: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
18683: }
18684: }
18685: unless (grep(/^\Q$type\E$/,@todelete)) {
18686: my $position = $env{'form.inststatus_pos_'.$type};
18687: $position =~ s/\D+//g;
18688: $allpos[$position] = $type;
18689: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18690: $alltypes{$type} =~ s/`//g;
18691: }
18692: }
18693: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18694: $currtitles =~ s/,$//;
18695: }
18696: }
18697: if ($env{'form.addinststatus'}) {
18698: my $newtype = $env{'form.addinststatus'};
18699: $newtype =~ s/\W//g;
18700: unless (exists($alltypes{$newtype})) {
18701: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18702: $alltypes{$newtype} =~ s/`//g;
18703: my $position = $env{'form.addinststatus_pos'};
18704: $position =~ s/\D+//g;
18705: if ($position ne '') {
18706: $allpos[$position] = $newtype;
18707: }
18708: }
18709: }
1.305 raeburn 18710: my @orderedstatus;
1.236 raeburn 18711: foreach my $type (@allpos) {
18712: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18713: push(@orderedstatus,$type);
18714: }
18715: }
18716: foreach my $type (keys(%alltypes)) {
18717: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18718: delete($alltypes{$type});
18719: }
18720: }
18721: $defaults_hash{'inststatus'} = {
18722: inststatustypes => \%alltypes,
18723: inststatusorder => \@orderedstatus,
1.305 raeburn 18724: inststatusguest => \@inststatusguest,
1.236 raeburn 18725: };
18726: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18727: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18728: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18729: }
18730: }
18731: if ($currorder ne join(',',@orderedstatus)) {
18732: $changes{'inststatus'}{'inststatusorder'} = 1;
18733: }
18734: my $newtitles;
18735: foreach my $item (@orderedstatus) {
18736: $newtitles .= $alltypes{$item}.',';
18737: }
18738: $newtitles =~ s/,$//;
18739: if ($currtitles ne $newtitles) {
18740: $changes{'inststatus'}{'inststatustypes'} = 1;
18741: }
1.43 raeburn 18742: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18743: $dom);
18744: if ($putresult eq 'ok') {
18745: if (keys(%changes) > 0) {
18746: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 18747: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18748: 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";
18749: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 18750: if ($item eq 'inststatus') {
18751: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 18752: if (@orderedstatus) {
1.236 raeburn 18753: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18754: foreach my $type (@orderedstatus) {
18755: $resulttext .= $alltypes{$type}.', ';
18756: }
18757: $resulttext =~ s/, $//;
18758: $resulttext .= '</li>';
1.305 raeburn 18759: } else {
18760: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 18761: }
18762: }
18763: } else {
18764: my $value = $env{'form.'.$item};
18765: if ($value eq '') {
18766: $value = &mt('none');
18767: } elsif ($item eq 'auth_def') {
18768: my %authnames = &authtype_names();
18769: my %shortauth = (
18770: internal => 'int',
18771: krb4 => 'krb4',
18772: krb5 => 'krb5',
18773: localauth => 'loc',
1.325 raeburn 18774: lti => 'lti',
1.236 raeburn 18775: );
18776: $value = $authnames{$shortauth{$value}};
18777: }
18778: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
18779: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 18780: }
18781: }
18782: $resulttext .= '</ul>';
18783: $mailmsgtext .= "\n";
18784: my $cachetime = 24*60*60;
1.72 raeburn 18785: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 18786: if (ref($lastactref) eq 'HASH') {
18787: $lastactref->{'domdefaults'} = 1;
18788: }
1.68 raeburn 18789: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 18790: my $notify = 1;
18791: if (ref($domconfig{'contacts'}) eq 'HASH') {
18792: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18793: $notify = 0;
18794: }
18795: }
18796: if ($notify) {
18797: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18798: "LON-CAPA Domain Settings Change - $dom",
18799: $mailmsgtext);
18800: }
1.54 raeburn 18801: }
1.43 raeburn 18802: } else {
1.54 raeburn 18803: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18804: }
18805: } else {
18806: $resulttext = '<span class="LC_error">'.
18807: &mt('An error occurred: [_1]',$putresult).'</span>';
18808: }
18809: if (@errors > 0) {
18810: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18811: foreach my $item (@errors) {
18812: $resulttext .= ' "'.$title->{$item}.'",';
18813: }
18814: $resulttext =~ s/,$//;
18815: }
18816: return $resulttext;
18817: }
18818:
1.46 raeburn 18819: sub modify_scantron {
1.205 raeburn 18820: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18821: my ($resulttext,%confhash,%changes,$errors);
18822: my $custom = 'custom.tab';
18823: my $default = 'default.tab';
18824: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 18825: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18826: &config_check($dom,$confname,$servadm);
18827: if ($env{'form.scantronformat.filename'} ne '') {
18828: my $error;
18829: if ($configuserok eq 'ok') {
18830: if ($switchserver) {
1.130 raeburn 18831: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18832: } else {
18833: if ($author_ok eq 'ok') {
18834: my ($result,$scantronurl) =
18835: &publishlogo($r,'upload','scantronformat',$dom,
18836: $confname,'scantron','','',$custom);
18837: if ($result eq 'ok') {
18838: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18839: $changes{'scantronformat'} = 1;
1.46 raeburn 18840: } else {
18841: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18842: }
18843: } else {
18844: $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);
18845: }
18846: }
18847: } else {
18848: $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);
18849: }
18850: if ($error) {
18851: &Apache::lonnet::logthis($error);
18852: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18853: }
18854: }
1.48 raeburn 18855: if (ref($domconfig{'scantron'}) eq 'HASH') {
18856: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18857: if ($env{'form.scantronformat_del'}) {
18858: $confhash{'scantron'}{'scantronformat'} = '';
18859: $changes{'scantronformat'} = 1;
1.347 raeburn 18860: } else {
18861: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 18862: }
18863: }
18864: }
1.347 raeburn 18865: my @options = ('hdr','pad','rem');
1.346 raeburn 18866: my @fields = &scantroncsv_fields();
18867: my %titles = &scantronconfig_titles();
1.347 raeburn 18868: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 18869: my ($newdat,$currdat,%newcol,%currcol);
18870: if (grep(/^dat$/,@formats)) {
18871: $confhash{'scantron'}{config}{dat} = 1;
18872: $newdat = 1;
18873: } else {
18874: $newdat = 0;
18875: }
18876: if (grep(/^csv$/,@formats)) {
18877: my %bynum;
18878: foreach my $field (@fields) {
18879: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18880: my $posscol = $1;
18881: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 18882: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 18883: $bynum{$posscol} = $field;
18884: $newcol{$field} = $posscol;
18885: }
18886: }
18887: }
1.347 raeburn 18888: if (keys(%newcol)) {
18889: foreach my $option (@options) {
18890: if ($env{'form.scantroncsv_'.$option}) {
18891: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18892: }
18893: }
18894: }
1.346 raeburn 18895: }
18896: $currdat = 1;
18897: if (ref($domconfig{'scantron'}) eq 'HASH') {
18898: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 18899: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 18900: $currdat = 0;
18901: }
18902: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18903: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18904: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18905: }
1.346 raeburn 18906: }
18907: }
18908: }
18909: if ($currdat != $newdat) {
18910: $changes{'config'} = 1;
18911: } else {
18912: foreach my $field (@fields) {
18913: if ($currcol{$field} ne '') {
18914: if ($currcol{$field} ne $newcol{$field}) {
18915: $changes{'config'} = 1;
18916: last;
1.347 raeburn 18917: }
1.346 raeburn 18918: } elsif ($newcol{$field} ne '') {
18919: $changes{'config'} = 1;
18920: last;
18921: }
18922: }
18923: }
1.46 raeburn 18924: if (keys(%confhash) > 0) {
18925: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18926: $dom);
18927: if ($putresult eq 'ok') {
18928: if (keys(%changes) > 0) {
1.48 raeburn 18929: if (ref($confhash{'scantron'}) eq 'HASH') {
18930: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 18931: if ($changes{'scantronformat'}) {
18932: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18933: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18934: } else {
18935: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18936: }
18937: }
1.347 raeburn 18938: if ($changes{'config'}) {
1.346 raeburn 18939: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18940: if ($confhash{'scantron'}{'config'}{'dat'}) {
18941: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18942: }
18943: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 18944: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18945: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18946: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18947: foreach my $field (@fields) {
18948: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18949: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18950: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18951: }
18952: }
18953: $resulttext .= '</ul></li>';
18954: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18955: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18956: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18957: foreach my $option (@options) {
18958: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18959: $resulttext .= '<li>'.$titles{$option}.'</li>';
18960: }
18961: }
18962: $resulttext .= '</ul></li>';
18963: }
1.346 raeburn 18964: }
18965: }
18966: }
18967: }
18968: } else {
18969: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18970: }
1.46 raeburn 18971: }
1.48 raeburn 18972: $resulttext .= '</ul>';
18973: } else {
1.130 raeburn 18974: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18975: }
18976: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 18977: if (ref($lastactref) eq 'HASH') {
18978: $lastactref->{'domainconfig'} = 1;
18979: }
1.46 raeburn 18980: } else {
1.346 raeburn 18981: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18982: }
18983: } else {
18984: $resulttext = '<span class="LC_error">'.
18985: &mt('An error occurred: [_1]',$putresult).'</span>';
18986: }
18987: } else {
1.130 raeburn 18988: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 18989: }
18990: if ($errors) {
1.353 raeburn 18991: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18992: $errors.'</ul></p>';
1.46 raeburn 18993: }
18994: return $resulttext;
18995: }
18996:
1.48 raeburn 18997: sub modify_coursecategories {
1.239 raeburn 18998: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18999: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19000: $cathash);
1.48 raeburn 19001: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19002: my @catitems = ('unauth','auth');
19003: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19004: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19005: $cathash = $domconfig{'coursecategories'}{'cats'};
19006: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19007: $changes{'togglecats'} = 1;
19008: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19009: }
19010: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19011: $changes{'categorize'} = 1;
19012: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19013: }
1.120 raeburn 19014: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19015: $changes{'togglecatscomm'} = 1;
19016: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19017: }
19018: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19019: $changes{'categorizecomm'} = 1;
19020: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19021:
19022: }
19023: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19024: $changes{'togglecatsplace'} = 1;
19025: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19026: }
19027: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19028: $changes{'categorizeplace'} = 1;
19029: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19030: }
1.238 raeburn 19031: foreach my $item (@catitems) {
19032: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19033: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19034: $changes{$item} = 1;
19035: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19036: }
19037: }
19038: }
1.57 raeburn 19039: } else {
19040: $changes{'togglecats'} = 1;
19041: $changes{'categorize'} = 1;
1.124 raeburn 19042: $changes{'togglecatscomm'} = 1;
19043: $changes{'categorizecomm'} = 1;
1.272 raeburn 19044: $changes{'togglecatsplace'} = 1;
19045: $changes{'categorizeplace'} = 1;
1.87 raeburn 19046: $domconfig{'coursecategories'} = {
19047: togglecats => $env{'form.togglecats'},
19048: categorize => $env{'form.categorize'},
1.124 raeburn 19049: togglecatscomm => $env{'form.togglecatscomm'},
19050: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19051: togglecatsplace => $env{'form.togglecatsplace'},
19052: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19053: };
1.238 raeburn 19054: foreach my $item (@catitems) {
19055: if ($env{'form.coursecat_'.$item} ne 'std') {
19056: $changes{$item} = 1;
19057: }
19058: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19059: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19060: }
19061: }
1.57 raeburn 19062: }
19063: if (ref($cathash) eq 'HASH') {
19064: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19065: push (@deletecategory,'instcode::0');
19066: }
1.120 raeburn 19067: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19068: push(@deletecategory,'communities::0');
19069: }
1.272 raeburn 19070: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19071: push(@deletecategory,'placement::0');
19072: }
1.48 raeburn 19073: }
1.57 raeburn 19074: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19075: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19076: if (@deletecategory > 0) {
19077: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19078: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19079: foreach my $item (@deletecategory) {
1.57 raeburn 19080: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19081: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19082: $deletions{$item} = 1;
1.57 raeburn 19083: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19084: }
19085: }
19086: }
1.57 raeburn 19087: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19088: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19089: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19090: $reorderings{$item} = 1;
1.57 raeburn 19091: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19092: }
19093: if ($env{'form.addcategory_name_'.$item} ne '') {
19094: my $newcat = $env{'form.addcategory_name_'.$item};
19095: my $newdepth = $depth+1;
19096: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19097: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19098: $adds{$newitem} = 1;
19099: }
19100: if ($env{'form.subcat_'.$item} ne '') {
19101: my $newcat = $env{'form.subcat_'.$item};
19102: my $newdepth = $depth+1;
19103: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19104: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19105: $adds{$newitem} = 1;
19106: }
19107: }
19108: }
19109: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19110: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19111: my $newitem = 'instcode::0';
1.57 raeburn 19112: if ($cathash->{$newitem} eq '') {
19113: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19114: $adds{$newitem} = 1;
19115: }
19116: } else {
19117: my $newitem = 'instcode::0';
1.57 raeburn 19118: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19119: $adds{$newitem} = 1;
19120: }
19121: }
1.120 raeburn 19122: if ($env{'form.communities'} eq '1') {
19123: if (ref($cathash) eq 'HASH') {
19124: my $newitem = 'communities::0';
19125: if ($cathash->{$newitem} eq '') {
19126: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19127: $adds{$newitem} = 1;
19128: }
19129: } else {
19130: my $newitem = 'communities::0';
19131: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19132: $adds{$newitem} = 1;
19133: }
19134: }
1.272 raeburn 19135: if ($env{'form.placement'} eq '1') {
19136: if (ref($cathash) eq 'HASH') {
19137: my $newitem = 'placement::0';
19138: if ($cathash->{$newitem} eq '') {
19139: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19140: $adds{$newitem} = 1;
19141: }
19142: } else {
19143: my $newitem = 'placement::0';
19144: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19145: $adds{$newitem} = 1;
19146: }
19147: }
1.48 raeburn 19148: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19149: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19150: ($env{'form.addcategory_name'} ne 'communities') &&
19151: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19152: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19153: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19154: $adds{$newitem} = 1;
19155: }
1.48 raeburn 19156: }
1.57 raeburn 19157: my $putresult;
1.48 raeburn 19158: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19159: if (keys(%deletions) > 0) {
19160: foreach my $key (keys(%deletions)) {
19161: if ($predelallitems{$key} ne '') {
19162: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19163: }
19164: }
19165: }
19166: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19167: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19168: if (ref($chkcats[0]) eq 'ARRAY') {
19169: my $depth = 0;
19170: my $chg = 0;
19171: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19172: my $name = $chkcats[0][$i];
19173: my $item;
19174: if ($name eq '') {
19175: $chg ++;
19176: } else {
19177: $item = &escape($name).'::0';
19178: if ($chg) {
1.57 raeburn 19179: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19180: }
19181: $depth ++;
1.57 raeburn 19182: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19183: $depth --;
19184: }
19185: }
19186: }
1.57 raeburn 19187: }
19188: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19189: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19190: if ($putresult eq 'ok') {
1.57 raeburn 19191: my %title = (
1.120 raeburn 19192: togglecats => 'Show/Hide a course in catalog',
19193: categorize => 'Assign a category to a course',
19194: togglecatscomm => 'Show/Hide a community in catalog',
19195: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19196: );
19197: my %level = (
1.120 raeburn 19198: dom => 'set in Domain ("Modify Course/Community")',
19199: crs => 'set in Course ("Course Configuration")',
19200: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19201: none => 'No catalog',
19202: std => 'Standard catalog',
19203: domonly => 'Domain-only catalog',
19204: codesrch => 'Code search form',
1.57 raeburn 19205: );
1.48 raeburn 19206: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19207: if ($changes{'togglecats'}) {
19208: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19209: }
19210: if ($changes{'categorize'}) {
19211: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19212: }
1.120 raeburn 19213: if ($changes{'togglecatscomm'}) {
19214: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19215: }
19216: if ($changes{'categorizecomm'}) {
19217: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19218: }
1.238 raeburn 19219: if ($changes{'unauth'}) {
19220: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19221: }
19222: if ($changes{'auth'}) {
19223: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19224: }
1.57 raeburn 19225: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19226: my $cathash;
19227: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19228: $cathash = $domconfig{'coursecategories'}{'cats'};
19229: } else {
19230: $cathash = {};
19231: }
19232: my (@cats,@trails,%allitems);
19233: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19234: if (keys(%deletions) > 0) {
19235: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19236: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19237: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19238: }
19239: $resulttext .= '</ul></li>';
19240: }
19241: if (keys(%reorderings) > 0) {
19242: my %sort_by_trail;
19243: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19244: foreach my $key (keys(%reorderings)) {
19245: if ($allitems{$key} ne '') {
19246: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19247: }
1.48 raeburn 19248: }
1.57 raeburn 19249: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19250: $resulttext .= '<li>'.$trails[$trail].'</li>';
19251: }
19252: $resulttext .= '</ul></li>';
1.48 raeburn 19253: }
1.57 raeburn 19254: if (keys(%adds) > 0) {
19255: my %sort_by_trail;
19256: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19257: foreach my $key (keys(%adds)) {
19258: if ($allitems{$key} ne '') {
19259: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19260: }
19261: }
19262: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19263: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19264: }
1.57 raeburn 19265: $resulttext .= '</ul></li>';
1.48 raeburn 19266: }
1.364 raeburn 19267: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19268: if (ref($lastactref) eq 'HASH') {
19269: $lastactref->{'cats'} = 1;
19270: }
1.48 raeburn 19271: }
19272: $resulttext .= '</ul>';
1.239 raeburn 19273: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19275: if ($changes{'auth'}) {
19276: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19277: }
19278: if ($changes{'unauth'}) {
19279: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19280: }
19281: my $cachetime = 24*60*60;
19282: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19283: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19284: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19285: }
19286: }
1.48 raeburn 19287: } else {
19288: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19289: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19290: }
19291: } else {
1.120 raeburn 19292: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19293: }
19294: return $resulttext;
19295: }
19296:
1.69 raeburn 19297: sub modify_serverstatuses {
19298: my ($dom,%domconfig) = @_;
19299: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19300: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19301: %currserverstatus = %{$domconfig{'serverstatuses'}};
19302: }
19303: my @pages = &serverstatus_pages();
19304: foreach my $type (@pages) {
19305: $newserverstatus{$type}{'namedusers'} = '';
19306: $newserverstatus{$type}{'machines'} = '';
19307: if (defined($env{'form.'.$type.'_namedusers'})) {
19308: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19309: my @okusers;
19310: foreach my $user (@users) {
19311: my ($uname,$udom) = split(/:/,$user);
19312: if (($udom =~ /^$match_domain$/) &&
19313: (&Apache::lonnet::domain($udom)) &&
19314: ($uname =~ /^$match_username$/)) {
19315: if (!grep(/^\Q$user\E/,@okusers)) {
19316: push(@okusers,$user);
19317: }
19318: }
19319: }
19320: if (@okusers > 0) {
19321: @okusers = sort(@okusers);
19322: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19323: }
19324: }
19325: if (defined($env{'form.'.$type.'_machines'})) {
19326: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19327: my @okmachines;
19328: foreach my $ip (@machines) {
19329: my @parts = split(/\./,$ip);
19330: next if (@parts < 4);
19331: my $badip = 0;
19332: for (my $i=0; $i<4; $i++) {
19333: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19334: $badip = 1;
19335: last;
19336: }
19337: }
19338: if (!$badip) {
19339: push(@okmachines,$ip);
19340: }
19341: }
19342: @okmachines = sort(@okmachines);
19343: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19344: }
19345: }
19346: my %serverstatushash = (
19347: serverstatuses => \%newserverstatus,
19348: );
19349: foreach my $type (@pages) {
1.83 raeburn 19350: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19351: my (@current,@new);
1.83 raeburn 19352: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19353: if ($currserverstatus{$type}{$setting} ne '') {
19354: @current = split(/,/,$currserverstatus{$type}{$setting});
19355: }
19356: }
19357: if ($newserverstatus{$type}{$setting} ne '') {
19358: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19359: }
19360: if (@current > 0) {
19361: if (@new > 0) {
19362: foreach my $item (@current) {
19363: if (!grep(/^\Q$item\E$/,@new)) {
19364: $changes{$type}{$setting} = 1;
1.82 raeburn 19365: last;
19366: }
19367: }
1.84 raeburn 19368: foreach my $item (@new) {
19369: if (!grep(/^\Q$item\E$/,@current)) {
19370: $changes{$type}{$setting} = 1;
19371: last;
1.82 raeburn 19372: }
19373: }
19374: } else {
1.83 raeburn 19375: $changes{$type}{$setting} = 1;
1.69 raeburn 19376: }
1.83 raeburn 19377: } elsif (@new > 0) {
19378: $changes{$type}{$setting} = 1;
1.69 raeburn 19379: }
19380: }
19381: }
19382: if (keys(%changes) > 0) {
1.81 raeburn 19383: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19384: my $putresult = &Apache::lonnet::put_dom('configuration',
19385: \%serverstatushash,$dom);
19386: if ($putresult eq 'ok') {
19387: $resulttext .= &mt('Changes made:').'<ul>';
19388: foreach my $type (@pages) {
1.84 raeburn 19389: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19390: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19391: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19392: if ($newserverstatus{$type}{'namedusers'} eq '') {
19393: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19394: } else {
19395: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19396: }
1.84 raeburn 19397: }
19398: if ($changes{$type}{'machines'}) {
1.69 raeburn 19399: if ($newserverstatus{$type}{'machines'} eq '') {
19400: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19401: } else {
19402: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19403: }
19404:
19405: }
19406: $resulttext .= '</ul></li>';
19407: }
19408: }
19409: $resulttext .= '</ul>';
19410: } else {
19411: $resulttext = '<span class="LC_error">'.
19412: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19413:
19414: }
19415: } else {
19416: $resulttext = &mt('No changes made to access to server status pages');
19417: }
19418: return $resulttext;
19419: }
19420:
1.118 jms 19421: sub modify_helpsettings {
1.285 raeburn 19422: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19423: my ($resulttext,$errors,%changes,%helphash);
19424: my %defaultchecked = ('submitbugs' => 'on');
19425: my @offon = ('off','on');
1.118 jms 19426: my @toggles = ('submitbugs');
1.285 raeburn 19427: my %current = ('submitbugs' => '',
19428: 'adhoc' => {},
19429: );
1.118 jms 19430: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19431: %current = %{$domconfig{'helpsettings'}};
19432: }
1.285 raeburn 19433: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19434: foreach my $item (@toggles) {
19435: if ($defaultchecked{$item} eq 'on') {
19436: if ($current{$item} eq '') {
19437: if ($env{'form.'.$item} eq '0') {
19438: $changes{$item} = 1;
19439: }
19440: } elsif ($current{$item} ne $env{'form.'.$item}) {
19441: $changes{$item} = 1;
19442: }
19443: } elsif ($defaultchecked{$item} eq 'off') {
19444: if ($current{$item} eq '') {
19445: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 19446: $changes{$item} = 1;
19447: }
1.282 raeburn 19448: } elsif ($current{$item} ne $env{'form.'.$item}) {
19449: $changes{$item} = 1;
19450: }
19451: }
19452: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
19453: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
19454: }
19455: }
1.285 raeburn 19456: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 19457: my $confname = $dom.'-domainconfig';
19458: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 19459: my (@allpos,%newsettings,%changedprivs,$newrole);
19460: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 19461: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 19462: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 19463: my %lt = &Apache::lonlocal::texthash(
19464: s => 'system',
19465: d => 'domain',
19466: order => 'Display order',
19467: access => 'Role usage',
1.291 raeburn 19468: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 19469: dh => 'All with domain helpdesk role',
19470: da => 'All with domain helpdesk assistant role',
1.285 raeburn 19471: none => 'None',
19472: status => 'Determined based on institutional status',
19473: inc => 'Include all, but exclude specific personnel',
19474: exc => 'Exclude all, but include specific personnel',
19475: );
19476: for (my $num=0; $num<=$maxnum; $num++) {
19477: my ($prefix,$identifier,$rolename,%curr);
19478: if ($num == $maxnum) {
19479: next unless ($env{'form.newcusthelp'} == $maxnum);
19480: $identifier = 'custhelp'.$num;
19481: $prefix = 'helproles_'.$num;
19482: $rolename = $env{'form.custhelpname'.$num};
19483: $rolename=~s/[^A-Za-z0-9]//gs;
19484: next if ($rolename eq '');
19485: next if (exists($existing{'rolesdef_'.$rolename}));
19486: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19487: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19488: $newprivs{'c'},$confname,$dom);
19489: if ($result ne 'ok') {
19490: $errors .= '<li><span class="LC_error">'.
19491: &mt('An error occurred storing the new custom role: [_1]',
19492: $result).'</span></li>';
19493: next;
19494: } else {
19495: $changedprivs{$rolename} = \%newprivs;
19496: $newrole = $rolename;
19497: }
19498: } else {
19499: $prefix = 'helproles_'.$num;
19500: $rolename = $env{'form.'.$prefix};
19501: next if ($rolename eq '');
19502: next unless (exists($existing{'rolesdef_'.$rolename}));
19503: $identifier = 'custhelp'.$num;
19504: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
19505: my %currprivs;
1.289 raeburn 19506: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 19507: split(/\_/,$existing{'rolesdef_'.$rolename});
19508: foreach my $level ('c','d','s') {
19509: if ($newprivs{$level} ne $currprivs{$level}) {
19510: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
19511: $newprivs{'c'},$confname,$dom);
19512: if ($result ne 'ok') {
19513: $errors .= '<li><span class="LC_error">'.
19514: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
19515: $rolename,$result).'</span></li>';
19516: } else {
19517: $changedprivs{$rolename} = \%newprivs;
19518: }
19519: last;
19520: }
19521: }
19522: if (ref($current{'adhoc'}) eq 'HASH') {
19523: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19524: %curr = %{$current{'adhoc'}{$rolename}};
19525: }
19526: }
19527: }
19528: my $newpos = $env{'form.'.$prefix.'_pos'};
19529: $newpos =~ s/\D+//g;
19530: $allpos[$newpos] = $rolename;
19531: my $newdesc = $env{'form.'.$prefix.'_desc'};
19532: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
19533: if ($curr{'desc'}) {
19534: if ($curr{'desc'} ne $newdesc) {
19535: $changes{'customrole'}{$rolename}{'desc'} = 1;
19536: $newsettings{$rolename}{'desc'} = $newdesc;
19537: }
19538: } elsif ($newdesc ne '') {
19539: $changes{'customrole'}{$rolename}{'desc'} = 1;
19540: $newsettings{$rolename}{'desc'} = $newdesc;
19541: }
19542: my $access = $env{'form.'.$prefix.'_access'};
19543: if (grep(/^\Q$access\E$/,@accesstypes)) {
19544: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
19545: if ($access eq 'status') {
19546: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
19547: if (scalar(@statuses) == 0) {
1.289 raeburn 19548: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 19549: } else {
19550: my (@shownstatus,$numtypes);
19551: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19552: if (ref($types) eq 'ARRAY') {
19553: $numtypes = scalar(@{$types});
19554: foreach my $type (sort(@statuses)) {
19555: if ($type eq 'default') {
19556: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19557: } elsif (grep(/^\Q$type\E$/,@{$types})) {
19558: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
19559: push(@shownstatus,$usertypes->{$type});
19560: }
19561: }
19562: }
19563: if (grep(/^default$/,@statuses)) {
19564: push(@shownstatus,$othertitle);
19565: }
19566: if (scalar(@shownstatus) == 1+$numtypes) {
19567: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
19568: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
19569: } else {
19570: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
19571: if (ref($curr{'status'}) eq 'ARRAY') {
19572: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19573: if (@diffs) {
19574: $changes{'customrole'}{$rolename}{$access} = 1;
19575: }
19576: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19577: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 19578: }
1.166 raeburn 19579: }
19580: }
1.285 raeburn 19581: } elsif (($access eq 'inc') || ($access eq 'exc')) {
19582: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
19583: my @newspecstaff;
19584: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
19585: foreach my $person (sort(@personnel)) {
19586: if ($domhelpdesk{$person}) {
19587: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
19588: }
19589: }
19590: if (ref($curr{$access}) eq 'ARRAY') {
19591: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
19592: if (@diffs) {
19593: $changes{'customrole'}{$rolename}{$access} = 1;
19594: }
19595: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19596: $changes{'customrole'}{$rolename}{$access} = 1;
19597: }
19598: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
19599: my ($uname,$udom) = split(/:/,$person);
19600: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
19601: }
19602: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 19603: }
1.285 raeburn 19604: } else {
19605: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
19606: }
19607: unless ($curr{'access'} eq $access) {
19608: $changes{'customrole'}{$rolename}{'access'} = 1;
19609: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 19610: }
19611: }
1.285 raeburn 19612: if (@allpos > 0) {
19613: my $idx = 0;
19614: foreach my $rolename (@allpos) {
19615: if ($rolename ne '') {
19616: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
19617: if (ref($current{'adhoc'}) eq 'HASH') {
19618: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
19619: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
19620: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 19621: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 19622: }
19623: }
1.282 raeburn 19624: }
1.285 raeburn 19625: $idx ++;
1.166 raeburn 19626: }
19627: }
1.118 jms 19628: }
1.123 jms 19629: my $putresult;
19630: if (keys(%changes) > 0) {
1.166 raeburn 19631: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 19632: if ($putresult eq 'ok') {
1.285 raeburn 19633: if (ref($helphash{'helpsettings'}) eq 'HASH') {
19634: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
19635: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
19636: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
19637: }
19638: }
19639: my $cachetime = 24*60*60;
19640: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19641: if (ref($lastactref) eq 'HASH') {
19642: $lastactref->{'domdefaults'} = 1;
19643: }
19644: } else {
19645: $errors .= '<li><span class="LC_error">'.
19646: &mt('An error occurred storing the settings: [_1]',
19647: $putresult).'</span></li>';
19648: }
19649: }
19650: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
19651: $resulttext = &mt('Changes made:').'<ul>';
19652: my (%shownprivs,@levelorder);
19653: @levelorder = ('c','d','s');
19654: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 19655: foreach my $item (sort(keys(%changes))) {
19656: if ($item eq 'submitbugs') {
19657: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
19658: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
19659: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 19660: } elsif ($item eq 'customrole') {
19661: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 19662: my @keyorder = ('order','desc','access','status','exc','inc');
19663: my %keytext = &Apache::lonlocal::texthash(
19664: order => 'Order',
19665: desc => 'Role description',
19666: access => 'Role usage',
1.300 droeschl 19667: status => 'Allowed institutional types',
1.285 raeburn 19668: exc => 'Allowed personnel',
19669: inc => 'Disallowed personnel',
19670: );
1.282 raeburn 19671: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 19672: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
19673: if ($role eq $newrole) {
19674: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
19675: $role).'<ul>';
19676: } else {
19677: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19678: $role).'<ul>';
19679: }
19680: foreach my $key (@keyorder) {
19681: if ($changes{'customrole'}{$role}{$key}) {
19682: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19683: $keytext{$key},$newsettings{$role}{$key}).
19684: '</li>';
19685: }
19686: }
19687: if (ref($changedprivs{$role}) eq 'HASH') {
19688: $shownprivs{$role} = 1;
19689: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19690: foreach my $level (@levelorder) {
19691: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19692: next if ($item eq '');
19693: my ($priv) = split(/\&/,$item,2);
19694: if (&Apache::lonnet::plaintext($priv)) {
19695: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19696: unless ($level eq 'c') {
19697: $resulttext .= ' ('.$lt{$level}.')';
19698: }
19699: $resulttext .= '</li>';
19700: }
19701: }
19702: }
19703: $resulttext .= '</ul>';
19704: }
19705: $resulttext .= '</ul></li>';
19706: }
19707: }
19708: }
19709: }
19710: }
19711: }
19712: if (keys(%changedprivs)) {
19713: foreach my $role (sort(keys(%changedprivs))) {
19714: unless ($shownprivs{$role}) {
19715: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19716: $role).'<ul>'.
19717: '<li>'.&mt('Privileges set to :').'<ul>';
19718: foreach my $level (@levelorder) {
19719: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19720: next if ($item eq '');
19721: my ($priv) = split(/\&/,$item,2);
19722: if (&Apache::lonnet::plaintext($priv)) {
19723: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19724: unless ($level eq 'c') {
19725: $resulttext .= ' ('.$lt{$level}.')';
19726: }
19727: $resulttext .= '</li>';
19728: }
1.282 raeburn 19729: }
19730: }
1.285 raeburn 19731: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 19732: }
19733: }
19734: }
1.285 raeburn 19735: $resulttext .= '</ul>';
19736: } else {
19737: $resulttext = &mt('No changes made to help settings');
1.118 jms 19738: }
19739: if ($errors) {
1.168 raeburn 19740: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 19741: $errors.'</ul>';
1.118 jms 19742: }
19743: return $resulttext;
19744: }
19745:
1.121 raeburn 19746: sub modify_coursedefaults {
1.212 raeburn 19747: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19748: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 19749: my %defaultchecked = (
19750: 'canuse_pdfforms' => 'off',
19751: 'uselcmath' => 'on',
19752: 'usejsme' => 'on'
19753: );
19754: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 19755: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 19756: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
19757: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19758: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 19759: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 19760: my %staticdefaults = (
19761: anonsurvey_threshold => 10,
19762: uploadquota => 500,
1.257 raeburn 19763: postsubmit => 60,
1.276 raeburn 19764: mysqltables => 172800,
1.198 raeburn 19765: );
1.314 raeburn 19766: my %texoptions = (
19767: MathJax => 'MathJax',
19768: mimetex => &mt('Convert to Images'),
19769: tth => &mt('TeX to HTML'),
19770: );
1.121 raeburn 19771: $defaultshash{'coursedefaults'} = {};
19772:
19773: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19774: if ($domconfig{'coursedefaults'} eq '') {
19775: $domconfig{'coursedefaults'} = {};
19776: }
19777: }
19778:
19779: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19780: foreach my $item (@toggles) {
19781: if ($defaultchecked{$item} eq 'on') {
19782: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19783: ($env{'form.'.$item} eq '0')) {
19784: $changes{$item} = 1;
1.192 raeburn 19785: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19786: $changes{$item} = 1;
19787: }
19788: } elsif ($defaultchecked{$item} eq 'off') {
19789: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19790: ($env{'form.'.$item} eq '1')) {
19791: $changes{$item} = 1;
19792: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19793: $changes{$item} = 1;
19794: }
19795: }
19796: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19797: }
1.198 raeburn 19798: foreach my $item (@numbers) {
19799: my ($currdef,$newdef);
1.208 raeburn 19800: $newdef = $env{'form.'.$item};
1.198 raeburn 19801: if ($item eq 'anonsurvey_threshold') {
19802: $currdef = $domconfig{'coursedefaults'}{$item};
19803: $newdef =~ s/\D//g;
19804: if ($newdef eq '' || $newdef < 1) {
19805: $newdef = 1;
19806: }
19807: $defaultshash{'coursedefaults'}{$item} = $newdef;
19808: } else {
1.276 raeburn 19809: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
19810: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19811: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 19812: }
19813: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 19814: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 19815: }
19816: if ($currdef ne $newdef) {
19817: if ($item eq 'anonsurvey_threshold') {
19818: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19819: $changes{$item} = 1;
19820: }
1.276 raeburn 19821: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 19822: my $setting = $1;
1.276 raeburn 19823: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19824: $changes{$setting} = 1;
1.198 raeburn 19825: }
19826: }
1.139 raeburn 19827: }
19828: }
1.314 raeburn 19829: my $texengine;
19830: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19831: $texengine = $env{'form.texengine'};
1.349 raeburn 19832: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19833: if ($currdef eq '') {
19834: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 19835: $changes{'texengine'} = 1;
19836: }
1.349 raeburn 19837: } elsif ($currdef ne $texengine) {
1.314 raeburn 19838: $changes{'texengine'} = 1;
19839: }
19840: }
19841: if ($texengine ne '') {
19842: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19843: }
1.264 raeburn 19844: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19845: my @currclonecode;
19846: if (ref($currclone) eq 'HASH') {
19847: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19848: @currclonecode = @{$currclone->{'instcode'}};
19849: }
19850: }
19851: my $newclone;
1.289 raeburn 19852: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 19853: $newclone = $env{'form.canclone'};
19854: }
19855: if ($newclone eq 'instcode') {
19856: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19857: my (%codedefaults,@code_order,@clonecode);
19858: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19859: \@code_order);
19860: foreach my $item (@code_order) {
19861: if (grep(/^\Q$item\E$/,@newcodes)) {
19862: push(@clonecode,$item);
19863: }
19864: }
19865: if (@clonecode) {
19866: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19867: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19868: if (@diffs) {
19869: $changes{'canclone'} = 1;
19870: }
19871: } else {
19872: $newclone eq '';
19873: }
19874: } elsif ($newclone ne '') {
1.289 raeburn 19875: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19876: }
1.264 raeburn 19877: if ($newclone ne $currclone) {
19878: $changes{'canclone'} = 1;
19879: }
1.257 raeburn 19880: my %credits;
19881: foreach my $type (@types) {
19882: unless ($type eq 'community') {
19883: $credits{$type} = $env{'form.'.$type.'_credits'};
19884: $credits{$type} =~ s/[^\d.]+//g;
19885: }
19886: }
19887: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19888: ($env{'form.coursecredits'} eq '1')) {
19889: $changes{'coursecredits'} = 1;
19890: foreach my $type (keys(%credits)) {
19891: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19892: }
19893: } else {
1.289 raeburn 19894: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 19895: foreach my $type (@types) {
19896: unless ($type eq 'community') {
1.289 raeburn 19897: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 19898: $changes{'coursecredits'} = 1;
19899: }
19900: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19901: }
19902: }
19903: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19904: foreach my $type (@types) {
19905: unless ($type eq 'community') {
19906: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19907: $changes{'coursecredits'} = 1;
19908: last;
19909: }
19910: }
19911: }
19912: }
19913: }
19914: if ($env{'form.postsubmit'} eq '1') {
19915: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19916: my %currtimeout;
19917: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19918: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19919: $changes{'postsubmit'} = 1;
19920: }
19921: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19922: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19923: }
19924: } else {
19925: $changes{'postsubmit'} = 1;
19926: }
19927: foreach my $type (@types) {
19928: my $timeout = $env{'form.'.$type.'_timeout'};
19929: $timeout =~ s/\D//g;
19930: if ($timeout == $staticdefaults{'postsubmit'}) {
19931: $timeout = '';
19932: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19933: $timeout = '0';
19934: }
19935: unless ($timeout eq '') {
19936: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19937: }
19938: if (exists($currtimeout{$type})) {
19939: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 19940: $changes{'postsubmit'} = 1;
1.257 raeburn 19941: }
19942: } elsif ($timeout ne '') {
19943: $changes{'postsubmit'} = 1;
19944: }
19945: }
19946: } else {
19947: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19948: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19949: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19950: $changes{'postsubmit'} = 1;
19951: }
19952: } else {
19953: $changes{'postsubmit'} = 1;
19954: }
1.192 raeburn 19955: }
1.121 raeburn 19956: }
19957: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19958: $dom);
19959: if ($putresult eq 'ok') {
19960: if (keys(%changes) > 0) {
1.213 raeburn 19961: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 19962: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 19963: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 19964: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
19965: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 19966: if ($changes{$item}) {
19967: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19968: }
1.289 raeburn 19969: }
1.192 raeburn 19970: if ($changes{'coursecredits'}) {
19971: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 19972: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19973: $domdefaults{$type.'credits'} =
19974: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19975: }
19976: }
19977: }
19978: if ($changes{'postsubmit'}) {
19979: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19980: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19981: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19982: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19983: $domdefaults{$type.'postsubtimeout'} =
19984: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19985: }
19986: }
1.192 raeburn 19987: }
19988: }
1.198 raeburn 19989: if ($changes{'uploadquota'}) {
19990: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19991: foreach my $type (@types) {
19992: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19993: }
19994: }
19995: }
1.264 raeburn 19996: if ($changes{'canclone'}) {
19997: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19998: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19999: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20000: if (@clonecodes) {
20001: $domdefaults{'canclone'} = join('+',@clonecodes);
20002: }
20003: }
20004: } else {
20005: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20006: }
20007: }
1.121 raeburn 20008: my $cachetime = 24*60*60;
20009: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20010: if (ref($lastactref) eq 'HASH') {
20011: $lastactref->{'domdefaults'} = 1;
20012: }
1.121 raeburn 20013: }
20014: $resulttext = &mt('Changes made:').'<ul>';
20015: foreach my $item (sort(keys(%changes))) {
20016: if ($item eq 'canuse_pdfforms') {
20017: if ($env{'form.'.$item} eq '1') {
20018: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20019: } else {
20020: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20021: }
1.257 raeburn 20022: } elsif ($item eq 'uselcmath') {
20023: if ($env{'form.'.$item} eq '1') {
20024: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20025: } else {
20026: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20027: }
20028: } elsif ($item eq 'usejsme') {
20029: if ($env{'form.'.$item} eq '1') {
20030: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20031: } else {
1.289 raeburn 20032: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20033: }
1.314 raeburn 20034: } elsif ($item eq 'texengine') {
20035: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20036: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20037: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20038: }
1.139 raeburn 20039: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20040: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20041: } elsif ($item eq 'uploadquota') {
20042: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20043: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20044: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20045: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20046: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20047: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20048: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20049: '</ul>'.
20050: '</li>';
20051: } else {
20052: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20053: }
1.276 raeburn 20054: } elsif ($item eq 'mysqltables') {
20055: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20056: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20057: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20058: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20059: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20060: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20061: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20062: '</ul>'.
20063: '</li>';
20064: } else {
20065: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20066: }
1.257 raeburn 20067: } elsif ($item eq 'postsubmit') {
20068: if ($domdefaults{'postsubmit'} eq 'off') {
20069: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20070: } else {
20071: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20072: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20073: $resulttext .= &mt('durations:').'<ul>';
20074: foreach my $type (@types) {
20075: $resulttext .= '<li>';
20076: my $timeout;
20077: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20078: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20079: }
20080: my $display;
20081: if ($timeout eq '0') {
20082: $display = &mt('unlimited');
20083: } elsif ($timeout eq '') {
20084: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20085: } else {
20086: $display = &mt('[quant,_1,second]',$timeout);
20087: }
20088: if ($type eq 'community') {
20089: $resulttext .= &mt('Communities');
20090: } elsif ($type eq 'official') {
20091: $resulttext .= &mt('Official courses');
20092: } elsif ($type eq 'unofficial') {
20093: $resulttext .= &mt('Unofficial courses');
20094: } elsif ($type eq 'textbook') {
20095: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20096: } elsif ($type eq 'placement') {
20097: $resulttext .= &mt('Placement tests');
1.257 raeburn 20098: }
20099: $resulttext .= ' -- '.$display.'</li>';
20100: }
20101: $resulttext .= '</ul>';
20102: }
1.289 raeburn 20103: $resulttext .= '</li>';
1.257 raeburn 20104: }
1.192 raeburn 20105: } elsif ($item eq 'coursecredits') {
20106: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20107: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20108: ($domdefaults{'unofficialcredits'} eq '') &&
20109: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20110: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20111: } else {
20112: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20113: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20114: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20115: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20116: '</ul>'.
20117: '</li>';
20118: }
20119: } else {
20120: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20121: }
1.264 raeburn 20122: } elsif ($item eq 'canclone') {
20123: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20124: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20125: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20126: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20127: }
20128: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20129: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20130: } else {
1.289 raeburn 20131: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20132: }
1.140 raeburn 20133: }
1.121 raeburn 20134: }
20135: $resulttext .= '</ul>';
20136: } else {
20137: $resulttext = &mt('No changes made to course defaults');
20138: }
20139: } else {
20140: $resulttext = '<span class="LC_error">'.
20141: &mt('An error occurred: [_1]',$putresult).'</span>';
20142: }
20143: return $resulttext;
20144: }
20145:
1.231 raeburn 20146: sub modify_selfenrollment {
20147: my ($dom,$lastactref,%domconfig) = @_;
20148: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20149: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20150: my %titles = &tool_titles();
1.232 raeburn 20151: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20152: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20153: $ordered{'default'} = ['types','registered','approval','limit'];
20154:
20155: my (%roles,%shown,%toplevel);
20156: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20157:
20158: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20159: if ($domconfig{'selfenrollment'} eq '') {
20160: $domconfig{'selfenrollment'} = {};
20161: }
20162: }
20163: %toplevel = (
20164: admin => 'Configuration Rights',
20165: default => 'Default settings',
20166: validation => 'Validation of self-enrollment requests',
20167: );
1.233 raeburn 20168: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20169:
20170: if (ref($ordered{'admin'}) eq 'ARRAY') {
20171: foreach my $item (@{$ordered{'admin'}}) {
20172: foreach my $type (@types) {
20173: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20174: $selfenrollhash{'admin'}{$type}{$item} = 1;
20175: } else {
20176: $selfenrollhash{'admin'}{$type}{$item} = 0;
20177: }
20178: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20179: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20180: if ($selfenrollhash{'admin'}{$type}{$item} ne
20181: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20182: push(@{$changes{'admin'}{$type}},$item);
20183: }
20184: } else {
20185: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20186: push(@{$changes{'admin'}{$type}},$item);
20187: }
20188: }
20189: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20190: push(@{$changes{'admin'}{$type}},$item);
20191: }
20192: }
20193: }
20194: }
20195:
20196: foreach my $item (@{$ordered{'default'}}) {
20197: foreach my $type (@types) {
20198: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20199: if ($item eq 'types') {
20200: unless (($value eq 'all') || ($value eq 'dom')) {
20201: $value = '';
20202: }
20203: } elsif ($item eq 'registered') {
20204: unless ($value eq '1') {
20205: $value = 0;
20206: }
20207: } elsif ($item eq 'approval') {
20208: unless ($value =~ /^[012]$/) {
20209: $value = 0;
20210: }
20211: } else {
20212: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20213: $value = 'none';
20214: }
20215: }
20216: $selfenrollhash{'default'}{$type}{$item} = $value;
20217: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20218: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20219: if ($selfenrollhash{'default'}{$type}{$item} ne
20220: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20221: push(@{$changes{'default'}{$type}},$item);
20222: }
20223: } else {
20224: push(@{$changes{'default'}{$type}},$item);
20225: }
20226: } else {
20227: push(@{$changes{'default'}{$type}},$item);
20228: }
20229: if ($item eq 'limit') {
20230: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20231: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20232: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20233: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20234: }
20235: } else {
20236: $selfenrollhash{'default'}{$type}{'cap'} = '';
20237: }
20238: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20239: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20240: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20241: push(@{$changes{'default'}{$type}},'cap');
20242: }
20243: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20244: push(@{$changes{'default'}{$type}},'cap');
20245: }
20246: }
20247: }
20248: }
20249:
20250: foreach my $item (@{$itemsref}) {
20251: if ($item eq 'fields') {
20252: my @changed;
20253: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20254: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20255: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20256: }
20257: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20258: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20259: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20260: $domconfig{'selfenrollment'}{'validation'}{$item});
20261: } else {
20262: @changed = @{$selfenrollhash{'validation'}{$item}};
20263: }
20264: } else {
20265: @changed = @{$selfenrollhash{'validation'}{$item}};
20266: }
20267: if (@changed) {
20268: if ($selfenrollhash{'validation'}{$item}) {
20269: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20270: } else {
20271: $changes{'validation'}{$item} = &mt('None');
20272: }
20273: }
20274: } else {
20275: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20276: if ($item eq 'markup') {
20277: if ($env{'form.selfenroll_validation_'.$item}) {
20278: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20279: }
20280: }
20281: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20282: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20283: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20284: }
20285: }
20286: }
20287: }
20288:
20289: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20290: $dom);
20291: if ($putresult eq 'ok') {
20292: if (keys(%changes) > 0) {
20293: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20294: $resulttext = &mt('Changes made:').'<ul>';
20295: foreach my $key ('admin','default','validation') {
20296: if (ref($changes{$key}) eq 'HASH') {
20297: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20298: if ($key eq 'validation') {
20299: foreach my $item (@{$itemsref}) {
20300: if (exists($changes{$key}{$item})) {
20301: if ($item eq 'markup') {
20302: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20303: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20304: } else {
20305: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20306: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20307: }
20308: }
20309: }
20310: } else {
20311: foreach my $type (@types) {
20312: if ($type eq 'community') {
20313: $roles{'1'} = &mt('Community personnel');
20314: } else {
20315: $roles{'1'} = &mt('Course personnel');
20316: }
20317: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20318: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20319: if ($key eq 'admin') {
20320: my @mgrdc = ();
20321: if (ref($ordered{$key}) eq 'ARRAY') {
20322: foreach my $item (@{$ordered{'admin'}}) {
20323: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20324: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20325: push(@mgrdc,$item);
20326: }
20327: }
20328: }
20329: if (@mgrdc) {
20330: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20331: } else {
20332: delete($domdefaults{$type.'selfenrolladmdc'});
20333: }
20334: }
20335: } else {
20336: if (ref($ordered{$key}) eq 'ARRAY') {
20337: foreach my $item (@{$ordered{$key}}) {
20338: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20339: $domdefaults{$type.'selfenroll'.$item} =
20340: $selfenrollhash{$key}{$type}{$item};
20341: }
20342: }
20343: }
20344: }
20345: }
1.231 raeburn 20346: $resulttext .= '<li>'.$titles{$type}.'<ul>';
20347: foreach my $item (@{$ordered{$key}}) {
20348: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20349: $resulttext .= '<li>';
20350: if ($key eq 'admin') {
20351: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
20352: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
20353: } else {
20354: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
20355: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
20356: }
20357: $resulttext .= '</li>';
20358: }
20359: }
20360: $resulttext .= '</ul></li>';
20361: }
20362: }
20363: $resulttext .= '</ul></li>';
20364: }
20365: }
1.305 raeburn 20366: }
20367: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
20368: my $cachetime = 24*60*60;
20369: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20370: if (ref($lastactref) eq 'HASH') {
20371: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 20372: }
1.231 raeburn 20373: }
20374: $resulttext .= '</ul>';
20375: } else {
20376: $resulttext = &mt('No changes made to self-enrollment settings');
20377: }
20378: } else {
20379: $resulttext = '<span class="LC_error">'.
20380: &mt('An error occurred: [_1]',$putresult).'</span>';
20381: }
20382: return $resulttext;
20383: }
20384:
1.373 raeburn 20385: sub modify_wafproxy {
20386: my ($dom,$action,$lastactref,%domconfig) = @_;
20387: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 20388: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
20389: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 20390: foreach my $server (sort(keys(%servers))) {
20391: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20392: if ($serverhome eq $server) {
20393: my $serverdom = &Apache::lonnet::host_domain($server);
20394: if ($serverdom eq $dom) {
20395: $canset{$server} = 1;
20396: }
20397: }
20398: }
1.381 raeburn 20399: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
20400: %{$values{$dom}} = ();
20401: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
20402: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
20403: }
1.388 raeburn 20404: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
20405: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
20406: }
1.382 raeburn 20407: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 20408: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
20409: }
20410: }
1.373 raeburn 20411: my $output;
20412: if (keys(%canset)) {
20413: %{$wafproxy{'alias'}} = ();
1.388 raeburn 20414: %{$wafproxy{'saml'}} = ();
1.373 raeburn 20415: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 20416: if ($env{'form.wafproxy_'.$dom}) {
20417: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
20418: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
20419: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
20420: $changes{'alias'} = 1;
20421: }
1.388 raeburn 20422: if ($env{'form.wafproxy_alias_saml_'.$key}) {
20423: $wafproxy{'saml'}{$key} = 1;
20424: }
20425: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
20426: $changes{'saml'} = 1;
20427: }
1.381 raeburn 20428: } else {
20429: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 20430: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 20431: if ($curralias{$key}) {
20432: $changes{'alias'} = 1;
20433: }
1.388 raeburn 20434: if ($currsaml{$key}) {
20435: $changes{'saml'} = 1;
20436: }
1.373 raeburn 20437: }
20438: if ($wafproxy{'alias'}{$key} eq '') {
20439: if ($curralias{$key}) {
20440: $expirecache{$key} = 1;
20441: }
20442: delete($wafproxy{'alias'}{$key});
20443: }
1.388 raeburn 20444: if ($wafproxy{'saml'}{$key} eq '') {
20445: if ($currsaml{$key}) {
20446: $expiresaml{$key} = 1;
20447: }
20448: delete($wafproxy{'saml'}{$key});
20449: }
1.373 raeburn 20450: }
20451: unless (keys(%{$wafproxy{'alias'}})) {
20452: delete($wafproxy{'alias'});
20453: }
1.388 raeburn 20454: unless (keys(%{$wafproxy{'saml'}})) {
20455: delete($wafproxy{'saml'});
20456: }
20457: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 20458: my %warn = (
20459: trusted => 'trusted IP range(s)',
1.381 raeburn 20460: vpnint => 'internal IP range(s) for VPN sessions(s)',
20461: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 20462: );
1.382 raeburn 20463: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20464: my $possible = $env{'form.wafproxy_'.$item};
20465: $possible =~ s/^\s+|\s+$//g;
20466: if ($possible ne '') {
1.381 raeburn 20467: if ($item eq 'remoteip') {
20468: if ($possible =~ /^[mhn]$/) {
20469: $wafproxy{$item} = $possible;
20470: }
20471: } elsif ($item eq 'ipheader') {
20472: if ($wafproxy{'remoteip'} eq 'h') {
20473: $wafproxy{$item} = $possible;
20474: }
1.382 raeburn 20475: } elsif ($item eq 'sslopt') {
20476: if ($possible =~ /^0|1$/) {
20477: $wafproxy{$item} = $possible;
20478: }
1.373 raeburn 20479: } else {
20480: my (@ok,$count);
1.381 raeburn 20481: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
20482: unless ($env{'form.wafproxy_vpnaccess'}) {
20483: $possible = '';
20484: }
20485: } elsif ($item eq 'trusted') {
20486: unless ($wafproxy{'remoteip'} eq 'h') {
20487: $possible = '';
20488: }
20489: }
20490: unless ($possible eq '') {
20491: $possible =~ s/[\r\n]+/\s/g;
20492: $possible =~ s/\s*-\s*/-/g;
20493: $possible =~ s/\s+/,/g;
20494: }
1.373 raeburn 20495: $count = 0;
1.381 raeburn 20496: if ($possible ne '') {
1.373 raeburn 20497: foreach my $poss (split(/\,/,$possible)) {
20498: $count ++;
20499: if (&validate_ip_pattern($poss)) {
20500: push(@ok,$poss);
20501: }
20502: }
20503: if (@ok) {
20504: $wafproxy{$item} = join(',',@ok);
20505: }
20506: my $diff = $count - scalar(@ok);
20507: if ($diff) {
20508: push(@warnings,'<li>'.
20509: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
20510: $diff,$warn{$item}).
20511: '</li>');
20512: }
20513: }
20514: }
1.381 raeburn 20515: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 20516: $changes{$item} = 1;
20517: }
1.381 raeburn 20518: } elsif ($currvalue{$item}) {
20519: $changes{$item} = 1;
20520: }
20521: }
20522: } else {
20523: if (keys(%curralias)) {
20524: $changes{'alias'} = 1;
1.388 raeburn 20525: }
20526: if (keys(%currsaml)) {
20527: $changes{'saml'} = 1;
1.381 raeburn 20528: }
20529: if (keys(%currvalue)) {
20530: foreach my $key (keys(%currvalue)) {
20531: $changes{$key} = 1;
1.373 raeburn 20532: }
20533: }
20534: }
20535: if (keys(%changes)) {
20536: my %defaultshash = (
20537: wafproxy => \%wafproxy,
20538: );
20539: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20540: $dom);
20541: if ($putresult eq 'ok') {
20542: my $cachetime = 24*60*60;
20543: my (%domdefaults,$updatedomdefs);
1.382 raeburn 20544: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20545: if ($changes{$item}) {
20546: unless ($updatedomdefs) {
20547: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20548: $updatedomdefs = 1;
20549: }
20550: if ($wafproxy{$item}) {
20551: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20552: } elsif (exists($domdefaults{'waf_'.$item})) {
20553: delete($domdefaults{'waf_'.$item});
20554: }
20555: }
20556: }
20557: if ($updatedomdefs) {
20558: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20559: if (ref($lastactref) eq 'HASH') {
20560: $lastactref->{'domdefaults'} = 1;
20561: }
20562: }
20563: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20564: my %updates = %expirecache;
20565: foreach my $key (keys(%expirecache)) {
20566: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20567: }
20568: if (ref($wafproxy{'alias'}) eq 'HASH') {
20569: my $cachetime = 24*60*60;
20570: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20571: $updates{$key} = 1;
20572: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20573: $cachetime);
20574: }
20575: }
20576: if (ref($lastactref) eq 'HASH') {
20577: $lastactref->{'proxyalias'} = \%updates;
20578: }
20579: }
1.388 raeburn 20580: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20581: my %samlupdates = %expiresaml;
20582: foreach my $key (keys(%expiresaml)) {
20583: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20584: }
20585: if (ref($wafproxy{'saml'}) eq 'HASH') {
20586: my $cachetime = 24*60*60;
20587: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20588: $samlupdates{$key} = 1;
20589: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20590: $cachetime);
20591: }
20592: }
20593: if (ref($lastactref) eq 'HASH') {
20594: $lastactref->{'proxysaml'} = \%samlupdates;
20595: }
20596: }
1.373 raeburn 20597: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382 raeburn 20598: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 20599: if ($changes{$item}) {
20600: if ($item eq 'alias') {
20601: my $numaliased = 0;
20602: if (ref($wafproxy{'alias'}) eq 'HASH') {
20603: my $shown;
20604: if (keys(%{$wafproxy{'alias'}})) {
20605: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20606: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20607: &Apache::lonnet::hostname($server),
20608: $wafproxy{'alias'}{$server}).'</li>';
20609: $numaliased ++;
20610: }
20611: if ($numaliased) {
20612: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20613: '<ul>'.$shown.'</ul>').'</li>';
20614: }
20615: }
20616: }
20617: unless ($numaliased) {
20618: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20619: }
1.388 raeburn 20620: } elsif ($item eq 'saml') {
20621: my $shown;
20622: if (ref($wafproxy{'saml'}) eq 'HASH') {
20623: if (keys(%{$wafproxy{'saml'}})) {
20624: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20625: }
20626: }
20627: if ($shown) {
20628: $output .= '<li>'.&mt('Alias used by Shibboleth for: [_1]',
20629: $shown).'</li>';
20630: } else {
20631: $output .= '<li>'.&mt('No alias used for Shibboleth').'</li>';
20632: }
1.373 raeburn 20633: } else {
1.381 raeburn 20634: if ($item eq 'remoteip') {
20635: my %ip_methods = &remoteip_methods();
20636: if ($wafproxy{$item} =~ /^[mh]$/) {
20637: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20638: $ip_methods{$wafproxy{$item}}).'</li>';
20639: } else {
20640: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20641: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20642: '</li>';
20643: } else {
20644: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20645: }
20646: }
20647: } elsif ($item eq 'ipheader') {
1.373 raeburn 20648: if ($wafproxy{$item}) {
1.381 raeburn 20649: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 20650: $wafproxy{$item}).'</li>';
20651: } else {
1.381 raeburn 20652: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 20653: }
20654: } elsif ($item eq 'trusted') {
20655: if ($wafproxy{$item}) {
1.381 raeburn 20656: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 20657: $wafproxy{$item}).'</li>';
20658: } else {
20659: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20660: }
1.381 raeburn 20661: } elsif ($item eq 'vpnint') {
20662: if ($wafproxy{$item}) {
20663: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20664: $wafproxy{$item}).'</li>';
20665: } else {
20666: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20667: }
20668: } elsif ($item eq 'vpnext') {
1.373 raeburn 20669: if ($wafproxy{$item}) {
1.381 raeburn 20670: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 20671: $wafproxy{$item}).'</li>';
20672: } else {
1.381 raeburn 20673: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 20674: }
1.382 raeburn 20675: } elsif ($item eq 'sslopt') {
20676: if ($wafproxy{$item}) {
20677: $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>';
20678: } else {
20679: $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>';
20680: }
1.373 raeburn 20681: }
20682: }
20683: }
20684: }
20685: } else {
20686: $output = '<span class="LC_error">'.
20687: &mt('An error occurred: [_1]',$putresult).'</span>';
20688: }
20689: } elsif (keys(%canset)) {
20690: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20691: }
20692: if (@warnings) {
20693: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20694: join("\n",@warnings).'</ul>';
20695: }
20696: return $output;
20697: }
20698:
20699: sub validate_ip_pattern {
20700: my ($pattern) = @_;
20701: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20702: my ($start,$end) = ($1,$2);
20703: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20704: return 1;
20705: }
20706: } elsif (&Net::CIDR::cidrvalidate($pattern)) {
20707: return 1;
20708: }
20709: return
20710: }
20711:
1.137 raeburn 20712: sub modify_usersessions {
1.212 raeburn 20713: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20714: my @hostingtypes = ('version','excludedomain','includedomain');
20715: my @offloadtypes = ('primary','default');
20716: my %types = (
20717: remote => \@hostingtypes,
20718: hosted => \@hostingtypes,
20719: spares => \@offloadtypes,
20720: );
20721: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20722: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 20723: my (%by_ip,%by_location,@intdoms,@instdoms);
20724: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 20725: my @locations = sort(keys(%by_location));
1.137 raeburn 20726: my (%defaultshash,%changes);
20727: foreach my $prefix (@prefixes) {
20728: $defaultshash{'usersessions'}{$prefix} = {};
20729: }
1.212 raeburn 20730: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20731: my $resulttext;
1.138 raeburn 20732: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20733: foreach my $prefix (@prefixes) {
1.145 raeburn 20734: next if ($prefix eq 'spares');
20735: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20736: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20737: if ($type eq 'version') {
20738: my $value = $env{'form.'.$prefix.'_'.$type};
20739: my $okvalue;
20740: if ($value ne '') {
20741: if (grep(/^\Q$value\E$/,@lcversions)) {
20742: $okvalue = $value;
20743: }
20744: }
20745: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20746: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20747: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20748: if ($inuse == 0) {
20749: $changes{$prefix}{$type} = 1;
20750: } else {
20751: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20752: $changes{$prefix}{$type} = 1;
20753: }
20754: if ($okvalue ne '') {
20755: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20756: }
20757: }
20758: } else {
20759: if (($inuse == 1) && ($okvalue ne '')) {
20760: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20761: $changes{$prefix}{$type} = 1;
20762: }
20763: }
20764: } else {
20765: if (($inuse == 1) && ($okvalue ne '')) {
20766: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20767: $changes{$prefix}{$type} = 1;
20768: }
20769: }
20770: } else {
20771: if (($inuse == 1) && ($okvalue ne '')) {
20772: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20773: $changes{$prefix}{$type} = 1;
20774: }
20775: }
20776: } else {
20777: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20778: my @okvals;
20779: foreach my $val (@vals) {
1.138 raeburn 20780: if ($val =~ /:/) {
20781: my @items = split(/:/,$val);
20782: foreach my $item (@items) {
20783: if (ref($by_location{$item}) eq 'ARRAY') {
20784: push(@okvals,$item);
20785: }
20786: }
20787: } else {
20788: if (ref($by_location{$val}) eq 'ARRAY') {
20789: push(@okvals,$val);
20790: }
1.137 raeburn 20791: }
20792: }
20793: @okvals = sort(@okvals);
20794: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20795: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20796: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20797: if ($inuse == 0) {
20798: $changes{$prefix}{$type} = 1;
20799: } else {
20800: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20801: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20802: if (@changed > 0) {
20803: $changes{$prefix}{$type} = 1;
20804: }
20805: }
20806: } else {
20807: if ($inuse == 1) {
20808: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20809: $changes{$prefix}{$type} = 1;
20810: }
20811: }
20812: } else {
20813: if ($inuse == 1) {
20814: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20815: $changes{$prefix}{$type} = 1;
20816: }
20817: }
20818: } else {
20819: if ($inuse == 1) {
20820: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20821: $changes{$prefix}{$type} = 1;
20822: }
20823: }
20824: }
20825: }
20826: }
1.145 raeburn 20827:
20828: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20829: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20830: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20831: my $savespares;
20832:
20833: foreach my $lonhost (sort(keys(%servers))) {
20834: my $serverhomeID =
20835: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20836: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20837: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20838: my %spareschg;
20839: foreach my $type (@{$types{'spares'}}) {
20840: my @okspares;
20841: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20842: foreach my $server (@checked) {
1.152 raeburn 20843: if (&Apache::lonnet::hostname($server) ne '') {
20844: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20845: unless (grep(/^\Q$server\E$/,@okspares)) {
20846: push(@okspares,$server);
20847: }
1.145 raeburn 20848: }
20849: }
20850: }
20851: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20852: my $newspare;
1.152 raeburn 20853: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20854: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20855: $newspare = $new;
20856: }
20857: }
1.152 raeburn 20858: my @spares;
20859: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20860: @spares = sort(@okspares,$newspare);
20861: } else {
20862: @spares = sort(@okspares);
20863: }
20864: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20865: if (ref($spareid{$lonhost}) eq 'HASH') {
20866: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20867: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20868: if (@diffs > 0) {
20869: $spareschg{$type} = 1;
20870: }
20871: }
20872: }
20873: }
20874: if (keys(%spareschg) > 0) {
20875: $changes{'spares'}{$lonhost} = \%spareschg;
20876: }
20877: }
1.261 raeburn 20878: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 20879: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 20880: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20881: my @okoffload;
20882: if (@offloadnow) {
20883: foreach my $server (@offloadnow) {
20884: if (&Apache::lonnet::hostname($server) ne '') {
20885: unless (grep(/^\Q$server\E$/,@okoffload)) {
20886: push(@okoffload,$server);
20887: }
20888: }
20889: }
20890: if (@okoffload) {
20891: foreach my $lonhost (@okoffload) {
20892: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20893: }
20894: }
20895: }
1.371 raeburn 20896: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20897: my @okoffloadoth;
20898: if (@offloadoth) {
20899: foreach my $server (@offloadoth) {
20900: if (&Apache::lonnet::hostname($server) ne '') {
20901: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20902: push(@okoffloadoth,$server);
20903: }
20904: }
20905: }
20906: if (@okoffloadoth) {
20907: foreach my $lonhost (@okoffloadoth) {
20908: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20909: }
20910: }
20911: }
1.145 raeburn 20912: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20913: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20914: if (ref($changes{'spares'}) eq 'HASH') {
20915: if (keys(%{$changes{'spares'}}) > 0) {
20916: $savespares = 1;
20917: }
20918: }
20919: } else {
20920: $savespares = 1;
20921: }
1.371 raeburn 20922: foreach my $offload ('offloadnow','offloadoth') {
20923: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20924: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20925: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20926: $changes{$offload} = 1;
20927: last;
20928: }
1.261 raeburn 20929: }
1.371 raeburn 20930: unless ($changes{$offload}) {
20931: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20932: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20933: $changes{$offload} = 1;
20934: last;
20935: }
1.261 raeburn 20936: }
20937: }
1.371 raeburn 20938: } else {
20939: if (($offload eq 'offloadnow') && (@okoffload)) {
20940: $changes{'offloadnow'} = 1;
20941: }
20942: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20943: $changes{'offloadoth'} = 1;
20944: }
20945: }
20946: }
20947: } else {
20948: if (@okoffload) {
1.261 raeburn 20949: $changes{'offloadnow'} = 1;
20950: }
1.371 raeburn 20951: if (@okoffloadoth) {
20952: $changes{'offloadoth'} = 1;
20953: }
1.145 raeburn 20954: }
1.147 raeburn 20955: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20956: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20957: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20958: $dom);
20959: if ($putresult eq 'ok') {
20960: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20961: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20962: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20963: }
20964: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20965: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20966: }
1.261 raeburn 20967: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20968: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20969: }
1.371 raeburn 20970: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20971: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20972: }
1.137 raeburn 20973: }
20974: my $cachetime = 24*60*60;
20975: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 20976: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 20977: if (ref($lastactref) eq 'HASH') {
20978: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 20979: $lastactref->{'usersessions'} = 1;
1.212 raeburn 20980: }
1.147 raeburn 20981: if (keys(%changes) > 0) {
20982: my %lt = &usersession_titles();
20983: $resulttext = &mt('Changes made:').'<ul>';
20984: foreach my $prefix (@prefixes) {
20985: if (ref($changes{$prefix}) eq 'HASH') {
20986: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20987: if ($prefix eq 'spares') {
20988: if (ref($changes{$prefix}) eq 'HASH') {
20989: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20990: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20991: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 20992: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20993: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20994: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20995: foreach my $type (@{$types{$prefix}}) {
20996: if ($changes{$prefix}{$lonhost}{$type}) {
20997: my $offloadto = &mt('None');
20998: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20999: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21000: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21001: }
1.145 raeburn 21002: }
1.147 raeburn 21003: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21004: }
1.137 raeburn 21005: }
21006: }
1.147 raeburn 21007: $resulttext .= '</li>';
1.137 raeburn 21008: }
21009: }
1.147 raeburn 21010: } else {
21011: foreach my $type (@{$types{$prefix}}) {
21012: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21013: my ($newvalue,$notinuse);
1.147 raeburn 21014: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21015: if (ref($defaultshash{'usersessions'}{$prefix})) {
21016: if ($type eq 'version') {
21017: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21018: } else {
21019: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21020: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21021: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21022: }
21023: } else {
21024: $notinuse = 1;
1.147 raeburn 21025: }
1.145 raeburn 21026: }
21027: }
21028: }
1.147 raeburn 21029: if ($newvalue eq '') {
21030: if ($type eq 'version') {
21031: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21032: } elsif ($notinuse) {
21033: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21034: } else {
21035: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21036: }
1.145 raeburn 21037: } else {
1.147 raeburn 21038: if ($type eq 'version') {
1.344 raeburn 21039: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21040: }
21041: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21042: }
1.137 raeburn 21043: }
21044: }
21045: }
1.147 raeburn 21046: $resulttext .= '</ul>';
1.137 raeburn 21047: }
21048: }
1.261 raeburn 21049: if ($changes{'offloadnow'}) {
21050: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21051: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21052: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21053: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21054: $resulttext .= '<li>'.$lonhost.'</li>';
21055: }
21056: $resulttext .= '</ul>';
21057: } else {
1.371 raeburn 21058: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21059: }
21060: } else {
21061: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21062: }
21063: }
21064: if ($changes{'offloadoth'}) {
21065: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21066: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21067: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21068: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21069: $resulttext .= '<li>'.$lonhost.'</li>';
21070: }
21071: $resulttext .= '</ul>';
21072: } else {
21073: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21074: }
21075: } else {
1.371 raeburn 21076: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21077: }
21078: }
1.147 raeburn 21079: $resulttext .= '</ul>';
21080: } else {
21081: $resulttext = $nochgmsg;
1.137 raeburn 21082: }
21083: } else {
21084: $resulttext = '<span class="LC_error">'.
21085: &mt('An error occurred: [_1]',$putresult).'</span>';
21086: }
21087: } else {
1.147 raeburn 21088: $resulttext = $nochgmsg;
1.137 raeburn 21089: }
21090: return $resulttext;
21091: }
21092:
1.275 raeburn 21093: sub modify_ssl {
21094: my ($dom,$lastactref,%domconfig) = @_;
21095: my (%by_ip,%by_location,@intdoms,@instdoms);
21096: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21097: my @locations = sort(keys(%by_location));
21098: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21099: my (%defaultshash,%changes);
21100: my $action = 'ssl';
1.293 raeburn 21101: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21102: foreach my $prefix (@prefixes) {
21103: $defaultshash{$action}{$prefix} = {};
21104: }
21105: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21106: my $resulttext;
21107: my %iphost = &Apache::lonnet::get_iphost();
21108: my @reptypes = ('certreq','nocertreq');
21109: my @connecttypes = ('dom','intdom','other');
21110: my %types = (
1.293 raeburn 21111: connto => \@connecttypes,
21112: connfrom => \@connecttypes,
21113: replication => \@reptypes,
1.275 raeburn 21114: );
21115: foreach my $prefix (sort(keys(%types))) {
21116: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21117: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21118: my $value = 'yes';
21119: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21120: $value = $env{'form.'.$prefix.'_'.$type};
21121: }
1.335 raeburn 21122: if (ref($domconfig{$action}) eq 'HASH') {
21123: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21124: if ($domconfig{$action}{$prefix}{$type} ne '') {
21125: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21126: $changes{$prefix}{$type} = 1;
21127: }
21128: $defaultshash{$action}{$prefix}{$type} = $value;
21129: } else {
21130: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21131: $changes{$prefix}{$type} = 1;
21132: }
21133: } else {
21134: $defaultshash{$action}{$prefix}{$type} = $value;
21135: $changes{$prefix}{$type} = 1;
21136: }
21137: } else {
21138: $defaultshash{$action}{$prefix}{$type} = $value;
21139: $changes{$prefix}{$type} = 1;
21140: }
21141: if (($type eq 'dom') && (keys(%servers) == 1)) {
21142: delete($changes{$prefix}{$type});
21143: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21144: delete($changes{$prefix}{$type});
21145: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21146: delete($changes{$prefix}{$type});
21147: }
21148: } elsif ($prefix eq 'replication') {
21149: if (@locations > 0) {
21150: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21151: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21152: my @okvals;
21153: foreach my $val (@vals) {
21154: if ($val =~ /:/) {
21155: my @items = split(/:/,$val);
21156: foreach my $item (@items) {
21157: if (ref($by_location{$item}) eq 'ARRAY') {
21158: push(@okvals,$item);
21159: }
21160: }
21161: } else {
21162: if (ref($by_location{$val}) eq 'ARRAY') {
21163: push(@okvals,$val);
21164: }
21165: }
21166: }
21167: @okvals = sort(@okvals);
21168: if (ref($domconfig{$action}) eq 'HASH') {
21169: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21170: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21171: if ($inuse == 0) {
21172: $changes{$prefix}{$type} = 1;
21173: } else {
21174: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21175: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21176: if (@changed > 0) {
21177: $changes{$prefix}{$type} = 1;
21178: }
21179: }
21180: } else {
21181: if ($inuse == 1) {
21182: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21183: $changes{$prefix}{$type} = 1;
21184: }
21185: }
21186: } else {
21187: if ($inuse == 1) {
21188: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21189: $changes{$prefix}{$type} = 1;
21190: }
21191: }
21192: } else {
21193: if ($inuse == 1) {
21194: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21195: $changes{$prefix}{$type} = 1;
21196: }
21197: }
21198: }
21199: }
21200: }
21201: }
1.336 raeburn 21202: if (keys(%changes)) {
21203: foreach my $prefix (keys(%changes)) {
21204: if (ref($changes{$prefix}) eq 'HASH') {
21205: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21206: delete($changes{$prefix});
21207: }
21208: } else {
21209: delete($changes{$prefix});
21210: }
21211: }
21212: }
1.275 raeburn 21213: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21214: if (keys(%changes) > 0) {
21215: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21216: $dom);
21217: if ($putresult eq 'ok') {
21218: if (ref($defaultshash{$action}) eq 'HASH') {
21219: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21220: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21221: }
1.293 raeburn 21222: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21223: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21224: }
21225: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21226: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21227: }
21228: }
21229: my $cachetime = 24*60*60;
21230: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21231: if (ref($lastactref) eq 'HASH') {
21232: $lastactref->{'domdefaults'} = 1;
21233: }
21234: if (keys(%changes) > 0) {
21235: my %titles = &ssl_titles();
21236: $resulttext = &mt('Changes made:').'<ul>';
21237: foreach my $prefix (@prefixes) {
21238: if (ref($changes{$prefix}) eq 'HASH') {
21239: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21240: foreach my $type (@{$types{$prefix}}) {
21241: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21242: my ($newvalue,$notinuse);
1.275 raeburn 21243: if (ref($defaultshash{$action}) eq 'HASH') {
21244: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21245: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21246: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21247: } else {
21248: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21249: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21250: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21251: }
21252: } else {
21253: $notinuse = 1;
1.275 raeburn 21254: }
21255: }
21256: }
1.344 raeburn 21257: if ($notinuse) {
21258: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21259: } elsif ($newvalue eq '') {
1.275 raeburn 21260: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21261: } else {
21262: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21263: }
21264: }
21265: }
21266: }
21267: $resulttext .= '</ul>';
21268: }
21269: }
21270: } else {
21271: $resulttext = $nochgmsg;
21272: }
21273: } else {
21274: $resulttext = '<span class="LC_error">'.
21275: &mt('An error occurred: [_1]',$putresult).'</span>';
21276: }
21277: } else {
21278: $resulttext = $nochgmsg;
21279: }
21280: return $resulttext;
21281: }
21282:
1.279 raeburn 21283: sub modify_trust {
21284: my ($dom,$lastactref,%domconfig) = @_;
21285: my (%by_ip,%by_location,@intdoms,@instdoms);
21286: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21287: my @locations = sort(keys(%by_location));
21288: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21289: my @types = ('exc','inc');
21290: my (%defaultshash,%changes);
21291: foreach my $prefix (@prefixes) {
21292: $defaultshash{'trust'}{$prefix} = {};
21293: }
21294: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21295: my $resulttext;
21296: foreach my $prefix (@prefixes) {
21297: foreach my $type (@types) {
21298: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21299: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21300: my @okvals;
21301: foreach my $val (@vals) {
21302: if ($val =~ /:/) {
21303: my @items = split(/:/,$val);
21304: foreach my $item (@items) {
21305: if (ref($by_location{$item}) eq 'ARRAY') {
21306: push(@okvals,$item);
21307: }
21308: }
21309: } else {
21310: if (ref($by_location{$val}) eq 'ARRAY') {
21311: push(@okvals,$val);
21312: }
21313: }
21314: }
21315: @okvals = sort(@okvals);
21316: if (ref($domconfig{'trust'}) eq 'HASH') {
21317: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21318: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21319: if ($inuse == 0) {
21320: $changes{$prefix}{$type} = 1;
21321: } else {
21322: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21323: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
21324: if (@changed > 0) {
21325: $changes{$prefix}{$type} = 1;
21326: }
21327: }
21328: } else {
21329: if ($inuse == 1) {
21330: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21331: $changes{$prefix}{$type} = 1;
21332: }
21333: }
21334: } else {
21335: if ($inuse == 1) {
21336: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21337: $changes{$prefix}{$type} = 1;
21338: }
21339: }
21340: } else {
21341: if ($inuse == 1) {
21342: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21343: $changes{$prefix}{$type} = 1;
21344: }
21345: }
21346: }
21347: }
21348: my $nochgmsg = &mt('No changes made to trust settings.');
21349: if (keys(%changes) > 0) {
21350: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21351: $dom);
21352: if ($putresult eq 'ok') {
21353: if (ref($defaultshash{'trust'}) eq 'HASH') {
21354: foreach my $prefix (@prefixes) {
21355: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
21356: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
21357: }
21358: }
21359: }
21360: my $cachetime = 24*60*60;
21361: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21362: if (ref($lastactref) eq 'HASH') {
21363: $lastactref->{'domdefaults'} = 1;
21364: }
21365: if (keys(%changes) > 0) {
21366: my %lt = &trust_titles();
21367: $resulttext = &mt('Changes made:').'<ul>';
21368: foreach my $prefix (@prefixes) {
21369: if (ref($changes{$prefix}) eq 'HASH') {
21370: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21371: foreach my $type (@types) {
21372: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21373: my ($newvalue,$notinuse);
1.279 raeburn 21374: if (ref($defaultshash{'trust'}) eq 'HASH') {
21375: if (ref($defaultshash{'trust'}{$prefix})) {
21376: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21377: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
21378: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
21379: }
1.344 raeburn 21380: } else {
21381: $notinuse = 1;
1.279 raeburn 21382: }
21383: }
21384: }
1.344 raeburn 21385: if ($notinuse) {
21386: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
21387: } elsif ($newvalue eq '') {
1.279 raeburn 21388: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21389: } else {
21390: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
21391: }
21392: }
21393: }
21394: $resulttext .= '</ul>';
21395: }
21396: }
21397: $resulttext .= '</ul>';
21398: } else {
21399: $resulttext = $nochgmsg;
21400: }
21401: } else {
21402: $resulttext = '<span class="LC_error">'.
21403: &mt('An error occurred: [_1]',$putresult).'</span>';
21404: }
21405: } else {
21406: $resulttext = $nochgmsg;
21407: }
21408: return $resulttext;
21409: }
21410:
1.150 raeburn 21411: sub modify_loadbalancing {
21412: my ($dom,%domconfig) = @_;
21413: my $primary_id = &Apache::lonnet::domain($dom,'primary');
21414: my $intdom = &Apache::lonnet::internet_dom($primary_id);
21415: my ($othertitle,$usertypes,$types) =
21416: &Apache::loncommon::sorted_inst_types($dom);
21417: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 21418: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 21419: my @sparestypes = ('primary','default');
21420: my %typetitles = &sparestype_titles();
21421: my $resulttext;
1.342 raeburn 21422: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21423: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21424: %existing = %{$domconfig{'loadbalancing'}};
21425: }
21426: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 21427: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 21428: my ($saveloadbalancing,%defaultshash,%changes);
21429: my ($alltypes,$othertypes,$titles) =
21430: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
21431: my %ruletitles = &offloadtype_text();
21432: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
21433: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
21434: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
21435: if ($balancer eq '') {
21436: next;
21437: }
1.210 raeburn 21438: if (!exists($servers{$balancer})) {
1.171 raeburn 21439: if (exists($currbalancer{$balancer})) {
21440: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 21441: }
1.171 raeburn 21442: next;
21443: }
21444: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
21445: push(@{$changes{'delete'}},$balancer);
21446: next;
21447: }
21448: if (!exists($currbalancer{$balancer})) {
21449: push(@{$changes{'add'}},$balancer);
21450: }
21451: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
21452: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
21453: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
21454: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21455: $saveloadbalancing = 1;
21456: }
21457: foreach my $sparetype (@sparestypes) {
21458: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
21459: my @offloadto;
21460: foreach my $target (@targets) {
21461: if (($servers{$target}) && ($target ne $balancer)) {
21462: if ($sparetype eq 'default') {
21463: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
21464: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 21465: }
21466: }
1.171 raeburn 21467: unless(grep(/^\Q$target\E$/,@offloadto)) {
21468: push(@offloadto,$target);
21469: }
1.150 raeburn 21470: }
21471: }
1.284 raeburn 21472: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
21473: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
21474: push(@offloadto,$balancer);
21475: }
21476: }
21477: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 21478: }
1.342 raeburn 21479: if ($env{'form.loadbalancing_cookie_'.$i}) {
21480: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
21481: if (exists($currbalancer{$balancer})) {
21482: unless ($currcookies{$balancer}) {
21483: $changes{'curr'}{$balancer}{'cookie'} = 1;
21484: }
21485: }
21486: } elsif (exists($currbalancer{$balancer})) {
21487: if ($currcookies{$balancer}) {
21488: $changes{'curr'}{$balancer}{'cookie'} = 1;
21489: }
21490: }
1.171 raeburn 21491: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 21492: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21493: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
21494: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 21495: if (@targetdiffs > 0) {
1.171 raeburn 21496: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21497: }
1.171 raeburn 21498: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21499: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21500: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 21501: }
21502: }
21503: }
21504: } else {
1.171 raeburn 21505: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 21506: foreach my $sparetype (@sparestypes) {
1.171 raeburn 21507: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21508: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21509: $changes{'curr'}{$balancer}{'targets'} = 1;
21510: }
1.150 raeburn 21511: }
21512: }
1.210 raeburn 21513: }
1.150 raeburn 21514: }
21515: my $ishomedom;
1.171 raeburn 21516: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
21517: $ishomedom = 1;
1.150 raeburn 21518: }
21519: if (ref($alltypes) eq 'ARRAY') {
21520: foreach my $type (@{$alltypes}) {
21521: my $rule;
1.210 raeburn 21522: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 21523: (!$ishomedom)) {
1.171 raeburn 21524: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
21525: }
21526: if ($rule eq 'specific') {
1.255 raeburn 21527: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 21528: if (exists($servers{$specifiedhost})) {
1.255 raeburn 21529: $rule = $specifiedhost;
21530: }
1.150 raeburn 21531: }
1.171 raeburn 21532: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
21533: if (ref($currrules{$balancer}) eq 'HASH') {
21534: if ($rule ne $currrules{$balancer}{$type}) {
21535: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21536: }
21537: } elsif ($rule ne '') {
1.171 raeburn 21538: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 21539: }
21540: }
21541: }
1.171 raeburn 21542: }
21543: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
21544: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
21545: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
21546: $defaultshash{'loadbalancing'} = {};
21547: }
21548: my $putresult = &Apache::lonnet::put_dom('configuration',
21549: \%defaultshash,$dom);
21550: if ($putresult eq 'ok') {
21551: if (keys(%changes) > 0) {
1.252 raeburn 21552: my %toupdate;
1.171 raeburn 21553: if (ref($changes{'delete'}) eq 'ARRAY') {
21554: foreach my $balancer (sort(@{$changes{'delete'}})) {
21555: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 21556: $toupdate{$balancer} = 1;
1.150 raeburn 21557: }
1.171 raeburn 21558: }
21559: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 21560: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 21561: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 21562: $toupdate{$balancer} = 1;
1.171 raeburn 21563: }
21564: }
21565: if (ref($changes{'curr'}) eq 'HASH') {
21566: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 21567: $toupdate{$balancer} = 1;
1.171 raeburn 21568: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
21569: if ($changes{'curr'}{$balancer}{'targets'}) {
21570: my %offloadstr;
21571: foreach my $sparetype (@sparestypes) {
21572: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21573: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
21574: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21575: }
21576: }
1.150 raeburn 21577: }
1.171 raeburn 21578: if (keys(%offloadstr) == 0) {
21579: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 21580: } else {
1.171 raeburn 21581: my $showoffload;
21582: foreach my $sparetype (@sparestypes) {
21583: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
21584: if (defined($offloadstr{$sparetype})) {
21585: $showoffload .= $offloadstr{$sparetype};
21586: } else {
21587: $showoffload .= &mt('None');
21588: }
21589: $showoffload .= (' 'x3);
21590: }
21591: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 21592: }
21593: }
21594: }
1.171 raeburn 21595: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
21596: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
21597: foreach my $type (@{$alltypes}) {
21598: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
21599: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21600: my $balancetext;
21601: if ($rule eq '') {
21602: $balancetext = $ruletitles{'default'};
1.209 raeburn 21603: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 21604: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 21605: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 21606: foreach my $sparetype (@sparestypes) {
21607: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
21608: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
21609: }
21610: }
1.253 raeburn 21611: foreach my $item (@{$alltypes}) {
21612: next if ($item =~ /^_LC_ipchange/);
21613: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
21614: if ($hasrule eq 'homeserver') {
21615: map { $toupdate{$_} = 1; } (keys(%libraryservers));
21616: } else {
21617: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
21618: if ($servers{$hasrule}) {
21619: $toupdate{$hasrule} = 1;
21620: }
21621: }
21622: }
21623: }
1.254 raeburn 21624: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
21625: $balancetext = $ruletitles{$rule};
21626: } else {
21627: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
21628: $balancetext = $ruletitles{'particular'}.' '.$receiver;
21629: if ($receiver) {
21630: $toupdate{$receiver};
21631: }
21632: }
21633: } else {
21634: $balancetext = $ruletitles{$rule};
1.252 raeburn 21635: }
1.171 raeburn 21636: } else {
21637: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
21638: }
1.210 raeburn 21639: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 21640: }
21641: }
21642: }
21643: }
1.342 raeburn 21644: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 21645: if ($currcookies{$balancer}) {
21646: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
21647: $balancer).'</li>';
21648: } else {
21649: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
21650: $balancer).'</li>';
21651: }
1.342 raeburn 21652: }
1.375 raeburn 21653: }
21654: }
21655: if (keys(%toupdate)) {
21656: my %thismachine;
21657: my $updatedhere;
21658: my $cachetime = 60*60*24;
21659: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
21660: foreach my $lonhost (keys(%toupdate)) {
21661: if ($thismachine{$lonhost}) {
21662: unless ($updatedhere) {
21663: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
21664: $defaultshash{'loadbalancing'},
21665: $cachetime);
21666: $updatedhere = 1;
1.252 raeburn 21667: }
1.375 raeburn 21668: } else {
21669: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
21670: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 21671: }
1.150 raeburn 21672: }
1.171 raeburn 21673: }
21674: if ($resulttext ne '') {
21675: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 21676: } else {
21677: $resulttext = $nochgmsg;
21678: }
21679: } else {
1.171 raeburn 21680: $resulttext = $nochgmsg;
1.150 raeburn 21681: }
21682: } else {
1.171 raeburn 21683: $resulttext = '<span class="LC_error">'.
21684: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 21685: }
21686: } else {
1.171 raeburn 21687: $resulttext = $nochgmsg;
1.150 raeburn 21688: }
21689: return $resulttext;
21690: }
21691:
1.48 raeburn 21692: sub recurse_check {
21693: my ($chkcats,$categories,$depth,$name) = @_;
21694: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
21695: my $chg = 0;
21696: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
21697: my $category = $chkcats->[$depth]{$name}[$j];
21698: my $item;
21699: if ($category eq '') {
21700: $chg ++;
21701: } else {
21702: my $deeper = $depth + 1;
21703: $item = &escape($category).':'.&escape($name).':'.$depth;
21704: if ($chg) {
21705: $categories->{$item} -= $chg;
21706: }
21707: &recurse_check($chkcats,$categories,$deeper,$category);
21708: $deeper --;
21709: }
21710: }
21711: }
21712: return;
21713: }
21714:
21715: sub recurse_cat_deletes {
21716: my ($item,$coursecategories,$deletions) = @_;
21717: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
21718: my $subdepth = $depth + 1;
21719: if (ref($coursecategories) eq 'HASH') {
21720: foreach my $subitem (keys(%{$coursecategories})) {
21721: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
21722: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
21723: delete($coursecategories->{$subitem});
21724: $deletions->{$subitem} = 1;
21725: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 21726: }
1.48 raeburn 21727: }
21728: }
21729: return;
21730: }
21731:
1.125 raeburn 21732: sub active_dc_picker {
1.191 raeburn 21733: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 21734: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 21735: my @domcoord = keys(%domcoords);
21736: if (keys(%currhash)) {
21737: foreach my $dc (keys(%currhash)) {
21738: unless (exists($domcoords{$dc})) {
21739: push(@domcoord,$dc);
21740: }
21741: }
21742: }
21743: @domcoord = sort(@domcoord);
1.210 raeburn 21744: my $numdcs = scalar(@domcoord);
1.191 raeburn 21745: my $rows = 0;
21746: my $table;
1.125 raeburn 21747: if ($numdcs > 1) {
1.191 raeburn 21748: $table = '<table>';
21749: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 21750: my $rem = $i%($numinrow);
21751: if ($rem == 0) {
21752: if ($i > 0) {
1.191 raeburn 21753: $table .= '</tr>';
1.125 raeburn 21754: }
1.191 raeburn 21755: $table .= '<tr>';
21756: $rows ++;
1.125 raeburn 21757: }
1.191 raeburn 21758: my $check = '';
21759: if ($inputtype eq 'radio') {
21760: if (keys(%currhash) == 0) {
21761: if (!$i) {
21762: $check = ' checked="checked"';
21763: }
21764: } elsif (exists($currhash{$domcoord[$i]})) {
21765: $check = ' checked="checked"';
21766: }
21767: } else {
21768: if (exists($currhash{$domcoord[$i]})) {
21769: $check = ' checked="checked"';
1.125 raeburn 21770: }
21771: }
1.191 raeburn 21772: if ($i == @domcoord - 1) {
1.125 raeburn 21773: my $colsleft = $numinrow - $rem;
21774: if ($colsleft > 1) {
1.191 raeburn 21775: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 21776: } else {
1.191 raeburn 21777: $table .= '<td class="LC_left_item">';
1.125 raeburn 21778: }
21779: } else {
1.191 raeburn 21780: $table .= '<td class="LC_left_item">';
21781: }
21782: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
21783: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
21784: $table .= '<span class="LC_nobreak"><label>'.
21785: '<input type="'.$inputtype.'" name="'.$name.'"'.
21786: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
21787: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 21788: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 21789: }
1.219 raeburn 21790: $table .= '</label></span></td>';
1.191 raeburn 21791: }
21792: $table .= '</tr></table>';
21793: } elsif ($numdcs == 1) {
1.219 raeburn 21794: my ($dcname,$dcdom) = split(':',$domcoord[0]);
21795: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 21796: if ($inputtype eq 'radio') {
1.247 raeburn 21797: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 21798: if ($user ne $dcname.':'.$dcdom) {
21799: $table .= ' ('.$dcname.':'.$dcdom.')';
21800: }
1.191 raeburn 21801: } else {
21802: my $check;
21803: if (exists($currhash{$domcoord[0]})) {
21804: $check = ' checked="checked"';
1.125 raeburn 21805: }
1.247 raeburn 21806: $table = '<span class="LC_nobreak"><label>'.
21807: '<input type="checkbox" name="'.$name.'" '.
21808: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 21809: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 21810: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 21811: }
1.220 raeburn 21812: $table .= '</label></span>';
1.191 raeburn 21813: $rows ++;
1.125 raeburn 21814: }
21815: }
1.191 raeburn 21816: return ($numdcs,$table,$rows);
1.125 raeburn 21817: }
21818:
1.137 raeburn 21819: sub usersession_titles {
21820: return &Apache::lonlocal::texthash(
21821: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
21822: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 21823: spares => 'Servers offloaded to, when busy',
1.137 raeburn 21824: version => 'LON-CAPA version requirement',
1.138 raeburn 21825: excludedomain => 'Allow all, but exclude specific domains',
21826: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 21827: primary => 'Primary (checked first)',
1.154 raeburn 21828: default => 'Default',
1.137 raeburn 21829: );
21830: }
21831:
1.152 raeburn 21832: sub id_for_thisdom {
21833: my (%servers) = @_;
21834: my %altids;
21835: foreach my $server (keys(%servers)) {
21836: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21837: if ($serverhome ne $server) {
21838: $altids{$serverhome} = $server;
21839: }
21840: }
21841: return %altids;
21842: }
21843:
1.150 raeburn 21844: sub count_servers {
21845: my ($currbalancer,%servers) = @_;
21846: my (@spares,$numspares);
21847: foreach my $lonhost (sort(keys(%servers))) {
21848: next if ($currbalancer eq $lonhost);
21849: push(@spares,$lonhost);
21850: }
21851: if ($currbalancer) {
21852: $numspares = scalar(@spares);
21853: } else {
21854: $numspares = scalar(@spares) - 1;
21855: }
21856: return ($numspares,@spares);
21857: }
21858:
21859: sub lonbalance_targets_js {
1.171 raeburn 21860: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21861: my $select = &mt('Select');
21862: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21863: if (ref($servers) eq 'HASH') {
21864: $alltargets = join("','",sort(keys(%{$servers})));
21865: my @homedoms;
21866: foreach my $server (sort(keys(%{$servers}))) {
21867: if (&Apache::lonnet::host_domain($server) eq $dom) {
21868: push(@homedoms,'1');
21869: } else {
21870: push(@homedoms,'0');
21871: }
21872: }
21873: $allishome = join("','",@homedoms);
21874: }
21875: if (ref($types) eq 'ARRAY') {
21876: if (@{$types} > 0) {
21877: @alltypes = @{$types};
21878: }
21879: }
21880: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21881: $allinsttypes = join("','",@alltypes);
1.342 raeburn 21882: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21883: if (ref($settings) eq 'HASH') {
21884: %existing = %{$settings};
21885: }
21886: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 21887: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 21888: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21889: return <<"END";
21890:
21891: <script type="text/javascript">
21892: // <![CDATA[
21893:
1.171 raeburn 21894: currBalancers = new Array('$balancers');
21895:
21896: function toggleTargets(balnum) {
21897: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21898: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21899: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21900: var prevbalancer = prevhostitem.value;
21901: var baltotal = document.getElementById('loadbalancing_total').value;
21902: prevhostitem.value = balancer;
21903: if (prevbalancer != '') {
21904: var prevIdx = currBalancers.indexOf(prevbalancer);
21905: if (prevIdx != -1) {
21906: currBalancers.splice(prevIdx,1);
21907: }
21908: }
1.150 raeburn 21909: if (balancer == '') {
1.171 raeburn 21910: hideSpares(balnum);
1.150 raeburn 21911: } else {
1.171 raeburn 21912: var currIdx = currBalancers.indexOf(balancer);
21913: if (currIdx == -1) {
21914: currBalancers.push(balancer);
21915: }
1.150 raeburn 21916: var homedoms = new Array('$allishome');
1.171 raeburn 21917: var ishomedom = homedoms[lonhostitem.selectedIndex];
21918: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21919: }
1.171 raeburn 21920: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21921: return;
21922: }
21923:
1.171 raeburn 21924: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21925: var alltargets = new Array('$alltargets');
21926: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21927: var offloadtypes = new Array('primary','default');
21928:
1.171 raeburn 21929: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21930: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21931:
1.151 raeburn 21932: for (var i=0; i<offloadtypes.length; i++) {
21933: var count = 0;
21934: for (var j=0; j<alltargets.length; j++) {
21935: if (alltargets[j] != balancer) {
1.171 raeburn 21936: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21937: item.value = alltargets[j];
21938: item.style.textAlign='left';
21939: item.style.textFace='normal';
21940: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21941: if (currBalancers.indexOf(alltargets[j]) == -1) {
21942: item.disabled = '';
21943: } else {
21944: item.disabled = 'disabled';
21945: item.checked = false;
21946: }
1.151 raeburn 21947: count ++;
21948: }
1.150 raeburn 21949: }
21950: }
1.151 raeburn 21951: for (var k=0; k<insttypes.length; k++) {
21952: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21953: if (ishomedom == 1) {
1.171 raeburn 21954: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21955: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21956: } else {
1.171 raeburn 21957: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21958: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21959: }
21960: } else {
1.171 raeburn 21961: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21962: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21963: }
1.151 raeburn 21964: if ((insttypes[k] != '_LC_external') &&
21965: ((insttypes[k] != '_LC_internetdom') ||
21966: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 21967: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21968: item.options.length = 0;
21969: item.options[0] = new Option("","",true,true);
1.210 raeburn 21970: var idx = 0;
1.151 raeburn 21971: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 21972: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21973: idx ++;
21974: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21975: }
21976: }
21977: }
21978: }
21979: return;
21980: }
21981:
1.171 raeburn 21982: function hideSpares(balnum) {
1.150 raeburn 21983: var alltargets = new Array('$alltargets');
21984: var insttypes = new Array('$allinsttypes');
21985: var offloadtypes = new Array('primary','default');
21986:
1.171 raeburn 21987: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21988: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21989:
21990: var total = alltargets.length - 1;
21991: for (var i=0; i<offloadtypes; i++) {
21992: for (var j=0; j<total; j++) {
1.171 raeburn 21993: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21994: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21995: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21996: }
1.150 raeburn 21997: }
21998: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 21999: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22000: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22001: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22002: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22003: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22004: }
22005: }
22006: return;
22007: }
22008:
1.171 raeburn 22009: function checkOffloads(item,balnum,type) {
1.150 raeburn 22010: var alltargets = new Array('$alltargets');
22011: var offloadtypes = new Array('primary','default');
22012: if (item.checked) {
22013: var total = alltargets.length - 1;
22014: var other;
22015: if (type == offloadtypes[0]) {
1.151 raeburn 22016: other = offloadtypes[1];
1.150 raeburn 22017: } else {
1.151 raeburn 22018: other = offloadtypes[0];
1.150 raeburn 22019: }
22020: for (var i=0; i<total; i++) {
1.171 raeburn 22021: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22022: if (server == item.value) {
1.171 raeburn 22023: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22024: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22025: }
22026: }
22027: }
22028: }
22029: return;
22030: }
22031:
1.171 raeburn 22032: function singleServerToggle(balnum,type) {
22033: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22034: if (offloadtoSelIdx == 0) {
1.171 raeburn 22035: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22036: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22037:
22038: } else {
1.171 raeburn 22039: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22040: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22041: }
22042: return;
22043: }
22044:
1.171 raeburn 22045: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22046: if (type == '_LC_external') {
1.171 raeburn 22047: return;
1.150 raeburn 22048: }
1.171 raeburn 22049: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22050: for (var i=0; i<typesRules.length; i++) {
22051: if (formname.elements[typesRules[i]].checked) {
22052: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22053: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22054: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22055: } else {
1.171 raeburn 22056: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22057: }
22058: }
22059: }
22060: return;
22061: }
22062:
22063: function balancerDeleteChange(balnum) {
22064: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22065: var baltotal = document.getElementById('loadbalancing_total').value;
22066: var addtarget;
22067: var removetarget;
22068: var action = 'delete';
22069: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22070: var lonhost = hostitem.value;
22071: var currIdx = currBalancers.indexOf(lonhost);
22072: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22073: if (currIdx != -1) {
22074: currBalancers.splice(currIdx,1);
22075: }
22076: addtarget = lonhost;
22077: } else {
22078: if (currIdx == -1) {
22079: currBalancers.push(lonhost);
22080: }
22081: removetarget = lonhost;
22082: action = 'undelete';
22083: }
22084: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22085: }
22086: return;
22087: }
22088:
22089: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22090: if (baltotal > 1) {
22091: var offloadtypes = new Array('primary','default');
22092: var alltargets = new Array('$alltargets');
22093: var insttypes = new Array('$allinsttypes');
22094: for (var i=0; i<baltotal; i++) {
22095: if (i != balnum) {
22096: for (var j=0; j<offloadtypes.length; j++) {
22097: var total = alltargets.length - 1;
22098: for (var k=0; k<total; k++) {
22099: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22100: var server = serveritem.value;
22101: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22102: if (server == addtarget) {
22103: serveritem.disabled = '';
22104: }
22105: }
22106: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22107: if (server == removetarget) {
22108: serveritem.disabled = 'disabled';
22109: serveritem.checked = false;
22110: }
22111: }
22112: }
22113: }
22114: for (var j=0; j<insttypes.length; j++) {
22115: if (insttypes[j] != '_LC_external') {
22116: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22117: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22118: var currSel = singleserver.selectedIndex;
22119: var currVal = singleserver.options[currSel].value;
22120: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22121: var numoptions = singleserver.options.length;
22122: var needsnew = 1;
22123: for (var k=0; k<numoptions; k++) {
22124: if (singleserver.options[k] == addtarget) {
22125: needsnew = 0;
22126: break;
22127: }
22128: }
22129: if (needsnew == 1) {
22130: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22131: }
22132: }
22133: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22134: singleserver.options.length = 0;
22135: if ((currVal) && (currVal != removetarget)) {
22136: singleserver.options[0] = new Option("","",false,false);
22137: } else {
22138: singleserver.options[0] = new Option("","",true,true);
22139: }
22140: var idx = 0;
22141: for (var m=0; m<alltargets.length; m++) {
22142: if (currBalancers.indexOf(alltargets[m]) == -1) {
22143: idx ++;
22144: if (currVal == alltargets[m]) {
22145: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22146: } else {
22147: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22148: }
22149: }
22150: }
22151: }
22152: }
22153: }
22154: }
1.150 raeburn 22155: }
22156: }
22157: }
22158: return;
22159: }
22160:
1.152 raeburn 22161: // ]]>
22162: </script>
22163:
22164: END
22165: }
22166:
1.372 raeburn 22167:
1.152 raeburn 22168: sub new_spares_js {
22169: my @sparestypes = ('primary','default');
22170: my $types = join("','",@sparestypes);
22171: my $select = &mt('Select');
22172: return <<"END";
22173:
22174: <script type="text/javascript">
22175: // <![CDATA[
22176:
22177: function updateNewSpares(formname,lonhost) {
22178: var types = new Array('$types');
22179: var include = new Array();
22180: var exclude = new Array();
22181: for (var i=0; i<types.length; i++) {
22182: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22183: for (var j=0; j<spareboxes.length; j++) {
22184: if (formname.elements[spareboxes[j]].checked) {
22185: exclude.push(formname.elements[spareboxes[j]].value);
22186: } else {
22187: include.push(formname.elements[spareboxes[j]].value);
22188: }
22189: }
22190: }
22191: for (var i=0; i<types.length; i++) {
22192: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22193: var selIdx = newSpare.selectedIndex;
22194: var currnew = newSpare.options[selIdx].value;
22195: var okSpares = new Array();
22196: for (var j=0; j<newSpare.options.length; j++) {
22197: var possible = newSpare.options[j].value;
22198: if (possible != '') {
22199: if (exclude.indexOf(possible) == -1) {
22200: okSpares.push(possible);
22201: } else {
22202: if (currnew == possible) {
22203: selIdx = 0;
22204: }
22205: }
22206: }
22207: }
22208: for (var k=0; k<include.length; k++) {
22209: if (okSpares.indexOf(include[k]) == -1) {
22210: okSpares.push(include[k]);
22211: }
22212: }
22213: okSpares.sort();
22214: newSpare.options.length = 0;
22215: if (selIdx == 0) {
22216: newSpare.options[0] = new Option("$select","",true,true);
22217: } else {
22218: newSpare.options[0] = new Option("$select","",false,false);
22219: }
22220: for (var m=0; m<okSpares.length; m++) {
22221: var idx = m+1;
22222: var selThis = 0;
22223: if (selIdx != 0) {
22224: if (okSpares[m] == currnew) {
22225: selThis = 1;
22226: }
22227: }
22228: if (selThis == 1) {
22229: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22230: } else {
22231: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22232: }
22233: }
22234: }
22235: return;
22236: }
22237:
22238: function checkNewSpares(lonhost,type) {
22239: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22240: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22241: if (chosen != '') {
1.152 raeburn 22242: var othertype;
22243: var othernewSpare;
22244: if (type == 'primary') {
22245: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22246: }
22247: if (type == 'default') {
22248: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22249: }
22250: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22251: othernewSpare.selectedIndex = 0;
22252: }
22253: }
22254: return;
22255: }
22256:
22257: // ]]>
22258: </script>
22259:
22260: END
22261:
22262: }
22263:
22264: sub common_domprefs_js {
22265: return <<"END";
22266:
22267: <script type="text/javascript">
22268: // <![CDATA[
22269:
1.150 raeburn 22270: function getIndicesByName(formname,item) {
1.152 raeburn 22271: var group = new Array();
1.150 raeburn 22272: for (var i=0;i<formname.elements.length;i++) {
22273: if (formname.elements[i].name == item) {
1.152 raeburn 22274: group.push(formname.elements[i].id);
1.150 raeburn 22275: }
22276: }
1.152 raeburn 22277: return group;
1.150 raeburn 22278: }
22279:
22280: // ]]>
22281: </script>
22282:
22283: END
1.152 raeburn 22284:
1.150 raeburn 22285: }
22286:
1.165 raeburn 22287: sub recaptcha_js {
22288: my %lt = &captcha_phrases();
22289: return <<"END";
22290:
22291: <script type="text/javascript">
22292: // <![CDATA[
22293:
22294: function updateCaptcha(caller,context) {
22295: var privitem;
22296: var pubitem;
22297: var privtext;
22298: var pubtext;
1.269 raeburn 22299: var versionitem;
22300: var versiontext;
1.165 raeburn 22301: if (document.getElementById(context+'_recaptchapub')) {
22302: pubitem = document.getElementById(context+'_recaptchapub');
22303: } else {
22304: return;
22305: }
22306: if (document.getElementById(context+'_recaptchapriv')) {
22307: privitem = document.getElementById(context+'_recaptchapriv');
22308: } else {
22309: return;
22310: }
22311: if (document.getElementById(context+'_recaptchapubtxt')) {
22312: pubtext = document.getElementById(context+'_recaptchapubtxt');
22313: } else {
22314: return;
22315: }
22316: if (document.getElementById(context+'_recaptchaprivtxt')) {
22317: privtext = document.getElementById(context+'_recaptchaprivtxt');
22318: } else {
22319: return;
22320: }
1.269 raeburn 22321: if (document.getElementById(context+'_recaptchaversion')) {
22322: versionitem = document.getElementById(context+'_recaptchaversion');
22323: } else {
22324: return;
22325: }
22326: if (document.getElementById(context+'_recaptchavertxt')) {
22327: versiontext = document.getElementById(context+'_recaptchavertxt');
22328: } else {
22329: return;
22330: }
1.165 raeburn 22331: if (caller.checked) {
22332: if (caller.value == 'recaptcha') {
22333: pubitem.type = 'text';
22334: privitem.type = 'text';
22335: pubitem.size = '40';
22336: privitem.size = '40';
22337: pubtext.innerHTML = "$lt{'pub'}";
22338: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 22339: versionitem.type = 'text';
22340: versionitem.size = '3';
1.289 raeburn 22341: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 22342: } else {
22343: pubitem.type = 'hidden';
22344: privitem.type = 'hidden';
1.269 raeburn 22345: versionitem.type = 'hidden';
1.165 raeburn 22346: pubtext.innerHTML = '';
22347: privtext.innerHTML = '';
1.269 raeburn 22348: versiontext.innerHTML = '';
1.165 raeburn 22349: }
22350: }
22351: return;
22352: }
22353:
22354: // ]]>
22355: </script>
22356:
22357: END
22358:
22359: }
22360:
1.236 raeburn 22361: sub toggle_display_js {
1.192 raeburn 22362: return <<"END";
22363:
22364: <script type="text/javascript">
22365: // <![CDATA[
22366:
1.236 raeburn 22367: function toggleDisplay(domForm,caller) {
22368: if (document.getElementById(caller)) {
22369: var divitem = document.getElementById(caller);
22370: var optionsElement = domForm.coursecredits;
1.264 raeburn 22371: var checkval = 1;
22372: var dispval = 'block';
1.303 raeburn 22373: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 22374: if (caller == 'emailoptions') {
1.372 raeburn 22375: optionsElement = domForm.cancreate_email;
1.236 raeburn 22376: }
1.257 raeburn 22377: if (caller == 'studentsubmission') {
22378: optionsElement = domForm.postsubmit;
22379: }
1.264 raeburn 22380: if (caller == 'cloneinstcode') {
22381: optionsElement = domForm.canclone;
22382: checkval = 'instcode';
22383: }
1.303 raeburn 22384: if (selfcreateRegExp.test(caller)) {
22385: optionsElement = domForm.elements[caller];
22386: checkval = 'other';
22387: dispval = 'inline'
22388: }
1.236 raeburn 22389: if (optionsElement.length) {
1.192 raeburn 22390: var currval;
1.236 raeburn 22391: for (var i=0; i<optionsElement.length; i++) {
22392: if (optionsElement[i].checked) {
22393: currval = optionsElement[i].value;
1.192 raeburn 22394: }
22395: }
1.264 raeburn 22396: if (currval == checkval) {
22397: divitem.style.display = dispval;
1.192 raeburn 22398: } else {
1.236 raeburn 22399: divitem.style.display = 'none';
1.192 raeburn 22400: }
22401: }
22402: }
22403: return;
22404: }
22405:
22406: // ]]>
22407: </script>
22408:
22409: END
22410:
22411: }
22412:
1.165 raeburn 22413: sub captcha_phrases {
22414: return &Apache::lonlocal::texthash (
22415: priv => 'Private key',
22416: pub => 'Public key',
22417: original => 'original (CAPTCHA)',
22418: recaptcha => 'successor (ReCAPTCHA)',
22419: notused => 'unused',
1.289 raeburn 22420: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 22421: );
22422: }
22423:
1.205 raeburn 22424: sub devalidate_remote_domconfs {
1.212 raeburn 22425: my ($dom,$cachekeys) = @_;
22426: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 22427: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22428: my %thismachine;
22429: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 22430: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.388 raeburn 22431: 'directorysrch','passwdconf','cats','proxyalias','proxysaml');
1.386 raeburn 22432: my %cache_by_lonhost;
22433: if (exists($cachekeys->{'samllanding'})) {
22434: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
22435: my %landing = %{$cachekeys->{'samllanding'}};
22436: my %domservers = &Apache::lonnet::get_servers($dom);
22437: if (keys(%domservers)) {
22438: foreach my $server (keys(%domservers)) {
22439: my @cached;
22440: next if ($thismachine{$server});
22441: if ($landing{$server}) {
22442: push(@cached,&escape('samllanding').':'.&escape($server));
22443: }
22444: if (@cached) {
22445: $cache_by_lonhost{$server} = \@cached;
22446: }
22447: }
22448: }
22449: }
22450: }
1.260 raeburn 22451: if (keys(%servers)) {
1.205 raeburn 22452: foreach my $server (keys(%servers)) {
22453: next if ($thismachine{$server});
1.212 raeburn 22454: my @cached;
22455: foreach my $name (@posscached) {
22456: if ($cachekeys->{$name}) {
1.388 raeburn 22457: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 22458: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 22459: foreach my $key (keys(%{$cachekeys->{$name}})) {
22460: push(@cached,&escape($name).':'.&escape($key));
22461: }
22462: }
22463: } else {
22464: push(@cached,&escape($name).':'.&escape($dom));
22465: }
1.212 raeburn 22466: }
22467: }
1.386 raeburn 22468: if ((exists($cache_by_lonhost{$server})) &&
22469: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
22470: push(@cached,@{$cache_by_lonhost{$server}});
22471: }
1.212 raeburn 22472: if (@cached) {
22473: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
22474: }
1.205 raeburn 22475: }
22476: }
22477: return;
22478: }
22479:
1.3 raeburn 22480: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>